use of cn.taketoday.mock.web.MockFilterChain 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.MockFilterChain in project today-infrastructure 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!");
}
use of cn.taketoday.mock.web.MockFilterChain in project today-infrastructure 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 doFilterWithServletAndFilters.
@Test
void doFilterWithServletAndFilters() throws Exception {
Servlet servlet = mock(Servlet.class);
MockFilter filter2 = new MockFilter(servlet);
MockFilter filter1 = new MockFilter(null);
MockFilterChain chain = new MockFilterChain(servlet, filter1, filter2);
chain.doFilter(this.request, this.response);
assertThat(filter1.invoked).isTrue();
assertThat(filter2.invoked).isTrue();
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 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();
}
Aggregations