use of org.springframework.boot.web.servlet.server.MockServletWebServerFactory in project spring-boot by spring-projects.
the class AnnotationConfigServletWebServerApplicationContextTests 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 singleServletBean.
@Test
public void singleServletBean() throws Exception {
addWebServerFactoryBean();
Servlet servlet = mock(Servlet.class);
this.context.registerBeanDefinition("servletBean", beanDefinition(servlet));
this.context.refresh();
MockServletWebServerFactory factory = getWebServerFactory();
verify(factory.getServletContext()).addServlet("servletBean", servlet);
verify(factory.getRegisteredServlet(0).getRegistration()).addMapping("/");
}
use of org.springframework.boot.web.servlet.server.MockServletWebServerFactory in project spring-boot by spring-projects.
the class ServletWebServerApplicationContextTests method orderedBeanInsertedCorrectly.
@Test
public void orderedBeanInsertedCorrectly() throws Exception {
addWebServerFactoryBean();
OrderedFilter filter = new OrderedFilter();
this.context.registerBeanDefinition("filterBean", beanDefinition(filter));
FilterRegistrationBean<Filter> registration = new FilterRegistrationBean<>();
registration.setFilter(mock(Filter.class));
registration.setOrder(100);
this.context.registerBeanDefinition("filterRegistrationBean", beanDefinition(registration));
this.context.refresh();
MockServletWebServerFactory factory = getWebServerFactory();
verify(factory.getServletContext()).addFilter("filterBean", filter);
verify(factory.getServletContext()).addFilter("object", registration.getFilter());
assertThat(factory.getRegisteredFilter(0).getFilter()).isEqualTo(filter);
}
use of org.springframework.boot.web.servlet.server.MockServletWebServerFactory in project spring-boot by spring-projects.
the class ServletWebServerApplicationContextTests method servletAndFilterBeans.
@Test
public void servletAndFilterBeans() throws Exception {
addWebServerFactoryBean();
Servlet servlet = mock(Servlet.class);
Filter filter1 = mock(Filter.class, withSettings().extraInterfaces(Ordered.class));
given(((Ordered) filter1).getOrder()).willReturn(1);
Filter filter2 = mock(Filter.class, withSettings().extraInterfaces(Ordered.class));
given(((Ordered) filter2).getOrder()).willReturn(2);
this.context.registerBeanDefinition("servletBean", beanDefinition(servlet));
this.context.registerBeanDefinition("filterBean2", beanDefinition(filter2));
this.context.registerBeanDefinition("filterBean1", beanDefinition(filter1));
this.context.refresh();
MockServletWebServerFactory factory = getWebServerFactory();
ServletContext servletContext = factory.getServletContext();
InOrder ordered = inOrder(servletContext);
verify(factory.getServletContext()).addServlet("servletBean", servlet);
verify(factory.getRegisteredServlet(0).getRegistration()).addMapping("/");
ordered.verify(factory.getServletContext()).addFilter("filterBean1", filter1);
ordered.verify(factory.getServletContext()).addFilter("filterBean2", filter2);
verify(factory.getRegisteredFilter(0).getRegistration()).addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, "/*");
verify(factory.getRegisteredFilter(1).getRegistration()).addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, "/*");
}
use of org.springframework.boot.web.servlet.server.MockServletWebServerFactory in project spring-boot by spring-projects.
the class ServletWebServerApplicationContextTests method startRegistrations.
@Test
public void startRegistrations() throws Exception {
addWebServerFactoryBean();
this.context.refresh();
MockServletWebServerFactory factory = getWebServerFactory();
// Ensure that the context has been setup
assertThat(this.context.getServletContext()).isEqualTo(factory.getServletContext());
verify(factory.getServletContext()).setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.context);
// Ensure WebApplicationContextUtils.registerWebApplicationScopes was called
assertThat(this.context.getBeanFactory().getRegisteredScope(WebApplicationContext.SCOPE_SESSION)).isInstanceOf(SessionScope.class);
// Ensure WebApplicationContextUtils.registerEnvironmentBeans was called
assertThat(this.context.containsBean(WebApplicationContext.SERVLET_CONTEXT_BEAN_NAME)).isTrue();
}
Aggregations