Serializer Helper Utility fix
Change-Id: I4bf7e2d6b5c810397bf27b405e5c7b354d74ca34
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
deleted file mode 100644
index c37fd57..0000000
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/AddToDataNodeListTest.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * 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/TestUtils.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestUtils.java
index 07f8595..8b8c058 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,8 +20,10 @@
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.InnerNode;
import org.onosproject.yang.model.KeyLeaf;
import org.onosproject.yang.model.LeafListKey;
+import org.onosproject.yang.model.LeafNode;
import org.onosproject.yang.model.ListKey;
import org.onosproject.yang.model.NodeKey;
import org.onosproject.yang.model.ResourceId;
@@ -31,6 +33,7 @@
import java.util.List;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
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;
@@ -63,9 +66,9 @@
/**
* Checks the schema context values of given leaf list node.
*/
- static void checkLeafListSchemaContext(String name, String namespace,
- String pname, String pnamespace,
- YangLeafList child) {
+ public static void checkLeafListSchemaContext(String name, String namespace,
+ String pname, String pnamespace,
+ YangLeafList child) {
SchemaId id = child.getSchemaId();
assertEquals(id.name(), name);
assertEquals(id.namespace(), namespace);
@@ -109,14 +112,13 @@
/**
* Validate the resource id builder.
*/
- public static void validateResourceId(String[] nA, String[] nsA, String[] valA,
- ResourceId rBlrEx) {
+ 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]);
@@ -141,4 +143,50 @@
}
}
}
+
+ /**
+ * Validates the give data node content.
+ *
+ * @param node data node
+ * @param n name
+ * @param ns namespace
+ * @param type data node type
+ * @param isChild denotes the given node has child or not
+ * @param value value of leaf
+ */
+ public static void validateDataNode(DataNode node, String n, String ns,
+ DataNode.Type type, boolean isChild,
+ String value) {
+ NodeKey k = node.key();
+ SchemaId id = k.schemaId();
+ assertEquals(id.name(), n);
+ assertEquals(id.namespace(), ns);
+ if (node instanceof InnerNode) {
+ assertEquals(((InnerNode) node).type(), type);
+ if (isChild) {
+ assertNotNull(((InnerNode) node).childNodes());
+ } else {
+ assertNull(((InnerNode) node).childNodes());
+ }
+ } else {
+ assertEquals(((LeafNode) node).type(), type);
+ assertEquals(((LeafNode) node).value().toString(), value);
+ }
+ }
+
+ /**
+ * Validates the give key leaf content.
+ *
+ * @param key key leaf
+ * @param n name
+ * @param ns namespace
+ * @param v value of leaf node
+ */
+ public static void validateLeafDataNode(KeyLeaf key, String n, String ns,
+ String v) {
+ SchemaId id = key.leafSchema();
+ assertEquals(id.name(), n);
+ assertEquals(id.namespace(), ns);
+ assertEquals(key.leafValue().toString(), v);
+ }
}
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/CaseSchemaContextTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/schemacontext/CaseSchemaContextTest.java
similarity index 96%
rename from runtime/src/test/java/org/onosproject/yang/runtime/impl/CaseSchemaContextTest.java
rename to runtime/src/test/java/org/onosproject/yang/runtime/impl/schemacontext/CaseSchemaContextTest.java
index 522f843..4d54d2c 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/CaseSchemaContextTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/schemacontext/CaseSchemaContextTest.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.onosproject.yang.runtime.impl;
+package org.onosproject.yang.runtime.impl.schemacontext;
import org.junit.Test;
import org.onosproject.yang.compiler.datamodel.DefaultYangNamespace;
@@ -24,6 +24,7 @@
import org.onosproject.yang.compiler.datamodel.YangSchemaNodeIdentifier;
import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
import org.onosproject.yang.model.SchemaId;
+import org.onosproject.yang.runtime.impl.TestYangSchemaNodeProvider;
import org.onosproject.yang.runtime.ymrimpl.DefaultYangModelRegistry;
import static org.onosproject.yang.model.DataNode.Type.MULTI_INSTANCE_NODE;
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/LeafSchemaContextTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/schemacontext/LeafSchemaContextTest.java
similarity index 96%
rename from runtime/src/test/java/org/onosproject/yang/runtime/impl/LeafSchemaContextTest.java
rename to runtime/src/test/java/org/onosproject/yang/runtime/impl/schemacontext/LeafSchemaContextTest.java
index 19c8746..cc9e0bd 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/LeafSchemaContextTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/schemacontext/LeafSchemaContextTest.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.onosproject.yang.runtime.impl;
+package org.onosproject.yang.runtime.impl.schemacontext;
import org.junit.Test;
import org.onosproject.yang.compiler.datamodel.DefaultYangNamespace;
@@ -26,6 +26,7 @@
import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
import org.onosproject.yang.model.DataNode;
import org.onosproject.yang.model.SchemaId;
+import org.onosproject.yang.runtime.impl.TestYangSchemaNodeProvider;
import org.onosproject.yang.runtime.ymrimpl.DefaultYangModelRegistry;
import static org.onosproject.yang.runtime.impl.TestUtils.checkLeafListSchemaContext;
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/RpcSchemaContextTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/schemacontext/RpcSchemaContextTest.java
similarity index 97%
rename from runtime/src/test/java/org/onosproject/yang/runtime/impl/RpcSchemaContextTest.java
rename to runtime/src/test/java/org/onosproject/yang/runtime/impl/schemacontext/RpcSchemaContextTest.java
index 3197470..89f0105 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/RpcSchemaContextTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/schemacontext/RpcSchemaContextTest.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.onosproject.yang.runtime.impl;
+package org.onosproject.yang.runtime.impl.schemacontext;
/**
* Tests the default schema context methods.
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/SchemaContextTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/schemacontext/SchemaContextTest.java
similarity index 96%
rename from runtime/src/test/java/org/onosproject/yang/runtime/impl/SchemaContextTest.java
rename to runtime/src/test/java/org/onosproject/yang/runtime/impl/schemacontext/SchemaContextTest.java
index a12d9cc..e1e473a 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/SchemaContextTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/schemacontext/SchemaContextTest.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.onosproject.yang.runtime.impl;
+package org.onosproject.yang.runtime.impl.schemacontext;
import org.junit.Test;
import org.onosproject.yang.compiler.datamodel.YangAugment;
@@ -24,6 +24,7 @@
import org.onosproject.yang.compiler.datamodel.YangNode;
import org.onosproject.yang.model.DataNode;
import org.onosproject.yang.model.SchemaId;
+import org.onosproject.yang.runtime.impl.TestYangSchemaNodeProvider;
import org.onosproject.yang.runtime.ymrimpl.DefaultYangModelRegistry;
import java.util.List;
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/AddToDataNodeIetfNetTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeIetfNetTest.java
similarity index 94%
rename from runtime/src/test/java/org/onosproject/yang/runtime/impl/AddToDataNodeIetfNetTest.java
rename to runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeIetfNetTest.java
index 3295861..df125bc 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/AddToDataNodeIetfNetTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeIetfNetTest.java
@@ -14,27 +14,24 @@
* limitations under the License.
*/
-package org.onosproject.yang.runtime.impl;
+package org.onosproject.yang.runtime.impl.serializerhelper;
-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 org.onosproject.yang.runtime.impl.TestYangSerializerContext;
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.schemacontext.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();
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeListTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeListTest.java
new file mode 100644
index 0000000..e5e6579
--- /dev/null
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeListTest.java
@@ -0,0 +1,194 @@
+/*
+ * 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.serializerhelper;
+
+import org.junit.Test;
+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.helperutils.HelperContext;
+import org.onosproject.yang.runtime.impl.TestYangSerializerContext;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.Map;
+
+import static org.onosproject.yang.model.DataNode.Type.MULTI_INSTANCE_LEAF_VALUE_NODE;
+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.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.validateDataNode;
+import static org.onosproject.yang.runtime.impl.TestUtils.validateLeafDataNode;
+import static org.onosproject.yang.runtime.impl.TestUtils.validateResourceId;
+
+/**
+ * Tests the serializer helper methods.
+ */
+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() throws IOException {
+
+ Object ob;
+ 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);
+ dBlr = exitDataNode(dBlr);
+ value = "2";
+ dBlr = addDataNode(dBlr, "leaf1", LNS, value, null);
+ dBlr = exitDataNode(dBlr);
+ value = "3";
+ dBlr = addDataNode(dBlr, "leaf1", LNS, value, null);
+ dBlr = exitDataNode(dBlr);
+ value = "4";
+ dBlr = addDataNode(dBlr, "leaf1", LNS, value, null);
+ ResourceId id3 = getResourceId(dBlr);
+ dBlr = exitDataNode(dBlr);
+
+ //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);
+
+ nA = new String[]{"/", "leaf1", ""};
+ nsA = new String[]{null, LNS, ""};
+ valA = new String[]{"4", "2", "3", "0", ""};
+ validateResourceId(nA, nsA, valA, id3);
+
+ DataNode node = dBlr.build();
+ validateDataNode(node, "/", null, SINGLE_INSTANCE_NODE, true, null);
+
+ Map<NodeKey, DataNode> childMap = ((InnerNode) node).childNodes();
+ Iterator<Map.Entry<NodeKey, DataNode>> it = childMap.entrySet().iterator();
+ Map.Entry<NodeKey, DataNode> n = it.next();
+ validateDataNode(n.getValue(), "l1", LNS, MULTI_INSTANCE_NODE,
+ true, null);
+
+ Iterator<KeyLeaf> keyIt = ((ListKey) n.getKey()).keyLeafs().iterator();
+
+ validateLeafDataNode(keyIt.next(), "k1", LNS, "1");
+ validateLeafDataNode(keyIt.next(), "k2", LNS, "2");
+ validateLeafDataNode(keyIt.next(), "k3", LNS, "3");
+
+ Iterator<Map.Entry<NodeKey, DataNode>> it1;
+ it1 = ((InnerNode) n.getValue()).childNodes().entrySet().iterator();
+ validateDataNode(it1.next().getValue(), "k1", LNS,
+ SINGLE_INSTANCE_LEAF_VALUE_NODE, false, "1");
+ validateDataNode(it1.next().getValue(), "k2", LNS,
+ SINGLE_INSTANCE_LEAF_VALUE_NODE, false, "2");
+ DataNode n1 = it1.next().getValue();
+ validateDataNode(n1, "c1", LNS,
+ SINGLE_INSTANCE_NODE, true, null);
+ validateDataNode(it1.next().getValue(), "k3", LNS,
+ SINGLE_INSTANCE_LEAF_VALUE_NODE, false, "3");
+
+ Iterator<Map.Entry<NodeKey, DataNode>> it2;
+ it2 = ((InnerNode) n1).childNodes().entrySet().iterator();
+ validateDataNode(it2.next().getValue(), "l1", LNS,
+ SINGLE_INSTANCE_LEAF_VALUE_NODE, false, "0");
+ validateDataNode(it.next().getValue(), "leaf1", LNS,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, false, "1");
+ validateDataNode(it.next().getValue(), "leaf1", LNS,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, false, "2");
+ validateDataNode(it.next().getValue(), "leaf1", LNS,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, false, "3");
+ validateDataNode(it.next().getValue(), "leaf1", LNS,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, false, "4");
+ }
+}
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/AddToDataNodeRidTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeRidTest.java
similarity index 94%
rename from runtime/src/test/java/org/onosproject/yang/runtime/impl/AddToDataNodeRidTest.java
rename to runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeRidTest.java
index fdce7f3..f2a38ad 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/AddToDataNodeRidTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeRidTest.java
@@ -14,14 +14,13 @@
* limitations under the License.
*/
-package org.onosproject.yang.runtime.impl;
+package org.onosproject.yang.runtime.impl.serializerhelper;
-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 org.onosproject.yang.runtime.impl.TestYangSerializerContext;
import static org.onosproject.yang.runtime.helperutils.SerializerHelper.addDataNode;
import static org.onosproject.yang.runtime.helperutils.SerializerHelper.addToResourceId;
@@ -33,8 +32,6 @@
/**
* Tests the serializer helper methods.
*/
-
-@FixMethodOrder(MethodSorters.DEFAULT)
public class AddToDataNodeRidTest {
public static final String LNS = "yrt:list";
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/AddToDataNodeRidTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToResourceIdTest.java
similarity index 65%
copy from runtime/src/test/java/org/onosproject/yang/runtime/impl/AddToDataNodeRidTest.java
copy to runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToResourceIdTest.java
index fdce7f3..271a649 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/AddToDataNodeRidTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToResourceIdTest.java
@@ -14,28 +14,25 @@
* limitations under the License.
*/
-package org.onosproject.yang.runtime.impl;
+package org.onosproject.yang.runtime.impl.serializerhelper;
-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 org.onosproject.yang.runtime.impl.TestYangSerializerContext;
-import static org.onosproject.yang.runtime.helperutils.SerializerHelper.addDataNode;
+import java.util.LinkedList;
+import java.util.List;
+
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 class AddToResourceIdTest {
public static final String LNS = "yrt:list";
@@ -69,24 +66,23 @@
String[] valA;
/**
- * Test add to data node after initializing it with resource builder.
+ * Test add to data node 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);
+ List<String> valueSet = new LinkedList<>();
+ valueSet.add("1");
+ valueSet.add("2");
+ valueSet.add("3");
+ rIdBlr = addToResourceId(rIdBlr, "l1", LNS, valueSet);
+ ResourceId id = rIdBlr.build();
//Tree validation
- nA = new String[]{"/", "l1", "c1", "l1", ""};
- nsA = new String[]{null, LNS, LNS, LNS, ""};
- valA = new String[]{"0", ""};
+ 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, id);
}
}
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/DataNodeInitializationTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/DataNodeInitializationTest.java
similarity index 93%
rename from runtime/src/test/java/org/onosproject/yang/runtime/impl/DataNodeInitializationTest.java
rename to runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/DataNodeInitializationTest.java
index e1d3fc2..4c95a74 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/DataNodeInitializationTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/DataNodeInitializationTest.java
@@ -14,15 +14,14 @@
* limitations under the License.
*/
-package org.onosproject.yang.runtime.impl;
+package org.onosproject.yang.runtime.impl.serializerhelper;
-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 org.onosproject.yang.runtime.impl.TestYangSerializerContext;
import static org.onosproject.yang.runtime.helperutils.SerializerHelper.initializeDataNode;
import static org.onosproject.yang.runtime.helperutils.SerializerHelper.initializeResourceId;
@@ -31,8 +30,6 @@
/**
* Tests the initialize data node methods in serializer helper.
*/
-
-@FixMethodOrder(MethodSorters.DEFAULT)
public class DataNodeInitializationTest {
TestYangSerializerContext context = new TestYangSerializerContext();
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/DataNodeNegative1Test.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/DataNodeNegative1Test.java
new file mode 100644
index 0000000..39364b2
--- /dev/null
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/DataNodeNegative1Test.java
@@ -0,0 +1,70 @@
+/*
+ * 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.serializerhelper;
+
+import org.junit.Test;
+import org.onosproject.yang.model.DataNode;
+import org.onosproject.yang.model.ResourceId;
+import org.onosproject.yang.runtime.impl.TestYangSerializerContext;
+
+import static org.junit.Assert.assertEquals;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.addDataNode;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.initializeDataNode;
+
+/**
+ * Tests the serializer helper methods.
+ */
+public class DataNodeNegative1Test {
+
+ TestYangSerializerContext context = new TestYangSerializerContext();
+
+ /*
+ * Reference for data node builder.
+ */
+ DataNode.Builder dBlr;
+
+ /*
+ * Reference for resource id.
+ */
+ ResourceId id;
+
+ /*
+ * Reference for the value.
+ */
+ String value;
+
+ private static final String E_NAMESPACE =
+ "NameSpace is mandatory to provide for first level node.";
+
+ /**
+ * Test adding a node null namespace negative scenario.
+ */
+ @Test
+ public void negativeTest() {
+
+ dBlr = initializeDataNode(context);
+ value = "1";
+ boolean isExpOccurred = false;
+ try {
+ dBlr = addDataNode(dBlr, "l1", null, value, null);
+ } catch (IllegalArgumentException e) {
+ isExpOccurred = true;
+ assertEquals(e.getMessage(), E_NAMESPACE);
+ }
+ assertEquals(isExpOccurred, true);
+ }
+}
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/DataNodeNegativeTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/DataNodeNegativeTest.java
new file mode 100644
index 0000000..7cef8a9
--- /dev/null
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/DataNodeNegativeTest.java
@@ -0,0 +1,72 @@
+/*
+ * 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.serializerhelper;
+
+import org.junit.Test;
+import org.onosproject.yang.model.DataNode;
+import org.onosproject.yang.model.ResourceId;
+import org.onosproject.yang.runtime.impl.TestYangSerializerContext;
+
+import static org.junit.Assert.assertEquals;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.addDataNode;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.initializeDataNode;
+
+/**
+ * Tests the serializer helper methods.
+ */
+public class DataNodeNegativeTest {
+
+ public static final String LNS = "yrt:list";
+
+ TestYangSerializerContext context = new TestYangSerializerContext();
+
+ /*
+ * Reference for data node builder.
+ */
+ DataNode.Builder dBlr;
+
+ /*
+ * Reference for resource id.
+ */
+ ResourceId id;
+
+ /*
+ * Reference for the value.
+ */
+ String value;
+
+ private static final String FMT_NOT_EXIST =
+ "Schema node with name %s doesn't exist.";
+
+ /**
+ * Test adding a node with value negative scenario.
+ */
+ @Test
+ public void negative1Test() {
+
+ dBlr = initializeDataNode(context);
+ value = "1";
+ boolean isExpOccurred = false;
+ try {
+ dBlr = addDataNode(dBlr, "l1", LNS, value, null);
+ } catch (IllegalArgumentException e) {
+ isExpOccurred = true;
+ assertEquals(e.getMessage(), String.format(FMT_NOT_EXIST, "l1"));
+ }
+ assertEquals(isExpOccurred, true);
+ }
+}
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/ResourceIdInitializationTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/ResourceIdInitializationTest.java
similarity index 73%
rename from runtime/src/test/java/org/onosproject/yang/runtime/impl/ResourceIdInitializationTest.java
rename to runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/ResourceIdInitializationTest.java
index 7122c82..2ef2864 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/ResourceIdInitializationTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/ResourceIdInitializationTest.java
@@ -14,23 +14,22 @@
* limitations under the License.
*/
-package org.onosproject.yang.runtime.impl;
+package org.onosproject.yang.runtime.impl.serializerhelper;
-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 org.onosproject.yang.runtime.impl.TestYangSerializerContext;
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.schemacontext.SchemaContextTest.IETFNS;
import static org.onosproject.yang.runtime.impl.TestUtils.checkRootLevelContext;
+import static org.onosproject.yang.runtime.impl.TestUtils.validateResourceId;
/**
* Tests the initialize resource id methods in serializer helper.
*/
-@FixMethodOrder(MethodSorters.DEFAULT)
public class ResourceIdInitializationTest {
TestYangSerializerContext context = new TestYangSerializerContext();
@@ -45,6 +44,13 @@
*/
String value;
+ /*
+ * Reference for string array to used for resource id testing.
+ */
+ String[] nA;
+ String[] nsA;
+ String[] valA;
+
/**
* Checks initialize resource id.
*/
@@ -63,5 +69,11 @@
rIdBlr = addToResourceId(rIdBlr, "network", null, value);
value = "network1";
rIdBlr = addToResourceId(rIdBlr, "network-id", null, value);
+ ResourceId id = rIdBlr.build();
+
+ 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/serializerhelper/ResourceIdNegative2Test.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/ResourceIdNegative2Test.java
new file mode 100644
index 0000000..655c9c8
--- /dev/null
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/ResourceIdNegative2Test.java
@@ -0,0 +1,64 @@
+/*
+ * 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.serializerhelper;
+
+import org.junit.Test;
+import org.onosproject.yang.model.ResourceId;
+import org.onosproject.yang.runtime.impl.TestYangSerializerContext;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.addToResourceId;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.initializeResourceId;
+
+/**
+ * Tests the serializer helper methods.
+ */
+public class ResourceIdNegative2Test {
+
+ public static final String LNS = "yrt:list";
+
+ TestYangSerializerContext context = new TestYangSerializerContext();
+
+ private static final String E_TOO_MANY =
+ "Too many key parameters in l1. Expected 3; actual 4.";
+
+ /**
+ * Test adding list in resource id with more then expected key value
+ * negative scenario.
+ */
+ @Test
+ public void negative3Test() {
+
+ ResourceId.Builder rIdBlr = initializeResourceId(context);
+ List<String> valueSet = new LinkedList<>();
+ valueSet.add("1");
+ valueSet.add("2");
+ valueSet.add("3");
+ valueSet.add("4");
+ boolean isExpOccurred = false;
+ try {
+ addToResourceId(rIdBlr, "l1", LNS, valueSet);
+ } catch (IllegalArgumentException e) {
+ isExpOccurred = true;
+ assertEquals(e.getMessage(), E_TOO_MANY);
+ }
+ assertEquals(isExpOccurred, true);
+ }
+}
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/ResourceIdNegative3Test.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/ResourceIdNegative3Test.java
new file mode 100644
index 0000000..a7e39ca
--- /dev/null
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/ResourceIdNegative3Test.java
@@ -0,0 +1,62 @@
+/*
+ * 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.serializerhelper;
+
+import org.junit.Test;
+import org.onosproject.yang.model.ResourceId;
+import org.onosproject.yang.runtime.impl.TestYangSerializerContext;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.addToResourceId;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.initializeResourceId;
+
+/**
+ * Tests the serializer helper methods.
+ */
+public class ResourceIdNegative3Test {
+
+ public static final String LNS = "yrt:list";
+
+ TestYangSerializerContext context = new TestYangSerializerContext();
+
+ private static final String E_TOO_FEW =
+ "Too few key parameters in l1. Expected 3; actual 2.";
+
+ /**
+ * Test adding list in resource id with less then expected key value
+ * negative scenario.
+ */
+ @Test
+ public void negativeTest() {
+
+ ResourceId.Builder rIdBlr = initializeResourceId(context);
+ List<String> valueSet = new LinkedList<>();
+ valueSet.add("1");
+ valueSet.add("2");
+ boolean isExpOccurred = false;
+ try {
+ rIdBlr = addToResourceId(rIdBlr, "l1", LNS, valueSet);
+ } catch (IllegalArgumentException e) {
+ isExpOccurred = true;
+ assertEquals(e.getMessage(), E_TOO_FEW);
+ }
+ assertEquals(isExpOccurred, true);
+ }
+}
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/ResourceIdNegativeTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/ResourceIdNegativeTest.java
new file mode 100644
index 0000000..2f09763
--- /dev/null
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/ResourceIdNegativeTest.java
@@ -0,0 +1,62 @@
+/*
+ * 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.serializerhelper;
+
+import org.junit.Test;
+import org.onosproject.yang.model.ResourceId;
+import org.onosproject.yang.runtime.impl.TestYangSerializerContext;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.addToResourceId;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.initializeResourceId;
+
+/**
+ * Tests the serializer helper methods.
+ */
+public class ResourceIdNegativeTest {
+
+ public static final String LNS = "yrt:list";
+
+ TestYangSerializerContext context = new TestYangSerializerContext();
+
+ private static final String E_LEAFLIST =
+ "Method is not allowed to pass multiple values for leaf-list.";
+
+ /**
+ * Test adding a leaf-list node in resource id with list of values negative
+ * scenario.
+ */
+ @Test
+ public void negative1Test() {
+
+ ResourceId.Builder rIdBlr = initializeResourceId(context);
+ List<String> valueSet = new LinkedList<>();
+ valueSet.add("1");
+ valueSet.add("2");
+ boolean isExpOccurred = false;
+ try {
+ addToResourceId(rIdBlr, "leaf1", LNS, valueSet);
+ } catch (IllegalArgumentException e) {
+ isExpOccurred = true;
+ assertEquals(e.getMessage(), E_LEAFLIST);
+ }
+ assertEquals(isExpOccurred, true);
+ }
+}
diff --git a/runtime/src/test/resources/schemaProviderTestYangFiles/list.yang b/runtime/src/test/resources/schemaProviderTestYangFiles/list.yang
index fcc67eb..122ce11 100644
--- a/runtime/src/test/resources/schemaProviderTestYangFiles/list.yang
+++ b/runtime/src/test/resources/schemaProviderTestYangFiles/list.yang
@@ -34,4 +34,8 @@
}
}
}
+
+ leaf-list leaf1 {
+ type string;
+ }
}
\ No newline at end of file