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.openmrs2_0.UserController2_0Test.java

/**
 * @see PatientController#getPatient(String,WebRequest)
 * @throws Exception//w  ww  .j  a  va 2 s.com
 * @verifies get a full representation of a patient
 */
@Test
public void getUser_shouldGetAFullRepresentationOfAPatient() throws Exception {

    MockHttpServletRequest req = request(RequestMethod.GET, getURI() + "/" + getUuid());
    req.addParameter(RestConstants.REQUEST_PROPERTY_FOR_REPRESENTATION, RestConstants.REPRESENTATION_FULL);

    SimpleObject result = deserialize(handle(req));
    Util.log("User retrieved (full)", result);

    Assert.assertNotNull(result);
    Assert.assertEquals(getUuid(), PropertyUtils.getProperty(result, "uuid"));

    Assert.assertNull(PropertyUtils.getProperty(result, "secretQuestion"));
}

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

/**
 * @see PatientController#getPatient(String,WebRequest)
 * @throws Exception /* w w  w .  j  av  a 2s.  c o  m*/
 * @verifies get a full representation of a patient
 */
@Test
public void getUser_shouldGetAFullRepresentationOfAPatient() throws Exception {

    MockHttpServletRequest req = request(RequestMethod.GET, getURI() + "/" + getUuid());
    req.addParameter(RestConstants.REQUEST_PROPERTY_FOR_REPRESENTATION, RestConstants.REPRESENTATION_FULL);

    SimpleObject result = deserialize(handle(req));
    Util.log("User retrieved (full)", result);

    Assert.assertNotNull(result);
    Assert.assertEquals(getUuid(), PropertyUtils.getProperty(result, "uuid"));

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

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

@Test
public void shouldSearchAndReturnAListOfLocationsMatchingTheQueryString() throws Exception {

    MockHttpServletRequest req = request(RequestMethod.GET, getURI());
    req.addParameter("q", "xan");
    SimpleObject result = deserialize(handle(req));

    List<Object> hits = (List<Object>) result.get("results");
    Assert.assertEquals(1, hits.size());
    Assert.assertEquals(service.getLocation(2).getUuid(), PropertyUtils.getProperty(hits.get(0), "uuid"));

}

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

@Test
public void shouldSearchAndReturnListOfLocationsWithSpecifiedTag() throws Exception {

    executeDataSet(LOCATION_TAG_INITIAL_XML);

    MockHttpServletRequest req = request(RequestMethod.GET, getURI());
    req.addParameter("tag", "001e503a-47ed-11df-bc8b-001e378eb67e");

    SimpleObject result = deserialize(handle(req));
    List<Object> hits = (List<Object>) result.get("results");
    Assert.assertEquals(1, hits.size()); // should ignore retired location?
    Assert.assertEquals(service.getLocation(1).getUuid(), PropertyUtils.getProperty(hits.get(0), "uuid"));
}

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

@Test
public void shouldSearchAndReturnNothingIfTagDoesNotMatchEvenIfQueryDoes() throws Exception {

    executeDataSet(LOCATION_TAG_INITIAL_XML);

    MockHttpServletRequest req = request(RequestMethod.GET, getURI());
    req.addParameter("tag", "invalid-uuid");
    req.addParameter("q", "Xan");

    SimpleObject result = deserialize(handle(req));
    List<Object> hits = (List<Object>) result.get("results");
    Assert.assertEquals(0, hits.size()); // should ignore retired location?
}

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

@Test
public void shouldSearchAndReturnListOfLocationsWithSpecifiedTagAndQueryString() throws Exception {

    executeDataSet(LOCATION_TAG_INITIAL_XML);

    MockHttpServletRequest req = request(RequestMethod.GET, getURI());
    req.addParameter("tag", "0940c6d4-47ed-11df-bc8b-001e378eb67e");
    req.addParameter("q", "Xan");

    SimpleObject result = deserialize(handle(req));
    List<Object> hits = (List<Object>) result.get("results");
    Assert.assertEquals(1, hits.size()); // should ignore retired location?
    Assert.assertEquals(service.getLocation(2).getUuid(), PropertyUtils.getProperty(hits.get(0), "uuid"));
}

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

/**
 * @see UserController#retireUser(User,String,WebRequest)
 * @throws Exception /*  w  w  w  .  java2  s . co m*/
 * @verifies void a patient
 */
@Test
public void retireUser_shouldRetireAUser() throws Exception {

    User user = service.getUserByUuid(getUuid());
    Assert.assertFalse(user.isRetired());

    MockHttpServletRequest req = request(RequestMethod.DELETE, getURI() + "/" + user.getUuid());
    req.addParameter("!purge", "");
    req.addParameter("reason", "unit test");
    handle(req);

    User retiredUser = service.getUserByUuid(getUuid());
    Assert.assertTrue(retiredUser.isRetired());
    Assert.assertEquals("unit test", retiredUser.getRetireReason());
}

From source file:org.openmrs.web.controller.form.FormFormControllerTest.java

@Test
public void shouldNotSaveAFormWhenFormsAreLocked() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest("POST", "/admin/forms/formEdit.form?formId=1");
    request.setSession(new MockHttpSession(null));
    HttpServletResponse response = new MockHttpServletResponse();
    controller.handleRequest(request, response);

    request.addParameter("name", "TRUNK");
    request.addParameter("version", "1");
    request.addParameter("action", "Form.save");
    request.setContentType("application/x-www-form-urlencoded");

    ModelAndView mav = controller.handleRequest(request, response);
    Assert.assertEquals("The save attempt should have failed!", "index.htm", mav.getViewName());
    Assert.assertNotEquals("formEdit.form", mav.getViewName());
    Assert.assertSame(controller.getFormView(), mav.getViewName());
    Assert.assertNotNull(formService.getForm(1));
}

From source file:org.auraframework.integration.test.http.resource.InlineJsTest.java

/**
 * Verify all content in script tag in aura:template is written into inlineJs.
 *
 * TODO: go over inline JS in aura:template and split the test into specific small cases.
 *///from  w w w. j a v  a  2s . c  o  m
public void testInlineScriptInAuraTemplate() throws Exception {
    // Arrange
    if (contextService.isEstablished()) {
        contextService.endContext();
    }

    String appMarkup = String.format(baseApplicationTag, "template='aura:template'", "");
    DefDescriptor<ApplicationDef> appDesc = addSourceAutoCleanup(ApplicationDef.class, appMarkup);

    AuraContext context = contextService.startContext(AuraContext.Mode.DEV, AuraContext.Format.JS,
            AuraContext.Authentication.AUTHENTICATED, appDesc);

    MockHttpServletRequest mockRequest = new MockHttpServletRequest();
    mockRequest.addParameter("jwt", configAdapter.generateJwtToken());
    MockHttpServletResponse mockResponse = new MockHttpServletResponse();

    InlineJs inlineJs = getInlineJs();

    // Act
    inlineJs.write(mockRequest, mockResponse, context);
    String content = mockResponse.getContentAsString();

    // Assert
    this.goldFileText(content);
}

From source file:org.openmrs.web.controller.ForgotPasswordFormControllerTest.java

@Test
public void shouldNotAcceptWithInvalidSecretQuestionIfUserIsNull() throws Exception {
    ForgotPasswordFormController controller = (ForgotPasswordFormController) applicationContext
            .getBean("forgotPasswordForm");
    MockHttpServletRequest request = new MockHttpServletRequest();

    request.setMethod("POST");
    request.addParameter("uname", "");
    HttpServletResponse response = new MockHttpServletResponse();

    controller.handleRequest(request, response);
    Assert.assertFalse(Context.isAuthenticated());
}