RecipeSearchBizTest.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* ===================================================================
  2. * RecipeSearchBizTest.java
  3. *
  4. * Created Sep 15, 2004 5:07:32 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: RecipeSearchBizTest.java 30 2009-05-04 01:53:34Z msqr $
  24. * ===================================================================
  25. */
  26. package magoffin.matt.ieat.biz.test;
  27. import java.util.List;
  28. import magoffin.matt.ieat.biz.RecipeSearchBiz;
  29. import magoffin.matt.ieat.domain.Recipe;
  30. import magoffin.matt.ieat.domain.UiSearchResults;
  31. import magoffin.matt.ieat.test.AbstractSpringEnabledTest;
  32. import magoffin.matt.ieat.util.IndexCriteriaImpl;
  33. import magoffin.matt.ieat.util.IngredientCriteriaImpl;
  34. /**
  35. * Test case for the RecipceSearchBiz.
  36. *
  37. * <p>These tests can only work when the test data is loaded in the database!</p>
  38. *
  39. * @author Matt Magoffin (spamsqr@msqr.us)
  40. * @version $Revision: 30 $ $Date: 2009-05-04 13:53:34 +1200 (Mon, 04 May 2009) $
  41. */
  42. public class RecipeSearchBizTest extends AbstractSpringEnabledTest {
  43. /**
  44. * Test that able to get index list for 't'.
  45. */
  46. public void testGetRecipesForIndexLowercase() {
  47. RecipeSearchBiz.IndexCriteria criteria = new IndexCriteriaImpl("t",0,0);
  48. testRecipeIndexSearchResults(criteria); // get rows with 't'
  49. }
  50. /**
  51. * Test that able to get index list for 'T'.
  52. */
  53. public void testGetRecipesForIndexUppercase() {
  54. RecipeSearchBiz.IndexCriteria criteria = new IndexCriteriaImpl("T",0,0);
  55. testRecipeIndexSearchResults(criteria); // get rows with capital 'T'
  56. }
  57. /**
  58. * Test that index lists for 't' and 'T' are the same.
  59. */
  60. public void testGetRecipesForIndexUppercaseSameAsLowercase() {
  61. RecipeSearchBiz.IndexCriteria criteria1 = new IndexCriteriaImpl("t",0,0);
  62. RecipeSearchBiz.IndexCriteria criteria2 = new IndexCriteriaImpl("T",0,0);
  63. UiSearchResults lowerResults = testRecipeIndexSearchResults(criteria1);
  64. UiSearchResults upperResults = testRecipeIndexSearchResults(criteria2);
  65. assertTrue("recipe index search results for lower/upper case should be the same size",
  66. lowerResults.getRecipe().size() == upperResults.getRecipe().size());
  67. // verify all names the same...
  68. for ( int i = 0; i < lowerResults.getRecipe().size(); i++ ) {
  69. Recipe r1 = (Recipe)lowerResults.getRecipe().get(i);
  70. Recipe r2 = (Recipe)upperResults.getRecipe().get(i);
  71. assertEquals(r1.getName(),r2.getName());
  72. }
  73. }
  74. /**
  75. * Test searching for "similar" ingredients.
  76. */
  77. public void testSearchForIngredientsSimilaryNamed() {
  78. IngredientCriteriaImpl criteria = new IngredientCriteriaImpl("chip");
  79. RecipeSearchBiz searchBiz = getRecipeSearchBiz();
  80. UiSearchResults results = searchBiz.findIngredientsSimilarlyNamed(criteria);
  81. assertTrue("Search results for ingredients similarly named should never be null",results != null);
  82. }
  83. @SuppressWarnings("unchecked")
  84. private UiSearchResults testRecipeIndexSearchResults(RecipeSearchBiz.IndexCriteria criteria) {
  85. RecipeSearchBiz searchBiz = getRecipeSearchBiz();
  86. UiSearchResults results = searchBiz.findRecipesForIndex(criteria);
  87. assertNotNull("recipe index search results should never be null", results);
  88. List recipes = results.getRecipe();
  89. assertNotNull("recipe index search results recipe list should never be null",recipes);
  90. assertTrue("recipe index search results list should have at least 1 element", recipes.size() > 0);
  91. for ( int i = 0; i < recipes.size(); i++ ) {
  92. Recipe r = (Recipe)recipes.get(i);
  93. assertNotNull("recipe index search result " +i +" name should not be null",r.getName());
  94. assertTrue("recipe index search result " +i +" name should start with "
  95. +criteria.getDisplaySection() +" (ignoring case)",
  96. r.getName().toLowerCase().startsWith(criteria.getDisplaySection().toLowerCase()));
  97. }
  98. return results;
  99. }
  100. }