Search in sources :

Example 1 with IteratorIterable

use of org.apache.commons.collections4.iterators.IteratorIterable in project sling by apache.

the class CommonMergedResourceProviderTest method testOrderOfNonOverlappingChildren.

@Test
public void testOrderOfNonOverlappingChildren() throws PersistenceException {
    // create new child nodes below base and overlay
    MockHelper.create(this.resolver).resource("/apps/base/child1").resource("/apps/base/child2").resource("/apps/overlay/child3").resource("/apps/overlay/child4").commit();
    Resource mergedResource = this.provider.getResource(ctx, "/merged", ResourceContext.EMPTY_CONTEXT, null);
    // convert the iterator returned by list children into an iterable (to be able to perform some tests)
    IteratorIterable<Resource> iterable = new IteratorIterable<Resource>(provider.listChildren(ctx, mergedResource), true);
    Assert.assertThat(iterable, Matchers.contains(ResourceMatchers.name("child1"), ResourceMatchers.name("child2"), ResourceMatchers.name("child3"), ResourceMatchers.name("child4")));
}
Also used : IteratorIterable(org.apache.commons.collections4.iterators.IteratorIterable) NonExistingResource(org.apache.sling.api.resource.NonExistingResource) Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Example 2 with IteratorIterable

use of org.apache.commons.collections4.iterators.IteratorIterable in project sling by apache.

the class CommonMergedResourceProviderTest method testHideChildren.

@Test
public void testHideChildren() throws PersistenceException {
    // create new child nodes below base and overlay
    MockHelper.create(this.resolver).resource("/apps/base/child1").p("property1", "frombase").resource("/apps/base/child2").p("property1", "frombase").resource("/apps/overlay/child1").p("property1", "fromoverlay").resource("/apps/overlay/child3").p("property1", "fromoverlay").commit();
    ModifiableValueMap properties = overlay.adaptTo(ModifiableValueMap.class);
    properties.put(MergedResourceConstants.PN_HIDE_CHILDREN, "*");
    resolver.commit();
    Resource mergedResource = this.provider.getResource(ctx, "/merged", ResourceContext.EMPTY_CONTEXT, null);
    // convert the iterator returned by list children into an iterable (to be able to perform some tests)
    IteratorIterable<Resource> iterable = new IteratorIterable<Resource>(provider.listChildren(ctx, mergedResource), true);
    // all overlay resource are still exposed, because hiding children by wildcard only hides children from underlying resources
    Assert.assertThat(iterable, Matchers.containsInAnyOrder(ResourceMatchers.nameAndProps("child1", Collections.singletonMap("property1", (Object) "fromoverlay")), ResourceMatchers.nameAndProps("child3", Collections.singletonMap("property1", (Object) "fromoverlay"))));
    // now hide by explicit value
    properties.put(MergedResourceConstants.PN_HIDE_CHILDREN, "child1");
    resolver.commit();
    // child1 is no longer exposed from overlay, because hiding children by name hides children from underlying as well as from local resources, child2 is exposed from base
    iterable = new IteratorIterable<Resource>(provider.listChildren(ctx, mergedResource), true);
    Assert.assertThat(iterable, Matchers.containsInAnyOrder(ResourceMatchers.name("child2"), ResourceMatchers.name("child3")));
    // now hide by negated value (hide all underlying children except for the one with name child2)
    properties.put(MergedResourceConstants.PN_HIDE_CHILDREN, new String[] { "!child2", "*", "child3" });
    resolver.commit();
    iterable = new IteratorIterable<Resource>(provider.listChildren(ctx, mergedResource), true);
    Assert.assertThat(iterable, Matchers.containsInAnyOrder(ResourceMatchers.name("child2"), ResourceMatchers.nameAndProps("child1", Collections.singletonMap("property1", (Object) "fromoverlay"))));
}
Also used : IteratorIterable(org.apache.commons.collections4.iterators.IteratorIterable) NonExistingResource(org.apache.sling.api.resource.NonExistingResource) Resource(org.apache.sling.api.resource.Resource) ModifiableValueMap(org.apache.sling.api.resource.ModifiableValueMap) Test(org.junit.Test)

Example 3 with IteratorIterable

use of org.apache.commons.collections4.iterators.IteratorIterable in project sling by apache.

the class CommonMergedResourceProviderTest method testOrderOfPartiallyOverwrittenChildren.

@Test
public void testOrderOfPartiallyOverwrittenChildren() throws PersistenceException {
    // see https://issues.apache.org/jira/browse/SLING-4915
    // create new child nodes below base and overlay
    MockHelper.create(this.resolver).resource("/apps/base/child1").resource("/apps/base/child2").resource("/apps/base/child3").resource("/apps/overlay/child4").resource("/apps/overlay/child2").resource("/apps/overlay/child3").commit();
    Resource mergedResource = this.provider.getResource(ctx, "/merged", ResourceContext.EMPTY_CONTEXT, null);
    // convert the iterator returned by list children into an iterable (to be able to perform some tests)
    IteratorIterable<Resource> iterable = new IteratorIterable<Resource>(provider.listChildren(ctx, mergedResource), true);
    Assert.assertThat(iterable, Matchers.contains(ResourceMatchers.name("child1"), ResourceMatchers.name("child4"), ResourceMatchers.name("child2"), ResourceMatchers.name("child3")));
}
Also used : IteratorIterable(org.apache.commons.collections4.iterators.IteratorIterable) NonExistingResource(org.apache.sling.api.resource.NonExistingResource) Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Example 4 with IteratorIterable

use of org.apache.commons.collections4.iterators.IteratorIterable in project sling by apache.

the class CommonMergedResourceProviderTest method testOrderBeingModifiedThroughOrderBefore.

@Test
public void testOrderBeingModifiedThroughOrderBefore() throws PersistenceException {
    // create new child nodes below base and overlay
    MockHelper.create(this.resolver).resource("/apps/base/child1").resource("/apps/base/child2").resource("/apps/overlay/child3").p(MergedResourceConstants.PN_ORDER_BEFORE, "child2").commit();
    Resource mergedResource = this.provider.getResource(ctx, "/merged", ResourceContext.EMPTY_CONTEXT, null);
    // convert the iterator returned by list children into an iterable (to be able to perform some tests)
    IteratorIterable<Resource> iterable = new IteratorIterable<Resource>(provider.listChildren(ctx, mergedResource), true);
    Assert.assertThat(iterable, Matchers.contains(ResourceMatchers.name("child1"), ResourceMatchers.name("child3"), ResourceMatchers.name("child2")));
}
Also used : IteratorIterable(org.apache.commons.collections4.iterators.IteratorIterable) NonExistingResource(org.apache.sling.api.resource.NonExistingResource) Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Example 5 with IteratorIterable

use of org.apache.commons.collections4.iterators.IteratorIterable in project sling by apache.

the class CommonMergedResourceProviderTest method testHideChildrenWithResourceNamesStartingWithExclamationMark.

@Test
public void testHideChildrenWithResourceNamesStartingWithExclamationMark() throws PersistenceException {
    // create new child nodes below base and overlay
    MockHelper.create(this.resolver).resource("/apps/base/!child1").p("property1", "frombase").resource("/apps/overlay/!child1").p("property1", "fromoverlay").resource("/apps/overlay/!child3").p("property1", "fromoverlay").commit();
    ModifiableValueMap properties = overlay.adaptTo(ModifiableValueMap.class);
    // escape the resource name with another exclamation mark
    properties.put(MergedResourceConstants.PN_HIDE_CHILDREN, "!!child3");
    resolver.commit();
    Resource mergedResource = this.provider.getResource(ctx, "/merged", ResourceContext.EMPTY_CONTEXT, null);
    // convert the iterator returned by list children into an iterable (to be able to perform some tests)
    IteratorIterable<Resource> iterable = new IteratorIterable<Resource>(provider.listChildren(ctx, mergedResource), true);
    // the resource named "!child3" should be hidden
    Assert.assertThat(iterable, Matchers.contains(ResourceMatchers.nameAndProps("!child1", Collections.singletonMap("property1", (Object) "fromoverlay"))));
}
Also used : IteratorIterable(org.apache.commons.collections4.iterators.IteratorIterable) NonExistingResource(org.apache.sling.api.resource.NonExistingResource) Resource(org.apache.sling.api.resource.Resource) ModifiableValueMap(org.apache.sling.api.resource.ModifiableValueMap) Test(org.junit.Test)

Aggregations

IteratorIterable (org.apache.commons.collections4.iterators.IteratorIterable)5 NonExistingResource (org.apache.sling.api.resource.NonExistingResource)5 Resource (org.apache.sling.api.resource.Resource)5 Test (org.junit.Test)5 ModifiableValueMap (org.apache.sling.api.resource.ModifiableValueMap)2