@Test public void testAddRemoveNewChildAndStore() 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 item.removeChild(newChild); // 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 testRemoveChild() throws Exception { // GIVEN JcrNodeAdapter item = new JcrNodeAdapter(baseNode); // Create a child node Node child = baseNode.addNode("child"); JcrNodeAdapter childItem = new JcrNodeAdapter(child); item.addChild(childItem); // Create one new child Item JcrNewNodeAdapter newChild = new JcrNewNodeAdapter(baseNode, "mgnl:content"); item.addChild(newChild); // WHEN boolean resBoolean = item.removeChild(childItem); // THEN Map<String, AbstractJcrNodeAdapter> res = item.getChildren(); assertEquals(true, resBoolean); assertEquals(1, res.size()); assertEquals(null, res.get(childItem.getNodeName())); assertEquals(newChild, res.get(newChild.getNodeName())); assertEquals(item, newChild.getParent()); Map<String, AbstractJcrNodeAdapter> resRemobed = item.getRemovedChildren(); assertEquals(1, resRemobed.size()); assertEquals(childItem, resRemobed.get(childItem.getNodeName())); }
@Test public void testAddChild() throws Exception { // GIVEN JcrNodeAdapter item = new JcrNodeAdapter(baseNode); // Create a child node Node child = baseNode.addNode("child"); JcrNodeAdapter childItem = new JcrNodeAdapter(child); item.addChild(childItem); // Create one new child Item JcrNewNodeAdapter newChild = new JcrNewNodeAdapter(baseNode, "mgnl:content"); item.addChild(newChild); // WHEN Map<String, AbstractJcrNodeAdapter> res = item.getChildren(); // THEN assertNotNull(res); assertEquals(2, res.size()); assertEquals(childItem, res.get(childItem.getNodeName())); assertEquals(item, childItem.getParent()); assertEquals(newChild, res.get(newChild.getNodeName())); assertEquals(item, newChild.getParent()); }