Example usage for org.springframework.mock.web MockHttpServletRequest addParameter

List of usage examples for org.springframework.mock.web MockHttpServletRequest addParameter

Introduction

In this page you can find the example usage for org.springframework.mock.web MockHttpServletRequest addParameter.

Prototype

public void addParameter(String name, String... values) 

Source Link

Document

Add an array of values for the specified HTTP parameter.

Usage

From source file:com.github.woonsan.katharsis.servlet.KatharsisServletTest.java

@Test
public void testUnacceptableRequestContentType() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest(servletContext);
    request.setMethod("GET");
    request.setContextPath("");
    request.setServletPath("/api");
    request.setPathInfo("/tasks");
    request.setRequestURI("/api/tasks");
    request.setContentType(JsonApiMediaType.APPLICATION_JSON_API);
    request.addHeader("Accept", "application/xml");
    request.addParameter("filter", "{\"name\":\"John\"}");

    MockHttpServletResponse response = new MockHttpServletResponse();

    katharsisServlet.service(request, response);

    assertEquals(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, response.getStatus());
    String responseContent = response.getContentAsString();
    assertTrue(responseContent == null || "".equals(responseContent.trim()));
}

From source file:org.openmrs.module.htmlformentryui.fragment.controller.htmlform.EnterHtmlFormFragmentControllerComponentTest.java

@Test
public void testEditingHtmlFormDefinedInUiResourceShouldChangeTimeOfEncounterDateIfNewDateHasTimeComponentEvenIfNotDifferentFromCurrentDate()
        throws Exception {
    // first, ensure the form is created and persisted, by calling the controller display method
    testDefiningAnHtmlFormInUiResource();
    HtmlForm hf = htmlFormEntryService.getHtmlFormByForm(formService.getFormByUuid("form-uuid"));

    // make "Hippocrates" a provider
    Provider provider = new Provider();
    provider.setPerson(personService.getPerson(502));
    providerService.saveProvider(provider);

    Patient patient = patientService.getPatient(8);
    assertThat(encounterService.getEncountersByPatient(patient).size(), is(0));

    Date initialEncounterDate = new DateTime(2012, 1, 20, 10, 10, 10, 0).toDate();
    String dateString = new SimpleDateFormat("yyyy-MM-dd").format(initialEncounterDate);

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter("w2", "70"); // weight in kg
    request.addParameter("w5", dateString); // date
    request.addParameter("w3hours", "10");
    request.addParameter("w3minutes", "10");
    request.addParameter("w3seconds", "10");
    request.addParameter("w7", "2"); // location = Xanadu
    request.addParameter("w9", "502"); // provider = Hippocrates

    SimpleObject result = controller.submit(sessionContext, patient, hf, null, null, false, null, adtService,
            featureToggles, ui, request);
    assertThat((Boolean) result.get("success"), is(Boolean.TRUE));
    assertThat(encounterService.getEncountersByPatient(patient).size(), is(1));
    Encounter created = encounterService.getEncountersByPatient(patient).get(0);

    Date updatedEncounterDate = new DateTime(2012, 1, 20, 20, 20, 20, 0).toDate();
    String updatedDateString = new SimpleDateFormat("yyyy-MM-dd").format(updatedEncounterDate);

    MockHttpServletRequest editRequest = new MockHttpServletRequest();
    editRequest.addParameter("w2", "70"); // weight in kg
    editRequest.addParameter("w5", updatedDateString); // date
    editRequest.addParameter("w3hours", "20"); /// note that we are zeroing out the hour, minute and day component
    editRequest.addParameter("w3minutes", "20");
    editRequest.addParameter("w3seconds", "20");
    editRequest.addParameter("w7", "2"); // location = Xanadu
    editRequest.addParameter("w9", "502"); // provider = Hippocrates

    result = controller.submit(sessionContext, patient, hf, created, null, false, null, adtService,
            featureToggles, ui, editRequest);
    assertThat((Boolean) result.get("success"), is(Boolean.TRUE));
    assertThat(encounterService.getEncountersByPatient(patient).size(), is(1));

    // this the date we input has an updated time component, we want to have updated the encounter date
    assertThat(created.getEncounterDatetime(), is(updatedEncounterDate));

}

From source file:org.openmrs.module.htmlformentryui.fragment.controller.htmlform.EnterHtmlFormFragmentControllerComponentTest.java

@Test
public void testEditingHtmlFormDefinedInUiResourceShouldChangeTimeOfEncounterDateIfNewDateDifferentFromOldDate()
        throws Exception {
    // first, ensure the form is created and persisted, by calling the controller display method
    testDefiningAnHtmlFormInUiResource();
    HtmlForm hf = htmlFormEntryService.getHtmlFormByForm(formService.getFormByUuid("form-uuid"));

    // make "Hippocrates" a provider
    Provider provider = new Provider();
    provider.setPerson(personService.getPerson(502));
    providerService.saveProvider(provider);

    Patient patient = patientService.getPatient(8);
    assertThat(encounterService.getEncountersByPatient(patient).size(), is(0));

    Date initialEncounterDate = new DateTime(2012, 1, 20, 10, 10, 10, 0).toDate();
    String dateString = new SimpleDateFormat("yyyy-MM-dd").format(initialEncounterDate);

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter("w2", "70"); // weight in kg
    request.addParameter("w5", dateString); // date
    request.addParameter("w3hours", "10");
    request.addParameter("w3minutes", "10");
    request.addParameter("w3seconds", "10");
    request.addParameter("w7", "2"); // location = Xanadu
    request.addParameter("w9", "502"); // provider = Hippocrates

    SimpleObject result = controller.submit(sessionContext, patient, hf, null, null, false, null, adtService,
            featureToggles, ui, request);
    assertThat((Boolean) result.get("success"), is(Boolean.TRUE));
    assertThat(encounterService.getEncountersByPatient(patient).size(), is(1));
    Encounter created = encounterService.getEncountersByPatient(patient).get(0);

    Date updatedEncounterDate = new DateTime(2012, 1, 22, 0, 0, 0, 0).toDate();
    String updatedDateString = new SimpleDateFormat("yyyy-MM-dd").format(updatedEncounterDate);

    MockHttpServletRequest editRequest = new MockHttpServletRequest();
    editRequest.addParameter("w2", "70"); // weight in kg
    editRequest.addParameter("w5", updatedDateString); // date
    editRequest.addParameter("w3hours", "0"); /// note that we are zeroing out the hour, minute and day component
    editRequest.addParameter("w3minutes", "0");
    editRequest.addParameter("w3seconds", "0");
    editRequest.addParameter("w7", "2"); // location = Xanadu
    editRequest.addParameter("w9", "502"); // provider = Hippocrates

    result = controller.submit(sessionContext, patient, hf, created, null, false, null, adtService,
            featureToggles, ui, editRequest);
    assertThat((Boolean) result.get("success"), is(Boolean.TRUE));
    assertThat(encounterService.getEncountersByPatient(patient).size(), is(1));

    // this the date we input has an updated time component, we want to have updated the encounter date
    assertThat(created.getEncounterDatetime(), is(updatedEncounterDate));

}

From source file:com.github.woonsan.katharsis.servlet.KatharsisFilterTest.java

@Test
public void onSimpleResourceGetShouldReturnOneResource() throws Exception {
    MockFilterChain filterChain = new MockFilterChain();

    MockHttpServletRequest request = new MockHttpServletRequest(servletContext);
    request.setMethod("GET");
    request.setContextPath("");
    request.setServletPath(null);//from   w w w .  j  a  v a2s  .c o m
    request.setPathInfo(null);
    request.setRequestURI("/api/tasks/1");
    request.setContentType(JsonApiMediaType.APPLICATION_JSON_API);
    request.addHeader("Accept", "*/*");
    request.addParameter("filter", "");

    MockHttpServletResponse response = new MockHttpServletResponse();

    katharsisFilter.doFilter(request, response, filterChain);

    String responseContent = response.getContentAsString();

    log.debug("responseContent: {}", responseContent);
    assertNotNull(responseContent);

    assertJsonPartEquals("tasks", responseContent, "data.type");
    assertJsonPartEquals("\"1\"", responseContent, "data.id");
    assertJsonPartEquals(SOME_TASK_ATTRIBUTES, responseContent, "data.attributes");
    assertJsonPartEquals(FIRST_TASK_LINKS, responseContent, "data.links");
    assertJsonPartEquals(PROJECT1_RELATIONSHIP_LINKS, responseContent, "data.relationships.project.links");
    assertJsonPartEquals("[]", responseContent, "included");
}

From source file:org.openmrs.module.radiology.web.controller.RadiologyOrderFormControllerTest.java

/**
 * @see RadiologyOrderFormController#postDiscontinueRadiologyOrder(HttpServletRequest,
 *      HttpServletResponse, Order, String, Date)
 *//*from   w w w. j  a  v  a  2 s.  co  m*/
@Test
@Verifies(value = "should discontinue non discontinued order and redirect to discontinuation order", method = "postDiscontinueRadiologyOrder(HttpServletRequest, HttpServletResponse, Order, String, Date)")
public void postDiscontinueRadiologyOrder_shouldDiscontinueNonDiscontinuedOrderAndRedirectToDiscontinuationOrder()
        throws Exception {
    //given
    RadiologyOrder mockRadiologyOrderToDiscontinue = RadiologyTestData.getMockRadiologyOrder1();
    mockRadiologyOrderToDiscontinue.getStudy().setMwlStatus(MwlStatus.DISCONTINUE_OK);
    String discontinueReason = "Wrong Procedure";
    Date discontinueDate = new GregorianCalendar(2015, Calendar.JANUARY, 01).getTime();

    Order mockDiscontinuationOrder = new Order();
    mockDiscontinuationOrder.setOrderId(2);
    mockDiscontinuationOrder.setAction(Order.Action.DISCONTINUE);
    mockDiscontinuationOrder.setOrderer(mockRadiologyOrderToDiscontinue.getOrderer());
    mockDiscontinuationOrder.setOrderReasonNonCoded(discontinueReason);
    mockDiscontinuationOrder.setDateActivated(discontinueDate);
    mockDiscontinuationOrder.setPreviousOrder(mockRadiologyOrderToDiscontinue);

    MockHttpServletRequest mockRequest = new MockHttpServletRequest();
    mockRequest.addParameter("discontinueOrder", "discontinueOrder");
    MockHttpSession mockSession = new MockHttpSession();
    mockRequest.setSession(mockSession);

    when(radiologyService.getRadiologyOrderByOrderId(mockRadiologyOrderToDiscontinue.getOrderId()))
            .thenReturn(mockRadiologyOrderToDiscontinue);
    when(radiologyService.discontinueRadiologyOrder(mockRadiologyOrderToDiscontinue,
            mockDiscontinuationOrder.getOrderer(), mockDiscontinuationOrder.getDateActivated(),
            mockDiscontinuationOrder.getOrderReasonNonCoded())).thenReturn(mockDiscontinuationOrder);

    assertThat(mockRadiologyOrderToDiscontinue.getAction(), is(Order.Action.NEW));
    ModelAndView modelAndView = radiologyOrderFormController.postDiscontinueRadiologyOrder(mockRequest, null,
            mockRadiologyOrderToDiscontinue, mockDiscontinuationOrder);

    assertNotNull(modelAndView);
    assertThat(modelAndView.getViewName(), is(
            "redirect:/module/radiology/radiologyOrder.form?orderId=" + mockDiscontinuationOrder.getOrderId()));
    assertThat((String) mockSession.getAttribute(WebConstants.OPENMRS_MSG_ATTR),
            is("Order.discontinuedSuccessfully"));
}

From source file:org.araneaframework.tests.FormConstraintTest.java

public void testFormAfterTodayConstraint() throws Exception {

    FormWidget testForm = makeUsualForm();

    MockHttpServletRequest request = new MockHttpServletRequest();

    SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");

    //invalid/*  w  w  w .  ja  va2s.c o  m*/

    request.addParameter("testForm.__present", "true");
    request.addParameter("testForm.myDateTime.date", "11.10.1015");
    request.addParameter("testForm.myDateTime.time", "01:01");

    testForm.getElement("myDateTime").setConstraint(new AfterTodayConstraint(false));

    StandardServletInputData input = new StandardServletInputData(request);
    input.pushScope("testForm");
    testForm._getWidget().update(input);
    input.popScope();

    assertTrue("Test form must not be valid after reading from request", !testForm.convertAndValidate());

    request = new MockHttpServletRequest();

    //invalid
    request.addParameter("testForm.__present", "true");
    request.addParameter("testForm.myDateTime.date", sdf.format(new Date()));
    request.addParameter("testForm.myDateTime.time", "00:00");

    testForm.getElement("myDateTime").setConstraint(new AfterTodayConstraint(false));

    input = new StandardServletInputData(request);
    input.pushScope("testForm");
    testForm._getWidget().update(input);
    input.popScope();

    assertTrue("Test form must not be valid after reading from request", !testForm.convertAndValidate());

    request = new MockHttpServletRequest();

    //invalid    
    request.addParameter("testForm.__present", "true");
    request.addParameter("testForm.myDateTime.date", "11.10.2015");
    request.addParameter("testForm.myDateTime.time", "01:01");

    //Testing primitive constraint
    testForm.getElement("myDateTime").setConstraint(new AfterTodayConstraint(true));

    input = new StandardServletInputData(request);
    input.pushScope("testForm");
    testForm._getWidget().update(input);
    input.popScope();

    assertTrue("Test form must be valid after reading from request", testForm.convertAndValidate());

    request = new MockHttpServletRequest();

    //valid
    request.addParameter("testForm.__present", "true");
    request.addParameter("testForm.myDateTime.date", sdf.format(new Date()));
    request.addParameter("testForm.myDateTime.time", "00:01");

    //Testing primitive constraint
    testForm.getElement("myDateTime").setConstraint(new AfterTodayConstraint(true));

    input = new StandardServletInputData(request);
    input.pushScope("testForm");
    testForm._getWidget().update(input);
    input.popScope();

    assertTrue("Test form must be valid after reading from request", testForm.convertAndValidate());
}

From source file:alpha.portal.webapp.controller.ContributorRoleControllerTest.java

/**
 * V-Test (save, show, edit, delete).// w  w  w  .j  a va2  s  . com
 * 
 * @throws Exception
 *             the exception
 */
@SuppressWarnings("unchecked")
@Test
public void testVTest() throws Exception {
    final String newCRName = "New Test Contributor Role";

    final int numberOfRolesBeforeAdd = this.contributorRoleManager.getAll().size();

    /**
     * Add
     */
    MockHttpServletRequest request = this.newPost("/contributorRole");
    request.setRemoteUser(this.testUserName);
    request.addParameter("save_new", "button.save");
    request.addParameter("newContributorRole", newCRName);

    MockHttpServletResponse response = new MockHttpServletResponse();

    this.ctrl.saveNew(request, response);
    Assert.assertTrue(StringUtils.isBlank(response.getErrorMessage()));

    /**
     * Show
     */
    request = this.newGet("/contributorRole");
    request.setRemoteUser(this.testUserName);

    ModelAndView result = this.ctrl.showPage(request);
    Map<String, Object> resModel = result.getModel();

    final Object contribListObj = resModel.get("contributorRolesList");
    final List<ContributorRole> contribList = (List<ContributorRole>) contribListObj;
    Assert.assertEquals((numberOfRolesBeforeAdd + 1), contribList.size());
    ContributorRole newCR = this.contributorRoleManager.getContributorRoleByName(newCRName);
    boolean contains = false;
    for (int c = 0; (c < contribList.size()) && (contains == false); c++) {
        if (contribList.get(c).getName().equals(newCRName)) {
            contains = true;
        }
    }
    Assert.assertTrue("New contrib.role in roles list", contains);

    /**
     * Edit-Page
     */
    request = this.newGet("/contributorRole");
    request.setRemoteUser(this.testUserName);
    request.addParameter("edit", newCR.getContributorRoleId().toString());

    result = this.ctrl.showPage(request);
    resModel = result.getModel();

    Assert.assertTrue(resModel.containsKey("showEditingForm"));
    Assert.assertTrue(resModel.containsKey("roleToEditId"));
    Assert.assertTrue(resModel.containsKey("roleToEdit"));
    Assert.assertFalse(resModel.containsKey("messageId"));

    Assert.assertEquals(newCR.getContributorRoleId().toString(), resModel.get("roleToEditId"));
    Assert.assertEquals(newCR.getName(), resModel.get("roleToEdit"));

    /**
     * Edit-Post
     */
    request = this.newPost("/contributorRole");
    request.setRemoteUser(this.testUserName);
    request.addParameter("save_edit", "button.save");
    request.addParameter("newContributorRole", newCRName + " - Changed");
    request.addParameter("oldContribRoleId", newCR.getContributorRoleId().toString());

    response = new MockHttpServletResponse();

    this.ctrl.saveEdit(request, response);
    Assert.assertTrue(StringUtils.isBlank(response.getErrorMessage()));

    newCR = this.contributorRoleManager.get(newCR.getContributorRoleId());
    Assert.assertEquals(newCRName + " - Changed", newCR.getName());

    /**
     * Delete
     */
    request = this.newPost("/contributorRole");
    request.setRemoteUser(this.testUserName);
    request.addParameter("delete", newCR.getContributorRoleId().toString());

    result = this.ctrl.showPage(request);
    resModel = result.getModel();

    Assert.assertTrue(resModel.containsKey("contributorRolesList"));
    Assert.assertTrue(StringUtils.isBlank(response.getErrorMessage()));

    boolean isException = false;
    try {
        newCR = this.contributorRoleManager.get(newCR.getContributorRoleId());
    } catch (final ObjectRetrievalFailureException e) {
        isException = true;
    }
    Assert.assertTrue("role not deleted", isException);
}

From source file:org.openmrs.module.radiology.web.controller.RadiologyOrderFormControllerTest.java

/**
 * @see RadiologyOrderFormController#postDiscontinueRadiologyOrder(HttpServletRequest,
 *      HttpServletResponse, Order, String, Date)
 *//* www. ja  v  a 2 s.co  m*/
@Test
@Verifies(value = "should not redirect if discontinuation failed in pacs", method = "postDiscontinueRadiologyOrder(HttpServletRequest, HttpServletResponse, Order, String, Date)")
public void postDiscontinueRadiologyOrder_shouldNotRedirectIfDiscontinuationFailedInPacs() throws Exception {
    //given
    RadiologyOrder mockRadiologyOrderToDiscontinue = RadiologyTestData.getMockRadiologyOrder1();
    mockRadiologyOrderToDiscontinue.getStudy().setMwlStatus(MwlStatus.DISCONTINUE_ERR);
    String discontinueReason = "Wrong Procedure";
    Date discontinueDate = new GregorianCalendar(2015, Calendar.JANUARY, 01).getTime();

    Order mockDiscontinuationOrder = new Order();
    mockDiscontinuationOrder.setOrderId(2);
    mockDiscontinuationOrder.setAction(Order.Action.DISCONTINUE);
    mockDiscontinuationOrder.setOrderer(mockRadiologyOrderToDiscontinue.getOrderer());
    mockDiscontinuationOrder.setOrderReasonNonCoded(discontinueReason);
    mockDiscontinuationOrder.setPreviousOrder(mockRadiologyOrderToDiscontinue);

    MockHttpServletRequest mockRequest = new MockHttpServletRequest();
    mockRequest.addParameter("discontinueOrder", "discontinueOrder");
    MockHttpSession mockSession = new MockHttpSession();
    mockRequest.setSession(mockSession);

    when(radiologyService.getRadiologyOrderByOrderId(mockRadiologyOrderToDiscontinue.getOrderId()))
            .thenReturn(mockRadiologyOrderToDiscontinue);
    when(orderService.discontinueOrder(mockRadiologyOrderToDiscontinue, discontinueReason, discontinueDate,
            mockRadiologyOrderToDiscontinue.getOrderer(), mockRadiologyOrderToDiscontinue.getEncounter()))
                    .thenReturn(mockDiscontinuationOrder);

    ModelAndView modelAndView = radiologyOrderFormController.postDiscontinueRadiologyOrder(mockRequest, null,
            mockRadiologyOrderToDiscontinue, mockDiscontinuationOrder);

    assertNotNull(modelAndView);
    assertThat(modelAndView.getViewName(), is("module/radiology/radiologyOrderForm"));

    assertThat(modelAndView.getModelMap(), hasKey("order"));
    Order order = (Order) modelAndView.getModelMap().get("order");
    assertThat(order, is((Order) mockRadiologyOrderToDiscontinue));

    assertThat(modelAndView.getModelMap(), hasKey("radiologyOrder"));
    RadiologyOrder radiologyOrder = (RadiologyOrder) modelAndView.getModelMap().get("radiologyOrder");
    assertThat(radiologyOrder, is(mockRadiologyOrderToDiscontinue));

    assertNotNull(mockSession.getAttribute(WebConstants.OPENMRS_ERROR_ATTR));
    assertThat((String) mockSession.getAttribute(WebConstants.OPENMRS_ERROR_ATTR),
            is("radiology.failWorklist"));
}

From source file:org.openmrs.module.radiology.web.controller.RadiologyOrderFormControllerTest.java

/**
 * @see RadiologyOrderFormController#postSaveRadiologyOrder(HttpServletRequest, Integer, Order,
 *      BindingResult)//ww  w  .jav a 2 s. c  om
 */
@Test
@Verifies(value = "should set http session attribute openmrs message to saved fail worklist and redirect to patient dashboard when save study was not successful and given patient id", method = "postSaveRadiologyOrder(HttpServletRequest, Integer, RadiologyOrder, BindingResult)")
public void postSaveRadiologyOrder_shouldSetHttpSessionAttributeOpenmrsMessageToSavedFailWorklistAndRedirectToPatientDashboardWhenSaveStudyWasNotSuccessfulAndGivenPatientId()
        throws Exception {

    //given
    RadiologyOrder mockRadiologyOrder = RadiologyTestData.getMockRadiologyOrder1();
    mockRadiologyOrder.getStudy().setMwlStatus(MwlStatus.SAVE_ERR);

    when(radiologyService.placeRadiologyOrder(mockRadiologyOrder)).thenReturn(mockRadiologyOrder);

    MockHttpServletRequest mockRequest = new MockHttpServletRequest();
    mockRequest.addParameter("saveOrder", "saveOrder");
    MockHttpSession mockSession = new MockHttpSession();
    mockRequest.setSession(mockSession);

    BindingResult orderErrors = mock(BindingResult.class);
    when(orderErrors.hasErrors()).thenReturn(false);

    ModelAndView modelAndView = radiologyOrderFormController.postSaveRadiologyOrder(mockRequest,
            mockRadiologyOrder.getPatient().getPatientId(), mockRadiologyOrder, mockRadiologyOrder,
            orderErrors);

    assertNotNull(modelAndView);
    assertThat(modelAndView.getViewName(),
            is("redirect:/patientDashboard.form?patientId=" + mockRadiologyOrder.getPatient().getPatientId()));
    assertThat((String) mockSession.getAttribute(WebConstants.OPENMRS_MSG_ATTR),
            is("radiology.savedFailWorklist"));

    mockRequest = new MockHttpServletRequest();
    mockRequest.addParameter("saveOrder", "saveOrder");
    mockSession = new MockHttpSession();
    mockRequest.setSession(mockSession);

    mockRadiologyOrder.getStudy().setMwlStatus(MwlStatus.SAVE_ERR);
    when(radiologyService.placeRadiologyOrder(mockRadiologyOrder)).thenReturn(mockRadiologyOrder);

    modelAndView = radiologyOrderFormController.postSaveRadiologyOrder(mockRequest,
            mockRadiologyOrder.getPatient().getPatientId(), mockRadiologyOrder, mockRadiologyOrder,
            orderErrors);

    assertNotNull(modelAndView);
    assertThat(modelAndView.getViewName(),
            is("redirect:/patientDashboard.form?patientId=" + mockRadiologyOrder.getPatient().getPatientId()));
    assertThat((String) mockSession.getAttribute(WebConstants.OPENMRS_MSG_ATTR),
            is("radiology.savedFailWorklist"));
}

From source file:org.openmrs.web.controller.observation.ObsFormControllerTest.java

/**
 * Test to make sure a new patient form can save a person relationship
 * /*ww  w . j  a va 2s . c o m*/
 * @throws Exception
 */
@Test
public void shouldSaveObsFormNormally() throws Exception {
    ObsService os = Context.getObsService();

    // set up the controller
    ObsFormController controller = new ObsFormController();
    controller.setApplicationContext(applicationContext);
    controller.setSuccessView("encounter.form");
    controller.setFormView("obs.form");

    // set up the request and do an initial "get" as if the user loaded the
    // page for the first time
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/admin/observations/obs.form");
    request.setSession(new MockHttpSession(null));
    HttpServletResponse response = new MockHttpServletResponse();
    controller.handleRequest(request, response);

    // set this to be a page submission
    request.setMethod("POST");

    // add all of the parameters that are expected
    // all but the relationship "3a" should match the stored data
    request.addParameter("person", "2");
    request.addParameter("encounter", "3");
    request.addParameter("location", "1");
    request.addParameter("obsDatetime", "05/05/2005");
    request.addParameter("concept", "4"); // CIVIL_STATUS (conceptid=4) concept
    request.addParameter("valueCoded", "5"); // conceptNameId=2458 for SINGLE concept
    request.addParameter("saveObs", "Save Obs"); // so that the form is processed

    // send the parameters to the controller
    controller.handleRequest(request, response);

    // make sure an obs was created
    List<Obs> obsForPatient = os.getObservationsByPerson(new Person(2));
    assertEquals(1, obsForPatient.size());
    assertEquals(3, obsForPatient.get(0).getEncounter().getId().intValue());
    assertEquals(1, obsForPatient.get(0).getLocation().getId().intValue());
}