Exemplo n.º 1
0
  private RegistrationChildForm getExpectedForm(String caseId) {
    ChildCase expectedChildCase = new ChildCase();
    expectedChildCase.setCaseId(caseId);

    Flw expectedFlw = new Flw();
    expectedFlw.setFlwId("89fda0284e008d2e0c980fb13fa0e5bb");

    RegistrationChildForm expectedChildForm = new RegistrationChildForm();
    expectedChildForm.setChildCase(expectedChildCase);
    expectedChildForm.setFlw(expectedFlw);
    expectedChildForm.setDateModified(
        new DateTime(2013, 3, 3, 10, 38, 52, 804, DateTimeZone.forOffsetHoursMinutes(5, 30))
            .toDate());
    expectedChildForm.setChildName("suraj");
    expectedChildForm.setBirthStatus("healthy");
    expectedChildForm.setInstanceId("ff2eb090-03a9-4f23-afed-cf6012784c55");
    expectedChildForm.setTimeStart(
        new DateTime(2013, 3, 3, 10, 31, 51, 45, DateTimeZone.forOffsetHoursMinutes(5, 30))
            .toDate());
    expectedChildForm.setTimeEnd(
        new DateTime(2013, 3, 3, 10, 38, 52, 804, DateTimeZone.forOffsetHoursMinutes(5, 30))
            .toDate());

    return expectedChildForm;
  }
Exemplo n.º 2
0
  @Test
  public void
      shouldSaveChildFormByDeletingOlderFormIfFormWithSameInstanceIdAndCaseIdExistsAlready() {
    final String instanceId = "e34707f8-80c8-4198-bf99-c11c90ba5c98";
    final String caseId = "3e8998ce-b19f-4fa7-b1a1-721b6951e3cf";
    final Date oldFormModifiedDate = DateTime.parse("2012-07-10T12:02:59.923+05:30").toDate();

    ChildCase persistedChildCase = new ChildCase();
    persistedChildCase.setCaseId(caseId);

    final DeathChildForm persistedForm = new DeathChildForm();
    persistedForm.setInstanceId(instanceId);
    persistedForm.setChildCase(persistedChildCase);
    persistedForm.setDateModified(oldFormModifiedDate);
    persistedForm.setServerDateModified(oldFormModifiedDate);
    template.save(persistedForm);

    final String newFormModifiedOn = "2012-07-20T12:02:59.923+05:30";
    final Date newFormModifiedDate = DateTime.parse(newFormModifiedOn).toDate();
    final HashMap<String, String> deathChildFormValues =
        new HashMap<String, String>() {
          {
            put("caseId", caseId);
            put("dateModified", newFormModifiedOn);
            put("serverDateModified", newFormModifiedOn);
            put("userId", "89fda0284e008d2e0c980fb13fa0e5bb");
            put("close", "true");
            put("instanceId", instanceId);
            put("xmlns", "http://bihar.commcarehq.org/pregnancy/death");
          }
        };

    careService.processAndSaveForms(
        null,
        new ArrayList<Map<String, String>>() {
          {
            add(deathChildFormValues);
          }
        });

    List<DeathChildForm> deathChildForms = template.loadAll(DeathChildForm.class);
    assertEquals(1, deathChildForms.size());
    assertEquals(newFormModifiedDate, deathChildForms.get(0).getDateModified());
  }
Exemplo n.º 3
0
  @Test
  public void shouldUpdateEntityByExternalPrimaryKeyWhenExists() {
    String caseId = "94d5374f-290e-409f-bc57-86c2e4bcc43f";
    ChildCase existingChild = new ChildCase();
    existingChild.setCaseId(caseId);
    existingChild.setName("old Child name");
    template.save(existingChild);

    HashMap<String, String> updatedValues =
        new HashMap<String, String>() {
          {
            put("caseId", "94d5374f-290e-409f-bc57-86c2e4bcc43f");
            put("name", "new child name");
          }
        };

    careService.saveByExternalPrimaryKey(ChildCase.class, updatedValues);

    List<ChildCase> childCases = template.loadAll(ChildCase.class);
    Assert.assertEquals(1, childCases.size());

    ChildCase expectedChildCase = new ChildCase();
    expectedChildCase.setCaseId(caseId);
    expectedChildCase.setName("new child name");
    assertReflectionEqualsWithIgnore(
        expectedChildCase,
        childCases.get(0),
        new String[] {"id", "creationTime", "lastModifiedTime"});
  }