Add test for dispatcher registration
This commit is contained in:
@@ -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 {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user