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
}
}
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
}
}
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;
}
Aggregations