List of usage examples for org.apache.commons.collections4.iterators IteratorIterable IteratorIterable
public IteratorIterable(final Iterator<? extends E> iterator, final boolean multipleUse)
IteratorIterable
that will use the given iterator. From source file:org.apache.sling.resourcemerger.impl.CommonMergedResourceProviderTest.java
@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();/*from w ww. ja va2 s . co m*/ 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.resourceWithNameAndProps("child1", Collections.singletonMap("property1", (Object) "fromoverlay")), ResourceMatchers.resourceWithNameAndProps("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.resourceWithName("child2"), ResourceMatchers.resourceWithName("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.resourceWithName("child2"), ResourceMatchers.resourceWithNameAndProps("child1", Collections.singletonMap("property1", (Object) "fromoverlay")))); }
From source file:org.apache.sling.resourcemerger.impl.CommonMergedResourceProviderTest.java
@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); properties.put(MergedResourceConstants.PN_HIDE_CHILDREN, "!!child3"); // escape the resource name with another exclamation mark resolver.commit();//from ww w. ja va 2s .c om 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.resourceWithNameAndProps("!child1", Collections.singletonMap("property1", (Object) "fromoverlay")))); }
From source file:org.apache.sling.resourcemerger.impl.CommonMergedResourceProviderTest.java
@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,/*from w w w .j av a 2 s . c om*/ Matchers.contains(ResourceMatchers.resourceWithName("child1"), ResourceMatchers.resourceWithName("child4"), ResourceMatchers.resourceWithName("child2"), ResourceMatchers.resourceWithName("child3"))); }
From source file:org.apache.sling.resourcemerger.impl.CommonMergedResourceProviderTest.java
@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,// w w w.j a v a 2 s. c o m Matchers.contains(ResourceMatchers.resourceWithName("child1"), ResourceMatchers.resourceWithName("child2"), ResourceMatchers.resourceWithName("child3"), ResourceMatchers.resourceWithName("child4"))); }
From source file:org.apache.sling.resourcemerger.impl.CommonMergedResourceProviderTest.java
@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.resourceWithName("child1"), ResourceMatchers.resourceWithName("child3"), ResourceMatchers.resourceWithName("child2"))); }