コード例 #1
0
  @Test
  public void pregnancyVisitWithReferralWithMissingFieldShouldNotPublishEvent() {
    String formId = "formId";
    String referralCaseId = "referralCaseId";
    String motherCaseId = "motherCaseId";
    CommcareForm form = CommcareForm("Pregnancy Visit");
    form.getForm().setElementName("form");

    AddSingleValueFormField(form, Commcare.CREATE_REFERRAL, "yes");
    AddSingleValueFormField(form, Commcare.LAST_VISIT, "2013-01-03");

    FormValueElement aCase = AddSingleValueFormField(form, Commcare.CASE, "case");
    aCase.addAttribute(Commcare.CASE_ID, motherCaseId);

    CaseInfo referralCase = new CaseInfo();
    referralCase.setCaseType("referral");

    when(commcareCaseService.getCaseByCaseId(referralCaseId)).thenReturn(referralCase);

    CaseInfo motherCase = new CaseInfo();
    motherCase.setCaseType("mother");

    when(commcareCaseService.getCaseByCaseId(motherCaseId)).thenReturn(motherCase);

    when(commcareFormService.retrieveForm(formId)).thenReturn(form);

    List<String> list = Arrays.asList(motherCaseId, referralCaseId);
    commCareFormStubListener.handle(CommcareFormStubEvent(formId, list));

    verify(eventRelay).sendEventMessage(any(MotechEvent.class));
  }
コード例 #2
0
  @Test
  public void shouldNotPublishEventIfFormNotFound() {
    when(commcareFormService.retrieveForm("formId")).thenReturn(null);

    commCareFormStubListener.handle(CommcareFormStubEvent("formId"));

    verify(eventRelay, never()).sendEventMessage(null);
  }
コード例 #3
0
  @Test
  public void shouldNotPublishEventFromFormWeDontNeed() {
    String formId = "formId";
    CommcareForm form = CommcareForm("A Form We Don't Care About");

    when(commcareFormService.retrieveForm(formId)).thenReturn(form);

    commCareFormStubListener.handle(CommcareFormStubEvent(formId));

    verify(eventRelay, never()).sendEventMessage(null);
  }
コード例 #4
0
  @Test
  public void postPartumVisitReferralShouldPublish() {
    String formId = "formId";
    String referralCaseId = "referralCaseId";
    String motherCaseId = "motherCaseId";
    CommcareForm form = CommcareForm("Post Partum Visit");
    form.getForm().setElementName("form");

    AddSingleValueFormField(form, Commcare.MOTHER_ALIVE, "yes");
    AddSingleValueFormField(form, Commcare.DELIVERED, "yes");
    AddSingleValueFormField(form, Commcare.CREATE_REFERRAL, "yes");
    AddSingleValueFormField(form, Commcare.REFERRAL_ID, "referralId");
    AddSingleValueFormField(form, Commcare.LAST_VISIT, "2013-01-03");

    FormValueElement aCase = AddSingleValueFormField(form, Commcare.CASE, "case");
    aCase.addAttribute(Commcare.CASE_ID, motherCaseId);

    FormValueElement postPartumVisit = new FormValueElement();
    postPartumVisit.setElementName(Commcare.POST_PARTUM_VISIT);

    AddSubelementValueFormField(postPartumVisit, Commcare.DATE_OF_BIRTH, "2013-01-03");
    AddSubelementValueFormField(postPartumVisit, Commcare.ATTENDED_PNC, "yes");
    AddSubelementValueFormField(postPartumVisit, Commcare.PLACE_OF_BIRTH, "home");

    form.getForm().addFormValueElement(Commcare.POST_PARTUM_VISIT, postPartumVisit);

    CaseInfo referralCase = new CaseInfo();
    referralCase.setCaseType("referral");

    when(commcareCaseService.getCaseByCaseId(referralCaseId)).thenReturn(referralCase);

    CaseInfo motherCase = new CaseInfo();
    motherCase.setCaseType("mother");

    when(commcareCaseService.getCaseByCaseId(motherCaseId)).thenReturn(motherCase);

    when(commcareFormService.retrieveForm(formId)).thenReturn(form);

    List<String> list = Arrays.asList(motherCaseId, referralCaseId);
    commCareFormStubListener.handle(CommcareFormStubEvent(formId, list));

    verify(eventRelay).sendEventMessage(any(MotechEvent.class));
  }
コード例 #5
0
  @Test
  public void pregnancyVisitWithoutReferralShouldPublishNoEvent() {
    String formId = "formId";
    CommcareForm form = CommcareForm("Pregnancy Visit");
    form.getForm().setElementName("form");

    AddSingleValueFormField(form, Commcare.CREATE_REFERRAL, "no");
    AddSingleValueFormField(form, Commcare.REFERRAL_ID, null);
    AddSingleValueFormField(form, Commcare.LAST_VISIT, "2013-01-03");

    FormValueElement aCase = AddSingleValueFormField(form, Commcare.CASE, "case");
    aCase.addAttribute(Commcare.CASE_ID, "caseId");

    when(commcareFormService.retrieveForm(formId)).thenReturn(form);

    commCareFormStubListener.handle(CommcareFormStubEvent(formId));

    verify(eventRelay, never()).sendEventMessage(any(MotechEvent.class));
  }