use of org.springframework.test.web.servlet.ResultMatcher in project spring-framework by spring-projects.
the class ModelResultMatchers method attributeHasErrors.
/**
* Assert the given model attribute(s) have errors.
*/
public ResultMatcher attributeHasErrors(final String... names) {
return new ResultMatcher() {
@Override
public void match(MvcResult mvcResult) throws Exception {
ModelAndView mav = getModelAndView(mvcResult);
for (String name : names) {
BindingResult result = getBindingResult(mav, name);
assertTrue("No errors for attribute [" + name + "]", result.hasErrors());
}
}
};
}
use of org.springframework.test.web.servlet.ResultMatcher in project spring-framework by spring-projects.
the class ModelResultMatchers method attributeHasFieldErrors.
/**
* Assert the given model attribute field(s) have errors.
*/
public ResultMatcher attributeHasFieldErrors(final String name, final String... fieldNames) {
return new ResultMatcher() {
@Override
public void match(MvcResult mvcResult) throws Exception {
ModelAndView mav = getModelAndView(mvcResult);
BindingResult result = getBindingResult(mav, name);
assertTrue("No errors for attribute: [" + name + "]", result.hasErrors());
for (final String fieldName : fieldNames) {
boolean hasFieldErrors = result.hasFieldErrors(fieldName);
assertTrue("No errors for field: [" + fieldName + "] of attribute [" + name + "]", hasFieldErrors);
}
}
};
}
use of org.springframework.test.web.servlet.ResultMatcher in project spring-framework by spring-projects.
the class CookieResultMatchers method value.
/**
* Assert a cookie value with the given Hamcrest {@link Matcher}.
*/
public ResultMatcher value(final String name, final Matcher<? super String> matcher) {
return new ResultMatcher() {
@Override
public void match(MvcResult result) {
Cookie cookie = result.getResponse().getCookie(name);
assertTrue("Response cookie not found: " + name, cookie != null);
assertThat("Response cookie", cookie.getValue(), matcher);
}
};
}
use of org.springframework.test.web.servlet.ResultMatcher in project spring-framework by spring-projects.
the class CookieResultMatchers method domain.
/**
* Assert a cookie's domain value.
*/
public ResultMatcher domain(final String name, final String domain) {
return new ResultMatcher() {
@Override
public void match(MvcResult result) throws Exception {
Cookie cookie = result.getResponse().getCookie(name);
assertEquals("Response cookie domain", domain, cookie.getDomain());
}
};
}
use of org.springframework.test.web.servlet.ResultMatcher in project spring-framework by spring-projects.
the class CookieResultMatchers method version.
/**
* Assert a cookie's version value.
*/
public ResultMatcher version(final String name, final int version) {
return new ResultMatcher() {
@Override
public void match(MvcResult result) throws Exception {
Cookie cookie = result.getResponse().getCookie(name);
assertEquals("Response cookie version", version, cookie.getVersion());
}
};
}
Aggregations