use of org.apache.sling.commons.testing.jcr.MockPropertyIterator 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.MockPropertyIterator 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;
}
use of org.apache.sling.commons.testing.jcr.MockPropertyIterator 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