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);
}
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/");
}
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/");
}
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();
}
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);
}
Aggregations