Esempio n. 1
0
  @Test
  public void shouldNotDeleteEarlierFormIfNewerMotherFormWithSameInstanceIdHasOldDate() {
    NewForm persistedForm = new NewForm();
    persistedForm.setInstanceId("e34707f8-80c8-4198-bf99-c11c90ba5c98");
    final Date oldFormModifiedDate = DateTime.parse("2012-07-20T12:02:59.923+05:30").toDate();
    persistedForm.setServerDateModified(oldFormModifiedDate);
    persistedForm.setDateModified(oldFormModifiedDate);
    template.save(persistedForm);

    final String newFormModifiedOn = "2012-07-10T12:02:59.923+05:30";

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

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

    List<NewForm> newFormsFromDb = template.loadAll(NewForm.class);
    assertEquals(1, newFormsFromDb.size());
    assertEquals(oldFormModifiedDate, newFormsFromDb.get(0).getDateModified());
  }
Esempio n. 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());
  }
Esempio n. 3
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(
       "&#2327;&#2366;&#2351;&#2340;&#2381;&#2352;&#2368; &#2342;&#2375;&#2357;&#2368;");
   expectedForm.setHusbandName(
       "&#2342;&#2367;&#2344;&#2375;&#2358; &#2350;&#2369;&#2326;&#2367;&#2351;&#2366;");
   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;
 }