use of org.springframework.web.method.support.HandlerMethodArgumentResolver in project spring-data-commons by spring-projects.
the class PageableDefaultUnitTests method rejectsInvalidQulifiers.
@Test
public void rejectsInvalidQulifiers() throws Exception {
MethodParameter parameter = TestUtils.getParameterOfMethod(getControllerClass(), "invalidQualifiers", Pageable.class, Pageable.class);
HandlerMethodArgumentResolver resolver = getResolver();
assertThat(resolver.supportsParameter(parameter)).isTrue();
exception.expect(IllegalStateException.class);
exception.expectMessage("unique");
resolver.resolveArgument(parameter, null, TestUtils.getWebRequest(), null);
}
use of org.springframework.web.method.support.HandlerMethodArgumentResolver in project spring-data-commons by spring-projects.
the class SortDefaultUnitTests method rejectsDoubleAnnotatedMethod.
@Test
public void rejectsDoubleAnnotatedMethod() throws Exception {
MethodParameter parameter = getParameterOfMethod("invalid");
HandlerMethodArgumentResolver resolver = new SortHandlerMethodArgumentResolver();
assertThat(resolver.supportsParameter(parameter)).isTrue();
exception.expect(IllegalArgumentException.class);
exception.expectMessage(SortDefault.class.getSimpleName());
exception.expectMessage(SortDefaults.class.getSimpleName());
exception.expectMessage(parameter.toString());
resolver.resolveArgument(parameter, null, TestUtils.getWebRequest(), null);
}
use of org.springframework.web.method.support.HandlerMethodArgumentResolver in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method typedCommandProvidingFormController.
@PathPatternsParameterizedTest
void typedCommandProvidingFormController(boolean usePathPatterns) throws Exception {
initDispatcherServlet(MyTypedCommandProvidingFormController.class, usePathPatterns, wac -> {
wac.registerBeanDefinition("viewResolver", new RootBeanDefinition(TestViewResolver.class));
RootBeanDefinition adapterDef = new RootBeanDefinition(RequestMappingHandlerAdapter.class);
adapterDef.getPropertyValues().add("webBindingInitializer", new MyWebBindingInitializer());
List<HandlerMethodArgumentResolver> argumentResolvers = new ArrayList<>();
argumentResolvers.add(new ServletWebArgumentResolverAdapter(new MySpecialArgumentResolver()));
adapterDef.getPropertyValues().add("customArgumentResolvers", argumentResolvers);
wac.registerBeanDefinition("handlerAdapter", adapterDef);
});
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myPath.do");
request.addParameter("defaultName", "10");
request.addParameter("age", "value2");
request.addParameter("date", "2007-10-02");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo("myView-Integer:10-typeMismatch-tb1-myOriginalValue");
request = new MockHttpServletRequest("GET", "/myOtherPath.do");
request.addParameter("defaultName", "10");
request.addParameter("age", "value2");
request.addParameter("date", "2007-10-02");
response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo("myView-myName-typeMismatch-tb1-myOriginalValue");
request = new MockHttpServletRequest("GET", "/myThirdPath.do");
request.addParameter("defaultName", "10");
request.addParameter("age", "100");
request.addParameter("date", "2007-10-02");
response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo("myView-special-99-special-99");
}
use of org.springframework.web.method.support.HandlerMethodArgumentResolver in project spring-framework by spring-projects.
the class RequestMappingHandlerAdapterTests method setCustomArgumentResolvers.
@Test
public void setCustomArgumentResolvers() throws Exception {
HandlerMethodArgumentResolver resolver = new ServletRequestMethodArgumentResolver();
this.handlerAdapter.setCustomArgumentResolvers(Collections.singletonList(resolver));
this.handlerAdapter.afterPropertiesSet();
assertThat(this.handlerAdapter.getArgumentResolvers().contains(resolver)).isTrue();
assertMethodProcessorCount(RESOLVER_COUNT + 1, INIT_BINDER_RESOLVER_COUNT + 1, HANDLER_COUNT);
}
use of org.springframework.web.method.support.HandlerMethodArgumentResolver in project spring-framework by spring-projects.
the class RequestMappingHandlerAdapterTests method setArgumentResolvers.
@Test
public void setArgumentResolvers() throws Exception {
HandlerMethodArgumentResolver resolver = new ServletRequestMethodArgumentResolver();
this.handlerAdapter.setArgumentResolvers(Collections.singletonList(resolver));
this.handlerAdapter.afterPropertiesSet();
assertMethodProcessorCount(1, INIT_BINDER_RESOLVER_COUNT, HANDLER_COUNT);
}
Aggregations