use of org.apache.sling.api.SlingHttpServletRequest in project sling by apache.
the class ContentDispositionFilterTest method test_isJcrData2.
@Test
public void test_isJcrData2() throws Throwable {
contentDispositionFilter = new ContentDispositionFilter();
final SlingHttpServletRequest request = context.mock(SlingHttpServletRequest.class);
final SlingHttpServletResponse response = context.mock(SlingHttpServletResponse.class);
final Resource resource = context.mock(Resource.class);
context.checking(new Expectations() {
{
allowing(request).getResource();
will(returnValue(resource));
}
});
final ContentDispositionFilter.RewriterResponse rewriterResponse = contentDispositionFilter.new RewriterResponse(request, response);
final ValueMap properties = context.mock(ValueMap.class);
context.checking(new Expectations() {
{
allowing(resource).adaptTo(ValueMap.class);
will(returnValue(properties));
allowing(properties).containsKey(PROP_JCR_DATA);
will(returnValue(true));
}
});
Boolean result = (Boolean) PrivateAccessor.invoke(rewriterResponse, "isJcrData", new Class[] { Resource.class }, new Object[] { resource });
Assert.assertTrue(result);
}
use of org.apache.sling.api.SlingHttpServletRequest in project sling by apache.
the class ContentDispositionFilterTest method test_doFilter17.
@Test
public void test_doFilter17() throws Throwable {
final SlingHttpServletRequest request = context.mock(SlingHttpServletRequest.class);
final SlingHttpServletResponse response = context.mock(SlingHttpServletResponse.class);
final Resource resource = context.mock(Resource.class, "resource");
final ValueMap properties = context.mock(ValueMap.class);
contentDispositionFilter = new ContentDispositionFilter();
callActivateWithConfiguration(new String[] { "/content/usergenerated" }, new String[] { "" }, false);
final AtomicInteger counter = new AtomicInteger();
context.checking(new Expectations() {
{
allowing(request).getMethod();
will(returnValue("GET"));
exactly(1).of(response).containsHeader("Content-Disposition");
will(returnValue(false));
exactly(1).of(response).containsHeader("Content-Disposition");
will(returnValue(true));
exactly(1).of(request).getAttribute(RewriterResponse.ATTRIBUTE_NAME);
will(returnValue(null));
exactly(1).of(request).getAttribute(RewriterResponse.ATTRIBUTE_NAME);
will(returnValue("text/html"));
allowing(request).setAttribute(RewriterResponse.ATTRIBUTE_NAME, "text/xml");
allowing(request).setAttribute(RewriterResponse.ATTRIBUTE_NAME, "text/html");
allowing(request).getResource();
will(returnValue(resource));
allowing(resource).getPath();
will(returnValue("/content/other"));
allowing(resource).adaptTo(ValueMap.class);
will(returnValue(properties));
allowing(properties).containsKey(PROP_JCR_DATA);
will(returnValue(true));
allowing(response).setContentType("text/html");
allowing(response).setContentType("text/xml");
//CONTENT DISPOSITION IS NOT SET
never(response).addHeader("Content-Disposition", "attachment");
}
});
final ContentDispositionFilter.RewriterResponse rewriterResponse = contentDispositionFilter.new RewriterResponse(request, response) {
@Override
public void addHeader(String name, String value) {
counter.incrementAndGet();
}
};
rewriterResponse.setContentType("text/html");
Assert.assertEquals(0, counter.intValue());
}
use of org.apache.sling.api.SlingHttpServletRequest in project sling by apache.
the class ContentDispositionFilterTest method test_isJcrData7.
@Test
public void test_isJcrData7() throws Throwable {
contentDispositionFilter = new ContentDispositionFilter();
final SlingHttpServletRequest request = context.mock(SlingHttpServletRequest.class);
final SlingHttpServletResponse response = context.mock(SlingHttpServletResponse.class);
final Resource child = context.mock(Resource.class, "child");
final Resource resource = context.mock(Resource.class, "resource");
final ValueMap properties = context.mock(ValueMap.class);
context.checking(new Expectations() {
{
allowing(request).getResource();
will(returnValue(resource));
allowing(resource).adaptTo(ValueMap.class);
will(returnValue(properties));
allowing(properties).containsKey(PROP_JCR_DATA);
will(returnValue(false));
allowing(resource).getChild(JCR_CONTENT_LEAF);
will(returnValue(child));
allowing(child).adaptTo(ValueMap.class);
will(returnValue(null));
}
});
final ContentDispositionFilter.RewriterResponse rewriterResponse = contentDispositionFilter.new RewriterResponse(request, response);
Boolean result = (Boolean) PrivateAccessor.invoke(rewriterResponse, "isJcrData", new Class[] { Resource.class }, new Object[] { resource });
Assert.assertFalse(result);
}
use of org.apache.sling.api.SlingHttpServletRequest in project sling by apache.
the class ContentDispositionFilterTest method test_doFilter16.
/**
* Test repeated setContentType calls don't add multiple headers, case 2 changing mime type
* @throws Throwable
*/
@Test
public void test_doFilter16() throws Throwable {
final SlingHttpServletRequest request = context.mock(SlingHttpServletRequest.class);
final SlingHttpServletResponse response = context.mock(SlingHttpServletResponse.class);
final Resource resource = context.mock(Resource.class, "resource");
final ValueMap properties = context.mock(ValueMap.class);
callActivateWithConfiguration(new String[] { "/content/usergenerated" }, new String[] { "" });
final AtomicInteger counter = new AtomicInteger();
context.checking(new Expectations() {
{
allowing(request).getMethod();
will(returnValue("GET"));
exactly(1).of(response).containsHeader("Content-Disposition");
will(returnValue(false));
exactly(1).of(response).containsHeader("Content-Disposition");
will(returnValue(true));
exactly(1).of(request).getAttribute(RewriterResponse.ATTRIBUTE_NAME);
will(returnValue(null));
exactly(1).of(request).getAttribute(RewriterResponse.ATTRIBUTE_NAME);
will(returnValue("text/html"));
allowing(request).setAttribute(RewriterResponse.ATTRIBUTE_NAME, "text/xml");
allowing(request).setAttribute(RewriterResponse.ATTRIBUTE_NAME, "text/html");
allowing(request).getResource();
will(returnValue(resource));
allowing(resource).getPath();
will(returnValue("/content/usergenerated"));
allowing(resource).adaptTo(ValueMap.class);
will(returnValue(properties));
allowing(properties).containsKey(PROP_JCR_DATA);
will(returnValue(true));
allowing(response).setContentType("text/html");
allowing(response).setContentType("text/xml");
//CONTENT DISPOSITION IS SET
exactly(1).of(response).addHeader("Content-Disposition", "attachment");
}
});
final ContentDispositionFilter.RewriterResponse rewriterResponse = contentDispositionFilter.new RewriterResponse(request, response) {
@Override
public void addHeader(String name, String value) {
counter.incrementAndGet();
}
};
rewriterResponse.setContentType("text/html");
rewriterResponse.setContentType("text/xml");
Assert.assertEquals(1, counter.intValue());
}
use of org.apache.sling.api.SlingHttpServletRequest in project sling by apache.
the class ContentDispositionFilterTest method test_doFilter5.
@Test
public void test_doFilter5() throws Throwable {
final SlingHttpServletRequest request = context.mock(SlingHttpServletRequest.class);
final SlingHttpServletResponse response = context.mock(SlingHttpServletResponse.class);
final Resource resource = context.mock(Resource.class, "resource");
final ValueMap properties = context.mock(ValueMap.class);
callActivateWithConfiguration(new String[] { "/content/usergenerated/*" }, new String[] { "" });
final AtomicInteger counter = new AtomicInteger();
context.checking(new Expectations() {
{
allowing(request).getMethod();
will(returnValue("GET"));
allowing(response).containsHeader("Content-Disposition");
will(returnValue(false));
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("/content/usergenerated/author"));
allowing(resource).adaptTo(ValueMap.class);
will(returnValue(properties));
allowing(properties).containsKey(PROP_JCR_DATA);
will(returnValue(true));
allowing(response).setContentType("text/html");
//CONTENT DISPOSITION IS SET
exactly(1).of(response).addHeader("Content-Disposition", "attachment");
}
});
final ContentDispositionFilter.RewriterResponse rewriterResponse = contentDispositionFilter.new RewriterResponse(request, response) {
@Override
public void addHeader(String name, String value) {
counter.incrementAndGet();
}
};
rewriterResponse.setContentType("text/html");
Assert.assertEquals(1, counter.intValue());
}
Aggregations