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.ConceptSearchController1_9Test.java

@Test
public void shouldSearchAndReturnAListOfConceptsMatchingTheQueryStringAndConceptClass() throws Exception {
    MockHttpServletRequest req = request(RequestMethod.GET, getURI());
    req.addParameter("q", "ma");
    req.addParameter("conceptClasses", "2a3738f5-26f0-4f97-ae7a-f99e42fa6d44");
    SimpleObject result = deserialize(handle(req));

    List<Object> hits = (List<Object>) result.get("results");
    Assert.assertEquals(1, hits.size());
    Assert.assertEquals("MALARIA PROGRAM", Util.getByPath(hits.get(0), "display"));
    Assert.assertEquals("f923524a-b90c-4870-a948-4125638606fd", Util.getByPath(hits.get(0), "concept/uuid"));

    //Try multiple concept classes
    req.addParameter("conceptClasses", "ecdee8a7-d741-4fe7-8e01-f79cacbe97bc");
    result = deserialize(handle(req));//ww  w  .j  a va2  s .c o m

    hits = (List<Object>) result.get("results");
    assertThat(hits, containsInAnyOrder(isConceptWithUuid("92afda7c-78c9-47bd-a841-0de0817027d4"),
            isConceptWithUuid("f923524a-b90c-4870-a948-4125638606fd")));
}

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

/**
 * @see LocationAttributeTypeController#retireLocationAttributeType(LocationAttributeType,String,WebRequest)
 * @verifies void a location attribute type
 *//*from w  w w  .j a  v a  2  s  .c  om*/
@Test
public void retireLocationAttributeType_shouldRetireALocationAttributeType() throws Exception {
    LocationAttributeType locationAttributeType = Context.getLocationService().getLocationAttributeType(1);
    Assert.assertFalse(locationAttributeType.isRetired());

    MockHttpServletRequest request = request(RequestMethod.DELETE, getURI() + "/" + getUuid());
    request.addParameter("reason", "test");
    handle(request);

    locationAttributeType = Context.getLocationService().getLocationAttributeType(1);
    Assert.assertTrue(locationAttributeType.isRetired());
    Assert.assertEquals("test", locationAttributeType.getRetireReason());
}

From source file:ejportal.webapp.action.UserActionTest.java

/**
 * Test save.//from  www .  ja v  a  2 s. c  om
 * 
 * @throws Exception
 *             the exception
 */
public void testSave() throws Exception {
    final UserManager userManager = (UserManager) this.applicationContext.getBean("userManager");
    final User user = userManager.getUserByUsername("user");
    user.setPassword("user");
    user.setConfirmPassword("user");
    this.action.setUser(user);
    this.action.setFrom("list");

    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter("encryptPass", "true");
    ServletActionContext.setRequest(request);

    Assert.assertEquals("input", this.action.save());
    Assert.assertNotNull(this.action.getUser());
    Assert.assertFalse(this.action.hasActionErrors());
}

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

@Test
public void shouldGetRefByUuid() throws Exception {
    MockHttpServletRequest request = request(RequestMethod.GET, getURI() + "/" + getUuid());
    request.addParameter("v", "ref");
    SimpleObject result = deserialize(handle(request));

    Assert.assertNotNull(result);/* w w w  .jav a 2 s  .c  o  m*/
    Assert.assertEquals(getUuid(), PropertyUtils.getProperty(result, "uuid"));
}

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

@Test
public void shouldGetFullByUuid() throws Exception {
    MockHttpServletRequest request = request(RequestMethod.GET, getURI() + "/" + getUuid());
    request.addParameter("v", "full");
    SimpleObject result = deserialize(handle(request));

    Assert.assertNotNull(result);// www.  j av  a 2  s .co  m
    Assert.assertEquals(getUuid(), PropertyUtils.getProperty(result, "uuid"));
}

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

@Test
public void shouldSearchAConceptSourceIfItMatchesTheQuery() throws Exception {
    MockHttpServletRequest req = request(RequestMethod.GET, getURI());
    req.addParameter("q", "ome");
    SimpleObject result = deserialize(handle(req));
    Assert.assertEquals(2, Util.getResultsSize(result));
}

From source file:org.openmrs.module.webservices.rest19ext.web.v1_0.controller.VisitAttributeTypeControllerTest.java

/**
 * @see VisitAttributeTypeController#retrieve(String, javax.servlet.http.HttpServletRequest)
 */// w w  w.  java  2 s . c o  m
@Test
public void retrieve_shouldGetAFullRepresentationOfAVisitAttributeType() throws Exception {
    MockHttpServletRequest req = new MockHttpServletRequest();
    req.addParameter(RestConstants.REQUEST_PROPERTY_FOR_REPRESENTATION, RestConstants.REPRESENTATION_FULL);
    Object result = controller.retrieve(Rest19ExtTestConstants.VISIT_ATTRIBUTE_TYPE_UUID, req);
    Assert.assertNotNull(result);
    Assert.assertEquals(Rest19ExtTestConstants.VISIT_ATTRIBUTE_TYPE_UUID,
            PropertyUtils.getProperty(result, "uuid"));
    Assert.assertNotNull(PropertyUtils.getProperty(result, "auditInfo"));
}

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

@Test
public void shouldRetireAConceptClass() throws Exception {
    String uuid = "77177ce7-1410-40ee-bbad-ff6905ee3095";

    Assert.assertEquals(false, service.getConceptClassByUuid(uuid).isRetired());
    MockHttpServletRequest req = request(RequestMethod.DELETE, getURI() + "/" + uuid);
    req.addParameter("!purge", "");
    final String reason = "none";
    req.addParameter("reason", reason);
    handle(req);//from w  w  w .  j  a  v a 2  s.com
    Assert.assertEquals(true, service.getConceptClassByUuid(uuid).isRetired());
    Assert.assertEquals(reason, service.getConceptClassByUuid(uuid).getRetireReason());
}

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

@Test
public void shouldPurgeAPatientIdentifierType() throws Exception {
    final String uuid = "158d6b17-a8ab-435b-8fe3-952a04bda757";
    assertNotNull(service.getPatientIdentifierTypeByUuid(uuid));
    MockHttpServletRequest req = request(RequestMethod.DELETE, getURI() + "/" + uuid);
    req.addParameter("purge", "");
    handle(req);/* ww  w.  ja v  a2s . c om*/
    assertNull(service.getPatientIdentifierTypeByUuid(uuid));
}

From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8.ConceptDatatypeController1_8Test.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));

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