diff --git a/src/main/java/io/wcm/handler/media/impl/MediaHandlerConfigAdapterFactory.java b/src/main/java/io/wcm/handler/media/impl/MediaHandlerAdapterFactory.java similarity index 73% rename from src/main/java/io/wcm/handler/media/impl/MediaHandlerConfigAdapterFactory.java rename to src/main/java/io/wcm/handler/media/impl/MediaHandlerAdapterFactory.java index 3a3b681e..fd38bd8a 100644 --- a/src/main/java/io/wcm/handler/media/impl/MediaHandlerConfigAdapterFactory.java +++ b/src/main/java/io/wcm/handler/media/impl/MediaHandlerAdapterFactory.java @@ -21,11 +21,14 @@ import org.apache.sling.api.adapter.Adaptable; import org.apache.sling.api.adapter.AdapterFactory; +import org.apache.sling.api.resource.Resource; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; +import io.wcm.handler.media.MediaComponentPropertyResolver; import io.wcm.handler.media.spi.MediaHandlerConfig; import io.wcm.sling.commons.caservice.ContextAwareServiceResolver; +import io.wcm.wcm.commons.component.ComponentPropertyResolverFactory; /** * Adapts resources or requests to {@link MediaHandlerConfig} via {@link ContextAwareServiceResolver}. @@ -34,12 +37,15 @@ property = { AdapterFactory.ADAPTABLE_CLASSES + "=org.apache.sling.api.resource.Resource", AdapterFactory.ADAPTABLE_CLASSES + "=org.apache.sling.api.SlingHttpServletRequest", - AdapterFactory.ADAPTER_CLASSES + "=io.wcm.handler.media.spi.MediaHandlerConfig" + AdapterFactory.ADAPTER_CLASSES + "=io.wcm.handler.media.spi.MediaHandlerConfig", + AdapterFactory.ADAPTER_CLASSES + "=io.wcm.handler.media.MediaComponentPropertyResolver" }) -public class MediaHandlerConfigAdapterFactory implements AdapterFactory { +public class MediaHandlerAdapterFactory implements AdapterFactory { @Reference private ContextAwareServiceResolver serviceResolver; + @Reference + private ComponentPropertyResolverFactory componentPropertyResolverFactory; @SuppressWarnings({ "unchecked", "null" }) @Override @@ -47,6 +53,9 @@ public AdapterType getAdapter(Object adaptable, Class if (type == MediaHandlerConfig.class) { return (AdapterType)serviceResolver.resolve(MediaHandlerConfig.class, (Adaptable)adaptable); } + if (type == MediaComponentPropertyResolver.class && adaptable instanceof Resource) { + return (AdapterType)new MediaComponentPropertyResolver((Resource)adaptable, componentPropertyResolverFactory); + } return null; } diff --git a/src/main/webapp/app-root/components/granite/form/fileupload/fileupload.jsp b/src/main/webapp/app-root/components/granite/form/fileupload/fileupload.jsp index 19be9d12..740502d3 100644 --- a/src/main/webapp/app-root/components/granite/form/fileupload/fileupload.jsp +++ b/src/main/webapp/app-root/components/granite/form/fileupload/fileupload.jsp @@ -166,13 +166,14 @@ String[] mediaFormats = null; String[] mediaFormatsMandatory = null; boolean mediaCropAuto = false; if (contentResource != null) { - MediaComponentPropertyResolver componentPropertyResolver = new MediaComponentPropertyResolver(contentResource); - mediaFormats = getStringArrayWithExpressionSupport("mediaFormats", - MediaNameConstants.PN_COMPONENT_MEDIA_FORMATS, cfg, ex, componentPropertyResolver.getMediaFormatNames()); - mediaFormatsMandatory = getStringArrayWithExpressionSupport("mediaFormatsMandatory", - MediaNameConstants.PN_COMPONENT_MEDIA_FORMATS_MANDATORY, cfg, ex, componentPropertyResolver.getMandatoryMediaFormatNames()); - mediaCropAuto = getBooleanWithExpressionSupport("mediaCropAuto", - MediaNameConstants.PN_COMPONENT_MEDIA_AUTOCROP, cfg, ex, componentPropertyResolver.isAutoCrop()); + try (MediaComponentPropertyResolver componentPropertyResolver = contentResource.adaptTo(MediaComponentPropertyResolver.class)) { + mediaFormats = getStringArrayWithExpressionSupport("mediaFormats", + MediaNameConstants.PN_COMPONENT_MEDIA_FORMATS, cfg, ex, componentPropertyResolver.getMediaFormatNames()); + mediaFormatsMandatory = getStringArrayWithExpressionSupport("mediaFormatsMandatory", + MediaNameConstants.PN_COMPONENT_MEDIA_FORMATS_MANDATORY, cfg, ex, componentPropertyResolver.getMandatoryMediaFormatNames()); + mediaCropAuto = getBooleanWithExpressionSupport("mediaCropAuto", + MediaNameConstants.PN_COMPONENT_MEDIA_AUTOCROP, cfg, ex, componentPropertyResolver.isAutoCrop()); + } // add info about media formats in field description String mediaFormatsFieldDescription = buildMediaFormatsFieldDescription(mediaFormats, contentResource, i18n); diff --git a/src/main/webapp/app-root/components/granite/form/pathfield/pathfield.jsp b/src/main/webapp/app-root/components/granite/form/pathfield/pathfield.jsp index 883fae67..d516f731 100644 --- a/src/main/webapp/app-root/components/granite/form/pathfield/pathfield.jsp +++ b/src/main/webapp/app-root/components/granite/form/pathfield/pathfield.jsp @@ -132,13 +132,14 @@ String[] mediaFormats = null; String[] mediaFormatsMandatory = null; boolean mediaCropAuto = false; if (contentResource != null) { - MediaComponentPropertyResolver componentPropertyResolver = new MediaComponentPropertyResolver(contentResource); - mediaFormats = getStringArrayWithExpressionSupport("mediaFormats", - MediaNameConstants.PN_COMPONENT_MEDIA_FORMATS, cfg, ex, componentPropertyResolver.getMediaFormatNames()); - mediaFormatsMandatory = getStringArrayWithExpressionSupport("mediaFormatsMandatory", - MediaNameConstants.PN_COMPONENT_MEDIA_FORMATS_MANDATORY, cfg, ex, componentPropertyResolver.getMandatoryMediaFormatNames()); - mediaCropAuto = getBooleanWithExpressionSupport("mediaCropAuto", - MediaNameConstants.PN_COMPONENT_MEDIA_AUTOCROP, cfg, ex, componentPropertyResolver.isAutoCrop()); + try (MediaComponentPropertyResolver componentPropertyResolver = contentResource.adaptTo(MediaComponentPropertyResolver.class)) { + mediaFormats = getStringArrayWithExpressionSupport("mediaFormats", + MediaNameConstants.PN_COMPONENT_MEDIA_FORMATS, cfg, ex, componentPropertyResolver.getMediaFormatNames()); + mediaFormatsMandatory = getStringArrayWithExpressionSupport("mediaFormatsMandatory", + MediaNameConstants.PN_COMPONENT_MEDIA_FORMATS_MANDATORY, cfg, ex, componentPropertyResolver.getMandatoryMediaFormatNames()); + mediaCropAuto = getBooleanWithExpressionSupport("mediaCropAuto", + MediaNameConstants.PN_COMPONENT_MEDIA_AUTOCROP, cfg, ex, componentPropertyResolver.isAutoCrop()); + } // add info about media formats in field description String mediaFormatsFieldDescription = buildMediaFormatsFieldDescription(mediaFormats, contentResource, i18n); diff --git a/src/test/java/io/wcm/handler/media/MediaComponentPropertyResolverTest.java b/src/test/java/io/wcm/handler/media/MediaComponentPropertyResolverTest.java index e1afe33d..5b5f3a0b 100644 --- a/src/test/java/io/wcm/handler/media/MediaComponentPropertyResolverTest.java +++ b/src/test/java/io/wcm/handler/media/MediaComponentPropertyResolverTest.java @@ -49,7 +49,6 @@ import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ValueMap; import org.apache.sling.api.wrappers.ValueMapDecorator; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -58,9 +57,9 @@ import io.wcm.handler.media.MediaArgs.PictureSource; import io.wcm.handler.media.MediaArgs.WidthOption; import io.wcm.handler.media.testcontext.AppAemContext; +import io.wcm.sling.commons.adapter.AdaptTo; import io.wcm.testing.mock.aem.junit5.AemContext; import io.wcm.testing.mock.aem.junit5.AemContextExtension; -import io.wcm.wcm.commons.component.ComponentPropertyResolverFactory; @ExtendWith(AemContextExtension.class) class MediaComponentPropertyResolverTest { @@ -69,19 +68,12 @@ class MediaComponentPropertyResolverTest { private final AemContext context = AppAemContext.newAemContext(); - private ComponentPropertyResolverFactory componentPropertyResolverFactory; - - @BeforeEach - void setUp() { - componentPropertyResolverFactory = context.getService(ComponentPropertyResolverFactory.class); - } - @Test void testIsAutoCrop_Default() throws Exception { Resource resource = context.create().resource("/content/r1"); context.resourceResolver().commit(); - try (MediaComponentPropertyResolver underTest = new MediaComponentPropertyResolver(resource, componentPropertyResolverFactory)) { + try (MediaComponentPropertyResolver underTest = AdaptTo.notNull(resource, MediaComponentPropertyResolver.class)) { assertFalse(underTest.isAutoCrop()); } } @@ -94,7 +86,7 @@ void testIsAutoCrop_Component() throws Exception { PROPERTY_RESOURCE_TYPE, RESOURCE_TYPE); context.resourceResolver().commit(); - try (MediaComponentPropertyResolver underTest = new MediaComponentPropertyResolver(resource, componentPropertyResolverFactory)) { + try (MediaComponentPropertyResolver underTest = AdaptTo.notNull(resource, MediaComponentPropertyResolver.class)) { assertTrue(underTest.isAutoCrop()); } } @@ -110,7 +102,7 @@ void testIsAutoCrop_Component_Subresource() throws Exception { Resource subresource2 = context.create().resource(subresource1, "subresource2"); context.resourceResolver().commit(); - try (MediaComponentPropertyResolver underTest = new MediaComponentPropertyResolver(subresource2, componentPropertyResolverFactory)) { + try (MediaComponentPropertyResolver underTest = AdaptTo.notNull(subresource2, MediaComponentPropertyResolver.class)) { assertTrue(underTest.isAutoCrop()); } } @@ -126,7 +118,7 @@ void testIsAutoCrop_Component_Policy() throws Exception { PROPERTY_RESOURCE_TYPE, RESOURCE_TYPE); context.resourceResolver().commit(); - try (MediaComponentPropertyResolver underTest = new MediaComponentPropertyResolver(resource, componentPropertyResolverFactory)) { + try (MediaComponentPropertyResolver underTest = AdaptTo.notNull(resource, MediaComponentPropertyResolver.class)) { assertFalse(underTest.isAutoCrop()); } } @@ -148,7 +140,7 @@ void testGetMediaFormatOptions_Single() throws Exception { PROPERTY_RESOURCE_TYPE, RESOURCE_TYPE); context.resourceResolver().commit(); - try (MediaComponentPropertyResolver underTest = new MediaComponentPropertyResolver(resource, componentPropertyResolverFactory)) { + try (MediaComponentPropertyResolver underTest = AdaptTo.notNull(resource, MediaComponentPropertyResolver.class)) { assertArrayEquals(new MediaFormatOption[] { new MediaFormatOption("home_stage", false) }, underTest.getMediaFormatOptions()); @@ -163,7 +155,7 @@ void testGetMediaFormatOptions_Multi() throws Exception { PROPERTY_RESOURCE_TYPE, RESOURCE_TYPE); context.resourceResolver().commit(); - try (MediaComponentPropertyResolver underTest = new MediaComponentPropertyResolver(resource, componentPropertyResolverFactory)) { + try (MediaComponentPropertyResolver underTest = AdaptTo.notNull(resource, MediaComponentPropertyResolver.class)) { assertArrayEquals(new MediaFormatOption[] { new MediaFormatOption("home_stage", false), new MediaFormatOption("home_teaser", false) @@ -186,7 +178,7 @@ void testGetMediaFormatOptions_Multi_MandatoryLegacy() throws Exception { PROPERTY_RESOURCE_TYPE, RESOURCE_TYPE); context.resourceResolver().commit(); - try (MediaComponentPropertyResolver underTest = new MediaComponentPropertyResolver(resource, componentPropertyResolverFactory)) { + try (MediaComponentPropertyResolver underTest = AdaptTo.notNull(resource, MediaComponentPropertyResolver.class)) { assertArrayEquals(new MediaFormatOption[] { new MediaFormatOption("home_stage", true), new MediaFormatOption("home_teaser", true) @@ -212,7 +204,7 @@ void testGetMediaFormatOptions_Multi_Mandatory() throws Exception { PROPERTY_RESOURCE_TYPE, RESOURCE_TYPE); context.resourceResolver().commit(); - try (MediaComponentPropertyResolver underTest = new MediaComponentPropertyResolver(resource, componentPropertyResolverFactory)) { + try (MediaComponentPropertyResolver underTest = AdaptTo.notNull(resource, MediaComponentPropertyResolver.class)) { assertArrayEquals(new MediaFormatOption[] { new MediaFormatOption("home_stage", true), new MediaFormatOption("home_teaser", false) @@ -237,7 +229,7 @@ void testGetMediaFormatOptions_Multi_Mandatory_Names() throws Exception { PROPERTY_RESOURCE_TYPE, RESOURCE_TYPE); context.resourceResolver().commit(); - try (MediaComponentPropertyResolver underTest = new MediaComponentPropertyResolver(resource, componentPropertyResolverFactory)) { + try (MediaComponentPropertyResolver underTest = AdaptTo.notNull(resource, MediaComponentPropertyResolver.class)) { assertArrayEquals(new MediaFormatOption[] { new MediaFormatOption("home_stage", true), new MediaFormatOption("home_teaser", false), @@ -283,7 +275,7 @@ void testGetImageSizes_NotExisting() throws Exception { PROPERTY_RESOURCE_TYPE, RESOURCE_TYPE); context.resourceResolver().commit(); - try (MediaComponentPropertyResolver underTest = new MediaComponentPropertyResolver(resource, componentPropertyResolverFactory)) { + try (MediaComponentPropertyResolver underTest = AdaptTo.notNull(resource, MediaComponentPropertyResolver.class)) { assertNull(underTest.getImageSizes()); } } @@ -296,7 +288,7 @@ void testGetImageSizes_Empty() throws Exception { PROPERTY_RESOURCE_TYPE, RESOURCE_TYPE); context.resourceResolver().commit(); - try (MediaComponentPropertyResolver underTest = new MediaComponentPropertyResolver(resource, componentPropertyResolverFactory)) { + try (MediaComponentPropertyResolver underTest = AdaptTo.notNull(resource, MediaComponentPropertyResolver.class)) { assertNull(underTest.getImageSizes()); } } @@ -311,7 +303,7 @@ void testGetImageSizes_Valid() throws Exception { PROPERTY_RESOURCE_TYPE, RESOURCE_TYPE); context.resourceResolver().commit(); - try (MediaComponentPropertyResolver underTest = new MediaComponentPropertyResolver(resource, componentPropertyResolverFactory)) { + try (MediaComponentPropertyResolver underTest = AdaptTo.notNull(resource, MediaComponentPropertyResolver.class)) { assertEquals(new ImageSizes("sizes1", new WidthOption[] { new WidthOption(200, true), new WidthOption(400, true), @@ -330,7 +322,7 @@ void testGetImageSizes_Invalid() throws Exception { PROPERTY_RESOURCE_TYPE, RESOURCE_TYPE); context.resourceResolver().commit(); - try (MediaComponentPropertyResolver underTest = new MediaComponentPropertyResolver(resource, componentPropertyResolverFactory)) { + try (MediaComponentPropertyResolver underTest = AdaptTo.notNull(resource, MediaComponentPropertyResolver.class)) { assertNull(underTest.getImageSizes()); } } @@ -346,7 +338,7 @@ void testGetImageSizes_Valid_Active() throws Exception { PROPERTY_RESOURCE_TYPE, RESOURCE_TYPE); context.resourceResolver().commit(); - try (MediaComponentPropertyResolver underTest = new MediaComponentPropertyResolver(resource, componentPropertyResolverFactory)) { + try (MediaComponentPropertyResolver underTest = AdaptTo.notNull(resource, MediaComponentPropertyResolver.class)) { assertEquals(new ImageSizes("sizes1", 200, 400), underTest.getImageSizes()); } } @@ -362,7 +354,7 @@ void testGetImageSizes_Valid_NotActive() throws Exception { PROPERTY_RESOURCE_TYPE, RESOURCE_TYPE); context.resourceResolver().commit(); - try (MediaComponentPropertyResolver underTest = new MediaComponentPropertyResolver(resource, componentPropertyResolverFactory)) { + try (MediaComponentPropertyResolver underTest = AdaptTo.notNull(resource, MediaComponentPropertyResolver.class)) { assertNull(underTest.getImageSizes()); } } @@ -374,7 +366,7 @@ void testGetPictureSources_NotExisting() throws Exception { PROPERTY_RESOURCE_TYPE, RESOURCE_TYPE); context.resourceResolver().commit(); - try (MediaComponentPropertyResolver underTest = new MediaComponentPropertyResolver(resource, componentPropertyResolverFactory)) { + try (MediaComponentPropertyResolver underTest = AdaptTo.notNull(resource, MediaComponentPropertyResolver.class)) { assertNull(underTest.getPictureSources()); } } @@ -387,7 +379,7 @@ void testGetPictureSources_Empty() throws Exception { PROPERTY_RESOURCE_TYPE, RESOURCE_TYPE); context.resourceResolver().commit(); - try (MediaComponentPropertyResolver underTest = new MediaComponentPropertyResolver(resource, componentPropertyResolverFactory)) { + try (MediaComponentPropertyResolver underTest = AdaptTo.notNull(resource, MediaComponentPropertyResolver.class)) { assertNull(underTest.getImageSizes()); } } @@ -408,7 +400,7 @@ void testGetPictureSources_Valid() throws Exception { PROPERTY_RESOURCE_TYPE, RESOURCE_TYPE); context.resourceResolver().commit(); - try (MediaComponentPropertyResolver underTest = new MediaComponentPropertyResolver(resource, componentPropertyResolverFactory)) { + try (MediaComponentPropertyResolver underTest = AdaptTo.notNull(resource, MediaComponentPropertyResolver.class)) { assertArrayEquals(new PictureSource[] { new PictureSource("home_stage") .media("media1") @@ -437,7 +429,7 @@ void testGetPictureSources_Invalid() throws Exception { PROPERTY_RESOURCE_TYPE, RESOURCE_TYPE); context.resourceResolver().commit(); - try (MediaComponentPropertyResolver underTest = new MediaComponentPropertyResolver(resource, componentPropertyResolverFactory)) { + try (MediaComponentPropertyResolver underTest = AdaptTo.notNull(resource, MediaComponentPropertyResolver.class)) { assertNull(underTest.getPictureSources()); } } @@ -455,7 +447,7 @@ void testGetPictureSources_Valid_Active() throws Exception { context.resourceResolver().commit(); context.resourceResolver().commit(); - try (MediaComponentPropertyResolver underTest = new MediaComponentPropertyResolver(resource, componentPropertyResolverFactory)) { + try (MediaComponentPropertyResolver underTest = AdaptTo.notNull(resource, MediaComponentPropertyResolver.class)) { assertArrayEquals(new PictureSource[] { new PictureSource("home_stage").widths(200, 400) }, underTest.getPictureSources()); @@ -474,7 +466,7 @@ void testGetPictureSources_Valid_Inactive() throws Exception { PROPERTY_RESOURCE_TYPE, RESOURCE_TYPE); context.resourceResolver().commit(); - try (MediaComponentPropertyResolver underTest = new MediaComponentPropertyResolver(resource, componentPropertyResolverFactory)) { + try (MediaComponentPropertyResolver underTest = AdaptTo.notNull(resource, MediaComponentPropertyResolver.class)) { assertNull(underTest.getPictureSources()); } } diff --git a/src/test/java/io/wcm/handler/media/testcontext/AppAemContext.java b/src/test/java/io/wcm/handler/media/testcontext/AppAemContext.java index 38c7f0c3..c4433a00 100644 --- a/src/test/java/io/wcm/handler/media/testcontext/AppAemContext.java +++ b/src/test/java/io/wcm/handler/media/testcontext/AppAemContext.java @@ -31,7 +31,7 @@ import io.wcm.handler.media.format.impl.MediaFormatProviderManagerImpl; import io.wcm.handler.media.impl.DefaultMediaHandlerConfig; -import io.wcm.handler.media.impl.MediaHandlerConfigAdapterFactory; +import io.wcm.handler.media.impl.MediaHandlerAdapterFactory; import io.wcm.handler.media.spi.MediaFormatProvider; import io.wcm.handler.media.spi.MediaHandlerConfig; import io.wcm.handler.mediasource.dam.impl.dynamicmedia.DynamicMediaSupportServiceImpl; @@ -100,13 +100,13 @@ public static AemContext newAemContext(@Nullable ResourceResolverType resourceRe public void execute(@NotNull AemContext context) throws Exception { // handler SPI - context.registerInjectActivateService(new SiteRootDetectorImpl()); - context.registerInjectActivateService(new UrlHandlerAdapterFactory()); - context.registerInjectActivateService(new ClientlibProxyRewriterImpl()); - context.registerInjectActivateService(new DefaultUrlHandlerConfig()); + context.registerInjectActivateService(SiteRootDetectorImpl.class); + context.registerInjectActivateService(UrlHandlerAdapterFactory.class); + context.registerInjectActivateService(ClientlibProxyRewriterImpl.class); + context.registerInjectActivateService(DefaultUrlHandlerConfig.class); context.registerService(UrlHandlerConfig.class, new DummyUrlHandlerConfig()); - context.registerInjectActivateService(new MediaHandlerConfigAdapterFactory()); - context.registerInjectActivateService(new DefaultMediaHandlerConfig()); + context.registerInjectActivateService(MediaHandlerAdapterFactory.class); + context.registerInjectActivateService(DefaultMediaHandlerConfig.class); context.registerService(MediaHandlerConfig.class, new DummyMediaHandlerConfig()); // context path strategy @@ -114,10 +114,10 @@ public void execute(@NotNull AemContext context) throws Exception { // media formats context.registerService(MediaFormatProvider.class, new DummyMediaFormatProvider()); - context.registerInjectActivateService(new MediaFormatProviderManagerImpl()); + context.registerInjectActivateService(MediaFormatProviderManagerImpl.class); // dynamic media - context.registerInjectActivateService(new DynamicMediaSupportServiceImpl()); + context.registerInjectActivateService(DynamicMediaSupportServiceImpl.class); // sling models registration context.addModelsForPackage( diff --git a/src/test/java/io/wcm/handler/media/testcontext/MediaSourceDamAppAemContext.java b/src/test/java/io/wcm/handler/media/testcontext/MediaSourceDamAppAemContext.java index 1a2ad879..72acb2ad 100644 --- a/src/test/java/io/wcm/handler/media/testcontext/MediaSourceDamAppAemContext.java +++ b/src/test/java/io/wcm/handler/media/testcontext/MediaSourceDamAppAemContext.java @@ -33,7 +33,7 @@ import io.wcm.handler.media.format.impl.MediaFormatProviderManagerImpl; import io.wcm.handler.media.impl.DefaultMediaHandlerConfig; -import io.wcm.handler.media.impl.MediaHandlerConfigAdapterFactory; +import io.wcm.handler.media.impl.MediaHandlerAdapterFactory; import io.wcm.handler.media.spi.MediaFormatProvider; import io.wcm.handler.media.spi.MediaHandlerConfig; import io.wcm.handler.mediasource.dam.impl.dynamicmedia.DynamicMediaSupportServiceImpl; @@ -97,13 +97,13 @@ public static AemContext newAemContext(ResourceResolverType resourceResolverType public void execute(@NotNull AemContext context) throws PersistenceException, IOException { // handler SPI - context.registerInjectActivateService(new SiteRootDetectorImpl()); - context.registerInjectActivateService(new UrlHandlerAdapterFactory()); - context.registerInjectActivateService(new ClientlibProxyRewriterImpl()); - context.registerInjectActivateService(new DefaultUrlHandlerConfig()); + context.registerInjectActivateService(SiteRootDetectorImpl.class); + context.registerInjectActivateService(UrlHandlerAdapterFactory.class); + context.registerInjectActivateService(ClientlibProxyRewriterImpl.class); + context.registerInjectActivateService(DefaultUrlHandlerConfig.class); context.registerService(UrlHandlerConfig.class, new DummyUrlHandlerConfig()); - context.registerInjectActivateService(new MediaHandlerConfigAdapterFactory()); - context.registerInjectActivateService(new DefaultMediaHandlerConfig()); + context.registerInjectActivateService(MediaHandlerAdapterFactory.class); + context.registerInjectActivateService(DefaultMediaHandlerConfig.class); context.registerService(MediaHandlerConfig.class, new DummyMediaHandlerConfig()); // context path strategy @@ -111,10 +111,10 @@ public void execute(@NotNull AemContext context) throws PersistenceException, IO // media formats context.registerService(MediaFormatProvider.class, new DummyMediaFormatProvider()); - context.registerInjectActivateService(new MediaFormatProviderManagerImpl()); + context.registerInjectActivateService(MediaFormatProviderManagerImpl.class); // dynamic media - context.registerInjectActivateService(new DynamicMediaSupportServiceImpl()); + context.registerInjectActivateService(DynamicMediaSupportServiceImpl.class); // sling models registration context.addModelsForPackage("io.wcm.handler.media", diff --git a/src/test/java/io/wcm/handler/media/testcontext/MediaSourceInlineAppAemContext.java b/src/test/java/io/wcm/handler/media/testcontext/MediaSourceInlineAppAemContext.java index 743db9ba..baadf2c5 100644 --- a/src/test/java/io/wcm/handler/media/testcontext/MediaSourceInlineAppAemContext.java +++ b/src/test/java/io/wcm/handler/media/testcontext/MediaSourceInlineAppAemContext.java @@ -33,7 +33,7 @@ import io.wcm.handler.media.format.impl.MediaFormatProviderManagerImpl; import io.wcm.handler.media.impl.DefaultMediaHandlerConfig; -import io.wcm.handler.media.impl.MediaHandlerConfigAdapterFactory; +import io.wcm.handler.media.impl.MediaHandlerAdapterFactory; import io.wcm.handler.media.spi.MediaFormatProvider; import io.wcm.handler.media.spi.MediaHandlerConfig; import io.wcm.handler.mediasource.dam.impl.dynamicmedia.DynamicMediaSupportServiceImpl; @@ -86,13 +86,13 @@ public static AemContext newAemContext() { public void execute(@NotNull AemContext context) throws PersistenceException, IOException { // handler SPI - context.registerInjectActivateService(new SiteRootDetectorImpl()); - context.registerInjectActivateService(new UrlHandlerAdapterFactory()); - context.registerInjectActivateService(new ClientlibProxyRewriterImpl()); - context.registerInjectActivateService(new DefaultUrlHandlerConfig()); + context.registerInjectActivateService(SiteRootDetectorImpl.class); + context.registerInjectActivateService(UrlHandlerAdapterFactory.class); + context.registerInjectActivateService(ClientlibProxyRewriterImpl.class); + context.registerInjectActivateService(DefaultUrlHandlerConfig.class); context.registerService(UrlHandlerConfig.class, new DummyUrlHandlerConfig()); - context.registerInjectActivateService(new MediaHandlerConfigAdapterFactory()); - context.registerInjectActivateService(new DefaultMediaHandlerConfig()); + context.registerInjectActivateService(MediaHandlerAdapterFactory.class); + context.registerInjectActivateService(DefaultMediaHandlerConfig.class); context.registerService(MediaHandlerConfig.class, new DummyMediaHandlerConfig()); // context path strategy @@ -100,10 +100,10 @@ public void execute(@NotNull AemContext context) throws PersistenceException, IO // media formats context.registerService(MediaFormatProvider.class, new DummyMediaFormatProvider()); - context.registerInjectActivateService(new MediaFormatProviderManagerImpl()); + context.registerInjectActivateService(MediaFormatProviderManagerImpl.class); // dynamic media - context.registerInjectActivateService(new DynamicMediaSupportServiceImpl()); + context.registerInjectActivateService(DynamicMediaSupportServiceImpl.class); // sling models registration context.addModelsForPackage("io.wcm.handler.media",