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;
}
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;
}
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");
}
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.");
}
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.");
}
Aggregations