Commit 894940d7 authored by Dave Syer's avatar Dave Syer

Add test for dispatcher registration

parent b631c113
......@@ -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 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment