use of cn.taketoday.mock.web.MockFilterConfig in project today-infrastructure by TAKETODAY.
the class ErrorPageFilterTests method oncePerRequest.
@Test
void oncePerRequest() throws Exception {
this.chain = new TestFilterChain((request, response, chain) -> {
response.sendError(400, "BAD");
assertThat(request.getAttribute("FILTER.FILTERED")).isNotNull();
});
this.filter.init(new MockFilterConfig("FILTER"));
this.filter.doFilter(this.request, this.response, this.chain);
}
use of cn.taketoday.mock.web.MockFilterConfig in project today-infrastructure by TAKETODAY.
the class DelegatingFilterProxyRegistrationBeanTests method initShouldNotCauseEarlyInitialization.
@Test
void initShouldNotCauseEarlyInitialization() throws Exception {
this.applicationContext.registerBeanDefinition("mockFilter", new RootBeanDefinition(MockFilter.class));
DelegatingFilterProxyRegistrationBean registrationBean = createFilterRegistrationBean();
Filter filter = registrationBean.getFilter();
filter.init(new MockFilterConfig());
assertThat(mockFilterInitialized.get()).isNull();
filter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), new MockFilterChain());
assertThat(mockFilterInitialized.get()).isTrue();
}
use of cn.taketoday.mock.web.MockFilterConfig in project today-framework by TAKETODAY.
the class ErrorPageFilterTests method oncePerRequest.
@Test
void oncePerRequest() throws Exception {
this.chain = new TestFilterChain((request, response, chain) -> {
response.sendError(400, "BAD");
assertThat(request.getAttribute("FILTER.FILTERED")).isNotNull();
});
this.filter.init(new MockFilterConfig("FILTER"));
this.filter.doFilter(this.request, this.response, this.chain);
}
use of cn.taketoday.mock.web.MockFilterConfig in project today-framework by TAKETODAY.
the class DelegatingFilterProxyRegistrationBeanTests method initShouldNotCauseEarlyInitialization.
@Test
void initShouldNotCauseEarlyInitialization() throws Exception {
this.applicationContext.registerBeanDefinition("mockFilter", new RootBeanDefinition(MockFilter.class));
DelegatingFilterProxyRegistrationBean registrationBean = createFilterRegistrationBean();
Filter filter = registrationBean.getFilter();
filter.init(new MockFilterConfig());
assertThat(mockFilterInitialized.get()).isNull();
filter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), new MockFilterChain());
assertThat(mockFilterInitialized.get()).isTrue();
}
use of cn.taketoday.mock.web.MockFilterConfig in project today-framework by TAKETODAY.
the class ServletWebServerApplicationContextTests method delegatingFilterProxyRegistrationBeansSkipsTargetBeanNames.
@Test
void delegatingFilterProxyRegistrationBeansSkipsTargetBeanNames() {
addWebServerFactoryBean();
DelegatingFilterProxyRegistrationBean initializer = new DelegatingFilterProxyRegistrationBean("filterBean");
this.context.registerBeanDefinition("initializerBean", beanDefinition(initializer));
BeanDefinition filterBeanDefinition = beanDefinition(new IllegalStateException("Create FilterBean Failure"));
filterBeanDefinition.setLazyInit(true);
this.context.registerBeanDefinition("filterBean", filterBeanDefinition);
this.context.refresh();
ServletContext servletContext = getWebServerFactory().getServletContext();
then(servletContext).should(atMost(1)).addFilter(anyString(), this.filterCaptor.capture());
// Up to this point the filterBean should not have been created, calling
// the delegate proxy will trigger creation and an exception
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() -> {
this.filterCaptor.getValue().init(new MockFilterConfig());
this.filterCaptor.getValue().doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), new MockFilterChain());
}).havingRootCause().isInstanceOf(IllegalStateException.class).withMessageContaining("Create FilterBean Failure");
}
Aggregations