Search in sources :

Example 6 with StubMvcResult

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

the class JsonPathResultMatchersTests method valueWithJsonPrefix.

@Test
public void valueWithJsonPrefix() throws Exception {
    String jsonPrefix = "prefix";
    StubMvcResult result = createPrefixedStubMvcResult(jsonPrefix);
    new JsonPathResultMatchers("$.str").prefix(jsonPrefix).value("foo").match(result);
}
Also used : StubMvcResult(org.springframework.test.web.servlet.StubMvcResult) Test(org.junit.Test)

Example 7 with StubMvcResult

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

the class JsonPathResultMatchersTests method valueWithJsonWrongPrefix.

@Test(expected = AssertionError.class)
public void valueWithJsonWrongPrefix() throws Exception {
    String jsonPrefix = "prefix";
    StubMvcResult result = createPrefixedStubMvcResult(jsonPrefix);
    new JsonPathResultMatchers("$.str").prefix("wrong").value("foo").match(result);
}
Also used : StubMvcResult(org.springframework.test.web.servlet.StubMvcResult) Test(org.junit.Test)

Example 8 with StubMvcResult

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

the class JsonPathResultMatchersTests method valueWithJsonPrefixNotConfigured.

@Test(expected = AssertionError.class)
public void valueWithJsonPrefixNotConfigured() throws Exception {
    String jsonPrefix = "prefix";
    StubMvcResult result = createPrefixedStubMvcResult(jsonPrefix);
    new JsonPathResultMatchers("$.str").value("foo").match(result);
}
Also used : StubMvcResult(org.springframework.test.web.servlet.StubMvcResult) Test(org.junit.Test)

Example 9 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.Test)

Example 10 with StubMvcResult

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

the class ContentResultMatchersTests method getStubMvcResult.

private StubMvcResult getStubMvcResult() throws Exception {
    MockHttpServletResponse response = new MockHttpServletResponse();
    response.addHeader("Content-Type", "application/json; charset=UTF-8");
    response.getWriter().print(new String(CONTENT.getBytes("UTF-8")));
    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)

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