use of org.springframework.test.web.servlet.StubMvcResult in project spring-framework by spring-projects.
the class FlashAttributeResultMatchersTests method getStubMvcResult.
private StubMvcResult getStubMvcResult() {
FlashMap flashMap = new FlashMap();
flashMap.put("good", "good");
StubMvcResult mvcResult = new StubMvcResult(null, null, null, null, null, flashMap, null);
return mvcResult;
}
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
public void valueWithJsonWrongPrefix() throws Exception {
String jsonPrefix = "prefix";
StubMvcResult result = createPrefixedStubMvcResult(jsonPrefix);
assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> 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
public void valueWithJsonPrefixNotConfigured() throws Exception {
String jsonPrefix = "prefix";
StubMvcResult result = createPrefixedStubMvcResult(jsonPrefix);
assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> 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 testHttpStatusCodeResultMatchers.
@Test
public void testHttpStatusCodeResultMatchers() throws Exception {
List<AssertionError> failures = new ArrayList<>();
for (HttpStatus status : HttpStatus.values()) {
MockHttpServletResponse response = new MockHttpServletResponse();
response.setStatus(status.value());
MvcResult mvcResult = new StubMvcResult(request, null, null, null, null, null, response);
try {
Method method = getMethodForHttpStatus(status);
ResultMatcher matcher = (ResultMatcher) ReflectionUtils.invokeMethod(method, this.matchers);
try {
matcher.match(mvcResult);
} catch (AssertionError error) {
failures.add(error);
}
} catch (Exception ex) {
throw new Exception("Failed to obtain ResultMatcher for status " + status, ex);
}
}
if (!failures.isEmpty()) {
fail("Failed status codes: " + failures);
}
}
Aggregations