X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fsal%2Fyang-prototype%2Fyang%2Fyang-data-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fyang%2Fdata%2Fimpl%2FNodeModificationBuilderImplTest.java;h=5f4e482bcac59783398388a915a174d223eacc1b;hp=2df397a9ed9058fbcfcdfbf7dd2148ccdeca9864;hb=39b426fb075e8690911802f70aceb865cc83715d;hpb=9d0e5ef647eb242f7750e30482b403676f56c682 diff --git a/opendaylight/sal/yang-prototype/yang/yang-data-impl/src/test/java/org/opendaylight/controller/yang/data/impl/NodeModificationBuilderImplTest.java b/opendaylight/sal/yang-prototype/yang/yang-data-impl/src/test/java/org/opendaylight/controller/yang/data/impl/NodeModificationBuilderImplTest.java old mode 100755 new mode 100644 index 2df397a9ed..5f4e482bca --- a/opendaylight/sal/yang-prototype/yang/yang-data-impl/src/test/java/org/opendaylight/controller/yang/data/impl/NodeModificationBuilderImplTest.java +++ b/opendaylight/sal/yang-prototype/yang/yang-data-impl/src/test/java/org/opendaylight/controller/yang/data/impl/NodeModificationBuilderImplTest.java @@ -18,8 +18,11 @@ import org.opendaylight.controller.yang.common.QName; import org.opendaylight.controller.yang.data.api.CompositeNode; import org.opendaylight.controller.yang.data.api.MutableCompositeNode; import org.opendaylight.controller.yang.data.api.MutableSimpleNode; +import org.opendaylight.controller.yang.data.api.Node; import org.opendaylight.controller.yang.data.api.SimpleNode; import org.opendaylight.controller.yang.model.api.SchemaContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.w3c.dom.Document; /** @@ -27,12 +30,28 @@ import org.w3c.dom.Document; * */ public class NodeModificationBuilderImplTest { + + private static final Logger LOG = LoggerFactory + .getLogger(NodeModificationBuilderImplTest.class); private SchemaContext schemaCtx; private QName qName; private CompositeNode network; private NodeModificationBuilderImpl nodeModificationBuilder; + private String ns; + + /** + * @throws Exception + */ + private void dumpResult() throws Exception { + CompositeNode diffTree = nodeModificationBuilder.buildDiffTree(); + CompositeNode diffTreeImmutable = NodeFactory.copyDeepAsImmutable(diffTree, null); + + Document diffShadow = NodeUtils.buildShadowDomTree(diffTreeImmutable); + NodeHelper.dumpDoc(diffShadow, System.out); + } + /** * prepare schemaContext * @throws Exception @@ -41,14 +60,130 @@ public class NodeModificationBuilderImplTest { public void setUp() throws Exception { schemaCtx = NodeHelper.loadSchemaContext(); + ns = "urn:opendaylight:controller:network"; qName = new QName( - new URI("urn:opendaylight:controller:network"), + new URI(ns), new Date(1369000800000L), "topos"); network = NodeHelper.buildTestConfigTree(qName); nodeModificationBuilder = new NodeModificationBuilderImpl(network, schemaCtx); } + /** + * Test method for + * {@link org.opendaylight.controller.yang.data.impl.NodeModificationBuilderImpl#getMutableEquivalent(org.opendaylight.controller.yang.data.api.Node)} + * . + */ + @Test + public void testGetMutableEquivalent() { + MutableCompositeNode rootMutable = (MutableCompositeNode) + nodeModificationBuilder.getMutableEquivalent(network); + + CompositeNode topologies = network.getCompositesByName("topologies").iterator().next(); + Node mutableEquivalent = nodeModificationBuilder.getMutableEquivalent(topologies); + CompositeNode topologiesMutable = rootMutable.getCompositesByName("topologies").iterator().next(); + + Assert.assertSame(topologiesMutable, mutableEquivalent); + } + + /** + * Test method for + * {@link org.opendaylight.controller.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()} + * . + * @throws Exception + */ + @Test + public void testBuildDiffTreeAddSimple() throws Exception { + LOG.debug("testBuildDiffTreeAddSimple"); + Document networkShadow = NodeUtils.buildShadowDomTree(network); + CompositeNode needle = NodeUtils.findNodeByXpath(networkShadow, + NodeHelper.AddNamespaceToPattern( + "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]", ns)); + + MutableCompositeNode mutableParent = (MutableCompositeNode) + nodeModificationBuilder.getMutableEquivalent(needle); + + MutableSimpleNode newMutable = NodeFactory.createMutableSimpleNode( + new QName(needle.getNodeType(), "anySubNode"), mutableParent, "42", null, null); + + nodeModificationBuilder.addNode(newMutable); + dumpResult(); + } + + /** + * Test method for + * {@link org.opendaylight.controller.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()} + * . + * @throws Exception + */ + @Test + public void testBuildDiffTreeAddComposite() throws Exception { + LOG.debug("testBuildDiffTreeAddComposite"); + Document networkShadow = NodeUtils.buildShadowDomTree(network); + CompositeNode needle = NodeUtils.findNodeByXpath(networkShadow, + NodeHelper.AddNamespaceToPattern( + "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]", ns)); + + MutableCompositeNode mutableParent = (MutableCompositeNode) + nodeModificationBuilder.getMutableEquivalent(needle); + + MutableSimpleNode newMutable = NodeFactory.createMutableSimpleNode( + new QName(needle.getNodeType(), "anySubNode"), null, "42", null, null); + + MutableCompositeNode newMutableCom = NodeFactory.createMutableCompositeNode( + new QName(needle.getNodeType(), "anySubNode"), mutableParent, + NodeUtils.buildChildrenList(newMutable), null, null); + NodeUtils.fixChildrenRelation(newMutableCom); + newMutableCom.init(); + + nodeModificationBuilder.addNode(newMutableCom); + dumpResult(); + } + + /** + * Test method for + * {@link org.opendaylight.controller.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()} + * . + * @throws Exception + */ + @Test + public void testBuildDiffTreeDeleteComposite() throws Exception { + LOG.debug("testBuildDiffTreeDeleteComposite"); + Document networkShadow = NodeUtils.buildShadowDomTree(network); + SimpleNode needle = NodeUtils.findNodeByXpath(networkShadow, + NodeHelper.AddNamespaceToPattern( + "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns)); + + @SuppressWarnings("unchecked") + MutableSimpleNode mutableNeedle = (MutableSimpleNode) + nodeModificationBuilder.getMutableEquivalent(needle); + + nodeModificationBuilder.deleteNode(mutableNeedle.getParent().asMutable()); + dumpResult(); + } + + /** + * Test method for + * {@link org.opendaylight.controller.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()} + * . + * @throws Exception + */ + @Test + public void testBuildDiffTreeDeleteSimple() throws Exception { + LOG.debug("testBuildDiffTreeDeleteSimple"); + Document networkShadow = NodeUtils.buildShadowDomTree(network); + SimpleNode needle = NodeUtils.findNodeByXpath(networkShadow, + NodeHelper.AddNamespaceToPattern( + "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns)); + + @SuppressWarnings("unchecked") + MutableSimpleNode mutableNeedle = (MutableSimpleNode) + nodeModificationBuilder.getMutableEquivalent(needle); + + nodeModificationBuilder.deleteNode(mutableNeedle); + dumpResult(); + } + /** * Test method for * {@link org.opendaylight.controller.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()} @@ -56,37 +191,111 @@ public class NodeModificationBuilderImplTest { * @throws Exception */ @Test - public void testBuildDiffTree() throws Exception { + public void testBuildDiffTreeMerge() throws Exception { + LOG.debug("testBuildDiffTreeMerge"); Document networkShadow = NodeUtils.buildShadowDomTree(network); - SimpleNode needle = NodeUtils.findNodeByXpath(networkShadow, - "//node[node-id='nodeId_19']//termination-point[2]/tp-id"); + SimpleNode needle = NodeUtils.findNodeByXpath(networkShadow, + NodeHelper.AddNamespaceToPattern( + "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns)); @SuppressWarnings("unchecked") MutableSimpleNode mutableNeedle = (MutableSimpleNode) nodeModificationBuilder.getMutableEquivalent(needle); mutableNeedle.setValue("tpId_18x"); - nodeModificationBuilder.replaceNode(mutableNeedle); - CompositeNode diffTree = nodeModificationBuilder.buildDiffTree(); + nodeModificationBuilder.mergeNode(mutableNeedle.getParent().asMutable()); + dumpResult(); + } + + /** + * Test method for + * {@link org.opendaylight.controller.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()} + * . + * @throws Exception + */ + @Test + public void testBuildDiffTreeRemoveComposite() throws Exception { + LOG.debug("testBuildDiffTreeRemoveComposite"); + Document networkShadow = NodeUtils.buildShadowDomTree(network); + SimpleNode needle = NodeUtils.findNodeByXpath(networkShadow, + NodeHelper.AddNamespaceToPattern( + "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns)); - Document diffShadow = NodeUtils.buildShadowDomTree(diffTree); - NodeHelper.dumpDoc(diffShadow, System.out); + @SuppressWarnings("unchecked") + MutableSimpleNode mutableNeedle = (MutableSimpleNode) + nodeModificationBuilder.getMutableEquivalent(needle); + + nodeModificationBuilder.removeNode(mutableNeedle.getParent().asMutable()); + dumpResult(); } /** * Test method for - * {@link org.opendaylight.controller.yang.data.impl.NodeModificationBuilderImpl#getMutableEquivalent(org.opendaylight.controller.yang.data.api.Node)} + * {@link org.opendaylight.controller.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()} * . + * @throws Exception */ @Test - public void testGetMutableEquivalent() { - MutableCompositeNode rootMutable = (MutableCompositeNode) - nodeModificationBuilder.getMutableEquivalent(network); + public void testBuildDiffTreeRemoveSimple() throws Exception { + LOG.debug("testBuildDiffTreeRemoveSimple"); + Document networkShadow = NodeUtils.buildShadowDomTree(network); + SimpleNode needle = NodeUtils.findNodeByXpath(networkShadow, + NodeHelper.AddNamespaceToPattern( + "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns)); - CompositeNode topologies = network.getCompositesByName("topologies").iterator().next(); - CompositeNode topologiesMutable = rootMutable.getCompositesByName("topologies").iterator().next(); + @SuppressWarnings("unchecked") + MutableSimpleNode mutableNeedle = (MutableSimpleNode) + nodeModificationBuilder.getMutableEquivalent(needle); + + nodeModificationBuilder.removeNode(mutableNeedle); + dumpResult(); + } + + /** + * Test method for + * {@link org.opendaylight.controller.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()} + * . + * @throws Exception + */ + @Test + public void testBuildDiffTreeReplaceComposite() throws Exception { + LOG.debug("testBuildDiffTreeReplaceComposite"); + Document networkShadow = NodeUtils.buildShadowDomTree(network); + SimpleNode needle = NodeUtils.findNodeByXpath(networkShadow, + NodeHelper.AddNamespaceToPattern( + "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns)); + + @SuppressWarnings("unchecked") + MutableSimpleNode mutableNeedle = (MutableSimpleNode) + nodeModificationBuilder.getMutableEquivalent(needle); + + mutableNeedle.setValue("tpId_18x"); + nodeModificationBuilder.replaceNode(mutableNeedle.getParent().asMutable()); + dumpResult(); + } + + /** + * Test method for + * {@link org.opendaylight.controller.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()} + * . + * @throws Exception + */ + @Test + public void testBuildDiffTreeReplaceSimple() throws Exception { + LOG.debug("testBuildDiffTreeReplaceSimple"); + Document networkShadow = NodeUtils.buildShadowDomTree(network); + SimpleNode needle = NodeUtils.findNodeByXpath(networkShadow, + NodeHelper.AddNamespaceToPattern( + "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns)); - Assert.assertSame(topologiesMutable, nodeModificationBuilder.getMutableEquivalent(topologies)); + @SuppressWarnings("unchecked") + MutableSimpleNode mutableNeedle = (MutableSimpleNode) + nodeModificationBuilder.getMutableEquivalent(needle); + + mutableNeedle.setValue("tpId_18x"); + nodeModificationBuilder.replaceNode(mutableNeedle); + dumpResult(); } + }