MealDaoTest.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* ===================================================================
  2. * MealDaoTest.java
  3. *
  4. * Created Sep 16, 2004 4:30:05 PM
  5. *
  6. * Copyright (c) 2004 Matt Magoffin (spamsqr@msqr.us)
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  21. * 02111-1307 USA
  22. * ===================================================================
  23. * $Id: MealDaoTest.java 39 2009-05-06 03:30:47Z msqr $
  24. * ===================================================================
  25. */
  26. package magoffin.matt.ieat.dao;
  27. import magoffin.matt.ieat.domain.Meal;
  28. import magoffin.matt.ieat.domain.MealRecipe;
  29. import magoffin.matt.ieat.domain.Recipe;
  30. import magoffin.matt.ieat.domain.User;
  31. /**
  32. * Test case for the RecipceDao.
  33. *
  34. * <p>These tests can only work when the test data is loaded in the database!</p>
  35. *
  36. * @author Matt Magoffin (spamsqr@msqr.us)
  37. * @version $Revision: 39 $ $Date: 2009-05-06 15:30:47 +1200 (Wed, 06 May 2009) $
  38. */
  39. public class MealDaoTest extends AbstractDaoTest {
  40. /** The MealDao to test. */
  41. protected MealDao mealDao;
  42. /** The RecipeDao to test with. */
  43. protected RecipeDao recipeDao;
  44. /** The UserDao to test with. */
  45. protected UserDao userDao;
  46. /**
  47. * Test able to create a meal.
  48. */
  49. public void testCreateMealWithoutRecipies() {
  50. Meal m = getDummyMeal();
  51. Meal storedMeal = mealDao.get(mealDao.store(m));
  52. assertNotNull("The persisted meal should have a mealId value",storedMeal.getMealId());
  53. }
  54. /**
  55. * Test able to create a meal with recipes.
  56. */
  57. @SuppressWarnings("unchecked")
  58. public void testCreateMealWithRecipies() {
  59. Meal m = null;
  60. Recipe r1 = null;
  61. Recipe r2 = null;
  62. m = getDummyMeal();
  63. r1 = getDummyRecipe();
  64. r2 = getDummyRecipe();
  65. r1 = recipeDao.get(recipeDao.store(r1));
  66. r2 = recipeDao.get(recipeDao.store(r2));
  67. MealRecipe mr1 = domainObjectFactory.getMealRecipeInstance();
  68. mr1.setCourse(getTestCourse());
  69. mr1.setQuantity(1.0f);
  70. mr1.setRecipe(r1);
  71. MealRecipe mr2 = domainObjectFactory.getMealRecipeInstance();
  72. mr2.setCourse(getTestCourse());
  73. mr2.setQuantity(2.0f);
  74. mr2.setRecipe(r2);
  75. m.getRecipe().add(mr1);
  76. m.getRecipe().add(mr2);
  77. Meal storedMeal = mealDao.get(mealDao.store(m));
  78. assertNotNull("The persisted meal should have a mealId value",storedMeal.getMealId());
  79. assertTrue("The persisted meal should have 2 recipes in it", storedMeal.getRecipe().size() == 2);
  80. }
  81. /**
  82. * Returns a dummy meal, with a newly created dummy user as the owner.
  83. * @return meal
  84. */
  85. private Meal getDummyMeal() {
  86. Meal m = domainObjectFactory.getMealInstance();
  87. m.setName("MealDaoTest Meal");
  88. User u = getDummyUser();
  89. u = userDao.get(userDao.store(u));
  90. m.setOwner(u);
  91. return m;
  92. }
  93. }