use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.
the class DefaultHandlerExceptionResolverTests method handleMissingPathVariable.
@Test
public void handleMissingPathVariable() throws NoSuchMethodException {
Method method = getClass().getMethod("handle", String.class);
MethodParameter parameter = new MethodParameter(method, 0);
MissingPathVariableException ex = new MissingPathVariableException("foo", parameter);
ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex);
assertNotNull("No ModelAndView returned", mav);
assertTrue("No Empty ModelAndView returned", mav.isEmpty());
assertEquals("Invalid status code", 500, response.getStatus());
assertEquals("Missing URI template variable 'foo' for method parameter of type String", response.getErrorMessage());
}
use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.
the class DefaultHandlerExceptionResolverTests method handleMethodArgumentNotValid.
@Test
public void handleMethodArgumentNotValid() throws Exception {
BeanPropertyBindingResult errors = new BeanPropertyBindingResult(new TestBean(), "testBean");
errors.rejectValue("name", "invalid");
MethodParameter parameter = new MethodParameter(this.getClass().getMethod("handle", String.class), 0);
MethodArgumentNotValidException ex = new MethodArgumentNotValidException(parameter, errors);
ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex);
assertNotNull("No ModelAndView returned", mav);
assertTrue("No Empty ModelAndView returned", mav.isEmpty());
assertEquals("Invalid status code", 400, response.getStatus());
}
use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.
the class ServletResponseMethodArgumentResolverTests method servletResponseNoMavContainer.
// SPR-8983
@Test
public void servletResponseNoMavContainer() throws Exception {
MethodParameter servletResponseParameter = new MethodParameter(method, 0);
assertTrue("ServletResponse not supported", resolver.supportsParameter(servletResponseParameter));
Object result = resolver.resolveArgument(servletResponseParameter, null, webRequest, null);
assertSame("Invalid result", servletResponse, result);
}
use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.
the class ServletResponseMethodArgumentResolverTests method writer.
@Test
public void writer() throws Exception {
MethodParameter writerParameter = new MethodParameter(method, 2);
assertTrue("Writer not supported", resolver.supportsParameter(writerParameter));
Object result = resolver.resolveArgument(writerParameter, mavContainer, webRequest, null);
assertSame("Invalid result", servletResponse.getWriter(), result);
assertTrue(mavContainer.isRequestHandled());
}
use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.
the class ServletResponseMethodArgumentResolverTests method servletResponse.
@Test
public void servletResponse() throws Exception {
MethodParameter servletResponseParameter = new MethodParameter(method, 0);
assertTrue("ServletResponse not supported", resolver.supportsParameter(servletResponseParameter));
Object result = resolver.resolveArgument(servletResponseParameter, mavContainer, webRequest, null);
assertSame("Invalid result", servletResponse, result);
assertTrue(mavContainer.isRequestHandled());
}
Aggregations