use of cn.taketoday.framework.web.servlet.FilterRegistrationBean 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.FilterRegistrationBean in project today-infrastructure by TAKETODAY.
the class ServletWebServerApplicationContextTests method filterRegistrationBeansSkipsRegisteredFilters.
@Test
void filterRegistrationBeansSkipsRegisteredFilters() {
addWebServerFactoryBean();
Filter filter = mock(Filter.class);
FilterRegistrationBean<Filter> initializer = new FilterRegistrationBean<>(filter);
this.context.registerBeanDefinition("initializerBean", beanDefinition(initializer));
this.context.registerBeanDefinition("filterBean", beanDefinition(filter));
this.context.refresh();
ServletContext servletContext = getWebServerFactory().getServletContext();
then(servletContext).should(atMost(1)).addFilter(anyString(), any(Filter.class));
}
use of cn.taketoday.framework.web.servlet.FilterRegistrationBean in project today-framework by TAKETODAY.
the class ServletWebServerApplicationContextTests method filterRegistrationBeansSkipsRegisteredFilters.
@Test
void filterRegistrationBeansSkipsRegisteredFilters() {
addWebServerFactoryBean();
Filter filter = mock(Filter.class);
FilterRegistrationBean<Filter> initializer = new FilterRegistrationBean<>(filter);
this.context.registerBeanDefinition("initializerBean", beanDefinition(initializer));
this.context.registerBeanDefinition("filterBean", beanDefinition(filter));
this.context.refresh();
ServletContext servletContext = getWebServerFactory().getServletContext();
then(servletContext).should(atMost(1)).addFilter(anyString(), any(Filter.class));
}
use of cn.taketoday.framework.web.servlet.FilterRegistrationBean in project today-framework by TAKETODAY.
the class AbstractServletWebServerFactoryTests method startServletAndFilter.
@Test
void startServletAndFilter() throws Exception {
AbstractServletWebServerFactory factory = getFactory();
this.webServer = factory.getWebServer(exampleServletRegistration(), new FilterRegistrationBean<>(new ExampleFilter()));
this.webServer.start();
assertThat(getResponse(getLocalUrl("/hello"))).isEqualTo("[Hello World]");
}
use of cn.taketoday.framework.web.servlet.FilterRegistrationBean in project today-framework 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);
}
Aggregations