Serializer Helper Utility fix

Change-Id: I4bf7e2d6b5c810397bf27b405e5c7b354d74ca34
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/helperutils/ExtResourceIdBldr.java b/runtime/src/main/java/org/onosproject/yang/runtime/helperutils/ExtResourceIdBldr.java
index 29bdf2c..6db16ab 100644
--- a/runtime/src/main/java/org/onosproject/yang/runtime/helperutils/ExtResourceIdBldr.java
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/helperutils/ExtResourceIdBldr.java
@@ -16,10 +16,14 @@
 
 package org.onosproject.yang.runtime.helperutils;
 
+import org.onosproject.yang.model.KeyLeaf;
+import org.onosproject.yang.model.LeafListKey;
 import org.onosproject.yang.model.LeafListKey.LeafListKeyBuilder;
+import org.onosproject.yang.model.ListKey;
 import org.onosproject.yang.model.ModelException;
 import org.onosproject.yang.model.NodeKey;
 import org.onosproject.yang.model.ResourceId;
+import org.onosproject.yang.model.SchemaId;
 
 import java.util.LinkedList;
 import java.util.List;
@@ -51,20 +55,27 @@
      */
     void traveseToParent() {
         if (curKeyBuilder != null) {
+            curKeyBuilder = null;
+        } else {
             curKeyBuilder = builders.get(builders.size() - 1);
             builders.remove(builders.size() - 1);
         }
     }
 
+    @Override
+    public ResourceId build() {
+        return getResourceId();
+    }
+
     /**
      * Returns the resource id for current node.
      *
      * @return resource Id
      */
     ResourceId getResourceId() {
-
-        builders.add(curKeyBuilder);
-
+        if (curKeyBuilder != null) {
+            builders.add(curKeyBuilder);
+        }
         List<NodeKey> keys = new LinkedList<>();
         for (NodeKey.NodeKeyBuilder builder : builders) {
             keys.add(builder.build());
@@ -73,4 +84,40 @@
         builders.remove(builders.size() - 1);
         return (new ResourceId(this));
     }
+
+    /**
+     * Creates the extended resource id builder from given resource id
+     * builder.
+     *
+     * @param ridBldr extended resource id builder
+     * @param builder resource id builder
+     * @return updated extended resource id builder
+     */
+    public ExtResourceIdBldr copyBuilder(ExtResourceIdBldr ridBldr, ResourceId
+            .Builder builder) {
+        ResourceId id = builder.build();
+        SchemaId sId;
+        // Preparing the extended resource id builder from resourceId.
+        List<NodeKey> keys = id.nodeKeys();
+
+        for (NodeKey k : keys) {
+            sId = k.schemaId();
+            if (k instanceof ListKey) {
+                List<KeyLeaf> kLeaf = ((ListKey) k).keyLeafs();
+                for (KeyLeaf kl : kLeaf) {
+                    sId = kl.leafSchema();
+                    ridBldr.addKeyLeaf(sId.name(), sId.namespace(),
+                                       kl.leafValue());
+                }
+                continue;
+            } else if (k instanceof LeafListKey) {
+                sId = k.schemaId();
+                ridBldr.addLeafListBranchPoint(sId.name(), sId.namespace(),
+                                               ((LeafListKey) k).value());
+                continue;
+            }
+            ridBldr.addBranchPointSchema(sId.name(), sId.namespace());
+        }
+        return ridBldr;
+    }
 }
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/helperutils/SerializerHelper.java b/runtime/src/main/java/org/onosproject/yang/runtime/helperutils/SerializerHelper.java
index 28cdb5f..3245a56 100644
--- a/runtime/src/main/java/org/onosproject/yang/runtime/helperutils/SerializerHelper.java
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/helperutils/SerializerHelper.java
@@ -55,6 +55,7 @@
             "NameSpace is mandatory to provide for first level node.";
     private static final String E_LEAFLIST =
             "Method is not allowed to pass multiple values for leaf-list.";
+    private static final String E_RESID = "Invalid resourceId builder.";
 
     // Name for first level child
     private static final String SLASH = "/";
@@ -74,7 +75,7 @@
             YangSerializerContext context) {
         SchemaContext cont = context.getContext();
         SchemaId id = cont.getSchemaId();
-        ExtResourceIdBldr rIdBdr = new ExtResourceIdBldr();
+        ResourceId.Builder rIdBdr = ResourceId.builder();
         rIdBdr.addBranchPointSchema(id.name(), id.namespace());
         // Adding the schema context to resource id app info.
         rIdBdr.appInfo(cont);
@@ -141,29 +142,32 @@
     public static ResourceId.Builder addToResourceId(
             ResourceId.Builder builder, String name, String namespace,
             List<String> value) throws IllegalArgumentException {
+        Object valObject;
         SchemaContext child = getChildSchemaContext(
                 (SchemaContext) builder.appInfo(), name, namespace);
         namespace = child.getSchemaId().namespace();
-        builder.appInfo(child);
         DataNode.Type childType = child.getType();
         try {
             if (childType == MULTI_INSTANCE_LEAF_VALUE_NODE) {
                 if (value.size() > 1) {
                     throw new IllegalArgumentException(errorMsg(E_LEAFLIST));
                 }
-                builder.addLeafListBranchPoint(name, namespace, value);
+                valObject = ((LeafSchemaContext) child).fromString(
+                        value.get(0));
+                builder.addLeafListBranchPoint(name, namespace, valObject);
             } else if (childType == MULTI_INSTANCE_NODE) {
+                // Adding list node.
+                String v = null;
+                builder = addToResourceId(builder, name, namespace, v);
                 Set<String> keyLeafs = ((ListSchemaContext) child)
                         .getKeyLeaf();
-                int expectedCount = keyLeafs.size();
-
                 try {
-                    checkElementCount(name, expectedCount, value.size());
+                    checkElementCount(name, keyLeafs.size(), value.size());
                 } catch (IllegalArgumentException e) {
                     throw new IllegalArgumentException(e.getMessage());
                 }
 
-                //After validation adding the key nodes under the list node.
+                // After validation adding the key nodes under the list node.
                 Iterator<String> sklIter = keyLeafs.iterator();
                 Iterator<String> kvlIter = value.iterator();
                 String keyEleName;
@@ -171,15 +175,20 @@
                 while (kvlIter.hasNext()) {
                     String val = kvlIter.next();
                     keyEleName = sklIter.next();
-                    builder.addKeyLeaf(keyEleName, namespace, val);
+                    SchemaContext keyChild = getChildSchemaContext(
+                            (SchemaContext) builder.appInfo(), keyEleName,
+                            namespace);
+                    valObject = ((LeafSchemaContext) keyChild).fromString(val);
+                    builder.addKeyLeaf(keyEleName, namespace, valObject);
                 }
             } else {
-                throw new IllegalArgumentException(errorMsg(FMT_NOT_EXIST,
-                                                            name));
+                throw new IllegalArgumentException(
+                        errorMsg(FMT_NOT_EXIST, name));
             }
         } catch (IllegalArgumentException e) {
             throw new IllegalArgumentException(e.getMessage());
         }
+        builder.appInfo(child);
         return builder;
     }
 
@@ -194,15 +203,16 @@
      */
     public static Builder initializeDataNode(ResourceId.Builder builder) {
 
-        if (!(builder instanceof ExtResourceIdBldr)) {
-            throw new IllegalArgumentException("Invalid resourceId builder.");
-        }
+        ExtResourceIdBldr rIdBldr = new ExtResourceIdBldr();
+        rIdBldr = rIdBldr.copyBuilder(rIdBldr, builder);
+        rIdBldr.appInfo(builder.appInfo());
         SchemaContext node = (SchemaContext) builder.appInfo();
         HelperContext info = new HelperContext();
         info.setResourceIdBuilder(null);
-        info.setParentResourceIdBldr((ExtResourceIdBldr) builder);
+        info.setParentResourceIdBldr(rIdBldr);
         SchemaId sId = node.getSchemaId();
-        InnerNode.Builder dBldr = InnerNode.builder(sId.name(), sId.namespace());
+        InnerNode.Builder dBldr = InnerNode.builder(
+                sId.name(), sId.namespace());
         dBldr.appInfo(info);
         return dBldr;
     }
@@ -222,14 +232,12 @@
         rId.addBranchPointSchema(sId.name(), sId.namespace());
         rId.appInfo(node);
         info.setResourceIdBuilder(rId);
-//        info.setSchemaContext(node);
         InnerNode.Builder dBlr = InnerNode.builder(sId.name(), sId.namespace());
         dBlr.type(SINGLE_INSTANCE_NODE);
         dBlr.appInfo(info);
         return dBlr;
     }
 
-
     /**
      * Adds a data node to a given data node builder.
      * <p>
@@ -254,7 +262,7 @@
      */
     public static Builder addDataNode(Builder builder,
                                       String name, String namespace,
-                                      String value, DataNode type) {
+                                      String value, DataNode.Type type) {
         try {
             SchemaContext node;
             ExtResourceIdBldr rIdBldr;
@@ -263,7 +271,6 @@
             ExtResourceIdBldr curBldr = info.getResourceIdBuilder();
             boolean isCreate = false;
             if (curBldr != null) {
-//                node = info.getSchemaContext();
                 rIdBldr = info.getResourceIdBuilder();
                 node = (SchemaContext) rIdBldr.appInfo();
                 isCreate = true;
@@ -275,10 +282,14 @@
                     node, name, namespace);
             DataNode.Type nodeType = childSchema.getType();
             if (type != null && !nodeType.equals(type)) {
-                throw new IllegalArgumentException(errorMsg(FMT_NOT_EXIST, name));
+                throw new IllegalArgumentException(
+                        errorMsg(FMT_NOT_EXIST, name));
             }
 
+            // Updating the namespace
+            namespace = childSchema.getSchemaId().namespace();
             updateResourceId(rIdBldr, name, value, childSchema, nodeType);
+            Object valObject;
             if (isCreate) {
                 switch (nodeType) {
 
@@ -288,9 +299,21 @@
                                 .type(nodeType);
                         break;
                     case SINGLE_INSTANCE_LEAF_VALUE_NODE:
+                        valObject = ((LeafSchemaContext) childSchema)
+                                .fromString(value);
+                        if (((YangLeaf) childSchema).isKeyLeaf()) {
+                            builder = builder.addKeyLeaf(
+                                    name, namespace, valObject);
+                        }
+                        builder = builder.createChildBuilder(
+                                name, namespace, valObject).type(nodeType);
+                        break;
                     case MULTI_INSTANCE_LEAF_VALUE_NODE:
-                        builder = builder.createChildBuilder(name, namespace, value)
-                                .type(nodeType);
+                        valObject = ((LeafSchemaContext) childSchema)
+                                .fromString(value);
+                        builder = builder.createChildBuilder(
+                                name, namespace, valObject).type(nodeType)
+                                .addLeafListValue(valObject);
                         break;
                     default:
                         throw new IllegalArgumentException(
@@ -302,7 +325,6 @@
                 builder.type(nodeType);
                 nodeInfo = info;
             }
-//            nodeInfo.setSchemaContext(childSchema);
             nodeInfo.setResourceIdBuilder(rIdBldr);
             builder.appInfo(nodeInfo);
         } catch (IllegalArgumentException e) {
@@ -411,9 +433,9 @@
      * @param child   child schema context
      * @param type    type of data node
      */
-    private static void updateResourceId(ResourceId.Builder builder, String name,
-                                         String value, SchemaContext child,
-                                         DataNode.Type type)
+    private static void updateResourceId(
+            ResourceId.Builder builder, String name, String value,
+            SchemaContext child, DataNode.Type type)
             throws IllegalArgumentException {
 
         Object valObject;
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