use of org.springframework.test.web.servlet.MvcResult in project spring-framework by spring-projects.
the class CookieResultMatchers method exists.
/**
* Assert a cookie exists. The existence check is irrespective of whether
* max age is 0 (i.e. expired).
*/
public ResultMatcher exists(final String name) {
return new ResultMatcher() {
@Override
public void match(MvcResult result) {
Cookie cookie = result.getResponse().getCookie(name);
assertTrue("No cookie with name: " + name, cookie != null);
}
};
}
use of org.springframework.test.web.servlet.MvcResult in project spring-framework by spring-projects.
the class MockMvcClientHttpRequestFactory method createRequest.
@Override
public ClientHttpRequest createRequest(final URI uri, final HttpMethod httpMethod) throws IOException {
return new MockClientHttpRequest(httpMethod, uri) {
@Override
public ClientHttpResponse executeInternal() throws IOException {
try {
MockHttpServletRequestBuilder requestBuilder = request(httpMethod, uri);
requestBuilder.content(getBodyAsBytes());
requestBuilder.headers(getHeaders());
MvcResult mvcResult = MockMvcClientHttpRequestFactory.this.mockMvc.perform(requestBuilder).andReturn();
MockHttpServletResponse servletResponse = mvcResult.getResponse();
HttpStatus status = HttpStatus.valueOf(servletResponse.getStatus());
byte[] body = servletResponse.getContentAsByteArray();
HttpHeaders headers = getResponseHeaders(servletResponse);
MockClientHttpResponse clientResponse = new MockClientHttpResponse(body, status);
clientResponse.getHeaders().putAll(headers);
return clientResponse;
} catch (Exception ex) {
byte[] body = ex.toString().getBytes(StandardCharsets.UTF_8);
return new MockClientHttpResponse(body, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
};
}
use of org.springframework.test.web.servlet.MvcResult in project spring-framework by spring-projects.
the class CookieResultMatchers method comment.
/**
* Assert a cookie's comment value.
*/
public ResultMatcher comment(final String name, final String comment) {
return new ResultMatcher() {
@Override
public void match(MvcResult result) throws Exception {
Cookie cookie = result.getResponse().getCookie(name);
assertEquals("Response cookie comment", comment, cookie.getComment());
}
};
}
use of org.springframework.test.web.servlet.MvcResult in project spring-framework by spring-projects.
the class CookieResultMatchers method maxAge.
/**
* Assert a cookie's maxAge with a Hamcrest {@link Matcher}.
*/
public ResultMatcher maxAge(final String name, final Matcher<? super Integer> matcher) {
return new ResultMatcher() {
@Override
public void match(MvcResult result) {
Cookie cookie = result.getResponse().getCookie(name);
assertTrue("No cookie with name: " + name, cookie != null);
assertThat("Response cookie maxAge", cookie.getMaxAge(), matcher);
}
};
}
use of org.springframework.test.web.servlet.MvcResult in project spring-framework by spring-projects.
the class CookieResultMatchers method doesNotExist.
/**
* Assert a cookie does not exist. Note that the existence check is
* irrespective of whether max age is 0, i.e. expired.
*/
public ResultMatcher doesNotExist(final String name) {
return new ResultMatcher() {
@Override
public void match(MvcResult result) {
Cookie cookie = result.getResponse().getCookie(name);
assertTrue("Unexpected cookie with name " + name, cookie == null);
}
};
}
Aggregations