use of org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorage in project sling by apache.
the class FactoryPreconditionsTest method testPIDs.
@Test
public void testPIDs() {
final ResourceProviderTracker tracker = Mockito.mock(ResourceProviderTracker.class);
final ResourceProviderStorage storage = Mockito.mock(ResourceProviderStorage.class);
Mockito.when(tracker.getResourceProviderStorage()).thenReturn(storage);
FactoryPreconditions conditions = new FactoryPreconditions();
conditions.activate(null, new HashSet<>(Arrays.asList("pid1", "pid3")), null, tracker);
final List<ResourceProviderHandler> handlers1 = getResourceProviderHandlers(new String[] { "pid2" });
Mockito.when(storage.getAllHandlers()).thenReturn(handlers1);
assertFalse(conditions.checkPreconditions(null, null));
final List<ResourceProviderHandler> handlers2 = getResourceProviderHandlers(new String[] { "pid1", "pid2", "pid3" });
Mockito.when(storage.getAllHandlers()).thenReturn(handlers2);
assertTrue(conditions.checkPreconditions(null, null));
final List<ResourceProviderHandler> handlers3 = getResourceProviderHandlers(new String[] { "pid1" });
Mockito.when(storage.getAllHandlers()).thenReturn(handlers3);
assertFalse(conditions.checkPreconditions(null, null));
}
use of org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorage in project sling by apache.
the class MockedResourceResolverImplTest method before.
@SuppressWarnings("unchecked")
@Before
public void before() throws LoginException {
activator = new ResourceResolverFactoryActivator();
// system bundle access
final Bundle systemBundle = Mockito.mock(Bundle.class);
Mockito.when(systemBundle.getState()).thenReturn(Bundle.ACTIVE);
Mockito.when(bundleContext.getBundle(Constants.SYSTEM_BUNDLE_LOCATION)).thenReturn(systemBundle);
activator.resourceAccessSecurityTracker = new ResourceAccessSecurityTracker();
activator.resourceProviderTracker = resourceProviderTracker;
activator.changeListenerWhiteboard = resourceChangeListenerWhiteboard;
activator.serviceUserMapper = Mockito.mock(ServiceUserMapper.class);
handlers.add(createRPHandler(resourceProvider, "org.apache.sling.resourceresolver.impl.DummyTestProvider", 10L, "/single"));
// setup mapping resources at /etc/map to exercise vanity etc.
// hmm, can't provide the resolver since its not up and ready.
// mapping almost certainly work properly until this can be setup correctly.
buildMappingResource("/etc/map", mappingResourceProvider, null);
handlers.add(createRPHandler(mappingResourceProvider, "org.apache.sling.resourceresolver.impl.MapProvider", 11L, "/etc"));
handlers.add(createRPHandler(appsResourceProvider, "org.apache.sling.resourceresolver.impl.AppsProvider", 12L, "/libs"));
handlers.add(createRPHandler(appsResourceProvider, "org.apache.sling.resourceresolver.impl.AppsProvider", 13L, "/apps"));
handlers.add(createRPHandler(queriableResourceProviderA, "org.apache.sling.resourceresolver.impl.QueriableResourceProviderA", 14L, "/searchA"));
Mockito.when(queriableResourceProviderA.getQueryLanguageProvider()).thenReturn(queryProvider);
ResourceProviderStorage storage = new ResourceProviderStorage(handlers);
Mockito.when(resourceProviderTracker.getResourceProviderStorage()).thenReturn(storage);
// activate the components.
activator.activate(bundleContext, new ResourceResolverFactoryConfig() {
@Override
public Class<? extends Annotation> annotationType() {
return null;
}
@Override
public String[] resource_resolver_virtual() {
return new String[] { "/:/" };
}
@Override
public String[] resource_resolver_vanitypath_whitelist() {
return null;
}
@Override
public boolean resource_resolver_vanitypath_maxEntries_startup() {
return true;
}
@Override
public int resource_resolver_vanitypath_maxEntries() {
return -1;
}
@Override
public int resource_resolver_vanitypath_bloomfilter_maxBytes() {
return 1024000;
}
@Override
public String[] resource_resolver_vanitypath_blacklist() {
return null;
}
@Override
public boolean resource_resolver_vanity_precedence() {
return false;
}
@Override
public String[] resource_resolver_searchpath() {
return new String[] { "/apps", "/libs" };
}
@Override
public String[] resource_resolver_required_providers() {
return new String[] { "org.apache.sling.resourceresolver.impl.DummyTestProvider" };
}
@Override
public String[] resource_resolver_required_providernames() {
return null;
}
@Override
public boolean resource_resolver_providerhandling_paranoid() {
return false;
}
@Override
public boolean resource_resolver_optimize_alias_resolution() {
return true;
}
@Override
public String[] resource_resolver_mapping() {
return new String[] { "/:/", "/content/:/", "/system/docroot/:/", "/content.html-/$" };
}
@Override
public String[] resource_resolver_map_observation() {
return new String[] { "/" };
}
@Override
public String resource_resolver_map_location() {
return MapEntries.DEFAULT_MAP_ROOT;
}
@Override
public boolean resource_resolver_manglenamespaces() {
return true;
}
@Override
public boolean resource_resolver_log_closing() {
return false;
}
@Override
public boolean resource_resolver_enable_vanitypath() {
return true;
}
@Override
public int resource_resolver_default_vanity_redirect_status() {
return 302;
}
@Override
public boolean resource_resolver_allowDirect() {
return true;
}
@Override
public boolean resource_resolver_log_unclosed() {
return true;
}
});
// configure using Bundle
Mockito.when(usingBundle.getBundleContext()).thenReturn(usingBundleContext);
Mockito.when(usingBundleContext.getBundle()).thenReturn(usingBundle);
// extract any services that were registered into a map.
ArgumentCaptor<Class> classesCaptor = ArgumentCaptor.forClass(Class.class);
ArgumentCaptor<ServiceFactory> serviceCaptor = ArgumentCaptor.forClass(ServiceFactory.class);
@SuppressWarnings("rawtypes") ArgumentCaptor<Dictionary> propertiesCaptor = ArgumentCaptor.forClass(Dictionary.class);
Mockito.verify(bundleContext, Mockito.atLeastOnce()).registerService((Class<ResourceResolverFactory>) classesCaptor.capture(), (ServiceFactory<ResourceResolverFactory>) serviceCaptor.capture(), propertiesCaptor.capture());
int si = 0;
List<ServiceFactory> serviceList = serviceCaptor.getAllValues();
@SuppressWarnings({ "unused", "rawtypes" }) List<Dictionary> servicePropertiesList = propertiesCaptor.getAllValues();
for (Class serviceClass : classesCaptor.getAllValues()) {
services.put(serviceClass.getName(), serviceList.get(si));
serviceProperties.put(serviceClass.getName(), serviceProperties.get(si));
si++;
}
// verify that a ResourceResolverFactoryImpl was created and registered.
Assert.assertNotNull("" + services, services.get(ResourceResolverFactory.class.getName()));
Object rrf = services.get(ResourceResolverFactory.class.getName());
if (rrf instanceof ServiceFactory) {
rrf = ((ServiceFactory) rrf).getService(usingBundle, null);
}
Assert.assertTrue(rrf instanceof ResourceResolverFactoryImpl);
resourceResolverFactory = (ResourceResolverFactoryImpl) rrf;
}
use of org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorage in project sling by apache.
the class FactoryPreconditionsTest method testUnregisteringService.
@Test
public void testUnregisteringService() {
final ResourceProviderTracker tracker = Mockito.mock(ResourceProviderTracker.class);
final ResourceProviderStorage storage = Mockito.mock(ResourceProviderStorage.class);
Mockito.when(tracker.getResourceProviderStorage()).thenReturn(storage);
FactoryPreconditions conditions = new FactoryPreconditions();
conditions.activate(null, new HashSet<>(Arrays.asList("pid1", "pid3")), null, tracker);
final List<ResourceProviderHandler> handlers2 = getResourceProviderHandlers(new String[] { "pid1", "pid2", "pid3" });
Mockito.when(storage.getAllHandlers()).thenReturn(handlers2);
assertTrue(conditions.checkPreconditions(null, null));
assertTrue(conditions.checkPreconditions(null, "pid2"));
assertFalse(conditions.checkPreconditions(null, "pid1"));
}
use of org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorage in project sling by apache.
the class FactoryPreconditionsTest method testNoRequiredProviders.
@Test
public void testNoRequiredProviders() {
final ResourceProviderTracker tracker = Mockito.mock(ResourceProviderTracker.class);
final ResourceProviderStorage storage = Mockito.mock(ResourceProviderStorage.class);
Mockito.when(tracker.getResourceProviderStorage()).thenReturn(storage);
FactoryPreconditions conditions = new FactoryPreconditions();
conditions.activate(null, null, null, tracker);
assertTrue(conditions.checkPreconditions(null, null));
conditions = new FactoryPreconditions();
conditions.activate(null, Collections.<String>emptySet(), Collections.<String>emptySet(), tracker);
assertTrue(conditions.checkPreconditions(null, null));
}
use of org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorage in project sling by apache.
the class FactoryPreconditionsTest method testNames.
@Test
public void testNames() {
final ResourceProviderTracker tracker = Mockito.mock(ResourceProviderTracker.class);
final ResourceProviderStorage storage = Mockito.mock(ResourceProviderStorage.class);
Mockito.when(tracker.getResourceProviderStorage()).thenReturn(storage);
FactoryPreconditions conditions = new FactoryPreconditions();
conditions.activate(null, null, new HashSet<>(Arrays.asList("n1", "n2")), tracker);
final List<ResourceProviderHandler> handlers1 = getResourceProviderHandlersWithNames(new String[] { "n2" });
Mockito.when(storage.getAllHandlers()).thenReturn(handlers1);
assertFalse(conditions.checkPreconditions(null, null));
final List<ResourceProviderHandler> handlers2 = getResourceProviderHandlersWithNames(new String[] { "n1", "n2", "n3" });
Mockito.when(storage.getAllHandlers()).thenReturn(handlers2);
assertTrue(conditions.checkPreconditions(null, null));
final List<ResourceProviderHandler> handlers3 = getResourceProviderHandlersWithNames(new String[] { "n1" });
Mockito.when(storage.getAllHandlers()).thenReturn(handlers3);
assertFalse(conditions.checkPreconditions(null, null));
}
Aggregations