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

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

Introduction

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

Prototype

public void setQueryString(@Nullable String queryString) 

Source Link

Usage

From source file:com.google.api.server.spi.auth.EndpointsPeerAuthenticatorTest.java

private static MockHttpServletRequest createRequest(String host, int port, String servletPath,
        String contextPath, String queryString) {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addHeader("Host", host);
    request.setServerName(host);//w  w  w. j a  va 2s. c  o m
    request.setServerPort(port);
    request.setServletPath(servletPath);
    request.setQueryString(queryString);
    request.setContextPath(contextPath);
    return request;
}

From source file:net.jadler.stubbing.server.jetty.RequestUtilsTest.java

@Test
public void parameters() throws IOException {
    final MockHttpServletRequest httpRequest = prepareEmptyRequest();
    httpRequest.setQueryString("a=1&b=3");
    httpRequest.setContent("a=2".getBytes());
    httpRequest.addHeader("content-type", "application/x-www-form-urlencoded");

    final Request req = RequestUtils.convert(httpRequest);
    assertThat(req.getParameters().getKeys(), containsInAnyOrder("a", "b"));
    assertThat(req.getParameters().getValues("a"), contains("1", "2"));
    assertThat(req.getParameters().getValues("b"), contains("3"));
}

From source file:net.jadler.stubbing.server.jetty.RequestUtilsTest.java

@Test
public void parametersURLEncoded() throws IOException {
    final MockHttpServletRequest httpRequest = prepareEmptyRequest();
    httpRequest.setQueryString("param1%20name=param1%20value");
    httpRequest.setContent("param2%20name=param2%20value".getBytes());
    httpRequest.addHeader("content-type", "application/x-www-form-urlencoded");

    final Request req = RequestUtils.convert(httpRequest);
    assertThat(req.getParameters().getKeys(), containsInAnyOrder("param1%20name", "param2%20name"));
    assertThat(req.getParameters().getValues("param1%20name"), contains("param1%20value"));
    assertThat(req.getParameters().getValues("param2%20name"), contains("param2%20value"));
}

From source file:org.jasig.cas.web.NoSuchFlowExecutionExceptionResolverTests.java

public void testNoSuchFlowExecutionExeptionWithQueryString() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI("test");
    request.setQueryString("test=test");
    ModelAndView model = (this.resolver.resolveException(request, new MockHttpServletResponse(), null,
            new NoSuchFlowExecutionException(new FlowExecutionKey() {

                private static final long serialVersionUID = -4750073902540974152L;

                public String toString() {
                    return "test";
                }//from  www .  j a  v a 2s. co  m

                @Override
                public boolean equals(Object o) {
                    return true;
                }

                @Override
                public int hashCode() {
                    return 0;
                }
            }, new RuntimeException())));

    assertEquals(request.getRequestURI() + "?" + request.getQueryString(),
            ((RedirectView) model.getView()).getUrl());
}

From source file:org.apache.wink.test.mock.MockHttpServletRequestWrapperTestCase.java

@Test
public void testQuery() throws Exception {
    MockHttpServletRequest req = MockRequestConstructor.constructMockRequest("GET", "/test", "application/json",
            (String) null, null);
    req.setQueryString("x=1&y=2&z=%20");
    String x = req.getParameter("x");
    String y = req.getParameter("y");
    String z = req.getParameter("z");
    String a = req.getParameter("a");

    Assert.assertEquals("1", x);
    Assert.assertEquals("2", y);
    Assert.assertEquals(" ", z);
    Assert.assertNull(a);/* w  w  w  . j av  a 2  s .c om*/

    Assert.assertEquals(3, req.getParameterMap().size());
}

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

@Test
public void failsAuthenticationErrorGetSubject() throws Exception {
    MockHttpServletRequest mockHttpServletRequest = getRequest();
    mockHttpServletRequest.setQueryString("error=invalid_request");
    openIdConnectIdentity.setTokenEndpoint(token_endpoint);
    try {/*from   w w w  . jav a 2s.c o  m*/
        openIdConnectIdentity.getSubject(mockHttpServletRequest);
    } catch (SocialUserAuthenticationException e) {
        Assert.assertEquals(e.getMessage(), "invalid_request");
    }
}

From source file:org.jasig.cas.web.FlowExecutionExceptionResolverTests.java

@Test
public void testNoSuchFlowExecutionExeptionWithQueryString() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI("test");
    request.setQueryString("test=test");
    ModelAndView model = this.resolver.resolveException(request, new MockHttpServletResponse(), null,
            new NoSuchFlowExecutionException(new FlowExecutionKey() {

                private static final long serialVersionUID = -4750073902540974152L;

                @Override//from   www .  j  av a  2  s . co m
                public String toString() {
                    return "test";
                }

                @Override
                public boolean equals(final Object o) {
                    return true;
                }

                @Override
                public int hashCode() {
                    return 0;
                }
            }, new RuntimeException()));

    assertEquals(request.getRequestURI() + "?" + request.getQueryString(),
            ((RedirectView) model.getView()).getUrl());
}

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

@Test
public void failsAuthenticationStateMismatchGetSubject() throws Exception {
    MockHttpServletRequest mockHttpServletRequest = getRequest();
    mockHttpServletRequest.setQueryString("code=1234abcd&state=1234abcd");
    mockHttpServletRequest.getSession().setAttribute("fi.okm.mpass.state", new State("234abcd"));
    openIdConnectIdentity.setTokenEndpoint(token_endpoint);
    openIdConnectIdentity.setClientId("oauth2ClientId");
    openIdConnectIdentity.setClientSecret("oauth2ClientSecret");
    try {//from www. ja  v  a  2  s .c  om
        openIdConnectIdentity.getSubject(mockHttpServletRequest);
    } catch (SocialUserAuthenticationException e) {
        Assert.assertEquals(e.getMessage(), "State parameter not satisfied");
    }
}

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

@Test
public void failsAuthenticationNoStateGetSubject() throws Exception {
    MockHttpServletRequest mockHttpServletRequest = getRequest();
    mockHttpServletRequest.setQueryString("code=1234abcd");
    openIdConnectIdentity.setTokenEndpoint(token_endpoint);
    mockHttpServletRequest.getSession().setAttribute("fi.okm.mpass.state", new State("234abcd"));
    openIdConnectIdentity.setClientId("oauth2ClientId");
    openIdConnectIdentity.setClientSecret("oauth2ClientSecret");
    try {//from w ww  .  j a  va2  s .  c  om
        openIdConnectIdentity.getSubject(mockHttpServletRequest);
    } catch (SocialUserAuthenticationException e) {
        Assert.assertEquals(e.getMessage(), "State parameter not satisfied");
    }

}

From source file:org.hdiv.web.servlet.tags.form.FormTagTests.java

protected void extendRequest(MockHttpServletRequest request) {
    request.setRequestURI(REQUEST_URI);
    request.setQueryString("foo=bar");
    this.request = request;
}