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.jasig.cas.authentication.principal.GoogleAccountsServiceTests.java

public static GoogleAccountsService getGoogleAccountsService() throws Exception {
    final PublicKeyFactoryBean pubKeyFactoryBean = new PublicKeyFactoryBean();
    pubKeyFactoryBean.setAlgorithm("DSA");
    final PrivateKeyFactoryBean privKeyFactoryBean = new PrivateKeyFactoryBean();
    privKeyFactoryBean.setAlgorithm("DSA");

    final ClassPathResource pubKeyResource = new ClassPathResource("DSAPublicKey01.key");
    final ClassPathResource privKeyResource = new ClassPathResource("DSAPrivateKey01.key");

    pubKeyFactoryBean.setLocation(pubKeyResource);
    privKeyFactoryBean.setLocation(privKeyResource);
    pubKeyFactoryBean.afterPropertiesSet();
    privKeyFactoryBean.afterPropertiesSet();

    final DSAPrivateKey privateKey = (DSAPrivateKey) privKeyFactoryBean.getObject();
    final DSAPublicKey publicKey = (DSAPublicKey) pubKeyFactoryBean.getObject();

    final MockHttpServletRequest request = new MockHttpServletRequest();

    final String SAMLRequest = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><samlp:AuthnRequest xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\" ID=\"5545454455\" Version=\"2.0\" IssueInstant=\"Value\" ProtocolBinding=\"urn:oasis:names.tc:SAML:2.0:bindings:HTTP-Redirect\" ProviderName=\"https://localhost:8443/myRutgers\" AssertionConsumerServiceURL=\"https://localhost:8443/myRutgers\"/>";
    request.setParameter("SAMLRequest", encodeMessage(SAMLRequest));

    return GoogleAccountsService.createServiceFrom(request, privateKey, publicKey, "username");
}

From source file:org.openmrs.web.attribute.handler.SerializingFieldGenDatatypeHandlerTest.java

/**
 * @verifies return the correct typed value
 * @see SerializingFieldGenDatatypeHandler#getValue(org.openmrs.customdatatype.SerializingCustomDatatype,
 *      javax.servlet.http.HttpServletRequest, String)
 *///w  ww  . j  a  v a2  s.c  o  m
@Test
public void getValue_shouldReturnTheCorrectTypedValue() throws Exception {
    final String locationUuid = "some uuid";
    final String formFieldName = "uuid";
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter(formFieldName, locationUuid);
    Location expectedLocation = mock(Location.class);
    MockLocationDatatype datatype = mock(MockLocationDatatype.class);
    when(datatype.deserialize(eq(locationUuid))).thenReturn(expectedLocation);
    SerializingFieldGenDatatypeHandler handler = new MockLocationFieldGenDatatypeHandler();
    Assert.assertEquals(expectedLocation, handler.getValue(datatype, request, formFieldName));
}

From source file:org.jasig.cas.web.support.SamlArgumentExtractorTests.java

public void testObtainService() {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter("TARGET", "test");
    final Service service = this.extractor.extractService(request);
    assertEquals("test", service.getId());
}

From source file:com.google.api.server.spi.config.model.StandardParametersTest.java

@Test
public void shouldPrettyPrint_false() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter("prettyPrint", "false");
    assertThat(StandardParameters.shouldPrettyPrint(request)).isFalse();
}

From source file:com.google.api.server.spi.config.model.StandardParametersTest.java

@Test
public void shouldPrettyPrint_true() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter("prettyPrint", "true");
    assertThat(StandardParameters.shouldPrettyPrint(request)).isTrue();
}

From source file:org.jasig.cas.authentication.principal.SamlServiceTests.java

public void testResponseForJsession() {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter("TARGET", "http://www.cnn.com/;jsession=test");
    final SamlService impl = SamlService.createServiceFrom(request, null);

    assertEquals("http://www.cnn.com/", impl.getId());
}

From source file:org.cloudfoundry.identity.uaa.authentication.AuthzAuthenticationFilterTests.java

@Test
public void authenticatesValidUser() throws Exception {

    String msg = "{ \"username\":\"marissa\", \"password\":\"koala\"}";

    AuthenticationManager am = mock(AuthenticationManager.class);
    Authentication result = mock(Authentication.class);
    when(am.authenticate(any(AuthzAuthenticationRequest.class))).thenReturn(result);
    AuthzAuthenticationFilter filter = new AuthzAuthenticationFilter(am);

    MockHttpServletRequest request = new MockHttpServletRequest("POST", "/oauth/authorize");
    request.setParameter("credentials", msg);
    MockHttpServletResponse response = new MockHttpServletResponse();

    filter.doFilter(request, response, new MockFilterChain());

}

From source file:org.jasig.cas.authentication.principal.SamlServiceTests.java

public void testResponse() {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter("TARGET", "service");
    final SamlService impl = SamlService.createServiceFrom(request, null);

    final Response response = impl.getResponse("ticketId");
    assertNotNull(response);/*  w  ww . j  a v a 2  s  .com*/
    assertEquals(ResponseType.REDIRECT, response.getResponseType());
    assertTrue(response.getUrl().contains("SAMLart="));
}

From source file:org.jasig.cas.authentication.principal.SamlServiceTests.java

public void testResponseWithNoTicket() {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter("TARGET", "service");
    final SamlService impl = SamlService.createServiceFrom(request, null);

    final Response response = impl.getResponse(null);
    assertNotNull(response);//from   ww  w  . j  ava2  s.c o  m
    assertEquals(ResponseType.REDIRECT, response.getResponseType());
    assertFalse(response.getUrl().contains("SAMLart="));
}

From source file:org.jasig.cas.web.support.WebUtilTests.java

public void testFoundNoService() {
    final SamlArgumentExtractor openIdArgumentExtractor = new SamlArgumentExtractor();
    final ArgumentExtractor[] argumentExtractors = new ArgumentExtractor[] { openIdArgumentExtractor };
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter("service", "test");

    final Service service = WebUtils.getService(Arrays.asList(argumentExtractors), request);

    assertNull(service);// w ww  .j av  a 2 s . c  o  m
}