Example usage for org.springframework.mock.web MockHttpServletRequest setParameter

List of usage examples for org.springframework.mock.web MockHttpServletRequest setParameter

Introduction

In this page you can find the example usage for org.springframework.mock.web MockHttpServletRequest setParameter.

Prototype

public void setParameter(String name, String... values) 

Source Link

Document

Set an array of values for the specified HTTP parameter.

Usage

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

@Test
public void shouldRespectStartIndexAndLimit() throws Exception {
    MockHttpServletRequest req = newGetRequest(getURI());
    req.setParameter("q", "Test");
    SimpleObject results = deserialize(handle(req));
    int fullCount = Util.getResultsSize(results);
    assertTrue("This test assumes > 2 matching patients", fullCount > 2);

    req.addParameter(RestConstants.REQUEST_PROPERTY_FOR_LIMIT, "2");
    results = deserialize(handle(req));/* w ww.  j  av a  2s . com*/
    int firstCount = Util.getResultsSize(results);
    assertEquals(2, firstCount);

    req.removeParameter(RestConstants.REQUEST_PROPERTY_FOR_LIMIT);
    req.addParameter(RestConstants.REQUEST_PROPERTY_FOR_START_INDEX, "2");
    results = deserialize(handle(req));
    int restCount = Util.getResultsSize(results);
    assertEquals(fullCount, firstCount + restCount);
}

From source file:fi.okm.mpass.idp.authn.impl.SocialUserOpenIdConnectStartServletTest.java

/**
 * Run servlet without {@link ProfileRequestContext}.
 * @throws Exception//from   www.  ja  v  a  2s . c o m
 */
@Test
public void testNoProfileRequestContext() throws Exception {
    final MockHttpServletRequest httpRequest = new MockHttpServletRequest();
    httpRequest.setParameter(ExternalAuthentication.CONVERSATION_KEY, conversationKey);
    httpRequest.getSession().setAttribute(ExternalAuthentication.CONVERSATION_KEY + conversationKey,
            new MockExternalAuthentication());
    Assert.assertTrue(runService(servlet, httpRequest, new MockHttpServletResponse()));
}

From source file:fi.okm.mpass.idp.authn.impl.SocialUserOpenIdConnectStartServletTest.java

/**
 * Run servlet without {@link AuthenticationContext}.
 * @throws Exception/*  w ww .j  ava 2 s  . c om*/
 */
@Test
public void testNoAuthenticationContext() throws Exception {
    final MockHttpServletRequest httpRequest = new MockHttpServletRequest();
    httpRequest.setParameter(ExternalAuthentication.CONVERSATION_KEY, conversationKey);
    final ProfileRequestContext<?, ?> ctx = new ProfileRequestContext<>();
    httpRequest.setAttribute(ProfileRequestContext.BINDING_KEY, ctx);
    httpRequest.getSession().setAttribute(ExternalAuthentication.CONVERSATION_KEY + conversationKey,
            new MockExternalAuthentication());
    Assert.assertTrue(runService(servlet, httpRequest, new MockHttpServletResponse()));
}

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

@Test
public void verifyOK() throws Exception {
    final AccessToken accessToken = mock(AccessToken.class);
    when(accessToken.getId()).thenReturn(TOKEN_ID);

    final CentralOAuthService centralOAuthService = mock(CentralOAuthService.class);
    when(centralOAuthService.getToken(TOKEN_ID)).thenReturn(accessToken);
    when(centralOAuthService.revokeToken(accessToken)).thenReturn(true);

    final MockHttpServletRequest mockRequest = new MockHttpServletRequest("POST",
            CONTEXT + OAuthConstants.REVOKE_URL);
    mockRequest.setParameter(OAuthConstants.TOKEN, TOKEN_ID);
    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();

    final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController();
    oauth20WrapperController.setCentralOAuthService(centralOAuthService);
    oauth20WrapperController.afterPropertiesSet();

    final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse);
    assertNull(modelAndView);//www. ja  va  2s .com
    assertEquals(HttpStatus.SC_NO_CONTENT, mockResponse.getStatus());
    assertNull(mockResponse.getContentType());
    assertEquals("null", mockResponse.getContentAsString());
}

From source file:fi.okm.mpass.shibboleth.authn.impl.ShibbolethSpAuthnServletTest.java

protected MockHttpServletRequest initServletRequest() {
    final MockHttpServletRequest servletRequest = new MockHttpServletRequest();
    final MockHttpSession session = new MockHttpSession();
    servletRequest.setParameter(ExternalAuthentication.CONVERSATION_KEY, conversationKey);
    session.setAttribute(ExternalAuthentication.CONVERSATION_KEY + conversationKey,
            new ExternalAuthenticationImpl(prc));
    servletRequest.setSession(session);/*www.j  a v a2s  .  c  om*/
    return servletRequest;
}

From source file:fi.okm.mpass.idp.authn.impl.SocialUserOpenIdConnectStartServletTest.java

/**
 * Run servlet without {@link SocialUserOpenIdConnectContext}.
 * @throws Exception//from   w w w .j a  v  a  2s. c  om
 */
@Test
public void testNoSocialUserContext() throws Exception {
    final MockHttpServletRequest httpRequest = new MockHttpServletRequest();
    httpRequest.setParameter(ExternalAuthentication.CONVERSATION_KEY, conversationKey);
    final ProfileRequestContext<?, ?> ctx = new ProfileRequestContext<>();
    httpRequest.getSession().setAttribute(ExternalAuthentication.CONVERSATION_KEY + conversationKey,
            new ExternalAuthenticationImpl(ctx));
    final AuthenticationContext authnCtx = ctx.getSubcontext(AuthenticationContext.class, true);
    final AuthenticationFlowDescriptor flow = new AuthenticationFlowDescriptor();
    flow.setId("mock");
    authnCtx.setAttemptedFlow(flow);
    Assert.assertTrue(runService(servlet, httpRequest, new MockHttpServletResponse()));
}

From source file:org.openmrs.module.clinicalsummary.web.service.PatientSearchControllerTest.java

/**
 * @verifies should return empty list when no patient match search term
 * @see org.openmrs.module.clinicalsummary.web.controller.service.PatientSearchController#searchPatient(String, String, String, javax.servlet.http.HttpServletResponse)
 *//* ww w .  j  av a  2s. co  m*/
@Test
public void searchPatient_shouldReturnEmptyListWhenNoPatientMatchSearchTerm() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setMethod("GET");
    request.setRequestURI("/module/clinicalsummary/service/patient/search");
    request.setParameter("term", "999-3");
    request.setParameter("username", "admin");
    request.setParameter("password", "test");

    MockHttpServletResponse response = new MockHttpServletResponse();
    HandlerAdapter handlerAdapter = new AnnotationMethodHandlerAdapter();
    handlerAdapter.handle(request, response, controller);

    Assert.assertTrue(StringUtils.isNotEmpty(response.getContentAsString()));
    Assert.assertFalse(StringUtils.contains(response.getContentAsString(), "999-3"));
}

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

@Test
public void shouldGetReferenceRepresentationOfPatientProgram() throws Exception {
    MockHttpServletRequest req = request(RequestMethod.GET, getURI() + "/" + getUuid());
    req.setParameter(RestConstants.REQUEST_PROPERTY_FOR_REPRESENTATION, Representation.REF.getRepresentation());
    SimpleObject result = deserialize(handle(req));

    Assert.assertEquals(getUuid(), PropertyUtils.getProperty(result, "uuid"));
    Assert.assertNotNull(PropertyUtils.getProperty(result, "display"));
    Assert.assertNull(PropertyUtils.getProperty(result, "patient"));
}

From source file:org.openmrs.module.clinicalsummary.web.service.PatientSearchControllerTest.java

/**
 * @verifies should return patients with name search term
 * @see org.openmrs.module.clinicalsummary.web.controller.service.PatientSearchController#searchPatient(String, String, String, javax.servlet.http.HttpServletResponse)
 *//*from  w  w w. j a  v a2s  .co  m*/
@Test
public void searchPatient_shouldReturnPatientsWithNameSearchTerm() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setMethod("GET");
    request.setRequestURI("/module/clinicalsummary/service/patient/search");
    request.setParameter("term", "Collet");
    request.setParameter("username", "admin");
    request.setParameter("password", "test");

    MockHttpServletResponse response = new MockHttpServletResponse();
    HandlerAdapter handlerAdapter = new AnnotationMethodHandlerAdapter();
    handlerAdapter.handle(request, response, controller);

    Assert.assertTrue(StringUtils.isNotEmpty(response.getContentAsString()));
    Assert.assertTrue(StringUtils.contains(response.getContentAsString(), "Collet Test Chebaskwony"));
    Assert.assertTrue(StringUtils.contains(response.getContentAsString(), "6TS-4"));
}

From source file:org.openmrs.module.clinicalsummary.web.service.PatientSearchControllerTest.java

/**
 * @verifies should return patients with identifier search term
 * @see org.openmrs.module.clinicalsummary.web.controller.service.PatientSearchController#searchPatient(String, String, String, javax.servlet.http.HttpServletResponse)
 *//* www.ja v a2 s  .co  m*/
@Test
public void searchPatient_shouldReturnPatientsWithIdentifierSearchTerm() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setMethod("GET");
    request.setRequestURI("/module/clinicalsummary/service/patient/search");
    request.setParameter("term", "6TS-4");
    request.setParameter("username", "admin");
    request.setParameter("password", "test");

    MockHttpServletResponse response = new MockHttpServletResponse();
    HandlerAdapter handlerAdapter = new AnnotationMethodHandlerAdapter();
    handlerAdapter.handle(request, response, controller);

    Assert.assertTrue(StringUtils.isNotEmpty(response.getContentAsString()));
    Assert.assertTrue(StringUtils.contains(response.getContentAsString(), "Collet Test Chebaskwony"));
    Assert.assertTrue(StringUtils.contains(response.getContentAsString(), "6TS-4"));
}