Search in sources :

Example 1 with ContextPathStrategy

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

the class DefaultContextPathStrategyTest method testDisabled.

@Test
public void testDisabled() {
    ContextPathStrategy underTest = context.registerInjectActivateService(new DefaultContextPathStrategy(), "enabled", false);
    assertFalse(underTest.findContextResources(site1Page1).hasNext());
    assertFalse(underTest.findContextResources(site2Page1).hasNext());
}
Also used : ContextPathStrategy(org.apache.sling.caconfig.resource.spi.ContextPathStrategy) Test(org.junit.Test)

Example 2 with ContextPathStrategy

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

the class DefaultContextPathStrategyTest method testConfigRefResourceNames.

@Test
public void testConfigRefResourceNames() {
    ContextPathStrategy underTest = context.registerInjectActivateService(new DefaultContextPathStrategy(), "configRefResourceNames", new String[] { "jcr:content" });
    context.build().resource("/content/tenant1/region1/jcr:content", PROPERTY_CONFIG_REF, "/conf/tenant1/region1");
    assertThat(toResourceIterator(underTest.findContextResources(site1Page1)), ResourceIteratorMatchers.paths("/content/tenant1/region1"));
    assertThat(ImmutableList.copyOf(toConfigRefIterator(underTest.findContextResources(site1Page1))), Matchers.contains("/conf/tenant1/region1"));
    assertThat(toResourceIterator(underTest.findContextResources(site2Page1)), ResourceIteratorMatchers.paths("/content/tenant1/region1"));
    assertThat(ImmutableList.copyOf(toConfigRefIterator(underTest.findContextResources(site2Page1))), Matchers.contains("/conf/tenant1/region1"));
}
Also used : ContextPathStrategy(org.apache.sling.caconfig.resource.spi.ContextPathStrategy) Test(org.junit.Test)

Example 3 with ContextPathStrategy

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

the class ContextPathStrategyMultiplexerImplTest method registerContextPathStrategy.

private void registerContextPathStrategy(String... paths) {
    final List<Resource> resources = new ArrayList<>();
    for (String path : paths) {
        Resource resource = context.resourceResolver().getResource(path);
        if (resource != null) {
            resources.add(resource);
        }
    }
    context.registerService(ContextPathStrategy.class, new ContextPathStrategy() {

        @Override
        public Iterator<ContextResource> findContextResources(Resource resource) {
            return toContextResourceIterator(resources.iterator());
        }
    });
}
Also used : ArrayList(java.util.ArrayList) Resource(org.apache.sling.api.resource.Resource) ContextResource(org.apache.sling.caconfig.resource.spi.ContextResource) ContextResourceTestUtil.toContextResourceIterator(org.apache.sling.caconfig.resource.impl.util.ContextResourceTestUtil.toContextResourceIterator) Iterator(java.util.Iterator) ContextResourceTestUtil.toResourceIterator(org.apache.sling.caconfig.resource.impl.util.ContextResourceTestUtil.toResourceIterator) DefaultContextPathStrategy(org.apache.sling.caconfig.resource.impl.def.DefaultContextPathStrategy) ContextPathStrategy(org.apache.sling.caconfig.resource.spi.ContextPathStrategy)

Example 4 with ContextPathStrategy

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

the class DefaultContextPathStrategyTest method testFindContextPaths.

@Test
public void testFindContextPaths() {
    ContextPathStrategy underTest = context.registerInjectActivateService(new DefaultContextPathStrategy());
    assertThat(toResourceIterator(underTest.findContextResources(site1Page1)), ResourceIteratorMatchers.paths("/content/tenant1/region1/site1", "/content/tenant1/region1", "/content/tenant1"));
    assertThat(ImmutableList.copyOf(toConfigRefIterator(underTest.findContextResources(site1Page1))), Matchers.contains("/conf/tenant1/region1/site1", "/conf/tenant1/region1", "/conf/tenant1"));
    assertThat(toResourceIterator(underTest.findContextResources(site2Page1)), ResourceIteratorMatchers.paths("/content/tenant1/region1/site2", "/content/tenant1/region1", "/content/tenant1"));
    assertThat(ImmutableList.copyOf(toConfigRefIterator(underTest.findContextResources(site2Page1))), Matchers.contains("/conf/tenant1/region1/site2", "/conf/tenant1/region1", "/conf/tenant1"));
}
Also used : ContextPathStrategy(org.apache.sling.caconfig.resource.spi.ContextPathStrategy) Test(org.junit.Test)

Aggregations

ContextPathStrategy (org.apache.sling.caconfig.resource.spi.ContextPathStrategy)4 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 Resource (org.apache.sling.api.resource.Resource)1 DefaultContextPathStrategy (org.apache.sling.caconfig.resource.impl.def.DefaultContextPathStrategy)1 ContextResourceTestUtil.toContextResourceIterator (org.apache.sling.caconfig.resource.impl.util.ContextResourceTestUtil.toContextResourceIterator)1 ContextResourceTestUtil.toResourceIterator (org.apache.sling.caconfig.resource.impl.util.ContextResourceTestUtil.toResourceIterator)1 ContextResource (org.apache.sling.caconfig.resource.spi.ContextResource)1