Search in sources :

Example 1 with AssetStore

use of com.day.cq.dam.api.handler.store.AssetStore in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class AdaptiveImageServletMappingConfigurationConsumerTest method setUp.

@BeforeEach
public void setUp() {
    AssetStore assetStore = mock(AssetStore.class);
    context.registerService(AssetStore.class, assetStore);
    AdaptiveImageServletMetrics metrics = mock(AdaptiveImageServletMetrics.class);
    context.registerService(AdaptiveImageServletMetrics.class, metrics);
}
Also used : AssetStore(com.day.cq.dam.api.handler.store.AssetStore) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with AssetStore

use of com.day.cq.dam.api.handler.store.AssetStore in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class AdaptiveImageServletTest method init.

@Before
public void init() throws IOException {
    resourceResolver = aemContext.resourceResolver();
    servlet = new AdaptiveImageServlet();
    Whitebox.setInternalState(servlet, "mimeTypeService", mockedMimeTypeService);
    AssetHandler assetHandler = mock(AssetHandler.class);
    AssetStore assetStore = mock(AssetStore.class);
    when(assetStore.getAssetHandler(anyString())).thenReturn(assetHandler);
    when(assetHandler.getImage(any(Rendition.class))).thenAnswer(new Answer<BufferedImage>() {

        @Override
        public BufferedImage answer(InvocationOnMock invocationOnMock) throws Throwable {
            Rendition rendition = invocationOnMock.getArgumentAt(0, Rendition.class);
            return ImageIO.read(rendition.getStream());
        }
    });
    Whitebox.setInternalState(servlet, "assetStore", assetStore);
    activateServlet(servlet);
}
Also used : Rendition(com.day.cq.dam.api.Rendition) InvocationOnMock(org.mockito.invocation.InvocationOnMock) AssetHandler(com.day.cq.dam.api.handler.AssetHandler) AssetStore(com.day.cq.dam.api.handler.store.AssetStore) BufferedImage(java.awt.image.BufferedImage) Before(org.junit.Before)

Example 3 with AssetStore

use of com.day.cq.dam.api.handler.store.AssetStore in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class AdaptiveImageServletTest method setUp.

@BeforeEach
void setUp() throws Exception {
    internalSetUp(TEST_BASE);
    context.load().binaryFile("/image/" + PNG_IMAGE_RECTANGLE_BINARY_NAME, PNG_RECTANGLE_ASSET_PATH + "/jcr:content/renditions/original");
    context.load().binaryFile("/image/" + "cq5dam.web.1280.1280_" + PNG_IMAGE_BINARY_NAME, PNG_RECTANGLE_ASSET_PATH + "/jcr:content/renditions/cq5dam.web.1280.1280.png");
    context.load().binaryFile("/image/" + PNG_IMAGE_SMALL_BINARY_NAME, PNG_SMALL_ASSET_PATH + "/jcr:content/renditions/original");
    context.load().binaryFile("/image/" + "cq5dam.web.1280.1280_" + PNG_IMAGE_BINARY_NAME, PNG_SMALL_ASSET_PATH + "/jcr:content/renditions/cq5dam.web.1280.1280.png");
    resourceResolver = context.resourceResolver();
    AssetHandler assetHandler = mock(AssetHandler.class);
    AssetStore assetStore = mock(AssetStore.class);
    AdaptiveImageServletMetrics metrics = mock(AdaptiveImageServletMetrics.class);
    when(metrics.startDurationRecording()).thenReturn(mock(Timer.Context.class));
    when(assetStore.getAssetHandler(anyString())).thenReturn(assetHandler);
    IIORegistry registry = IIORegistry.getDefaultInstance();
    Iterator iter = registry.getServiceProviders(ImageReaderSpi.class, true);
    // Force ImageIO to pick TwelveMonkeys plugins for JPG and TIFF
    while (iter.hasNext()) {
        ImageReaderSpi provider = (ImageReaderSpi) iter.next();
        if (!provider.getClass().getName().contains("twelvemonkeys") && ((Arrays.stream(provider.getFormatNames()).filter(f -> "JPG".equalsIgnoreCase(f)).count() > 0) || (Arrays.stream(provider.getFormatNames()).filter(f -> "TIFF".equalsIgnoreCase(f)).count() > 0))) {
            registry.deregisterServiceProvider(provider);
        }
    }
    when(assetHandler.getImage(any(Rendition.class))).thenAnswer(invocation -> {
        Rendition rendition = invocation.getArgument(0);
        return ImageIO.read(rendition.getStream());
    });
    servlet = new AdaptiveImageServlet(mockedMimeTypeService, assetStore, metrics, ADAPTIVE_IMAGE_SERVLET_DEFAULT_RESIZE_WIDTH, AdaptiveImageServlet.DEFAULT_MAX_SIZE);
    testLogger = Utils.mockLogger(AdaptiveImageServlet.class, "LOGGER");
}
Also used : IIORegistry(javax.imageio.spi.IIORegistry) ImageReaderSpi(javax.imageio.spi.ImageReaderSpi) Rendition(com.day.cq.dam.api.Rendition) Iterator(java.util.Iterator) AssetHandler(com.day.cq.dam.api.handler.AssetHandler) AssetStore(com.day.cq.dam.api.handler.store.AssetStore) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

AssetStore (com.day.cq.dam.api.handler.store.AssetStore)3 Rendition (com.day.cq.dam.api.Rendition)2 AssetHandler (com.day.cq.dam.api.handler.AssetHandler)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 BufferedImage (java.awt.image.BufferedImage)1 Iterator (java.util.Iterator)1 IIORegistry (javax.imageio.spi.IIORegistry)1 ImageReaderSpi (javax.imageio.spi.ImageReaderSpi)1 Before (org.junit.Before)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1