HierarchicalDirectedGraphImpl graph = new HierarchicalDirectedGraphImpl(dhns, dhns.getGraphStructure().getMainView());
TreeStructure treeStructure = dhns.getGraphStructure().getMainView().getStructure();
GraphFactoryImpl factory = dhns.factory();
for (int i = 0; i < 10; i++) {
Node node = factory.newNode();
node.getNodeData().setLabel("Node " + i);
graph.addNode(node);
System.out.println("Node " + i + " added. Id = " + node.getId());
}
graph.readLock();
//Test
assertEquals("root size", 11, treeStructure.getTreeSize());
assertEquals("graph size", 10, graph.getNodeCount());
for (int i = 0; i < 10; i++) {
AbstractNode n = treeStructure.getNodeAt(i);
assertEquals("AbstractNode pre", i, n.getPre());
assertEquals("AbstractNode id", i, n.getId());
assertEquals("AbstractNode enabled", i > 0, n.isEnabled());
assertEquals("AbstractNode avl node", i, n.avlNode.getIndex());
if (n.avlNode.next() != null) {
assertEquals("AbstractNode next", treeStructure.getNodeAt(i + 1).avlNode, n.avlNode.next());
}
if (n.avlNode.previous() != null) {
assertEquals("AbstractNode previous", treeStructure.getNodeAt(i - 1).avlNode, n.avlNode.previous());
}
}
int i = 1;
for (Node node : graph.getNodes()) {
assertEquals("node iterator", i, node.getId());
i++;
}
graph.readUnlock();
}