Search in sources :

Example 11 with ContentPolicyMapping

use of com.day.cq.wcm.api.policies.ContentPolicyMapping in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class AdaptiveImageServletTest method testDAMAssetCropScalingWithRotation.

@Test
public void testDAMAssetCropScalingWithRotation() throws Exception {
    Pair<MockSlingHttpServletRequest, MockSlingHttpServletResponse> requestResponsePair = prepareRequestResponsePair(IMAGE13_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());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) MockSlingHttpServletRequest(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest) ContentPolicyMapping(com.day.cq.wcm.api.policies.ContentPolicyMapping) ContentPolicy(com.day.cq.wcm.api.policies.ContentPolicy) MockSlingHttpServletResponse(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse) BufferedImage(java.awt.image.BufferedImage) Test(org.junit.Test)

Example 12 with ContentPolicyMapping

use of com.day.cq.wcm.api.policies.ContentPolicyMapping in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class AdaptiveImageServletTest method testDAMAssetCrop.

@Test
public void testDAMAssetCrop() throws Exception {
    Pair<MockSlingHttpServletRequest, MockSlingHttpServletResponse> requestResponsePair = prepareRequestResponsePair(IMAGE11_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());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) MockSlingHttpServletRequest(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest) ContentPolicyMapping(com.day.cq.wcm.api.policies.ContentPolicyMapping) ContentPolicy(com.day.cq.wcm.api.policies.ContentPolicy) MockSlingHttpServletResponse(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse) BufferedImage(java.awt.image.BufferedImage) Test(org.junit.Test)

Example 13 with ContentPolicyMapping

use of com.day.cq.wcm.api.policies.ContentPolicyMapping 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());
}
Also used : MockSlingHttpServletRequest(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest) ContentPolicyMapping(com.day.cq.wcm.api.policies.ContentPolicyMapping) ContentPolicy(com.day.cq.wcm.api.policies.ContentPolicy) MockSlingHttpServletResponse(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse) Test(org.junit.Test)

Example 14 with ContentPolicyMapping

use of com.day.cq.wcm.api.policies.ContentPolicyMapping 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());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) MockSlingHttpServletRequest(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest) ContentPolicyMapping(com.day.cq.wcm.api.policies.ContentPolicyMapping) ContentPolicy(com.day.cq.wcm.api.policies.ContentPolicy) MockSlingHttpServletResponse(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse) BufferedImage(java.awt.image.BufferedImage) Test(org.junit.Test)

Example 15 with ContentPolicyMapping

use of com.day.cq.wcm.api.policies.ContentPolicyMapping 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());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) MockSlingHttpServletRequest(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest) ContentPolicyMapping(com.day.cq.wcm.api.policies.ContentPolicyMapping) ContentPolicy(com.day.cq.wcm.api.policies.ContentPolicy) MockSlingHttpServletResponse(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse) BufferedImage(java.awt.image.BufferedImage) Test(org.junit.Test)

Aggregations

ContentPolicy (com.day.cq.wcm.api.policies.ContentPolicy)17 ContentPolicyMapping (com.day.cq.wcm.api.policies.ContentPolicyMapping)17 MockSlingHttpServletRequest (org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest)17 MockSlingHttpServletResponse (org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse)15 Test (org.junit.Test)15 ByteArrayInputStream (java.io.ByteArrayInputStream)12 BufferedImage (java.awt.image.BufferedImage)10 Style (com.day.cq.wcm.api.designer.Style)2 InputStream (java.io.InputStream)2 Resource (org.apache.sling.api.resource.Resource)2 SlingBindings (org.apache.sling.api.scripting.SlingBindings)2 SightlyWCMMode (com.adobe.cq.sightly.SightlyWCMMode)1 MockStyle (com.adobe.cq.wcm.core.components.context.MockStyle)1 Page (com.day.cq.wcm.api.Page)1 Template (com.day.cq.wcm.api.Template)1 Design (com.day.cq.wcm.api.designer.Design)1 Logger (org.slf4j.Logger)1