Search in sources :

Example 1 with ConfigurationResourceResolvingStrategy

use of org.apache.sling.caconfig.resource.spi.ConfigurationResourceResolvingStrategy in project sling by apache.

the class ConfigurationResourceResolvingStrategyMultiplexerImplTest method testMultipleStrategies.

@Test
public void testMultipleStrategies() {
    // strategy 1
    context.registerService(ConfigurationResourceResolvingStrategy.class, new ConfigurationResourceResolvingStrategy() {

        @Override
        public Resource getResource(Resource resource, Collection<String> bucketNames, String configName) {
            return context.resourceResolver().getResource("/conf/site1/sling:test/test");
        }

        @Override
        public Collection<Resource> getResourceCollection(Resource resource, Collection<String> bucketNames, String configName) {
            return ImmutableList.copyOf(context.resourceResolver().getResource("/conf/site1/sling:test/feature").listChildren());
        }

        @Override
        public Iterator<Resource> getResourceInheritanceChain(Resource resource, Collection<String> bucketNames, String configName) {
            return Iterators.singletonIterator(getResource(resource, bucketNames, configName));
        }

        @Override
        public Collection<Iterator<Resource>> getResourceCollectionInheritanceChain(Resource resource, Collection<String> bucketNames, String configName) {
            return Collections2.transform(getResourceCollection(resource, bucketNames, configName), new Function<Resource, Iterator<Resource>>() {

                @Override
                public Iterator<Resource> apply(Resource input) {
                    return Iterators.singletonIterator(input);
                }
            });
        }

        @Override
        public String getResourcePath(Resource resource, String bucketName, String configName) {
            return "/conf/site1/sling:test/test";
        }

        @Override
        public String getResourceCollectionParentPath(Resource resource, String bucketName, String configName) {
            return "/conf/site1/sling:test/feature";
        }
    }, Constants.SERVICE_RANKING, 2000);
    // strategy 2
    context.registerService(ConfigurationResourceResolvingStrategy.class, new ConfigurationResourceResolvingStrategy() {

        @Override
        public Resource getResource(Resource resource, Collection<String> bucketNames, String configName) {
            return context.resourceResolver().getResource("/libs/conf/sling:test/test");
        }

        @Override
        public Collection<Resource> getResourceCollection(Resource resource, Collection<String> bucketNames, String configName) {
            return ImmutableList.copyOf(context.resourceResolver().getResource("/libs/conf/sling:test/feature").listChildren());
        }

        @Override
        public Iterator<Resource> getResourceInheritanceChain(Resource resource, Collection<String> bucketNames, String configName) {
            return Iterators.singletonIterator(getResource(resource, bucketNames, configName));
        }

        @Override
        public Collection<Iterator<Resource>> getResourceCollectionInheritanceChain(Resource resource, Collection<String> bucketNames, String configName) {
            return Collections2.transform(getResourceCollection(resource, bucketNames, configName), new Function<Resource, Iterator<Resource>>() {

                @Override
                public Iterator<Resource> apply(Resource input) {
                    return Iterators.singletonIterator(input);
                }
            });
        }

        @Override
        public String getResourcePath(Resource resource, String bucketName, String configName) {
            return null;
        }

        @Override
        public String getResourceCollectionParentPath(Resource resource, String bucketName, String configName) {
            return null;
        }
    }, Constants.SERVICE_RANKING, 1000);
    assertThat(underTest.getResource(site1Page1, BUCKETS, "test"), ResourceMatchers.path("/conf/site1/sling:test/test"));
    assertThat(underTest.getResourceCollection(site1Page1, BUCKETS, "feature"), ResourceCollectionMatchers.paths("/conf/site1/sling:test/feature/c"));
    assertThat(first(underTest.getResourceInheritanceChain(site1Page1, BUCKETS, "test")), ResourceMatchers.path("/conf/site1/sling:test/test"));
    assertThat(first(underTest.getResourceCollectionInheritanceChain(site1Page1, BUCKETS, "feature")), ResourceCollectionMatchers.paths("/conf/site1/sling:test/feature/c"));
    assertEquals("/conf/site1/sling:test/test", underTest.getResourcePath(site1Page1, BUCKET, "test"));
    assertEquals("/conf/site1/sling:test/feature", underTest.getResourceCollectionParentPath(site1Page1, BUCKET, "feature"));
}
Also used : Function(com.google.common.base.Function) Resource(org.apache.sling.api.resource.Resource) Iterator(java.util.Iterator) Collection(java.util.Collection) ConfigurationResourceResolvingStrategy(org.apache.sling.caconfig.resource.spi.ConfigurationResourceResolvingStrategy) DefaultConfigurationResourceResolvingStrategy(org.apache.sling.caconfig.resource.impl.def.DefaultConfigurationResourceResolvingStrategy) Test(org.junit.Test)

Example 2 with ConfigurationResourceResolvingStrategy

use of org.apache.sling.caconfig.resource.spi.ConfigurationResourceResolvingStrategy in project sling by apache.

the class DefaultConfigurationResourceResolvingStrategyTest method testGetResourceCollection_NoInheritProps_InheritParent.

/**
     * Default resource inheritance without customizing inheritance, but with now resources inner-most context.
     * => inherit from next context level.
     */
@Test
public void testGetResourceCollection_NoInheritProps_InheritParent() {
    ConfigurationResourceResolvingStrategy underTest = context.registerInjectActivateService(new DefaultConfigurationResourceResolvingStrategy());
    // build config resources
    context.build().resource("/apps/conf/sling:test/feature/a").resource("/libs/conf/sling:test/feature/a").resource("/libs/conf/sling:test/feature/b");
    assertThat(underTest.getResourceCollection(site1Page1, BUCKETS, "feature"), ResourceCollectionMatchers.paths("/apps/conf/sling:test/feature/a"));
    assertThat(underTest.getResourceCollection(site2Page1, BUCKETS, "feature"), ResourceCollectionMatchers.paths("/apps/conf/sling:test/feature/a"));
}
Also used : ConfigurationResourceResolvingStrategy(org.apache.sling.caconfig.resource.spi.ConfigurationResourceResolvingStrategy) Test(org.junit.Test)

Example 3 with ConfigurationResourceResolvingStrategy

use of org.apache.sling.caconfig.resource.spi.ConfigurationResourceResolvingStrategy in project sling by apache.

the class DefaultConfigurationResourceResolvingStrategyTest method testGetResourceCollectionParentPath.

@Test
public void testGetResourceCollectionParentPath() throws Exception {
    ConfigurationResourceResolvingStrategy underTest = context.registerInjectActivateService(new DefaultConfigurationResourceResolvingStrategy());
    assertEquals("/conf/site1/sling:test/feature", underTest.getResourceCollectionParentPath(site1Page1, BUCKET, "feature"));
}
Also used : ConfigurationResourceResolvingStrategy(org.apache.sling.caconfig.resource.spi.ConfigurationResourceResolvingStrategy) Test(org.junit.Test)

Example 4 with ConfigurationResourceResolvingStrategy

use of org.apache.sling.caconfig.resource.spi.ConfigurationResourceResolvingStrategy in project sling by apache.

the class DefaultConfigurationResourceResolvingStrategyTest method testGetResourcePath.

@Test
public void testGetResourcePath() throws Exception {
    ConfigurationResourceResolvingStrategy underTest = context.registerInjectActivateService(new DefaultConfigurationResourceResolvingStrategy());
    assertEquals("/conf/site1/sling:test/test", underTest.getResourcePath(site1Page1, BUCKET, "test"));
}
Also used : ConfigurationResourceResolvingStrategy(org.apache.sling.caconfig.resource.spi.ConfigurationResourceResolvingStrategy) Test(org.junit.Test)

Example 5 with ConfigurationResourceResolvingStrategy

use of org.apache.sling.caconfig.resource.spi.ConfigurationResourceResolvingStrategy in project sling by apache.

the class DefaultConfigurationResourceResolvingStrategyTest method testRelativeConfPropery.

@Test
public void testRelativeConfPropery() {
    ConfigurationResourceResolvingStrategy underTest = context.registerInjectActivateService(new DefaultConfigurationResourceResolvingStrategy());
    // build config resources
    context.build().resource("/conf/main/sub/sling:test/test").resource("/conf/main/sub/deep/sling:test/test");
    assertEquals("/conf/main/sub/sling:test/test", underTest.getResource(subPage, BUCKETS, "test").getPath());
    assertEquals("/conf/main/sub/deep/sling:test/test", underTest.getResource(deepPage, BUCKETS, "test").getPath());
}
Also used : ConfigurationResourceResolvingStrategy(org.apache.sling.caconfig.resource.spi.ConfigurationResourceResolvingStrategy) Test(org.junit.Test)

Aggregations

ConfigurationResourceResolvingStrategy (org.apache.sling.caconfig.resource.spi.ConfigurationResourceResolvingStrategy)12 Test (org.junit.Test)12 Function (com.google.common.base.Function)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 Resource (org.apache.sling.api.resource.Resource)1 DefaultConfigurationResourceResolvingStrategy (org.apache.sling.caconfig.resource.impl.def.DefaultConfigurationResourceResolvingStrategy)1