Search in sources :

Example 16 with HandlerMethodArgumentResolver

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

the class ExceptionHandlerExceptionResolverTests method setArgumentResolvers.

@Test
void setArgumentResolvers() {
    HandlerMethodArgumentResolver resolver = new ServletRequestMethodArgumentResolver();
    this.resolver.setArgumentResolvers(Collections.singletonList(resolver));
    this.resolver.afterPropertiesSet();
    assertMethodProcessorCount(1, HANDLER_COUNT);
}
Also used : HandlerMethodArgumentResolver(org.springframework.web.method.support.HandlerMethodArgumentResolver) Test(org.junit.jupiter.api.Test)

Example 17 with HandlerMethodArgumentResolver

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

the class ExceptionHandlerExceptionResolverTests method setCustomArgumentResolvers.

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

Example 18 with HandlerMethodArgumentResolver

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) {
    assertThat(bean).isNotNull();
    Object value = new DirectFieldAccessor(bean).getPropertyValue("customArgumentResolvers");
    assertThat(value).isNotNull();
    assertThat(value instanceof List).isTrue();
    @SuppressWarnings("unchecked") List<HandlerMethodArgumentResolver> resolvers = (List<HandlerMethodArgumentResolver>) value;
    assertThat(resolvers.size()).isEqualTo(3);
    assertThat(resolvers.get(0) instanceof ServletWebArgumentResolverAdapter).isTrue();
    assertThat(resolvers.get(1) instanceof TestHandlerMethodArgumentResolver).isTrue();
    assertThat(resolvers.get(2) instanceof TestHandlerMethodArgumentResolver).isTrue();
    assertThat(resolvers.get(2)).isNotSameAs(resolvers.get(1));
}
Also used : DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) List(java.util.List) ServletWebArgumentResolverAdapter(org.springframework.web.servlet.mvc.method.annotation.ServletWebArgumentResolverAdapter) HandlerMethodArgumentResolver(org.springframework.web.method.support.HandlerMethodArgumentResolver)

Example 19 with HandlerMethodArgumentResolver

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(this.config.mvcContentNegotiationManager(), this.config.mvcConversionService(), this.config.mvcValidator());
    // ConversionService
    String actual = this.config.mvcConversionService().convert(new TestBean(), String.class);
    assertThat(actual).isEqualTo("converted");
    // Message converters
    List<HttpMessageConverter<?>> converters = adapter.getMessageConverters();
    assertThat(converters.size()).isEqualTo(2);
    assertThat(converters.get(0).getClass()).isEqualTo(StringHttpMessageConverter.class);
    assertThat(converters.get(1).getClass()).isEqualTo(MappingJackson2HttpMessageConverter.class);
    ObjectMapper objectMapper = ((MappingJackson2HttpMessageConverter) converters.get(1)).getObjectMapper();
    assertThat(objectMapper.getDeserializationConfig().isEnabled(DEFAULT_VIEW_INCLUSION)).isFalse();
    assertThat(objectMapper.getSerializationConfig().isEnabled(DEFAULT_VIEW_INCLUSION)).isFalse();
    assertThat(objectMapper.getDeserializationConfig().isEnabled(FAIL_ON_UNKNOWN_PROPERTIES)).isFalse();
    DirectFieldAccessor fieldAccessor = new DirectFieldAccessor(adapter);
    // Custom argument resolvers and return value handlers
    List<HandlerMethodArgumentResolver> argResolvers = (List<HandlerMethodArgumentResolver>) fieldAccessor.getPropertyValue("customArgumentResolvers");
    assertThat(argResolvers.size()).isEqualTo(1);
    List<HandlerMethodReturnValueHandler> handlers = (List<HandlerMethodReturnValueHandler>) fieldAccessor.getPropertyValue("customReturnValueHandlers");
    assertThat(handlers.size()).isEqualTo(1);
    // Async support options
    assertThat(fieldAccessor.getPropertyValue("taskExecutor").getClass()).isEqualTo(ConcurrentTaskExecutor.class);
    assertThat(fieldAccessor.getPropertyValue("asyncRequestTimeout")).isEqualTo(2500L);
    CallableProcessingInterceptor[] callableInterceptors = (CallableProcessingInterceptor[]) fieldAccessor.getPropertyValue("callableInterceptors");
    assertThat(callableInterceptors.length).isEqualTo(1);
    DeferredResultProcessingInterceptor[] deferredResultInterceptors = (DeferredResultProcessingInterceptor[]) fieldAccessor.getPropertyValue("deferredResultInterceptors");
    assertThat(deferredResultInterceptors.length).isEqualTo(1);
    assertThat(fieldAccessor.getPropertyValue("ignoreDefaultModelOnRedirect")).asInstanceOf(BOOLEAN).isFalse();
}
Also used : HandlerMethodReturnValueHandler(org.springframework.web.method.support.HandlerMethodReturnValueHandler) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) DeferredResultProcessingInterceptor(org.springframework.web.context.request.async.DeferredResultProcessingInterceptor) HandlerMethodArgumentResolver(org.springframework.web.method.support.HandlerMethodArgumentResolver) TestBean(org.springframework.beans.testfixture.beans.TestBean) CallableProcessingInterceptor(org.springframework.web.context.request.async.CallableProcessingInterceptor) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) List(java.util.List) RequestMappingHandlerAdapter(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Aggregations

HandlerMethodArgumentResolver (org.springframework.web.method.support.HandlerMethodArgumentResolver)19 Test (org.junit.jupiter.api.Test)7 ArrayList (java.util.ArrayList)5 ModelMethodProcessor (org.springframework.web.method.annotation.ModelMethodProcessor)4 Test (org.junit.Test)3 MethodParameter (org.springframework.core.MethodParameter)3 ExpressionValueMethodArgumentResolver (org.springframework.web.method.annotation.ExpressionValueMethodArgumentResolver)3 RequestParamMapMethodArgumentResolver (org.springframework.web.method.annotation.RequestParamMapMethodArgumentResolver)3 RequestParamMethodArgumentResolver (org.springframework.web.method.annotation.RequestParamMethodArgumentResolver)3 List (java.util.List)2 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)2 ErrorsMethodArgumentResolver (org.springframework.web.method.annotation.ErrorsMethodArgumentResolver)2 MapMethodProcessor (org.springframework.web.method.annotation.MapMethodProcessor)2 RequestHeaderMapMethodArgumentResolver (org.springframework.web.method.annotation.RequestHeaderMapMethodArgumentResolver)2 RequestHeaderMethodArgumentResolver (org.springframework.web.method.annotation.RequestHeaderMethodArgumentResolver)2 SessionStatusMethodArgumentResolver (org.springframework.web.method.annotation.SessionStatusMethodArgumentResolver)2 HandlerMethodReturnValueHandler (org.springframework.web.method.support.HandlerMethodReturnValueHandler)2 RequestMappingHandlerAdapter (org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 LinkedList (java.util.LinkedList)1