// setup mock OSGi environment
Dictionary<String, Object> resourceProviderFactoryProps = new Hashtable<String, Object>();
resourceProviderFactoryProps.put(Constants.SERVICE_VENDOR, "sling-mock");
resourceProviderFactoryProps.put(Constants.SERVICE_DESCRIPTION, "sling-mock");
resourceProviderFactoryProps.put("resource.resolver.manglenamespaces", true);
ComponentContext componentContext = MockOsgi.newComponentContext(resourceProviderFactoryProps);
// setup mocked JCR environment
componentContext.getBundleContext()
.registerService(SlingRepository.class.getName(), this.slingRepository, null);
// setup real sling JCR resource provider implementation for use in
// mocked context
JcrResourceProviderFactory jcrResourceProviderFactory = new JcrResourceProviderFactory();
MockOsgi.injectServices(jcrResourceProviderFactory, componentContext.getBundleContext());
MockOsgi.activate(jcrResourceProviderFactory, componentContext.getBundleContext(),
ImmutableMap.<String, Object> of());
ResourceProvider resourceProvider;
if (isAdmin) {
resourceProvider = jcrResourceProviderFactory.getAdministrativeResourceProvider(authenticationInfo);
}
else {
resourceProvider = jcrResourceProviderFactory.getResourceProvider(authenticationInfo);
}
Dictionary<Object, Object> resourceProviderProps = new Hashtable<Object, Object>();
resourceProviderProps.put(ResourceProvider.ROOTS, new String[] { "/" });
componentContext.getBundleContext().registerService(ResourceProvider.class.getName(), resourceProvider,
resourceProviderProps);
ServiceReference resourceProviderServiceReference = componentContext.getBundleContext().getServiceReference(
ResourceProvider.class.getName());
// setup real sling resource resolver implementation for use in mocked
// context
MockResourceResolverFactoryActivator activator = new MockResourceResolverFactoryActivator();