use of org.springframework.test.web.servlet.ResultMatcher in project spring-framework by spring-projects.
the class ModelResultMatchers method attributeHasFieldErrorCode.
/**
* Assert a field error code for a model attribute using exact String match.
* @since 4.1
*/
public ResultMatcher attributeHasFieldErrorCode(final String name, final String fieldName, final String error) {
return new ResultMatcher() {
public void match(MvcResult mvcResult) throws Exception {
ModelAndView mav = getModelAndView(mvcResult);
BindingResult result = getBindingResult(mav, name);
assertTrue("No errors for attribute: [" + name + "]", result.hasErrors());
boolean hasFieldErrors = result.hasFieldErrors(fieldName);
assertTrue("No errors for field: [" + fieldName + "] of attribute [" + name + "]", hasFieldErrors);
String code = result.getFieldError(fieldName).getCode();
assertTrue("Expected error code '" + error + "' but got '" + code + "'", code.equals(error));
}
};
}
use of org.springframework.test.web.servlet.ResultMatcher in project spring-framework by spring-projects.
the class RequestResultMatchers method asyncNotStarted.
/**
* Assert that asynchronous processing was not started.
* @see #asyncStarted()
*/
public ResultMatcher asyncNotStarted() {
return new ResultMatcher() {
@Override
public void match(MvcResult result) {
HttpServletRequest request = result.getRequest();
assertEquals("Async started", false, request.isAsyncStarted());
}
};
}
use of org.springframework.test.web.servlet.ResultMatcher in project spring-framework by spring-projects.
the class RequestResultMatchers method asyncResult.
/**
* Assert the result from asynchronous processing with the given matcher.
* <p>This method can be used when a controller method returns {@link Callable}
* or {@link WebAsyncTask}.
*/
public <T> ResultMatcher asyncResult(final Matcher<T> matcher) {
return new ResultMatcher() {
@Override
@SuppressWarnings("unchecked")
public void match(MvcResult result) {
HttpServletRequest request = result.getRequest();
assertAsyncStarted(request);
assertThat("Async result", (T) result.getAsyncResult(), matcher);
}
};
}
use of org.springframework.test.web.servlet.ResultMatcher in project spring-framework by spring-projects.
the class ViewResultMatchers method name.
/**
* Assert the selected view name.
*/
public ResultMatcher name(final String expectedViewName) {
return new ResultMatcher() {
@Override
public void match(MvcResult result) throws Exception {
ModelAndView mav = result.getModelAndView();
assertTrue("No ModelAndView found", mav != null);
assertEquals("View name", expectedViewName, mav.getViewName());
}
};
}
use of org.springframework.test.web.servlet.ResultMatcher in project spring-framework by spring-projects.
the class XpathResultMatchers method number.
/**
* Evaluate the XPath and assert the {@link Double} value found with the
* given Hamcrest {@link Matcher}.
*/
public ResultMatcher number(final Matcher<? super Double> matcher) {
return new ResultMatcher() {
@Override
public void match(MvcResult result) throws Exception {
MockHttpServletResponse response = result.getResponse();
xpathHelper.assertNumber(response.getContentAsByteArray(), getDefinedEncoding(response), matcher);
}
};
}
Aggregations