use of cn.taketoday.mock.web.MockFilterChain 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");
}
use of cn.taketoday.mock.web.MockFilterChain in project today-framework by TAKETODAY.
the class MockFilterChainTests method doFilterNullResponse.
@Test
void doFilterNullResponse() throws Exception {
MockFilterChain chain = new MockFilterChain();
assertThatIllegalArgumentException().isThrownBy(() -> chain.doFilter(this.request, null));
}
use of cn.taketoday.mock.web.MockFilterChain in project today-framework by TAKETODAY.
the class MockFilterChainTests method doFilterNullRequest.
@Test
void doFilterNullRequest() throws Exception {
MockFilterChain chain = new MockFilterChain();
assertThatIllegalArgumentException().isThrownBy(() -> chain.doFilter(null, this.response));
}
use of cn.taketoday.mock.web.MockFilterChain in project today-framework by TAKETODAY.
the class MockFilterChainTests method doFilterWithServlet.
@Test
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);
assertThatIllegalStateException().isThrownBy(() -> chain.doFilter(this.request, this.response)).withMessage("This FilterChain has already been called!");
}
use of cn.taketoday.mock.web.MockFilterChain in project today-framework by TAKETODAY.
the class MockFilterChainTests method doFilterEmptyChain.
@Test
void doFilterEmptyChain() throws Exception {
MockFilterChain chain = new MockFilterChain();
chain.doFilter(this.request, this.response);
assertThat(chain.getRequest()).isEqualTo(request);
assertThat(chain.getResponse()).isEqualTo(response);
assertThatIllegalStateException().isThrownBy(() -> chain.doFilter(this.request, this.response)).withMessage("This FilterChain has already been called!");
}
Aggregations