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

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

Introduction

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

Prototype

@Override
    public BufferedReader getReader() throws UnsupportedEncodingException 

Source Link

Usage

From source file:org.springframework.test.web.servlet.htmlunit.HtmlUnitRequestBuilderTest.java

@Test
public void buildRequestReader() throws Exception {
    String expectedBody = "request body";
    webRequest.setHttpMethod(HttpMethod.POST);
    webRequest.setRequestBody(expectedBody);

    MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);

    assertThat(IOUtils.toString(actualRequest.getReader())).isEqualTo(expectedBody);
}

From source file:io.pivotal.cla.mvc.github.GitHubHooksControllerTests.java

private MockHttpServletRequestBuilder hookRequest() {
    MockHttpServletRequestBuilder post = post("/github/hooks/pull_request/pivotal")
            .with(new RequestPostProcessor() {

                @Override/*from w ww . j a  v  a2 s.  c om*/
                public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) {
                    if (accessToken != null) {
                        try {
                            String signature = getSignature(request);
                            request.addHeader("X-Hub-Signature", signature);
                        } catch (Exception e) {
                            throw new RuntimeException(e);
                        }
                    }
                    return request;
                }

                private String getSignature(MockHttpServletRequest request)
                        throws IOException, UnsupportedEncodingException, Exception {
                    String body = IOUtils.toString(request.getReader());
                    String signature = oauth.create(body, accessToken.getToken());
                    return signature;
                }
            });

    return post;
}

From source file:org.springframework.test.web.servlet.htmlunit.HtmlUnitRequestBuilderTests.java

@Test
public void buildRequestReader() throws Exception {
    String expectedBody = "request body";
    webRequest.setHttpMethod(HttpMethod.POST);
    webRequest.setRequestBody(expectedBody);

    MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);

    assertThat(IOUtils.toString(actualRequest.getReader()), equalTo(expectedBody));
}