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