Search in sources :

Example 1 with MockValueMap

use of org.apache.sling.testing.resourceresolver.MockValueMap in project acs-aem-commons by Adobe-Consulting-Services.

the class EnsureOakIndexJobHandlerTest method getEnsureOakDefinition.

Resource getEnsureOakDefinition(Map<String, Object> properties) {
    Resource r = mock(Resource.class);
    ValueMap vm = new MockValueMap(r, properties);
    when(r.getValueMap()).thenReturn(vm);
    when(r.adaptTo(ModifiableValueMap.class)).thenReturn(new ModifiableValueMapDecorator(properties));
    when(r.getName()).thenReturn(INDEX_NAME);
    when(r.getPath()).thenReturn(DEFINITION_PATH);
    when(r.listChildren()).thenReturn(IteratorUtils.EMPTY_LIST_ITERATOR);
    return r;
}
Also used : ModifiableValueMapDecorator(org.apache.sling.api.wrappers.ModifiableValueMapDecorator) MockValueMap(org.apache.sling.testing.resourceresolver.MockValueMap) ValueMap(org.apache.sling.api.resource.ValueMap) MockValueMap(org.apache.sling.testing.resourceresolver.MockValueMap) ModifiableValueMap(org.apache.sling.api.resource.ModifiableValueMap) Resource(org.apache.sling.api.resource.Resource)

Example 2 with MockValueMap

use of org.apache.sling.testing.resourceresolver.MockValueMap in project acs-aem-commons by Adobe-Consulting-Services.

the class EnsureOakIndexJobHandlerTest method getOakDefinition.

Resource getOakDefinition(Map<String, Object> properties) {
    Resource r = mock(Resource.class);
    ValueMap vm = new MockValueMap(r, properties);
    when(r.adaptTo(ModifiableValueMap.class)).thenReturn(new ModifiableValueMapDecorator(properties));
    when(r.getValueMap()).thenReturn(vm);
    when(r.getName()).thenReturn(INDEX_NAME);
    when(r.getPath()).thenReturn(OAK_INDEX + "/" + INDEX_NAME);
    when(r.listChildren()).thenReturn(IteratorUtils.EMPTY_LIST_ITERATOR);
    return r;
}
Also used : ModifiableValueMapDecorator(org.apache.sling.api.wrappers.ModifiableValueMapDecorator) MockValueMap(org.apache.sling.testing.resourceresolver.MockValueMap) ValueMap(org.apache.sling.api.resource.ValueMap) MockValueMap(org.apache.sling.testing.resourceresolver.MockValueMap) ModifiableValueMap(org.apache.sling.api.resource.ModifiableValueMap) Resource(org.apache.sling.api.resource.Resource)

Example 3 with MockValueMap

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

the class AdaptiveImageServletTest method testTransformAndStreamAssetForTiffRenderedAsJpegWithoutJpegRenditionsAndUnableToProcess.

@Test
void testTransformAndStreamAssetForTiffRenderedAsJpegWithoutJpegRenditionsAndUnableToProcess() 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 }));
    when(mockAsset.getOriginal()).thenReturn(original);
    servlet.transformAndStreamAsset(response, new MockValueMap(request.getResource(), new HashMap<>()), 2000, 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 4 with MockValueMap

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

the class AdaptiveImageServletTest method testTransformAndStreamAssetForTiffRenderedAsJpegWithJpegRenditions.

@Test
void testTransformAndStreamAssetForTiffRenderedAsJpegWithJpegRenditions() 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");
    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<>()), 2000, 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(850, 850);
    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 5 with MockValueMap

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

the class AdaptiveImageServletTest method testTransformAndStreamAssetForTiffRenderedAsJpegWithoutJpegRenditions.

@Test
void testTransformAndStreamAssetForTiffRenderedAsJpegWithoutJpegRenditions() 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<>()), 2000, 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