use of org.springframework.boot.web.servlet.ServletContextInitializer in project spring-boot by spring-projects.
the class AbstractServletWebServerFactoryTests method startBlocksUntilReadyToServe.
@Test
public void startBlocksUntilReadyToServe() throws Exception {
AbstractServletWebServerFactory factory = getFactory();
final Date[] date = new Date[1];
this.webServer = factory.getWebServer(new ServletContextInitializer() {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
try {
Thread.sleep(500);
date[0] = new Date();
} catch (InterruptedException ex) {
throw new ServletException(ex);
}
}
});
this.webServer.start();
assertThat(date[0]).isNotNull();
}
use of org.springframework.boot.web.servlet.ServletContextInitializer in project spring-boot by spring-projects.
the class AbstractServletWebServerFactoryTests method multipleConfigurations.
@Test
public void multipleConfigurations() throws Exception {
AbstractServletWebServerFactory factory = getFactory();
ServletContextInitializer[] initializers = new ServletContextInitializer[6];
for (int i = 0; i < initializers.length; i++) {
initializers[i] = mock(ServletContextInitializer.class);
}
factory.setInitializers(Arrays.asList(initializers[2], initializers[3]));
factory.addInitializers(initializers[4], initializers[5]);
this.webServer = factory.getWebServer(initializers[0], initializers[1]);
this.webServer.start();
InOrder ordered = inOrder((Object[]) initializers);
for (ServletContextInitializer initializer : initializers) {
ordered.verify(initializer).onStartup((ServletContext) any());
}
}
use of org.springframework.boot.web.servlet.ServletContextInitializer in project spring-boot by spring-projects.
the class ServletWebServerApplicationContextTests method servletContextInitializerBeans.
@Test
public void servletContextInitializerBeans() throws Exception {
addWebServerFactoryBean();
ServletContextInitializer initializer1 = mock(ServletContextInitializer.class, withSettings().extraInterfaces(Ordered.class));
given(((Ordered) initializer1).getOrder()).willReturn(1);
ServletContextInitializer initializer2 = mock(ServletContextInitializer.class, withSettings().extraInterfaces(Ordered.class));
given(((Ordered) initializer2).getOrder()).willReturn(2);
this.context.registerBeanDefinition("initializerBean2", beanDefinition(initializer2));
this.context.registerBeanDefinition("initializerBean1", beanDefinition(initializer1));
this.context.refresh();
ServletContext servletContext = getWebServerFactory().getServletContext();
InOrder ordered = inOrder(initializer1, initializer2);
ordered.verify(initializer1).onStartup(servletContext);
ordered.verify(initializer2).onStartup(servletContext);
}
use of org.springframework.boot.web.servlet.ServletContextInitializer in project spring-boot by spring-projects.
the class ServletWebServerApplicationContextTests method servletContextInitializerBeansDoesNotSkipServletsAndFilters.
@Test
public void servletContextInitializerBeansDoesNotSkipServletsAndFilters() throws Exception {
addWebServerFactoryBean();
ServletContextInitializer initializer = mock(ServletContextInitializer.class);
Servlet servlet = mock(Servlet.class);
Filter filter = mock(Filter.class);
this.context.registerBeanDefinition("initializerBean", beanDefinition(initializer));
this.context.registerBeanDefinition("servletBean", beanDefinition(servlet));
this.context.registerBeanDefinition("filterBean", beanDefinition(filter));
this.context.refresh();
ServletContext servletContext = getWebServerFactory().getServletContext();
verify(initializer).onStartup(servletContext);
verify(servletContext).addServlet(anyString(), (Servlet) any());
verify(servletContext).addFilter(anyString(), (Filter) any());
}
Aggregations