[ONOS-5883] Implemention of Serializer Helper Utility
Change-Id: Ifffcdb1ee6de8dfd1a08df9e0b5473651509a6dd
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/AddToDataNodeIetfNetTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/AddToDataNodeIetfNetTest.java
new file mode 100644
index 0000000..3295861
--- /dev/null
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/AddToDataNodeIetfNetTest.java
@@ -0,0 +1,146 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * 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.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+import org.onosproject.yang.model.DataNode;
+import org.onosproject.yang.model.ResourceId;
+import org.onosproject.yang.runtime.helperutils.HelperContext;
+
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.addDataNode;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.exitDataNode;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.getResourceId;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.initializeDataNode;
+import static org.onosproject.yang.runtime.impl.SchemaContextTest.IETFNS;
+import static org.onosproject.yang.runtime.impl.TestUtils.validateResourceId;
+
+/**
+ * Tests the serializer helper methods.
+ */
+
+@FixMethodOrder(MethodSorters.DEFAULT)
+public class AddToDataNodeIetfNetTest {
+
+ 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;
+
+ /**
+ * Test add to data node builder.
+ */
+ @Test
+ public void addToDataTest() {
+
+ dBlr = initializeDataNode(context);
+ // Adding container
+ dBlr = addDataNode(dBlr, "networks", IETFNS, value, null);
+ // Adding list inside container
+ dBlr = addDataNode(dBlr, "network", null, value, null);
+ // Adding key element network Id
+ value = "network1";
+ dBlr = addDataNode(dBlr, "network-id", null, value, null);
+
+ info = (HelperContext) dBlr.appInfo();
+ id = getResourceId(dBlr);
+
+ // Traverse back to parent
+ dBlr = exitDataNode(dBlr);
+ //Tree validation
+ info = (HelperContext) dBlr.appInfo();
+ id = getResourceId(dBlr);
+ value = null;
+ // Adding list inside list
+ dBlr = addDataNode(dBlr, "supporting-network", null, value, null);
+ // Adding key element network-ref
+ value = "network2";
+ dBlr = addDataNode(dBlr, "network-ref", null, value, null);
+ dBlr = exitDataNode(dBlr);
+ dBlr = exitDataNode(dBlr);
+
+ value = null;
+ // Adding list inside list
+ dBlr = addDataNode(dBlr, "node", null, 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);
+
+ value = null;
+ // Adding container
+ dBlr = addDataNode(dBlr, "networks-state", IETFNS, value, null);
+ // Adding list inside container
+ dBlr = addDataNode(dBlr, "network", null, value, null);
+ // Adding key element network-ref
+ value = "network5";
+ dBlr = addDataNode(dBlr, "network-ref", null, value, null);
+ dBlr = exitDataNode(dBlr);
+
+ // Adding leaf server-provided
+ value = "true";
+ dBlr = addDataNode(dBlr, "server-provided", null, value, null);
+
+ //Tree validation
+ nA = new String[]{"/", "networks", "network", "network-id", ""};
+ nsA = new String[]{null, IETFNS, IETFNS, IETFNS, ""};
+ valA = new String[]{"network1", ""};
+ validateResourceId(nA, nsA, valA, id);
+ }
+}
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/AddToDataNodeListTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/AddToDataNodeListTest.java
new file mode 100644
index 0000000..c37fd57
--- /dev/null
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/AddToDataNodeListTest.java
@@ -0,0 +1,133 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * 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.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+import org.onosproject.yang.model.DataNode;
+import org.onosproject.yang.model.ResourceId;
+import org.onosproject.yang.runtime.helperutils.HelperContext;
+
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.addDataNode;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.exitDataNode;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.getResourceId;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.initializeDataNode;
+import static org.onosproject.yang.runtime.impl.TestUtils.validateResourceId;
+
+/**
+ * Tests the serializer helper methods.
+ */
+
+@FixMethodOrder(MethodSorters.DEFAULT)
+public class AddToDataNodeListTest {
+
+ public static final String LNS = "yrt:list";
+
+ 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;
+
+ /**
+ * Test add to data node builder.
+ */
+ @Test
+ public void addToDataListTest() {
+
+ dBlr = initializeDataNode(context);
+
+ dBlr = addDataNode(dBlr, "l1", LNS, value, null);
+ value = "1";
+ dBlr = addDataNode(dBlr, "k1", null, value, null);
+ dBlr = exitDataNode(dBlr);
+ value = "2";
+ dBlr = addDataNode(dBlr, "k2", null, value, null);
+ dBlr = exitDataNode(dBlr);
+ value = null;
+ dBlr = addDataNode(dBlr, "c1", null, value, null);
+ value = "0";
+ dBlr = addDataNode(dBlr, "l1", null, value, null);
+
+ info = (HelperContext) dBlr.appInfo();
+ id = getResourceId(dBlr);
+ dBlr = exitDataNode(dBlr);
+
+ ResourceId id1 = getResourceId(dBlr);
+ dBlr = exitDataNode(dBlr);
+
+ value = "3";
+ dBlr = addDataNode(dBlr, "k3", null, value, null);
+
+ info = (HelperContext) dBlr.appInfo();
+ ResourceId id2 = getResourceId(dBlr);
+
+ dBlr = exitDataNode(dBlr);
+ dBlr = exitDataNode(dBlr);
+
+// // Checking leaf list
+// value = "1";
+// dBlr = addDataNode(dBlr, "leaf1", LNS, value, null);
+// value = "2";
+// dBlr = addDataNode(dBlr, "leaf1", LNS, value, null);
+// value = "3";
+// dBlr = addDataNode(dBlr, "leaf1", LNS, value, null);
+// value = "4";
+// dBlr = addDataNode(dBlr, "leaf1", LNS, value, null);
+
+ //Tree validation
+ nA = new String[]{"/", "l1", "k1", "k2", "k3", "c1", "l1", ""};
+ nsA = new String[]{null, LNS, LNS, LNS, LNS, LNS, LNS, ""};
+ valA = new String[]{"1", "2", "3", "0", ""};
+ validateResourceId(nA, nsA, valA, id);
+
+ nA = new String[]{"/", "l1", "k1", "k2", "k3", "c1", ""};
+ nsA = new String[]{null, LNS, LNS, LNS, LNS, LNS, ""};
+ valA = new String[]{"1", "2", "3", ""};
+ validateResourceId(nA, nsA, valA, id1);
+
+ nA = new String[]{"/", "l1", "k1", "k2", "k3", ""};
+ nsA = new String[]{null, LNS, LNS, LNS, LNS, ""};
+ valA = new String[]{"1", "2", "3", ""};
+ validateResourceId(nA, nsA, valA, id2);
+ return;
+ }
+}
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/AddToDataNodeRidTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/AddToDataNodeRidTest.java
new file mode 100644
index 0000000..fdce7f3
--- /dev/null
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/AddToDataNodeRidTest.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * 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.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+import org.onosproject.yang.model.DataNode;
+import org.onosproject.yang.model.ResourceId;
+import org.onosproject.yang.runtime.helperutils.HelperContext;
+
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.addDataNode;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.addToResourceId;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.getResourceId;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.initializeDataNode;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.initializeResourceId;
+import static org.onosproject.yang.runtime.impl.TestUtils.validateResourceId;
+
+/**
+ * Tests the serializer helper methods.
+ */
+
+@FixMethodOrder(MethodSorters.DEFAULT)
+public class AddToDataNodeRidTest {
+
+ public static final String LNS = "yrt:list";
+
+ 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;
+
+ /**
+ * Test add to data node after initializing it with resource builder.
+ */
+ @Test
+ public void addToDataListTest() {
+
+ ResourceId.Builder rIdBlr = initializeResourceId(context);
+ rIdBlr = addToResourceId(rIdBlr, "l1", LNS, value);
+ rIdBlr = addToResourceId(rIdBlr, "c1", LNS, value);
+ dBlr = initializeDataNode(rIdBlr);
+ value = "0";
+ dBlr = addDataNode(dBlr, "l1", null, value, null);
+ info = (HelperContext) dBlr.appInfo();
+ id = getResourceId(dBlr);
+
+ //Tree validation
+ nA = new String[]{"/", "l1", "c1", "l1", ""};
+ nsA = new String[]{null, LNS, LNS, LNS, ""};
+ valA = new String[]{"0", ""};
+ validateResourceId(nA, nsA, valA, id);
+ }
+}
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestCaseSchemaContext.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/CaseSchemaContextTest.java
similarity index 98%
rename from runtime/src/test/java/org/onosproject/yang/runtime/impl/TestCaseSchemaContext.java
rename to runtime/src/test/java/org/onosproject/yang/runtime/impl/CaseSchemaContextTest.java
index cedfdf5..522f843 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestCaseSchemaContext.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/CaseSchemaContextTest.java
@@ -35,7 +35,7 @@
/**
* Tests the default schema context methods.
*/
-public class TestCaseSchemaContext {
+public class CaseSchemaContextTest {
private static TestYangSchemaNodeProvider schemaProvider =
new TestYangSchemaNodeProvider();
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/DataNodeInitializationTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/DataNodeInitializationTest.java
new file mode 100644
index 0000000..e1d3fc2
--- /dev/null
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/DataNodeInitializationTest.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * 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.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+import org.onosproject.yang.model.DataNode;
+import org.onosproject.yang.model.ResourceId;
+import org.onosproject.yang.model.SchemaContext;
+import org.onosproject.yang.runtime.helperutils.HelperContext;
+
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.initializeDataNode;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.initializeResourceId;
+import static org.onosproject.yang.runtime.impl.TestUtils.checkRootLevelContext;
+
+/**
+ * Tests the initialize data node methods in serializer helper.
+ */
+
+@FixMethodOrder(MethodSorters.DEFAULT)
+public class DataNodeInitializationTest {
+
+ TestYangSerializerContext context = new TestYangSerializerContext();
+
+ /*
+ * Reference for resource id builder.
+ */
+ ResourceId.Builder rIdBlr;
+
+ /*
+ * Reference for data node info.
+ */
+ HelperContext info;
+
+ /*
+ * Reference for data node builder.
+ */
+ DataNode.Builder dBlr;
+
+ /**
+ * Checks initialize data node using context.
+ */
+ @Test
+ public void initializeDataNodeTest() {
+
+ dBlr = initializeDataNode(context);
+ info = (HelperContext) dBlr.appInfo();
+ checkRootLevelContext((SchemaContext) info.getResourceIdBuilder()
+ .appInfo());
+ }
+
+ /**
+ * Checks initialize data node using resource id.
+ */
+ @Test
+ public void initializeDataNodeRIdTest() {
+
+ rIdBlr = initializeResourceId(context);
+ dBlr = initializeDataNode(rIdBlr);
+ info = (HelperContext) dBlr.appInfo();
+ checkRootLevelContext((SchemaContext) info.getParentResourceIdBldr()
+ .appInfo());
+ }
+}
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestLeafSchemaContext.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/LeafSchemaContextTest.java
similarity index 98%
rename from runtime/src/test/java/org/onosproject/yang/runtime/impl/TestLeafSchemaContext.java
rename to runtime/src/test/java/org/onosproject/yang/runtime/impl/LeafSchemaContextTest.java
index 4ceecf9..19c8746 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestLeafSchemaContext.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/LeafSchemaContextTest.java
@@ -35,7 +35,7 @@
/**
* Tests the default schema context methods.
*/
-public class TestLeafSchemaContext {
+public class LeafSchemaContextTest {
private static TestYangSchemaNodeProvider schemaProvider =
new TestYangSchemaNodeProvider();
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/ResourceIdInitializationTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/ResourceIdInitializationTest.java
new file mode 100644
index 0000000..7122c82
--- /dev/null
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/ResourceIdInitializationTest.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * 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.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+import org.onosproject.yang.model.ResourceId;
+import org.onosproject.yang.model.SchemaContext;
+
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.addToResourceId;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.initializeResourceId;
+import static org.onosproject.yang.runtime.impl.SchemaContextTest.IETFNS;
+import static org.onosproject.yang.runtime.impl.TestUtils.checkRootLevelContext;
+
+/**
+ * Tests the initialize resource id methods in serializer helper.
+ */
+@FixMethodOrder(MethodSorters.DEFAULT)
+public class ResourceIdInitializationTest {
+
+ TestYangSerializerContext context = new TestYangSerializerContext();
+
+ /*
+ * Reference for resource id builder.
+ */
+ ResourceId.Builder rIdBlr;
+
+ /*
+ * Reference for the value.
+ */
+ String value;
+
+ /**
+ * Checks initialize resource id.
+ */
+ @Test
+ public void initializeResourceIdTest() {
+
+ rIdBlr = initializeResourceId(context);
+ checkRootLevelContext((SchemaContext) rIdBlr.appInfo());
+ }
+
+ @Test
+ public void addToResourceIdTest() {
+
+ rIdBlr = initializeResourceId(context);
+ rIdBlr = addToResourceId(rIdBlr, "networks", IETFNS, value);
+ rIdBlr = addToResourceId(rIdBlr, "network", null, value);
+ value = "network1";
+ rIdBlr = addToResourceId(rIdBlr, "network-id", null, value);
+ }
+}
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestRpcSchemaContext.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/RpcSchemaContextTest.java
similarity index 98%
rename from runtime/src/test/java/org/onosproject/yang/runtime/impl/TestRpcSchemaContext.java
rename to runtime/src/test/java/org/onosproject/yang/runtime/impl/RpcSchemaContextTest.java
index 1468222..3197470 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestRpcSchemaContext.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/RpcSchemaContextTest.java
@@ -19,7 +19,7 @@
/**
* Tests the default schema context methods.
*/
-public class TestRpcSchemaContext {
+public class RpcSchemaContextTest {
//TODO : need to be updated afetr RPC implementation
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestSchemaContext.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/SchemaContextTest.java
similarity index 98%
rename from runtime/src/test/java/org/onosproject/yang/runtime/impl/TestSchemaContext.java
rename to runtime/src/test/java/org/onosproject/yang/runtime/impl/SchemaContextTest.java
index a767c1c..a12d9cc 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestSchemaContext.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/SchemaContextTest.java
@@ -28,14 +28,13 @@
import java.util.List;
-
import static org.onosproject.yang.runtime.impl.TestUtils.checkLeafSchemaContext;
import static org.onosproject.yang.runtime.impl.TestUtils.checkSchemaContext;
/**
* Tests the default schema context methods.
*/
-public class TestSchemaContext {
+public class SchemaContextTest {
private static TestYangSchemaNodeProvider schemaProvider =
new TestYangSchemaNodeProvider();
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 f249534..07f8595 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
@@ -20,11 +20,21 @@
import org.onosproject.yang.compiler.datamodel.YangLeafList;
import org.onosproject.yang.compiler.datamodel.YangNode;
import org.onosproject.yang.model.DataNode;
+import org.onosproject.yang.model.KeyLeaf;
+import org.onosproject.yang.model.LeafListKey;
+import org.onosproject.yang.model.ListKey;
+import org.onosproject.yang.model.NodeKey;
+import org.onosproject.yang.model.ResourceId;
+import org.onosproject.yang.model.SchemaContext;
import org.onosproject.yang.model.SchemaId;
+import java.util.List;
+
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
import static org.onosproject.yang.model.DataNode.Type.MULTI_INSTANCE_LEAF_VALUE_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;
public final class TestUtils {
@@ -37,9 +47,9 @@
/**
* Checks the schema context values of given leaf node.
*/
- static void checkLeafSchemaContext(String name, String namespace,
- String pname, String pnamespace,
- YangLeaf child) {
+ public static void checkLeafSchemaContext(String name, String namespace,
+ String pname, String pnamespace,
+ YangLeaf child) {
SchemaId id = child.getSchemaId();
assertEquals(id.name(), name);
assertEquals(id.namespace(), namespace);
@@ -69,9 +79,9 @@
/**
* Checks the schema context values of given node.
*/
- static void checkSchemaContext(String name, String namespace,
- String pname, String pnamespace,
- DataNode.Type type, YangNode child) {
+ public static void checkSchemaContext(String name, String namespace,
+ String pname, String pnamespace,
+ DataNode.Type type, YangNode child) {
SchemaId id = child.getSchemaId();
assertEquals(id.name(), name);
assertEquals(id.namespace(), namespace);
@@ -81,4 +91,54 @@
assertEquals(id.namespace(), pnamespace);
assertEquals(child.getType(), type);
}
+
+
+ /**
+ * Validates the root level node schema context.
+ *
+ * @param context schema context
+ */
+ public static void checkRootLevelContext(SchemaContext context) {
+ SchemaId id = context.getSchemaId();
+ assertEquals(id.name(), "/");
+ assertEquals(id.namespace(), null);
+ assertNull(context.getParentContext());
+ assertEquals(context.getType(), SINGLE_INSTANCE_NODE);
+ }
+
+ /**
+ * Validate the resource id builder.
+ */
+ public static void validateResourceId(String[] nA, String[] nsA, String[] valA,
+ ResourceId rBlrEx) {
+ SchemaId sId;
+ Object val = null;
+ List<NodeKey> keys = rBlrEx.nodeKeys();
+ int i = 0;
+ int j = 0;
+ ListKey.ListKeyBuilder lKeyBlr;
+ for (NodeKey k : keys) {
+ sId = k.schemaId();
+ assertEquals(sId.name(), nA[i]);
+ assertEquals(sId.namespace(), nsA[i]);
+ i++;
+ if (k instanceof ListKey) {
+ List<KeyLeaf> kLeaf = ((ListKey) k).keyLeafs();
+ for (KeyLeaf kl : kLeaf) {
+ sId = kl.leafSchema();
+ assertEquals(sId.name(), nA[i]);
+ assertEquals(sId.namespace(), nsA[i]);
+ assertEquals(kl.leafValAsString(), valA[j]);
+ i++;
+ j++;
+ }
+ } else if (k instanceof LeafListKey) {
+ val = ((LeafListKey) k).value().toString();
+ }
+ if (val != null) {
+ assertEquals(val, valA[j]);
+ j++;
+ }
+ }
+ }
}
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
new file mode 100644
index 0000000..5e1ebe6
--- /dev/null
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestYangSerializerContext.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * 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.onosproject.yang.model.SchemaContext;
+import org.onosproject.yang.runtime.YangSerializerContext;
+import org.onosproject.yang.runtime.ymrimpl.DefaultYangModelRegistry;
+
+/**
+ * Tests the default schema context provider methods.
+ */
+public class TestYangSerializerContext implements YangSerializerContext {
+
+ private static TestYangSchemaNodeProvider schemaProvider =
+ new TestYangSchemaNodeProvider();
+
+
+ @Override
+ public SchemaContext getContext() {
+ schemaProvider.processSchemaRegistry();
+ DefaultYangModelRegistry registry = schemaProvider.registry();
+ return registry;
+ }
+}
diff --git a/runtime/src/test/resources/schemaProviderTestYangFiles/list.yang b/runtime/src/test/resources/schemaProviderTestYangFiles/list.yang
new file mode 100644
index 0000000..fcc67eb
--- /dev/null
+++ b/runtime/src/test/resources/schemaProviderTestYangFiles/list.yang
@@ -0,0 +1,37 @@
+module list {
+
+ yang-version 1;
+
+ namespace "yrt:list";
+
+ prefix "l";
+
+ organization "ON-LAB";
+
+ description "This module defines for list.";
+
+ revision "2016-06-24" {
+ description "Initial revision.";
+ }
+
+ list l1 {
+ key "k1 k2 k3";
+ leaf k1 {
+ type string;
+ }
+
+ leaf k2 {
+ type string;
+ }
+
+ leaf k3 {
+ type string;
+ }
+
+ container c1 {
+ leaf l1 {
+ type string;
+ }
+ }
+ }
+}
\ No newline at end of file