예제 #1
0
  public void testGetChildAPI() {

    Node<Object, Object> rootNode = cache.getRoot();

    // creates a Node<Object, Object> with fqn /a/b/c
    Node childA = rootNode.addChild(A);
    childA.addChild(B).addChild(C);

    rootNode.getChild(A).put("key", "value");
    rootNode.getChild(A).getChild(B).put("key", "value");
    rootNode.getChild(A).getChild(B).getChild(C).put("key", "value");

    assertEquals("value", rootNode.getChild(A).get("key"));
    assertEquals("value", rootNode.getChild(A).getChild(B).get("key"));
    assertEquals("value", rootNode.getChild(A).getChild(B).getChild(C).get("key"));

    assertNull(rootNode.getChild(Fqn.fromElements("nonexistent")));
  }
예제 #2
0
  /** 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()));
  }