use of org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class AdaptiveImageServletTest method testImageFileWithNegativeRequestedWidth.
@Test
public void testImageFileWithNegativeRequestedWidth() throws Exception {
Pair<MockSlingHttpServletRequest, MockSlingHttpServletResponse> requestResponsePair = prepareRequestResponsePair(IMAGE7_PATH, "img.-1", "png");
MockSlingHttpServletRequest request = requestResponsePair.getLeft();
MockSlingHttpServletResponse response = requestResponsePair.getRight();
ContentPolicyMapping mapping = request.getResource().adaptTo(ContentPolicyMapping.class);
ContentPolicy contentPolicy = mapping.getPolicy();
when(contentPolicyManager.getPolicy(request.getResource())).thenReturn(contentPolicy);
servlet.doGet(request, response);
assertEquals(HttpServletResponse.SC_BAD_REQUEST, response.getStatus());
}
use of org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class AdaptiveImageServletTest method testImageFileCropScaling.
@Test
public void testImageFileCropScaling() throws Exception {
Pair<MockSlingHttpServletRequest, MockSlingHttpServletResponse> requestResponsePair = prepareRequestResponsePair(IMAGE10_PATH, "img.1440", "png");
MockSlingHttpServletRequest request = requestResponsePair.getLeft();
MockSlingHttpServletResponse response = requestResponsePair.getRight();
ContentPolicyMapping mapping = request.getResource().adaptTo(ContentPolicyMapping.class);
ContentPolicy contentPolicy = mapping.getPolicy();
when(contentPolicyManager.getPolicy(request.getResource())).thenReturn(contentPolicy);
servlet.doGet(request, response);
BufferedImage image = ImageIO.read(new ByteArrayInputStream(response.getOutput()));
assertEquals("Expected the cropped rectangle to have a 1390px width, since the servlet should not perform cropping upscaling.", 1390, image.getWidth());
assertEquals("Expected the cropped rectangle to have a 515px height, since the servlet should not perform cropping upscaling.", 515, image.getHeight());
}
use of org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class AdaptiveImageServletTest method testGIFUploadedToDAMBrowserCached.
@Test
public void testGIFUploadedToDAMBrowserCached() throws Exception {
Pair<MockSlingHttpServletRequest, MockSlingHttpServletResponse> requestResponsePair = prepareRequestResponsePair(IMAGE6_PATH, "img", "gif");
MockSlingHttpServletRequest request = requestResponsePair.getLeft();
MockSlingHttpServletResponse response = requestResponsePair.getRight();
// 1 millisecond less than the jcr:lastModified value from test-conf.json
request.addDateHeader("If-Modified-Since", 1489998822137L);
servlet.doGet(request, response);
assertEquals(HttpServletResponse.SC_NOT_MODIFIED, response.getStatus());
}
use of org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class AdaptiveImageServletTest method testPNGFileDirectStream.
@Test
public void testPNGFileDirectStream() throws Exception {
Pair<MockSlingHttpServletRequest, MockSlingHttpServletResponse> requestResponsePair = prepareRequestResponsePair(IMAGE3_PATH, "img.600", "png");
MockSlingHttpServletRequest request = requestResponsePair.getLeft();
MockSlingHttpServletResponse response = requestResponsePair.getRight();
ContentPolicyMapping mapping = request.getResource().adaptTo(ContentPolicyMapping.class);
ContentPolicy contentPolicy = mapping.getPolicy();
when(contentPolicyManager.getPolicy(request.getResource())).thenReturn(contentPolicy);
servlet.doGet(request, response);
ByteArrayInputStream stream = new ByteArrayInputStream(response.getOutput());
BufferedImage image = ImageIO.read(stream);
assertEquals(600, image.getWidth());
assertEquals(600, image.getHeight());
}
use of org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class AdaptiveImageServletTest method testWithInvalidFileReference.
@Test
public void testWithInvalidFileReference() throws Exception {
Pair<MockSlingHttpServletRequest, MockSlingHttpServletResponse> requestResponsePair = prepareRequestResponsePair(IMAGE2_PATH, "img", "png");
MockSlingHttpServletRequest request = requestResponsePair.getLeft();
MockSlingHttpServletResponse response = requestResponsePair.getRight();
servlet.doGet(request, response);
assertEquals("Expected a 404 response when the image does not have a valid file reference.", HttpServletResponse.SC_NOT_FOUND, response.getStatus());
assertArrayEquals("Expected an empty response output.", new byte[0], response.getOutput());
}
Aggregations