@Test
  public void testAddRemoveExistingChildAndStore() throws Exception {
    // GIVEN
    JcrNodeAdapter item = new JcrNodeAdapter(baseNode);
    // Add property to the Item
    DefaultProperty<String> property = new DefaultProperty<String>(String.class, "propertyValue");
    item.addItemProperty("propertyName", property);
    // Create one new child Item
    // Create a child node
    Node child = baseNode.addNode("childNode");
    JcrNodeAdapter childItem = new JcrNodeAdapter(child);
    item.addChild(childItem);
    assertEquals(true, baseNode.hasNode("childNode"));
    // Add property to the child Item
    DefaultProperty<String> childProperty =
        new DefaultProperty<String>(String.class, "childPropertyValue");
    childItem.addItemProperty("childPropertyName", childProperty);

    // WHEN
    item.removeChild(childItem);

    // THEN
    // Get node
    Node res = item.applyChanges();
    assertNotNull(res);
    assertEquals(baseNode, res);
    assertEquals(true, res.hasProperty("propertyName"));
    assertEquals("propertyValue", res.getProperty("propertyName").getValue().getString());
    assertEquals(false, res.hasNode("childNode"));
  }
  @Test
  public void testAddNewChildAndStore() throws Exception {
    // GIVEN
    JcrNodeAdapter item = new JcrNodeAdapter(baseNode);
    // Add property to the Item
    DefaultProperty<String> property = new DefaultProperty<String>(String.class, "propertyValue");
    item.addItemProperty("propertyName", property);
    // Create one new child Item
    JcrNewNodeAdapter newChild = new JcrNewNodeAdapter(baseNode, "mgnl:content", "childNode");
    item.addChild(newChild);
    // Add property to the child Item
    DefaultProperty<String> childProperty =
        new DefaultProperty<String>(String.class, "childPropertyValue");
    newChild.addItemProperty("childPropertyName", childProperty);

    // WHEN
    Node res = item.applyChanges();

    // THEN
    assertNotNull(res);
    assertEquals(baseNode, res);
    assertEquals(true, res.hasProperty("propertyName"));
    assertEquals("propertyValue", res.getProperty("propertyName").getValue().getString());
    assertEquals(true, res.hasNode("childNode"));
    assertEquals(true, res.getNode("childNode").hasProperty("childPropertyName"));
    assertEquals(
        "childPropertyValue",
        res.getNode("childNode").getProperty("childPropertyName").getValue().getString());
  }