use of org.apache.sling.commons.testing.jcr.MockNodeIterator 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
}
}
use of org.apache.sling.commons.testing.jcr.MockNodeIterator 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
}
}
use of org.apache.sling.commons.testing.jcr.MockNodeIterator in project acs-aem-commons by Adobe-Consulting-Services.
the class RootNodeMockFactory method generateBucketNodeChain.
private Node[] generateBucketNodeChain(Node rootNode, boolean isEmpty) throws RepositoryException {
final Node[] bucketNodeChain = new Node[settings.bucketDepth];
Node currentParentNode = rootNode;
for (int i = 0; i < settings.bucketDepth; i++) {
final Node node = mockStandardNode("bucketnode" + (isEmpty ? "-empty" : "") + "-level-" + (i + 1));
bucketNodeChain[i] = node;
when(node.getParent()).thenReturn(currentParentNode);
when(node.getProperties()).thenReturn(new MockPropertyIterator(IteratorUtils.EMPTY_ITERATOR));
when(node.hasProperty(JCRHttpCacheStoreConstants.PN_ISCACHEENTRYNODE)).thenReturn(false);
when(node.hasProperty(JCRHttpCacheStoreConstants.PN_ISBUCKETNODE)).thenReturn(true);
currentParentNode = node;
}
for (int i = 0; i < settings.bucketDepth; i++) {
if (i < settings.bucketDepth) {
final Node node = bucketNodeChain[i];
final Node childNode = bucketNodeChain[i];
final AtomicInteger deleteCounter = new AtomicInteger();
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
deleteCounter.getAndIncrement();
return null;
}
}).when(node).remove();
when(node.getParent().getNodes()).thenAnswer(new Answer<NodeIterator>() {
@Override
public NodeIterator answer(InvocationOnMock invocationOnMock) throws Throwable {
if (deleteCounter.get() > 0) {
return new MockNodeIterator();
} else {
return new MockNodeIterator(new Node[] { childNode });
}
}
});
}
}
return bucketNodeChain;
}
use of org.apache.sling.commons.testing.jcr.MockNodeIterator in project acs-aem-commons by Adobe-Consulting-Services.
the class RootNodeMockFactory method generateEntryNodes.
private NodeIterator generateEntryNodes(final Node parentNode) throws RepositoryException, IOException {
int totalNodeCount = settings.entryNodeCount + settings.expiredEntryNodeCount;
final Node[] nodes = new AbstractNode[totalNodeCount];
int i = 0;
for (; i < settings.entryNodeCount; i++) {
final Node randomNode = mockEntryNode(parentNode, i, false);
nodes[i] = randomNode;
}
for (; i < totalNodeCount; i++) {
final Node randomNode = mockEntryNode(parentNode, i, true);
nodes[i] = randomNode;
}
return new MockNodeIterator(nodes);
}
use of org.apache.sling.commons.testing.jcr.MockNodeIterator in project acs-aem-commons by Adobe-Consulting-Services.
the class RootNodeMockFactory method build.
public Node build() throws RepositoryException, IOException {
final Node rootNode = mockStandardNode("rootnode");
when(rootNode.getPath()).thenReturn(ROOT_PATH);
Node[] bucketNodeChain = generateBucketNodeChain(rootNode, false);
Node parentNode = bucketNodeChain[bucketNodeChain.length - 1];
final NodeIterator entryNodes = generateEntryNodes(parentNode);
when(parentNode.getNodes()).thenReturn(entryNodes);
Node[] level1nodes = new Node[1 + settings.emptyBucketNodeChainCount];
level1nodes[0] = bucketNodeChain[0];
for (int i = 0; i < settings.emptyBucketNodeChainCount; i++) {
Node[] emptyBucketNodeChain = generateBucketNodeChain(rootNode, true);
when(emptyBucketNodeChain[emptyBucketNodeChain.length - 1].getNodes()).thenReturn(new MockNodeIterator());
level1nodes[i + 1] = emptyBucketNodeChain[0];
}
when(rootNode.getNodes()).thenReturn(new MockNodeIterator(level1nodes));
when(rootNode.getProperties()).thenReturn(new MockPropertyIterator(IteratorUtils.EMPTY_ITERATOR));
return rootNode;
}
Aggregations