Search in sources :

Example 6 with MockValueMap

use of org.apache.sling.testing.resourceresolver.MockValueMap in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class DownloadImplTest method testDownloadWithDefaultTitleType.

@Test
void testDownloadWithDefaultTitleType() {
    Resource mockResource = mock(Resource.class);
    Style mockStyle = new MockStyle(mockResource, new MockValueMap(mockResource));
    Download download = getDownloadUnderTest(DOWNLOAD_1, mockStyle);
    assertNull(download.getTitleType(), "Expected title type is not correct");
    Utils.testJSONExport(download, Utils.getTestExporterJSONPath(TEST_BASE, DOWNLOAD_FULLY_CONFIGURED));
}
Also used : MockValueMap(org.apache.sling.testing.resourceresolver.MockValueMap) Resource(org.apache.sling.api.resource.Resource) MockStyle(com.adobe.cq.wcm.core.components.testing.MockStyle) MockStyle(com.adobe.cq.wcm.core.components.testing.MockStyle) Style(com.day.cq.wcm.api.designer.Style) Download(com.adobe.cq.wcm.core.components.models.Download) Test(org.junit.jupiter.api.Test)

Example 7 with MockValueMap

use of org.apache.sling.testing.resourceresolver.MockValueMap in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class ContentFragmentUtilsTest method getGridTypeSetInFragmentPolicy.

@Test
public void getGridTypeSetInFragmentPolicy() {
    // GIVEN
    ContentPolicyManager contentPolicyManager = Mockito.mock(ContentPolicyManager.class);
    ContentPolicy contentPolicy = Mockito.mock(ContentPolicy.class);
    ResourceResolver resourceResolver = Mockito.mock(ResourceResolver.class);
    Resource resource = Mockito.mock(Resource.class);
    ValueMap valueMap = new MockValueMap(resource);
    valueMap.put(PN_CFM_GRID_TYPE, "foobar");
    Mockito.when(resource.getResourceResolver()).thenReturn(resourceResolver);
    Mockito.when(resourceResolver.adaptTo(Mockito.eq(ContentPolicyManager.class))).thenReturn(contentPolicyManager);
    Mockito.when(contentPolicyManager.getPolicy(Mockito.eq(resource))).thenReturn(contentPolicy);
    Mockito.when(contentPolicy.getProperties()).thenReturn(valueMap);
    // WHEN
    String defaultGridResourceType = ContentFragmentUtils.getGridResourceType(resource);
    // THEN
    Assertions.assertEquals(defaultGridResourceType, "foobar");
}
Also used : ContentPolicyManager(com.day.cq.wcm.api.policies.ContentPolicyManager) MockValueMap(org.apache.sling.testing.resourceresolver.MockValueMap) ValueMap(org.apache.sling.api.resource.ValueMap) MockValueMap(org.apache.sling.testing.resourceresolver.MockValueMap) ContentPolicy(com.day.cq.wcm.api.policies.ContentPolicy) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Resource(org.apache.sling.api.resource.Resource) Test(org.junit.jupiter.api.Test)

Example 8 with MockValueMap

use of org.apache.sling.testing.resourceresolver.MockValueMap in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class AdaptiveImageServletTest method testTransformAndStreamAssetForTiffRenderedAsJpegWithJpegRenditionsWithResize.

@Test
void testTransformAndStreamAssetForTiffRenderedAsJpegWithJpegRenditionsWithResize() throws IOException {
    Pair<MockSlingHttpServletRequest, MockSlingHttpServletResponse> requestResponsePair = prepareRequestResponsePair(IMAGE0_PATH, "img.800", "png");
    MockSlingHttpServletRequest request = requestResponsePair.getLeft();
    MockSlingHttpServletResponse response = requestResponsePair.getRight();
    Asset mockAsset = mock(Asset.class);
    when(mockAsset.getMimeType()).thenReturn("image/tiff");
    Rendition smallerJpeg = mockRendition(mockAsset, "750px", 1000000, "image/jpeg", 750, 750);
    Rendition largerJpeg = mockRendition(mockAsset, "850px", 2000000, "image/jpeg", 850, 850);
    when(largerJpeg.getStream()).thenReturn(this.getClass().getClassLoader().getResourceAsStream("image/Adobe_Systems_logo_and_wordmark.850.jpg"));
    when(mockAsset.getRenditions()).thenReturn(new LinkedList<Rendition>() {

        {
            add(smallerJpeg);
            add(largerJpeg);
        }
    });
    when(mockAsset.getMetadataValue(DamConstants.TIFF_IMAGEWIDTH)).thenReturn("2000");
    when(mockAsset.getMetadataValue(DamConstants.TIFF_IMAGELENGTH)).thenReturn("2000");
    Rendition original = mockRendition(mockAsset, "original", 9999999, "image/tiff", 2000, 2000);
    when(mockAsset.getOriginal()).thenReturn(original);
    servlet.transformAndStreamAsset(response, new MockValueMap(request.getResource(), new HashMap<>()), 800, 90, mockAsset, "image/jpeg", "test");
    Assertions.assertEquals(200, response.getStatus(), "Expected a 200 response code.");
    Assertions.assertEquals("image/jpeg", response.getContentType(), "Expected a JPG image.");
    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());
    Assertions.assertEquals(expectedDimension, actualDimension, "Expected image rendered at requested size.");
}
Also used : MockValueMap(org.apache.sling.testing.resourceresolver.MockValueMap) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) MockSlingHttpServletRequest(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest) Rendition(com.day.cq.dam.api.Rendition) MockSlingHttpServletResponse(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse) Asset(com.day.cq.dam.api.Asset) BufferedImage(java.awt.image.BufferedImage) Test(org.junit.jupiter.api.Test) AbstractImageTest(com.adobe.cq.wcm.core.components.internal.models.v1.AbstractImageTest)

Example 9 with MockValueMap

use of org.apache.sling.testing.resourceresolver.MockValueMap in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class AdaptiveImageServletTest method testTransformAndStreamAssetForTiffRenderedAsJpegWithoutJpegRenditionsAndUnableToProcessWithResize.

@Test
void testTransformAndStreamAssetForTiffRenderedAsJpegWithoutJpegRenditionsAndUnableToProcessWithResize() throws IOException {
    Pair<MockSlingHttpServletRequest, MockSlingHttpServletResponse> requestResponsePair = prepareRequestResponsePair(IMAGE0_PATH, "img.2000", "png");
    MockSlingHttpServletRequest request = requestResponsePair.getLeft();
    MockSlingHttpServletResponse response = requestResponsePair.getRight();
    Asset mockAsset = mock(Asset.class);
    when(mockAsset.getMimeType()).thenReturn("image/tiff");
    when(mockAsset.getRenditions()).thenReturn(new LinkedList<>());
    when(mockAsset.getMetadataValue(DamConstants.TIFF_IMAGEWIDTH)).thenReturn("2000");
    when(mockAsset.getMetadataValue(DamConstants.TIFF_IMAGELENGTH)).thenReturn("2000");
    Rendition original = mockRendition(mockAsset, "original", 9999999, "image/tiff", 2000, 2000);
    when(original.getStream()).thenReturn(new ByteArrayInputStream(new byte[] { 0, 1, 2 }), new ByteArrayInputStream(new byte[] { 0, 1, 2 }), new ByteArrayInputStream(new byte[] { 0, 1, 2 }));
    when(mockAsset.getOriginal()).thenReturn(original);
    servlet.transformAndStreamAsset(response, new MockValueMap(request.getResource(), new HashMap<>()), 800, 90, mockAsset, "image/jpeg", "test");
    Assertions.assertEquals(200, response.getStatus(), "Expected a 200 response code.");
    Assertions.assertEquals("image/tiff", response.getContentType(), "Expected a TIFF image.");
    Assertions.assertEquals(3, response.getOutput().length, "Expected three-byte original TIFF");
}
Also used : MockValueMap(org.apache.sling.testing.resourceresolver.MockValueMap) ByteArrayInputStream(java.io.ByteArrayInputStream) HashMap(java.util.HashMap) MockSlingHttpServletRequest(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest) Rendition(com.day.cq.dam.api.Rendition) MockSlingHttpServletResponse(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse) Asset(com.day.cq.dam.api.Asset) Test(org.junit.jupiter.api.Test) AbstractImageTest(com.adobe.cq.wcm.core.components.internal.models.v1.AbstractImageTest)

Example 10 with MockValueMap

use of org.apache.sling.testing.resourceresolver.MockValueMap in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class AdaptiveImageServletTest method testTransformAndStreamAssetForTiffRenderedAsJpegWithoutJpegRenditionsNoResize.

@Test
void testTransformAndStreamAssetForTiffRenderedAsJpegWithoutJpegRenditionsNoResize() throws IOException {
    Pair<MockSlingHttpServletRequest, MockSlingHttpServletResponse> requestResponsePair = prepareRequestResponsePair(IMAGE0_PATH, "img.2000", "png");
    MockSlingHttpServletRequest request = requestResponsePair.getLeft();
    MockSlingHttpServletResponse response = requestResponsePair.getRight();
    Asset mockAsset = mock(Asset.class);
    when(mockAsset.getMimeType()).thenReturn("image/tiff");
    when(mockAsset.getRenditions()).thenReturn(new LinkedList<>());
    when(mockAsset.getMetadataValue(DamConstants.TIFF_IMAGEWIDTH)).thenReturn("2000");
    when(mockAsset.getMetadataValue(DamConstants.TIFF_IMAGELENGTH)).thenReturn("2000");
    Rendition original = mockRendition(mockAsset, "original", 9999999, "image/tiff", 2000, 2000);
    when(original.getStream()).thenReturn(this.getClass().getClassLoader().getResourceAsStream("image/Adobe_Systems_logo_and_wordmark.tiff"));
    when(mockAsset.getOriginal()).thenReturn(original);
    servlet.transformAndStreamAsset(response, new MockValueMap(request.getResource(), new HashMap<>()), 0, 90, mockAsset, "image/jpeg", "test");
    Assertions.assertEquals(200, response.getStatus(), "Expected a 200 response code.");
    Assertions.assertEquals("image/jpeg", response.getContentType(), "Expected a JPG image.");
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(response.getOutput());
    BufferedImage image = ImageIO.read(byteArrayInputStream);
    Dimension expectedDimension = new Dimension(2000, 2000);
    Dimension actualDimension = new Dimension(image.getWidth(), image.getHeight());
    Assertions.assertEquals(expectedDimension, actualDimension, "Expected image rendered at requested size.");
}
Also used : MockValueMap(org.apache.sling.testing.resourceresolver.MockValueMap) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) MockSlingHttpServletRequest(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest) Rendition(com.day.cq.dam.api.Rendition) MockSlingHttpServletResponse(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse) Asset(com.day.cq.dam.api.Asset) BufferedImage(java.awt.image.BufferedImage) Test(org.junit.jupiter.api.Test) AbstractImageTest(com.adobe.cq.wcm.core.components.internal.models.v1.AbstractImageTest)

Aggregations

MockValueMap (org.apache.sling.testing.resourceresolver.MockValueMap)13 Test (org.junit.jupiter.api.Test)11 Resource (org.apache.sling.api.resource.Resource)7 AbstractImageTest (com.adobe.cq.wcm.core.components.internal.models.v1.AbstractImageTest)6 Asset (com.day.cq.dam.api.Asset)6 Rendition (com.day.cq.dam.api.Rendition)6 ByteArrayInputStream (java.io.ByteArrayInputStream)6 HashMap (java.util.HashMap)6 MockSlingHttpServletRequest (org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest)6 MockSlingHttpServletResponse (org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse)6 ValueMap (org.apache.sling.api.resource.ValueMap)5 BufferedImage (java.awt.image.BufferedImage)4 ContentFragment (com.adobe.cq.dam.cfm.ContentFragment)2 Download (com.adobe.cq.wcm.core.components.models.Download)2 MockStyle (com.adobe.cq.wcm.core.components.testing.MockStyle)2 Style (com.day.cq.wcm.api.designer.Style)2 ModifiableValueMap (org.apache.sling.api.resource.ModifiableValueMap)2 ModifiableValueMapDecorator (org.apache.sling.api.wrappers.ModifiableValueMapDecorator)2 FragmentTemplate (com.adobe.cq.dam.cfm.FragmentTemplate)1 ContentPolicy (com.day.cq.wcm.api.policies.ContentPolicy)1