use of cn.taketoday.framework.web.servlet.server.MockServletWebServerFactory in project today-infrastructure by TAKETODAY.
the class ServletWebServerApplicationContextTests method orderedBeanInsertedCorrectly.
@Test
void orderedBeanInsertedCorrectly() {
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();
then(factory.getServletContext()).should().addFilter("filterBean", filter);
then(factory.getServletContext()).should().addFilter("object", registration.getFilter());
assertThat(factory.getRegisteredFilter(0).getFilter()).isEqualTo(filter);
}
use of cn.taketoday.framework.web.servlet.server.MockServletWebServerFactory in project today-infrastructure by TAKETODAY.
the class ServletWebServerApplicationContextTests method multipleServletBeansWithMainDispatcher.
@Test
void multipleServletBeansWithMainDispatcher() {
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);
then(servletContext).should(ordered).addServlet("dispatcherServlet", servlet1);
then(servletContext).should(ordered).addServlet("servletBean2", servlet2);
then(factory.getRegisteredServlet(0).getRegistration()).should().addMapping("/");
then(factory.getRegisteredServlet(1).getRegistration()).should().addMapping("/servletBean2/");
}
use of cn.taketoday.framework.web.servlet.server.MockServletWebServerFactory in project today-infrastructure by TAKETODAY.
the class ServletWebServerApplicationContextTests method startRegistrations.
@Test
void startRegistrations() {
addWebServerFactoryBean();
this.context.refresh();
MockServletWebServerFactory factory = getWebServerFactory();
// Ensure that the context has been setup
assertThat(this.context.getServletContext()).isEqualTo(factory.getServletContext());
then(factory.getServletContext()).should().setAttribute(WebServletApplicationContext.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(WebServletApplicationContext.SERVLET_CONTEXT_BEAN_NAME)).isTrue();
}
use of cn.taketoday.framework.web.servlet.server.MockServletWebServerFactory in project today-infrastructure by TAKETODAY.
the class ServletWebServerApplicationContextTests method servletAndFilterBeans.
@Test
void servletAndFilterBeans() {
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);
then(factory.getServletContext()).should().addServlet("servletBean", servlet);
then(factory.getRegisteredServlet(0).getRegistration()).should().addMapping("/");
then(factory.getServletContext()).should(ordered).addFilter("filterBean1", filter1);
then(factory.getServletContext()).should(ordered).addFilter("filterBean2", filter2);
then(factory.getRegisteredFilter(0).getRegistration()).should().addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, "/*");
then(factory.getRegisteredFilter(1).getRegistration()).should().addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, "/*");
}
use of cn.taketoday.framework.web.servlet.server.MockServletWebServerFactory in project today-infrastructure by TAKETODAY.
the class ServletWebServerApplicationContextTests method stopOnClose.
@Test
void stopOnClose() {
addWebServerFactoryBean();
this.context.refresh();
MockServletWebServerFactory factory = getWebServerFactory();
this.context.close();
then(factory.getWebServer()).should().stop();
}
Aggregations