Search in sources :

Example 11 with StubMvcResult

use of org.springframework.test.web.servlet.StubMvcResult in project spring-framework by spring-projects.

the class JsonPathResultMatchersTests method prefixWithPayloadNotLongEnough.

@Test(expected = AssertionError.class)
public void prefixWithPayloadNotLongEnough() throws Exception {
    MockHttpServletResponse response = new MockHttpServletResponse();
    response.addHeader("Content-Type", "application/json");
    response.getWriter().print(new String("test".getBytes("ISO-8859-1")));
    StubMvcResult result = new StubMvcResult(null, null, null, null, null, null, response);
    new JsonPathResultMatchers("$.str").prefix("prefix").value("foo").match(result);
}
Also used : StubMvcResult(org.springframework.test.web.servlet.StubMvcResult) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 12 with StubMvcResult

use of org.springframework.test.web.servlet.StubMvcResult in project spring-framework by spring-projects.

the class JsonPathResultMatchersTests method createPrefixedStubMvcResult.

private StubMvcResult createPrefixedStubMvcResult(String jsonPrefix) throws Exception {
    MockHttpServletResponse response = new MockHttpServletResponse();
    response.addHeader("Content-Type", "application/json");
    response.getWriter().print(jsonPrefix + new String(RESPONSE_CONTENT.getBytes("ISO-8859-1")));
    return new StubMvcResult(null, null, null, null, null, null, response);
}
Also used : StubMvcResult(org.springframework.test.web.servlet.StubMvcResult) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Example 13 with StubMvcResult

use of org.springframework.test.web.servlet.StubMvcResult in project spring-framework by spring-projects.

the class MockMvcResultMatchersTests method getForwardedUrlStubMvcResult.

private StubMvcResult getForwardedUrlStubMvcResult(String forwardedUrl) {
    MockHttpServletResponse response = new MockHttpServletResponse();
    response.setForwardedUrl(forwardedUrl);
    StubMvcResult mvcResult = new StubMvcResult(null, null, null, null, null, null, response);
    return mvcResult;
}
Also used : StubMvcResult(org.springframework.test.web.servlet.StubMvcResult) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Example 14 with StubMvcResult

use of org.springframework.test.web.servlet.StubMvcResult in project spring-framework by spring-projects.

the class MockMvcResultMatchersTests method getRedirectedUrlStubMvcResult.

private StubMvcResult getRedirectedUrlStubMvcResult(String redirectUrl) throws Exception {
    MockHttpServletResponse response = new MockHttpServletResponse();
    response.sendRedirect(redirectUrl);
    StubMvcResult mvcResult = new StubMvcResult(null, null, null, null, null, null, response);
    return mvcResult;
}
Also used : StubMvcResult(org.springframework.test.web.servlet.StubMvcResult) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Aggregations

StubMvcResult (org.springframework.test.web.servlet.StubMvcResult)14 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)9 Test (org.junit.Test)8 HttpStatus (org.springframework.http.HttpStatus)2 MvcResult (org.springframework.test.web.servlet.MvcResult)2 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 ResultMatcher (org.springframework.test.web.servlet.ResultMatcher)1 FlashMap (org.springframework.web.servlet.FlashMap)1