[ONOS-5883] Implemention of Serializer Helper Utility

Change-Id: Ifffcdb1ee6de8dfd1a08df9e0b5473651509a6dd
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangList.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangList.java
index 0855b98..deaa24c 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangList.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangList.java
@@ -21,7 +21,7 @@
 import org.onosproject.yang.compiler.datamodel.utils.Parsable;
 import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
 import org.onosproject.yang.model.DataNode;
-import org.onosproject.yang.model.MultiInstanceNodeContext;
+import org.onosproject.yang.model.ListSchemaContext;
 import org.onosproject.yang.model.SchemaContext;
 import org.onosproject.yang.model.SchemaId;
 
@@ -89,7 +89,7 @@
         implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector,
         YangAugmentableNode, YangMustHolder, YangWhenHolder, YangIfFeatureHolder, YangSchemaNode,
         YangIsFilterContentNodes, YangConfig, YangUniqueHolder,
-        YangMaxElementHolder, YangMinElementHolder, SchemaDataNode, MultiInstanceNodeContext {
+        YangMaxElementHolder, YangMinElementHolder, SchemaDataNode, ListSchemaContext {
 
     private static final long serialVersionUID = 806201609L;
 
diff --git a/model/src/main/java/org/onosproject/yang/model/LeafListKey.java b/model/src/main/java/org/onosproject/yang/model/LeafListKey.java
index ba4ab46..4ad39e8 100644
--- a/model/src/main/java/org/onosproject/yang/model/LeafListKey.java
+++ b/model/src/main/java/org/onosproject/yang/model/LeafListKey.java
@@ -43,7 +43,7 @@
      *
      * @return value maintained in the node
      */
-    Object value() {
+    public Object value() {
         return val;
     }
 
@@ -52,7 +52,7 @@
      *
      * @return string representation of value
      */
-    String asString() {
+    public String asString() {
         return val.toString();
     }
 
@@ -115,7 +115,7 @@
          * @param val leaf list value
          * @return builder
          */
-        LeafListKeyBuilder value(Object val) {
+        public LeafListKeyBuilder value(Object val) {
             this.val = val;
             return this;
         }
diff --git a/model/src/main/java/org/onosproject/yang/model/ListKey.java b/model/src/main/java/org/onosproject/yang/model/ListKey.java
index 51ce2f4..297a660 100644
--- a/model/src/main/java/org/onosproject/yang/model/ListKey.java
+++ b/model/src/main/java/org/onosproject/yang/model/ListKey.java
@@ -16,6 +16,8 @@
 
 package org.onosproject.yang.model;
 
+import com.google.common.collect.ImmutableList;
+
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Objects;
@@ -47,8 +49,8 @@
      *
      * @return List of key leaf nodes
      */
-    List<KeyLeaf> keyLeafs() {
-        return keyLeafs;
+    public List<KeyLeaf> keyLeafs() {
+        return ImmutableList.copyOf(keyLeafs);
     }
 
     /**
@@ -130,7 +132,7 @@
          * @param nameSpace key laef namespace
          * @param val       value of key
          */
-        void addKeyLeaf(String name, String nameSpace, Object val) {
+        public void addKeyLeaf(String name, String nameSpace, Object val) {
             KeyLeaf keyLeaf = new KeyLeaf(name, nameSpace, val);
             keyLeafs.add(keyLeaf);
         }
diff --git a/model/src/main/java/org/onosproject/yang/model/ModelConstants.java b/model/src/main/java/org/onosproject/yang/model/ModelConstants.java
index 5439998..76629df 100644
--- a/model/src/main/java/org/onosproject/yang/model/ModelConstants.java
+++ b/model/src/main/java/org/onosproject/yang/model/ModelConstants.java
@@ -19,11 +19,12 @@
 /**
  * Constants used in model package.
  */
-final class ModelConstants {
-    static final String INCOMPLETE_SCHEMA_INFO = "Schema info is not complete";
-    static final String LEAF_IS_TERMINAL = "Leaf must be the terminal node";
-    static final String NON_KEY_LEAF = "Leaf list is not a key of list";
-    static final String NO_KEY_SET = "Resource Identifier is empty";
+public final class ModelConstants {
+    public static final String INCOMPLETE_SCHEMA_INFO = "Schema info is not " +
+            "complete";
+    public static final String LEAF_IS_TERMINAL = "Leaf must be the terminal node";
+    public static final String NON_KEY_LEAF = "Leaf list is not a key of list";
+    public static final String NO_KEY_SET = "Resource Identifier is empty";
 
     // Forbid construction.
     private ModelConstants() {
diff --git a/model/src/main/java/org/onosproject/yang/model/MultiInstanceNodeContext.java b/model/src/main/java/org/onosproject/yang/model/MultiInstanceNodeContext.java
deleted file mode 100644
index 8ebb6b1..0000000
--- a/model/src/main/java/org/onosproject/yang/model/MultiInstanceNodeContext.java
+++ /dev/null
@@ -1,41 +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.model;
-
-import java.util.Set;
-
-/**
- * Representation of multi instance node schema context.
- */
-public interface MultiInstanceNodeContext extends SchemaContext {
-
-    /**
-     * Returns child context.
-     *
-     * @param id schema identifier
-     * @return child schema context
-     * @throws IllegalArgumentException when schema identifier is invalid
-     */
-    SchemaContext getChildContext(SchemaId id);
-
-    /**
-     * Returns ordered set of key leaf name as per the YANG schema.
-     *
-     * @return set of key leaf
-     */
-    Set<String> getKeyLeaf();
-}
diff --git a/model/src/main/java/org/onosproject/yang/model/NodeKey.java b/model/src/main/java/org/onosproject/yang/model/NodeKey.java
index 5149072..863a1e2 100644
--- a/model/src/main/java/org/onosproject/yang/model/NodeKey.java
+++ b/model/src/main/java/org/onosproject/yang/model/NodeKey.java
@@ -158,7 +158,6 @@
          */
         public NodeKey build() {
             checkNotNull(schemaId.name(), INCOMPLETE_SCHEMA_INFO);
-            checkNotNull(schemaId.namespace(), INCOMPLETE_SCHEMA_INFO);
             return new NodeKey(this);
         }
     }
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 5b09d2b..44df822 100644
--- a/model/src/main/java/org/onosproject/yang/model/ResourceId.java
+++ b/model/src/main/java/org/onosproject/yang/model/ResourceId.java
@@ -32,7 +32,7 @@
  * hierarchy to reach a resource in the instance tree.
  */
 
-public final class ResourceId {
+public class ResourceId {
 
     /**
      * List of node keys.
@@ -44,7 +44,7 @@
      *
      * @param builder initialized builder
      */
-    private ResourceId(Builder builder) {
+    public ResourceId(Builder builder) {
         nodeKeyList = builder.nodeKeyList;
     }
 
@@ -113,8 +113,8 @@
          */
         protected Object appInfo;
 
-        private List<NodeKey> nodeKeyList;
-        private NodeKey.NodeKeyBuilder curKeyBuilder = null;
+        protected List<NodeKey> nodeKeyList;
+        protected NodeKey.NodeKeyBuilder curKeyBuilder;
 
         /**
          * Creates an instance of resource identifier builder.
@@ -156,7 +156,7 @@
         /**
          * Validates, build and add current key.
          */
-        private void processCurKey() {
+        protected void processCurKey() {
             if (curKeyBuilder != null) {
                 if (curKeyBuilder instanceof LeafListKey.LeafListKeyBuilder) {
                     throw new ModelException(LEAF_IS_TERMINAL);
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
new file mode 100644
index 0000000..29bdf2c
--- /dev/null
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/helperutils/ExtResourceIdBldr.java
@@ -0,0 +1,76 @@
+/*
+ * 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.LeafListKey.LeafListKeyBuilder;
+import org.onosproject.yang.model.ModelException;
+import org.onosproject.yang.model.NodeKey;
+import org.onosproject.yang.model.ResourceId;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import static org.onosproject.yang.model.ModelConstants.LEAF_IS_TERMINAL;
+
+/**
+ * Representation of an entity which extends the resource identifier to
+ * provide the additional functionality of traversing back in resource id.
+ */
+public final class ExtResourceIdBldr extends ResourceId.Builder {
+
+    private List<NodeKey.NodeKeyBuilder> builders = new LinkedList<>();
+
+    @Override
+    protected void processCurKey() {
+        if (curKeyBuilder != null) {
+            if (curKeyBuilder instanceof LeafListKeyBuilder) {
+                throw new ModelException(LEAF_IS_TERMINAL);
+            }
+            builders.add(curKeyBuilder);
+        }
+    }
+
+    /**
+     * Traverses up in current resource id by deleting the last key entry.
+     *
+     * This shouldn't be called for key leaf.
+     */
+    void traveseToParent() {
+        if (curKeyBuilder != null) {
+            curKeyBuilder = builders.get(builders.size() - 1);
+            builders.remove(builders.size() - 1);
+        }
+    }
+
+    /**
+     * Returns the resource id for current node.
+     *
+     * @return resource Id
+     */
+    ResourceId getResourceId() {
+
+        builders.add(curKeyBuilder);
+
+        List<NodeKey> keys = new LinkedList<>();
+        for (NodeKey.NodeKeyBuilder builder : builders) {
+            keys.add(builder.build());
+        }
+        nodeKeyList = keys;
+        builders.remove(builders.size() - 1);
+        return (new ResourceId(this));
+    }
+}
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/helperutils/HelperContext.java b/runtime/src/main/java/org/onosproject/yang/runtime/helperutils/HelperContext.java
new file mode 100644
index 0000000..a8b2d23
--- /dev/null
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/helperutils/HelperContext.java
@@ -0,0 +1,76 @@
+/*
+ * 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;
+
+/**
+ * Representation of an entity which maintains additional information
+ * required to create the data node.
+ */
+public class HelperContext {
+
+    /**
+     * Reference for resource identifier builder.
+     */
+    private ExtResourceIdBldr resourceIdBldr;
+
+    /**
+     * Reference for parent resource id builder.
+     */
+    private ExtResourceIdBldr parentResourceIdBldr;
+
+    // Forbid construction.
+    HelperContext() {
+        resourceIdBldr = new ExtResourceIdBldr();
+    }
+
+    /**
+     * Returns resource identifier builder of the node.
+     *
+     * @return resource identifier builder
+     */
+    public ExtResourceIdBldr getResourceIdBuilder() {
+        return resourceIdBldr;
+    }
+
+    /**
+     * Adds resource identifier of the current node.
+     *
+     * @param builder resource identifier builder
+     */
+    void setResourceIdBuilder(ExtResourceIdBldr builder) {
+        resourceIdBldr = builder;
+    }
+
+    /**
+     * Returns parent resource id builder.
+     * This will be used in case of data node initialization with resource id.
+     *
+     * @return parent resource id builder
+     */
+    public ExtResourceIdBldr getParentResourceIdBldr() {
+        return parentResourceIdBldr;
+    }
+
+    /**
+     * Sets parent resource id builder for current node.
+     *
+     * @param prid parent resource id builder
+     */
+    void setParentResourceIdBldr(ExtResourceIdBldr prid) {
+        parentResourceIdBldr = prid;
+    }
+}
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 e786673..28cdb5f 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
@@ -16,13 +16,26 @@
 
 package org.onosproject.yang.runtime.helperutils;
 
+import org.onosproject.yang.compiler.datamodel.YangLeaf;
 import org.onosproject.yang.model.DataNode;
+import org.onosproject.yang.model.InnerNode;
+import org.onosproject.yang.model.LeafSchemaContext;
+import org.onosproject.yang.model.ListSchemaContext;
 import org.onosproject.yang.model.ResourceId;
+import org.onosproject.yang.model.SchemaContext;
+import org.onosproject.yang.model.SchemaId;
+import org.onosproject.yang.model.SingleInstanceNodeContext;
 import org.onosproject.yang.runtime.YangSerializerContext;
 
+import java.util.Iterator;
 import java.util.List;
+import java.util.Set;
 
 import static org.onosproject.yang.model.DataNode.Builder;
+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;
 
 /**
  * Representation of serializer helper utilities, serializer can use them to
@@ -31,6 +44,21 @@
  */
 public final class SerializerHelper {
 
+    // Serializer helper formatted error string
+    private static final String FMT_TOO_FEW =
+            "Too few key parameters in %s. Expected %d; actual %d.";
+    private static final String FMT_TOO_MANY =
+            "Too many key parameters in %s. Expected %d; actual %d.";
+    private static final String FMT_NOT_EXIST =
+            "Schema node with name %s doesn't exist.";
+    private static final String E_NAMESPACE =
+            "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.";
+
+    // Name for first level child
+    private static final String SLASH = "/";
+
     // Forbid construction.
     private SerializerHelper() {
     }
@@ -44,13 +72,17 @@
      */
     public static ResourceId.Builder initializeResourceId(
             YangSerializerContext context) {
-        // TODO implementation
-        return null;
+        SchemaContext cont = context.getContext();
+        SchemaId id = cont.getSchemaId();
+        ExtResourceIdBldr rIdBdr = new ExtResourceIdBldr();
+        rIdBdr.addBranchPointSchema(id.name(), id.namespace());
+        // Adding the schema context to resource id app info.
+        rIdBdr.appInfo(cont);
+        return rIdBdr;
     }
 
     /**
-     * Adds to resource identifier builder. To add a top level logical
-     * resource identifier ("/"), name as "/" should be provided.
+     * Adds to resource identifier builder.
      * <p>
      * Builder and name are mandatory inputs, In case namespace is null,
      * namespace of last key in the keylist of resource identifier builder will
@@ -70,8 +102,20 @@
     public static ResourceId.Builder addToResourceId(
             ResourceId.Builder builder, String name, String namespace,
             String value) {
-        // TODO implementation
-        return null;
+        try {
+            SchemaContext child = getChildSchemaContext(
+                    (SchemaContext) builder.appInfo(), name, namespace);
+            if (child == null) {
+                throw new IllegalArgumentException(
+                        errorMsg(FMT_NOT_EXIST, name));
+            }
+            DataNode.Type type = child.getType();
+            updateResourceId(builder, name, value, child, type);
+            builder.appInfo(child);
+        } catch (IllegalArgumentException e) {
+            throw new IllegalArgumentException(e.getMessage());
+        }
+        return builder;
     }
 
     /**
@@ -96,23 +140,97 @@
      */
     public static ResourceId.Builder addToResourceId(
             ResourceId.Builder builder, String name, String namespace,
-            List<String> value) {
-        // TODO implementation
-        return null;
+            List<String> value) throws IllegalArgumentException {
+        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);
+            } else if (childType == MULTI_INSTANCE_NODE) {
+                Set<String> keyLeafs = ((ListSchemaContext) child)
+                        .getKeyLeaf();
+                int expectedCount = keyLeafs.size();
+
+                try {
+                    checkElementCount(name, expectedCount, 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;
+
+                while (kvlIter.hasNext()) {
+                    String val = kvlIter.next();
+                    keyEleName = sklIter.next();
+                    builder.addKeyLeaf(keyEleName, namespace, val);
+                }
+            } else {
+                throw new IllegalArgumentException(errorMsg(FMT_NOT_EXIST,
+                                                            name));
+            }
+        } catch (IllegalArgumentException e) {
+            throw new IllegalArgumentException(e.getMessage());
+        }
+        return builder;
     }
 
     /**
-     * Initializes a new data node builder.
+     * Initializes a new data node builder using resource identifier builder.
+     * <p>
+     * This API can only be used when passed parameter resourceId builder is
+     * prepared with the help of serializer helper utility.
      *
      * @param builder resource identifier builder
      * @return data node builder
      */
     public static Builder initializeDataNode(ResourceId.Builder builder) {
-        // TODO implementation
-        return null;
+
+        if (!(builder instanceof ExtResourceIdBldr)) {
+            throw new IllegalArgumentException("Invalid resourceId builder.");
+        }
+        SchemaContext node = (SchemaContext) builder.appInfo();
+        HelperContext info = new HelperContext();
+        info.setResourceIdBuilder(null);
+        info.setParentResourceIdBldr((ExtResourceIdBldr) builder);
+        SchemaId sId = node.getSchemaId();
+        InnerNode.Builder dBldr = InnerNode.builder(sId.name(), sId.namespace());
+        dBldr.appInfo(info);
+        return dBldr;
     }
 
     /**
+     * Initializes a new data node builder.
+     *
+     * @param context YANG serializer context
+     * @return data node builder
+     */
+    public static Builder initializeDataNode(YangSerializerContext context) {
+
+        SchemaContext node = context.getContext();
+        SchemaId sId = node.getSchemaId();
+        HelperContext info = new HelperContext();
+        ExtResourceIdBldr rId = info.getResourceIdBuilder();
+        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>
      * Name and builder is mandatory inputs. If namespace is not provided
@@ -136,9 +254,74 @@
      */
     public static Builder addDataNode(Builder builder,
                                       String name, String namespace,
-                                      String value, DataNode.Type type) {
-        // TODO implementation
-        return null;
+                                      String value, DataNode type) {
+        try {
+            SchemaContext node;
+            ExtResourceIdBldr rIdBldr;
+            HelperContext nodeInfo;
+            HelperContext info = (HelperContext) builder.appInfo();
+            ExtResourceIdBldr curBldr = info.getResourceIdBuilder();
+            boolean isCreate = false;
+            if (curBldr != null) {
+//                node = info.getSchemaContext();
+                rIdBldr = info.getResourceIdBuilder();
+                node = (SchemaContext) rIdBldr.appInfo();
+                isCreate = true;
+            } else {
+                node = (SchemaContext) info.getParentResourceIdBldr().appInfo();
+                rIdBldr = info.getParentResourceIdBldr();
+            }
+            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));
+            }
+
+            updateResourceId(rIdBldr, name, value, childSchema, nodeType);
+            if (isCreate) {
+                switch (nodeType) {
+
+                    case SINGLE_INSTANCE_NODE:
+                    case MULTI_INSTANCE_NODE:
+                        builder = builder.createChildBuilder(name, namespace)
+                                .type(nodeType);
+                        break;
+                    case SINGLE_INSTANCE_LEAF_VALUE_NODE:
+                    case MULTI_INSTANCE_LEAF_VALUE_NODE:
+                        builder = builder.createChildBuilder(name, namespace, value)
+                                .type(nodeType);
+                        break;
+                    default:
+                        throw new IllegalArgumentException(
+                                errorMsg(FMT_NOT_EXIST, name));
+                }
+
+                nodeInfo = new HelperContext();
+            } else {
+                builder.type(nodeType);
+                nodeInfo = info;
+            }
+//            nodeInfo.setSchemaContext(childSchema);
+            nodeInfo.setResourceIdBuilder(rIdBldr);
+            builder.appInfo(nodeInfo);
+        } catch (IllegalArgumentException e) {
+            throw new IllegalArgumentException(e.getMessage());
+        }
+        return builder;
+    }
+
+    /**
+     * Returns resource identifier for a given data node. This API will
+     * be used by serializer to obtain the resource identifier in the
+     * scenario when an annotation is associated with a given data node.
+     *
+     * @param builder data node builder
+     * @return resource identifier of the data node
+     */
+    public static ResourceId getResourceId(Builder builder) {
+        HelperContext info = (HelperContext) builder.appInfo();
+        return info.getResourceIdBuilder().getResourceId();
     }
 
     /**
@@ -157,20 +340,122 @@
      * @return parent builder
      */
     public static Builder exitDataNode(Builder builder) {
-        // TODO implementation
-        return null;
+        HelperContext info = (HelperContext) builder.appInfo();
+        ExtResourceIdBldr rId = info.getResourceIdBuilder();
+        SchemaContext cont = (SchemaContext) rId.appInfo();
+        // Deleting the last key entry in resource id.
+        if (cont.getType() == SINGLE_INSTANCE_LEAF_VALUE_NODE) {
+            if (!((YangLeaf) cont).isKeyLeaf()) {
+                rId.traveseToParent();
+            }
+        } else {
+            rId.traveseToParent();
+        }
+        rId.appInfo(cont.getParentContext());
+        return builder.exitNode();
     }
 
     /**
-     * Returns resource identifier for a given data node. This API will
-     * be used by serializer to obtain the resource identifier in the
-     * scenario when an annotation is associated with a given data node.
+     * Returns child schema context for request name and namespace from given
+     * resourceId builder.
      *
-     * @param builder data node builder
-     * @return resource identifier of the data node
+     * @param context   parent schema context
+     * @param name      name of the child node
+     * @param namespace namespace of the child node
+     * @return schema context
      */
-    public static ResourceId getResourceId(Builder builder) {
-        // TODO implementation
-        return null;
+    private static SchemaContext getChildSchemaContext(
+            SchemaContext context, String name, String namespace)
+            throws IllegalArgumentException {
+        SchemaContext child;
+        SchemaId parentId = context.getSchemaId();
+        if (namespace == null && parentId.name().equals(SLASH)) {
+            throw new IllegalArgumentException(E_NAMESPACE);
+        } else if (namespace == null) {
+            namespace = parentId.namespace();
+        }
+
+        SchemaId id = new SchemaId(name, namespace);
+        child = ((SingleInstanceNodeContext) context).getChildContext(id);
+        return child;
+    }
+
+    /**
+     * Checks the user supplied list of argument match's the expected value
+     * or not.
+     *
+     * @param name     name of the parent list/leaf-list node
+     * @param expected count suppose to be
+     * @param actual   user supplied values count
+     * @throws IllegalArgumentException when user requested multi instance node
+     *                                  instance's count doesn't fit into the
+     *                                  allowed instance limit
+     */
+    private static void checkElementCount(String name, int expected, int actual)
+            throws IllegalArgumentException {
+        if (expected < actual) {
+            throw new IllegalArgumentException(
+                    errorMsg(FMT_TOO_MANY, name, expected, actual));
+        } else if (expected > actual) {
+            throw new IllegalArgumentException(
+                    errorMsg(FMT_TOO_FEW, name, expected, actual));
+        }
+    }
+
+    /**
+     * Updates running resource id for current provided builder.
+     *
+     * @param builder resource identifier builder
+     * @param name    name of node
+     * @param value   value of node
+     * @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)
+            throws IllegalArgumentException {
+
+        Object valObject;
+        switch (type) {
+            case SINGLE_INSTANCE_LEAF_VALUE_NODE:
+                if (((YangLeaf) child).isKeyLeaf()) {
+                    valObject = ((LeafSchemaContext) child).fromString(value);
+                    builder.addKeyLeaf(name, child.getSchemaId().namespace(),
+                                       valObject);
+                } else {
+                    builder.addBranchPointSchema(name, child.getSchemaId()
+                            .namespace());
+                }
+                break;
+            case MULTI_INSTANCE_LEAF_VALUE_NODE:
+                valObject = ((LeafSchemaContext) child).fromString(value);
+                builder.addLeafListBranchPoint(name, child.getSchemaId()
+                        .namespace(), valObject);
+                break;
+            case MULTI_INSTANCE_NODE:
+            case SINGLE_INSTANCE_NODE:
+                if (value == null) {
+                    builder.addBranchPointSchema(name, child.getSchemaId()
+                            .namespace());
+                    break;
+                }
+            default:
+                throw new IllegalArgumentException(
+                        errorMsg(FMT_NOT_EXIST, name));
+        }
+        builder.appInfo(child);
+    }
+
+    /**
+     * Returns the error string by filling the parameters in the given
+     * formatted error string.
+     *
+     * @param fmt    error format string
+     * @param params parameters to be filled in formatted string
+     * @return error string
+     */
+    public static String errorMsg(String fmt, Object... params) {
+        return String.format(fmt, params);
     }
 }
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/AddToDataNodeIetfNetTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/AddToDataNodeIetfNetTest.java
new file mode 100644
index 0000000..3295861
--- /dev/null
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/AddToDataNodeIetfNetTest.java
@@ -0,0 +1,146 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.runtime.impl;
+
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+import org.onosproject.yang.model.DataNode;
+import org.onosproject.yang.model.ResourceId;
+import org.onosproject.yang.runtime.helperutils.HelperContext;
+
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.addDataNode;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.exitDataNode;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.getResourceId;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.initializeDataNode;
+import static org.onosproject.yang.runtime.impl.SchemaContextTest.IETFNS;
+import static org.onosproject.yang.runtime.impl.TestUtils.validateResourceId;
+
+/**
+ * Tests the serializer helper methods.
+ */
+
+@FixMethodOrder(MethodSorters.DEFAULT)
+public class AddToDataNodeIetfNetTest {
+
+    TestYangSerializerContext context = new TestYangSerializerContext();
+
+    /*
+     * Reference for data node info.
+     */
+    HelperContext info;
+
+    /*
+     * Reference for data node builder.
+     */
+    DataNode.Builder dBlr;
+
+    /*
+     * Reference for resource id.
+     */
+    ResourceId id;
+
+    /*
+     * Reference for the value.
+     */
+    String value;
+
+    /*
+     * Reference for string array to used for resource id testing.
+     */
+    String[] nA;
+    String[] nsA;
+    String[] valA;
+
+    /**
+     * Test add to data node builder.
+     */
+    @Test
+    public void addToDataTest() {
+
+        dBlr = initializeDataNode(context);
+        // Adding container
+        dBlr = addDataNode(dBlr, "networks", IETFNS, value, null);
+        // Adding list inside container
+        dBlr = addDataNode(dBlr, "network", null, value, null);
+        // Adding key element network Id
+        value = "network1";
+        dBlr = addDataNode(dBlr, "network-id", null, value, null);
+
+        info = (HelperContext) dBlr.appInfo();
+        id = getResourceId(dBlr);
+
+        // Traverse back to parent
+        dBlr = exitDataNode(dBlr);
+        //Tree validation
+        info = (HelperContext) dBlr.appInfo();
+        id = getResourceId(dBlr);
+        value = null;
+        // Adding list inside list
+        dBlr = addDataNode(dBlr, "supporting-network", null, value, null);
+        // Adding key element network-ref
+        value = "network2";
+        dBlr = addDataNode(dBlr, "network-ref", null, value, null);
+        dBlr = exitDataNode(dBlr);
+        dBlr = exitDataNode(dBlr);
+
+        value = null;
+        // Adding list inside list
+        dBlr = addDataNode(dBlr, "node", null, value, null);
+        // Adding key element node-id
+        value = "node1";
+        dBlr = addDataNode(dBlr, "node-id", null, value, null);
+        dBlr = exitDataNode(dBlr);
+
+        value = null;
+        // Adding list inside list
+        dBlr = addDataNode(dBlr, "supporting-node", null, value, null);
+        // Adding key element network-ref
+        value = "network3";
+        dBlr = addDataNode(dBlr, "network-ref", null, value, null);
+        dBlr = exitDataNode(dBlr);
+
+        value = "network4";
+        // Adding key element node-ref
+        dBlr = addDataNode(dBlr, "node-ref", null, value, null);
+        dBlr = exitDataNode(dBlr);
+        dBlr = exitDataNode(dBlr);
+        dBlr = exitDataNode(dBlr);
+        dBlr = exitDataNode(dBlr);
+        dBlr = exitDataNode(dBlr);
+
+        value = null;
+        // Adding container
+        dBlr = addDataNode(dBlr, "networks-state", IETFNS, value, null);
+        // Adding list inside container
+        dBlr = addDataNode(dBlr, "network", null, value, null);
+        // Adding key element network-ref
+        value = "network5";
+        dBlr = addDataNode(dBlr, "network-ref", null, value, null);
+        dBlr = exitDataNode(dBlr);
+
+        // Adding leaf server-provided
+        value = "true";
+        dBlr = addDataNode(dBlr, "server-provided", null, value, null);
+
+        //Tree validation
+        nA = new String[]{"/", "networks", "network", "network-id", ""};
+        nsA = new String[]{null, IETFNS, IETFNS, IETFNS, ""};
+        valA = new String[]{"network1", ""};
+        validateResourceId(nA, nsA, valA, id);
+    }
+}
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/AddToDataNodeListTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/AddToDataNodeListTest.java
new file mode 100644
index 0000000..c37fd57
--- /dev/null
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/AddToDataNodeListTest.java
@@ -0,0 +1,133 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.runtime.impl;
+
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+import org.onosproject.yang.model.DataNode;
+import org.onosproject.yang.model.ResourceId;
+import org.onosproject.yang.runtime.helperutils.HelperContext;
+
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.addDataNode;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.exitDataNode;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.getResourceId;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.initializeDataNode;
+import static org.onosproject.yang.runtime.impl.TestUtils.validateResourceId;
+
+/**
+ * Tests the serializer helper methods.
+ */
+
+@FixMethodOrder(MethodSorters.DEFAULT)
+public class AddToDataNodeListTest {
+
+    public static final String LNS = "yrt:list";
+
+    TestYangSerializerContext context = new TestYangSerializerContext();
+
+    /*
+     * Reference for data node info.
+     */
+    HelperContext info;
+
+    /*
+     * Reference for data node builder.
+     */
+    DataNode.Builder dBlr;
+
+    /*
+     * Reference for resource id.
+     */
+    ResourceId id;
+
+    /*
+     * Reference for the value.
+     */
+    String value;
+
+    /*
+     * Reference for string array to used for resource id testing.
+     */
+    String[] nA;
+    String[] nsA;
+    String[] valA;
+
+    /**
+     * Test add to data node builder.
+     */
+    @Test
+    public void addToDataListTest() {
+
+        dBlr = initializeDataNode(context);
+
+        dBlr = addDataNode(dBlr, "l1", LNS, value, null);
+        value = "1";
+        dBlr = addDataNode(dBlr, "k1", null, value, null);
+        dBlr = exitDataNode(dBlr);
+        value = "2";
+        dBlr = addDataNode(dBlr, "k2", null, value, null);
+        dBlr = exitDataNode(dBlr);
+        value = null;
+        dBlr = addDataNode(dBlr, "c1", null, value, null);
+        value = "0";
+        dBlr = addDataNode(dBlr, "l1", null, value, null);
+
+        info = (HelperContext) dBlr.appInfo();
+        id = getResourceId(dBlr);
+        dBlr = exitDataNode(dBlr);
+
+        ResourceId id1 = getResourceId(dBlr);
+        dBlr = exitDataNode(dBlr);
+
+        value = "3";
+        dBlr = addDataNode(dBlr, "k3", null, value, null);
+
+        info = (HelperContext) dBlr.appInfo();
+        ResourceId id2 = getResourceId(dBlr);
+
+        dBlr = exitDataNode(dBlr);
+        dBlr = exitDataNode(dBlr);
+
+//        // Checking leaf list
+//        value = "1";
+//        dBlr = addDataNode(dBlr, "leaf1", LNS, value, null);
+//        value = "2";
+//        dBlr = addDataNode(dBlr, "leaf1", LNS, value, null);
+//        value = "3";
+//        dBlr = addDataNode(dBlr, "leaf1", LNS, value, null);
+//        value = "4";
+//        dBlr = addDataNode(dBlr, "leaf1", LNS, value, null);
+
+        //Tree validation
+        nA = new String[]{"/", "l1", "k1", "k2", "k3", "c1", "l1", ""};
+        nsA = new String[]{null, LNS, LNS, LNS, LNS, LNS, LNS, ""};
+        valA = new String[]{"1", "2", "3", "0", ""};
+        validateResourceId(nA, nsA, valA, id);
+
+        nA = new String[]{"/", "l1", "k1", "k2", "k3", "c1", ""};
+        nsA = new String[]{null, LNS, LNS, LNS, LNS, LNS, ""};
+        valA = new String[]{"1", "2", "3", ""};
+        validateResourceId(nA, nsA, valA, id1);
+
+        nA = new String[]{"/", "l1", "k1", "k2", "k3", ""};
+        nsA = new String[]{null, LNS, LNS, LNS, LNS, ""};
+        valA = new String[]{"1", "2", "3", ""};
+        validateResourceId(nA, nsA, valA, id2);
+        return;
+    }
+}
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/AddToDataNodeRidTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/AddToDataNodeRidTest.java
new file mode 100644
index 0000000..fdce7f3
--- /dev/null
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/AddToDataNodeRidTest.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.runtime.impl;
+
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+import org.onosproject.yang.model.DataNode;
+import org.onosproject.yang.model.ResourceId;
+import org.onosproject.yang.runtime.helperutils.HelperContext;
+
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.addDataNode;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.addToResourceId;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.getResourceId;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.initializeDataNode;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.initializeResourceId;
+import static org.onosproject.yang.runtime.impl.TestUtils.validateResourceId;
+
+/**
+ * Tests the serializer helper methods.
+ */
+
+@FixMethodOrder(MethodSorters.DEFAULT)
+public class AddToDataNodeRidTest {
+
+    public static final String LNS = "yrt:list";
+
+    TestYangSerializerContext context = new TestYangSerializerContext();
+
+    /*
+     * Reference for data node info.
+     */
+    HelperContext info;
+
+    /*
+     * Reference for data node builder.
+     */
+    DataNode.Builder dBlr;
+
+    /*
+     * Reference for resource id.
+     */
+    ResourceId id;
+
+    /*
+     * Reference for the value.
+     */
+    String value;
+
+    /*
+     * Reference for string array to used for resource id testing.
+     */
+    String[] nA;
+    String[] nsA;
+    String[] valA;
+
+    /**
+     * Test add to data node after initializing it with resource builder.
+     */
+    @Test
+    public void addToDataListTest() {
+
+        ResourceId.Builder rIdBlr = initializeResourceId(context);
+        rIdBlr = addToResourceId(rIdBlr, "l1", LNS, value);
+        rIdBlr = addToResourceId(rIdBlr, "c1", LNS, value);
+        dBlr = initializeDataNode(rIdBlr);
+        value = "0";
+        dBlr = addDataNode(dBlr, "l1", null, value, null);
+        info = (HelperContext) dBlr.appInfo();
+        id = getResourceId(dBlr);
+
+        //Tree validation
+        nA = new String[]{"/", "l1", "c1", "l1", ""};
+        nsA = new String[]{null, LNS, LNS, LNS, ""};
+        valA = new String[]{"0", ""};
+        validateResourceId(nA, nsA, valA, id);
+    }
+}
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestCaseSchemaContext.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/CaseSchemaContextTest.java
similarity index 98%
rename from runtime/src/test/java/org/onosproject/yang/runtime/impl/TestCaseSchemaContext.java
rename to runtime/src/test/java/org/onosproject/yang/runtime/impl/CaseSchemaContextTest.java
index cedfdf5..522f843 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestCaseSchemaContext.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/CaseSchemaContextTest.java
@@ -35,7 +35,7 @@
 /**
  * Tests the default schema context methods.
  */
-public class TestCaseSchemaContext {
+public class CaseSchemaContextTest {
 
     private static TestYangSchemaNodeProvider schemaProvider =
             new TestYangSchemaNodeProvider();
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/DataNodeInitializationTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/DataNodeInitializationTest.java
new file mode 100644
index 0000000..e1d3fc2
--- /dev/null
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/DataNodeInitializationTest.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.runtime.impl;
+
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+import org.onosproject.yang.model.DataNode;
+import org.onosproject.yang.model.ResourceId;
+import org.onosproject.yang.model.SchemaContext;
+import org.onosproject.yang.runtime.helperutils.HelperContext;
+
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.initializeDataNode;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.initializeResourceId;
+import static org.onosproject.yang.runtime.impl.TestUtils.checkRootLevelContext;
+
+/**
+ * Tests the initialize data node methods in serializer helper.
+ */
+
+@FixMethodOrder(MethodSorters.DEFAULT)
+public class DataNodeInitializationTest {
+
+    TestYangSerializerContext context = new TestYangSerializerContext();
+
+    /*
+     * Reference for resource id builder.
+     */
+    ResourceId.Builder rIdBlr;
+
+    /*
+     * Reference for data node info.
+     */
+    HelperContext info;
+
+    /*
+     * Reference for data node builder.
+     */
+    DataNode.Builder dBlr;
+
+    /**
+     * Checks initialize data node using context.
+     */
+    @Test
+    public void initializeDataNodeTest() {
+
+        dBlr = initializeDataNode(context);
+        info = (HelperContext) dBlr.appInfo();
+        checkRootLevelContext((SchemaContext) info.getResourceIdBuilder()
+                .appInfo());
+    }
+
+    /**
+     * Checks initialize data node using resource id.
+     */
+    @Test
+    public void initializeDataNodeRIdTest() {
+
+        rIdBlr = initializeResourceId(context);
+        dBlr = initializeDataNode(rIdBlr);
+        info = (HelperContext) dBlr.appInfo();
+        checkRootLevelContext((SchemaContext) info.getParentResourceIdBldr()
+                .appInfo());
+    }
+}
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestLeafSchemaContext.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/LeafSchemaContextTest.java
similarity index 98%
rename from runtime/src/test/java/org/onosproject/yang/runtime/impl/TestLeafSchemaContext.java
rename to runtime/src/test/java/org/onosproject/yang/runtime/impl/LeafSchemaContextTest.java
index 4ceecf9..19c8746 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestLeafSchemaContext.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/LeafSchemaContextTest.java
@@ -35,7 +35,7 @@
 /**
  * Tests the default schema context methods.
  */
-public class TestLeafSchemaContext {
+public class LeafSchemaContextTest {
 
     private static TestYangSchemaNodeProvider schemaProvider =
             new TestYangSchemaNodeProvider();
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/ResourceIdInitializationTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/ResourceIdInitializationTest.java
new file mode 100644
index 0000000..7122c82
--- /dev/null
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/ResourceIdInitializationTest.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.runtime.impl;
+
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+import org.onosproject.yang.model.ResourceId;
+import org.onosproject.yang.model.SchemaContext;
+
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.addToResourceId;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.initializeResourceId;
+import static org.onosproject.yang.runtime.impl.SchemaContextTest.IETFNS;
+import static org.onosproject.yang.runtime.impl.TestUtils.checkRootLevelContext;
+
+/**
+ * Tests the initialize resource id methods in serializer helper.
+ */
+@FixMethodOrder(MethodSorters.DEFAULT)
+public class ResourceIdInitializationTest {
+
+    TestYangSerializerContext context = new TestYangSerializerContext();
+
+    /*
+     * Reference for resource id builder.
+     */
+    ResourceId.Builder rIdBlr;
+
+    /*
+     * Reference for the value.
+     */
+    String value;
+
+    /**
+     * Checks initialize resource id.
+     */
+    @Test
+    public void initializeResourceIdTest() {
+
+        rIdBlr = initializeResourceId(context);
+        checkRootLevelContext((SchemaContext) rIdBlr.appInfo());
+    }
+
+    @Test
+    public void addToResourceIdTest() {
+
+        rIdBlr = initializeResourceId(context);
+        rIdBlr = addToResourceId(rIdBlr, "networks", IETFNS, value);
+        rIdBlr = addToResourceId(rIdBlr, "network", null, value);
+        value = "network1";
+        rIdBlr = addToResourceId(rIdBlr, "network-id", null, value);
+    }
+}
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestRpcSchemaContext.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/RpcSchemaContextTest.java
similarity index 98%
rename from runtime/src/test/java/org/onosproject/yang/runtime/impl/TestRpcSchemaContext.java
rename to runtime/src/test/java/org/onosproject/yang/runtime/impl/RpcSchemaContextTest.java
index 1468222..3197470 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestRpcSchemaContext.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/RpcSchemaContextTest.java
@@ -19,7 +19,7 @@
 /**
  * Tests the default schema context methods.
  */
-public class TestRpcSchemaContext {
+public class RpcSchemaContextTest {
 
     //TODO : need to be updated afetr RPC implementation
 
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestSchemaContext.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/SchemaContextTest.java
similarity index 98%
rename from runtime/src/test/java/org/onosproject/yang/runtime/impl/TestSchemaContext.java
rename to runtime/src/test/java/org/onosproject/yang/runtime/impl/SchemaContextTest.java
index a767c1c..a12d9cc 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestSchemaContext.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/SchemaContextTest.java
@@ -28,14 +28,13 @@
 
 import java.util.List;
 
-
 import static org.onosproject.yang.runtime.impl.TestUtils.checkLeafSchemaContext;
 import static org.onosproject.yang.runtime.impl.TestUtils.checkSchemaContext;
 
 /**
  * Tests the default schema context methods.
  */
-public class TestSchemaContext {
+public class SchemaContextTest {
 
     private static TestYangSchemaNodeProvider schemaProvider =
             new TestYangSchemaNodeProvider();
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestUtils.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestUtils.java
index f249534..07f8595 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestUtils.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestUtils.java
@@ -20,11 +20,21 @@
 import org.onosproject.yang.compiler.datamodel.YangLeafList;
 import org.onosproject.yang.compiler.datamodel.YangNode;
 import org.onosproject.yang.model.DataNode;
+import org.onosproject.yang.model.KeyLeaf;
+import org.onosproject.yang.model.LeafListKey;
+import org.onosproject.yang.model.ListKey;
+import org.onosproject.yang.model.NodeKey;
+import org.onosproject.yang.model.ResourceId;
+import org.onosproject.yang.model.SchemaContext;
 import org.onosproject.yang.model.SchemaId;
 
+import java.util.List;
+
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
 import static org.onosproject.yang.model.DataNode.Type.MULTI_INSTANCE_LEAF_VALUE_NODE;
 import static org.onosproject.yang.model.DataNode.Type.SINGLE_INSTANCE_LEAF_VALUE_NODE;
+import static org.onosproject.yang.model.DataNode.Type.SINGLE_INSTANCE_NODE;
 
 public final class TestUtils {
 
@@ -37,9 +47,9 @@
     /**
      * Checks the schema context values of given leaf node.
      */
-    static void checkLeafSchemaContext(String name, String namespace,
-                                       String pname, String pnamespace,
-                                       YangLeaf child) {
+    public static void checkLeafSchemaContext(String name, String namespace,
+                                              String pname, String pnamespace,
+                                              YangLeaf child) {
         SchemaId id = child.getSchemaId();
         assertEquals(id.name(), name);
         assertEquals(id.namespace(), namespace);
@@ -69,9 +79,9 @@
     /**
      * Checks the schema context values of given node.
      */
-    static void checkSchemaContext(String name, String namespace,
-                                   String pname, String pnamespace,
-                                   DataNode.Type type, YangNode child) {
+    public static void checkSchemaContext(String name, String namespace,
+                                          String pname, String pnamespace,
+                                          DataNode.Type type, YangNode child) {
         SchemaId id = child.getSchemaId();
         assertEquals(id.name(), name);
         assertEquals(id.namespace(), namespace);
@@ -81,4 +91,54 @@
         assertEquals(id.namespace(), pnamespace);
         assertEquals(child.getType(), type);
     }
+
+
+    /**
+     * Validates the root level node schema context.
+     *
+     * @param context schema context
+     */
+    public static void checkRootLevelContext(SchemaContext context) {
+        SchemaId id = context.getSchemaId();
+        assertEquals(id.name(), "/");
+        assertEquals(id.namespace(), null);
+        assertNull(context.getParentContext());
+        assertEquals(context.getType(), SINGLE_INSTANCE_NODE);
+    }
+
+    /**
+     * Validate the resource id builder.
+     */
+    public static void validateResourceId(String[] nA, String[] nsA, String[] valA,
+                                          ResourceId rBlrEx) {
+        SchemaId sId;
+        Object val = null;
+        List<NodeKey> keys = rBlrEx.nodeKeys();
+        int i = 0;
+        int j = 0;
+        ListKey.ListKeyBuilder lKeyBlr;
+        for (NodeKey k : keys) {
+            sId = k.schemaId();
+            assertEquals(sId.name(), nA[i]);
+            assertEquals(sId.namespace(), nsA[i]);
+            i++;
+            if (k instanceof ListKey) {
+                List<KeyLeaf> kLeaf = ((ListKey) k).keyLeafs();
+                for (KeyLeaf kl : kLeaf) {
+                    sId = kl.leafSchema();
+                    assertEquals(sId.name(), nA[i]);
+                    assertEquals(sId.namespace(), nsA[i]);
+                    assertEquals(kl.leafValAsString(), valA[j]);
+                    i++;
+                    j++;
+                }
+            } else if (k instanceof LeafListKey) {
+                val = ((LeafListKey) k).value().toString();
+            }
+            if (val != null) {
+                assertEquals(val, valA[j]);
+                j++;
+            }
+        }
+    }
 }
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestYangSerializerContext.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestYangSerializerContext.java
new file mode 100644
index 0000000..5e1ebe6
--- /dev/null
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestYangSerializerContext.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.runtime.impl;
+
+import org.onosproject.yang.model.SchemaContext;
+import org.onosproject.yang.runtime.YangSerializerContext;
+import org.onosproject.yang.runtime.ymrimpl.DefaultYangModelRegistry;
+
+/**
+ * Tests the default schema context provider methods.
+ */
+public class TestYangSerializerContext implements YangSerializerContext {
+
+    private static TestYangSchemaNodeProvider schemaProvider =
+            new TestYangSchemaNodeProvider();
+
+
+    @Override
+    public SchemaContext getContext() {
+        schemaProvider.processSchemaRegistry();
+        DefaultYangModelRegistry registry = schemaProvider.registry();
+        return registry;
+    }
+}
diff --git a/runtime/src/test/resources/schemaProviderTestYangFiles/list.yang b/runtime/src/test/resources/schemaProviderTestYangFiles/list.yang
new file mode 100644
index 0000000..fcc67eb
--- /dev/null
+++ b/runtime/src/test/resources/schemaProviderTestYangFiles/list.yang
@@ -0,0 +1,37 @@
+module list {
+
+    yang-version 1;
+
+    namespace "yrt:list";
+
+    prefix "l";
+
+    organization "ON-LAB";
+
+    description "This module defines for list.";
+
+    revision "2016-06-24" {
+        description "Initial revision.";
+    }
+
+    list l1 {
+        key "k1 k2 k3";
+            leaf k1 {
+               type string;
+            }
+
+            leaf k2 {
+              type string;
+            }
+
+            leaf k3 {
+              type string;
+            }
+
+            container c1 {
+                leaf l1 {
+                  type string;
+                }
+            }
+    }
+}
\ No newline at end of file