Search in sources :

Example 1 with MockServletWebServerFactory

use of org.springframework.boot.web.servlet.server.MockServletWebServerFactory in project spring-boot by spring-projects.

the class XmlServletWebServerApplicationContextTests method verifyContext.

private void verifyContext() {
    MockServletWebServerFactory factory = this.context.getBean(MockServletWebServerFactory.class);
    Servlet servlet = this.context.getBean(Servlet.class);
    verify(factory.getServletContext()).addServlet("servlet", servlet);
}
Also used : MockServletWebServerFactory(org.springframework.boot.web.servlet.server.MockServletWebServerFactory) Servlet(javax.servlet.Servlet)

Example 2 with MockServletWebServerFactory

use of org.springframework.boot.web.servlet.server.MockServletWebServerFactory in project spring-boot by spring-projects.

the class ServletWebServerApplicationContextTests method multipleServletBeansWithMainDispatcher.

@Test
public void multipleServletBeansWithMainDispatcher() throws Exception {
    addWebServerFactoryBean();
    Servlet servlet1 = mock(Servlet.class, withSettings().extraInterfaces(Ordered.class));
    given(((Ordered) servlet1).getOrder()).willReturn(1);
    Servlet servlet2 = mock(Servlet.class, withSettings().extraInterfaces(Ordered.class));
    given(((Ordered) servlet2).getOrder()).willReturn(2);
    this.context.registerBeanDefinition("servletBean2", beanDefinition(servlet2));
    this.context.registerBeanDefinition("dispatcherServlet", beanDefinition(servlet1));
    this.context.refresh();
    MockServletWebServerFactory factory = getWebServerFactory();
    ServletContext servletContext = factory.getServletContext();
    InOrder ordered = inOrder(servletContext);
    ordered.verify(servletContext).addServlet("dispatcherServlet", servlet1);
    ordered.verify(servletContext).addServlet("servletBean2", servlet2);
    verify(factory.getRegisteredServlet(0).getRegistration()).addMapping("/");
    verify(factory.getRegisteredServlet(1).getRegistration()).addMapping("/servletBean2/");
}
Also used : MockServletWebServerFactory(org.springframework.boot.web.servlet.server.MockServletWebServerFactory) InOrder(org.mockito.InOrder) Ordered(org.springframework.core.Ordered) Servlet(javax.servlet.Servlet) ServletContext(javax.servlet.ServletContext) Test(org.junit.Test)

Example 3 with MockServletWebServerFactory

use of org.springframework.boot.web.servlet.server.MockServletWebServerFactory in project spring-boot by spring-projects.

the class ServletWebServerApplicationContextTests method multipleServletBeans.

@Test
public void multipleServletBeans() throws Exception {
    addWebServerFactoryBean();
    Servlet servlet1 = mock(Servlet.class, withSettings().extraInterfaces(Ordered.class));
    given(((Ordered) servlet1).getOrder()).willReturn(1);
    Servlet servlet2 = mock(Servlet.class, withSettings().extraInterfaces(Ordered.class));
    given(((Ordered) servlet2).getOrder()).willReturn(2);
    this.context.registerBeanDefinition("servletBean2", beanDefinition(servlet2));
    this.context.registerBeanDefinition("servletBean1", beanDefinition(servlet1));
    this.context.refresh();
    MockServletWebServerFactory factory = getWebServerFactory();
    ServletContext servletContext = factory.getServletContext();
    InOrder ordered = inOrder(servletContext);
    ordered.verify(servletContext).addServlet("servletBean1", servlet1);
    ordered.verify(servletContext).addServlet("servletBean2", servlet2);
    verify(factory.getRegisteredServlet(0).getRegistration()).addMapping("/servletBean1/");
    verify(factory.getRegisteredServlet(1).getRegistration()).addMapping("/servletBean2/");
}
Also used : MockServletWebServerFactory(org.springframework.boot.web.servlet.server.MockServletWebServerFactory) InOrder(org.mockito.InOrder) Ordered(org.springframework.core.Ordered) Servlet(javax.servlet.Servlet) ServletContext(javax.servlet.ServletContext) Test(org.junit.Test)

Example 4 with MockServletWebServerFactory

use of org.springframework.boot.web.servlet.server.MockServletWebServerFactory in project spring-boot by spring-projects.

the class ServletWebServerApplicationContextTests method stopOnClose.

@Test
public void stopOnClose() throws Exception {
    addWebServerFactoryBean();
    this.context.refresh();
    MockServletWebServerFactory factory = getWebServerFactory();
    this.context.close();
    verify(factory.getWebServer()).stop();
}
Also used : MockServletWebServerFactory(org.springframework.boot.web.servlet.server.MockServletWebServerFactory) Test(org.junit.Test)

Example 5 with MockServletWebServerFactory

use of org.springframework.boot.web.servlet.server.MockServletWebServerFactory in project spring-boot by spring-projects.

the class ServletWebServerFactoryAutoConfigurationTests method verifyContext.

private void verifyContext() {
    MockServletWebServerFactory factory = getWebServerFactory();
    Servlet servlet = this.context.getBean(DispatcherServletAutoConfiguration.DEFAULT_DISPATCHER_SERVLET_BEAN_NAME, Servlet.class);
    verify(factory.getServletContext()).addServlet("dispatcherServlet", servlet);
}
Also used : MockServletWebServerFactory(org.springframework.boot.web.servlet.server.MockServletWebServerFactory) Servlet(javax.servlet.Servlet) FrameworkServlet(org.springframework.web.servlet.FrameworkServlet) DispatcherServlet(org.springframework.web.servlet.DispatcherServlet)

Aggregations

MockServletWebServerFactory (org.springframework.boot.web.servlet.server.MockServletWebServerFactory)10 Servlet (javax.servlet.Servlet)7 Test (org.junit.Test)7 ServletContext (javax.servlet.ServletContext)3 InOrder (org.mockito.InOrder)3 Ordered (org.springframework.core.Ordered)3 Filter (javax.servlet.Filter)2 GenericServlet (javax.servlet.GenericServlet)1 MockServlet (org.springframework.boot.testutil.MockServlet)1 FilterRegistrationBean (org.springframework.boot.web.servlet.FilterRegistrationBean)1 DispatcherServlet (org.springframework.web.servlet.DispatcherServlet)1 FrameworkServlet (org.springframework.web.servlet.FrameworkServlet)1