From 894940d7aae43aca51c75ac40156691b8086514e Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Mon, 4 Nov 2013 11:39:02 +0000 Subject: [PATCH] Add test for dispatcher registration --- ...ervletContainerAutoConfigurationTests.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/EmbeddedServletContainerAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/EmbeddedServletContainerAutoConfigurationTests.java index c215b80196..e3545cbb41 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/EmbeddedServletContainerAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/EmbeddedServletContainerAutoConfigurationTests.java @@ -27,6 +27,7 @@ import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletCont import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer; import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.MockEmbeddedServletContainerFactory; +import org.springframework.boot.context.embedded.ServletRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.stereotype.Component; @@ -74,6 +75,17 @@ public class EmbeddedServletContainerAutoConfigurationTests { assertEquals(2, this.context.getBeanNamesForType(DispatcherServlet.class).length); } + @Test + public void contextAlreadyHasDispatcherServletAndRegistration() throws Exception { + this.context = new AnnotationConfigEmbeddedWebApplicationContext( + DispatcherServletWithRegistrationConfiguration.class, + EmbeddedContainerConfiguration.class, + EmbeddedServletContainerAutoConfiguration.class, + DispatcherServletAutoConfiguration.class); + verifyContext(); + assertEquals(1, this.context.getBeanNamesForType(DispatcherServlet.class).length); + } + @Test public void containerHasNoServletContext() throws Exception { this.context = new AnnotationConfigEmbeddedWebApplicationContext( @@ -139,6 +151,21 @@ public class EmbeddedServletContainerAutoConfigurationTests { } + @Configuration + public static class DispatcherServletWithRegistrationConfiguration { + + @Bean(name = DispatcherServletAutoConfiguration.DEFAULT_DISPATCHER_SERVLET_BEAN_NAME) + public DispatcherServlet dispatcherServlet() { + return new DispatcherServlet(); + } + + @Bean + public ServletRegistrationBean dispatcherRegistration() { + return new ServletRegistrationBean(dispatcherServlet(), "/app/*"); + } + + } + @Component public static class EnsureContainerHasNoServletContext implements BeanPostProcessor {