use of javax.servlet.Servlet in project spring-boot by spring-projects.
the class ServletWebServerApplicationContextTests method servletContextInitializerBeansSkipsRegisteredServletsAndFilters.
@Test
public void servletContextInitializerBeansSkipsRegisteredServletsAndFilters() throws Exception {
addWebServerFactoryBean();
Servlet servlet = mock(Servlet.class);
Filter filter = mock(Filter.class);
ServletRegistrationBean<Servlet> initializer = new ServletRegistrationBean<>(servlet, "/foo");
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(servletContext, atMost(1)).addServlet(anyString(), (Servlet) any());
verify(servletContext, atMost(1)).addFilter(anyString(), (Filter) any());
}
use of javax.servlet.Servlet 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 javax.servlet.Servlet 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 javax.servlet.Servlet in project spring-framework by spring-projects.
the class MockFilterChainTests method doFilterWithServlet.
@Test
public void doFilterWithServlet() throws Exception {
Servlet servlet = mock(Servlet.class);
MockFilterChain chain = new MockFilterChain(servlet);
chain.doFilter(this.request, this.response);
verify(servlet).service(this.request, this.response);
try {
chain.doFilter(this.request, this.response);
fail("Expected Exception");
} catch (IllegalStateException ex) {
assertEquals("This FilterChain has already been called!", ex.getMessage());
}
}
use of javax.servlet.Servlet 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