This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag org.apache.sling.testing.sling-mock-1.6.0 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git
commit 21a5c64e2732e8b96ce7ded55420e55498076cb7 Author: Stefan Seifert <[email protected]> AuthorDate: Sat Oct 3 00:57:36 2015 +0000 SLING-5088 register default service user mapping for mock bundle git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1706516 13f79535-47bb-0310-9956-ffa450edef68 --- .../sling/ResourceResolverFactoryInitializer.java | 27 ++++++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverFactoryInitializer.java b/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverFactoryInitializer.java index fef5f6c..0780aee 100644 --- a/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverFactoryInitializer.java +++ b/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverFactoryInitializer.java @@ -113,7 +113,10 @@ class ResourceResolverFactoryInitializer { * @param bundleContext Bundle context */ private static void ensureResourceResolverFactoryActivatorDependencies(BundleContext bundleContext) { - registerServiceIfNotPresent(bundleContext, ServiceUserMapper.class, new ServiceUserMapperImpl()); + Dictionary<String, Object> config = new Hashtable<String, Object>(); + config.put("user.mapping", bundleContext.getBundle().getSymbolicName() + "=admin"); + registerServiceIfNotPresent(bundleContext, ServiceUserMapper.class, new ServiceUserMapperImpl(), config); + registerServiceIfNotPresent(bundleContext, ResourceAccessSecurityTracker.class, new ResourceAccessSecurityTracker()); registerServiceIfNotPresent(bundleContext, EventAdmin.class, new MockEventAdmin()); } @@ -140,13 +143,27 @@ class ResourceResolverFactoryInitializer { * Registers a service if the service class is found in classpath, * and if no service with this class is already registered. * @param className Service class name + * @param serviceClass Service class + * @param instance Service instance + */ + private static void registerServiceIfNotPresent(BundleContext bundleContext, Class<?> serviceClass, + Object instance) { + registerServiceIfNotPresent(bundleContext, serviceClass, instance, new Hashtable<String, Object>()); + } + /** + * Registers a service if the service class is found in classpath, + * and if no service with this class is already registered. + * @param className Service class name + * @param serviceClass Service class + * @param instance Service instance + * @param config OSGi config */ - private static void registerServiceIfNotPresent(BundleContext bundleContext, Class<?> serviceClass, Object instance) { + private static void registerServiceIfNotPresent(BundleContext bundleContext, Class<?> serviceClass, + Object instance, Dictionary<String, Object> config) { if (bundleContext.getServiceReference(serviceClass.getName()) == null) { - Dictionary<String,Object> properties = new Hashtable<String, Object>(); MockOsgi.injectServices(instance, bundleContext); - MockOsgi.activate(instance, bundleContext, properties); - bundleContext.registerService(serviceClass.getName(), instance, properties); + MockOsgi.activate(instance, bundleContext, config); + bundleContext.registerService(serviceClass.getName(), instance, config); } } -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
