Search in sources :

Example 1 with MockProperty

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

Calendar (java.util.Calendar)1 Node (javax.jcr.Node)1 AbstractNode (org.apache.jackrabbit.commons.AbstractNode)1 MockNodeIterator (org.apache.sling.commons.testing.jcr.MockNodeIterator)1 MockProperty (org.apache.sling.commons.testing.jcr.MockProperty)1 MockPropertyIterator (org.apache.sling.commons.testing.jcr.MockPropertyIterator)1