| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- /* ===================================================================
- * MealDaoTest.java
- *
- * Created Sep 16, 2004 4:30:05 PM
- *
- * Copyright (c) 2004 Matt Magoffin (spamsqr@msqr.us)
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- * 02111-1307 USA
- * ===================================================================
- * $Id: MealDaoTest.java 39 2009-05-06 03:30:47Z msqr $
- * ===================================================================
- */
- package magoffin.matt.ieat.dao;
- import magoffin.matt.ieat.domain.Meal;
- import magoffin.matt.ieat.domain.MealRecipe;
- import magoffin.matt.ieat.domain.Recipe;
- import magoffin.matt.ieat.domain.User;
- /**
- * Test case for the RecipceDao.
- *
- * <p>These tests can only work when the test data is loaded in the database!</p>
- *
- * @author Matt Magoffin (spamsqr@msqr.us)
- * @version $Revision: 39 $ $Date: 2009-05-06 15:30:47 +1200 (Wed, 06 May 2009) $
- */
- public class MealDaoTest extends AbstractDaoTest {
-
- /** The MealDao to test. */
- protected MealDao mealDao;
-
- /** The RecipeDao to test with. */
- protected RecipeDao recipeDao;
-
- /** The UserDao to test with. */
- protected UserDao userDao;
-
- /**
- * Test able to create a meal.
- */
- public void testCreateMealWithoutRecipies() {
- Meal m = getDummyMeal();
- Meal storedMeal = mealDao.get(mealDao.store(m));
- assertNotNull("The persisted meal should have a mealId value",storedMeal.getMealId());
- }
-
- /**
- * Test able to create a meal with recipes.
- */
- @SuppressWarnings("unchecked")
- public void testCreateMealWithRecipies() {
- Meal m = null;
- Recipe r1 = null;
- Recipe r2 = null;
- m = getDummyMeal();
- r1 = getDummyRecipe();
- r2 = getDummyRecipe();
-
- r1 = recipeDao.get(recipeDao.store(r1));
- r2 = recipeDao.get(recipeDao.store(r2));
-
- MealRecipe mr1 = domainObjectFactory.getMealRecipeInstance();
- mr1.setCourse(getTestCourse());
- mr1.setQuantity(1.0f);
- mr1.setRecipe(r1);
-
- MealRecipe mr2 = domainObjectFactory.getMealRecipeInstance();
- mr2.setCourse(getTestCourse());
- mr2.setQuantity(2.0f);
- mr2.setRecipe(r2);
-
- m.getRecipe().add(mr1);
- m.getRecipe().add(mr2);
-
- Meal storedMeal = mealDao.get(mealDao.store(m));
- assertNotNull("The persisted meal should have a mealId value",storedMeal.getMealId());
-
- assertTrue("The persisted meal should have 2 recipes in it", storedMeal.getRecipe().size() == 2);
- }
- /**
- * Returns a dummy meal, with a newly created dummy user as the owner.
- * @return meal
- */
- private Meal getDummyMeal() {
- Meal m = domainObjectFactory.getMealInstance();
- m.setName("MealDaoTest Meal");
-
- User u = getDummyUser();
- u = userDao.get(userDao.store(u));
-
- m.setOwner(u);
-
- return m;
- }
-
- }
|