RecipeDaoTest.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* ===================================================================
  2. * RecipeDaoTest.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: RecipeDaoTest.java 59 2009-05-11 09:16:24Z msqr $
  24. * ===================================================================
  25. */
  26. package magoffin.matt.ieat.dao;
  27. import java.util.Date;
  28. import magoffin.matt.ieat.dao.RecipeDao;
  29. import magoffin.matt.ieat.dao.RecipeDao.RecipeIndexCallbackData;
  30. import magoffin.matt.ieat.domain.Recipe;
  31. import org.apache.log4j.Logger;
  32. /**
  33. * Test case for the RecipceDao.
  34. *
  35. * <p>These tests can only work when the test data is loaded in the database!</p>
  36. *
  37. * @author Matt Magoffin (spamsqr@msqr.us)
  38. * @version $Revision: 59 $ $Date: 2009-05-11 21:16:24 +1200 (Mon, 11 May 2009) $
  39. */
  40. public class RecipeDaoTest extends AbstractDaoTest {
  41. private static final Logger LOG = Logger.getLogger(RecipeDaoTest.class);
  42. /** The RecipeDao to test with. */
  43. protected RecipeDao recipeDao;
  44. /**
  45. * Test able to create a Recipe.
  46. */
  47. public void testCreateRecipe() {
  48. Recipe r = getDummyRecipe();
  49. Recipe storedRecipe = null;
  50. storedRecipe = recipeDao.get(recipeDao.store(r));
  51. assertNotNull("The persisted recipe should have a recipeId value",storedRecipe.getRecipeId());
  52. }
  53. /**
  54. * Test able to update a recipe.
  55. */
  56. public void testUpdateRecipe() {
  57. Recipe r = getDummyRecipe();
  58. Recipe updatedRecipe = null;
  59. r = recipeDao.get(recipeDao.store(r));
  60. String newName = "My Test Recipe " +new Date();
  61. r.setName(newName);
  62. updatedRecipe = recipeDao.get(recipeDao.store(r));
  63. // first verify recipe name is same as newName
  64. assertEquals(newName,updatedRecipe.getName());
  65. // re-load the recipe, just to be sure
  66. updatedRecipe = recipeDao.get(r.getRecipeId());
  67. assertEquals(newName,updatedRecipe.getName());
  68. }
  69. /**
  70. * Test able to index recipes.
  71. */
  72. public void testIndex() {
  73. recipeDao.index(new RecipeDao.RecipeIndexCallback() {
  74. public void handle(RecipeIndexCallbackData data) {
  75. if ( LOG.isDebugEnabled() ) {
  76. LOG.debug("Got recipe index callback data: " +data);
  77. }
  78. assertNotNull("Recipe callback data should not be null", data);
  79. assertTrue("Recipe callback data 'name' should not be null", data.getName() != null);
  80. assertTrue("Recipe callback data 'recipeId' should not be null", data.getRecipeId() != null);
  81. }
  82. public void finish() {
  83. if ( LOG.isDebugEnabled() ) {
  84. LOG.debug("Recipe indexing finished.");
  85. }
  86. }
  87. });
  88. }
  89. }