use of com.day.cq.wcm.api.policies.ContentPolicy in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class AdaptiveImageServletTest method testDAMAssetCropScaling.
@Test
public void testDAMAssetCropScaling() throws Exception {
Pair<MockSlingHttpServletRequest, MockSlingHttpServletResponse> requestResponsePair = prepareRequestResponsePair(IMAGE9_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 com.day.cq.wcm.api.policies.ContentPolicy in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class AdaptiveImageServletTest method testRequestWithWidthDesignAllowed.
@Test
public void testRequestWithWidthDesignAllowed() throws Exception {
Pair<MockSlingHttpServletRequest, MockSlingHttpServletResponse> requestResponsePair = prepareRequestResponsePair(IMAGE0_PATH, "img.800", "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(800, 800);
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());
}
use of com.day.cq.wcm.api.policies.ContentPolicy in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class AdaptiveImageServletTest method testDAMAssetWithNegativeRequestedWidth.
@Test
public void testDAMAssetWithNegativeRequestedWidth() throws Exception {
Pair<MockSlingHttpServletRequest, MockSlingHttpServletResponse> requestResponsePair = prepareRequestResponsePair(IMAGE8_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 com.day.cq.wcm.api.policies.ContentPolicy 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 com.day.cq.wcm.api.policies.ContentPolicy 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());
}
Aggregations