use of org.springframework.test.web.servlet.ResultMatcher in project spring-framework by spring-projects.
the class ContentResultMatchers method contentTypeCompatibleWith.
/**
* Assert the ServletResponse content type is compatible with the given
* content type as defined by {@link MediaType#isCompatibleWith(MediaType)}.
*/
public ResultMatcher contentTypeCompatibleWith(final MediaType contentType) {
return new ResultMatcher() {
@Override
public void match(MvcResult result) throws Exception {
String actual = result.getResponse().getContentType();
assertTrue("Content type not set", actual != null);
MediaType actualContentType = MediaType.parseMediaType(actual);
assertTrue("Content type [" + actual + "] is not compatible with [" + contentType + "]", actualContentType.isCompatibleWith(contentType));
}
};
}
use of org.springframework.test.web.servlet.ResultMatcher in project spring-framework by spring-projects.
the class CookieResultMatchers method secure.
/**
* Assert whether the cookie must be sent over a secure protocol or not.
*/
public ResultMatcher secure(final String name, final boolean secure) {
return new ResultMatcher() {
@Override
public void match(MvcResult result) throws Exception {
Cookie cookie = result.getResponse().getCookie(name);
assertEquals("Response cookie secure", secure, cookie.getSecure());
}
};
}
use of org.springframework.test.web.servlet.ResultMatcher 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.ResultMatcher 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.ResultMatcher 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);
}
};
}
Aggregations