Search in sources :

Example 1 with SlingHttpServletResponseImpl

use of org.apache.sling.engine.impl.SlingHttpServletResponseImpl in project sling by apache.

the class RequestDataTest method setup.

@Before
public void setup() throws Exception {
    context = new Mockery() {

        {
            setImposteriser(ClassImposteriser.INSTANCE);
        }
    };
    req = context.mock(HttpServletRequest.class);
    resp = context.mock(HttpServletResponse.class);
    final ContentData contentData = context.mock(ContentData.class);
    final Servlet servlet = context.mock(Servlet.class);
    final ServletConfig servletConfig = context.mock(ServletConfig.class);
    context.checking(new Expectations() {

        {
            allowing(req).getServletPath();
            will(returnValue("/"));
            allowing(req).getPathInfo();
            will(returnValue(""));
            allowing(req).getMethod();
            will(returnValue("GET"));
            allowing(req).setAttribute(with(any(String.class)), with(any(Object.class)));
            allowing(req).setAttribute(with(any(String.class)), with(aNull(Object.class)));
            allowing(contentData).getServlet();
            will(returnValue(servlet));
            allowing(servlet).getServletConfig();
            will(returnValue(servletConfig));
            allowing(servlet).service(with(any(ServletRequest.class)), with(any(ServletResponse.class)));
            allowing(servletConfig).getServletName();
            will(returnValue("SERVLET_NAME"));
            allowing(req).getAttribute(RequestProgressTracker.class.getName());
            will(returnValue(null));
        }
    });
    requestData = new RequestData(null, req, resp) {

        @Override
        public ContentData getContentData() {
            return contentData;
        }
    };
    slingRequest = new SlingHttpServletRequestImpl(requestData, req);
    slingResponse = new SlingHttpServletResponseImpl(requestData, resp);
    RequestData.setMaxCallCounter(2);
}
Also used : Expectations(org.jmock.Expectations) ServletRequest(javax.servlet.ServletRequest) SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) SlingHttpServletResponse(org.apache.sling.api.SlingHttpServletResponse) ServletResponse(javax.servlet.ServletResponse) SlingHttpServletResponseImpl(org.apache.sling.engine.impl.SlingHttpServletResponseImpl) ServletConfig(javax.servlet.ServletConfig) HttpServletResponse(javax.servlet.http.HttpServletResponse) SlingHttpServletResponse(org.apache.sling.api.SlingHttpServletResponse) Mockery(org.jmock.Mockery) SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) SlingHttpServletRequestImpl(org.apache.sling.engine.impl.SlingHttpServletRequestImpl) Servlet(javax.servlet.Servlet) Before(org.junit.Before)

Example 2 with SlingHttpServletResponseImpl

use of org.apache.sling.engine.impl.SlingHttpServletResponseImpl in project sling by apache.

the class ExternalServletContextWrapperTest method testUnwrappingSlingResponse.

/**
     * Unwrapping a sling response should return the first-level response wrapped
     * by the sling response.
     */
@Test
public void testUnwrappingSlingResponse() {
    final HttpServletResponse resp = context.mock(HttpServletResponse.class);
    final HttpServletResponseWrapper wrapper = new HttpServletResponseWrapper(resp);
    final HttpServletResponseWrapper wrapper2 = new HttpServletResponseWrapper(wrapper);
    final SlingHttpServletResponseImpl slingResponse = new SlingHttpServletResponseImpl(null, wrapper2);
    ServletResponse unwrapped = ExternalServletContextWrapper.RequestDispatcherWrapper.unwrapServletResponse(slingResponse);
    assertEquals(wrapper2, unwrapped);
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletResponse(javax.servlet.ServletResponse) SlingHttpServletResponseImpl(org.apache.sling.engine.impl.SlingHttpServletResponseImpl) HttpServletResponseWrapper(javax.servlet.http.HttpServletResponseWrapper) HttpServletResponse(javax.servlet.http.HttpServletResponse) Test(org.junit.Test)

Example 3 with SlingHttpServletResponseImpl

use of org.apache.sling.engine.impl.SlingHttpServletResponseImpl in project sling by apache.

the class ExternalServletContextWrapperTest method testUnwrappingWrappedSlingResponse.

/**
     * Unwrapping a wrapped sling response should return the first-level response
     * wrapped by the sling response.
     */
@Test
public void testUnwrappingWrappedSlingResponse() {
    final HttpServletResponse resp = context.mock(HttpServletResponse.class);
    final HttpServletResponseWrapper wrapper = new HttpServletResponseWrapper(resp);
    final HttpServletResponseWrapper wrapper2 = new HttpServletResponseWrapper(wrapper);
    final SlingHttpServletResponseImpl slingResponse = new SlingHttpServletResponseImpl(null, wrapper2);
    final HttpServletResponseWrapper slingWrapper = new HttpServletResponseWrapper(slingResponse);
    ServletResponse unwrapped = ExternalServletContextWrapper.RequestDispatcherWrapper.unwrapServletResponse(slingWrapper);
    assertEquals(wrapper2, unwrapped);
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletResponse(javax.servlet.ServletResponse) SlingHttpServletResponseImpl(org.apache.sling.engine.impl.SlingHttpServletResponseImpl) HttpServletResponseWrapper(javax.servlet.http.HttpServletResponseWrapper) HttpServletResponse(javax.servlet.http.HttpServletResponse) Test(org.junit.Test)

Aggregations

ServletResponse (javax.servlet.ServletResponse)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 SlingHttpServletResponseImpl (org.apache.sling.engine.impl.SlingHttpServletResponseImpl)3 HttpServletResponseWrapper (javax.servlet.http.HttpServletResponseWrapper)2 Test (org.junit.Test)2 Servlet (javax.servlet.Servlet)1 ServletConfig (javax.servlet.ServletConfig)1 ServletRequest (javax.servlet.ServletRequest)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 SlingHttpServletRequest (org.apache.sling.api.SlingHttpServletRequest)1 SlingHttpServletResponse (org.apache.sling.api.SlingHttpServletResponse)1 SlingHttpServletRequestImpl (org.apache.sling.engine.impl.SlingHttpServletRequestImpl)1 Expectations (org.jmock.Expectations)1 Mockery (org.jmock.Mockery)1 Before (org.junit.Before)1