Search in sources :

Example 31 with RewriterResponse

use of org.apache.sling.security.impl.ContentDispositionFilter.RewriterResponse in project sling by apache.

the class ContentDispositionFilterTest method test_doFilter1.

@Test
public void test_doFilter1() throws Throwable {
    final SlingHttpServletRequest request = context.mock(SlingHttpServletRequest.class);
    final SlingHttpServletResponse response = context.mock(SlingHttpServletResponse.class);
    final Resource resource = context.mock(Resource.class, "resource");
    callActivateWithConfiguration(new String[] { "/content/usergenerated" }, new String[] { "" });
    context.checking(new Expectations() {

        {
            allowing(request).getMethod();
            will(returnValue("GET"));
            allowing(request).getAttribute(RewriterResponse.ATTRIBUTE_NAME);
            will(returnValue(null));
            allowing(request).setAttribute(RewriterResponse.ATTRIBUTE_NAME, "text/html");
            allowing(request).getResource();
            will(returnValue(resource));
            allowing(resource).getPath();
            will(returnValue("/libs"));
            allowing(response).setContentType("text/html");
            //CONTENT DISPOSITION MUST NOT SET
            never(response).addHeader("Content-Disposition", "attachment");
        }
    });
    ContentDispositionFilter.RewriterResponse rewriterResponse = contentDispositionFilter.new RewriterResponse(request, response);
    rewriterResponse.setContentType("text/html");
}
Also used : SlingHttpServletResponse(org.apache.sling.api.SlingHttpServletResponse) Expectations(org.jmock.Expectations) RewriterResponse(org.apache.sling.security.impl.ContentDispositionFilter.RewriterResponse) Resource(org.apache.sling.api.resource.Resource) RewriterResponse(org.apache.sling.security.impl.ContentDispositionFilter.RewriterResponse) SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest) Test(org.junit.Test)

Aggregations

SlingHttpServletRequest (org.apache.sling.api.SlingHttpServletRequest)31 SlingHttpServletResponse (org.apache.sling.api.SlingHttpServletResponse)31 Resource (org.apache.sling.api.resource.Resource)31 RewriterResponse (org.apache.sling.security.impl.ContentDispositionFilter.RewriterResponse)31 Expectations (org.jmock.Expectations)31 Test (org.junit.Test)31 ValueMap (org.apache.sling.api.resource.ValueMap)21 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)15