Search in sources :

Example 6 with MockNodeIterator

use of org.apache.sling.commons.testing.jcr.MockNodeIterator 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 7 with MockNodeIterator

use of org.apache.sling.commons.testing.jcr.MockNodeIterator 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)

Example 8 with MockNodeIterator

use of org.apache.sling.commons.testing.jcr.MockNodeIterator in project acs-aem-commons by Adobe-Consulting-Services.

the class RootNodeMockFactory method mockEntryNode.

private Node mockEntryNode(Node parentNode, int i, boolean isExpired) throws RepositoryException, IOException {
    final String nodeName = (isExpired) ? "expired-entrynode-" : "entrynode-";
    final Node entryNode = mockStandardNode(nodeName + (i + 1));
    if (settings.enableCacheEntryBinaryContent) {
        mockEntryContentNode(entryNode);
    }
    when(entryNode.hasProperty(JCRHttpCacheStoreConstants.PN_ISCACHEENTRYNODE)).thenReturn(true);
    when(entryNode.hasProperty(JCRHttpCacheStoreConstants.PN_ISBUCKETNODE)).thenReturn(false);
    when(entryNode.hasProperty(JCRHttpCacheStoreConstants.PN_EXPIRES_ON)).thenReturn(true);
    when(entryNode.getNodes()).thenReturn(new MockNodeIterator());
    when(entryNode.getProperties()).thenReturn(new MockPropertyIterator(IteratorUtils.EMPTY_ITERATOR));
    when(entryNode.getParent()).thenReturn(parentNode);
    final MockProperty expiresMockProperty = new MockProperty(JCRHttpCacheStoreConstants.PN_EXPIRES_ON);
    int seconds;
    if (isExpired) {
        seconds = -9000;
    } else {
        seconds = 9000;
    }
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.SECOND, seconds);
    expiresMockProperty.setValue(calendar);
    when(entryNode.getProperty(JCRHttpCacheStoreConstants.PN_EXPIRES_ON)).thenReturn(expiresMockProperty);
    return entryNode;
}
Also used : MockNodeIterator(org.apache.sling.commons.testing.jcr.MockNodeIterator) AbstractNode(org.apache.jackrabbit.commons.AbstractNode) Node(javax.jcr.Node) Calendar(java.util.Calendar) MockPropertyIterator(org.apache.sling.commons.testing.jcr.MockPropertyIterator) MockProperty(org.apache.sling.commons.testing.jcr.MockProperty)

Aggregations

MockNodeIterator (org.apache.sling.commons.testing.jcr.MockNodeIterator)8 Node (javax.jcr.Node)7 NodeIterator (javax.jcr.NodeIterator)6 NoSuchElementException (java.util.NoSuchElementException)4 AbstractNode (org.apache.jackrabbit.commons.AbstractNode)4 JcrNodeResourceIterator (org.apache.sling.jcr.resource.internal.helper.jcr.JcrNodeResourceIterator)4 Resource (org.apache.sling.api.resource.Resource)3 MockNode (org.apache.sling.commons.testing.jcr.MockNode)3 MockPropertyIterator (org.apache.sling.commons.testing.jcr.MockPropertyIterator)3 Calendar (java.util.Calendar)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 MockProperty (org.apache.sling.commons.testing.jcr.MockProperty)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1