// Iterate over each subgraph. Note that because each location should have a path, the path can be used
// to ensure the structure matches.
Iterator<SubgraphNode> iter1 = subgraph1.iterator();
Iterator<SubgraphNode> iter2 = subgraph2.iterator();
while (iter1.hasNext() && iter2.hasNext()) {
Node node1 = iter1.next();
Node node2 = iter2.next();
assertThat(node1, is(notNullValue()));
assertThat(node2, is(notNullValue()));
// Each node should have equivalent paths ..
assertThat(node1.getLocation().hasPath(), is(true));
assertThat(node2.getLocation().hasPath(), is(true));
if (pathsShouldMatch) {
assertThat(node1.getLocation().getPath(), is(node2.getLocation().getPath()));
} else {
Path relativeNode1 = node1.getLocation().getPath().relativeTo(rootPath1);
Path relativeNode2 = node2.getLocation().getPath().relativeTo(rootPath2);
assertThat(relativeNode1, is(relativeNode2));
}
// Each node should have the same Identification properties ...
if (idPropertiesShouldMatch) {
assertThat(node1.getLocation().getIdProperties(), is(node2.getLocation().getIdProperties()));
}
// Do not compare the workspace name.
// Each node should have the same properties (excluding any identification properties) ...
Map<Name, Property> properties1 = new HashMap<Name, Property>(node1.getPropertiesByName());
Map<Name, Property> properties2 = new HashMap<Name, Property>(node2.getPropertiesByName());
if (!idPropertiesShouldMatch) {
for (Property idProperty : node1.getLocation().getIdProperties()) {
properties1.remove(idProperty.getName());
}
for (Property idProperty : node2.getLocation().getIdProperties()) {
properties2.remove(idProperty.getName());
}
}
assertThat(properties1, is(properties2));
// Each node should have the same children. We can check this, tho this will be enforced when comparing paths ...
assertThat(node1.getChildrenSegments(), is(node2.getChildrenSegments()));
}
// There should be no more nodes in either iterator ...
assertThat(iter1.hasNext(), is(false));
assertThat(iter2.hasNext(), is(false));