@Test
public void testView() {
DhnsGraphController controller = new DhnsGraphController();
Dhns dhns = new Dhns(controller, null);
HierarchicalGraph graph = new HierarchicalDirectedGraphImpl(dhns, dhns.getGraphStructure().getMainView());
TreeStructure treeStructure = dhns.getGraphStructure().getMainView().getStructure();
GraphFactoryImpl factory = dhns.factory();
//Nodes
for (int i = 0; i < 5; i++) {
Node node = factory.newNode();
node.getNodeData().setLabel("Node " + i);
graph.addNode(node);
}
for (Node n : graph.getTopNodes().toArray()) {
Node newC = factory.newNode();
graph.addNode(newC, n);
}
//treeStructure.showTreeAsTable();
//Test getNodes()
for (Node n : graph.getNodes()) {
assertEquals(1, graph.getChildrenCount(n));
}
//Test isInView
for (Node n : graph.getNodes()) {
assertTrue(graph.isInView(n));
assertFalse(graph.isInView(graph.getChildren(n).toArray()[0]));
}
//Test resetView
//treeStructure.showTreeAsTable();
graph.resetViewToLeaves();
for (Node n : graph.getNodes()) {
assertEquals(1, graph.getLevel(n));
assertFalse(graph.isInView(graph.getParent(n)));
}
graph.resetViewToTopNodes();
for (Node n : graph.getNodes()) {
assertEquals(0, graph.getLevel(n));
}
graph.resetViewToLevel(1);
for (Node n : graph.getNodes()) {
assertEquals(1, graph.getLevel(n));
assertFalse(graph.isInView(graph.getParent(n)));
}
for (Node n : graph.getNodes(1).toArray()) {
graph.removeFromGroup(n);
}
//treeStructure.showTreeAsTable();
try {
checkHierarchy(treeStructure);