Search in sources :

Example 1 with ResourceDecoratorTracker

use of org.apache.sling.resourceresolver.impl.helper.ResourceDecoratorTracker in project sling by apache.

the class ResourceDecoratorTestBase method setup.

@Before
public void setup() throws LoginException {
    final ResourceDecorator d = new ResourceDecorator() {

        @Override
        public Resource decorate(Resource resource) {
            return ResourceDecoratorTestBase.this.wrapResourceForTest(resource);
        }

        @Override
        public Resource decorate(Resource resource, HttpServletRequest request) {
            throw new UnsupportedOperationException("Not supposed to be used in these tests");
        }
    };
    final ResourceDecoratorTracker t = new ResourceDecoratorTracker();
    t.bindResourceDecorator(d, null);
    final ResourceProvider<?> provider = new ResourceProvider<Object>() {

        @Override
        public QueryLanguageProvider<Object> getQueryLanguageProvider() {
            return new QueryLanguageProvider<Object>() {

                @Override
                public String[] getSupportedLanguages(ResolveContext<Object> ctx) {
                    return new String[] { QUERY_LANGUAGE };
                }

                @Override
                public Iterator<Resource> findResources(ResolveContext<Object> ctx, String query, String language) {
                    final List<Resource> found = new ArrayList<Resource>();
                    found.add(mockResource("/tmp/C"));
                    found.add(mockResource("/tmp/D"));
                    found.add(mockResource("/var/one"));
                    found.add(mockResource("/var/two"));
                    return found.iterator();
                }

                @Override
                public Iterator<ValueMap> queryResources(ResolveContext<Object> ctx, String query, String language) {
                    return null;
                }
            };
        }

        @Override
        public Resource getResource(ResolveContext<Object> ctx, String path, final ResourceContext rCtx, Resource parent) {
            if (path.equals("/") || path.startsWith("/tmp") || path.startsWith("/var")) {
                return mockResource(path);
            }
            return null;
        }

        @Override
        public Iterator<Resource> listChildren(ResolveContext<Object> ctx, Resource parent) {
            final List<Resource> children = new ArrayList<Resource>();
            if ("/".equals(parent.getPath())) {
                children.add(mockResource("/tmp"));
                children.add(mockResource("/var"));
            } else if ("/var".equals(parent.getPath())) {
                children.add(mockResource("/var/one"));
                children.add(mockResource("/var/two"));
                children.add(mockResource("/var/three"));
            } else if ("/tmp".equals(parent.getPath())) {
                children.add(mockResource("/tmp/A"));
                children.add(mockResource("/tmp/B"));
                children.add(mockResource("/tmp/C"));
                children.add(mockResource("/tmp/D"));
            }
            return children.iterator();
        }
    };
    ResourceResolverFactoryActivator activator = new ResourceResolverFactoryActivator();
    final CommonResourceResolverFactoryImpl crf = new CommonResourceResolverFactoryImpl(activator) {

        @Override
        public ResourceDecoratorTracker getResourceDecoratorTracker() {
            return t;
        }

        @Override
        public ResourceAccessSecurityTracker getResourceAccessSecurityTracker() {
            return new ResourceAccessSecurityTracker();
        }
    };
    final List<ResourceProviderHandler> list = Arrays.asList(MockedResourceResolverImplTest.createRPHandler(provider, "A-provider", 0L, "/"));
    resolver = new ResourceResolverImpl(crf, false, null, new ResourceProviderStorageProvider() {

        @Override
        public ResourceProviderStorage getResourceProviderStorage() {
            return new ResourceProviderStorage(list);
        }
    });
}
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) ValueMap(org.apache.sling.api.resource.ValueMap) NonExistingResource(org.apache.sling.api.resource.NonExistingResource) Resource(org.apache.sling.api.resource.Resource) ArrayList(java.util.ArrayList) ResourceProviderStorageProvider(org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorageProvider) ResourceDecorator(org.apache.sling.api.resource.ResourceDecorator) HttpServletRequest(javax.servlet.http.HttpServletRequest) ResourceProviderStorage(org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorage) ResourceProvider(org.apache.sling.spi.resource.provider.ResourceProvider) ResourceDecoratorTracker(org.apache.sling.resourceresolver.impl.helper.ResourceDecoratorTracker) QueryLanguageProvider(org.apache.sling.spi.resource.provider.QueryLanguageProvider) Before(org.junit.Before)

Aggregations

ArrayList (java.util.ArrayList)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 NonExistingResource (org.apache.sling.api.resource.NonExistingResource)1 Resource (org.apache.sling.api.resource.Resource)1 ResourceDecorator (org.apache.sling.api.resource.ResourceDecorator)1 ValueMap (org.apache.sling.api.resource.ValueMap)1 ResourceDecoratorTracker (org.apache.sling.resourceresolver.impl.helper.ResourceDecoratorTracker)1 ResourceProviderHandler (org.apache.sling.resourceresolver.impl.providers.ResourceProviderHandler)1 ResourceProviderStorage (org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorage)1 ResourceProviderStorageProvider (org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorageProvider)1 QueryLanguageProvider (org.apache.sling.spi.resource.provider.QueryLanguageProvider)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 Before (org.junit.Before)1