コード例 #1
0
 /** Try to view it as a nutritionist that isn't designated */
 @Test
 public void testNonDesignatedNutritionistBounded() {
   action = new ViewFoodEntryAction(factory, 9000000071L);
   try {
     action.getBoundedDiary("02/02/2014", "02/02/2014", 1);
     fail("Not his designated nutritionist");
   } catch (ITrustException e) {
     assertEquals("You do not have permission to view the Food Diary!", e.getMessage());
   } catch (FormValidationException d) {
     fail(d.getMessage());
   }
 }
コード例 #2
0
 /** Ensure patients can't view the bounded food diary of other patients. */
 @Test
 public void testViewFoodDiaryOfOtherPatientBounded() {
   action = new ViewFoodEntryAction(factory, 333);
   try {
     action.getBoundedDiary("12/12/2014", "12/12/2014", 334);
     fail("You should not be able to view other patient's food diary.");
   } catch (ITrustException e) {
     assertEquals("You do not have permission to view the Food Diary!", e.getMessage());
   } catch (FormValidationException d) {
     fail("Not your food diary");
   }
 }
コード例 #3
0
 /** Test with evil factory */
 @Test
 public void testEvilFactoryGetBoundedDiary() {
   EvilDAOFactory evil = new EvilDAOFactory();
   action = new ViewFoodEntryAction(evil, 1);
   try {
     action.getBoundedDiary("", "", 1);
     fail("Working with evil factory");
   } catch (ITrustException d) {
     assertEquals("Error retrieving Food Diary", d.getMessage());
   } catch (FormValidationException e) {
     fail(e.getMessage());
   }
 }
コード例 #4
0
 /** Test bounded diary with bad dates */
 @Test
 public void testFoodDiaryBadDates() {
   action = new ViewFoodEntryAction(factory, 1);
   try {
     action.getBoundedDiary("", "", 1);
     fail("Bad dates");
   } catch (FormValidationException e) {
     assertEquals(
         "This form has not been validated correctly. "
             + "The following field are not properly "
             + "filled in: [Enter dates in MM/dd/yyyy]",
         e.getMessage());
   } catch (ITrustException d) {
     fail("Wanted bad dates");
   }
 }
コード例 #5
0
 /** Test start date after end date */
 @Test
 public void testStartAfterEnd() {
   action = new ViewFoodEntryAction(factory, 335);
   try {
     action.getBoundedDiary("12/12/2014", "12/10/2014", 335);
     fail("Start date after end date");
   } catch (ITrustException d) {
     fail("Why the error?");
   } catch (FormValidationException e) {
     assertEquals(
         "This form has not been validated correctly. "
             + "The following field are not properly filled in: "
             + "[Start date must be before end date!]",
         e.getMessage());
   }
 }
コード例 #6
0
  /** Test getting a bounded food diary */
  @Test
  public void testBoundedFoodDiary() {
    // aaron has multiple days
    action = new ViewFoodEntryAction(factory, 335);
    try {
      List<FoodEntryBean> beans = action.getBoundedDiary("04/13/2014", "04/13/2014", 335);
      assertEquals(1, beans.size());
      FoodEntryBean entry = beans.get(0);
      assertEquals("Snack", entry.getMealType().toString());
      assertEquals("Oreos", entry.getFood());
      assertEquals(53.0, entry.getServings(), .001);
      assertEquals(140.0, entry.getCalories(), .001);
      assertEquals(7.0, entry.getFatGrams(), .001);
      assertEquals(90.0, entry.getMilligramsSodium(), .001);
      assertEquals(21.0, entry.getCarbGrams(), .001);
      assertEquals(13.0, entry.getSugarGrams(), .001);
      assertEquals(1.0, entry.getFiberGrams(), .001);
      assertEquals(0.0, entry.getProteinGrams(), .001);

      // now get the totals
      List<FoodEntryBean> totals = action.getBoundedDiaryTotals("04/13/2014", "04/13/2014", 335);
      assertEquals(1, totals.size());
      FoodEntryBean total = totals.get(0);
      assertEquals(7420.0, total.getCalories(), .001);
      assertEquals(371.0, total.getFatGrams(), .001);
      assertEquals(4770.0, total.getMilligramsSodium(), .001);
      assertEquals(1113.0, total.getCarbGrams(), .001);
      assertEquals(53.0, total.getFiberGrams(), .001);
      assertEquals(689.0, total.getSugarGrams(), .001);
      assertEquals(0.0, total.getProteinGrams(), .001);
    } catch (ITrustException d) {
      fail("Why the error?");
    } catch (FormValidationException d) {
      fail("No errors in dates");
    }
  }