Search in sources :

Example 16 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 17 with StubMvcResult

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

the class StatusResultMatchersTests method statusRanges.

@Test
public void statusRanges() throws Exception {
    for (HttpStatus status : HttpStatus.values()) {
        MockHttpServletResponse response = new MockHttpServletResponse();
        response.setStatus(status.value());
        MvcResult mvcResult = new StubMvcResult(request, null, null, null, null, null, response);
        switch(status.series().value()) {
            case 1:
                this.matchers.is1xxInformational().match(mvcResult);
                break;
            case 2:
                this.matchers.is2xxSuccessful().match(mvcResult);
                break;
            case 3:
                this.matchers.is3xxRedirection().match(mvcResult);
                break;
            case 4:
                this.matchers.is4xxClientError().match(mvcResult);
                break;
            case 5:
                this.matchers.is5xxServerError().match(mvcResult);
                break;
            default:
                fail("Unexpected range for status code value " + status);
        }
    }
}
Also used : StubMvcResult(org.springframework.test.web.servlet.StubMvcResult) HttpStatus(org.springframework.http.HttpStatus) StubMvcResult(org.springframework.test.web.servlet.StubMvcResult) MvcResult(org.springframework.test.web.servlet.MvcResult) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Aggregations

StubMvcResult (org.springframework.test.web.servlet.StubMvcResult)17 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)12 Test (org.junit.jupiter.api.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