use of org.springframework.mock.web.MockFilterChain in project spring-boot by spring-projects.
the class DelegatingFilterProxyRegistrationBeanTests method initShouldNotCauseEarlyInitialization.
@Test
public 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()).isEqualTo(true);
}
use of org.springframework.mock.web.MockFilterChain in project spring-boot by spring-projects.
the class WebRequestTraceFilterTests method filterAddsTimeTaken.
@Test
@SuppressWarnings("unchecked")
public void filterAddsTimeTaken() throws Exception {
MockHttpServletRequest request = spy(new MockHttpServletRequest("GET", "/foo"));
MockHttpServletResponse response = new MockHttpServletResponse();
MockFilterChain chain = new MockFilterChain();
this.filter.doFilter(request, response, chain);
String timeTaken = (String) this.repository.findAll().iterator().next().getInfo().get("timeTaken");
assertThat(timeTaken).isNotNull();
}
use of org.springframework.mock.web.MockFilterChain in project spring-boot by spring-projects.
the class HelloWebSecurityApplicationTests method setup.
@Before
public void setup() {
this.request = new MockHttpServletRequest();
this.response = new MockHttpServletResponse();
this.chain = new MockFilterChain();
}
use of org.springframework.mock.web.MockFilterChain in project spring-boot by spring-projects.
the class RemoteDevToolsAutoConfigurationTests method setup.
@Before
public void setup() {
this.request = new MockHttpServletRequest();
this.response = new MockHttpServletResponse();
this.chain = new MockFilterChain();
}
use of org.springframework.mock.web.MockFilterChain in project spring-boot by spring-projects.
the class ErrorPageFilterTests method statusErrorWithCommittedResponse.
@Test
public void statusErrorWithCommittedResponse() throws Exception {
this.filter.addErrorPages(new ErrorPage(HttpStatus.BAD_REQUEST, "/400"));
this.chain = new MockFilterChain() {
@Override
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
((HttpServletResponse) response).sendError(400, "BAD");
response.flushBuffer();
super.doFilter(request, response);
}
};
this.filter.doFilter(this.request, this.response, this.chain);
assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus()).isEqualTo(400);
assertThat(this.response.isCommitted()).isTrue();
assertThat(this.response.getForwardedUrl()).isNull();
}
Aggregations