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:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_9.ProviderAttributeTypeController1_9Test.java

/**
 * @see ProviderAttributeTypeController#findProviderAttributeTypes(String,WebRequest,HttpServletResponse)
 * @verifies find matching provider attribute types
 *//*from   w  w  w .j  a  v  a2  s.  c o  m*/
@Test
public void findProviderAttributeTypes_shouldFindMatchingProviderAttributeTypes() throws Exception {
    MockHttpServletRequest request = newGetRequest(getURI());
    request.addParameter("q", "Joining");

    SimpleObject response = deserialize(handle(request));
    Assert.assertEquals(1, Util.getResultsSize(response));

    List<Object> results = Util.getResultsList(response);
    Object result = results.get(0);

    Assert.assertEquals(RestTestConstants1_9.PROVIDER_ATTRIBUTE_TYPE_UUID,
            PropertyUtils.getProperty(result, "uuid"));
    Assert.assertNotNull(PropertyUtils.getProperty(result, "links"));
    Assert.assertNotNull(PropertyUtils.getProperty(result, "display"));
}

From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_10.CareSettingController1_10Test.java

@Test
public void shouldSearchAndReturnAListOfCareSettingsMatchingTheQueryString() throws Exception {
    MockHttpServletRequest req = request(RequestMethod.GET, getURI());
    req.addParameter("q", "out");
    SimpleObject result = deserialize(handle(req));
    assertEquals(1, Util.getResultsSize(result));
    assertEquals(getUuid(), PropertyUtils.getProperty(Util.getResultsList(result).get(0), "uuid"));

    req.removeAllParameters();//from   w w w  .j  a v a2  s  .c om
    req.addParameter("q", "pati");
    result = deserialize(handle(req));
    assertEquals(2, Util.getResultsSize(result));
    List<String> uuids = Arrays.asList(
            new String[] { PropertyUtils.getProperty(Util.getResultsList(result).get(0), "uuid").toString(),
                    PropertyUtils.getProperty(Util.getResultsList(result).get(1), "uuid").toString() });
    assertThat(uuids, hasItems(getUuid(), "c365e560-c3ec-11e3-9c1a-0800200c9a66"));

}

From source file:se.vgregion.urlservice.controllers.AdminGuiControllerTest.java

@Test
public void deleteRedirectRule() throws IOException {
    UrlServiceService urlServiceService = mock(UrlServiceService.class);
    controller.setUrlServiceService(urlServiceService);

    UUID id = UUID.randomUUID();

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter("delete-" + id.toString(), "any value");

    controller.updateRedirectRules(request);

    verify(urlServiceService).removeRedirectRule(id);
}

From source file:se.vgregion.urlservice.controllers.AdminGuiControllerTest.java

@Test
public void deleteApplication() throws IOException {
    UrlServiceService urlServiceService = mock(UrlServiceService.class);
    controller.setUrlServiceService(urlServiceService);

    UUID id = UUID.randomUUID();

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter("delete-" + id.toString(), "any value");

    controller.updateApplications(request);

    verify(urlServiceService).removeApplication(id);
}

From source file:test.com.tsc9526.monalisa.service.actions.PostActionTest.java

public void testPostDbTableRow1() throws Exception {
    Record base = TestRecordV2().defaults();
    base.save();/*from   w w  w .  j  ava 2 s . co  m*/

    MockHttpServletRequest req = createRequest("/db1/test_record_v2");
    req.addParameter("name", "new_002");

    Response resp = getRespone(req);
    Assert.assertEquals(resp.getStatus(), 200, resp.getMessage());

    DataMap data = resp.getData();
    Assert.assertEquals(data.getInt("rows", 0), 1);

    DataMap entity = (DataMap) data.get("entity");
    Assert.assertEquals(entity.getInt("record_id", 0), base.getInteger("record_id") + 1);
}

From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.PersonAddressControllerTest.java

@Test
public void shouldIncludeLatitudeLongituteAndAuditInfoForFullRepresentation() throws Exception {
    executeDataSet(PERSON_NAME_XML);//from w  ww .j  a  v a  2 s .  c  om
    MockHttpServletRequest httpReq = new MockHttpServletRequest();
    httpReq.addParameter(RestConstants.REQUEST_PROPERTY_FOR_REPRESENTATION, RestConstants.REPRESENTATION_FULL);
    Object result = controller.retrieve(personUuid, "8a806d8c-822d-11e0-872f-18a905e044dc", httpReq);
    Assert.assertNotNull(result);
    Assert.assertNotNull(PropertyUtils.getProperty(result, "auditInfo"));
    Assert.assertNotNull(PropertyUtils.getProperty(result, "latitude"));
    Assert.assertNotNull(PropertyUtils.getProperty(result, "longitude"));
}

From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.RoleControllerTest.java

/**
 * @see RoleController#retrieve(String, javax.servlet.http.HttpServletRequest)
 * @verifies get a full representation of a Role
 *//*from   www .  jav a 2 s.c  om*/
@Test
public void getRole_shouldGetAFullRepresentationOfARole() throws Exception {
    MockHttpServletRequest req = new MockHttpServletRequest();
    req.addParameter(RestConstants.REQUEST_PROPERTY_FOR_REPRESENTATION, RestConstants.REPRESENTATION_FULL);
    Object result = new RoleController().retrieve("3480cb6d-c291-46c8-8d3a-96dc33d199fb", req);
    Assert.assertNotNull(result);
    Assert.assertEquals("3480cb6d-c291-46c8-8d3a-96dc33d199fb", PropertyUtils.getProperty(result, "uuid"));
    Assert.assertNotNull(PropertyUtils.getProperty(result, "name"));
    Assert.assertEquals("Provider", PropertyUtils.getProperty(result, "name"));
    Assert.assertNotNull(PropertyUtils.getProperty(result, "auditInfo"));
}

From source file:org.openmrs.module.formfilter.web.controller.AddFormFilterPropertyControllerTest.java

/**
 * @see {@link AddFormFilterPropertyController#onSubmit(FormFilterProperty, org.springframework.validation.BindingResult, org.springframework.web.bind.support.SessionStatus, javax.servlet.http.HttpServletRequest) }
 *///ww  w.  jav  a  2 s  .  com
@Test
@Verifies(value = "should add new FormFilterProperty", method = "onSubmit(FormFilterProperty, org.springframework.validation.BindingResult, org.springframework.web.bind.support.SessionStatus, javax.servlet.http.HttpServletRequest)")
public void onSubmit_shouldAddNewFormFilterProperty() {

    AddFormFilterPropertyController controller = new AddFormFilterPropertyController();

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter("formFilterId", "1");
    request.addParameter("propertyType", "AgeProperty");
    request.addParameter("minimumAge", "10");
    request.addParameter("maximumAge", "30");

    FormFilterProperty formFilterProperty = new FormFilterProperty();
    formFilterProperty.setFilterName("Test Filter");
    formFilterProperty.setFilterDescription("This filter used for testing.");

    controller.onSubmit(formFilterProperty, null, null, request);

    FormFilterService formFilterService = Context.getService(FormFilterService.class);

    FormFilterProperty temp = new FormFilterProperty();
    Set<FormFilterProperty> assignedFilters = formFilterService.getFormFilter(1).getFormFilterProperties();
    for (FormFilterProperty filterProperty : assignedFilters) {
        if (filterProperty.getFilterName() == "Test Filter")
            temp = filterProperty;
    }

    Assert.assertNotNull(temp);
}

From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_10.CareSettingController1_10Test.java

@Test
public void shouldReturnTheAuditInfoForTheFullRepresentation() throws Exception {
    MockHttpServletRequest req = request(RequestMethod.GET, getURI() + "/" + getUuid());
    req.addParameter(RestConstants.REQUEST_PROPERTY_FOR_REPRESENTATION, RestConstants.REPRESENTATION_FULL);
    SimpleObject result = deserialize(handle(req));

    assertNotNull(PropertyUtils.getProperty(result, "auditInfo"));
}

From source file:test.com.tsc9526.monalisa.service.actions.PostActionTest.java

public void testPostDbTableByMultiKeys() throws Exception {
    Assert.assertNotEquals(selectByPrimaryKey(2).get("name"), "xxyyzz002");

    MockHttpServletRequest req = createRequest("/db1/test_record_v2/record_id=2");

    req.addParameter("name", "xxyyzz002");
    Response resp = getRespone(req);
    Assert.assertEquals(resp.getStatus(), 200, resp.getMessage());
    Assert.assertEquals(selectByPrimaryKey(2).get("name"), "xxyyzz002");
}