use of javax.jcr.RangeIterator in project jackrabbit by apache.
the class AuthorizableImplTest method testMemberOfRangeIterator.
public void testMemberOfRangeIterator() throws NotExecutableException, RepositoryException {
Authorizable auth = null;
Group group = null;
try {
auth = userMgr.createUser(getTestPrincipal().getName(), "pw");
group = userMgr.createGroup(getTestPrincipal());
save(superuser);
Iterator<Group> groups = auth.declaredMemberOf();
assertTrue(groups instanceof RangeIterator);
assertEquals(0, ((RangeIterator) groups).getSize());
groups = auth.memberOf();
assertTrue(groups instanceof RangeIterator);
assertEquals(0, ((RangeIterator) groups).getSize());
group.addMember(auth);
groups = auth.declaredMemberOf();
assertTrue(groups instanceof RangeIterator);
assertEquals(1, ((RangeIterator) groups).getSize());
groups = auth.memberOf();
assertTrue(groups instanceof RangeIterator);
assertEquals(1, ((RangeIterator) groups).getSize());
} finally {
if (auth != null) {
auth.remove();
}
if (group != null) {
group.remove();
}
save(superuser);
}
}
use of javax.jcr.RangeIterator in project jackrabbit by apache.
the class FilteredRangeIteratorTest method testMatchAll.
public void testMatchAll() {
RangeIterator iterator = new FilteredRangeIterator(LIST.iterator());
assertEquals(3, iterator.getSize());
assertEquals(0, iterator.getPosition());
assertTrue(iterator.hasNext());
assertEquals("x", iterator.next());
assertEquals(1, iterator.getPosition());
assertTrue(iterator.hasNext());
assertEquals("y", iterator.next());
assertEquals(2, iterator.getPosition());
assertTrue(iterator.hasNext());
assertEquals("z", iterator.next());
assertEquals(3, iterator.getPosition());
assertFalse(iterator.hasNext());
}
use of javax.jcr.RangeIterator in project jackrabbit by apache.
the class LazyItemIteratorTest method testSizeShrinksIfInvalidItemFound.
public void testSizeShrinksIfInvalidItemFound() throws NotExecutableException, RepositoryException {
RangeIterator it;
try {
testRootNode.addNode(nodeName1, testNodeType);
testRootNode.addNode(nodeName2, testNodeType);
Node child = testRootNode.addNode(nodeName3, testNodeType);
testRootNode.save();
it = testRootNode.getNodes();
// remove 1 child -> force the iterator to contain an entry that
// cannot be resolved into a node.
child.remove();
} catch (RepositoryException e) {
throw new NotExecutableException();
}
// now the original size is off by one and will be adjusted automatically
long size = it.getSize();
long zise = 0;
while (it.hasNext()) {
it.next();
zise++;
}
// original size is bigger by 1 than the calculated size during the
// iteration.
assertTrue(size == zise + 1);
// retrieve size again and check if it has been been adjusted.
assertTrue(it.getSize() == zise);
}
use of javax.jcr.RangeIterator in project sling by apache.
the class MockNode method getNodes.
@Override
public NodeIterator getNodes(final String namePattern) throws RepositoryException {
final Pattern pattern = Pattern.compile(namePattern);
RangeIterator items = getMockedSession().listChildren(getPath(), new ItemFilter() {
@Override
public boolean accept(final ItemData item) throws RepositoryException {
return item.isNode() && pattern.matcher(item.getName()).matches();
}
});
return new NodeIteratorAdapter(items, items.getSize());
}
Aggregations