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.jasig.cas.web.ServiceValidateControllerTests.java

private HttpServletRequest getHttpServletRequest() throws TicketException {
    final String tId = getCentralAuthenticationService()
            .createTicketGrantingTicket(TestUtils.getCredentialsWithSameUsernameAndPassword());
    getCentralAuthenticationService().grantServiceTicket(tId, TestUtils.getService());
    final String sId2 = getCentralAuthenticationService().grantServiceTicket(tId, TestUtils.getService());

    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter("service", TestUtils.getService().getId());
    request.addParameter("ticket", sId2);
    request.addParameter("renew", "true");

    return request;
}

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

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

    req.removeAllParameters();/*w ww .ja  va2 s . c  o  m*/
    req.addParameter("q", "logy");
    result = deserialize(handle(req));
    assertEquals(3, 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(),
                    PropertyUtils.getProperty(Util.getResultsList(result).get(2), "uuid").toString() });
    assertThat(uuids, hasItems("90a1e5b0-ac05-11e3-a5e2-0800200c9a66", "9b6cf570-ac05-11e3-a5e2-0800200c9a66",
            "a4ebaf10-ac05-11e3-a5e2-0800200c9a66"));

}

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

@Test
public void shouldRetireADrug() throws Exception {

    Drug drug = service.getDrugByUuid(getUuid());
    Assert.assertFalse(drug.isRetired());

    MockHttpServletRequest req = request(RequestMethod.DELETE, getURI() + "/" + drug.getUuid());
    req.addParameter("!purge", "");
    req.addParameter("reason", "random reason");
    handle(req);/*w  ww  .ja v a2  s.  com*/

    Drug retiredDrug = service.getDrugByUuid(getUuid());
    Assert.assertTrue(retiredDrug.isRetired());
    Assert.assertEquals("random reason", retiredDrug.getRetireReason());

}

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

@Test
public void shouldIncludeLatitudeLongituteAndAuditInfoForFullRepresentation() 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"));
    Assert.assertNotNull(PropertyUtils.getProperty(result, "latitude"));
    Assert.assertNotNull(PropertyUtils.getProperty(result, "longitude"));
}

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

@Test
public void shouldPurgeAConceptReferenceTerm() throws Exception {
    final String uuid = "SSTRM-retired code";
    assertNotNull(service.getConceptReferenceTermByUuid(uuid));
    MockHttpServletRequest req = request(RequestMethod.DELETE, getURI() + "/" + uuid);
    req.addParameter("purge", "");
    handle(req);/*from  w ww  .  ja  v a 2s. c  o m*/
    assertNull(service.getConceptReferenceTermByUuid(uuid));
}

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

@Test
public void shouldPurgeAnOrderType() throws Exception {
    String uuid = "00e17510-aa09-11e3-a5e2-0800200c9a66";
    assertNotNull(service.getOrderTypeByUuid(uuid));
    MockHttpServletRequest req = request(RequestMethod.DELETE, getURI() + "/" + uuid);
    req.addParameter("purge", "");
    handle(req);/* ww  w. java  2  s  . com*/
    assertNull(service.getOrderTypeByUuid(uuid));
}

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

@Test
public void removeCohortMember_shouldRemoveCohortMember() throws Exception {

    MockHttpServletRequest req = request(RequestMethod.DELETE,
            getURI() + "/" + getUuid() + "/member/" + patientUuid);
    req.addParameter("!purge", "");
    handle(req);// w ww  .ja  va2 s.  c  om

    Cohort cohort = service.getCohortByUuid(getUuid());
    Patient patient = patientService.getPatientByUuid(patientUuid);
    Assert.assertTrue(!cohort.contains(patient));

}

From source file:alpha.portal.webapp.filter.LocaleFilterTest.java

/**
 * Test locale and country./* w  w  w  .  ja va2s .  c om*/
 * 
 * @throws Exception
 *             the exception
 */
public void testLocaleAndCountry() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setSession(new MockHttpSession());
    request.addParameter("locale", "zh_TW");

    final MockHttpServletResponse response = new MockHttpServletResponse();
    this.filter.doFilter(request, response, new MockFilterChain());

    // session not null, should result in not null
    final Locale locale = (Locale) request.getSession().getAttribute(Constants.PREFERRED_LOCALE_KEY);
    Assert.assertNotNull(locale);
    Assert.assertEquals(new Locale("zh", "TW"), locale);
}

From source file:org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.UserResource1_8Test.java

/**
 * @see {@link https://issues.openmrs.org/browse/RESTWS-490}
 * @throws Exception//from w ww  .j  av  a  2  s .co  m
 */
@SuppressWarnings("unchecked")
@Test
public void testCorrectResourceForUser() throws Exception {
    // prepare
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter("q", ""); // query for all
    final RequestContext context = RestUtil.getRequestContext(request, new MockHttpServletResponse());

    // search
    final SimpleObject simple = getResource().search(context);
    final List<SimpleObject> results = (List<SimpleObject>) simple.get("results");

    // verify
    Assert.assertFalse("A non-empty list is expected.", results.isEmpty());
    for (SimpleObject result : results) {
        final String selfLink = findSelfLink(result);
        Assert.assertTrue("Resource should be user, but is " + selfLink, selfLink.contains("/user/"));
    }
}

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

@Test
public void shouldPurgeARetiredProgram() throws Exception {

    Program program = service.getProgram(3);
    MockHttpServletRequest req = request(RequestMethod.DELETE, getURI() + "/" + program.getUuid());
    req.addParameter("purge", "");
    handle(req);/*from ww w. j  a  va2s  . c o  m*/

    Assert.assertNull(service.getProgram(3));
}