Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save djazayeri/e13403f3694a2ae6a1ab to your computer and use it in GitHub Desktop.
Save djazayeri/e13403f3694a2ae6a1ab to your computer and use it in GitHub Desktop.
additional test that shows an exception being thrown by controller
@Test
public void testErrorInPatientIdentifier() throws Exception {
FragmentModel model = new FragmentModel();
Patient patient = new Patient();
String resourcePath = "emr:htmlforms/patientIdentifierTest.xml";
when(resourceFactory.getResourceAsString("emr", "htmlforms/patientIdentifierTest.xml")).thenReturn(PATIENT_IDENTIFIER_TEST_FORM_DEFINITION);
FragmentConfiguration config = new FragmentConfiguration();
config.put("patient", patient);
config.put("definitionUiResource", resourcePath);
controller.controller(config, sessionContext, ui, htmlFormEntryService, adtService, formService, resourceFactory, featureToggles, patient, null, null, null, null, resourcePath, null, null, null, null, true, model, null);
// now the form is persisted in the DB
FormEntrySession command = (FormEntrySession) model.getAttribute("command");
String html = command.getHtmlToDisplay();
System.out.println(html);
HtmlForm hf = htmlFormEntryService.getHtmlFormByForm(formService.getFormByUuid("form-uuid"));
MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("w1", "invalid-identifier");
request.addParameter("w3", "1"); // value for the hidden widget for identifier type
request.addParameter("w4", "2016-03-24");
request.addParameter("w6", "2"); // location = Xanadu
request.addParameter("w8", "502"); // provider = Hippocrates
SimpleObject result = controller.submit(sessionContext, patient, hf, null, null, null, null, adtService, featureToggles, ui, request);
System.out.println(result.toJson());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment