Search in sources :

Example 6 with ResourceProviderTracker

use of org.apache.sling.resourceresolver.impl.providers.ResourceProviderTracker 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));
}
Also used : ResourceProviderStorage(org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorage) ResourceProviderHandler(org.apache.sling.resourceresolver.impl.providers.ResourceProviderHandler) ResourceProviderTracker(org.apache.sling.resourceresolver.impl.providers.ResourceProviderTracker) Test(org.junit.Test)

Example 7 with ResourceProviderTracker

use of org.apache.sling.resourceresolver.impl.providers.ResourceProviderTracker in project sling by apache.

the class FactoryPreconditionsTest method testDeactivated.

@Test
public void testDeactivated() {
    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.deactivate();
    assertFalse(conditions.checkPreconditions(null, null));
}
Also used : ResourceProviderStorage(org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorage) ResourceProviderTracker(org.apache.sling.resourceresolver.impl.providers.ResourceProviderTracker) Test(org.junit.Test)

Example 8 with ResourceProviderTracker

use of org.apache.sling.resourceresolver.impl.providers.ResourceProviderTracker in project sling by apache.

the class ResourceResolverImplTest method setup.

@Before
public void setup() throws LoginException {
    ResourceProvider<?> rp = new ResourceProvider<Object>() {

        @Override
        public Resource getResource(ResolveContext<Object> ctx, String path, ResourceContext rCtx, Resource parent) {
            return null;
        }

        @Override
        public Iterator<Resource> listChildren(ResolveContext<Object> ctx, Resource parent) {
            return null;
        }
    };
    List<ResourceProviderHandler> handlers = asList(createRPHandler(rp, "rp1", 0, "/"));
    resourceProviderTracker = mock(ResourceProviderTracker.class);
    ResourceProviderStorage storage = new ResourceProviderStorage(handlers);
    when(resourceProviderTracker.getResourceProviderStorage()).thenReturn(storage);
    ResourceResolverFactoryActivator activator = new ResourceResolverFactoryActivator();
    activator.resourceProviderTracker = resourceProviderTracker;
    activator.resourceAccessSecurityTracker = new ResourceAccessSecurityTracker();
    commonFactory = new CommonResourceResolverFactoryImpl(activator);
    final Bundle usingBundle = mock(Bundle.class);
    resFac = new ResourceResolverFactoryImpl(commonFactory, usingBundle, null);
    resResolver = resFac.getAdministrativeResourceResolver(null);
}
Also used : ResolveContext(org.apache.sling.spi.resource.provider.ResolveContext) ResourceContext(org.apache.sling.spi.resource.provider.ResourceContext) ResourceProviderHandler(org.apache.sling.resourceresolver.impl.providers.ResourceProviderHandler) Bundle(org.osgi.framework.Bundle) ResourceProviderTracker(org.apache.sling.resourceresolver.impl.providers.ResourceProviderTracker) NonExistingResource(org.apache.sling.api.resource.NonExistingResource) Resource(org.apache.sling.api.resource.Resource) SyntheticResource(org.apache.sling.api.resource.SyntheticResource) ResourceProviderStorage(org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorage) ResourceProvider(org.apache.sling.spi.resource.provider.ResourceProvider) Before(org.junit.Before)

Example 9 with ResourceProviderTracker

use of org.apache.sling.resourceresolver.impl.providers.ResourceProviderTracker in project sling by apache.

the class ResourceResolverFactoryTest method setup.

@Before
public void setup() {
    ResourceResolverFactoryActivator activator = new ResourceResolverFactoryActivator();
    activator.resourceProviderTracker = new ResourceProviderTracker();
    commonFactory = new CommonResourceResolverFactoryImpl(activator);
}
Also used : ResourceProviderTracker(org.apache.sling.resourceresolver.impl.providers.ResourceProviderTracker) Before(org.junit.Before)

Aggregations

ResourceProviderTracker (org.apache.sling.resourceresolver.impl.providers.ResourceProviderTracker)9 ResourceProviderStorage (org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorage)6 ResourceProviderHandler (org.apache.sling.resourceresolver.impl.providers.ResourceProviderHandler)5 Test (org.junit.Test)5 Before (org.junit.Before)2 ArrayList (java.util.ArrayList)1 BidiMap (org.apache.commons.collections4.BidiMap)1 TreeBidiMap (org.apache.commons.collections4.bidimap.TreeBidiMap)1 NonExistingResource (org.apache.sling.api.resource.NonExistingResource)1 Resource (org.apache.sling.api.resource.Resource)1 SyntheticResource (org.apache.sling.api.resource.SyntheticResource)1 Path (org.apache.sling.api.resource.path.Path)1 Mapping (org.apache.sling.resourceresolver.impl.mapping.Mapping)1 ResourceChangeListenerWhiteboard (org.apache.sling.resourceresolver.impl.observation.ResourceChangeListenerWhiteboard)1 ChangeListener (org.apache.sling.resourceresolver.impl.providers.ResourceProviderTracker.ChangeListener)1 ResolveContext (org.apache.sling.spi.resource.provider.ResolveContext)1 ResourceContext (org.apache.sling.spi.resource.provider.ResourceContext)1 ResourceProvider (org.apache.sling.spi.resource.provider.ResourceProvider)1 Bundle (org.osgi.framework.Bundle)1 ServiceReference (org.osgi.framework.ServiceReference)1