use of org.springframework.web.testfixture.servlet.MockFilterChain in project spring-framework by spring-projects.
the class RelativeRedirectFilterTests method wrapOnceOnly.
@Test
public void wrapOnceOnly() throws Exception {
HttpServletResponse original = new MockHttpServletResponse();
MockFilterChain chain = new MockFilterChain();
this.filter.doFilterInternal(new MockHttpServletRequest(), original, chain);
HttpServletResponse wrapped1 = (HttpServletResponse) chain.getResponse();
assertThat(wrapped1).isNotSameAs(original);
chain.reset();
this.filter.doFilterInternal(new MockHttpServletRequest(), wrapped1, chain);
HttpServletResponse current = (HttpServletResponse) chain.getResponse();
assertThat(current).isSameAs(wrapped1);
chain.reset();
HttpServletResponse wrapped2 = new HttpServletResponseWrapper(wrapped1);
this.filter.doFilterInternal(new MockHttpServletRequest(), wrapped2, chain);
current = (HttpServletResponse) chain.getResponse();
assertThat(current).isSameAs(wrapped2);
}
use of org.springframework.web.testfixture.servlet.MockFilterChain in project spring-framework by spring-projects.
the class FormContentFilterTests method setup.
@BeforeEach
public void setup() {
this.request = new MockHttpServletRequest("PUT", "/");
this.request.setContentType("application/x-www-form-urlencoded; charset=ISO-8859-1");
this.response = new MockHttpServletResponse();
this.filterChain = new MockFilterChain();
}
use of org.springframework.web.testfixture.servlet.MockFilterChain in project spring-framework by spring-projects.
the class FormContentFilterTests method wrapFormEncodedOnly.
@Test
public void wrapFormEncodedOnly() throws Exception {
String[] contentTypes = new String[] { "text/plain", "multipart/form-data" };
for (String contentType : contentTypes) {
MockHttpServletRequest request = new MockHttpServletRequest("PUT", "/");
request.setContent("".getBytes("ISO-8859-1"));
request.setContentType(contentType);
this.filterChain = new MockFilterChain();
this.filter.doFilter(request, this.response, this.filterChain);
assertThat(this.filterChain.getRequest()).isSameAs(request);
}
}
use of org.springframework.web.testfixture.servlet.MockFilterChain in project spring-framework by spring-projects.
the class FormContentFilterTests method wrapPutPatchAndDeleteOnly.
@Test
public void wrapPutPatchAndDeleteOnly() throws Exception {
for (HttpMethod method : HttpMethod.values()) {
MockHttpServletRequest request = new MockHttpServletRequest(method.name(), "/");
request.setContent("foo=bar".getBytes("ISO-8859-1"));
request.setContentType("application/x-www-form-urlencoded; charset=ISO-8859-1");
this.filterChain = new MockFilterChain();
this.filter.doFilter(request, this.response, this.filterChain);
if (method == HttpMethod.PUT || method == HttpMethod.PATCH || method == HttpMethod.DELETE) {
assertThat(this.filterChain.getRequest()).isNotSameAs(request);
} else {
assertThat(this.filterChain.getRequest()).isSameAs(request);
}
}
}
use of org.springframework.web.testfixture.servlet.MockFilterChain in project spring-framework by spring-projects.
the class ResourceUrlProviderJavaConfigTests method setup.
@BeforeEach
@SuppressWarnings("resource")
public void setup() throws Exception {
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.setServletContext(new MockServletContext());
context.register(WebConfig.class);
context.refresh();
this.request = new MockHttpServletRequest("GET", "/");
this.request.setContextPath("/myapp");
this.response = new MockHttpServletResponse();
this.filterChain = new MockFilterChain(this.servlet, new ResourceUrlEncodingFilter(), (request, response, chain) -> {
Object urlProvider = context.getBean(ResourceUrlProvider.class);
request.setAttribute(ResourceUrlProviderExposingInterceptor.RESOURCE_URL_PROVIDER_ATTR, urlProvider);
chain.doFilter(request, response);
});
}
Aggregations