Search in sources :

Example 1 with TreeTraverser

use of org.apache.jackrabbit.commons.flat.TreeTraverser in project jackrabbit by apache.

the class ItemSequenceTest method checkTreeProperty.

private static void checkTreeProperty(Node root, int minChildren, int maxChildren, Comparator<String> order) throws RepositoryException {
    int depth = -1;
    for (Node node : new TreeTraverser(root)) {
        String parentName = node.getName();
        if (node.hasNodes()) {
            int childCount = 0;
            for (NodeIterator nodes = node.getNodes(); nodes.hasNext(); ) {
                Node child = nodes.nextNode();
                childCount++;
                if (!root.isSame(node)) {
                    assertTrue("Mismatching order: node " + node + " contains child " + child, order.compare(parentName, child.getName()) <= 0);
                }
            }
            if (!root.isSame(node)) {
                assertTrue("Node " + node + " should have at least " + minChildren + " child nodes", minChildren <= childCount);
            }
            assertTrue("Node " + node + " should have no more than " + maxChildren + " child nodes", maxChildren >= childCount);
        } else {
            if (depth == -1) {
                depth = node.getDepth();
            } else {
                assertEquals("Node " + node + " has depth " + node.getDepth() + " instead of " + depth, depth, node.getDepth());
            }
            int propCount = 0;
            for (PropertyIterator properties = node.getProperties(); properties.hasNext(); ) {
                Property property = properties.nextProperty();
                String propertyName = property.getName();
                if (!JcrConstants.JCR_PRIMARYTYPE.equals(propertyName)) {
                    propCount++;
                    assertTrue("Mismatching order: node " + node + " contains property " + property, order.compare(parentName, propertyName) <= 0);
                }
            }
            if (propCount > 0) {
                assertTrue("Node " + node + " should have at least " + minChildren + " properties", minChildren <= propCount);
                assertTrue("Node" + node + " should have no more than " + maxChildren + " properties", maxChildren >= propCount);
            }
        }
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) Node(javax.jcr.Node) TreeTraverser(org.apache.jackrabbit.commons.flat.TreeTraverser) PropertyIterator(javax.jcr.PropertyIterator) Property(javax.jcr.Property)

Example 2 with TreeTraverser

use of org.apache.jackrabbit.commons.flat.TreeTraverser in project jackrabbit by apache.

the class TreeTraverserTest method testTraverseLeaves.

public void testTraverseLeaves() throws RepositoryException {
    addNodes(testNode, nodes);
    TreeTraverser traverser = new TreeTraverser(testNode, errorHandler, TreeTraverser.InclusionPolicy.LEAVES);
    checkNodes(traverser, leaves.iterator(), testNode.getPath());
}
Also used : TreeTraverser(org.apache.jackrabbit.commons.flat.TreeTraverser)

Example 3 with TreeTraverser

use of org.apache.jackrabbit.commons.flat.TreeTraverser in project jackrabbit by apache.

the class TreeTraverserTest method testTraverseNodes.

public void testTraverseNodes() throws RepositoryException {
    addNodes(testNode, nodes);
    TreeTraverser traverser = new TreeTraverser(testNode, errorHandler, TreeTraverser.InclusionPolicy.ALL);
    checkNodes(traverser, nodes.iterator(), testNode.getPath());
}
Also used : TreeTraverser(org.apache.jackrabbit.commons.flat.TreeTraverser)

Example 4 with TreeTraverser

use of org.apache.jackrabbit.commons.flat.TreeTraverser in project jackrabbit by apache.

the class TreeTraverserTest method testTraverseLeavesEmpty.

public void testTraverseLeavesEmpty() throws RepositoryException {
    TreeTraverser traverser = new TreeTraverser(testNode, errorHandler, TreeTraverser.InclusionPolicy.LEAVES);
    checkNodes(traverser, singleton(""), testNode.getPath());
}
Also used : TreeTraverser(org.apache.jackrabbit.commons.flat.TreeTraverser)

Example 5 with TreeTraverser

use of org.apache.jackrabbit.commons.flat.TreeTraverser in project jackrabbit by apache.

the class TreeTraverserTest method testTraverseNodesEmpty.

public void testTraverseNodesEmpty() throws RepositoryException {
    TreeTraverser traverser = new TreeTraverser(testNode, errorHandler, TreeTraverser.InclusionPolicy.ALL);
    checkNodes(traverser, singleton(""), testNode.getPath());
}
Also used : TreeTraverser(org.apache.jackrabbit.commons.flat.TreeTraverser)

Aggregations

TreeTraverser (org.apache.jackrabbit.commons.flat.TreeTraverser)5 Node (javax.jcr.Node)1 NodeIterator (javax.jcr.NodeIterator)1 Property (javax.jcr.Property)1 PropertyIterator (javax.jcr.PropertyIterator)1