| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- /* ===================================================================
- * RecipeDaoTest.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: RecipeDaoTest.java 59 2009-05-11 09:16:24Z msqr $
- * ===================================================================
- */
- package magoffin.matt.ieat.dao;
- import java.util.Date;
- import magoffin.matt.ieat.dao.RecipeDao;
- import magoffin.matt.ieat.dao.RecipeDao.RecipeIndexCallbackData;
- import magoffin.matt.ieat.domain.Recipe;
- import org.apache.log4j.Logger;
- /**
- * 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: 59 $ $Date: 2009-05-11 21:16:24 +1200 (Mon, 11 May 2009) $
- */
- public class RecipeDaoTest extends AbstractDaoTest {
-
- private static final Logger LOG = Logger.getLogger(RecipeDaoTest.class);
-
- /** The RecipeDao to test with. */
- protected RecipeDao recipeDao;
-
- /**
- * Test able to create a Recipe.
- */
- public void testCreateRecipe() {
- Recipe r = getDummyRecipe();
- Recipe storedRecipe = null;
- storedRecipe = recipeDao.get(recipeDao.store(r));
- assertNotNull("The persisted recipe should have a recipeId value",storedRecipe.getRecipeId());
- }
- /**
- * Test able to update a recipe.
- */
- public void testUpdateRecipe() {
- Recipe r = getDummyRecipe();
- Recipe updatedRecipe = null;
- r = recipeDao.get(recipeDao.store(r));
- String newName = "My Test Recipe " +new Date();
- r.setName(newName);
- updatedRecipe = recipeDao.get(recipeDao.store(r));
-
- // first verify recipe name is same as newName
- assertEquals(newName,updatedRecipe.getName());
-
- // re-load the recipe, just to be sure
- updatedRecipe = recipeDao.get(r.getRecipeId());
- assertEquals(newName,updatedRecipe.getName());
- }
-
- /**
- * Test able to index recipes.
- */
- public void testIndex() {
- recipeDao.index(new RecipeDao.RecipeIndexCallback() {
- public void handle(RecipeIndexCallbackData data) {
- if ( LOG.isDebugEnabled() ) {
- LOG.debug("Got recipe index callback data: " +data);
- }
- assertNotNull("Recipe callback data should not be null", data);
- assertTrue("Recipe callback data 'name' should not be null", data.getName() != null);
- assertTrue("Recipe callback data 'recipeId' should not be null", data.getRecipeId() != null);
- }
- public void finish() {
- if ( LOG.isDebugEnabled() ) {
- LOG.debug("Recipe indexing finished.");
- }
- }
- });
- }
-
- }
|