serializer helper fix and data node walker

Change-Id: I46c0b0228370044b2f56c4fe5fafeb6cd11bfff2
diff --git a/model/src/main/java/org/onosproject/yang/model/ResourceId.java b/model/src/main/java/org/onosproject/yang/model/ResourceId.java
index 44df822..c873cb1 100644
--- a/model/src/main/java/org/onosproject/yang/model/ResourceId.java
+++ b/model/src/main/java/org/onosproject/yang/model/ResourceId.java
@@ -196,7 +196,7 @@
             }
             leafListKeyBuilder = new LeafListKey.LeafListKeyBuilder()
                     .schemaId(name, nameSpace).value(val);
-
+            processCurKey();
             curKeyBuilder = leafListKeyBuilder;
             return this;
         }
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/helperutils/DataNodeListener.java b/runtime/src/main/java/org/onosproject/yang/runtime/helperutils/DataNodeListener.java
new file mode 100644
index 0000000..dd498c9
--- /dev/null
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/helperutils/DataNodeListener.java
@@ -0,0 +1,49 @@
+/*
+ * 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.helperutils;
+
+import org.onosproject.yang.model.DataNode;
+
+/**
+ * Abstraction of an entity which provide call back methods which are called
+ * by data node walker while walking the data tree.
+ * <p>
+ * This interface needs to be implemented by protocol implementing listener's
+ * based call backs while data walk.
+ */
+public interface DataNodeListener {
+
+    /**
+     * Data node's entry, it will be called during a node entry.
+     * All the related information about the node can be obtain from the node.
+     *
+     * @param node data node
+     */
+    //TODO add additional context which may contain information like location
+    // of multi instance node in map to later let json serializer use this.
+    void enterDataNode(DataNode node);
+
+    /**
+     * Data node's exit, it will be called during a node exit.
+     * All the related information about the node can be obtain from the node.
+     *
+     * @param node data node
+     */
+    //TODO add additional context which may contain information like location
+    // of multi instance node in map to later let json serializer use this.
+    void exitDataNode(DataNode node);
+}
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/helperutils/DefaultDataNodeWalker.java b/runtime/src/main/java/org/onosproject/yang/runtime/helperutils/DefaultDataNodeWalker.java
new file mode 100644
index 0000000..eaebb54
--- /dev/null
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/helperutils/DefaultDataNodeWalker.java
@@ -0,0 +1,69 @@
+/*
+ * 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.helperutils;
+
+
+import org.onosproject.yang.model.DataNode;
+import org.onosproject.yang.model.InnerNode;
+import org.onosproject.yang.model.NodeKey;
+
+import java.util.Map;
+
+/**
+ * Represents implementation of data node walker, which walks the data tree.
+ */
+public final class DefaultDataNodeWalker {
+
+    // Forbid construction.
+    private DefaultDataNodeWalker() {
+    }
+
+    /**
+     * Walks the data node tree from given node.
+     *
+     * @param listener data node listener implemented by the protocol
+     * @param node     root node of data tree
+     */
+    public static void walk(DataNodeListener listener, DataNode node) {
+
+        listener.enterDataNode(node);
+        // Walking all child's of given root node.
+        walkChildNode(listener, node);
+        listener.exitDataNode(node);
+    }
+
+    /**
+     * Walks the all child nodes of given root node.
+     *
+     * @param listener data node listener implemented by the protocol
+     * @param node     root node of data tree
+     */
+    private static void walkChildNode(DataNodeListener listener, DataNode node) {
+        Map<NodeKey, DataNode> childMap;
+        if (node instanceof InnerNode) {
+            childMap = ((InnerNode) node).childNodes();
+            for (Map.Entry<NodeKey, DataNode> entry : childMap.entrySet()) {
+                DataNode n = entry.getValue();
+                listener.enterDataNode(n);
+                if (n instanceof InnerNode) {
+                    walkChildNode(listener, n);
+                }
+                listener.exitDataNode(n);
+            }
+        }
+    }
+}
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 6db16ab..4d06677 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
@@ -55,8 +55,6 @@
      */
     void traveseToParent() {
         if (curKeyBuilder != null) {
-            curKeyBuilder = null;
-        } else {
             curKeyBuilder = builders.get(builders.size() - 1);
             builders.remove(builders.size() - 1);
         }
@@ -109,14 +107,13 @@
                     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;
+            } else {
+                ridBldr.addBranchPointSchema(sId.name(), sId.namespace());
             }
-            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 3245a56..4449d5c 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
@@ -19,6 +19,7 @@
 import org.onosproject.yang.compiler.datamodel.YangLeaf;
 import org.onosproject.yang.model.DataNode;
 import org.onosproject.yang.model.InnerNode;
+import org.onosproject.yang.model.LeafNode;
 import org.onosproject.yang.model.LeafSchemaContext;
 import org.onosproject.yang.model.ListSchemaContext;
 import org.onosproject.yang.model.ResourceId;
@@ -112,7 +113,6 @@
             }
             DataNode.Type type = child.getType();
             updateResourceId(builder, name, value, child, type);
-            builder.appInfo(child);
         } catch (IllegalArgumentException e) {
             throw new IllegalArgumentException(e.getMessage());
         }
@@ -125,9 +125,12 @@
      * with key's value.
      * <p>
      * Builder and name are mandatory inputs, In case namespace is null,
-     * namespace of last key in the keylist of resource identifier builder will
+     * namespace of last key in the key list of resource identifier builder will
      * be used. Value should only be provided for leaf-list/list.
      * <p>
+     * In case of list its mandatory to pass either all key values of list or
+     * non of them (wild card to support get operation).
+     * <p>
      * This API will also carry out necessary schema related validations.
      *
      * @param builder   resource identifier builder
@@ -159,27 +162,29 @@
                 // Adding list node.
                 String v = null;
                 builder = addToResourceId(builder, name, namespace, v);
-                Set<String> keyLeafs = ((ListSchemaContext) child)
-                        .getKeyLeaf();
-                try {
-                    checkElementCount(name, keyLeafs.size(), value.size());
-                } catch (IllegalArgumentException e) {
-                    throw new IllegalArgumentException(e.getMessage());
-                }
+                if (value != null && value.size() != 0) {
+                    Set<String> keyLeafs = ((ListSchemaContext) child)
+                            .getKeyLeaf();
+                    try {
+                        checkElementCount(name, keyLeafs.size(), value.size());
+                    } catch (IllegalArgumentException e) {
+                        throw new IllegalArgumentException(e.getMessage());
+                    }
 
-                // After validation adding the key nodes under the list node.
-                Iterator<String> sklIter = keyLeafs.iterator();
-                Iterator<String> kvlIter = value.iterator();
-                String keyEleName;
+                    // After validation adding the key nodes under the list node.
+                    Iterator<String> sklIter = keyLeafs.iterator();
+                    Iterator<String> kvlIter = value.iterator();
+                    String keyEleName;
 
-                while (kvlIter.hasNext()) {
-                    String val = kvlIter.next();
-                    keyEleName = sklIter.next();
-                    SchemaContext keyChild = getChildSchemaContext(
-                            (SchemaContext) builder.appInfo(), keyEleName,
-                            namespace);
-                    valObject = ((LeafSchemaContext) keyChild).fromString(val);
-                    builder.addKeyLeaf(keyEleName, namespace, valObject);
+                    while (kvlIter.hasNext()) {
+                        String val = kvlIter.next();
+                        keyEleName = sklIter.next();
+                        SchemaContext keyChild = getChildSchemaContext(
+                                (SchemaContext) builder.appInfo(), keyEleName,
+                                namespace);
+                        valObject = ((LeafSchemaContext) keyChild).fromString(val);
+                        builder.addKeyLeaf(keyEleName, namespace, valObject);
+                    }
                 }
             } else {
                 throw new IllegalArgumentException(
@@ -188,6 +193,7 @@
         } catch (IllegalArgumentException e) {
             throw new IllegalArgumentException(e.getMessage());
         }
+
         builder.appInfo(child);
         return builder;
     }
@@ -211,8 +217,9 @@
         info.setResourceIdBuilder(null);
         info.setParentResourceIdBldr(rIdBldr);
         SchemaId sId = node.getSchemaId();
+        // Creating a dummy node
         InnerNode.Builder dBldr = InnerNode.builder(
-                sId.name(), sId.namespace());
+                sId.name(), sId.namespace()).type(node.getType());
         dBldr.appInfo(info);
         return dBldr;
     }
@@ -264,23 +271,30 @@
                                       String name, String namespace,
                                       String value, DataNode.Type type) {
         try {
+            Object valObject;
             SchemaContext node;
             ExtResourceIdBldr rIdBldr;
             HelperContext nodeInfo;
+            boolean initWithRId = false;
             HelperContext info = (HelperContext) builder.appInfo();
             ExtResourceIdBldr curBldr = info.getResourceIdBuilder();
-            boolean isCreate = false;
+
             if (curBldr != null) {
                 rIdBldr = info.getResourceIdBuilder();
                 node = (SchemaContext) rIdBldr.appInfo();
-                isCreate = true;
+                nodeInfo = new HelperContext();
+                initWithRId = true;
             } else {
+                // If data node is initialized by resource id.
                 node = (SchemaContext) info.getParentResourceIdBldr().appInfo();
                 rIdBldr = info.getParentResourceIdBldr();
+                nodeInfo = info;
             }
+
             SchemaContext childSchema = getChildSchemaContext(
                     node, name, namespace);
             DataNode.Type nodeType = childSchema.getType();
+
             if (type != null && !nodeType.equals(type)) {
                 throw new IllegalArgumentException(
                         errorMsg(FMT_NOT_EXIST, name));
@@ -289,15 +303,43 @@
             // Updating the namespace
             namespace = childSchema.getSchemaId().namespace();
             updateResourceId(rIdBldr, name, value, childSchema, nodeType);
-            Object valObject;
-            if (isCreate) {
+
+            if (!initWithRId) {
+                /*
+                 * Adding first data node in case of if data node initialized
+                 * with resource id builder.
+                 */
+                // TODO check based on type, handle leaf without value scenario
+                // also handle list without key leaf scenario.
                 switch (nodeType) {
 
-                    case SINGLE_INSTANCE_NODE:
-                    case MULTI_INSTANCE_NODE:
-                        builder = builder.createChildBuilder(name, namespace)
-                                .type(nodeType);
+                    case SINGLE_INSTANCE_LEAF_VALUE_NODE:
+                        if (((YangLeaf) childSchema).isKeyLeaf()) {
+                            throw new IllegalArgumentException(E_RESID);
+                        }
+                        valObject = ((LeafSchemaContext) childSchema)
+                                .fromString(value);
+                        builder = LeafNode.builder(name, namespace).type(nodeType)
+                                .value(valObject);
                         break;
+                    case MULTI_INSTANCE_LEAF_VALUE_NODE:
+                        valObject = ((LeafSchemaContext) childSchema)
+                                .fromString(value);
+                        builder = LeafNode.builder(name, namespace).type(nodeType)
+                                .value(valObject);
+                        builder = builder.addLeafListValue(valObject);
+                        break;
+                    default:
+                    /*
+                     * Can't update the node key in dummy data node as
+                     * keybuilder will be initialized only once when
+                     * InnerNode.builder call is made with name and namespace.
+                     */
+                        builder = InnerNode.builder(name, namespace).type(nodeType);
+                        break;
+                }
+            } else {
+                switch (nodeType) {
                     case SINGLE_INSTANCE_LEAF_VALUE_NODE:
                         valObject = ((LeafSchemaContext) childSchema)
                                 .fromString(value);
@@ -312,19 +354,15 @@
                         valObject = ((LeafSchemaContext) childSchema)
                                 .fromString(value);
                         builder = builder.createChildBuilder(
-                                name, namespace, valObject).type(nodeType)
-                                .addLeafListValue(valObject);
+                                name, namespace, valObject).type(nodeType);
+                        builder = builder.addLeafListValue(valObject);
                         break;
                     default:
-                        throw new IllegalArgumentException(
-                                errorMsg(FMT_NOT_EXIST, name));
+                        builder = builder.createChildBuilder(name, namespace)
+                                .type(nodeType);
                 }
-
-                nodeInfo = new HelperContext();
-            } else {
-                builder.type(nodeType);
-                nodeInfo = info;
             }
+
             nodeInfo.setResourceIdBuilder(rIdBldr);
             builder.appInfo(nodeInfo);
         } catch (IllegalArgumentException e) {
@@ -343,6 +381,9 @@
      */
     public static ResourceId getResourceId(Builder builder) {
         HelperContext info = (HelperContext) builder.appInfo();
+        if (info.getParentResourceIdBldr() != null) {
+            return info.getParentResourceIdBldr().getResourceId();
+        }
         return info.getResourceIdBuilder().getResourceId();
     }
 
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 8b8c058..b17981a 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
@@ -29,7 +29,9 @@
 import org.onosproject.yang.model.ResourceId;
 import org.onosproject.yang.model.SchemaContext;
 import org.onosproject.yang.model.SchemaId;
+import org.onosproject.yang.runtime.helperutils.DataNodeListener;
 
+import java.util.ArrayList;
 import java.util.List;
 
 import static org.junit.Assert.assertEquals;
@@ -38,8 +40,9 @@
 import static org.onosproject.yang.model.DataNode.Type.MULTI_INSTANCE_LEAF_VALUE_NODE;
 import static org.onosproject.yang.model.DataNode.Type.SINGLE_INSTANCE_LEAF_VALUE_NODE;
 import static org.onosproject.yang.model.DataNode.Type.SINGLE_INSTANCE_NODE;
+import static org.onosproject.yang.runtime.helperutils.DefaultDataNodeWalker.walk;
 
-public final class TestUtils {
+public final class TestUtils implements DataNodeListener {
 
     /**
      * Restricts creation of test utils instance.
@@ -47,6 +50,37 @@
     private TestUtils() {
     }
 
+    public static final String PERIOD = ".";
+
+    // Logger list is used for walker testing.
+    private static final List<String> LOGGER = new ArrayList<>();
+
+    @Override
+    public void enterDataNode(DataNode node) {
+        LOGGER.add("Entry Node is " + node.key().schemaId().name() + PERIOD);
+    }
+
+    @Override
+    public void exitDataNode(DataNode node) {
+        LOGGER.add("Exit Node is " + node.key().schemaId().name() + PERIOD);
+    }
+
+    /**
+     * Returns the LOGGER with log for testing the YDT walker.
+     *
+     * @return list of logs
+     */
+    public static List<String> getLogger() {
+        return LOGGER;
+    }
+
+    /**
+     * Clear the LOGGER array.
+     */
+    public static void resetLogger() {
+        LOGGER.clear();
+    }
+
     /**
      * Checks the schema context values of given leaf node.
      */
@@ -135,7 +169,12 @@
                     j++;
                 }
             } else if (k instanceof LeafListKey) {
-                val = ((LeafListKey) k).value().toString();
+                if (((LeafListKey) k).value() == null) {
+                    assertNull(valA[j]);
+                    val = null;
+                } else {
+                    val = ((LeafListKey) k).value().toString();
+                }
             }
             if (val != null) {
                 assertEquals(val, valA[j]);
@@ -162,15 +201,19 @@
         assertEquals(id.name(), n);
         assertEquals(id.namespace(), ns);
         if (node instanceof InnerNode) {
-            assertEquals(((InnerNode) node).type(), type);
+            assertEquals(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);
+            assertEquals(node.type(), type);
+            if (((LeafNode) node).value() == null) {
+                assertNull(value);
+            } else {
+                assertEquals(((LeafNode) node).value().toString(), value);
+            }
         }
     }
 
@@ -189,4 +232,22 @@
         assertEquals(id.namespace(), ns);
         assertEquals(key.leafValue().toString(), v);
     }
+
+    /**
+     * Walks in the given built data tree and validates it.
+     */
+    public static void walkINTree(DataNode node,
+                                  String[] expected) {
+        resetLogger();
+
+        TestUtils utils = new TestUtils();
+        // Assign root node as starting node to walk the whole tree.
+        walk(utils, node);
+        // Logger list is used for walker testing.
+        List<String> logger = getLogger();
+
+        for (int i = 0; i < expected.length; i++) {
+            assertEquals(expected[i], logger.get(i));
+        }
+    }
 }
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeIetfNetTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeIetfNetTest.java
index df125bc..43b75b2 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeIetfNetTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeIetfNetTest.java
@@ -26,6 +26,7 @@
 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.walkINTree;
 import static org.onosproject.yang.runtime.impl.schemacontext.SchemaContextTest.IETFNS;
 import static org.onosproject.yang.runtime.impl.TestUtils.validateResourceId;
 
@@ -63,6 +64,38 @@
     String[] nsA;
     String[] valA;
 
+    private static final String[] EXPECTED = {
+            "Entry Node is /.",
+            "Entry Node is networks.",
+            "Entry Node is network.",
+            "Entry Node is network-id.",
+            "Exit Node is network-id.",
+            "Entry Node is supporting-network.",
+            "Entry Node is network-ref.",
+            "Exit Node is network-ref.",
+            "Exit Node is supporting-network.",
+            "Entry Node is node.",
+            "Entry Node is node-id.",
+            "Exit Node is node-id.",
+            "Entry Node is supporting-node.",
+            "Entry Node is network-ref.",
+            "Exit Node is network-ref.",
+            "Entry Node is node-ref.",
+            "Exit Node is node-ref.",
+            "Exit Node is supporting-node.",
+            "Exit Node is node.",
+            "Exit Node is network.",
+            "Exit Node is networks.",
+            "Entry Node is networks-state.",
+            "Entry Node is network.",
+            "Entry Node is network-ref.",
+            "Exit Node is network-ref.",
+            "Entry Node is server-provided.",
+            "Exit Node is server-provided.",
+            "Exit Node is network.",
+            "Exit Node is networks-state.",
+            "Exit Node is /.",
+    };
     /**
      * Test add to data node builder.
      */
@@ -129,15 +162,19 @@
         value = "network5";
         dBlr = addDataNode(dBlr, "network-ref", null, value, null);
         dBlr = exitDataNode(dBlr);
-
         // Adding leaf server-provided
         value = "true";
         dBlr = addDataNode(dBlr, "server-provided", null, value, null);
+        dBlr = exitDataNode(dBlr);
+        dBlr = exitDataNode(dBlr);
+        dBlr = exitDataNode(dBlr);
 
         //Tree validation
         nA = new String[]{"/", "networks", "network", "network-id", ""};
         nsA = new String[]{null, IETFNS, IETFNS, IETFNS, ""};
         valA = new String[]{"network1", ""};
         validateResourceId(nA, nsA, valA, id);
+        DataNode node = dBlr.build();
+        walkINTree(dBlr.build(), EXPECTED);
     }
 }
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeLeafListTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeLeafListTest.java
new file mode 100644
index 0000000..57618b9
--- /dev/null
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeLeafListTest.java
@@ -0,0 +1,99 @@
+/*
+ * 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.helperutils.HelperContext;
+import org.onosproject.yang.runtime.impl.TestYangSerializerContext;
+
+import static org.onosproject.yang.model.DataNode.Type.MULTI_INSTANCE_LEAF_VALUE_NODE;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.addDataNode;
+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.validateDataNode;
+import static org.onosproject.yang.runtime.impl.TestUtils.validateResourceId;
+import static org.onosproject.yang.runtime.impl.TestUtils.walkINTree;
+
+/**
+ * Tests the serializer helper methods.
+ */
+public class AddToDataNodeLeafListTest {
+
+    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;
+
+    private static final String[] EXPECTED = {
+            "Entry Node is leaf1.",
+            "Exit Node is leaf1."
+    };
+
+    /**
+     * Test add to data node after initializing it with resource builder.
+     */
+    @Test
+    public void addToDataLeafListTest() {
+
+        ResourceId.Builder rIdBlr = initializeResourceId(context);
+        dBlr = initializeDataNode(rIdBlr);
+        value = "0";
+        dBlr = addDataNode(dBlr, "leaf1", LNS, value, null);
+        info = (HelperContext) dBlr.appInfo();
+        id = getResourceId(dBlr);
+
+        //Tree validation
+        nA = new String[]{"/", "leaf1"};
+        nsA = new String[]{null, LNS};
+        valA = new String[]{"0"};
+        validateResourceId(nA, nsA, valA, id);
+
+        DataNode node = dBlr.build();
+        validateDataNode(node, "leaf1", LNS, MULTI_INSTANCE_LEAF_VALUE_NODE,
+                         false, "0");
+        walkINTree(node, EXPECTED);
+    }
+}
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeList1Test.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeList1Test.java
new file mode 100644
index 0000000..3ce0be0
--- /dev/null
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeList1Test.java
@@ -0,0 +1,179 @@
+/*
+ * 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_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.helperutils.SerializerHelper.initializeResourceId;
+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;
+import static org.onosproject.yang.runtime.impl.TestUtils.walkINTree;
+
+/**
+ * Tests the serializer helper methods.
+ */
+public class AddToDataNodeList1Test {
+
+
+    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;
+
+    private static final String[] EXPECTED = {
+            "Entry Node is l1.",
+            "Entry Node is k1.",
+            "Exit Node is k1.",
+            "Entry Node is k2.",
+            "Exit Node is k2.",
+            "Entry Node is c1.",
+            "Entry Node is leaf_c1.",
+            "Exit Node is leaf_c1.",
+            "Exit Node is c1.",
+            "Entry Node is k3.",
+            "Exit Node is k3.",
+            "Exit Node is l1.",
+    };
+
+    /**
+     * Test add to data node builder.
+     */
+    @Test
+    public void addToDataListTest() throws IOException {
+        ResourceId.Builder rIdBlr = initializeResourceId(context);
+        dBlr = initializeDataNode(rIdBlr);
+
+        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, "leaf_c1", 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);
+
+        //Tree validation
+        nA = new String[]{"/", "l1", "k1", "k2", "k3", "c1", "leaf_c1"};
+        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);
+
+        // Validating the data node.
+        DataNode node = dBlr.build();
+
+        validateDataNode(node, "l1", LNS, MULTI_INSTANCE_NODE,
+                         true, null);
+        Iterator<KeyLeaf> keyIt = ((ListKey) node.key())
+                .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) node).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(), "leaf_c1", LNS,
+                         SINGLE_INSTANCE_LEAF_VALUE_NODE, false, "0");
+        walkINTree(node, EXPECTED);
+    }
+}
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
index e5e6579..510ca2e 100644
--- 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
@@ -41,6 +41,7 @@
 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;
+import static org.onosproject.yang.runtime.impl.TestUtils.walkINTree;
 
 /**
  * Tests the serializer helper methods.
@@ -78,15 +79,38 @@
     String[] nsA;
     String[] valA;
 
+    private static final String[] EXPECTED = {
+            "Entry Node is /.",
+            "Entry Node is l1.",
+            "Entry Node is k1.",
+            "Exit Node is k1.",
+            "Entry Node is k2.",
+            "Exit Node is k2.",
+            "Entry Node is c1.",
+            "Entry Node is leaf_c1.",
+            "Exit Node is leaf_c1.",
+            "Exit Node is c1.",
+            "Entry Node is k3.",
+            "Exit Node is k3.",
+            "Exit Node is l1.",
+            "Entry Node is leaf1.",
+            "Exit Node is leaf1.",
+            "Entry Node is leaf1.",
+            "Exit Node is leaf1.",
+            "Entry Node is leaf1.",
+            "Exit Node is leaf1.",
+            "Entry Node is leaf1.",
+            "Exit Node is leaf1.",
+            "Exit Node is /."
+    };
+
     /**
      * Test add to data node builder.
      */
     @Test
     public void addToDataListTest() throws IOException {
-
-        Object ob;
+        ResourceId id;
         dBlr = initializeDataNode(context);
-
         dBlr = addDataNode(dBlr, "l1", LNS, value, null);
         value = "1";
         dBlr = addDataNode(dBlr, "k1", null, value, null);
@@ -97,7 +121,7 @@
         value = null;
         dBlr = addDataNode(dBlr, "c1", null, value, null);
         value = "0";
-        dBlr = addDataNode(dBlr, "l1", null, value, null);
+        dBlr = addDataNode(dBlr, "leaf_c1", null, value, null);
 
         info = (HelperContext) dBlr.appInfo();
         id = getResourceId(dBlr);
@@ -125,32 +149,33 @@
         value = "3";
         dBlr = addDataNode(dBlr, "leaf1", LNS, value, null);
         dBlr = exitDataNode(dBlr);
-        value = "4";
+        value = null;
         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", ""};
+        nA = new String[]{"/", "l1", "k1", "k2", "k3", "c1", "leaf_c1"};
+        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", ""};
+        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", ""};
+        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", ""};
+        nA = new String[]{"/", "leaf1"};
+        nsA = new String[]{null, LNS};
+        valA = new String[]{null};
         validateResourceId(nA, nsA, valA, id3);
 
+        // Validating the data node.
         DataNode node = dBlr.build();
         validateDataNode(node, "/", null, SINGLE_INSTANCE_NODE, true, null);
 
@@ -180,7 +205,7 @@
 
         Iterator<Map.Entry<NodeKey, DataNode>> it2;
         it2 = ((InnerNode) n1).childNodes().entrySet().iterator();
-        validateDataNode(it2.next().getValue(), "l1", LNS,
+        validateDataNode(it2.next().getValue(), "leaf_c1", LNS,
                          SINGLE_INSTANCE_LEAF_VALUE_NODE, false, "0");
         validateDataNode(it.next().getValue(), "leaf1", LNS,
                          MULTI_INSTANCE_LEAF_VALUE_NODE, false, "1");
@@ -189,6 +214,7 @@
         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");
+                         MULTI_INSTANCE_LEAF_VALUE_NODE, false, null);
+        walkINTree(dBlr.build(), EXPECTED);
     }
 }
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeLogisticTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeLogisticTest.java
new file mode 100644
index 0000000..fc088d5
--- /dev/null
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeLogisticTest.java
@@ -0,0 +1,423 @@
+/*
+ * 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.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;
+import static org.onosproject.yang.runtime.impl.TestUtils.walkINTree;
+
+/**
+ * Tests the serializer helper methods.
+ */
+public class AddToDataNodeLogisticTest {
+
+    public static final String LMNG = "yrt.Logistics-manager";
+
+    TestYangSerializerContext context = new TestYangSerializerContext();
+
+    /*
+     * Reference for data node info.
+     */
+    HelperContext info;
+
+    /*
+     * Reference for data node builder.
+     */
+    DataNode.Builder dBlr;
+
+    /*
+     * Reference for resource id.
+     */
+    ResourceId id;
+
+    /*
+     * Reference for the value.
+     */
+    String value;
+
+    /*
+     * Reference for string array to used for resource id testing.
+     */
+    String[] nA;
+    String[] nsA;
+    String[] valA;
+
+    private static final String[] EXPECTED = {
+            "Entry Node is /.",
+
+            "Entry Node is Customs-supervisor.",
+            "Exit Node is Customs-supervisor.",
+
+            "Entry Node is Merchandiser-supervisor.",
+            "Exit Node is Merchandiser-supervisor.",
+
+            "Entry Node is Material-supervisor.",
+            "Entry Node is name.",
+            "Exit Node is name.",
+            "Entry Node is departmentId.",
+            "Exit Node is departmentId.",
+            "Exit Node is Material-supervisor.",
+
+            "Entry Node is Material-supervisor.",
+            "Entry Node is name.",
+            "Exit Node is name.",
+            "Entry Node is departmentId.",
+            "Exit Node is departmentId.",
+            "Exit Node is Material-supervisor.",
+
+            "Entry Node is Material-supervisor.",
+            "Entry Node is name.",
+            "Exit Node is name.",
+            "Entry Node is departmentId.",
+            "Exit Node is departmentId.",
+            "Exit Node is Material-supervisor.",
+
+            "Entry Node is Purchasing-supervisor.",
+
+            "Entry Node is purchasing-specialist.",
+            "Exit Node is purchasing-specialist.",
+
+            "Entry Node is support.",
+            "Exit Node is support.",
+
+            "Entry Node is support.",
+            "Exit Node is support.",
+
+            "Entry Node is support.",
+            "Exit Node is support.",
+
+            "Exit Node is Purchasing-supervisor.",
+
+            "Entry Node is Warehouse-supervisor.",
+            "Exit Node is Warehouse-supervisor.",
+
+            "Entry Node is Warehouse-supervisor.",
+            "Exit Node is Warehouse-supervisor.",
+
+            "Entry Node is Warehouse-supervisor.",
+            "Exit Node is Warehouse-supervisor.",
+
+            "Entry Node is Warehouse-supervisor.",
+            "Exit Node is Warehouse-supervisor.",
+
+            "Entry Node is Trading-supervisor.",
+            "Exit Node is Trading-supervisor.",
+
+            "Entry Node is Employee-id.",
+            "Exit Node is Employee-id.",
+
+            "Entry Node is Employee-id.",
+            "Exit Node is Employee-id.",
+
+            "Entry Node is Employee-id.",
+            "Exit Node is Employee-id.",
+
+            "Entry Node is Employee-id.",
+            "Exit Node is Employee-id.",
+            "Exit Node is /."
+    };
+
+    /**
+     * Test add to data node builder logistic manager module.
+     */
+    @Test
+    public void addToDataTest() {
+
+        dBlr = getLogisticModuleDataNode();
+
+        walkINTree(dBlr.build(), EXPECTED);
+        // Validating the data node.
+        DataNode node = dBlr.build();
+        validateDataNode(node, "/", null, SINGLE_INSTANCE_NODE, true, null);
+
+        Map<NodeKey, DataNode> childMap = ((InnerNode) node).childNodes();
+        Iterator<Map.Entry<NodeKey, DataNode>> it = childMap.entrySet().iterator();
+        Map.Entry<NodeKey, DataNode> n = it.next();
+        value = "1";
+        validateDataNode(n.getValue(), "Customs-supervisor", LMNG,
+                         SINGLE_INSTANCE_LEAF_VALUE_NODE, false, value);
+
+        n = it.next();
+        value = "1";
+        validateDataNode(n.getValue(), "Merchandiser-supervisor", LMNG,
+                         SINGLE_INSTANCE_LEAF_VALUE_NODE, false, value);
+
+        n = it.next();
+        value = null;
+        validateDataNode(n.getValue(), "Material-supervisor", LMNG,
+                         MULTI_INSTANCE_NODE, true, value);
+
+        Iterator<KeyLeaf> keyIt = ((ListKey) n.getKey()).keyLeafs().iterator();
+        validateLeafDataNode(keyIt.next(), "name", LMNG, "abc");
+
+        Iterator<Map.Entry<NodeKey, DataNode>> it1;
+        it1 = ((InnerNode) n.getValue()).childNodes().entrySet().iterator();
+        validateDataNode(it1.next().getValue(), "name", LMNG,
+                         SINGLE_INSTANCE_LEAF_VALUE_NODE, false, "abc");
+        validateDataNode(it1.next().getValue(), "departmentId", LMNG,
+                         SINGLE_INSTANCE_LEAF_VALUE_NODE, false, "dep-1");
+
+        n = it.next();
+        value = null;
+        validateDataNode(n.getValue(), "Material-supervisor", LMNG,
+                         MULTI_INSTANCE_NODE, true, value);
+
+        keyIt = ((ListKey) n.getKey()).keyLeafs().iterator();
+        validateLeafDataNode(keyIt.next(), "name", LMNG, "abc1");
+        it1 = ((InnerNode) n.getValue()).childNodes().entrySet().iterator();
+        validateDataNode(it1.next().getValue(), "name", LMNG,
+                         SINGLE_INSTANCE_LEAF_VALUE_NODE, false, "abc1");
+        validateDataNode(it1.next().getValue(), "departmentId", LMNG,
+                         SINGLE_INSTANCE_LEAF_VALUE_NODE, false, "dep-1");
+
+        n = it.next();
+        value = null;
+        validateDataNode(n.getValue(), "Material-supervisor", LMNG,
+                         MULTI_INSTANCE_NODE, true, value);
+
+        keyIt = ((ListKey) n.getKey()).keyLeafs().iterator();
+        validateLeafDataNode(keyIt.next(), "name", LMNG, "abc2");
+        it1 = ((InnerNode) n.getValue()).childNodes().entrySet().iterator();
+        validateDataNode(it1.next().getValue(), "name", LMNG,
+                         SINGLE_INSTANCE_LEAF_VALUE_NODE, false, "abc2");
+        validateDataNode(it1.next().getValue(), "departmentId", LMNG,
+                         SINGLE_INSTANCE_LEAF_VALUE_NODE, false, "dep-1");
+
+        n = it.next();
+        value = null;
+        validateDataNode(n.getValue(), "Purchasing-supervisor", LMNG,
+                         SINGLE_INSTANCE_NODE, true, value);
+
+        it1 = ((InnerNode) n.getValue()).childNodes().entrySet().iterator();
+        validateDataNode(it1.next().getValue(), "purchasing-specialist", LMNG,
+                         SINGLE_INSTANCE_LEAF_VALUE_NODE, false, "xyz");
+        validateDataNode(it1.next().getValue(), "support", LMNG,
+                         MULTI_INSTANCE_LEAF_VALUE_NODE, false, "helpdesk");
+        validateDataNode(it1.next().getValue(), "support", LMNG,
+                         MULTI_INSTANCE_LEAF_VALUE_NODE, false, "helpdesk1");
+        validateDataNode(it1.next().getValue(), "support", LMNG,
+                         MULTI_INSTANCE_LEAF_VALUE_NODE, false, "helpdesk2");
+
+        n = it.next();
+        value = "1";
+        validateDataNode(n.getValue(), "Warehouse-supervisor", LMNG,
+                         MULTI_INSTANCE_LEAF_VALUE_NODE, false, value);
+
+        n = it.next();
+        value = "2";
+        validateDataNode(n.getValue(), "Warehouse-supervisor", LMNG,
+                         MULTI_INSTANCE_LEAF_VALUE_NODE, false, value);
+
+        n = it.next();
+        value = "3";
+        validateDataNode(n.getValue(), "Warehouse-supervisor", LMNG,
+                         MULTI_INSTANCE_LEAF_VALUE_NODE, false, value);
+
+        n = it.next();
+        value = "4";
+        validateDataNode(n.getValue(), "Warehouse-supervisor", LMNG,
+                         MULTI_INSTANCE_LEAF_VALUE_NODE, false, value);
+
+        n = it.next();
+        value = "1";
+        validateDataNode(n.getValue(), "Trading-supervisor", LMNG,
+                         SINGLE_INSTANCE_LEAF_VALUE_NODE, false, value);
+
+        n = it.next();
+        value = "1";
+        validateDataNode(n.getValue(), "Employee-id", LMNG,
+                         MULTI_INSTANCE_LEAF_VALUE_NODE, false, value);
+
+        n = it.next();
+        value = "2";
+        validateDataNode(n.getValue(), "Employee-id", LMNG,
+                         MULTI_INSTANCE_LEAF_VALUE_NODE, false, value);
+
+        n = it.next();
+        value = "3";
+        validateDataNode(n.getValue(), "Employee-id", LMNG,
+                         MULTI_INSTANCE_LEAF_VALUE_NODE, false, value);
+
+        n = it.next();
+        value = "4";
+        validateDataNode(n.getValue(), "Employee-id", LMNG,
+                         MULTI_INSTANCE_LEAF_VALUE_NODE, false, value);
+    }
+
+    /**
+     * Returns the logistic module data tree.
+     */
+    public DataNode.Builder getLogisticModuleDataNode() {
+        dBlr = initializeDataNode(context);
+
+        value = "1";
+        dBlr = addDataNode(dBlr, "Customs-supervisor", LMNG, value, null);
+        id = getResourceId(dBlr);
+        nA = new String[]{"/", "Customs-supervisor"};
+        nsA = new String[]{null, LMNG};
+        valA = new String[]{"1"};
+        validateResourceId(nA, nsA, valA, id);
+        dBlr = exitDataNode(dBlr);
+
+        dBlr = addDataNode(dBlr, "Merchandiser-supervisor", LMNG, value, null);
+        info = (HelperContext) dBlr.appInfo();
+        id = getResourceId(dBlr);
+        nA = new String[]{"/", "Merchandiser-supervisor"};
+        nsA = new String[]{null, LMNG};
+        valA = new String[]{"1"};
+        validateResourceId(nA, nsA, valA, id);
+
+        dBlr = exitDataNode(dBlr);
+
+        value = null;
+        dBlr = addDataNode(dBlr, "Material-supervisor", LMNG, value, null);
+
+        value = "abc";
+        dBlr = addDataNode(dBlr, "name", LMNG, value, null);
+        dBlr = exitDataNode(dBlr);
+
+        value = "dep-1";
+        dBlr = addDataNode(dBlr, "departmentId", null, value, null);
+        info = (HelperContext) dBlr.appInfo();
+        id = getResourceId(dBlr);
+        nA = new String[]{"/", "Material-supervisor", "name", "departmentId"};
+        nsA = new String[]{null, LMNG, LMNG, LMNG};
+        valA = new String[]{"abc", "dep-1"};
+        validateResourceId(nA, nsA, valA, id);
+        dBlr = exitDataNode(dBlr);
+        dBlr = exitDataNode(dBlr);
+
+        id = getResourceId(dBlr);
+        nA = new String[]{"/"};
+        nsA = new String[]{null};
+        valA = new String[]{};
+        validateResourceId(nA, nsA, valA, id);
+
+        value = null;
+        dBlr = addDataNode(dBlr, "Material-supervisor", LMNG, value, null);
+
+        value = "abc1";
+        dBlr = addDataNode(dBlr, "name", LMNG, value, null);
+        dBlr = exitDataNode(dBlr);
+
+        value = "dep-1";
+        dBlr = addDataNode(dBlr, "departmentId", null, value, null);
+        dBlr = exitDataNode(dBlr);
+        dBlr = exitDataNode(dBlr);
+
+        value = null;
+        dBlr = addDataNode(dBlr, "Material-supervisor", LMNG, value, null);
+
+        value = "abc2";
+        dBlr = addDataNode(dBlr, "name", LMNG, value, null);
+        dBlr = exitDataNode(dBlr);
+
+        value = "dep-1";
+        dBlr = addDataNode(dBlr, "departmentId", null, value, null);
+        id = getResourceId(dBlr);
+        nA = new String[]{"/", "Material-supervisor", "name", "departmentId"};
+        nsA = new String[]{null, LMNG, LMNG, LMNG};
+        valA = new String[]{"abc2", "dep-1"};
+        validateResourceId(nA, nsA, valA, id);
+        dBlr = exitDataNode(dBlr);
+        dBlr = exitDataNode(dBlr);
+
+        value = null;
+        dBlr = addDataNode(dBlr, "Purchasing-supervisor", LMNG, value, null);
+
+        value = "xyz";
+        dBlr = addDataNode(dBlr, "purchasing-specialist", LMNG, value, null);
+        dBlr = exitDataNode(dBlr);
+
+        value = "helpdesk";
+        dBlr = addDataNode(dBlr, "support", null, value, null);
+        dBlr = exitDataNode(dBlr);
+
+        value = "helpdesk1";
+        dBlr = addDataNode(dBlr, "support", null, value, null);
+        dBlr = exitDataNode(dBlr);
+
+        value = "helpdesk2";
+        dBlr = addDataNode(dBlr, "support", null, value, null);
+        id = getResourceId(dBlr);
+        nA = new String[]{"/", "Purchasing-supervisor", "support"};
+        nsA = new String[]{null, LMNG, LMNG};
+        valA = new String[]{"helpdesk2"};
+        validateResourceId(nA, nsA, valA, id);
+        dBlr = exitDataNode(dBlr);
+        dBlr = exitDataNode(dBlr);
+
+        value = "1";
+        dBlr = addDataNode(dBlr, "Warehouse-supervisor", LMNG, value, null);
+        dBlr = exitDataNode(dBlr);
+
+        value = "2";
+        dBlr = addDataNode(dBlr, "Warehouse-supervisor", LMNG, value, null);
+        dBlr = exitDataNode(dBlr);
+
+        value = "3";
+        dBlr = addDataNode(dBlr, "Warehouse-supervisor", LMNG, value, null);
+        dBlr = exitDataNode(dBlr);
+
+        value = "4";
+        dBlr = addDataNode(dBlr, "Warehouse-supervisor", LMNG, value, null);
+        dBlr = exitDataNode(dBlr);
+
+        value = "1";
+        dBlr = addDataNode(dBlr, "Trading-supervisor", LMNG, value, null);
+        dBlr = exitDataNode(dBlr);
+
+        value = "1";
+        dBlr = addDataNode(dBlr, "Employee-id", LMNG, value, null);
+        dBlr = exitDataNode(dBlr);
+
+        value = "2";
+        dBlr = addDataNode(dBlr, "Employee-id", LMNG, value, null);
+        dBlr = exitDataNode(dBlr);
+
+        value = "3";
+        dBlr = addDataNode(dBlr, "Employee-id", LMNG, value, null);
+        dBlr = exitDataNode(dBlr);
+
+        value = "4";
+        dBlr = addDataNode(dBlr, "Employee-id", LMNG, value, null);
+        dBlr = exitDataNode(dBlr);
+        return dBlr;
+    }
+}
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeRidTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeRidTest.java
index f2a38ad..e578cdf 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeRidTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeRidTest.java
@@ -22,11 +22,13 @@
 import org.onosproject.yang.runtime.helperutils.HelperContext;
 import org.onosproject.yang.runtime.impl.TestYangSerializerContext;
 
+import static org.onosproject.yang.model.DataNode.Type.SINGLE_INSTANCE_LEAF_VALUE_NODE;
 import static org.onosproject.yang.runtime.helperutils.SerializerHelper.addDataNode;
 import static org.onosproject.yang.runtime.helperutils.SerializerHelper.addToResourceId;
 import static org.onosproject.yang.runtime.helperutils.SerializerHelper.getResourceId;
 import static org.onosproject.yang.runtime.helperutils.SerializerHelper.initializeDataNode;
 import static org.onosproject.yang.runtime.helperutils.SerializerHelper.initializeResourceId;
+import static org.onosproject.yang.runtime.impl.TestUtils.validateDataNode;
 import static org.onosproject.yang.runtime.impl.TestUtils.validateResourceId;
 
 /**
@@ -75,15 +77,19 @@
         rIdBlr = addToResourceId(rIdBlr, "l1", LNS, value);
         rIdBlr = addToResourceId(rIdBlr, "c1", LNS, value);
         dBlr = initializeDataNode(rIdBlr);
-        value = "0";
-        dBlr = addDataNode(dBlr, "l1", null, value, null);
+        value = null;
+        dBlr = addDataNode(dBlr, "leaf_c1", null, value, null);
         info = (HelperContext) dBlr.appInfo();
         id = getResourceId(dBlr);
 
         //Tree validation
-        nA = new String[]{"/", "l1", "c1", "l1", ""};
-        nsA = new String[]{null, LNS, LNS, LNS, ""};
-        valA = new String[]{"0", ""};
+        nA = new String[]{"/", "l1", "c1", "leaf_c1"};
+        nsA = new String[]{null, LNS, LNS, LNS};
+        valA = new String[]{null};
         validateResourceId(nA, nsA, valA, id);
+
+        DataNode node = dBlr.build();
+        validateDataNode(node, "leaf_c1", LNS, SINGLE_INSTANCE_LEAF_VALUE_NODE,
+                         false, null);
     }
 }
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToResourceIdTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToResourceIdTest.java
index 271a649..bb13fd2 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToResourceIdTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToResourceIdTest.java
@@ -66,7 +66,7 @@
     String[] valA;
 
     /**
-     * Test add to data node builder.
+     * Test add to resource id with all list key.
      */
     @Test
     public void addToDataListTest() {
@@ -80,9 +80,27 @@
         ResourceId id = rIdBlr.build();
 
         //Tree validation
-        nA = new String[]{"/", "l1", "k1", "k2", "k3", ""};
-        nsA = new String[]{null, LNS, LNS, LNS, LNS, ""};
-        valA = new String[]{"1", "2", "3", ""};
+        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);
+    }
+
+    /**
+     * Test add to resource id without any key.
+     */
+    @Test
+    public void addToDataList1Test() {
+
+        ResourceId.Builder rIdBlr = initializeResourceId(context);
+        List<String> valueSet = null;
+        rIdBlr = addToResourceId(rIdBlr, "l1", LNS, valueSet);
+        ResourceId id = rIdBlr.build();
+
+        //Tree validation
+        nA = new String[]{"/", "l1"};
+        nsA = new String[]{null, LNS};
+        valA = new String[]{};
         validateResourceId(nA, nsA, valA, id);
     }
 }
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/DataNodeInitializationTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/DataNodeInitializationTest.java
index 4c95a74..b5edb5f 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/DataNodeInitializationTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/DataNodeInitializationTest.java
@@ -23,9 +23,13 @@
 import org.onosproject.yang.runtime.helperutils.HelperContext;
 import org.onosproject.yang.runtime.impl.TestYangSerializerContext;
 
+import static org.onosproject.yang.model.DataNode.Type.SINGLE_INSTANCE_NODE;
+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.checkRootLevelContext;
+import static org.onosproject.yang.runtime.impl.TestUtils.validateDataNode;
+import static org.onosproject.yang.runtime.impl.TestUtils.validateResourceId;
 
 /**
  * Tests the initialize data node methods in serializer helper.
@@ -49,6 +53,19 @@
      */
     DataNode.Builder dBlr;
 
+    /*
+     * Reference for resource id.
+     */
+    ResourceId id;
+
+
+    /*
+     * Reference for string array to used for resource id testing.
+     */
+    String[] nA;
+    String[] nsA;
+    String[] valA;
+
     /**
      * Checks initialize data node using context.
      */
@@ -59,6 +76,13 @@
         info = (HelperContext) dBlr.appInfo();
         checkRootLevelContext((SchemaContext) info.getResourceIdBuilder()
                 .appInfo());
+        id = getResourceId(dBlr);
+        nA = new String[]{"/"};
+        nsA = new String[]{null};
+        valA = new String[]{};
+        validateResourceId(nA, nsA, valA, id);
+        validateDataNode(dBlr.build(), "/", null,
+                         SINGLE_INSTANCE_NODE, true, null);
     }
 
     /**
@@ -72,5 +96,12 @@
         info = (HelperContext) dBlr.appInfo();
         checkRootLevelContext((SchemaContext) info.getParentResourceIdBldr()
                 .appInfo());
+        id = getResourceId(dBlr);
+        nA = new String[]{"/"};
+        nsA = new String[]{null};
+        valA = new String[]{};
+        validateResourceId(nA, nsA, valA, id);
+        validateDataNode(dBlr.build(), "/", null,
+                         SINGLE_INSTANCE_NODE, true, null);
     }
 }
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/ResourceIdInitializationTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/ResourceIdInitializationTest.java
index 2ef2864..66e8f31 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/ResourceIdInitializationTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/ResourceIdInitializationTest.java
@@ -23,9 +23,9 @@
 
 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.schemacontext.SchemaContextTest.IETFNS;
 import static org.onosproject.yang.runtime.impl.TestUtils.checkRootLevelContext;
 import static org.onosproject.yang.runtime.impl.TestUtils.validateResourceId;
+import static org.onosproject.yang.runtime.impl.schemacontext.SchemaContextTest.IETFNS;
 
 /**
  * Tests the initialize resource id methods in serializer helper.
@@ -71,9 +71,9 @@
         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", ""};
+        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/ResourceIdNegative3Test.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/ResourceIdNegative3Test.java
index a7e39ca..175364a 100644
--- 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
@@ -52,7 +52,7 @@
         valueSet.add("2");
         boolean isExpOccurred = false;
         try {
-            rIdBlr = addToResourceId(rIdBlr, "l1", LNS, valueSet);
+            addToResourceId(rIdBlr, "l1", LNS, valueSet);
         } catch (IllegalArgumentException e) {
             isExpOccurred = true;
             assertEquals(e.getMessage(), E_TOO_FEW);
diff --git a/runtime/src/test/resources/schemaProviderTestYangFiles/Logistics-manager.yang b/runtime/src/test/resources/schemaProviderTestYangFiles/Logistics-manager.yang
new file mode 100644
index 0000000..87c5db6
--- /dev/null
+++ b/runtime/src/test/resources/schemaProviderTestYangFiles/Logistics-manager.yang
@@ -0,0 +1,66 @@
+module Logistics-manager {
+
+    yang-version 1;
+
+    namespace "yrt.Logistics-manager";
+
+    prefix "root";
+
+    organization "ON-LAB";
+
+    description "This module defines for organisation.";
+
+    revision "2016-05-24" {
+        description "Initial revision.";
+    }
+
+    leaf Customs-supervisor {
+        type string;
+        description "name of the customs-supervisor.";
+    }
+
+    leaf Merchandiser-supervisor {
+        type string;
+        description "name of merchandiser-supervisor";
+    }
+
+    list Material-supervisor {
+        key "name";
+        leaf name {
+            type string;
+            description "name of logistics-supervisor";
+        }
+
+        leaf departmentId {
+            type string;
+            description "name of department";
+        }
+    }
+
+    container Purchasing-supervisor {
+        leaf purchasing-specialist {
+            type string;
+            description "name of the purchasing-specialist person";
+        }
+
+        leaf-list support {
+            type string;
+            description "name of the support person";
+        }
+    }
+
+    leaf-list Warehouse-supervisor {
+        type string;
+        description "name of the warehouse-supervisor's";
+    }
+
+    leaf Trading-supervisor {
+        type string;
+        description "name of the trading-supervisor";
+    }
+
+    leaf-list Employee-id {
+        type string;
+        description "list of the employee id";
+    }
+}
\ No newline at end of file
diff --git a/runtime/src/test/resources/schemaProviderTestYangFiles/list.yang b/runtime/src/test/resources/schemaProviderTestYangFiles/list.yang
index 122ce11..2ff07dc 100644
--- a/runtime/src/test/resources/schemaProviderTestYangFiles/list.yang
+++ b/runtime/src/test/resources/schemaProviderTestYangFiles/list.yang
@@ -29,7 +29,7 @@
             }
 
             container c1 {
-                leaf l1 {
+                leaf leaf_c1 {
                   type string;
                 }
             }