Search in sources :

Example 1 with ResourceProviderInfo

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

the class FactoryPreconditionsTest method getResourceProviderHandlersWithNames.

private List<ResourceProviderHandler> getResourceProviderHandlersWithNames(String[] names) {
    final List<ResourceProviderHandler> result = new ArrayList<ResourceProviderHandler>();
    for (final String n : names) {
        final ResourceProviderHandler handler = Mockito.mock(ResourceProviderHandler.class);
        final ResourceProviderInfo info = Mockito.mock(ResourceProviderInfo.class);
        Mockito.when(info.getName()).thenReturn(n);
        final ServiceReference ref = Mockito.mock(ServiceReference.class);
        Mockito.when(handler.getInfo()).thenReturn(info);
        Mockito.when(info.getServiceReference()).thenReturn(ref);
        result.add(handler);
    }
    return result;
}
Also used : ResourceProviderHandler(org.apache.sling.resourceresolver.impl.providers.ResourceProviderHandler) ArrayList(java.util.ArrayList) ResourceProviderInfo(org.apache.sling.resourceresolver.impl.providers.ResourceProviderInfo) ServiceReference(org.osgi.framework.ServiceReference)

Example 2 with ResourceProviderInfo

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

the class Fixture method registerResourceProvider.

public ResourceProviderInfo registerResourceProvider(ResourceProvider<?> rp, String root, AuthType authType) throws InvalidSyntaxException {
    Dictionary<String, String> props = new Hashtable<String, String>();
    props.put(ResourceProvider.PROPERTY_ROOT, root);
    props.put(ResourceProvider.PROPERTY_AUTHENTICATE, authType.name());
    props.put(ResourceProvider.PROPERTY_MODIFIABLE, Boolean.TRUE.toString());
    ServiceRegistration registration = bc.registerService(ResourceProvider.class.getName(), rp, props);
    ServiceReference sr = bc.getServiceReferences(ResourceProvider.class.getName(), "(" + ResourceProvider.PROPERTY_ROOT + "=" + root + ")")[0];
    ResourceProviderInfo providerInfo = new ResourceProviderInfo(sr);
    providerRegistrations.put(providerInfo, registration);
    return providerInfo;
}
Also used : Hashtable(java.util.Hashtable) ResourceProvider(org.apache.sling.spi.resource.provider.ResourceProvider) ResourceProviderInfo(org.apache.sling.resourceresolver.impl.providers.ResourceProviderInfo) ServiceRegistration(org.osgi.framework.ServiceRegistration) ServiceReference(org.osgi.framework.ServiceReference)

Example 3 with ResourceProviderInfo

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

the class FactoryPreconditionsTest method getResourceProviderHandlers.

private List<ResourceProviderHandler> getResourceProviderHandlers(String[] pids) {
    final List<ResourceProviderHandler> result = new ArrayList<ResourceProviderHandler>();
    for (final String p : pids) {
        final ResourceProviderHandler handler = Mockito.mock(ResourceProviderHandler.class);
        final ResourceProviderInfo info = Mockito.mock(ResourceProviderInfo.class);
        final ServiceReference ref = Mockito.mock(ServiceReference.class);
        Mockito.when(handler.getInfo()).thenReturn(info);
        Mockito.when(info.getServiceReference()).thenReturn(ref);
        Mockito.when(ref.getProperty(Constants.SERVICE_PID)).thenReturn(p);
        result.add(handler);
    }
    return result;
}
Also used : ResourceProviderHandler(org.apache.sling.resourceresolver.impl.providers.ResourceProviderHandler) ArrayList(java.util.ArrayList) ResourceProviderInfo(org.apache.sling.resourceresolver.impl.providers.ResourceProviderInfo) ServiceReference(org.osgi.framework.ServiceReference)

Example 4 with ResourceProviderInfo

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

the class MockedResourceResolverImplTest method createRPHandler.

public static ResourceProviderHandler createRPHandler(ResourceProvider<?> rp, String pid, long ranking, String path) {
    ServiceReference ref = Mockito.mock(ServiceReference.class);
    BundleContext bc = Mockito.mock(BundleContext.class);
    Mockito.when(bc.getService(Mockito.eq(ref))).thenReturn(rp);
    Mockito.when(ref.getProperty(Mockito.eq(Constants.SERVICE_ID))).thenReturn(new Random().nextLong());
    Mockito.when(ref.getProperty(Mockito.eq(Constants.SERVICE_PID))).thenReturn(pid);
    Mockito.when(ref.getProperty(Mockito.eq(Constants.SERVICE_RANKING))).thenReturn(ranking);
    Mockito.when(ref.getProperty(Mockito.eq(ResourceProvider.PROPERTY_ROOT))).thenReturn(path);
    Mockito.when(ref.getProperty(Mockito.eq(ResourceProvider.PROPERTY_MODIFIABLE))).thenReturn(true);
    Mockito.when(ref.getProperty(Mockito.eq(ResourceProvider.PROPERTY_ATTRIBUTABLE))).thenReturn(true);
    Mockito.when(ref.getProperty(Mockito.eq(ResourceProvider.PROPERTY_ADAPTABLE))).thenReturn(true);
    ResourceProviderInfo info = new ResourceProviderInfo(ref);
    final ResourceProviderHandler handler = new ResourceProviderHandler(bc, info);
    handler.activate();
    return handler;
}
Also used : ResourceProviderHandler(org.apache.sling.resourceresolver.impl.providers.ResourceProviderHandler) Random(java.util.Random) ResourceProviderInfo(org.apache.sling.resourceresolver.impl.providers.ResourceProviderInfo) ServiceReference(org.osgi.framework.ServiceReference) BundleContext(org.osgi.framework.BundleContext)

Example 5 with ResourceProviderInfo

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

the class ResourceResolverControlTest method prepare.

@Before
public void prepare() throws Exception {
    BundleContext bc = MockOsgi.newBundleContext();
    Fixture fixture = new Fixture(bc);
    // sub-provider
    subProvider = Mockito.mock(ResourceProvider.class);
    ResourceProviderInfo info = fixture.registerResourceProvider(subProvider, "/some/path", AuthType.required);
    ResourceProviderHandler handler = new ResourceProviderHandler(bc, info);
    when(subProvider.getQueryLanguageProvider()).thenReturn(new SimpleQueryLanguageProvider(QL_MOCK, QL_ANOTHER_MOCK) {

        @Override
        public Iterator<ValueMap> queryResources(ResolveContext<Object> ctx, String query, String language) {
            if (query.equals(QUERY_MOCK_FIND_ALL) && language.equals(QL_MOCK)) {
                SimpleValueMapImpl valueMap = new SimpleValueMapImpl();
                valueMap.put("key", "value");
                return Collections.<ValueMap>singletonList(valueMap).iterator();
            }
            throw new UnsupportedOperationException();
        }

        @Override
        public Iterator<Resource> findResources(ResolveContext<Object> ctx, String query, String language) {
            if (query.equals(QUERY_MOCK_FIND_ALL) && language.equals(QL_MOCK)) {
                return Collections.<Resource>singletonList(newMockResource("/some/path/object")).iterator();
            }
            throw new UnsupportedOperationException();
        }
    });
    handler.activate();
    rootProvider = mock(ResourceProvider.class);
    ResourceProviderInfo rootInfo = fixture.registerResourceProvider(rootProvider, "/", AuthType.required);
    ResourceProviderHandler rootHandler = new ResourceProviderHandler(bc, rootInfo);
    when(rootProvider.getQueryLanguageProvider()).thenReturn(new SimpleQueryLanguageProvider(QL_NOOP));
    rootHandler.activate();
    // configure mock resources
    Resource root = configureResourceAt(rootProvider, "/");
    somethingResource = configureResourceAt(rootProvider, "/something");
    subProviderResource = configureResourceAt(subProvider, "/some/path/object");
    // configure query at '/'
    when(rootProvider.listChildren((ResolveContext<Object>) Mockito.anyObject(), Mockito.eq(root))).thenReturn(Collections.singleton(somethingResource).iterator());
    ResourceResolver rr = mock(ResourceResolver.class);
    ResourceAccessSecurityTracker securityTracker = Mockito.mock(ResourceAccessSecurityTracker.class);
    authInfo = getAuthInfo();
    handlers = Arrays.asList(rootHandler, handler);
    final ResourceProviderStorage storage = new ResourceProviderStorage(handlers);
    crp = new ResourceResolverControl(false, authInfo, new ResourceProviderStorageProvider() {

        @Override
        public ResourceProviderStorage getResourceProviderStorage() {
            return storage;
        }
    });
    context = new ResourceResolverContext(rr, securityTracker);
}
Also used : ResourceProviderHandler(org.apache.sling.resourceresolver.impl.providers.ResourceProviderHandler) ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource) ResourceProviderStorageProvider(org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorageProvider) SimpleValueMapImpl(org.apache.sling.resourceresolver.impl.SimpleValueMapImpl) ResourceProviderInfo(org.apache.sling.resourceresolver.impl.providers.ResourceProviderInfo) ResourceProviderStorage(org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorage) ResourceProvider(org.apache.sling.spi.resource.provider.ResourceProvider) Iterator(java.util.Iterator) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) ResourceAccessSecurityTracker(org.apache.sling.resourceresolver.impl.ResourceAccessSecurityTracker) Fixture(org.apache.sling.resourceresolver.impl.Fixture) BundleContext(org.osgi.framework.BundleContext) Before(org.junit.Before)

Aggregations

ResourceProviderInfo (org.apache.sling.resourceresolver.impl.providers.ResourceProviderInfo)5 ResourceProviderHandler (org.apache.sling.resourceresolver.impl.providers.ResourceProviderHandler)4 ServiceReference (org.osgi.framework.ServiceReference)4 ArrayList (java.util.ArrayList)2 ResourceProvider (org.apache.sling.spi.resource.provider.ResourceProvider)2 BundleContext (org.osgi.framework.BundleContext)2 Hashtable (java.util.Hashtable)1 Iterator (java.util.Iterator)1 Random (java.util.Random)1 Resource (org.apache.sling.api.resource.Resource)1 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)1 ValueMap (org.apache.sling.api.resource.ValueMap)1 Fixture (org.apache.sling.resourceresolver.impl.Fixture)1 ResourceAccessSecurityTracker (org.apache.sling.resourceresolver.impl.ResourceAccessSecurityTracker)1 SimpleValueMapImpl (org.apache.sling.resourceresolver.impl.SimpleValueMapImpl)1 ResourceProviderStorage (org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorage)1 ResourceProviderStorageProvider (org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorageProvider)1 Before (org.junit.Before)1 ServiceRegistration (org.osgi.framework.ServiceRegistration)1