Search in sources :

Example 6 with RangeIterator

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);
    }
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) RangeIterator(javax.jcr.RangeIterator) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable)

Example 7 with RangeIterator

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());
}
Also used : RangeIterator(javax.jcr.RangeIterator)

Example 8 with RangeIterator

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);
}
Also used : RangeIterator(javax.jcr.RangeIterator) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException)

Example 9 with RangeIterator

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());
}
Also used : Pattern(java.util.regex.Pattern) RangeIterator(javax.jcr.RangeIterator) NodeIteratorAdapter(org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter) RepositoryException(javax.jcr.RepositoryException)

Aggregations

RangeIterator (javax.jcr.RangeIterator)9 RepositoryException (javax.jcr.RepositoryException)3 Pattern (java.util.regex.Pattern)2 Node (javax.jcr.Node)1 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)1 Group (org.apache.jackrabbit.api.security.user.Group)1 NodeIteratorAdapter (org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter)1 PropertyIteratorAdapter (org.apache.jackrabbit.commons.iterator.PropertyIteratorAdapter)1 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)1