Example #1
0
 private NewForm expectedForm(MotherCase motherCase, Flw flw) {
   NewForm expectedForm = new NewForm();
   expectedForm.setDateModified(
       new DateTime(2012, 7, 21, 12, 2, 59, 923, DateTimeZone.forOffsetHoursMinutes(5, 30))
           .toDate());
   expectedForm.setFullName(
       "गायत्री देवी");
   expectedForm.setHusbandName(
       "दिनेश मुखिया");
   expectedForm.setHhNumber(165);
   expectedForm.setFamilyNumber(5);
   expectedForm.setDobKnown("no");
   expectedForm.setCaste("other");
   expectedForm.setAgeCalc(null);
   expectedForm.setInstanceId("e34707f8-80c8-4198-bf99-c11c90ba5c98");
   expectedForm.setMotherCase(motherCase);
   expectedForm.setFlw(flw);
   expectedForm.setTimeStart(
       new DateTime(2012, 7, 21, 11, 59, 31, 76, DateTimeZone.forOffsetHoursMinutes(5, 30))
           .toDate());
   expectedForm.setTimeEnd(
       new DateTime(2012, 7, 21, 12, 2, 59, 923, DateTimeZone.forOffsetHoursMinutes(5, 30))
           .toDate());
   return expectedForm;
 }
Example #2
0
  @Test
  public void shouldDeleteEarlierFormIfBothNewerAndOlderMotherFormWithSameInstanceIdHasNullDate() {
    NewForm persistedForm = new NewForm();
    persistedForm.setInstanceId("e34707f8-80c8-4198-bf99-c11c90ba5c98");

    persistedForm.setCaste("OldCaste");
    persistedForm.setServerDateModified(null);
    template.save(persistedForm);

    final String newCaste = "NewCaste";

    Map<String, String> motherFormValues =
        new HashMap<String, String>() {
          {
            put("caseId", "94d5374f-290e-409f-bc57-86c2e4bcc43f");
            put("serverDateModified", null);
            put("userId", "89fda0284e008d2e0c980fb13fa0e5bb");
            put("xmlns", "http://bihar.commcarehq.org/pregnancy/new");
            put("instanceId", "e34707f8-80c8-4198-bf99-c11c90ba5c98");
            put("caste", newCaste);
          }
        };

    careService.processAndSaveForms(motherFormValues, new ArrayList<Map<String, String>>());

    List<NewForm> newFormsFromDb = template.loadAll(NewForm.class);
    assertEquals(1, newFormsFromDb.size());
    assertNull(newFormsFromDb.get(0).getDateModified());
    assertEquals(newCaste, newFormsFromDb.get(0).getCaste());
  }