Ejemplo n.º 1
0
  public void testDefensiveCopyOfChildren() {

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

    Fqn childFqn = Fqn.fromString("/child");
    rootNode.addChild(childFqn).put("k", "v");
    Set<Node<Object, Object>> children = rootNode.getChildren();
    Set<Object> childrenNames = rootNode.getChildrenNames();

    assert childrenNames.size() == 1;
    assert childrenNames.contains(childFqn.getLastElement());

    assert children.size() == 1;
    assert children.iterator().next().getFqn().equals(childFqn);

    // now change stuff.

    rootNode.addChild(Fqn.fromString("/child2"));

    // assert that the collections we initially got have not changed.
    assert childrenNames.size() == 1;
    assert childrenNames.contains(childFqn.getLastElement());

    assert children.size() == 1;
    assert children.iterator().next().getFqn().equals(childFqn);
  }
Ejemplo n.º 2
0
  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());
  }