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#retireProviderAttributeType(ProviderAttributeType,String,WebRequest)
 * @verifies void a provider attribute type
 *///w ww.  ja v a 2s.c  om
@Test
public void retireProviderAttributeType_shouldRetireAProviderAttributeType() throws Exception {
    ProviderAttributeType providerAttributeType = Context.getProviderService().getProviderAttributeType(1);
    Assert.assertFalse(providerAttributeType.isRetired());

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

    handle(request);

    providerAttributeType = Context.getProviderService().getProviderAttributeType(1);
    Assert.assertTrue(providerAttributeType.isRetired());
    Assert.assertEquals("test", providerAttributeType.getRetireReason());
}

From source file:org.jasig.cas.support.oauth.web.OAuth20CallbackAuthorizeControllerTests.java

@Test
public void testOK() throws Exception {
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET",
            CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_URL);
    mockRequest.addParameter(OAuthConstants.TICKET, SERVICE_TICKET);
    final MockHttpSession mockSession = new MockHttpSession();
    mockSession.putValue(OAuthConstants.OAUTH20_CALLBACKURL, REDIRECT_URI);
    mockSession.putValue(OAuthConstants.OAUTH20_SERVICE_NAME, SERVICE_NAME);
    mockRequest.setSession(mockSession);
    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
    final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController();
    oauth20WrapperController.afterPropertiesSet();
    final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse);
    assertEquals(OAuthConstants.CONFIRM_VIEW, modelAndView.getViewName());
    final Map<String, Object> map = modelAndView.getModel();
    assertEquals(SERVICE_NAME, map.get("serviceName"));
    assertEquals(REDIRECT_URI + "?" + OAuthConstants.CODE + "=" + SERVICE_TICKET, map.get("callbackUrl"));
}

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

@Test(expected = ResourceDoesNotSupportOperationException.class)
public void shouldNotSupportRetiringAConceptDatatype() throws Exception {
    MockHttpServletRequest req = request(RequestMethod.DELETE, getURI() + "/" + getUuid());
    req.addParameter("!purge", "");
    handle(req);/*w ww.jav  a2 s .c  o m*/
}

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

@Test(expected = ResourceDoesNotSupportOperationException.class)
public void shouldNotSupportPurgingAConceptDatatype() throws Exception {
    MockHttpServletRequest req = request(RequestMethod.DELETE, getURI() + "/" + getUuid());
    req.addParameter("purge", "");
    handle(req);/*from w  ww  . j a  va  2s  .com*/
}

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

@Test
public void getAllCohortMembers_shouldGetADefaultRepresentationOfAllCohortMembers() throws Exception {
    int size = service.getCohortByUuid(getUuid()).getMemberIds().size();

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

    Util.log("Cohort member fetched (default)", result);
    Assert.assertEquals(size, Util.getResultsSize(result));
}

From source file:org.jasig.cas.support.oauth.web.OAuth20CallbackAuthorizeControllerTests.java

@Test
public void testOKWithState() throws Exception {
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET",
            CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_URL);
    mockRequest.addParameter(OAuthConstants.TICKET, SERVICE_TICKET);
    final MockHttpSession mockSession = new MockHttpSession();
    mockSession.putValue(OAuthConstants.OAUTH20_CALLBACKURL, REDIRECT_URI);
    mockSession.putValue(OAuthConstants.OAUTH20_SERVICE_NAME, SERVICE_NAME);
    mockSession.putValue(OAuthConstants.OAUTH20_STATE, STATE);
    mockRequest.setSession(mockSession);
    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
    final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController();
    oauth20WrapperController.afterPropertiesSet();
    final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse);
    assertEquals(OAuthConstants.CONFIRM_VIEW, modelAndView.getViewName());
    final Map<String, Object> map = modelAndView.getModel();
    assertEquals(SERVICE_NAME, map.get("serviceName"));
    assertEquals(REDIRECT_URI + "?" + OAuthConstants.CODE + "=" + SERVICE_TICKET + "&" + OAuthConstants.STATE
            + "=" + STATE, map.get("callbackUrl"));
}

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

/**
 * Test save conflicting user./*from   ww w.  j  a  va2 s .c o  m*/
 * 
 * @throws Exception
 *             the exception
 */
public void testSaveConflictingUser() throws Exception {
    final UserManager userManager = (UserManager) this.applicationContext.getBean("userManager");
    final User user = userManager.getUserByUsername("user");
    user.setPassword("user");
    user.setConfirmPassword("user");
    // e-mail address from existing user
    // User existingUser = (User) userManager.getUsers().get(0);
    final User existingUser = userManager.getUserByUsername("admin");
    user.setEmail(existingUser.getEmail());
    this.action.setUser(user);
    this.action.setFrom("list");

    final Integer originalVersionNumber = user.getVersion();
    this.log.debug("original version #: " + originalVersionNumber);

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

    Assert.assertEquals("input", this.action.save());
    Assert.assertNotNull(this.action.getUser());
    Assert.assertEquals(originalVersionNumber, user.getVersion());
    Assert.assertTrue(this.action.hasActionErrors());
}

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

@Test
public void shouldRetireAPatientIdentifierType() throws Exception {
    assertEquals(false, service.getPatientIdentifierTypeByUuid(getUuid()).isRetired());
    MockHttpServletRequest req = request(RequestMethod.DELETE, getURI() + "/" + getUuid());
    req.addParameter("!purge", "");
    final String reason = "none";
    req.addParameter("reason", reason);
    handle(req);/*from w w w . java2  s  .  co  m*/
    assertEquals(true, service.getPatientIdentifierTypeByUuid(getUuid()).isRetired());
    assertEquals(reason, service.getPatientIdentifierTypeByUuid(getUuid()).getRetireReason());
}

From source file:org.synyx.hades.extensions.web.PageableArgumentResolverUnitTest.java

@Test
public void assertOverridesDefaults() throws Exception {

    Integer sizeParam = 5;/*ww w.ja v a  2 s  .  com*/

    MethodParameter parameter = new MethodParameter(defaultsMethod, 0);
    MockHttpServletRequest mockRequest = new MockHttpServletRequest();

    mockRequest.addParameter("page.page", sizeParam.toString());
    NativeWebRequest webRequest = new ServletWebRequest(mockRequest);
    PageableArgumentResolver resolver = new PageableArgumentResolver();
    Object argument = resolver.resolveArgument(parameter, webRequest);

    assertTrue(argument instanceof Pageable);

    Pageable pageable = (Pageable) argument;
    assertEquals(SampleController.DEFAULT_PAGESIZE, pageable.getPageSize());
    assertEquals(sizeParam - 1, pageable.getPageNumber());
}

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

@Test
public void shouldReturnTheAuditInfoForTheFullRepresentation() throws Exception {
    MockHttpServletRequest httpReq = new MockHttpServletRequest();
    httpReq.addParameter(RestConstants.REQUEST_PROPERTY_FOR_REPRESENTATION, RestConstants.REPRESENTATION_FULL);
    Object result = controller.retrieve("167ce20c-4785-4285-9119-d197268f7f4a", httpReq);
    Assert.assertNotNull(result);//  w ww .  ja va  2s  .  com
    Assert.assertNotNull(PropertyUtils.getProperty(result, "auditInfo"));
}