use of org.springframework.web.method.support.HandlerMethodArgumentResolver in project spring-framework by spring-projects.
the class RequestMappingHandlerAdapterTests method setInitBinderArgumentResolvers.
@Test
public void setInitBinderArgumentResolvers() throws Exception {
HandlerMethodArgumentResolver resolver = new ServletRequestMethodArgumentResolver();
this.handlerAdapter.setInitBinderArgumentResolvers(Collections.singletonList(resolver));
this.handlerAdapter.afterPropertiesSet();
assertMethodProcessorCount(RESOLVER_COUNT, 1, HANDLER_COUNT);
}
use of org.springframework.web.method.support.HandlerMethodArgumentResolver in project spring-framework by spring-projects.
the class RequestMappingHandlerAdapterTests method setAlwaysUseRedirectAttributes.
@Test
public void setAlwaysUseRedirectAttributes() throws Exception {
HandlerMethodArgumentResolver redirectAttributesResolver = new RedirectAttributesMethodArgumentResolver();
HandlerMethodArgumentResolver modelResolver = new ModelMethodProcessor();
HandlerMethodReturnValueHandler viewHandler = new ViewNameMethodReturnValueHandler();
this.handlerAdapter.setArgumentResolvers(Arrays.asList(redirectAttributesResolver, modelResolver));
this.handlerAdapter.setReturnValueHandlers(Collections.singletonList(viewHandler));
this.handlerAdapter.setIgnoreDefaultModelOnRedirect(true);
this.handlerAdapter.afterPropertiesSet();
this.request.setAttribute(DispatcherServlet.OUTPUT_FLASH_MAP_ATTRIBUTE, new FlashMap());
HandlerMethod handlerMethod = handlerMethod(new RedirectAttributeController(), "handle", Model.class);
ModelAndView mav = this.handlerAdapter.handle(request, response, handlerMethod);
assertTrue("Without RedirectAttributes arg, model should be empty", mav.getModel().isEmpty());
}
use of org.springframework.web.method.support.HandlerMethodArgumentResolver in project spring-framework by spring-projects.
the class TestPathHelper method testArgumentResolvers.
private void testArgumentResolvers(Object bean) {
assertNotNull(bean);
Object value = new DirectFieldAccessor(bean).getPropertyValue("customArgumentResolvers");
assertNotNull(value);
assertTrue(value instanceof List);
@SuppressWarnings("unchecked") List<HandlerMethodArgumentResolver> resolvers = (List<HandlerMethodArgumentResolver>) value;
assertEquals(3, resolvers.size());
assertTrue(resolvers.get(0) instanceof ServletWebArgumentResolverAdapter);
assertTrue(resolvers.get(1) instanceof TestHandlerMethodArgumentResolver);
assertTrue(resolvers.get(2) instanceof TestHandlerMethodArgumentResolver);
assertNotSame(resolvers.get(1), resolvers.get(2));
}
use of org.springframework.web.method.support.HandlerMethodArgumentResolver in project spring-framework by spring-projects.
the class WebMvcConfigurationSupportExtensionTests method requestMappingHandlerAdapter.
@SuppressWarnings("unchecked")
@Test
public void requestMappingHandlerAdapter() throws Exception {
RequestMappingHandlerAdapter adapter = this.config.requestMappingHandlerAdapter();
// ConversionService
String actual = this.config.mvcConversionService().convert(new TestBean(), String.class);
assertEquals("converted", actual);
// Message converters
List<HttpMessageConverter<?>> converters = adapter.getMessageConverters();
assertEquals(2, converters.size());
assertEquals(StringHttpMessageConverter.class, converters.get(0).getClass());
assertEquals(MappingJackson2HttpMessageConverter.class, converters.get(1).getClass());
ObjectMapper objectMapper = ((MappingJackson2HttpMessageConverter) converters.get(1)).getObjectMapper();
assertFalse(objectMapper.getDeserializationConfig().isEnabled(DEFAULT_VIEW_INCLUSION));
assertFalse(objectMapper.getSerializationConfig().isEnabled(DEFAULT_VIEW_INCLUSION));
assertFalse(objectMapper.getDeserializationConfig().isEnabled(FAIL_ON_UNKNOWN_PROPERTIES));
DirectFieldAccessor fieldAccessor = new DirectFieldAccessor(adapter);
// Custom argument resolvers and return value handlers
List<HandlerMethodArgumentResolver> argResolvers = (List<HandlerMethodArgumentResolver>) fieldAccessor.getPropertyValue("customArgumentResolvers");
assertEquals(1, argResolvers.size());
List<HandlerMethodReturnValueHandler> handlers = (List<HandlerMethodReturnValueHandler>) fieldAccessor.getPropertyValue("customReturnValueHandlers");
assertEquals(1, handlers.size());
// Async support options
assertEquals(ConcurrentTaskExecutor.class, fieldAccessor.getPropertyValue("taskExecutor").getClass());
assertEquals(2500L, fieldAccessor.getPropertyValue("asyncRequestTimeout"));
CallableProcessingInterceptor[] callableInterceptors = (CallableProcessingInterceptor[]) fieldAccessor.getPropertyValue("callableInterceptors");
assertEquals(1, callableInterceptors.length);
DeferredResultProcessingInterceptor[] deferredResultInterceptors = (DeferredResultProcessingInterceptor[]) fieldAccessor.getPropertyValue("deferredResultInterceptors");
assertEquals(1, deferredResultInterceptors.length);
assertEquals(false, fieldAccessor.getPropertyValue("ignoreDefaultModelOnRedirect"));
}
use of org.springframework.web.method.support.HandlerMethodArgumentResolver in project spring-framework by spring-projects.
the class ExceptionHandlerExceptionResolverTests method setArgumentResolvers.
@Test
public void setArgumentResolvers() throws Exception {
HandlerMethodArgumentResolver resolver = new ServletRequestMethodArgumentResolver();
this.resolver.setArgumentResolvers(Collections.singletonList(resolver));
this.resolver.afterPropertiesSet();
assertMethodProcessorCount(1, HANDLER_COUNT);
}
Aggregations