use of org.springframework.test.web.servlet.MvcResult in project spring-framework by spring-projects.
the class CookieResultMatchers method value.
/**
* Assert a cookie value.
*/
public ResultMatcher value(final String name, final String expectedValue) {
return new ResultMatcher() {
@Override
public void match(MvcResult result) {
Cookie cookie = result.getResponse().getCookie(name);
assertTrue("Response cookie not found: " + name, cookie != null);
assertEquals("Response cookie", expectedValue, cookie.getValue());
}
};
}
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 value.
*/
public ResultMatcher maxAge(final String name, final int maxAge) {
return new ResultMatcher() {
@Override
public void match(MvcResult result) {
Cookie cookie = result.getResponse().getCookie(name);
assertTrue("No cookie with name: " + name, cookie != null);
assertEquals("Response cookie maxAge", maxAge, cookie.getMaxAge());
}
};
}
use of org.springframework.test.web.servlet.MvcResult in project spring-framework by spring-projects.
the class HandlerResultMatchers method method.
/**
* Assert the controller method used to process the request.
*/
public ResultMatcher method(final Method method) {
return new ResultMatcher() {
@Override
public void match(MvcResult result) throws Exception {
HandlerMethod handlerMethod = getHandlerMethod(result);
assertEquals("Handler method", method, handlerMethod.getMethod());
}
};
}
use of org.springframework.test.web.servlet.MvcResult in project spring-framework by spring-projects.
the class HandlerResultMatchers method methodName.
/**
* Assert the name of the controller method used to process the request
* using the given Hamcrest {@link Matcher}.
*/
public ResultMatcher methodName(final Matcher<? super String> matcher) {
return new ResultMatcher() {
@Override
public void match(MvcResult result) throws Exception {
HandlerMethod handlerMethod = getHandlerMethod(result);
assertThat("Handler method", handlerMethod.getMethod().getName(), matcher);
}
};
}
use of org.springframework.test.web.servlet.MvcResult in project spring-framework by spring-projects.
the class HeaderResultMatchers method dateValue.
/**
* Assert the primary value of the named response header as a date String,
* using the preferred date format described in RFC 7231.
* <p>The {@link ResultMatcher} returned by this method throws an
* {@link AssertionError} if the response does not contain the specified
* header, or if the supplied {@code value} does not match the primary value.
* @see <a href="https://tools.ietf.org/html/rfc7231#section-7.1.1.1">Section 7.1.1.1 of RFC 7231</a>
* @since 4.2
*/
public ResultMatcher dateValue(final String name, final long value) {
return new ResultMatcher() {
@Override
public void match(MvcResult result) {
SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
format.setTimeZone(TimeZone.getTimeZone("GMT"));
String formatted = format.format(new Date(value));
MockHttpServletResponse response = result.getResponse();
assertTrue("Response does not contain header " + name, response.containsHeader(name));
assertEquals("Response header " + name, formatted, response.getHeader(name));
}
};
}
Aggregations