Search in sources :

Example 61 with ServletRequest

use of javax.servlet.ServletRequest in project sling by apache.

the class ExternalServletContextWrapperTest method testUnwrappingWrappedSlingRequest.

/**
     * Unwrapping a wrapped sling request should return the first-level request
     * wrapped by the sling request.
     */
@Test
public void testUnwrappingWrappedSlingRequest() {
    final HttpServletRequest req = context.mock(HttpServletRequest.class);
    context.checking(new Expectations() {

        {
            allowing(req).getServletPath();
            will(returnValue("/"));
            allowing(req).getPathInfo();
            will(returnValue("/test"));
        }
    });
    final HttpServletRequestWrapper wrapper = new HttpServletRequestWrapper(req);
    final HttpServletRequestWrapper wrapper2 = new HttpServletRequestWrapper(wrapper);
    final SlingHttpServletRequestImpl slingRequest = new SlingHttpServletRequestImpl(null, wrapper2);
    final HttpServletRequestWrapper slingWrapper = new HttpServletRequestWrapper(slingRequest);
    ServletRequest unwrapped = ExternalServletContextWrapper.RequestDispatcherWrapper.unwrapServletRequest(slingWrapper);
    assertEquals(wrapper2, unwrapped);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Expectations(org.jmock.Expectations) ServletRequest(javax.servlet.ServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletRequestWrapper(javax.servlet.http.HttpServletRequestWrapper) SlingHttpServletRequestImpl(org.apache.sling.engine.impl.SlingHttpServletRequestImpl) Test(org.junit.Test)

Example 62 with ServletRequest

use of javax.servlet.ServletRequest in project sling by apache.

the class ExternalServletContextWrapperTest method testUnwrappingWrappedRequest.

/**
     * Unwrapping a wrapper request should return in the request.
     */
@Test
public void testUnwrappingWrappedRequest() {
    final ServletRequest req = context.mock(ServletRequest.class);
    final ServletRequestWrapper wrapper = new ServletRequestWrapper(req);
    ServletRequest unwrapped = ExternalServletContextWrapper.RequestDispatcherWrapper.unwrapServletRequest(wrapper);
    assertEquals(req, unwrapped);
}
Also used : ServletRequest(javax.servlet.ServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletRequestWrapper(javax.servlet.http.HttpServletRequestWrapper) ServletRequestWrapper(javax.servlet.ServletRequestWrapper) Test(org.junit.Test)

Example 63 with ServletRequest

use of javax.servlet.ServletRequest in project sling by apache.

the class ExternalServletContextWrapperTest method testUnwrappingDoubleWrappedRequest.

@Test
public void testUnwrappingDoubleWrappedRequest() {
    final ServletRequest req = context.mock(ServletRequest.class);
    final ServletRequestWrapper wrapper = new ServletRequestWrapper(req);
    final ServletRequestWrapper wrapper2 = new ServletRequestWrapper(wrapper);
    ServletRequest unwrapped = ExternalServletContextWrapper.RequestDispatcherWrapper.unwrapServletRequest(wrapper2);
    assertEquals(req, unwrapped);
}
Also used : ServletRequest(javax.servlet.ServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletRequestWrapper(javax.servlet.http.HttpServletRequestWrapper) ServletRequestWrapper(javax.servlet.ServletRequestWrapper) Test(org.junit.Test)

Example 64 with ServletRequest

use of javax.servlet.ServletRequest in project sling by apache.

the class ExternalServletContextWrapperTest method testUnwrappingRegularRequest.

/**
     * Unwrapping a non-wrapper request should return the request itself.
     */
@Test
public void testUnwrappingRegularRequest() {
    final ServletRequest req = context.mock(ServletRequest.class);
    ServletRequest unwrapped = ExternalServletContextWrapper.RequestDispatcherWrapper.unwrapServletRequest(req);
    assertEquals(req, unwrapped);
}
Also used : ServletRequest(javax.servlet.ServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) Test(org.junit.Test)

Example 65 with ServletRequest

use of javax.servlet.ServletRequest in project sling by apache.

the class ExternalServletContextWrapperTest method testUnwrappingSlingRequest.

/**
     * Unwrapping a sling request should return the first-level request wrapped
     * by the sling request.
     */
@Test
public void testUnwrappingSlingRequest() {
    final HttpServletRequest req = context.mock(HttpServletRequest.class);
    context.checking(new Expectations() {

        {
            allowing(req).getServletPath();
            will(returnValue("/"));
            allowing(req).getPathInfo();
            will(returnValue("/test"));
        }
    });
    final HttpServletRequestWrapper wrapper = new HttpServletRequestWrapper(req);
    final HttpServletRequestWrapper wrapper2 = new HttpServletRequestWrapper(wrapper);
    final SlingHttpServletRequestImpl slingRequest = new SlingHttpServletRequestImpl(null, wrapper2);
    ServletRequest unwrapped = ExternalServletContextWrapper.RequestDispatcherWrapper.unwrapServletRequest(slingRequest);
    assertEquals(wrapper2, unwrapped);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Expectations(org.jmock.Expectations) ServletRequest(javax.servlet.ServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletRequestWrapper(javax.servlet.http.HttpServletRequestWrapper) SlingHttpServletRequestImpl(org.apache.sling.engine.impl.SlingHttpServletRequestImpl) Test(org.junit.Test)

Aggregations

ServletRequest (javax.servlet.ServletRequest)185 ServletResponse (javax.servlet.ServletResponse)129 HttpServletRequest (javax.servlet.http.HttpServletRequest)117 HttpServletResponse (javax.servlet.http.HttpServletResponse)95 FilterChain (javax.servlet.FilterChain)79 Test (org.junit.Test)75 ServletException (javax.servlet.ServletException)59 IOException (java.io.IOException)57 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)35 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)35 MockFilterChain (org.springframework.mock.web.MockFilterChain)32 Filter (javax.servlet.Filter)28 Injector (com.google.inject.Injector)25 HttpServletResponseWrapper (javax.servlet.http.HttpServletResponseWrapper)21 NestedServletException (org.springframework.web.util.NestedServletException)19 ServletTestUtils.newFakeHttpServletRequest (com.google.inject.servlet.ServletTestUtils.newFakeHttpServletRequest)18 ServletTestUtils.newFakeHttpServletResponse (com.google.inject.servlet.ServletTestUtils.newFakeHttpServletResponse)18 HttpServletRequestWrapper (javax.servlet.http.HttpServletRequestWrapper)15 ErrorPage (org.springframework.boot.web.server.ErrorPage)15 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)14