Search in sources :

Example 1 with JcrNodeResourceIterator

use of org.apache.sling.jcr.resource.internal.helper.jcr.JcrNodeResourceIterator in project sling by apache.

the class JcrNodeResourceIteratorTest method testRoot.

public void testRoot() throws RepositoryException {
    String path = "/child";
    Node node = new MockNode(path);
    NodeIterator ni = new MockNodeIterator(new Node[] { node });
    JcrNodeResourceIterator ri = new JcrNodeResourceIterator(null, "/", null, ni, getHelperData(), null);
    assertTrue(ri.hasNext());
    Resource res = ri.next();
    assertEquals(path, res.getPath());
    assertEquals(node.getPrimaryNodeType().getName(), res.getResourceType());
    assertFalse(ri.hasNext());
    try {
        ri.next();
        fail("Expected no element in the iterator");
    } catch (NoSuchElementException nsee) {
    // expected
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) MockNodeIterator(org.apache.sling.commons.testing.jcr.MockNodeIterator) MockNodeIterator(org.apache.sling.commons.testing.jcr.MockNodeIterator) MockNode(org.apache.sling.commons.testing.jcr.MockNode) Node(javax.jcr.Node) Resource(org.apache.sling.api.resource.Resource) MockNode(org.apache.sling.commons.testing.jcr.MockNode) JcrNodeResourceIterator(org.apache.sling.jcr.resource.internal.helper.jcr.JcrNodeResourceIterator) NoSuchElementException(java.util.NoSuchElementException)

Example 2 with JcrNodeResourceIterator

use of org.apache.sling.jcr.resource.internal.helper.jcr.JcrNodeResourceIterator in project sling by apache.

the class JcrNodeResourceIteratorTest method testMulti.

public void testMulti() throws RepositoryException {
    int numNodes = 10;
    String pathBase = "/parent/path/node/";
    Node[] nodes = new Node[numNodes];
    for (int i = 0; i < nodes.length; i++) {
        nodes[i] = new MockNode(pathBase + i, "some:type" + i);
    }
    NodeIterator ni = new MockNodeIterator(nodes);
    JcrNodeResourceIterator ri = new JcrNodeResourceIterator(null, null, null, ni, getHelperData(), null);
    for (int i = 0; i < nodes.length; i++) {
        assertTrue(ri.hasNext());
        Resource res = ri.next();
        assertEquals(pathBase + i, res.getPath());
        assertEquals(nodes[i].getPrimaryNodeType().getName(), res.getResourceType());
    }
    assertFalse(ri.hasNext());
    try {
        ri.next();
        fail("Expected no element in the iterator");
    } catch (NoSuchElementException nsee) {
    // expected
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) MockNodeIterator(org.apache.sling.commons.testing.jcr.MockNodeIterator) MockNodeIterator(org.apache.sling.commons.testing.jcr.MockNodeIterator) MockNode(org.apache.sling.commons.testing.jcr.MockNode) Node(javax.jcr.Node) Resource(org.apache.sling.api.resource.Resource) MockNode(org.apache.sling.commons.testing.jcr.MockNode) JcrNodeResourceIterator(org.apache.sling.jcr.resource.internal.helper.jcr.JcrNodeResourceIterator) NoSuchElementException(java.util.NoSuchElementException)

Example 3 with JcrNodeResourceIterator

use of org.apache.sling.jcr.resource.internal.helper.jcr.JcrNodeResourceIterator in project sling by apache.

the class JcrNodeResourceIteratorTest method testEmpty.

public void testEmpty() {
    NodeIterator ni = new MockNodeIterator(null);
    JcrNodeResourceIterator ri = new JcrNodeResourceIterator(null, null, null, ni, getHelperData(), null);
    assertFalse(ri.hasNext());
    try {
        ri.next();
        fail("Expected no element in the iterator");
    } catch (NoSuchElementException nsee) {
    // expected
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) MockNodeIterator(org.apache.sling.commons.testing.jcr.MockNodeIterator) MockNodeIterator(org.apache.sling.commons.testing.jcr.MockNodeIterator) JcrNodeResourceIterator(org.apache.sling.jcr.resource.internal.helper.jcr.JcrNodeResourceIterator) NoSuchElementException(java.util.NoSuchElementException)

Example 4 with JcrNodeResourceIterator

use of org.apache.sling.jcr.resource.internal.helper.jcr.JcrNodeResourceIterator in project sling by apache.

the class JcrNodeResourceIteratorTest method testSingle.

public void testSingle() throws RepositoryException {
    String path = "/parent/path/node";
    Node node = new MockNode(path);
    NodeIterator ni = new MockNodeIterator(new Node[] { node });
    JcrNodeResourceIterator ri = new JcrNodeResourceIterator(null, null, null, ni, getHelperData(), null);
    assertTrue(ri.hasNext());
    Resource res = ri.next();
    assertEquals(path, res.getPath());
    assertEquals(node.getPrimaryNodeType().getName(), res.getResourceType());
    assertFalse(ri.hasNext());
    try {
        ri.next();
        fail("Expected no element in the iterator");
    } catch (NoSuchElementException nsee) {
    // expected
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) MockNodeIterator(org.apache.sling.commons.testing.jcr.MockNodeIterator) MockNodeIterator(org.apache.sling.commons.testing.jcr.MockNodeIterator) MockNode(org.apache.sling.commons.testing.jcr.MockNode) Node(javax.jcr.Node) Resource(org.apache.sling.api.resource.Resource) MockNode(org.apache.sling.commons.testing.jcr.MockNode) JcrNodeResourceIterator(org.apache.sling.jcr.resource.internal.helper.jcr.JcrNodeResourceIterator) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

NoSuchElementException (java.util.NoSuchElementException)4 NodeIterator (javax.jcr.NodeIterator)4 MockNodeIterator (org.apache.sling.commons.testing.jcr.MockNodeIterator)4 JcrNodeResourceIterator (org.apache.sling.jcr.resource.internal.helper.jcr.JcrNodeResourceIterator)4 Node (javax.jcr.Node)3 Resource (org.apache.sling.api.resource.Resource)3 MockNode (org.apache.sling.commons.testing.jcr.MockNode)3