Search in sources :

Example 11 with RequestMappingHandlerAdapter

use of org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter in project spring-framework by spring-projects.

the class TestPathHelper method testMessageCodesResolver.

@Test
public void testMessageCodesResolver() {
    loadBeanDefinitions("mvc-config-message-codes-resolver.xml");
    RequestMappingHandlerAdapter adapter = this.appContext.getBean(RequestMappingHandlerAdapter.class);
    assertNotNull(adapter);
    Object initializer = adapter.getWebBindingInitializer();
    assertNotNull(initializer);
    MessageCodesResolver resolver = ((ConfigurableWebBindingInitializer) initializer).getMessageCodesResolver();
    assertNotNull(resolver);
    assertEquals(TestMessageCodesResolver.class, resolver.getClass());
    assertEquals(false, new DirectFieldAccessor(adapter).getPropertyValue("ignoreDefaultModelOnRedirect"));
}
Also used : ConfigurableWebBindingInitializer(org.springframework.web.bind.support.ConfigurableWebBindingInitializer) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) RequestMappingHandlerAdapter(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter) MessageCodesResolver(org.springframework.validation.MessageCodesResolver) Test(org.junit.Test)

Example 12 with RequestMappingHandlerAdapter

use of org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter in project spring-framework by spring-projects.

the class DelegatingWebMvcConfigurationTests method requestMappingHandlerAdapter.

@Test
public void requestMappingHandlerAdapter() throws Exception {
    delegatingConfig.setConfigurers(Collections.singletonList(webMvcConfigurer));
    RequestMappingHandlerAdapter adapter = delegatingConfig.requestMappingHandlerAdapter();
    ConfigurableWebBindingInitializer initializer = (ConfigurableWebBindingInitializer) adapter.getWebBindingInitializer();
    ConversionService initializerConversionService = initializer.getConversionService();
    assertTrue(initializer.getValidator() instanceof LocalValidatorFactoryBean);
    verify(webMvcConfigurer).configureMessageConverters(converters.capture());
    verify(webMvcConfigurer).configureContentNegotiation(contentNegotiationConfigurer.capture());
    verify(webMvcConfigurer).addFormatters(conversionService.capture());
    verify(webMvcConfigurer).addArgumentResolvers(resolvers.capture());
    verify(webMvcConfigurer).addReturnValueHandlers(handlers.capture());
    verify(webMvcConfigurer).configureAsyncSupport(asyncConfigurer.capture());
    assertSame(conversionService.getValue(), initializerConversionService);
    assertEquals(0, resolvers.getValue().size());
    assertEquals(0, handlers.getValue().size());
    assertEquals(converters.getValue(), adapter.getMessageConverters());
    assertNotNull(asyncConfigurer);
}
Also used : LocalValidatorFactoryBean(org.springframework.validation.beanvalidation.LocalValidatorFactoryBean) ConfigurableWebBindingInitializer(org.springframework.web.bind.support.ConfigurableWebBindingInitializer) ConversionService(org.springframework.core.convert.ConversionService) FormattingConversionService(org.springframework.format.support.FormattingConversionService) RequestMappingHandlerAdapter(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter) Test(org.junit.Test)

Example 13 with RequestMappingHandlerAdapter

use of org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter in project spring-framework by spring-projects.

the class MvcNamespaceTests method testAsyncSupportOptions.

@Test
public void testAsyncSupportOptions() throws Exception {
    loadBeanDefinitions("mvc-config-async-support.xml", 15);
    RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class);
    assertNotNull(adapter);
    DirectFieldAccessor fieldAccessor = new DirectFieldAccessor(adapter);
    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);
}
Also used : DeferredResultProcessingInterceptor(org.springframework.web.context.request.async.DeferredResultProcessingInterceptor) CallableProcessingInterceptor(org.springframework.web.context.request.async.CallableProcessingInterceptor) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) RequestMappingHandlerAdapter(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter) Test(org.junit.Test)

Example 14 with RequestMappingHandlerAdapter

use of org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter in project spring-framework by spring-projects.

the class MvcNamespaceTests method doTestCustomValidator.

private void doTestCustomValidator(String xml) throws Exception {
    loadBeanDefinitions(xml, 14);
    RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class);
    assertNotNull(mapping);
    assertFalse(mapping.getUrlPathHelper().shouldRemoveSemicolonContent());
    RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class);
    assertNotNull(adapter);
    assertEquals(true, new DirectFieldAccessor(adapter).getPropertyValue("ignoreDefaultModelOnRedirect"));
    // default web binding initializer behavior test
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter("date", "2009-10-31");
    MockHttpServletResponse response = new MockHttpServletResponse();
    adapter.handle(request, response, handlerMethod);
    assertTrue(appContext.getBean(TestValidator.class).validatorInvoked);
    assertFalse(handler.recordedValidationError);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) RequestMappingHandlerMapping(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping) RequestMappingHandlerAdapter(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse)

Example 15 with RequestMappingHandlerAdapter

use of org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter in project spring-framework by spring-projects.

the class WebMvcConfigurationSupportTests method customArgumentResolvers.

@Test
public void customArgumentResolvers() {
    ApplicationContext context = initContext(CustomArgumentResolverConfig.class);
    RequestMappingHandlerAdapter adapter = context.getBean(RequestMappingHandlerAdapter.class);
    HandlerExceptionResolverComposite composite = context.getBean(HandlerExceptionResolverComposite.class);
    assertNotNull(adapter);
    assertEquals(1, adapter.getCustomArgumentResolvers().size());
    assertEquals(TestArgumentResolver.class, adapter.getCustomArgumentResolvers().get(0).getClass());
    assertEquals(1, adapter.getCustomReturnValueHandlers().size());
    assertEquals(TestReturnValueHandler.class, adapter.getCustomReturnValueHandlers().get(0).getClass());
    assertNotNull(composite);
    assertEquals(3, composite.getExceptionResolvers().size());
    assertEquals(ExceptionHandlerExceptionResolver.class, composite.getExceptionResolvers().get(0).getClass());
    ExceptionHandlerExceptionResolver resolver = (ExceptionHandlerExceptionResolver) composite.getExceptionResolvers().get(0);
    assertEquals(1, resolver.getCustomArgumentResolvers().size());
    assertEquals(TestArgumentResolver.class, resolver.getCustomArgumentResolvers().get(0).getClass());
    assertEquals(1, resolver.getCustomReturnValueHandlers().size());
    assertEquals(TestReturnValueHandler.class, resolver.getCustomReturnValueHandlers().get(0).getClass());
}
Also used : ExceptionHandlerExceptionResolver(org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) HandlerExceptionResolverComposite(org.springframework.web.servlet.handler.HandlerExceptionResolverComposite) RequestMappingHandlerAdapter(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter) Test(org.junit.Test)

Aggregations

RequestMappingHandlerAdapter (org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter)21 Test (org.junit.Test)17 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)6 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)5 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)4 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)4 ConfigurableWebBindingInitializer (org.springframework.web.bind.support.ConfigurableWebBindingInitializer)4 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)4 RequestMappingHandlerMapping (org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 ConversionService (org.springframework.core.convert.ConversionService)3 LocalValidatorFactoryBean (org.springframework.validation.beanvalidation.LocalValidatorFactoryBean)3 HandlerExecutionChain (org.springframework.web.servlet.HandlerExecutionChain)3 ConversionServiceExposingInterceptor (org.springframework.web.servlet.handler.ConversionServiceExposingInterceptor)3 List (java.util.List)2 ApplicationContext (org.springframework.context.ApplicationContext)2 Bean (org.springframework.context.annotation.Bean)2 FormattingConversionService (org.springframework.format.support.FormattingConversionService)2 ContentNegotiationManager (org.springframework.web.accept.ContentNegotiationManager)2 HandlerExceptionResolverComposite (org.springframework.web.servlet.handler.HandlerExceptionResolverComposite)2