}
}
@Test
public void shouldReadSubgraphStartingAtRootAndWithMaximumDepthOfThree() {
Subgraph subgraph = graph.getSubgraphOfDepth(3).at("/");
assertThat(subgraph, is(notNullValue()));
// Verify that the root node is the same as getting it directly ...
Node root = subgraph.getRoot();
assertSameNode(root, graph.getNodeAt("/"));
// Verify the first-level children ...
List<Location> children = graph.getChildren().of("/");
assertThat(children, is(notNullValue()));
for (Location childLocation : children) {
// Verify the child in the subgraph matches the same node obtained directly from the graph ...
Node child = subgraph.getNode(childLocation);
assertSameNode(child, graph.getNodeAt(childLocation));
// Now get the second-level children ...
List<Location> grandChildren = graph.getChildren().of(childLocation);
assertThat(grandChildren, is(notNullValue()));
for (Location grandchildLocation : grandChildren) {
// Verify the grandchild in the subgraph matches the same node obtained directly from the graph ...
Node grandchild = subgraph.getNode(grandchildLocation);
assertSameNode(grandchild, graph.getNodeAt(grandchildLocation));
// The subgraph should contain the children locations and properties for the grandchildren.
// However, the subgraph should not a node for the children of the grandchildren ...
for (Location greatGrandchild : grandchild.getChildren()) {
assertThat(subgraph.getNode(greatGrandchild), is(nullValue()));
}
}
}
}