/** Remember, Fqns are relative!! */ public void testParentsAndChildren() { Node<Object, Object> rootNode = cache.getRoot(); Node<Object, Object> nodeA = rootNode.addChild(A); Node<Object, Object> nodeB = nodeA.addChild(B); Node<Object, Object> nodeC = nodeA.addChild(C); Node<Object, Object> nodeD = rootNode.addChild(D); assertEquals(rootNode, nodeA.getParent()); assertEquals(nodeA, nodeB.getParent()); assertEquals(nodeA, nodeC.getParent()); assertEquals(rootNode, nodeD.getParent()); assertTrue(rootNode.hasChild(A)); assertFalse(rootNode.hasChild(B)); assertFalse(rootNode.hasChild(C)); assertTrue(rootNode.hasChild(D)); assertTrue(nodeA.hasChild(B)); assertTrue(nodeA.hasChild(C)); assertEquals(nodeA, rootNode.getChild(A)); assertEquals(nodeD, rootNode.getChild(D)); assertEquals(nodeB, nodeA.getChild(B)); assertEquals(nodeC, nodeA.getChild(C)); assertTrue(nodeA.getChildren().contains(nodeB)); assertTrue(nodeA.getChildren().contains(nodeC)); assertEquals(2, nodeA.getChildren().size()); assertTrue(rootNode.getChildren().contains(nodeA)); assertTrue(rootNode.getChildren().contains(nodeD)); assertEquals(2, rootNode.getChildren().size()); assertEquals(true, rootNode.removeChild(A)); assertFalse(rootNode.getChildren().contains(nodeA)); assertTrue(rootNode.getChildren().contains(nodeD)); assertEquals(1, rootNode.getChildren().size()); assertEquals("double remove", false, rootNode.removeChild(A)); assertEquals("double remove", false, rootNode.removeChild(A.getLastElement())); }
public void testGetChildrenNames() throws Exception { Node<Object, Object> rootNode = cache.getRoot(); rootNode.addChild(A).put("k", "v"); rootNode.addChild(B).put("k", "v"); Set<Object> childrenNames = new HashSet<Object>(); childrenNames.add(A.getLastElement()); childrenNames.add(B.getLastElement()); assertEquals(childrenNames, rootNode.getChildrenNames()); // now delete a child, within a tx tm.begin(); rootNode.removeChild(B); assertFalse(rootNode.hasChild(B)); childrenNames.remove(B.getLastElement()); assertEquals(childrenNames, rootNode.getChildrenNames()); tm.commit(); assertEquals(childrenNames, rootNode.getChildrenNames()); }