Search in sources :

Example 11 with HandlerMethodArgumentResolver

use of org.springframework.web.method.support.HandlerMethodArgumentResolver in project spring-framework by spring-projects.

the class ExceptionHandlerExceptionResolverTests method setCustomArgumentResolvers.

@Test
public void setCustomArgumentResolvers() throws Exception {
    HandlerMethodArgumentResolver resolver = new ServletRequestMethodArgumentResolver();
    this.resolver.setCustomArgumentResolvers(Collections.singletonList(resolver));
    this.resolver.afterPropertiesSet();
    assertTrue(this.resolver.getArgumentResolvers().getResolvers().contains(resolver));
    assertMethodProcessorCount(RESOLVER_COUNT + 1, HANDLER_COUNT);
}
Also used : HandlerMethodArgumentResolver(org.springframework.web.method.support.HandlerMethodArgumentResolver) Test(org.junit.Test)

Example 12 with HandlerMethodArgumentResolver

use of org.springframework.web.method.support.HandlerMethodArgumentResolver in project spring-framework by spring-projects.

the class RequestMappingHandlerAdapterIntegrationTests method setup.

@Before
public void setup() throws Exception {
    ConfigurableWebBindingInitializer bindingInitializer = new ConfigurableWebBindingInitializer();
    bindingInitializer.setValidator(new StubValidator());
    List<HandlerMethodArgumentResolver> customResolvers = new ArrayList<>();
    customResolvers.add(new ServletWebArgumentResolverAdapter(new ColorArgumentResolver()));
    GenericWebApplicationContext context = new GenericWebApplicationContext();
    context.refresh();
    handlerAdapter = new RequestMappingHandlerAdapter();
    handlerAdapter.setWebBindingInitializer(bindingInitializer);
    handlerAdapter.setCustomArgumentResolvers(customResolvers);
    handlerAdapter.setApplicationContext(context);
    handlerAdapter.setBeanFactory(context.getBeanFactory());
    handlerAdapter.afterPropertiesSet();
    request = new MockHttpServletRequest();
    response = new MockHttpServletResponse();
    request.setMethod("POST");
    // Expose request to the current thread (for SpEL expressions)
    RequestContextHolder.setRequestAttributes(new ServletWebRequest(request));
}
Also used : ConfigurableWebBindingInitializer(org.springframework.web.bind.support.ConfigurableWebBindingInitializer) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) ArrayList(java.util.ArrayList) HandlerMethodArgumentResolver(org.springframework.web.method.support.HandlerMethodArgumentResolver) GenericWebApplicationContext(org.springframework.web.context.support.GenericWebApplicationContext) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) Before(org.junit.Before)

Aggregations

HandlerMethodArgumentResolver (org.springframework.web.method.support.HandlerMethodArgumentResolver)12 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)4 ModelMethodProcessor (org.springframework.web.method.annotation.ModelMethodProcessor)3 List (java.util.List)2 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)2 ExpressionValueMethodArgumentResolver (org.springframework.web.method.annotation.ExpressionValueMethodArgumentResolver)2 RequestParamMapMethodArgumentResolver (org.springframework.web.method.annotation.RequestParamMapMethodArgumentResolver)2 RequestParamMethodArgumentResolver (org.springframework.web.method.annotation.RequestParamMethodArgumentResolver)2 HandlerMethodReturnValueHandler (org.springframework.web.method.support.HandlerMethodReturnValueHandler)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Before (org.junit.Before)1 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)1 StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)1 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)1 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)1 TestBean (org.springframework.tests.sample.beans.TestBean)1 ConfigurableWebBindingInitializer (org.springframework.web.bind.support.ConfigurableWebBindingInitializer)1 ServletWebRequest (org.springframework.web.context.request.ServletWebRequest)1