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);
}
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);
}
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);
}
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);
}
}
}
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);
}
Aggregations