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