use of org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class AdaptiveImageServletTest method testImageFileCropScalingWithRotation.
@Test
public void testImageFileCropScalingWithRotation() throws Exception {
Pair<MockSlingHttpServletRequest, MockSlingHttpServletResponse> requestResponsePair = prepareRequestResponsePair(IMAGE14_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 515px width, since the servlet should not perform cropping upscaling.", 515, image.getWidth());
assertEquals("Expected the cropped rectangle to have a 1390px height, since the servlet should not perform cropping upscaling.", 1390, 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 testImageFileCrop.
@Test
public void testImageFileCrop() throws Exception {
Pair<MockSlingHttpServletRequest, MockSlingHttpServletResponse> requestResponsePair = prepareRequestResponsePair(IMAGE12_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 1440px width, since the servlet should not perform cropping upscaling.", 1440, image.getWidth());
assertEquals("Expected the cropped rectangle to have a 1440px height, since the servlet should not perform cropping upscaling.", 1440, 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 testInvalidWidthSelector.
@Test
public void testInvalidWidthSelector() throws Exception {
Pair<MockSlingHttpServletRequest, MockSlingHttpServletResponse> requestResponsePair = prepareRequestResponsePair(IMAGE0_PATH, "img.full", "png");
MockSlingHttpServletRequest request = requestResponsePair.getLeft();
MockSlingHttpServletResponse response = requestResponsePair.getRight();
servlet.doGet(request, response);
assertEquals("Expected a 404 response when the request has an invalid width selector.", 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 testWithInvalidDesignWidth.
@Test
public void testWithInvalidDesignWidth() throws Exception {
Logger logger = spy(LoggerFactory.getLogger("FakeLogger"));
setFinalStatic(AdaptiveImageServlet.class.getDeclaredField("LOGGER"), logger);
Pair<MockSlingHttpServletRequest, MockSlingHttpServletResponse> requestResponsePair = prepareRequestResponsePair(IMAGE1_PATH, "img.700", "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 byteArrayInputStream = new ByteArrayInputStream(response.getOutput());
BufferedImage image = ImageIO.read(byteArrayInputStream);
Dimension expectedDimension = new Dimension(700, 700);
Dimension actualDimension = new Dimension(image.getWidth(), image.getHeight());
assertEquals("Expected image rendered at requested size.", expectedDimension, actualDimension);
assertEquals("Expected a PNG image.", "image/png", response.getContentType());
verify(logger).warn("One of the configured widths ({}) from the {} content policy is not a valid Integer.", "invalid", "/conf/coretest/settings/wcm/policies/coretest/components/content/image/policy_1478854677327");
}
use of org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class AdaptiveImageServletTest method testCorrectScalingPNGAssetWidth.
@Test
public void testCorrectScalingPNGAssetWidth() throws Exception {
Pair<MockSlingHttpServletRequest, MockSlingHttpServletResponse> requestResponsePair = prepareRequestResponsePair(IMAGE0_PATH, "img.2000", "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 is equal to the image's width.", IOUtils.contentEquals(directStream, stream));
}
Aggregations