@Before public void setupContext() { if (context == null) { context = new FormEntryContext(Mode.ENTER); } }
@Before public void setUp() { context = new FormEntryContext(FormEntryContext.Mode.ENTER); }
context = new FormEntryContext(mode); context.setDefaultLocation(defaultLocation); context.setHttpSession(httpSession);
/** * @see {@link HtmlFormEntryUtil#getLocation(String, FormEntryContext)} * @verifies not fail if trying to find a location by session attribute and we have no session */ @Test public void getLocation_shouldNotFailIfTryingToFindALocationBySessionAttriubteAndWeHaveNoSession() { FormEntryContext formEntryContext = new FormEntryContext(FormEntryContext.Mode.ENTER); Assert.assertNull(HtmlFormEntryUtil.getLocation("SessionAttribute:someSessionAttribute", formEntryContext)); }
@Test public void testPatientIdentifierValidation() throws Exception { // <patient field="identifier" identifierTypeId="1" /> FormEntryContext context = new FormEntryContext(FormEntryContext.Mode.ENTER); Map<String, String> attributes = new HashMap<String, String>(); attributes.put("field", "identifier"); attributes.put("identifierTypeId", "1"); PatientDetailSubmissionElement element = new PatientDetailSubmissionElement(context, attributes); String html = element.generateHtml(context); MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter("w1", "invalid-identifier"); request.addParameter("w3", "1"); // this is the hidden input for identifier type Collection<FormSubmissionError> errors = element.validateSubmission(context, request); assertThat(errors.size(), is(1)); assertThat(errors.iterator().next().getId(), is("w2")); // the error widget for w1 assertThat(errors.iterator().next().getError(), is("PatientIdentifier.error.unallowedIdentifier")); request.setParameter("w1", "1-1"); errors = element.validateSubmission(context, request); assertThat(errors.size(), is(1)); assertThat(errors.iterator().next().getId(), is("w2")); // the error widget for w1 assertThat(errors.iterator().next().getError(), is("PatientIdentifier.error.checkDigitWithParameter")); request.setParameter("w1", "1-8"); // TODO make sure this is a valid identifier with check digit errors = element.validateSubmission(context, request); assertThat(errors.size(), is(0)); }
/** * @see {@link HtmlFormEntryUtil#getLocation(String, FormEntryContext)} */ @Test @Verifies(value = "should find a location by session attribute", method = "getLocation(String,FormEntrySession)") public void getLocation_shouldFindALocationBySessionAttribute() throws Exception { String attrName = "emr.sessionLocation"; MockHttpSession httpSession = new MockHttpSession(); httpSession.setAttribute(attrName, "2"); FormEntryContext formEntryContext = new FormEntryContext(FormEntryContext.Mode.ENTER); formEntryContext.setHttpSession(httpSession); Assert.assertEquals("2", HtmlFormEntryUtil.getLocation("SessionAttribute:" + attrName, formEntryContext).getId().toString()); }