Search in sources :

Example 1 with MockFilterChain

use of org.springframework.mock.web.test.MockFilterChain in project spring-framework by spring-projects.

the class HttpPutFormContentFilterTests method wrapPutAndPatchOnly.

@Test
public void wrapPutAndPatchOnly() throws Exception {
    request.setContent("".getBytes("ISO-8859-1"));
    for (HttpMethod method : HttpMethod.values()) {
        request.setMethod(method.name());
        filterChain = new MockFilterChain();
        filter.doFilter(request, response, filterChain);
        if (method.equals(HttpMethod.PUT) || method.equals(HttpMethod.PATCH)) {
            assertNotSame("Should wrap HTTP method " + method, request, filterChain.getRequest());
        } else {
            assertSame("Should not wrap for HTTP method " + method, request, filterChain.getRequest());
        }
    }
}
Also used : MockFilterChain(org.springframework.mock.web.test.MockFilterChain) HttpMethod(org.springframework.http.HttpMethod) Test(org.junit.Test)

Example 2 with MockFilterChain

use of org.springframework.mock.web.test.MockFilterChain in project spring-framework by spring-projects.

the class ForwardedHeaderFilterTests method setUp.

@Before
@SuppressWarnings("serial")
public void setUp() throws Exception {
    this.request = new MockHttpServletRequest();
    this.request.setScheme("http");
    this.request.setServerName("localhost");
    this.request.setServerPort(80);
    this.filterChain = new MockFilterChain(new HttpServlet() {
    });
}
Also used : MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) HttpServlet(javax.servlet.http.HttpServlet) MockFilterChain(org.springframework.mock.web.test.MockFilterChain) Before(org.junit.Before)

Example 3 with MockFilterChain

use of org.springframework.mock.web.test.MockFilterChain in project spring-framework by spring-projects.

the class ForwardedHeaderFilterTests method doWithFiltersAndGetResponse.

@SuppressWarnings("serial")
private MockHttpServletResponse doWithFiltersAndGetResponse(Filter... filters) throws ServletException, IOException {
    MockHttpServletResponse response = new MockHttpServletResponse();
    FilterChain filterChain = new MockFilterChain(new HttpServlet() {
    }, filters);
    filterChain.doFilter(request, response);
    return response;
}
Also used : HttpServlet(javax.servlet.http.HttpServlet) FilterChain(javax.servlet.FilterChain) MockFilterChain(org.springframework.mock.web.test.MockFilterChain) MockFilterChain(org.springframework.mock.web.test.MockFilterChain) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse)

Example 4 with MockFilterChain

use of org.springframework.mock.web.test.MockFilterChain in project spring-framework by spring-projects.

the class HttpPutFormContentFilterTests method setup.

@Before
public void setup() {
    filter = new HttpPutFormContentFilter();
    request = new MockHttpServletRequest("PUT", "/");
    request.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=ISO-8859-1");
    request.setContentType("application/x-www-form-urlencoded; charset=ISO-8859-1");
    response = new MockHttpServletResponse();
    filterChain = new MockFilterChain();
}
Also used : MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) MockFilterChain(org.springframework.mock.web.test.MockFilterChain) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) Before(org.junit.Before)

Example 5 with MockFilterChain

use of org.springframework.mock.web.test.MockFilterChain in project spring-framework by spring-projects.

the class HttpPutFormContentFilterTests method invalidMediaType.

@Test
public void invalidMediaType() throws Exception {
    request.setContent("".getBytes("ISO-8859-1"));
    request.setContentType("foo");
    filterChain = new MockFilterChain();
    filter.doFilter(request, response, filterChain);
    assertSame(request, filterChain.getRequest());
}
Also used : MockFilterChain(org.springframework.mock.web.test.MockFilterChain) Test(org.junit.Test)

Aggregations

MockFilterChain (org.springframework.mock.web.test.MockFilterChain)6 Test (org.junit.Test)3 HttpServlet (javax.servlet.http.HttpServlet)2 Before (org.junit.Before)2 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)2 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)2 FilterChain (javax.servlet.FilterChain)1 HttpMethod (org.springframework.http.HttpMethod)1