[ONOS-7064] Yang Runtime support for Anydata code base
Change-Id: I6e3cde428e730b553b9b73700519bc749760148d
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestUtils.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestUtils.java
index 50acec5..f059e1f 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestUtils.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestUtils.java
@@ -60,7 +60,7 @@
public static final String L_NAME = "list";
public static final String LMNG = "yrt.Logistics-manager";
public static final String LMNG_N = "Logistics-manager";
-
+ public static final String TANY_NS = "yrt:list.test.anydata";
// Logger list is used for walker testing.
private static final List<String> LOGGER = new ArrayList<>();
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestYangSerializerContext.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestYangSerializerContext.java
index c2f8f0e..ef73cc1 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestYangSerializerContext.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestYangSerializerContext.java
@@ -30,10 +30,23 @@
*/
public class TestYangSerializerContext implements YangSerializerContext {
+ // Reference for YANG model registry
+ private DefaultYangModelRegistry reg;
+
+ /**
+ * Returns the YANG model registry.
+ *
+ * @return YANG model registry
+ */
+ public DefaultYangModelRegistry getRegistry() {
+ return reg;
+ }
+
@Override
public SchemaContext getContext() {
processSchemaRegistry();
- return registry();
+ reg = registry();
+ return reg;
}
@Override
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/YobAnydataTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/YobAnydataTest.java
new file mode 100644
index 0000000..75b1544
--- /dev/null
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/YobAnydataTest.java
@@ -0,0 +1,129 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.runtime.impl;
+
+import org.junit.Test;
+import org.onosproject.yang.gen.v1.yrtietfnetwork.rev20151208.yrtietfnetwork.networks.network.DefaultNode;
+import org.onosproject.yang.gen.v1.yrtietfnetwork.rev20151208.yrtietfnetwork.networks.network.Node;
+import org.onosproject.yang.gen.v1.yrtietfnetwork.rev20151208.yrtietfnetwork.networks.network.node.SupportingNode;
+import org.onosproject.yang.gen.v1.yrtnetworktopology.rev20151208.yrtnetworktopology.networks.network.augmentedndnetwork.DefaultLink;
+import org.onosproject.yang.gen.v1.yrtnetworktopology.rev20151208.yrtnetworktopology.networks.network.augmentedndnetwork.Link;
+import org.onosproject.yang.gen.v1.ytbaugmentfromanotherfile.rev20160826.ytbaugmentfromanotherfile.networks.network.node.augmentedndnode.terminationpoint.SupportingTerminationPoint;
+import org.onosproject.yang.gen.v11.anytest.rev20160624.anytest.DefaultC1;
+import org.onosproject.yang.gen.v11.anytest.rev20160624.anytest.c1.DefaultMydata2;
+import org.onosproject.yang.gen.v11.anytest.rev20160624.anytest.c1.Mydata2;
+import org.onosproject.yang.model.DataNode;
+import org.onosproject.yang.model.DefaultResourceData;
+import org.onosproject.yang.model.ModelObject;
+import org.onosproject.yang.model.ModelObjectData;
+import org.onosproject.yang.model.ResourceData;
+
+import java.util.List;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.onosproject.yang.runtime.SerializerHelper.addDataNode;
+import static org.onosproject.yang.runtime.SerializerHelper.exitDataNode;
+import static org.onosproject.yang.runtime.SerializerHelper.initializeDataNode;
+import static org.onosproject.yang.runtime.impl.TestUtils.IETFNS;
+import static org.onosproject.yang.runtime.impl.TestUtils.TANY_NS;
+
+/**
+ * Tests the YANG object building for the YANG data nodes based on the non
+ * schema augmented nodes.
+ */
+public class YobAnydataTest {
+ private static final String NW_TOPO_NAME_SPACE = "urn:ietf:params:xml:ns:yang:yrt-ietf-network-topology";
+ TestYangSerializerContext context = new TestYangSerializerContext();
+ DataNode.Builder dBlr;
+ String value;
+
+ public DataNode buildDnForAnydata() {
+ dBlr = initializeDataNode(context);
+ value = null;
+ // Adding container c1
+ dBlr = addDataNode(dBlr, "c1", TANY_NS, value, null);
+ // Adding anydata container
+ dBlr = addDataNode(dBlr, "mydata2", TANY_NS, value, null);
+ context.getRegistry().registerAnydataSchema(Mydata2.class, Node.class);
+ context.getRegistry().registerAnydataSchema(Mydata2.class, DefaultLink.class);
+ context.getRegistry().registerAnydataSchema(Mydata2.class, SupportingTerminationPoint.class);
+
+ // Adding list inside anydata container
+ dBlr = addDataNode(dBlr, "link", NW_TOPO_NAME_SPACE, value, null);
+ value = "link-id";
+ dBlr = addDataNode(dBlr, "link-id", NW_TOPO_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+ value = null;
+ dBlr = addDataNode(dBlr, "source", NW_TOPO_NAME_SPACE, value, null);
+ value = "source-node";
+ dBlr = addDataNode(dBlr, "source-node", NW_TOPO_NAME_SPACE, value, null);
+ dBlr = exitDataNode(dBlr);
+ dBlr = exitDataNode(dBlr); // exit source
+ dBlr = exitDataNode(dBlr); // exit link
+
+ // Adding list inside anydata container
+ value = null;
+ dBlr = addDataNode(dBlr, "node", IETFNS, value, null);
+ // Adding key element node-id
+ value = "node1";
+ dBlr = addDataNode(dBlr, "node-id", null, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = null;
+ // Adding list inside list
+ dBlr = addDataNode(dBlr, "supporting-node", null, value, null);
+ // Adding key element network-ref
+ value = "network3";
+ dBlr = addDataNode(dBlr, "network-ref", null, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "network4";
+ // Adding key element node-ref
+ dBlr = addDataNode(dBlr, "node-ref", null, value, null);
+ dBlr = exitDataNode(dBlr);
+ dBlr = exitDataNode(dBlr);
+ dBlr = exitDataNode(dBlr);
+ dBlr = exitDataNode(dBlr);
+ dBlr = exitDataNode(dBlr);
+ return dBlr.build();
+ }
+
+
+ @Test
+ public void anydataTest() {
+ DataNode dataNode = buildDnForAnydata();
+ ResourceData data = DefaultResourceData.builder()
+ .addDataNode(dataNode).build();
+ DefaultYobBuilder builder = new DefaultYobBuilder(context.getRegistry());
+ ModelObjectData modelObjectData = builder.getYangObject(data);
+ List<ModelObject> modelObjectList = modelObjectData.modelObjects();
+ ModelObject modelObject = modelObjectList.get(0);
+ DefaultC1 c1 = ((DefaultC1) modelObject);
+ DefaultMydata2 mydata2 = ((DefaultMydata2) c1.mydata2());
+
+ Link link = mydata2.anydata(DefaultLink.class);
+ assertThat(link.linkId().toString(), is("link-id"));
+ assertThat(link.source().sourceNode().toString(), is("source-node"));
+
+ Node node = mydata2.anydata(DefaultNode.class);
+ assertThat(node.nodeId().toString(), is("node1"));
+ SupportingNode snode = (SupportingNode) node.supportingNode().get(0);
+ assertThat(snode.networkRef().toString(), is("network3"));
+ assertThat(snode.nodeRef().toString(), is("network4"));
+ }
+}
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/YtbAnydataTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/YtbAnydataTest.java
new file mode 100644
index 0000000..eef9de7
--- /dev/null
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/YtbAnydataTest.java
@@ -0,0 +1,168 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.runtime.impl;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.onosproject.yang.gen.v1.yrtietfinettypes.rev20130715.yrtietfinettypes.Uri;
+import org.onosproject.yang.gen.v1.yrtietfnetwork.rev20151208.yrtietfnetwork.NetworkId;
+import org.onosproject.yang.gen.v1.yrtietfnetwork.rev20151208.yrtietfnetwork.NodeId;
+import org.onosproject.yang.gen.v1.yrtietfnetwork.rev20151208.yrtietfnetwork.networks.network.DefaultNode;
+import org.onosproject.yang.gen.v1.yrtietfnetwork.rev20151208.yrtietfnetwork.networks.network.Node;
+import org.onosproject.yang.gen.v1.yrtietfnetwork.rev20151208.yrtietfnetwork.networks.network.node.DefaultSupportingNode;
+import org.onosproject.yang.gen.v1.yrtnetworktopology.rev20151208.yrtnetworktopology.LinkId;
+import org.onosproject.yang.gen.v1.yrtnetworktopology.rev20151208.yrtnetworktopology.networks.network.augmentedndnetwork.DefaultLink;
+import org.onosproject.yang.gen.v1.yrtnetworktopology.rev20151208.yrtnetworktopology.networks.network.augmentedndnetwork.Link;
+import org.onosproject.yang.gen.v1.yrtnetworktopology.rev20151208.yrtnetworktopology.networks.network.augmentedndnetwork.link.DefaultSource;
+import org.onosproject.yang.gen.v11.anytest.rev20160624.anytest.DefaultC1;
+import org.onosproject.yang.gen.v11.anytest.rev20160624.anytest.c1.DefaultMydata2;
+import org.onosproject.yang.gen.v11.anytest.rev20160624.anytest.c1.Mydata2;
+import org.onosproject.yang.model.DataNode;
+import org.onosproject.yang.model.DefaultModelObjectData.Builder;
+import org.onosproject.yang.model.InnerNode;
+import org.onosproject.yang.model.ModelObjectId;
+import org.onosproject.yang.model.NodeKey;
+import org.onosproject.yang.model.ResourceData;
+import org.onosproject.yang.model.ResourceId;
+import org.onosproject.yang.model.SchemaId;
+
+import java.util.Iterator;
+import java.util.List;
+
+import static org.onosproject.yang.model.DataNode.Type.MULTI_INSTANCE_NODE;
+import static org.onosproject.yang.model.DataNode.Type.SINGLE_INSTANCE_LEAF_VALUE_NODE;
+import static org.onosproject.yang.model.DataNode.Type.SINGLE_INSTANCE_NODE;
+import static org.onosproject.yang.runtime.impl.MockYangSchemaNodeProvider.processSchemaRegistry;
+import static org.onosproject.yang.runtime.impl.MockYangSchemaNodeProvider.registry;
+import static org.onosproject.yang.runtime.impl.TestUtils.IETFNS;
+import static org.onosproject.yang.runtime.impl.TestUtils.TANY_NS;
+import static org.onosproject.yang.runtime.impl.TestUtils.TOPONS;
+import static org.onosproject.yang.runtime.impl.TestUtils.validateDataNode;
+
+/**
+ * Unit test cases for resource id conversion from model object id.
+ */
+public class YtbAnydataTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+ private ResourceData rscData;
+ private DefaultDataTreeBuilder treeBuilder;
+ private ResourceId id;
+ private List<NodeKey> keys;
+ private SchemaId sid;
+ private ModelObjectId mid;
+ private Builder data;
+ DefaultYangModelRegistry reg;
+
+ /**
+ * Prior setup for each UT.
+ */
+ @Before
+ public void setUp() {
+ processSchemaRegistry();
+ reg = registry();
+ treeBuilder = new DefaultDataTreeBuilder(reg);
+ }
+
+
+ /**
+ * Processes anydata with augmented node as child.
+ */
+ @Test
+ public void processAnydataTest() {
+
+ reg.registerAnydataSchema(Mydata2.class, Node.class);
+ reg.registerAnydataSchema(Mydata2.class, Link.class);
+ DefaultC1 c1 = new DefaultC1();
+ DefaultMydata2 mydata2 = new DefaultMydata2();
+
+ // link
+ DefaultLink link = new DefaultLink();
+ link.linkId(new LinkId(new Uri("link-id")));
+ DefaultSource source = new DefaultSource();
+ source.sourceNode(new NodeId(new Uri("source-node")));
+ link.source(source);
+
+ //node
+ DefaultNode node = new DefaultNode();
+ node.nodeId(new NodeId(new Uri("node1")));
+ DefaultSupportingNode sn = new DefaultSupportingNode();
+ sn.networkRef(new NetworkId(new Uri("network3")));
+ sn.nodeRef(new NodeId(new Uri("network4")));
+ node.addToSupportingNode(sn);
+ mydata2.addAnydata(link);
+ mydata2.addAnydata(node);
+
+ c1.mydata2(mydata2);
+ data = new Builder();
+ data.addModelObject(c1);
+ rscData = treeBuilder.getResourceData(data.build());
+
+ List<DataNode> nodes = rscData.dataNodes();
+ DataNode n = nodes.get(0);
+ validateDataNode(n, "c1", TANY_NS, SINGLE_INSTANCE_NODE,
+ true, null);
+ n = ((InnerNode) n).childNodes().values().iterator().next();
+ validateDataNode(n, "mydata2", TANY_NS, SINGLE_INSTANCE_NODE,
+ true, null);
+ Iterator<DataNode> it = ((InnerNode) n).childNodes().values().iterator();
+
+ // node validation
+ n = it.next();
+ validateDataNode(n, "node", IETFNS, MULTI_INSTANCE_NODE,
+ true, null);
+
+ Iterator<DataNode> it1 = ((InnerNode) n).childNodes().values().iterator();
+ n = it1.next();
+ validateDataNode(n, "node-id", IETFNS, SINGLE_INSTANCE_LEAF_VALUE_NODE,
+ false, "node1");
+ n = it1.next();
+ validateDataNode(n, "supporting-node", IETFNS, MULTI_INSTANCE_NODE,
+ true, null);
+
+ Iterator<DataNode> it2 = ((InnerNode) n).childNodes().values()
+ .iterator();
+ n = it2.next();
+ validateDataNode(n, "network-ref", IETFNS, SINGLE_INSTANCE_LEAF_VALUE_NODE,
+ false, "network3");
+ n = it2.next();
+ validateDataNode(n, "node-ref", IETFNS, SINGLE_INSTANCE_LEAF_VALUE_NODE,
+ false, "network4");
+
+ //link validation
+ n = it.next();
+ validateDataNode(n, "link", TOPONS, MULTI_INSTANCE_NODE,
+ true, null);
+
+ it1 = ((InnerNode) n).childNodes().values().iterator();
+ n = it1.next();
+ validateDataNode(n, "link-id", TOPONS, SINGLE_INSTANCE_LEAF_VALUE_NODE,
+ false, "link-id");
+ n = it1.next();
+ validateDataNode(n, "source", TOPONS, SINGLE_INSTANCE_NODE,
+ true, null);
+
+ it2 = ((InnerNode) n).childNodes().values().iterator();
+ n = it2.next();
+ validateDataNode(n, "source-node", TOPONS,
+ SINGLE_INSTANCE_LEAF_VALUE_NODE,
+ false, "source-node");
+ }
+}
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AnydataNegativeScenarioTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AnydataNegativeScenarioTest.java
new file mode 100644
index 0000000..5ffbb8e
--- /dev/null
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AnydataNegativeScenarioTest.java
@@ -0,0 +1,118 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.runtime.impl.serializerhelper;
+
+import org.junit.Test;
+import org.onosproject.yang.gen.v1.check.check.List52Keys;
+import org.onosproject.yang.gen.v1.yrtietfnetwork.rev20151208.yrtietfnetwork.networks.network.Node;
+import org.onosproject.yang.gen.v11.listanydata.rev20160624.ListAnydata;
+import org.onosproject.yang.gen.v11.listanydata.rev20160624.ListAnydataOpParam;
+import org.onosproject.yang.gen.v11.listanydata.rev20160624.listanydata.Mydata;
+import org.onosproject.yang.model.DataNode;
+import org.onosproject.yang.runtime.impl.TestYangSerializerContext;
+
+import static org.junit.Assert.assertEquals;
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.INVAL_ANYDATA;
+import static org.onosproject.yang.runtime.impl.UtilsConstants.FMT_INV;
+
+/**
+ * Tests the serializer helper methods.
+ */
+public class AnydataNegativeScenarioTest {
+
+ TestYangSerializerContext context = new TestYangSerializerContext();
+
+ /*
+ * Reference for data node builder.
+ */
+ DataNode.Builder dBlr;
+
+ /**
+ * Test anydata add to data node negative test scenario when given
+ * referenced node is not of type anydata.
+ */
+ @Test
+ public void addToDataTest() {
+ boolean isExpOccurred = false;
+ context.getContext();
+ try {
+ context.getRegistry().registerAnydataSchema(Node.class, Node.class);
+ } catch (IllegalArgumentException e) {
+ isExpOccurred = true;
+ assertEquals(e.getMessage(), String.format(FMT_INV, Node.class));
+ }
+ assertEquals(isExpOccurred, true);
+ }
+
+ /**
+ * Test anydata add to data node negative test scenario when given
+ * referenced node module is not registered.
+ */
+ @Test
+ public void addToData2Test() {
+ boolean isExpOccurred = false;
+ context.getContext();
+ try {
+ context.getRegistry().registerAnydataSchema(Mydata.class,
+ ListAnydataOpParam.class);
+ } catch (IllegalArgumentException e) {
+ isExpOccurred = true;
+ assertEquals(e.getMessage(), String.format(
+ INVAL_ANYDATA, ListAnydataOpParam.class));
+ }
+ assertEquals(isExpOccurred, true);
+ }
+
+
+ /**
+ * Test anydata add to data node negative test scenario when given
+ * referenced node is not of type list/container.
+ */
+ @Test
+ public void addToData3Test() {
+ boolean isExpOccurred = false;
+ context.getContext();
+ try {
+ context.getRegistry().registerAnydataSchema(Mydata.class,
+ ListAnydata.class);
+ } catch (IllegalArgumentException e) {
+ isExpOccurred = true;
+ assertEquals(e.getMessage(), String.format(
+ INVAL_ANYDATA, ListAnydata.class));
+ }
+ assertEquals(isExpOccurred, true);
+ }
+
+ /**
+ * Test anydata add to data node negative test scenario when given
+ * referenced node is not of type list/container.
+ */
+ @Test
+ public void addToData4Test() {
+ boolean isExpOccurred = false;
+ context.getContext();
+ try {
+ context.getRegistry().registerAnydataSchema(Mydata.class,
+ List52Keys.class);
+ } catch (IllegalArgumentException e) {
+ isExpOccurred = true;
+ assertEquals(e.getMessage(), String.format(
+ INVAL_ANYDATA, List52Keys.class.getCanonicalName()));
+ }
+ assertEquals(isExpOccurred, true);
+ }
+}
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/IetfNetAnydataTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/IetfNetAnydataTest.java
new file mode 100644
index 0000000..8b9a9cd
--- /dev/null
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/IetfNetAnydataTest.java
@@ -0,0 +1,226 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.runtime.impl.serializerhelper;
+
+import org.junit.Test;
+import org.onosproject.yang.gen.v1.yrtietfnetwork.rev20151208.yrtietfnetwork.networks.network.Node;
+import org.onosproject.yang.gen.v1.yrtnetworktopology.rev20151208.yrtnetworktopology.networks.network.augmentedndnetwork.Link;
+import org.onosproject.yang.gen.v11.anytest.rev20160624.anytest.c1.Mydata2;
+import org.onosproject.yang.model.DataNode;
+import org.onosproject.yang.model.InnerNode;
+import org.onosproject.yang.model.KeyLeaf;
+import org.onosproject.yang.model.ListKey;
+import org.onosproject.yang.model.NodeKey;
+import org.onosproject.yang.model.ResourceId;
+import org.onosproject.yang.runtime.HelperContext;
+import org.onosproject.yang.runtime.impl.TestYangSerializerContext;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import static org.onosproject.yang.model.DataNode.Type.MULTI_INSTANCE_NODE;
+import static org.onosproject.yang.model.DataNode.Type.SINGLE_INSTANCE_LEAF_VALUE_NODE;
+import static org.onosproject.yang.model.DataNode.Type.SINGLE_INSTANCE_NODE;
+import static org.onosproject.yang.runtime.SerializerHelper.addDataNode;
+import static org.onosproject.yang.runtime.SerializerHelper.exitDataNode;
+import static org.onosproject.yang.runtime.SerializerHelper.initializeDataNode;
+import static org.onosproject.yang.runtime.impl.TestUtils.IETFNS;
+import static org.onosproject.yang.runtime.impl.TestUtils.TANY_NS;
+import static org.onosproject.yang.runtime.impl.TestUtils.TOPONS;
+import static org.onosproject.yang.runtime.impl.TestUtils.validateDataNode;
+import static org.onosproject.yang.runtime.impl.TestUtils.validateLeafDataNode;
+import static org.onosproject.yang.runtime.impl.TestUtils.walkINTree;
+
+/**
+ * Tests the serializer helper methods.
+ */
+public class IetfNetAnydataTest {
+
+ TestYangSerializerContext context = new TestYangSerializerContext();
+
+ /*
+ * Reference for data node info.
+ */
+ HelperContext info;
+
+ /*
+ * Reference for data node builder.
+ */
+ DataNode.Builder dBlr;
+
+ /*
+ * Reference for resource id.
+ */
+ ResourceId id;
+
+ /*
+ * Reference for the value.
+ */
+ String value;
+
+ /*
+ * Reference for string array to used for resource id testing.
+ */
+ String[] nA;
+ String[] nsA;
+ String[] valA;
+
+ private static final String[] EXPECTED = {
+ "Entry Node is /.",
+ "Entry Node is c1.",
+ "Entry Node is mydata2.",
+ "Entry Node is link.",
+ "Entry Node is link-id.",
+ "Exit Node is link-id.",
+ "Entry Node is source.",
+ "Entry Node is source-node.",
+ "Exit Node is source-node.",
+ "Exit Node is source.",
+ "Exit Node is link.",
+ "Entry Node is node.",
+ "Entry Node is node-id.",
+ "Exit Node is node-id.",
+ "Entry Node is supporting-node.",
+ "Entry Node is network-ref.",
+ "Exit Node is network-ref.",
+ "Entry Node is node-ref.",
+ "Exit Node is node-ref.",
+ "Exit Node is supporting-node.",
+ "Exit Node is node.",
+ "Exit Node is mydata2.",
+ "Exit Node is c1.",
+ "Exit Node is /."
+ };
+
+ /**
+ * Test anydata add to data node builder.
+ */
+ @Test
+ public void addToDataTest() {
+
+ dBlr = initializeDataNode(context);
+ value = null;
+ // Adding container c1
+ dBlr = addDataNode(dBlr, "c1", TANY_NS, value, null);
+ // Adding anydata container
+ dBlr = addDataNode(dBlr, "mydata2", TANY_NS, value, null);
+ context.getRegistry().registerAnydataSchema(Mydata2.class, Node.class);
+ context.getRegistry().registerAnydataSchema(Mydata2.class, Link.class);
+ // Adding list inside anydata container
+ dBlr = addDataNode(dBlr, "link", TOPONS, value, null);
+ value = "link-id";
+ dBlr = addDataNode(dBlr, "link-id", TOPONS, value, null);
+ dBlr = exitDataNode(dBlr);
+ value = null;
+ dBlr = addDataNode(dBlr, "source", TOPONS, value, null);
+ value = "source-node";
+ dBlr = addDataNode(dBlr, "source-node", TOPONS, value, null);
+ dBlr = exitDataNode(dBlr);
+ dBlr = exitDataNode(dBlr); // exit source
+ dBlr = exitDataNode(dBlr); // exit link
+
+ // Adding list inside anydata container
+ value = null;
+ dBlr = addDataNode(dBlr, "node", IETFNS, value, null);
+ // Adding key element node-id
+ value = "node1";
+ dBlr = addDataNode(dBlr, "node-id", null, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = null;
+ // Adding list inside list
+ dBlr = addDataNode(dBlr, "supporting-node", null, value, null);
+ // Adding key element network-ref
+ value = "network3";
+ dBlr = addDataNode(dBlr, "network-ref", null, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ value = "network4";
+ // Adding key element node-ref
+ dBlr = addDataNode(dBlr, "node-ref", null, value, null);
+ dBlr = exitDataNode(dBlr);
+ dBlr = exitDataNode(dBlr);
+ dBlr = exitDataNode(dBlr);
+ dBlr = exitDataNode(dBlr);
+ dBlr = exitDataNode(dBlr);
+
+ // Validating the data node.
+ DataNode node = dBlr.build();
+ validateDataNode(node, "/", null, SINGLE_INSTANCE_NODE, true, null);
+
+ Map<NodeKey, DataNode> childMap = ((InnerNode) node).childNodes();
+ Iterator<Map.Entry<NodeKey, DataNode>> iter = childMap.entrySet()
+ .iterator();
+ DataNode n = iter.next().getValue();
+ validateDataNode(n, "c1", TANY_NS, SINGLE_INSTANCE_NODE,
+ true, null);
+ n = ((InnerNode) n).childNodes().values().iterator().next();
+ validateDataNode(n, "mydata2", TANY_NS, SINGLE_INSTANCE_NODE,
+ true, null);
+ Iterator<DataNode> it = ((InnerNode) n).childNodes().values().iterator();
+
+ //link validation
+ n = it.next();
+ validateDataNode(n, "link", TOPONS, MULTI_INSTANCE_NODE,
+ true, null);
+ Iterator<KeyLeaf> keyIt = ((ListKey) n.key()).keyLeafs().iterator();
+
+ validateLeafDataNode(keyIt.next(), "link-id", TOPONS, "link-id");
+ Iterator<DataNode> it1 = ((InnerNode) n).childNodes().values().iterator();
+ n = it1.next();
+ validateDataNode(n, "link-id", TOPONS, SINGLE_INSTANCE_LEAF_VALUE_NODE,
+ false, "link-id");
+ n = it1.next();
+ validateDataNode(n, "source", TOPONS, SINGLE_INSTANCE_NODE,
+ true, null);
+
+ Iterator<DataNode> it2 = ((InnerNode) n).childNodes().values().iterator();
+ n = it2.next();
+ validateDataNode(n, "source-node", TOPONS, SINGLE_INSTANCE_LEAF_VALUE_NODE,
+ false, "source-node");
+
+ // node validation
+ n = it.next();
+ validateDataNode(n, "node", IETFNS, MULTI_INSTANCE_NODE,
+ true, null);
+ keyIt = ((ListKey) n.key()).keyLeafs().iterator();
+
+ validateLeafDataNode(keyIt.next(), "node-id", IETFNS, "node1");
+
+ it1 = ((InnerNode) n).childNodes().values().iterator();
+ n = it1.next();
+ validateDataNode(n, "node-id", IETFNS, SINGLE_INSTANCE_LEAF_VALUE_NODE,
+ false, "node1");
+ n = it1.next();
+ validateDataNode(n, "supporting-node", IETFNS, MULTI_INSTANCE_NODE,
+ true, null);
+
+ keyIt = ((ListKey) n.key()).keyLeafs().iterator();
+
+ validateLeafDataNode(keyIt.next(), "network-ref", IETFNS, "network3");
+
+ it2 = ((InnerNode) n).childNodes().values().iterator();
+ n = it2.next();
+ validateDataNode(n, "network-ref", IETFNS, SINGLE_INSTANCE_LEAF_VALUE_NODE,
+ false, "network3");
+ n = it2.next();
+ validateDataNode(n, "node-ref", IETFNS, SINGLE_INSTANCE_LEAF_VALUE_NODE,
+ false, "network4");
+
+ walkINTree(dBlr.build(), EXPECTED);
+ }
+}
diff --git a/runtime/src/test/resources/schemaProviderTestYangFiles/anyTest.yang b/runtime/src/test/resources/schemaProviderTestYangFiles/anyTest.yang
new file mode 100644
index 0000000..d125541
--- /dev/null
+++ b/runtime/src/test/resources/schemaProviderTestYangFiles/anyTest.yang
@@ -0,0 +1,24 @@
+module anyTest {
+
+ yang-version 1.1;
+
+ namespace "yrt:list.test.anydata";
+
+ prefix "l";
+
+ organization "ON-LAB";
+
+ description "This module defines for list.";
+
+ revision "2016-06-24" {
+ description "Initial revision.";
+ }
+
+ anydata mydata {
+
+ }
+ container c1 {
+ anydata mydata2 {
+ }
+ }
+}
\ No newline at end of file