Search in sources :

Example 1 with ServletContextInitializer

use of cn.taketoday.framework.web.servlet.ServletContextInitializer in project today-infrastructure by TAKETODAY.

the class AbstractServletWebServerFactoryTests method multipleConfigurations.

@Test
void multipleConfigurations() throws Exception {
    AbstractServletWebServerFactory factory = getFactory();
    ServletContextInitializer[] initializers = new ServletContextInitializer[6];
    Arrays.setAll(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) {
        then(initializer).should(ordered).onStartup(any(ServletContext.class));
    }
}
Also used : InOrder(org.mockito.InOrder) ServletContext(jakarta.servlet.ServletContext) ServletContextInitializer(cn.taketoday.framework.web.servlet.ServletContextInitializer) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 2 with ServletContextInitializer

use of cn.taketoday.framework.web.servlet.ServletContextInitializer in project today-infrastructure by TAKETODAY.

the class ServletWebServerApplicationContextTests method servletContextInitializerBeans.

@Test
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);
    then(initializer1).should(ordered).onStartup(servletContext);
    then(initializer2).should(ordered).onStartup(servletContext);
}
Also used : InOrder(org.mockito.InOrder) Ordered(cn.taketoday.core.Ordered) ServletContext(jakarta.servlet.ServletContext) ServletContextInitializer(cn.taketoday.framework.web.servlet.ServletContextInitializer) Test(org.junit.jupiter.api.Test)

Example 3 with ServletContextInitializer

use of cn.taketoday.framework.web.servlet.ServletContextInitializer in project today-infrastructure by TAKETODAY.

the class ServletWebServerApplicationContextTests method unorderedServletContextInitializerBeans.

@Test
void unorderedServletContextInitializerBeans() throws Exception {
    addWebServerFactoryBean();
    ServletContextInitializer initializer1 = mock(ServletContextInitializer.class);
    ServletContextInitializer initializer2 = mock(ServletContextInitializer.class);
    this.context.registerBeanDefinition("initializerBean2", beanDefinition(initializer2));
    this.context.registerBeanDefinition("initializerBean1", beanDefinition(initializer1));
    this.context.refresh();
    ServletContext servletContext = getWebServerFactory().getServletContext();
    then(initializer1).should().onStartup(servletContext);
    then(initializer2).should().onStartup(servletContext);
}
Also used : ServletContext(jakarta.servlet.ServletContext) ServletContextInitializer(cn.taketoday.framework.web.servlet.ServletContextInitializer) Test(org.junit.jupiter.api.Test)

Example 4 with ServletContextInitializer

use of cn.taketoday.framework.web.servlet.ServletContextInitializer in project today-framework by TAKETODAY.

the class AbstractServletWebServerFactoryTests method multipleConfigurations.

@Test
void multipleConfigurations() throws Exception {
    AbstractServletWebServerFactory factory = getFactory();
    ServletContextInitializer[] initializers = new ServletContextInitializer[6];
    Arrays.setAll(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) {
        then(initializer).should(ordered).onStartup(any(ServletContext.class));
    }
}
Also used : InOrder(org.mockito.InOrder) ServletContext(jakarta.servlet.ServletContext) ServletContextInitializer(cn.taketoday.framework.web.servlet.ServletContextInitializer) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 5 with ServletContextInitializer

use of cn.taketoday.framework.web.servlet.ServletContextInitializer in project today-framework by TAKETODAY.

the class ServletWebServerApplicationContext method selfInitialize.

private void selfInitialize(ServletContext servletContext) throws ServletException {
    prepareWebApplicationContext(servletContext);
    registerApplicationScope(servletContext);
    WebApplicationContextUtils.registerEnvironmentBeans(getBeanFactory(), servletContext);
    for (ServletContextInitializer beans : getServletContextInitializerBeans()) {
        beans.onStartup(servletContext);
    }
}
Also used : ServletContextInitializer(cn.taketoday.framework.web.servlet.ServletContextInitializer)

Aggregations

ServletContextInitializer (cn.taketoday.framework.web.servlet.ServletContextInitializer)10 ServletContext (jakarta.servlet.ServletContext)8 Test (org.junit.jupiter.api.Test)8 InOrder (org.mockito.InOrder)4 Ordered (cn.taketoday.core.Ordered)2 Filter (jakarta.servlet.Filter)2 Servlet (jakarta.servlet.Servlet)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2