use of org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class AdaptiveImageServletTest method testWrongNumberOfSelectors.
@Test
public void testWrongNumberOfSelectors() throws Exception {
Pair<MockSlingHttpServletRequest, MockSlingHttpServletResponse> requestResponsePair = prepareRequestResponsePair(IMAGE0_PATH, "img.1.1", "png");
MockSlingHttpServletRequest request = requestResponsePair.getLeft();
MockSlingHttpServletResponse response = requestResponsePair.getRight();
servlet.doGet(request, response);
assertEquals("Expected a 404 response when the request has more selectors than expected.", HttpServletResponse.SC_NOT_FOUND, response.getStatus());
assertArrayEquals("Expected an empty response output.", new byte[0], response.getOutput());
}
use of org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class AdaptiveImageServletTest method testGIFFileDirectStream.
@Test
public void testGIFFileDirectStream() throws Exception {
Pair<MockSlingHttpServletRequest, MockSlingHttpServletResponse> requestResponsePair = prepareRequestResponsePair(IMAGE5_PATH, "img", "gif");
MockSlingHttpServletRequest request = requestResponsePair.getLeft();
MockSlingHttpServletResponse response = requestResponsePair.getRight();
servlet.doGet(request, response);
ByteArrayInputStream stream = new ByteArrayInputStream(response.getOutput());
InputStream directStream = this.getClass().getClassLoader().getResourceAsStream("image/Adobe_Systems_logo_and_wordmark.svg.gif");
assertTrue(IOUtils.contentEquals(stream, directStream));
}
use of org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class AdaptiveImageServletTest method testRequestNoWidthWithDesign.
@Test
public void testRequestNoWidthWithDesign() throws Exception {
Pair<MockSlingHttpServletRequest, MockSlingHttpServletResponse> requestResponsePair = prepareRequestResponsePair(IMAGE0_PATH, "img", "png");
MockSlingHttpServletRequest request = requestResponsePair.getLeft();
MockSlingHttpServletResponse response = spy(requestResponsePair.getRight());
ContentPolicyMapping mapping = request.getResource().adaptTo(ContentPolicyMapping.class);
ContentPolicy contentPolicy = mapping.getPolicy();
when(contentPolicyManager.getPolicy(request.getResource())).thenReturn(contentPolicy);
servlet.doGet(request, response);
verify(response).setContentType("image/png");
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(response.getOutput());
BufferedImage image = ImageIO.read(byteArrayInputStream);
Dimension expectedDimension = new Dimension(600, 600);
Dimension actualDimension = new Dimension(image.getWidth(), image.getHeight());
assertEquals("Expected image rendered using the first width defined in the content policy.", expectedDimension, actualDimension);
}
use of org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class AdaptiveImageServletTest method testDAMFileUpscaledPNG.
@Test
public void testDAMFileUpscaledPNG() throws Exception {
Pair<MockSlingHttpServletRequest, MockSlingHttpServletResponse> requestResponsePair = prepareRequestResponsePair(IMAGE0_PATH, "img.2500", "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);
InputStream directStream = this.getClass().getClassLoader().getResourceAsStream("image/Adobe_Systems_logo_and_wordmark.svg.png");
ByteArrayInputStream stream = new ByteArrayInputStream(response.getOutput());
assertTrue("Expected to get the original asset back, since the requested width would result in upscaling the image.", IOUtils.contentEquals(directStream, stream));
}
use of org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class AdaptiveImageServletTest method testRequestWithWidthNoDesign.
@Test
public void testRequestWithWidthNoDesign() throws Exception {
Pair<MockSlingHttpServletRequest, MockSlingHttpServletResponse> requestResponsePair = prepareRequestResponsePair(IMAGE0_PATH, "img.800", "png");
MockSlingHttpServletRequest request = requestResponsePair.getLeft();
MockSlingHttpServletResponse response = requestResponsePair.getRight();
servlet.doGet(request, response);
assertEquals("Expected a 404 response when the request contains width information but no content policy has been defined.", HttpServletResponse.SC_NOT_FOUND, response.getStatus());
assertArrayEquals("Expected an empty response output.", new byte[0], response.getOutput());
}
Aggregations