public void testPutData() {

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

    assertTrue(rootNode.getData().isEmpty());

    Map<Object, Object> map = new HashMap<Object, Object>();
    map.put("k1", "v1");
    map.put("k2", "v2");

    rootNode.putAll(map);

    assertEquals(2, rootNode.getData().size());
    assertEquals("v1", rootNode.get("k1"));
    assertEquals("v2", rootNode.get("k2"));

    map.clear();
    map.put("k3", "v3");

    rootNode.putAll(map);
    assertEquals(3, rootNode.getData().size());
    assertEquals("v1", rootNode.get("k1"));
    assertEquals("v2", rootNode.get("k2"));
    assertEquals("v3", rootNode.get("k3"));

    map.clear();
    map.put("k4", "v4");
    map.put("k5", "v5");

    rootNode.replaceAll(map);
    assertEquals(2, rootNode.getData().size());
    assertEquals("v4", rootNode.get("k4"));
    assertEquals("v5", rootNode.get("k5"));
  }
  public void testClearingDataTx() throws Exception {

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

    tm.begin();
    rootNode.put("k", "v");
    rootNode.put("k2", "v2");
    assertEquals(2, rootNode.getKeys().size());
    rootNode.clearData();
    assertEquals(0, rootNode.getKeys().size());
    assertTrue(rootNode.getData().isEmpty());
    tm.commit();
    assertTrue(rootNode.getData().isEmpty());
  }
  public void testDefensiveCopyOfData() {

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

    rootNode.put("key", "value");
    Map<Object, Object> data = rootNode.getData();
    Set<Object> keys = rootNode.getKeys();

    assert keys.size() == 1;
    assert keys.contains("key");

    assert data.size() == 1;
    assert data.containsKey("key");

    // now change stuff.

    rootNode.put("key2", "value2");

    // assert that the collections we initially got have not changed.
    assert keys.size() == 1;
    assert keys.contains("key");

    assert data.size() == 1;
    assert data.containsKey("key");
  }
  public void testClearingData() {

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

    rootNode.put("k", "v");
    rootNode.put("k2", "v2");
    assertEquals(2, rootNode.getKeys().size());
    rootNode.clearData();
    assertEquals(0, rootNode.getKeys().size());
    assertTrue(rootNode.getData().isEmpty());
  }
  public void testImmutabilityOfData() {

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

    rootNode.put("key", "value");
    Map<Object, Object> m = rootNode.getData();
    try {
      m.put("x", "y");
      fail("Map should be immutable!!");
    } catch (Exception e) {
      // expected
    }

    try {
      rootNode.getKeys().add(new Object());
      fail("Key set should be immutable");
    } catch (Exception e) {
      // expected
    }
  }