Merge "JSON serializer implementation"
diff --git a/compiler/base/utils/src/main/java/org/onosproject/yang/compiler/utils/UtilConstants.java b/compiler/base/utils/src/main/java/org/onosproject/yang/compiler/utils/UtilConstants.java
index dc36d1c..215cac8 100644
--- a/compiler/base/utils/src/main/java/org/onosproject/yang/compiler/utils/UtilConstants.java
+++ b/compiler/base/utils/src/main/java/org/onosproject/yang/compiler/utils/UtilConstants.java
@@ -1750,7 +1750,7 @@
     /**
      * Static param for model object.
      */
-    public static final String MODEL_OBJECT = "ModelObject";
+    public static final String MODEL_OBJECT = "InnerModelObject";
 
     /**
      * Static param for add augmentation.
diff --git a/compiler/plugin/utils/src/main/java/org/onosproject/yang/compiler/plugin/utils/YangApacheUtils.java b/compiler/plugin/utils/src/main/java/org/onosproject/yang/compiler/plugin/utils/YangApacheUtils.java
index 1ce96b4..c457ec4 100644
--- a/compiler/plugin/utils/src/main/java/org/onosproject/yang/compiler/plugin/utils/YangApacheUtils.java
+++ b/compiler/plugin/utils/src/main/java/org/onosproject/yang/compiler/plugin/utils/YangApacheUtils.java
@@ -30,6 +30,7 @@
 import java.io.File;
 import java.io.IOException;
 import java.text.SimpleDateFormat;
+import java.util.Iterator;
 import java.util.List;
 import java.util.regex.Pattern;
 
@@ -104,7 +105,9 @@
                                              List<YangNode> curNodes) {
         DefaultYangModel model = new DefaultYangModel();
         YangModuleId id;
-        for (YangSchemaNode node : curNodes) {
+        Iterator<YangNode> it = curNodes.iterator();
+        while (it.hasNext()) {
+            YangSchemaNode node = it.next();
             id = processModuleId((YangNode) node);
             org.onosproject.yang.YangModule module =
                     new DefaultYangModule(id, get(node.getFileName()), get(path));
diff --git a/model/src/main/java/org/onosproject/yang/model/DefaultModelObjectData.java b/model/src/main/java/org/onosproject/yang/model/DefaultModelObjectData.java
new file mode 100644
index 0000000..0503069
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/DefaultModelObjectData.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.model;
+
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Representation of an entity that is composition of model objects identifier
+ * and its data.
+ */
+public class DefaultModelObjectData implements ModelObjectData {
+
+    private List<ModelObject> objects;
+    private ModelObjectId identifier;
+
+    /**
+     * Creates an instance of model object data.
+     *
+     * @param b model object data builder
+     */
+    protected DefaultModelObjectData(Builder b) {
+        objects = b.objects;
+        identifier = b.identifier;
+    }
+
+    @Override
+    public List<ModelObject> modelObjects() {
+        return objects;
+    }
+
+    @Override
+    public ModelObjectId identifier() {
+        return identifier;
+    }
+
+    /**
+     * Retrieves a new model object data builder.
+     *
+     * @return model object data builder
+     */
+    public static Builder builder() {
+        return new Builder();
+    }
+
+    /**
+     * Represents composite model data builder.
+     */
+    public static class Builder implements ModelObjectData.Builder {
+
+        private List<ModelObject> objects;
+        private ModelObjectId identifier;
+
+        /**
+         * Creates an instance of composite model data builder.
+         */
+        public Builder() {
+            objects = new LinkedList<>();
+        }
+
+        @Override
+        public Builder addModelObject(ModelObject o) {
+            objects.add(o);
+            return this;
+        }
+
+        @Override
+        public Builder identifer(ModelObjectId id) {
+            identifier = id;
+            return this;
+        }
+
+        @Override
+        public ModelObjectData build() {
+            return new DefaultModelObjectData(this);
+        }
+    }
+}
diff --git a/model/src/main/java/org/onosproject/yang/model/InnerModelObject.java b/model/src/main/java/org/onosproject/yang/model/InnerModelObject.java
new file mode 100644
index 0000000..03488f6
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/InnerModelObject.java
@@ -0,0 +1,78 @@
+/*
+ * 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 com.google.common.collect.ImmutableMap;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+/**
+ * Abstraction of an entity that provides common basis for all POJOs which are
+ * generated from a YANG model.
+ */
+public abstract class InnerModelObject extends ModelObject {
+
+    private ConcurrentMap<Class<? extends InnerModelObject>, InnerModelObject> augments =
+            new ConcurrentHashMap<>();
+
+    /**
+     * Creates an instance of Inner model object.
+     */
+    protected InnerModelObject() {
+        super(ModelObjectType.NON_ATOMIC);
+    }
+
+    /**
+     * Adds the specified augmentation to this model object.
+     *
+     * @param obj model object of augmentation
+     */
+    public void addAugmentation(InnerModelObject obj) {
+        augments.put(obj.getClass(), obj);
+    }
+
+    /**
+     * Removes the specified augmentation to this model object.
+     *
+     * @param obj model object of augmentation
+     */
+    public void removeAugmentation(InnerModelObject obj) {
+        augments.remove(obj.getClass());
+    }
+
+    /**
+     * Returns the map of augmentations available to this model object.
+     *
+     * @return map of augmentations
+     */
+    public Map<Class<? extends InnerModelObject>, InnerModelObject> augmentations() {
+        return ImmutableMap.copyOf(augments);
+    }
+
+    /**
+     * Returns the augmentation for to a given augmentation class.
+     *
+     * @param c   augmentation class
+     * @param <T> augmentation class type
+     * @return augmentation object if available, null otherwise
+     */
+    public <T extends InnerModelObject> T augmentation(Class<T> c) {
+        return (T) augments.get(c);
+    }
+}
diff --git a/model/src/main/java/org/onosproject/yang/model/LeafModelObject.java b/model/src/main/java/org/onosproject/yang/model/LeafModelObject.java
new file mode 100644
index 0000000..162fc54
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/LeafModelObject.java
@@ -0,0 +1,75 @@
+/*
+ * 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.LinkedList;
+import java.util.List;
+
+/**
+ * Representation of an entity that provides common basis to specify atomic
+ * model.
+ */
+public final class LeafModelObject extends ModelObject {
+
+    private LeafIdentifier leafIdentifier;
+    private List<Object> values;
+
+    /**
+     * Creates an instance of leaf model object.
+     */
+    public LeafModelObject() {
+        super(ModelObjectType.ATOMIC);
+        values = new LinkedList<>();
+    }
+
+    /**
+     * Returns leaf identifier.
+     *
+     * @return leaf identifier
+     */
+    public LeafIdentifier leafIdentifier() {
+        return leafIdentifier;
+    }
+
+    /**
+     * Sets leaf identifier.
+     *
+     * @param id leaf identifier
+     */
+    public void leafIdentifier(LeafIdentifier id) {
+        leafIdentifier = id;
+    }
+
+    /**
+     * Returns value of leaf, it will be single value for leaf and can be
+     * single or list for leaf-list.
+     *
+     * @return value(s)
+     */
+    public List<Object> values() {
+        return values;
+    }
+
+    /**
+     * Sets list of values. For leaf it will always be single value.
+     *
+     * @param v value(s)
+     */
+    public void values(List<Object> v) {
+        values = v;
+    }
+}
diff --git a/model/src/main/java/org/onosproject/yang/model/ModelConverter.java b/model/src/main/java/org/onosproject/yang/model/ModelConverter.java
index cdae6c6..32fd08f 100644
--- a/model/src/main/java/org/onosproject/yang/model/ModelConverter.java
+++ b/model/src/main/java/org/onosproject/yang/model/ModelConverter.java
@@ -23,21 +23,25 @@
 public interface ModelConverter {
 
     /**
-     * Produces a POJO of the specified type, initialized and backed by
-     * the specified data node.
+     * Produces a POJO of the specified type.
+     * <p>
+     * Resource identifier will be converted to model object identifier and
+     * list of data nodes will be converted to list of model objects.
      *
-     * @param node data node
-     * @param <T>  type of model object
-     * @return POJO of specified data node
+     * @param data resource data
+     * @return model object data of specified resource data
      */
-    <T extends ModelObject> T createModel(DataNode node);
+    ModelObjectData createModel(ResourceData data);
 
     /**
      * Produces an immutable tree structure rooted at the returned DataNode
      * using the supplied model POJO object.
+     * <p>
+     * Model object identifier will be converted to resource identfier and
+     * list of model objects will be converted to list of data nodes.
      *
-     * @param obj model object
-     * @return data node corresponds to model object
+     * @param modelData model object data
+     * @return resource data corresponds to model object
      */
-    DataNode createDataNode(ModelObject obj);
+    ResourceData createDataNode(ModelObjectData modelData);
 }
diff --git a/model/src/main/java/org/onosproject/yang/model/ModelObject.java b/model/src/main/java/org/onosproject/yang/model/ModelObject.java
index d6688f1..b91618a 100644
--- a/model/src/main/java/org/onosproject/yang/model/ModelObject.java
+++ b/model/src/main/java/org/onosproject/yang/model/ModelObject.java
@@ -16,59 +16,45 @@
 
 package org.onosproject.yang.model;
 
-import com.google.common.collect.ImmutableMap;
-
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
 /**
- * Abstraction of an entity that provides common basis for all POJOs which are
- * generated from a YANG model.
+ * Abstraction of an entity that provides common basis to specify atomic and
+ * non atomic model.
  */
 public abstract class ModelObject {
 
-    private ConcurrentMap<Class<? extends ModelObject>, ModelObject> augments =
-            new ConcurrentHashMap<>();
+    /*
+ * Represents type of node in data store.
+ */
+    public enum ModelObjectType {
+
+        /**
+         * Atomic node.
+         */
+        ATOMIC,
+
+        /**
+         * Non atomic node.
+         */
+        NON_ATOMIC
+    }
+
+    private ModelObjectType modelObjectType;
 
     /**
-     * Adds the specified augmentation to this model object.
+     * Creates an instance of model object.
      *
-     * @param obj model object of augmentation
+     * @param t type of model object
      */
-    public void addAugmentation(ModelObject obj) {
-        augments.put(obj.getClass(), obj);
+    protected ModelObject(ModelObjectType t) {
+        modelObjectType = t;
     }
 
     /**
-     * Removes the specified augmentation to this model object.
+     * Returns type of model object.
      *
-     * @param obj model object of augmentation
+     * @return type
      */
-    public void removeAugmentation(ModelObject obj) {
-        augments.remove(obj.getClass());
+    ModelObjectType getModelObjectType() {
+        return modelObjectType;
     }
-
-    /**
-     * Returns the map of augmentations available to this model object.
-     *
-     * @return map of augmentations
-     */
-    public Map<Class<? extends ModelObject>, ModelObject> augmentations() {
-        return ImmutableMap.copyOf(augments);
-    }
-
-    /**
-     * Returns the augmentation for to a given augmentation class.
-     *
-     * @param c   augmentation class
-     * @param <T> augmentation class type
-     * @return augmentation object if available, null otherwise
-     */
-    public <T extends ModelObject> T augmentation(Class<T> c) {
-        return (T) augments.get(c);
-    }
-
-    // TODO analyze if some more common information of generated code like
-    // augment which needs to be moved to base ModelObject.
 }
diff --git a/model/src/main/java/org/onosproject/yang/model/ModelObjectData.java b/model/src/main/java/org/onosproject/yang/model/ModelObjectData.java
new file mode 100644
index 0000000..02f6b6b
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/ModelObjectData.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.model;
+
+import java.util.List;
+
+/**
+ * Abstraction of an entity that is composition of model object identifier
+ * and its data.
+ */
+public interface ModelObjectData {
+
+    /**
+     * Returns model objects.
+     *
+     * @return model objects
+     */
+    List<ModelObject> modelObjects();
+
+    /**
+     * Returns module object identifier.
+     *
+     * @return identifier
+     */
+    ModelObjectId identifier();
+
+    /**
+     * Represents builder of composite model data.
+     */
+    interface Builder {
+
+        /**
+         * Adds a model object.
+         *
+         * @param o model object to be added
+         * @return builder
+         */
+        Builder addModelObject(ModelObject o);
+
+        /**
+         * Sets module object identifier.
+         *
+         * @param id identifier
+         * @return builder
+         */
+        Builder identifer(ModelObjectId id);
+
+        /**
+         * Builds an instance of model object data.
+         *
+         * @return model object data
+         */
+        ModelObjectData build();
+    }
+}
diff --git a/model/src/main/java/org/onosproject/yang/model/ModelObjectId.java b/model/src/main/java/org/onosproject/yang/model/ModelObjectId.java
index b0a522f..b82cdf6 100644
--- a/model/src/main/java/org/onosproject/yang/model/ModelObjectId.java
+++ b/model/src/main/java/org/onosproject/yang/model/ModelObjectId.java
@@ -98,7 +98,7 @@
          * @param <T>       generated java class which extends model object
          * @return updated builder pointing to the specified schema location
          */
-        public <T extends ModelObject> Builder addChild(Class<T> container) {
+        public <T extends InnerModelObject> Builder addChild(Class<T> container) {
             atomicPathList.add(new SingleInstanceNode<>(container));
             return this;
         }
@@ -113,7 +113,7 @@
          *             identify the list
          * @return updated builder pointing to the specified schema location
          */
-        public <T extends ModelObject & MultiInstanceObject<K>,
+        public <T extends InnerModelObject & MultiInstanceObject<K>,
                 K extends KeyInfo<T>> Builder addChild(Class<T> list, K key) {
             atomicPathList.add(new MultiInstanceNode<>(list, key));
             return this;
diff --git a/model/src/main/java/org/onosproject/yang/model/MultiInstanceNode.java b/model/src/main/java/org/onosproject/yang/model/MultiInstanceNode.java
index 72182e5..cfd7330 100644
--- a/model/src/main/java/org/onosproject/yang/model/MultiInstanceNode.java
+++ b/model/src/main/java/org/onosproject/yang/model/MultiInstanceNode.java
@@ -21,7 +21,7 @@
 /**
  * Represents a multi instance object.
  */
-public class MultiInstanceNode<T extends ModelObject, K extends KeyInfo>
+public class MultiInstanceNode<T extends InnerModelObject, K extends KeyInfo>
         extends AtomicPath {
 
     private Class<T> listClass;
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/ResourceData.java b/model/src/main/java/org/onosproject/yang/model/ResourceData.java
similarity index 92%
rename from runtime/src/main/java/org/onosproject/yang/runtime/ResourceData.java
rename to model/src/main/java/org/onosproject/yang/model/ResourceData.java
index b4af900..d087ad6 100644
--- a/runtime/src/main/java/org/onosproject/yang/runtime/ResourceData.java
+++ b/model/src/main/java/org/onosproject/yang/model/ResourceData.java
@@ -14,10 +14,7 @@
  * limitations under the License.
  */
 
-package org.onosproject.yang.runtime;
-
-import org.onosproject.yang.model.DataNode;
-import org.onosproject.yang.model.ResourceId;
+package org.onosproject.yang.model;
 
 import java.util.List;
 
diff --git a/model/src/main/java/org/onosproject/yang/model/SingleInstanceNode.java b/model/src/main/java/org/onosproject/yang/model/SingleInstanceNode.java
index 40c5076..de42f5b 100644
--- a/model/src/main/java/org/onosproject/yang/model/SingleInstanceNode.java
+++ b/model/src/main/java/org/onosproject/yang/model/SingleInstanceNode.java
@@ -21,7 +21,7 @@
 /**
  * Represents a single instance object.
  */
-public class SingleInstanceNode<T extends ModelObject> extends AtomicPath {
+public class SingleInstanceNode<T extends InnerModelObject> extends AtomicPath {
 
     private Class<T> containerClass;
 
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/CompositeData.java b/runtime/src/main/java/org/onosproject/yang/runtime/CompositeData.java
index 33653b3..b1d4bb8 100644
--- a/runtime/src/main/java/org/onosproject/yang/runtime/CompositeData.java
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/CompositeData.java
@@ -16,6 +16,8 @@
 
 package org.onosproject.yang.runtime;
 
+import org.onosproject.yang.model.ResourceData;
+
 import java.util.List;
 
 /**
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/DefaultCompositeData.java b/runtime/src/main/java/org/onosproject/yang/runtime/DefaultCompositeData.java
index b2e9f72..b3386bf 100644
--- a/runtime/src/main/java/org/onosproject/yang/runtime/DefaultCompositeData.java
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/DefaultCompositeData.java
@@ -16,6 +16,8 @@
 
 package org.onosproject.yang.runtime;
 
+import org.onosproject.yang.model.ResourceData;
+
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Objects;
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/DefaultResourceData.java b/runtime/src/main/java/org/onosproject/yang/runtime/DefaultResourceData.java
index dfdf5e2..ecf7971 100644
--- a/runtime/src/main/java/org/onosproject/yang/runtime/DefaultResourceData.java
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/DefaultResourceData.java
@@ -17,6 +17,7 @@
 package org.onosproject.yang.runtime;
 
 import org.onosproject.yang.model.DataNode;
+import org.onosproject.yang.model.ResourceData;
 import org.onosproject.yang.model.ResourceId;
 
 import java.util.LinkedList;
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/DefaultRuntimeContext.java b/runtime/src/main/java/org/onosproject/yang/runtime/DefaultRuntimeContext.java
new file mode 100644
index 0000000..274c8d5
--- /dev/null
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/DefaultRuntimeContext.java
@@ -0,0 +1,121 @@
+/*
+ * 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;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Objects;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+import static java.util.Objects.hash;
+
+/**
+ * Representation of default implementation of runtime context.
+ */
+public class DefaultRuntimeContext implements RuntimeContext {
+
+    private String dataFormat;
+    private List<Annotation> annotations;
+
+    /**
+     * Creates an instance of data node.
+     *
+     * @param b data node builder
+     */
+    protected DefaultRuntimeContext(Builder b) {
+        dataFormat = b.dataFormat;
+        annotations = b.annotations;
+    }
+
+    @Override
+    public String getDataFormat() {
+        return dataFormat;
+    }
+
+    @Override
+    public List<Annotation> getProtocolAnnotations() {
+        return annotations;
+    }
+
+    @Override
+    public int hashCode() {
+        return hash(dataFormat, annotations);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj instanceof DefaultRuntimeContext) {
+            DefaultRuntimeContext that = (DefaultRuntimeContext) obj;
+            return Objects.equals(dataFormat, that.dataFormat) &&
+                    Objects.equals(annotations, that.annotations);
+        }
+        return false;
+    }
+
+    @Override
+    public String toString() {
+        return toStringHelper(getClass())
+                .add("dataFormat", dataFormat)
+                .add("annotations", annotations)
+                .toString();
+    }
+
+    /**
+     * Retrieves a new runtime context builder.
+     *
+     * @return runtime context builder
+     */
+    public static Builder builder() {
+        return new Builder();
+    }
+
+    /**
+     * Represents implementation of runtime context builder.
+     */
+    public static class Builder implements RuntimeContext.Builder {
+
+        private String dataFormat;
+        private List<Annotation> annotations;
+
+        /**
+         * Creates an instance of runtime context builder.
+         */
+        public Builder() {
+            annotations = new LinkedList<>();
+        }
+
+        @Override
+        public RuntimeContext.Builder setDataFormat(String df) {
+            dataFormat = df;
+            return this;
+        }
+
+        @Override
+        public RuntimeContext.Builder addAnnotation(Annotation a) {
+            annotations.add(a);
+            return this;
+        }
+
+        @Override
+        public RuntimeContext build() {
+            return new DefaultRuntimeContext(this);
+        }
+    }
+}
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/DefaultYangSerializerContext.java b/runtime/src/main/java/org/onosproject/yang/runtime/DefaultYangSerializerContext.java
index 9da0b01..1ee5b1f 100644
--- a/runtime/src/main/java/org/onosproject/yang/runtime/DefaultYangSerializerContext.java
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/DefaultYangSerializerContext.java
@@ -18,24 +18,34 @@
 
 import org.onosproject.yang.model.SchemaContext;
 
+import java.util.List;
+
 /**
  * Represents YANG serializer context implementation.
  */
 public class DefaultYangSerializerContext implements YangSerializerContext {
 
     private SchemaContext rootContext;
+    private List<Annotation> annotations;
 
     /**
      * Creates an instance of YANG serializer context.
      *
      * @param c root's schema context
+     * @param a dependent annotations
      */
-    public DefaultYangSerializerContext(SchemaContext c) {
+    public DefaultYangSerializerContext(SchemaContext c, List<Annotation> a) {
         rootContext = c;
+        annotations = a;
     }
 
     @Override
     public SchemaContext getContext() {
         return null;
     }
+
+    @Override
+    public List<Annotation> getProtocolAnnotations() {
+        return annotations;
+    }
 }
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/RuntimeContext.java b/runtime/src/main/java/org/onosproject/yang/runtime/RuntimeContext.java
new file mode 100644
index 0000000..c769a0b
--- /dev/null
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/RuntimeContext.java
@@ -0,0 +1,98 @@
+/*
+ * 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;
+
+import java.util.List;
+
+/*
+ * Example usage of getProtocolAnnotations.
+ * Reference 6241:
+ * <rpc message-id="101"
+ * xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
+ * <edit-config>
+ * <target>
+ * <running/>
+ * </target>
+ * <config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0">
+ * <top xmlns="http://example.com/schema/1.2/config">
+ * <interface xc:operation="replace">
+ * <name>Ethernet0/0</name>
+ * <mtu>1500</mtu>
+ * <address>
+ * <name>192.0.2.4</name>
+ * <prefix-length>24</prefix-length>
+ * </address>
+ * </interface>
+ * </top>
+ * </config>
+ * </edit-config>
+ * </rpc>
+ * In above example annotation inside <config> is associated with protocol.
+ * YANG related data has dependency on the same.
+ */
+
+/**
+ * Abstraction of an entity that is representation of YANG runtime service
+ * context information.
+ */
+public interface RuntimeContext {
+
+    /**
+     * Returns data format.
+     *
+     * @return data format
+     */
+    String getDataFormat();
+
+    /**
+     * Returns dependent annotations which are present as a part of protocol
+     * specific information and YANG related data could have dependency on
+     * the same.
+     *
+     * @return list of annotations
+     */
+    List<Annotation> getProtocolAnnotations();
+
+    /**
+     * Abstraction of runtime context builder.
+     */
+    interface Builder {
+
+        /**
+         * Sets data format.
+         *
+         * @param dataFormat data format
+         * @return builder
+         */
+        Builder setDataFormat(String dataFormat);
+
+        /**
+         * Adds an annotation.
+         *
+         * @param annotation annotation
+         * @return builder
+         */
+        Builder addAnnotation(Annotation annotation);
+
+        /**
+         * Builds an instance of runtime context.
+         *
+         * @return runtime context
+         */
+        RuntimeContext build();
+    }
+}
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/YangRuntimeService.java b/runtime/src/main/java/org/onosproject/yang/runtime/YangRuntimeService.java
index 1d54ff7..a66d5fa 100644
--- a/runtime/src/main/java/org/onosproject/yang/runtime/YangRuntimeService.java
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/YangRuntimeService.java
@@ -37,14 +37,14 @@
      * which will be reported back to protocol in output. Produced
      * annotations will be in order of pre-order traversal.
      *
-     * @param external   composite input stream carrying external
-     *                   representation of configuration data
-     * @param dataFormat data format of the provided external representation
+     * @param external composite input stream carrying external
+     *                 representation of configuration data
+     * @param context  additional YANG runtime context information
      * @return in-memory representation of configuration data with decorated
      * node information
      * @throws YangRuntimeException when fails to perform decode operation
      */
-    CompositeData decode(CompositeStream external, String dataFormat);
+    CompositeData decode(CompositeStream external, RuntimeContext context);
 
     /**
      * Encodes the internal in-memory representation of a configuration model
@@ -65,11 +65,11 @@
      * decorations for the node. These decoration should be in pre-order
      * traversal order.
      *
-     * @param internal   in-memory representation of configuration data
-     * @param dataFormat expected data format of the external representation
+     * @param internal in-memory representation of configuration data
+     * @param context  additional YANG runtime context information
      * @return input stream carrying external representation of
      * configuration data
      * @throws YangRuntimeException when fails to perform encode operation
      */
-    CompositeStream encode(CompositeData internal, String dataFormat);
+    CompositeStream encode(CompositeData internal, RuntimeContext context);
 }
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/YangSerializerContext.java b/runtime/src/main/java/org/onosproject/yang/runtime/YangSerializerContext.java
index a5972e6..d7ab7d3 100644
--- a/runtime/src/main/java/org/onosproject/yang/runtime/YangSerializerContext.java
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/YangSerializerContext.java
@@ -18,6 +18,35 @@
 
 import org.onosproject.yang.model.SchemaContext;
 
+import java.util.List;
+
+/*
+ * Example usage of getProtocolAnnotations.
+ * Reference 6241:
+ * <rpc message-id="101"
+ * xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
+ * <edit-config>
+ * <target>
+ * <running/>
+ * </target>
+ * <config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0">
+ * <top xmlns="http://example.com/schema/1.2/config">
+ * <interface xc:operation="replace">
+ * <name>Ethernet0/0</name>
+ * <mtu>1500</mtu>
+ * <address>
+ * <name>192.0.2.4</name>
+ * <prefix-length>24</prefix-length>
+ * </address>
+ * </interface>
+ * </top>
+ * </config>
+ * </edit-config>
+ * </rpc>
+ * In above example annotation inside <config> is associated with protocol.
+ * YANG related data has dependency on the same.
+ */
+
 /**
  * Representation of a context for decoding YANG models via serializers.
  */
@@ -29,4 +58,13 @@
      * @return schema context provider
      */
     SchemaContext getContext();
+
+    /**
+     * Returns dependent annotations which are present as a part of protocol
+     * specific information and YANG related data could have dependency on
+     * the same.
+     *
+     * @return list of annotations
+     */
+    List<Annotation> getProtocolAnnotations();
 }
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/helperutils/ExtResourceIdBldr.java b/runtime/src/main/java/org/onosproject/yang/runtime/helperutils/ExtResourceIdBldr.java
index 29bdf2c..6db16ab 100644
--- a/runtime/src/main/java/org/onosproject/yang/runtime/helperutils/ExtResourceIdBldr.java
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/helperutils/ExtResourceIdBldr.java
@@ -16,10 +16,14 @@
 
 package org.onosproject.yang.runtime.helperutils;
 
+import org.onosproject.yang.model.KeyLeaf;
+import org.onosproject.yang.model.LeafListKey;
 import org.onosproject.yang.model.LeafListKey.LeafListKeyBuilder;
+import org.onosproject.yang.model.ListKey;
 import org.onosproject.yang.model.ModelException;
 import org.onosproject.yang.model.NodeKey;
 import org.onosproject.yang.model.ResourceId;
+import org.onosproject.yang.model.SchemaId;
 
 import java.util.LinkedList;
 import java.util.List;
@@ -51,20 +55,27 @@
      */
     void traveseToParent() {
         if (curKeyBuilder != null) {
+            curKeyBuilder = null;
+        } else {
             curKeyBuilder = builders.get(builders.size() - 1);
             builders.remove(builders.size() - 1);
         }
     }
 
+    @Override
+    public ResourceId build() {
+        return getResourceId();
+    }
+
     /**
      * Returns the resource id for current node.
      *
      * @return resource Id
      */
     ResourceId getResourceId() {
-
-        builders.add(curKeyBuilder);
-
+        if (curKeyBuilder != null) {
+            builders.add(curKeyBuilder);
+        }
         List<NodeKey> keys = new LinkedList<>();
         for (NodeKey.NodeKeyBuilder builder : builders) {
             keys.add(builder.build());
@@ -73,4 +84,40 @@
         builders.remove(builders.size() - 1);
         return (new ResourceId(this));
     }
+
+    /**
+     * Creates the extended resource id builder from given resource id
+     * builder.
+     *
+     * @param ridBldr extended resource id builder
+     * @param builder resource id builder
+     * @return updated extended resource id builder
+     */
+    public ExtResourceIdBldr copyBuilder(ExtResourceIdBldr ridBldr, ResourceId
+            .Builder builder) {
+        ResourceId id = builder.build();
+        SchemaId sId;
+        // Preparing the extended resource id builder from resourceId.
+        List<NodeKey> keys = id.nodeKeys();
+
+        for (NodeKey k : keys) {
+            sId = k.schemaId();
+            if (k instanceof ListKey) {
+                List<KeyLeaf> kLeaf = ((ListKey) k).keyLeafs();
+                for (KeyLeaf kl : kLeaf) {
+                    sId = kl.leafSchema();
+                    ridBldr.addKeyLeaf(sId.name(), sId.namespace(),
+                                       kl.leafValue());
+                }
+                continue;
+            } else if (k instanceof LeafListKey) {
+                sId = k.schemaId();
+                ridBldr.addLeafListBranchPoint(sId.name(), sId.namespace(),
+                                               ((LeafListKey) k).value());
+                continue;
+            }
+            ridBldr.addBranchPointSchema(sId.name(), sId.namespace());
+        }
+        return ridBldr;
+    }
 }
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/helperutils/SerializerHelper.java b/runtime/src/main/java/org/onosproject/yang/runtime/helperutils/SerializerHelper.java
index 78ee089..3245a56 100644
--- a/runtime/src/main/java/org/onosproject/yang/runtime/helperutils/SerializerHelper.java
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/helperutils/SerializerHelper.java
@@ -55,6 +55,7 @@
             "NameSpace is mandatory to provide for first level node.";
     private static final String E_LEAFLIST =
             "Method is not allowed to pass multiple values for leaf-list.";
+    private static final String E_RESID = "Invalid resourceId builder.";
 
     // Name for first level child
     private static final String SLASH = "/";
@@ -74,7 +75,7 @@
             YangSerializerContext context) {
         SchemaContext cont = context.getContext();
         SchemaId id = cont.getSchemaId();
-        ExtResourceIdBldr rIdBdr = new ExtResourceIdBldr();
+        ResourceId.Builder rIdBdr = ResourceId.builder();
         rIdBdr.addBranchPointSchema(id.name(), id.namespace());
         // Adding the schema context to resource id app info.
         rIdBdr.appInfo(cont);
@@ -141,29 +142,32 @@
     public static ResourceId.Builder addToResourceId(
             ResourceId.Builder builder, String name, String namespace,
             List<String> value) throws IllegalArgumentException {
+        Object valObject;
         SchemaContext child = getChildSchemaContext(
                 (SchemaContext) builder.appInfo(), name, namespace);
         namespace = child.getSchemaId().namespace();
-        builder.appInfo(child);
         DataNode.Type childType = child.getType();
         try {
             if (childType == MULTI_INSTANCE_LEAF_VALUE_NODE) {
                 if (value.size() > 1) {
                     throw new IllegalArgumentException(errorMsg(E_LEAFLIST));
                 }
-                builder.addLeafListBranchPoint(name, namespace, value);
+                valObject = ((LeafSchemaContext) child).fromString(
+                        value.get(0));
+                builder.addLeafListBranchPoint(name, namespace, valObject);
             } else if (childType == MULTI_INSTANCE_NODE) {
+                // Adding list node.
+                String v = null;
+                builder = addToResourceId(builder, name, namespace, v);
                 Set<String> keyLeafs = ((ListSchemaContext) child)
                         .getKeyLeaf();
-                int expectedCount = keyLeafs.size();
-
                 try {
-                    checkElementCount(name, expectedCount, value.size());
+                    checkElementCount(name, keyLeafs.size(), value.size());
                 } catch (IllegalArgumentException e) {
                     throw new IllegalArgumentException(e.getMessage());
                 }
 
-                //After validation adding the key nodes under the list node.
+                // After validation adding the key nodes under the list node.
                 Iterator<String> sklIter = keyLeafs.iterator();
                 Iterator<String> kvlIter = value.iterator();
                 String keyEleName;
@@ -171,15 +175,20 @@
                 while (kvlIter.hasNext()) {
                     String val = kvlIter.next();
                     keyEleName = sklIter.next();
-                    builder.addKeyLeaf(keyEleName, namespace, val);
+                    SchemaContext keyChild = getChildSchemaContext(
+                            (SchemaContext) builder.appInfo(), keyEleName,
+                            namespace);
+                    valObject = ((LeafSchemaContext) keyChild).fromString(val);
+                    builder.addKeyLeaf(keyEleName, namespace, valObject);
                 }
             } else {
-                throw new IllegalArgumentException(errorMsg(FMT_NOT_EXIST,
-                                                            name));
+                throw new IllegalArgumentException(
+                        errorMsg(FMT_NOT_EXIST, name));
             }
         } catch (IllegalArgumentException e) {
             throw new IllegalArgumentException(e.getMessage());
         }
+        builder.appInfo(child);
         return builder;
     }
 
@@ -194,15 +203,16 @@
      */
     public static Builder initializeDataNode(ResourceId.Builder builder) {
 
-        if (!(builder instanceof ExtResourceIdBldr)) {
-            throw new IllegalArgumentException("Invalid resourceId builder.");
-        }
+        ExtResourceIdBldr rIdBldr = new ExtResourceIdBldr();
+        rIdBldr = rIdBldr.copyBuilder(rIdBldr, builder);
+        rIdBldr.appInfo(builder.appInfo());
         SchemaContext node = (SchemaContext) builder.appInfo();
         HelperContext info = new HelperContext();
         info.setResourceIdBuilder(null);
-        info.setParentResourceIdBldr((ExtResourceIdBldr) builder);
+        info.setParentResourceIdBldr(rIdBldr);
         SchemaId sId = node.getSchemaId();
-        InnerNode.Builder dBldr = InnerNode.builder(sId.name(), sId.namespace());
+        InnerNode.Builder dBldr = InnerNode.builder(
+                sId.name(), sId.namespace());
         dBldr.appInfo(info);
         return dBldr;
     }
@@ -222,14 +232,12 @@
         rId.addBranchPointSchema(sId.name(), sId.namespace());
         rId.appInfo(node);
         info.setResourceIdBuilder(rId);
-//        info.setSchemaContext(node);
         InnerNode.Builder dBlr = InnerNode.builder(sId.name(), sId.namespace());
         dBlr.type(SINGLE_INSTANCE_NODE);
         dBlr.appInfo(info);
         return dBlr;
     }
 
-
     /**
      * Adds a data node to a given data node builder.
      * <p>
@@ -263,7 +271,6 @@
             ExtResourceIdBldr curBldr = info.getResourceIdBuilder();
             boolean isCreate = false;
             if (curBldr != null) {
-//                node = info.getSchemaContext();
                 rIdBldr = info.getResourceIdBuilder();
                 node = (SchemaContext) rIdBldr.appInfo();
                 isCreate = true;
@@ -275,10 +282,14 @@
                     node, name, namespace);
             DataNode.Type nodeType = childSchema.getType();
             if (type != null && !nodeType.equals(type)) {
-                throw new IllegalArgumentException(errorMsg(FMT_NOT_EXIST, name));
+                throw new IllegalArgumentException(
+                        errorMsg(FMT_NOT_EXIST, name));
             }
 
+            // Updating the namespace
+            namespace = childSchema.getSchemaId().namespace();
             updateResourceId(rIdBldr, name, value, childSchema, nodeType);
+            Object valObject;
             if (isCreate) {
                 switch (nodeType) {
 
@@ -288,9 +299,21 @@
                                 .type(nodeType);
                         break;
                     case SINGLE_INSTANCE_LEAF_VALUE_NODE:
+                        valObject = ((LeafSchemaContext) childSchema)
+                                .fromString(value);
+                        if (((YangLeaf) childSchema).isKeyLeaf()) {
+                            builder = builder.addKeyLeaf(
+                                    name, namespace, valObject);
+                        }
+                        builder = builder.createChildBuilder(
+                                name, namespace, valObject).type(nodeType);
+                        break;
                     case MULTI_INSTANCE_LEAF_VALUE_NODE:
-                        builder = builder.createChildBuilder(name, namespace, value)
-                                .type(nodeType);
+                        valObject = ((LeafSchemaContext) childSchema)
+                                .fromString(value);
+                        builder = builder.createChildBuilder(
+                                name, namespace, valObject).type(nodeType)
+                                .addLeafListValue(valObject);
                         break;
                     default:
                         throw new IllegalArgumentException(
@@ -302,7 +325,6 @@
                 builder.type(nodeType);
                 nodeInfo = info;
             }
-//            nodeInfo.setSchemaContext(childSchema);
             nodeInfo.setResourceIdBuilder(rIdBldr);
             builder.appInfo(nodeInfo);
         } catch (IllegalArgumentException e) {
@@ -411,9 +433,9 @@
      * @param child   child schema context
      * @param type    type of data node
      */
-    private static void updateResourceId(ResourceId.Builder builder, String name,
-                                         String value, SchemaContext child,
-                                         DataNode.Type type)
+    private static void updateResourceId(
+            ResourceId.Builder builder, String name, String value,
+            SchemaContext child, DataNode.Type type)
             throws IllegalArgumentException {
 
         Object valObject;
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/ymrimpl/DefaultYangModelRegistry.java b/runtime/src/main/java/org/onosproject/yang/runtime/ymrimpl/DefaultYangModelRegistry.java
index b064e9b..0f0d8a6 100644
--- a/runtime/src/main/java/org/onosproject/yang/runtime/ymrimpl/DefaultYangModelRegistry.java
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/ymrimpl/DefaultYangModelRegistry.java
@@ -54,9 +54,10 @@
 /**
  * Represents YANG model registry implementation.
  */
-public class DefaultYangModelRegistry implements YangModelRegistry, SingleInstanceNodeContext {
+public class DefaultYangModelRegistry implements YangModelRegistry,
+        SingleInstanceNodeContext {
 
-    private static final Logger log = getLogger(DefaultYangModelRegistry.class);
+    private final Logger log = getLogger(getClass());
     private static final String AT = "@";
 
     /*
@@ -181,9 +182,9 @@
                                          "unregistered.", sClass
                                          .getSimpleName(), param);
                     } else {
-                        throw new RuntimeException(
-                                sClass.getSimpleName() +
-                                        " service was not registered.");
+                        log.error("Either {} service was not registered or " +
+                                          "already unregistered from model " +
+                                          "registry.", sClass.getSimpleName());
                     }
                 }
             } else {
@@ -277,12 +278,16 @@
      * @return registered class
      */
     public Class<?> getRegisteredClass(YangSchemaNode schemaNode) {
-        String interfaceName = getInterfaceClassName(schemaNode);
-        String serviceName = getServiceName(schemaNode);
-        Class<?> regClass = registerClassStore.get(serviceName);
-        if (regClass == null) {
-            regClass = registerClassStore.get(interfaceName);
+        Class<?> regClass = null;
+        if (schemaNode != null) {
+            String interfaceName = getInterfaceClassName(schemaNode);
+            String serviceName = getServiceName(schemaNode);
+            regClass = registerClassStore.get(serviceName);
+            if (regClass == null) {
+                regClass = registerClassStore.get(interfaceName);
+            }
         }
+        log.error("{} node should not be null.");
         return regClass;
     }
 
@@ -476,7 +481,7 @@
      *
      * @param nodes set of module/submodule nodes
      */
-    public void updateChildContext(Set<YangNode> nodes) {
+    private void updateChildContext(Set<YangNode> nodes) {
         // Preparing schema id for logical node with name "/"
         for (YangNode node : nodes) {
             node.setLeafRootContext(this);
@@ -513,7 +518,7 @@
      *
      * @param curNode choice node
      */
-    public void updateSchemaContextForChoiceChild(YangNode curNode) {
+    private void updateSchemaContextForChoiceChild(YangNode curNode) {
         YangNode child = curNode.getChild();
         // Setting the parent context for case
         while (child != null) {
@@ -527,7 +532,7 @@
      *
      * @param curNode case node
      */
-    public void updateSchemaContextForCaseChild(YangNode curNode) {
+    private void updateSchemaContextForCaseChild(YangNode curNode) {
         curNode.setLeafRootContext(this);
         YangNode child = curNode.getChild();
         updateContextForChoiceCase(child);
@@ -538,8 +543,7 @@
 
         checkNotNull(schemaId);
         if (schemaId.namespace() == null) {
-            log.error("node with {} namespace not found.",
-                      schemaId.namespace());
+            log.error("node with {} namespace not found.", schemaId.namespace());
         }
 
         String namespace = schemaId.namespace();
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/yrhimpl/DefaultYangRuntimeHandler.java b/runtime/src/main/java/org/onosproject/yang/runtime/yrhimpl/DefaultYangRuntimeHandler.java
index 22667dd..074a06d 100644
--- a/runtime/src/main/java/org/onosproject/yang/runtime/yrhimpl/DefaultYangRuntimeHandler.java
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/yrhimpl/DefaultYangRuntimeHandler.java
@@ -20,13 +20,14 @@
 import org.onosproject.yang.runtime.CompositeData;
 import org.onosproject.yang.runtime.CompositeStream;
 import org.onosproject.yang.runtime.DefaultYangSerializerContext;
+import org.onosproject.yang.runtime.RuntimeContext;
 import org.onosproject.yang.runtime.YangRuntimeException;
 import org.onosproject.yang.runtime.YangRuntimeService;
 import org.onosproject.yang.runtime.YangSerializer;
 import org.onosproject.yang.runtime.YangSerializerContext;
 import org.onosproject.yang.runtime.YangSerializerRegistry;
-import org.onosproject.yang.runtime.ysrimpl.DefaultYangSerializerRegistry;
 import org.onosproject.yang.runtime.ymrimpl.DefaultYangModelRegistry;
+import org.onosproject.yang.runtime.ysrimpl.DefaultYangSerializerRegistry;
 import org.slf4j.Logger;
 
 import static org.slf4j.LoggerFactory.getLogger;
@@ -41,7 +42,6 @@
     private static final String NR = " is not registered.";
     private YangSerializerRegistry registry;
     private SchemaContext rootContext;
-    private YangSerializerContext serializerContext;
 
     /**
      * Creates a new YANG runtime manager.
@@ -53,19 +53,24 @@
                                      SchemaContext c) {
         registry = r;
         rootContext = c;
-        serializerContext = new DefaultYangSerializerContext(rootContext);
     }
 
     @Override
-    public CompositeData decode(CompositeStream external, String dataFormat) {
-        YangSerializer ys = getRegisteredSerializer(dataFormat);
-        return ys.decode(external, serializerContext);
+    public CompositeData decode(CompositeStream external, RuntimeContext c) {
+        YangSerializer ys = getRegisteredSerializer(c.getDataFormat());
+        YangSerializerContext sc =
+                new DefaultYangSerializerContext(rootContext,
+                                                 c.getProtocolAnnotations());
+        return ys.decode(external, sc);
     }
 
     @Override
-    public CompositeStream encode(CompositeData internal, String dataFormat) {
-        YangSerializer ys = getRegisteredSerializer(dataFormat);
-        return ys.encode(internal, serializerContext);
+    public CompositeStream encode(CompositeData internal, RuntimeContext c) {
+        YangSerializer ys = getRegisteredSerializer(c.getDataFormat());
+        YangSerializerContext sc =
+                new DefaultYangSerializerContext(rootContext,
+                                                 c.getProtocolAnnotations());
+        return ys.encode(internal, sc);
     }
 
     /**
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/AddToDataNodeListTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/AddToDataNodeListTest.java
deleted file mode 100644
index c37fd57..0000000
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/AddToDataNodeListTest.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * Copyright 2017-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yang.runtime.impl;
-
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.runners.MethodSorters;
-import org.onosproject.yang.model.DataNode;
-import org.onosproject.yang.model.ResourceId;
-import org.onosproject.yang.runtime.helperutils.HelperContext;
-
-import static org.onosproject.yang.runtime.helperutils.SerializerHelper.addDataNode;
-import static org.onosproject.yang.runtime.helperutils.SerializerHelper.exitDataNode;
-import static org.onosproject.yang.runtime.helperutils.SerializerHelper.getResourceId;
-import static org.onosproject.yang.runtime.helperutils.SerializerHelper.initializeDataNode;
-import static org.onosproject.yang.runtime.impl.TestUtils.validateResourceId;
-
-/**
- * Tests the serializer helper methods.
- */
-
-@FixMethodOrder(MethodSorters.DEFAULT)
-public class AddToDataNodeListTest {
-
-    public static final String LNS = "yrt:list";
-
-    TestYangSerializerContext context = new TestYangSerializerContext();
-
-    /*
-     * Reference for data node info.
-     */
-    HelperContext info;
-
-    /*
-     * Reference for data node builder.
-     */
-    DataNode.Builder dBlr;
-
-    /*
-     * Reference for resource id.
-     */
-    ResourceId id;
-
-    /*
-     * Reference for the value.
-     */
-    String value;
-
-    /*
-     * Reference for string array to used for resource id testing.
-     */
-    String[] nA;
-    String[] nsA;
-    String[] valA;
-
-    /**
-     * Test add to data node builder.
-     */
-    @Test
-    public void addToDataListTest() {
-
-        dBlr = initializeDataNode(context);
-
-        dBlr = addDataNode(dBlr, "l1", LNS, value, null);
-        value = "1";
-        dBlr = addDataNode(dBlr, "k1", null, value, null);
-        dBlr = exitDataNode(dBlr);
-        value = "2";
-        dBlr = addDataNode(dBlr, "k2", null, value, null);
-        dBlr = exitDataNode(dBlr);
-        value = null;
-        dBlr = addDataNode(dBlr, "c1", null, value, null);
-        value = "0";
-        dBlr = addDataNode(dBlr, "l1", null, value, null);
-
-        info = (HelperContext) dBlr.appInfo();
-        id = getResourceId(dBlr);
-        dBlr = exitDataNode(dBlr);
-
-        ResourceId id1 = getResourceId(dBlr);
-        dBlr = exitDataNode(dBlr);
-
-        value = "3";
-        dBlr = addDataNode(dBlr, "k3", null, value, null);
-
-        info = (HelperContext) dBlr.appInfo();
-        ResourceId id2 = getResourceId(dBlr);
-
-        dBlr = exitDataNode(dBlr);
-        dBlr = exitDataNode(dBlr);
-
-//        // Checking leaf list
-//        value = "1";
-//        dBlr = addDataNode(dBlr, "leaf1", LNS, value, null);
-//        value = "2";
-//        dBlr = addDataNode(dBlr, "leaf1", LNS, value, null);
-//        value = "3";
-//        dBlr = addDataNode(dBlr, "leaf1", LNS, value, null);
-//        value = "4";
-//        dBlr = addDataNode(dBlr, "leaf1", LNS, value, null);
-
-        //Tree validation
-        nA = new String[]{"/", "l1", "k1", "k2", "k3", "c1", "l1", ""};
-        nsA = new String[]{null, LNS, LNS, LNS, LNS, LNS, LNS, ""};
-        valA = new String[]{"1", "2", "3", "0", ""};
-        validateResourceId(nA, nsA, valA, id);
-
-        nA = new String[]{"/", "l1", "k1", "k2", "k3", "c1", ""};
-        nsA = new String[]{null, LNS, LNS, LNS, LNS, LNS, ""};
-        valA = new String[]{"1", "2", "3", ""};
-        validateResourceId(nA, nsA, valA, id1);
-
-        nA = new String[]{"/", "l1", "k1", "k2", "k3", ""};
-        nsA = new String[]{null, LNS, LNS, LNS, LNS, ""};
-        valA = new String[]{"1", "2", "3", ""};
-        validateResourceId(nA, nsA, valA, id2);
-        return;
-    }
-}
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/DefaultYangModelRegistryTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/DefaultYangModelRegistryTest.java
index 8d6caba..0e12c39 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/DefaultYangModelRegistryTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/DefaultYangModelRegistryTest.java
@@ -25,6 +25,8 @@
 import org.onosproject.yang.runtime.ymrimpl.DefaultYangModelRegistry;
 
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
 
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.core.Is.is;
@@ -101,10 +103,6 @@
             "org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf" +
                     ".network4.IetfNetwork4OpParam";
 
-    private static final String UN_REG_SCHEMA_NAME = "ietf-routing";
-    private static final String UN_REG_INTERFACE_NAME = "IetfRouting";
-    private static final String UN_REG_OP_PARAM_NAME = "IetfRoutingOpParam";
-    private static final String UN_REG_SERVICE_NAME = "IetfRoutingService";
     private static final String CHECK = "check";
     private static final String DATE_NAMESPACE = "2015-00-08";
     private static final String NAMESPACE =
@@ -126,39 +124,39 @@
 
         provider.processSchemaRegistry();
 
+        List<YangNode> nodes = new ArrayList<>();
         DefaultYangModelRegistry registry = provider.registry();
 
         YangSchemaNode yangNode = registry.getForSchemaName(SCHEMA_NAME_3);
         assertThat(true, is(SCHEMA_NAME_3.equals(yangNode.getName())));
 
-        yangNode =
-                registry.getForInterfaceFileName(
-                        INTERFACE_NAME_3);
+        yangNode = registry.getForInterfaceFileName(INTERFACE_NAME_3);
         assertThat(true, is(SCHEMA_NAME_3.equals(yangNode.getName())));
 
-        yangNode =
-                registry.getForOpPramFileName(
-                        OP_PARAM_NAME_3);
+        yangNode = registry.getForOpPramFileName(OP_PARAM_NAME_3);
         assertThat(true, is(SCHEMA_NAME_3.equals(yangNode.getName())));
 
-//        provider.unregisterService(SERVICE_NAME_3);
-        //TODO: fix unregister UT.
-//
-//        yangNode = registry.getForAppName(SERVICE_NAME_3);
-//        assertThat(true, is(yangNode == null));
-//
-//        yangNode = registry.getForSchemaName(SCHEMA_NAME_3);
-//        assertThat(true, is(yangNode == null));
-//
-//        yangNode =
-//                registry.getForInterfaceFileName(
-//                        INTERFACE_NAME_3);
-//        assertThat(true, is(yangNode == null));
-//
-//        yangNode =
-//                registry.getForOpPramFileName(
-//                        OP_PARAM_NAME_3);
-//        assertThat(true, is(yangNode == null));
+        Class<?> cls = registry.getRegisteredClass(yangNode);
+        assertThat(true, is(INTERFACE_NAME_3.equals(cls.getName())));
+
+        //Unregister service
+        nodes.add((YangNode) yangNode);
+        provider.unRegister(nodes);
+
+        yangNode = registry.getForAppName(SERVICE_NAME_3);
+        assertThat(true, is(yangNode == null));
+
+        yangNode = registry.getForSchemaName(SCHEMA_NAME_3);
+        assertThat(true, is(yangNode == null));
+
+        yangNode = registry.getForInterfaceFileName(INTERFACE_NAME_3);
+        assertThat(true, is(yangNode == null));
+
+        yangNode = registry.getForOpPramFileName(OP_PARAM_NAME_3);
+        assertThat(true, is(yangNode == null));
+
+        cls = registry.getRegisteredClass(yangNode);
+        assertThat(true, is(cls == null));
     }
 
     /**
@@ -172,179 +170,63 @@
             throws IOException {
 
         provider.processSchemaRegistry();
-        DefaultYangModelRegistry registry =
-                provider.registry();
+        DefaultYangModelRegistry registry = provider.registry();
 
+        List<YangNode> nodes = new ArrayList<>();
         //Service with rev.
         YangSchemaNode yangNode = registry.getForSchemaName(SCHEMA_NAME_4_15);
         assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
 
-        yangNode =
-                registry.getForInterfaceFileName(
-                        INTERFACE_NAME_REV_15);
+        yangNode = registry.getForInterfaceFileName(INTERFACE_NAME_REV_15);
         assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
 
-        yangNode =
-                registry.getForOpPramFileName(
-                        OP_PARAM_NAME_REV_15);
+        yangNode = registry.getForOpPramFileName(OP_PARAM_NAME_REV_15);
         assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
 
-        //       provider.unregisterService(SERVICE_NAME_REV_15);
+        Class<?> cls = registry.getRegisteredClass(yangNode);
+        assertThat(true, is(INTERFACE_NAME_REV_15.equals(cls.getName())));
+
+        //unregister SERVICE_NAME_REV_15.
+        nodes.add((YangNode) yangNode);
+        provider.unRegister(nodes);
 
         yangNode = registry.getForAppName(SERVICE_NAME_REV_15);
         assertThat(true, is(yangNode == null));
 
-        //Here the yangNode should be the node which does not have revision.
-        // asset should pass with false.
-        yangNode = registry.getForSchemaName(SCHEMA_NAME_4);
-        assertThat(true, is(((YangNode) yangNode).getRevision() == null));
-
-        yangNode = registry.getForSchemaName(SCHEMA_NAME_4);
-        assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
-
-        yangNode =
-                registry.getForInterfaceFileName(
-                        INTERFACE_NAME_NO_REV);
-        assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
-
-        yangNode =
-                registry.getForOpPramFileName(
-                        OP_PARAM_NAME_NO_REV);
-        assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
-
-        //provider.unregisterService(SERVICE_NAME_NO_REV);
-
-        yangNode = registry.getForAppName(SERVICE_NAME_NO_REV);
-        assertThat(true, is(yangNode == null));
-
-        //Here the yangNode should be the node which have different revision.
         yangNode = registry.getForSchemaName(SCHEMA_NAME_4);
         assertThat(true, is(yangNode != null));
-        //TODO: ureg.
-//        assertThat(true, is(((YangNode) yangNode).getRevision() != null));
-    }
 
-    /**
-     * Unit test case in which schema node should be present with multi
-     * revisions.
-     *
-     * @throws IOException when fails to do IO operation
-     */
-    //TODO: add unreg in UT
-    public void testForGetSchemaNodeWhenMultiRevision()
-            throws IOException {
-
-        provider.processSchemaRegistry();
-        DefaultYangModelRegistry registry =
-                provider.registry();
-
-        //Service with rev.
-        YangSchemaNode yangNode = registry.getForSchemaName(SCHEMA_NAME_4_15);
-        assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
-
-        yangNode =
-                registry.getForInterfaceFileName(
-                        INTERFACE_NAME_REV_15);
-        assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
-
-        yangNode =
-                registry.getForOpPramFileName(
-                        OP_PARAM_NAME_REV_15);
-        assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
-
-        //As we have not registered an  application this object should be null.
-        Object object = registry.getRegisteredClass(yangNode);
-        assertThat(true, is(object == null));
-//        provider.unregisterService(SERVICE_NAME_REV_15);
-
-        yangNode = registry.getForAppName(SERVICE_NAME_REV_15);
+        yangNode = registry.getForInterfaceFileName(INTERFACE_NAME_REV_15);
         assertThat(true, is(yangNode == null));
 
+        yangNode = registry.getForOpPramFileName(OP_PARAM_NAME_REV_15);
+        assertThat(true, is(yangNode == null));
+
+        cls = registry.getRegisteredClass(yangNode);
+        assertThat(true, is(cls == null));
+
         //Here the yangNode should be the node which does not have revision.
         // asset should pass with false.
         yangNode = registry.getForSchemaName(SCHEMA_NAME_4);
         assertThat(true, is(((YangNode) yangNode).getRevision() == null));
 
-        //Service with different revision.
-        yangNode = registry
-                .getForAppName(SERVICE_NAME_REV_16);
-        assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
-
-        yangNode = registry.getForSchemaName(SCHEMA_NAME_4_16);
-        assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
-
-        yangNode =
-                registry.getForInterfaceFileName(
-                        INTERFACE_NAME_REV_16);
-        assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
-
-        yangNode =
-                registry.getForOpPramFileName(
-                        OP_PARAM_NAME_REV_16);
-        assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
-
-        //As we have not registered an  application this object should be null.
-        object = registry.getRegisteredClass(yangNode);
-        assertThat(true, is(object == null));
-//        provider.unregisterService(SERVICE_NAME_REV_16);
-
-        yangNode = registry.getForAppName(SERVICE_NAME_REV_16);
-        assertThat(true, is(yangNode == null));
-
-        //Here the yangNode should be the node which have different revision.
-        yangNode = registry.getForSchemaName(SCHEMA_NAME_4);
-        assertThat(true, is(((YangNode) yangNode).getRevision() == null));
-
-        //Service with different revision.
-        yangNode = registry.getForAppName(SERVICE_NAME_REV_17);
-        assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
-
-        yangNode = registry.getForSchemaName(SCHEMA_NAME_4_17);
-        assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
-
-        yangNode =
-                registry.getForInterfaceFileName(
-                        INTERFACE_NAME_REV_17);
-        assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
-
-        yangNode =
-                registry.getForOpPramFileName(
-                        OP_PARAM_NAME_REV_17);
-        assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
-
-        //As we have not registered an  application this object should be null.
-        object = registry.getRegisteredClass(yangNode);
-        assertThat(true, is(object == null));
-//        provider.unregisterService(SERVICE_NAME_REV_17);
-
-        yangNode = registry.getForAppName(SERVICE_NAME_REV_17);
-        assertThat(true, is(yangNode == null));
-
-        //Here the yangNode should be the node which have different revision.
-        yangNode = registry.getForSchemaName(SCHEMA_NAME_4);
-        assertThat(true, is(((YangNode) yangNode).getRevision() == null));
-
-        //Service no revision.
-        yangNode = registry.getForAppName(SERVICE_NAME_NO_REV);
-        assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
+        //---------------------------------------------------------------//
 
         yangNode = registry.getForSchemaName(SCHEMA_NAME_4);
         assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
 
-        yangNode =
-                registry.getForInterfaceFileName(
-                        INTERFACE_NAME_NO_REV);
+        yangNode = registry.getForInterfaceFileName(INTERFACE_NAME_NO_REV);
         assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
 
-        yangNode =
-                registry.getForOpPramFileName(
-                        OP_PARAM_NAME_NO_REV);
+        yangNode = registry.getForOpPramFileName(OP_PARAM_NAME_NO_REV);
         assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
 
-        //As we have not registered an  application this object should be null.
-        object = registry.getRegisteredClass(yangNode);
-        assertThat(true, is(object == null));
-        //       provider.unregisterService(SERVICE_NAME_NO_REV);
+        cls = registry.getRegisteredClass(yangNode);
+        assertThat(true, is(INTERFACE_NAME_NO_REV.equals(cls.getName())));
+
+        //unregister SERVICE_NAME_NO_REV.
+        nodes.add((YangNode) yangNode);
+        provider.unRegister(nodes);
 
         yangNode = registry.getForAppName(SERVICE_NAME_NO_REV);
         assertThat(true, is(yangNode == null));
@@ -354,30 +236,223 @@
         assertThat(true, is(yangNode != null));
         assertThat(true, is(((YangNode) yangNode).getRevision() != null));
 
+        yangNode = registry.getForInterfaceFileName(INTERFACE_NAME_NO_REV);
+        assertThat(true, is(yangNode == null));
+
+        yangNode = registry.getForOpPramFileName(OP_PARAM_NAME_NO_REV);
+        assertThat(true, is(yangNode == null));
+
+        cls = registry.getRegisteredClass(yangNode);
+        assertThat(true, is(cls == null));
+    }
+
+    /**
+     * Unit test case in which schema node should be present with multi
+     * revisions.
+     *
+     * @throws IOException when fails to do IO operation
+     */
+    @Test
+    public void testForGetSchemaNodeWhenMultiRevision()
+            throws IOException {
+
+        provider.processSchemaRegistry();
+        DefaultYangModelRegistry registry = provider.registry();
+
+        List<YangNode> nodes = new ArrayList<>();
+        //Service with rev.
+        YangSchemaNode yangNode = registry.getForSchemaName(SCHEMA_NAME_4_15);
+        assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
+
+        yangNode = registry.getForInterfaceFileName(INTERFACE_NAME_REV_15);
+        assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
+
+        yangNode = registry.getForOpPramFileName(OP_PARAM_NAME_REV_15);
+        assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
+
+        Class<?> cls = registry.getRegisteredClass(yangNode);
+        assertThat(true, is(INTERFACE_NAME_REV_15.equals(cls.getName())));
+
+        //Unregister SERVICE_NAME_REV_15.
+        nodes.add((YangNode) yangNode);
+        provider.unRegister(nodes);
+
+        yangNode = registry.getForAppName(SERVICE_NAME_REV_15);
+        assertThat(true, is(yangNode == null));
+
+        yangNode = registry.getForSchemaName(SCHEMA_NAME_4);
+        assertThat(true, is(yangNode != null));
+
+        yangNode = registry.getForInterfaceFileName(INTERFACE_NAME_REV_15);
+        assertThat(true, is(yangNode == null));
+
+        yangNode = registry.getForOpPramFileName(OP_PARAM_NAME_REV_15);
+        assertThat(true, is(yangNode == null));
+
+        //Here the yangNode should be the node which does not have revision.
+        // asset should pass with false.
+        yangNode = registry.getForSchemaName(SCHEMA_NAME_4);
+        assertThat(true, is(((YangNode) yangNode).getRevision() == null));
+
+        cls = registry.getRegisteredClass(yangNode);
+        assertThat(true, is(cls != null));
+
+        //---------------------------------------------------------------//
+
+        //Here the yangNode should be the node which does not have revision.
+        // asset should pass with false.
+        yangNode = registry.getForSchemaName(SCHEMA_NAME_4);
+        assertThat(true, is(((YangNode) yangNode).getRevision() == null));
+
+        //Service with different revision.
+        yangNode = registry.getForAppName(SERVICE_NAME_REV_16);
+        assertThat(true, is(yangNode == null));
+
+        yangNode = registry.getForSchemaName(SCHEMA_NAME_4_16);
+        assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
+
+        yangNode = registry.getForInterfaceFileName(INTERFACE_NAME_REV_16);
+        assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
+
+        yangNode = registry.getForOpPramFileName(OP_PARAM_NAME_REV_16);
+        assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
+
+        cls = registry.getRegisteredClass(yangNode);
+        assertThat(true, is(INTERFACE_NAME_REV_16.equals(cls.getName())));
+
+        //Unregister SERVICE_NAME_REV_16.
+        nodes.add((YangNode) yangNode);
+        provider.unRegister(nodes);
+
+        yangNode = registry.getForAppName(SERVICE_NAME_REV_16);
+        assertThat(true, is(yangNode == null));
+
+        yangNode = registry.getForInterfaceFileName(INTERFACE_NAME_REV_16);
+        assertThat(true, is(yangNode == null));
+
+        yangNode = registry.getForOpPramFileName(OP_PARAM_NAME_REV_16);
+        assertThat(true, is(yangNode == null));
+
+        //Here the yangNode should be the node which have different revision.
+        yangNode = registry.getForSchemaName(SCHEMA_NAME_4);
+        assertThat(true, is(((YangNode) yangNode).getRevision() == null));
+
+        cls = registry.getRegisteredClass(yangNode);
+        assertThat(true, is(cls != null));
+
+        //---------------------------------------------------------------//
+
+        //Service with different revision.
+        yangNode = registry.getForAppName(SERVICE_NAME_REV_17);
+        assertThat(true, is(yangNode == null));
+
+        yangNode = registry.getForSchemaName(SCHEMA_NAME_4_17);
+        assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
+
+        yangNode = registry.getForInterfaceFileName(INTERFACE_NAME_REV_17);
+        assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
+
+        yangNode = registry.getForOpPramFileName(OP_PARAM_NAME_REV_17);
+        assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
+
+        cls = registry.getRegisteredClass(yangNode);
+        assertThat(true, is(INTERFACE_NAME_REV_17.equals(cls.getName())));
+
+        //Unregister SERVICE_NAME_REV_17.
+        nodes.add((YangNode) yangNode);
+        provider.unRegister(nodes);
+
+        yangNode = registry.getForAppName(SERVICE_NAME_REV_17);
+        assertThat(true, is(yangNode == null));
+
+        yangNode = registry.getForInterfaceFileName(INTERFACE_NAME_REV_17);
+        assertThat(true, is(yangNode == null));
+
+        yangNode = registry.getForOpPramFileName(OP_PARAM_NAME_REV_17);
+        assertThat(true, is(yangNode == null));
+
+        //Here the yangNode should be the node which have different revision.
+        yangNode = registry.getForSchemaName(SCHEMA_NAME_4);
+        assertThat(true, is(((YangNode) yangNode).getRevision() == null));
+
+        cls = registry.getRegisteredClass(yangNode);
+        assertThat(true, is(cls != null));
+
+        //---------------------------------------------------------------//
+
+        //Service no revision.
+        yangNode = registry.getForAppName(SERVICE_NAME_NO_REV);
+        assertThat(true, is(yangNode == null));
+
+        yangNode = registry.getForSchemaName(SCHEMA_NAME_4);
+        assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
+
+        yangNode = registry.getForInterfaceFileName(INTERFACE_NAME_NO_REV);
+        assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
+
+        yangNode = registry.getForOpPramFileName(OP_PARAM_NAME_NO_REV);
+        assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
+
+        cls = registry.getRegisteredClass(yangNode);
+        assertThat(true, is(INTERFACE_NAME_NO_REV.equals(cls.getName())));
+
+        //Unregister SERVICE_NAME_NO_REV.
+        nodes.add((YangNode) yangNode);
+        provider.unRegister(nodes);
+
+        yangNode = registry.getForAppName(SERVICE_NAME_NO_REV);
+        assertThat(true, is(yangNode == null));
+
+        yangNode = registry.getForInterfaceFileName(INTERFACE_NAME_NO_REV);
+        assertThat(true, is(yangNode == null));
+
+        yangNode = registry.getForOpPramFileName(OP_PARAM_NAME_NO_REV);
+        assertThat(true, is(yangNode == null));
+
+        //Here the yangNode should be the node which have different revision.
+        yangNode = registry.getForSchemaName(SCHEMA_NAME_4);
+        assertThat(true, is(yangNode != null));
+        assertThat(true, is(((YangNode) yangNode).getRevision() != null));
+
+        cls = registry.getRegisteredClass(yangNode);
+        assertThat(true, is(cls != null));
+
+        //---------------------------------------------------------------//
+
         //Service with different revision.
         yangNode = registry.getForAppName(SERVICE_NAME_REV_14);
-        assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
+        assertThat(true, is(yangNode == null));
 
         yangNode = registry.getForSchemaName(SCHEMA_NAME_4_14);
         assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
 
-        yangNode =
-                registry.getForInterfaceFileName(
-                        INTERFACE_NAME_REV_14);
+        yangNode = registry.getForInterfaceFileName(INTERFACE_NAME_REV_14);
         assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
 
-        yangNode =
-                registry.getForOpPramFileName(
-                        OP_PARAM_NAME_REV_14);
+        yangNode = registry.getForOpPramFileName(OP_PARAM_NAME_REV_14);
         assertThat(true, is(SCHEMA_NAME_4.equals(yangNode.getName())));
 
-        //As we have not registered an  application this object should be null.
-        object = registry.getRegisteredClass(yangNode);
-        assertThat(true, is(object == null));
-//        provider.unregisterService(SERVICE_NAME_REV_14);
+        cls = registry.getRegisteredClass(yangNode);
+        assertThat(true, is(INTERFACE_NAME_REV_14.equals(cls.getName())));
+
+        //Unregister SERVICE_NAME_REV_14.
+        nodes.add((YangNode) yangNode);
+        provider.unRegister(nodes);
 
         yangNode = registry.getForAppName(SERVICE_NAME_REV_14);
         assertThat(true, is(yangNode == null));
+
+        yangNode = registry.getForSchemaName(SCHEMA_NAME_4);
+        assertThat(true, is(yangNode == null));
+
+        yangNode = registry.getForInterfaceFileName(INTERFACE_NAME_REV_14);
+        assertThat(true, is(yangNode == null));
+
+        yangNode = registry.getForOpPramFileName(OP_PARAM_NAME_REV_14);
+        assertThat(true, is(yangNode == null));
+
+        cls = registry.getRegisteredClass(yangNode);
+        assertThat(true, is(cls == null));
     }
 
     /**
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/RuntimeHandlerTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/RuntimeHandlerTest.java
index 1d6369b..2f93f2b 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/RuntimeHandlerTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/RuntimeHandlerTest.java
@@ -19,6 +19,7 @@
 import org.junit.Test;
 import org.onosproject.yang.runtime.CompositeData;
 import org.onosproject.yang.runtime.CompositeStream;
+import org.onosproject.yang.runtime.DefaultRuntimeContext;
 import org.onosproject.yang.runtime.YangRuntimeService;
 import org.onosproject.yang.runtime.YangSerializer;
 import org.onosproject.yang.runtime.yrhimpl.DefaultYangRuntimeHandler;
@@ -51,11 +52,13 @@
     @Test
     public void validateRuntimeHandler() {
         register(XML);
-        CompositeData dd = s.decode(null, XML);
+        CompositeData dd = s.decode(null, DefaultRuntimeContext.builder()
+                .setDataFormat(XML).build());
         assertThat(TESTSTREAM, is(dd.resourceData().resourceId().nodeKeys()
                                           .get(0).schemaId().name()));
 
-        CompositeStream cs = s.encode(null, XML);
+        CompositeStream cs = s.encode(null, DefaultRuntimeContext.builder()
+                .setDataFormat(XML).build());
         assertThat(TESTSTREAM, is(cs.resourceId()));
     }
 
@@ -65,7 +68,8 @@
     @Test(expected = RuntimeException.class)
     public void validateRuntimeHandlerError() throws RuntimeException {
         register(XML);
-        CompositeData dd = s.decode(null, JSON);
+        CompositeData dd = s.decode(null, DefaultRuntimeContext.builder()
+                .setDataFormat(JSON).build());
         assertThat(TESTSTREAM, is(dd.resourceData().resourceId().nodeKeys()
                                           .get(0).schemaId().name()));
     }
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestSerializer.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestSerializer.java
index bf63dc6..2f4fab5 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestSerializer.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestSerializer.java
@@ -17,11 +17,11 @@
 package org.onosproject.yang.runtime.impl;
 
 import org.onosproject.yang.model.DataNode;
+import org.onosproject.yang.model.ResourceData;
 import org.onosproject.yang.model.ResourceId;
 import org.onosproject.yang.runtime.AnnotatedNodeInfo;
 import org.onosproject.yang.runtime.CompositeData;
 import org.onosproject.yang.runtime.CompositeStream;
-import org.onosproject.yang.runtime.ResourceData;
 import org.onosproject.yang.runtime.YangSerializer;
 import org.onosproject.yang.runtime.YangSerializerContext;
 
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestUtils.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestUtils.java
index 07f8595..8b8c058 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestUtils.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestUtils.java
@@ -20,8 +20,10 @@
 import org.onosproject.yang.compiler.datamodel.YangLeafList;
 import org.onosproject.yang.compiler.datamodel.YangNode;
 import org.onosproject.yang.model.DataNode;
+import org.onosproject.yang.model.InnerNode;
 import org.onosproject.yang.model.KeyLeaf;
 import org.onosproject.yang.model.LeafListKey;
+import org.onosproject.yang.model.LeafNode;
 import org.onosproject.yang.model.ListKey;
 import org.onosproject.yang.model.NodeKey;
 import org.onosproject.yang.model.ResourceId;
@@ -31,6 +33,7 @@
 import java.util.List;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.onosproject.yang.model.DataNode.Type.MULTI_INSTANCE_LEAF_VALUE_NODE;
 import static org.onosproject.yang.model.DataNode.Type.SINGLE_INSTANCE_LEAF_VALUE_NODE;
@@ -63,9 +66,9 @@
     /**
      * Checks the schema context values of given leaf list node.
      */
-    static void checkLeafListSchemaContext(String name, String namespace,
-                                           String pname, String pnamespace,
-                                           YangLeafList child) {
+    public static void checkLeafListSchemaContext(String name, String namespace,
+                                                  String pname, String pnamespace,
+                                                  YangLeafList child) {
         SchemaId id = child.getSchemaId();
         assertEquals(id.name(), name);
         assertEquals(id.namespace(), namespace);
@@ -109,14 +112,13 @@
     /**
      * Validate the resource id builder.
      */
-    public static void validateResourceId(String[] nA, String[] nsA, String[] valA,
-                                          ResourceId rBlrEx) {
+    public static void validateResourceId(String[] nA, String[] nsA,
+                                          String[] valA, ResourceId rBlrEx) {
         SchemaId sId;
         Object val = null;
         List<NodeKey> keys = rBlrEx.nodeKeys();
         int i = 0;
         int j = 0;
-        ListKey.ListKeyBuilder lKeyBlr;
         for (NodeKey k : keys) {
             sId = k.schemaId();
             assertEquals(sId.name(), nA[i]);
@@ -141,4 +143,50 @@
             }
         }
     }
+
+    /**
+     * Validates the give data node content.
+     *
+     * @param node    data node
+     * @param n       name
+     * @param ns      namespace
+     * @param type    data node type
+     * @param isChild denotes the given node has child or not
+     * @param value   value of leaf
+     */
+    public static void validateDataNode(DataNode node, String n, String ns,
+                                        DataNode.Type type, boolean isChild,
+                                        String value) {
+        NodeKey k = node.key();
+        SchemaId id = k.schemaId();
+        assertEquals(id.name(), n);
+        assertEquals(id.namespace(), ns);
+        if (node instanceof InnerNode) {
+            assertEquals(((InnerNode) node).type(), type);
+            if (isChild) {
+                assertNotNull(((InnerNode) node).childNodes());
+            } else {
+                assertNull(((InnerNode) node).childNodes());
+            }
+        } else {
+            assertEquals(((LeafNode) node).type(), type);
+            assertEquals(((LeafNode) node).value().toString(), value);
+        }
+    }
+
+    /**
+     * Validates the give key leaf content.
+     *
+     * @param key key leaf
+     * @param n   name
+     * @param ns  namespace
+     * @param v   value of leaf node
+     */
+    public static void validateLeafDataNode(KeyLeaf key, String n, String ns,
+                                            String v) {
+        SchemaId id = key.leafSchema();
+        assertEquals(id.name(), n);
+        assertEquals(id.namespace(), ns);
+        assertEquals(key.leafValue().toString(), v);
+    }
 }
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestYangSchemaNodeProvider.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestYangSchemaNodeProvider.java
index 59418e5..88f0a44 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestYangSchemaNodeProvider.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestYangSchemaNodeProvider.java
@@ -29,6 +29,7 @@
 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
@@ -42,7 +43,6 @@
 /**
  * Represents mock bundle context. provides bundle context for YSR to do unit
  * testing.
- * //TODO: add unreg ut.
  */
 public class TestYangSchemaNodeProvider {
 
@@ -70,41 +70,63 @@
             //Need to deserialize generated meta data file for unit tests.
             Set<YangNode> appNode = deSerializeDataModel(META_PATH);
             nodes.addAll(appNode);
-
-            //Process loading class file.
-            String appName;
-            ClassLoader classLoader = TestYangSchemaNodeProvider.class.getClassLoader();
-            for (YangSchemaNode node : nodes) {
-
-                //If service class is not generated then use
-                // interface file to load this class.
-                appName = getInterfaceClassName(node);
-                Class<?> cls;
-                try {
-                    cls = classLoader.loadClass(appName);
-                } catch (ClassNotFoundException e) {
-                    continue;
-                }
-
-                //Create model registration param.
-                ModelRegistrationParam.Builder b =
-                        DefaultModelRegistrationParam.builder();
-
-                //create a new YANG model
-                YangModel model = processYangModel(META_PATH, nodes);
-                //set YANG model
-                b.setYangModel(model);
-                //generate app info.
-                AppModuleInfo info = new DefaultAppModuleInfo(cls, null);
-                b.addAppModuleInfo(processModuleId((YangNode) node), info);
-                reg.registerModel(b.build());
-            }
+            reg.registerModel(prepareParam(nodes));
             deleteDirectory(TEMP_FOLDER_PATH);
         } catch (IOException e) {
         }
     }
 
     /**
+     * Unregister given nodes from runtime service.
+     *
+     * @param nodes list of nodes
+     */
+    public void unRegister(List<YangNode> nodes) {
+        reg.unregisterModel(prepareParam(nodes));
+    }
+
+    /**
+     * Prepares model registration parameter.
+     *
+     * @param nodes list of nodes
+     * @return model registration parameter
+     */
+    private ModelRegistrationParam prepareParam(List<YangNode> nodes) {
+        //Process loading class file.
+        String appName;
+        ClassLoader classLoader = getClass().getClassLoader();
+
+        //Create model registration param.
+        ModelRegistrationParam.Builder b =
+                DefaultModelRegistrationParam.builder();
+
+        //create a new YANG model
+        YangModel model = processYangModel(META_PATH, nodes);
+        //set YANG model
+        b.setYangModel(model);
+
+        Iterator<YangNode> it = nodes.iterator();
+        while (it.hasNext()) {
+            YangSchemaNode node = it.next();
+
+            //If service class is not generated then use
+            // interface file to load this class.
+            appName = getInterfaceClassName(node);
+            Class<?> cls;
+            try {
+                cls = classLoader.loadClass(appName);
+            } catch (ClassNotFoundException e) {
+                continue;
+            }
+
+            //generate app info.
+            AppModuleInfo info = new DefaultAppModuleInfo(cls, null);
+            b.addAppModuleInfo(processModuleId((YangNode) node), info);
+        }
+        return b.build();
+    }
+
+    /**
      * Returns schema registry.
      *
      * @return schema registry
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
index 5e1ebe6..bd34087 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestYangSerializerContext.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestYangSerializerContext.java
@@ -17,9 +17,12 @@
 package org.onosproject.yang.runtime.impl;
 
 import org.onosproject.yang.model.SchemaContext;
+import org.onosproject.yang.runtime.Annotation;
 import org.onosproject.yang.runtime.YangSerializerContext;
 import org.onosproject.yang.runtime.ymrimpl.DefaultYangModelRegistry;
 
+import java.util.List;
+
 /**
  * Tests the default schema context provider methods.
  */
@@ -35,4 +38,9 @@
         DefaultYangModelRegistry registry = schemaProvider.registry();
         return registry;
     }
+
+    @Override
+    public List<Annotation> getProtocolAnnotations() {
+        return null;
+    }
 }
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/CaseSchemaContextTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/schemacontext/CaseSchemaContextTest.java
similarity index 96%
rename from runtime/src/test/java/org/onosproject/yang/runtime/impl/CaseSchemaContextTest.java
rename to runtime/src/test/java/org/onosproject/yang/runtime/impl/schemacontext/CaseSchemaContextTest.java
index 522f843..4d54d2c 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/CaseSchemaContextTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/schemacontext/CaseSchemaContextTest.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package org.onosproject.yang.runtime.impl;
+package org.onosproject.yang.runtime.impl.schemacontext;
 
 import org.junit.Test;
 import org.onosproject.yang.compiler.datamodel.DefaultYangNamespace;
@@ -24,6 +24,7 @@
 import org.onosproject.yang.compiler.datamodel.YangSchemaNodeIdentifier;
 import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
 import org.onosproject.yang.model.SchemaId;
+import org.onosproject.yang.runtime.impl.TestYangSchemaNodeProvider;
 import org.onosproject.yang.runtime.ymrimpl.DefaultYangModelRegistry;
 
 import static org.onosproject.yang.model.DataNode.Type.MULTI_INSTANCE_NODE;
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/LeafSchemaContextTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/schemacontext/LeafSchemaContextTest.java
similarity index 96%
rename from runtime/src/test/java/org/onosproject/yang/runtime/impl/LeafSchemaContextTest.java
rename to runtime/src/test/java/org/onosproject/yang/runtime/impl/schemacontext/LeafSchemaContextTest.java
index 19c8746..cc9e0bd 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/LeafSchemaContextTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/schemacontext/LeafSchemaContextTest.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package org.onosproject.yang.runtime.impl;
+package org.onosproject.yang.runtime.impl.schemacontext;
 
 import org.junit.Test;
 import org.onosproject.yang.compiler.datamodel.DefaultYangNamespace;
@@ -26,6 +26,7 @@
 import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
 import org.onosproject.yang.model.DataNode;
 import org.onosproject.yang.model.SchemaId;
+import org.onosproject.yang.runtime.impl.TestYangSchemaNodeProvider;
 import org.onosproject.yang.runtime.ymrimpl.DefaultYangModelRegistry;
 
 import static org.onosproject.yang.runtime.impl.TestUtils.checkLeafListSchemaContext;
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/RpcSchemaContextTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/schemacontext/RpcSchemaContextTest.java
similarity index 97%
rename from runtime/src/test/java/org/onosproject/yang/runtime/impl/RpcSchemaContextTest.java
rename to runtime/src/test/java/org/onosproject/yang/runtime/impl/schemacontext/RpcSchemaContextTest.java
index 3197470..89f0105 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/RpcSchemaContextTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/schemacontext/RpcSchemaContextTest.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package org.onosproject.yang.runtime.impl;
+package org.onosproject.yang.runtime.impl.schemacontext;
 
 /**
  * Tests the default schema context methods.
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/SchemaContextTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/schemacontext/SchemaContextTest.java
similarity index 96%
rename from runtime/src/test/java/org/onosproject/yang/runtime/impl/SchemaContextTest.java
rename to runtime/src/test/java/org/onosproject/yang/runtime/impl/schemacontext/SchemaContextTest.java
index a12d9cc..e1e473a 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/SchemaContextTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/schemacontext/SchemaContextTest.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package org.onosproject.yang.runtime.impl;
+package org.onosproject.yang.runtime.impl.schemacontext;
 
 import org.junit.Test;
 import org.onosproject.yang.compiler.datamodel.YangAugment;
@@ -24,6 +24,7 @@
 import org.onosproject.yang.compiler.datamodel.YangNode;
 import org.onosproject.yang.model.DataNode;
 import org.onosproject.yang.model.SchemaId;
+import org.onosproject.yang.runtime.impl.TestYangSchemaNodeProvider;
 import org.onosproject.yang.runtime.ymrimpl.DefaultYangModelRegistry;
 
 import java.util.List;
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/AddToDataNodeIetfNetTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeIetfNetTest.java
similarity index 94%
rename from runtime/src/test/java/org/onosproject/yang/runtime/impl/AddToDataNodeIetfNetTest.java
rename to runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeIetfNetTest.java
index 3295861..df125bc 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/AddToDataNodeIetfNetTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeIetfNetTest.java
@@ -14,27 +14,24 @@
  * limitations under the License.
  */
 
-package org.onosproject.yang.runtime.impl;
+package org.onosproject.yang.runtime.impl.serializerhelper;
 
-import org.junit.FixMethodOrder;
 import org.junit.Test;
-import org.junit.runners.MethodSorters;
 import org.onosproject.yang.model.DataNode;
 import org.onosproject.yang.model.ResourceId;
 import org.onosproject.yang.runtime.helperutils.HelperContext;
+import org.onosproject.yang.runtime.impl.TestYangSerializerContext;
 
 import static org.onosproject.yang.runtime.helperutils.SerializerHelper.addDataNode;
 import static org.onosproject.yang.runtime.helperutils.SerializerHelper.exitDataNode;
 import static org.onosproject.yang.runtime.helperutils.SerializerHelper.getResourceId;
 import static org.onosproject.yang.runtime.helperutils.SerializerHelper.initializeDataNode;
-import static org.onosproject.yang.runtime.impl.SchemaContextTest.IETFNS;
+import static org.onosproject.yang.runtime.impl.schemacontext.SchemaContextTest.IETFNS;
 import static org.onosproject.yang.runtime.impl.TestUtils.validateResourceId;
 
 /**
  * Tests the serializer helper methods.
  */
-
-@FixMethodOrder(MethodSorters.DEFAULT)
 public class AddToDataNodeIetfNetTest {
 
     TestYangSerializerContext context = new TestYangSerializerContext();
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeListTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeListTest.java
new file mode 100644
index 0000000..e5e6579
--- /dev/null
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeListTest.java
@@ -0,0 +1,194 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.runtime.impl.serializerhelper;
+
+import org.junit.Test;
+import org.onosproject.yang.model.DataNode;
+import org.onosproject.yang.model.InnerNode;
+import org.onosproject.yang.model.KeyLeaf;
+import org.onosproject.yang.model.ListKey;
+import org.onosproject.yang.model.NodeKey;
+import org.onosproject.yang.model.ResourceId;
+import org.onosproject.yang.runtime.helperutils.HelperContext;
+import org.onosproject.yang.runtime.impl.TestYangSerializerContext;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.Map;
+
+import static org.onosproject.yang.model.DataNode.Type.MULTI_INSTANCE_LEAF_VALUE_NODE;
+import static org.onosproject.yang.model.DataNode.Type.MULTI_INSTANCE_NODE;
+import static org.onosproject.yang.model.DataNode.Type.SINGLE_INSTANCE_LEAF_VALUE_NODE;
+import static org.onosproject.yang.model.DataNode.Type.SINGLE_INSTANCE_NODE;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.addDataNode;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.exitDataNode;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.getResourceId;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.initializeDataNode;
+import static org.onosproject.yang.runtime.impl.TestUtils.validateDataNode;
+import static org.onosproject.yang.runtime.impl.TestUtils.validateLeafDataNode;
+import static org.onosproject.yang.runtime.impl.TestUtils.validateResourceId;
+
+/**
+ * Tests the serializer helper methods.
+ */
+public class AddToDataNodeListTest {
+
+    public static final String LNS = "yrt:list";
+
+    TestYangSerializerContext context = new TestYangSerializerContext();
+
+    /*
+     * Reference for data node info.
+     */
+    HelperContext info;
+
+    /*
+     * Reference for data node builder.
+     */
+    DataNode.Builder dBlr;
+
+    /*
+     * Reference for resource id.
+     */
+    ResourceId id;
+
+    /*
+     * Reference for the value.
+     */
+    String value;
+
+    /*
+     * Reference for string array to used for resource id testing.
+     */
+    String[] nA;
+    String[] nsA;
+    String[] valA;
+
+    /**
+     * Test add to data node builder.
+     */
+    @Test
+    public void addToDataListTest() throws IOException {
+
+        Object ob;
+        dBlr = initializeDataNode(context);
+
+        dBlr = addDataNode(dBlr, "l1", LNS, value, null);
+        value = "1";
+        dBlr = addDataNode(dBlr, "k1", null, value, null);
+        dBlr = exitDataNode(dBlr);
+        value = "2";
+        dBlr = addDataNode(dBlr, "k2", null, value, null);
+        dBlr = exitDataNode(dBlr);
+        value = null;
+        dBlr = addDataNode(dBlr, "c1", null, value, null);
+        value = "0";
+        dBlr = addDataNode(dBlr, "l1", null, value, null);
+
+        info = (HelperContext) dBlr.appInfo();
+        id = getResourceId(dBlr);
+        dBlr = exitDataNode(dBlr);
+
+        ResourceId id1 = getResourceId(dBlr);
+        dBlr = exitDataNode(dBlr);
+
+        value = "3";
+        dBlr = addDataNode(dBlr, "k3", null, value, null);
+
+        info = (HelperContext) dBlr.appInfo();
+        ResourceId id2 = getResourceId(dBlr);
+
+        dBlr = exitDataNode(dBlr);
+        dBlr = exitDataNode(dBlr);
+
+        // Checking leaf list
+        value = "1";
+        dBlr = addDataNode(dBlr, "leaf1", LNS, value, null);
+        dBlr = exitDataNode(dBlr);
+        value = "2";
+        dBlr = addDataNode(dBlr, "leaf1", LNS, value, null);
+        dBlr = exitDataNode(dBlr);
+        value = "3";
+        dBlr = addDataNode(dBlr, "leaf1", LNS, value, null);
+        dBlr = exitDataNode(dBlr);
+        value = "4";
+        dBlr = addDataNode(dBlr, "leaf1", LNS, value, null);
+        ResourceId id3 = getResourceId(dBlr);
+        dBlr = exitDataNode(dBlr);
+
+        //Tree validation
+        nA = new String[]{"/", "l1", "k1", "k2", "k3", "c1", "l1", ""};
+        nsA = new String[]{null, LNS, LNS, LNS, LNS, LNS, LNS, ""};
+        valA = new String[]{"1", "2", "3", "0", ""};
+        validateResourceId(nA, nsA, valA, id);
+
+        nA = new String[]{"/", "l1", "k1", "k2", "k3", "c1", ""};
+        nsA = new String[]{null, LNS, LNS, LNS, LNS, LNS, ""};
+        valA = new String[]{"1", "2", "3", ""};
+        validateResourceId(nA, nsA, valA, id1);
+
+        nA = new String[]{"/", "l1", "k1", "k2", "k3", ""};
+        nsA = new String[]{null, LNS, LNS, LNS, LNS, ""};
+        valA = new String[]{"1", "2", "3", ""};
+        validateResourceId(nA, nsA, valA, id2);
+
+        nA = new String[]{"/", "leaf1", ""};
+        nsA = new String[]{null, LNS, ""};
+        valA = new String[]{"4", "2", "3", "0", ""};
+        validateResourceId(nA, nsA, valA, id3);
+
+        DataNode node = dBlr.build();
+        validateDataNode(node, "/", null, SINGLE_INSTANCE_NODE, true, null);
+
+        Map<NodeKey, DataNode> childMap = ((InnerNode) node).childNodes();
+        Iterator<Map.Entry<NodeKey, DataNode>> it = childMap.entrySet().iterator();
+        Map.Entry<NodeKey, DataNode> n = it.next();
+        validateDataNode(n.getValue(), "l1", LNS, MULTI_INSTANCE_NODE,
+                         true, null);
+
+        Iterator<KeyLeaf> keyIt = ((ListKey) n.getKey()).keyLeafs().iterator();
+
+        validateLeafDataNode(keyIt.next(), "k1", LNS, "1");
+        validateLeafDataNode(keyIt.next(), "k2", LNS, "2");
+        validateLeafDataNode(keyIt.next(), "k3", LNS, "3");
+
+        Iterator<Map.Entry<NodeKey, DataNode>> it1;
+        it1 = ((InnerNode) n.getValue()).childNodes().entrySet().iterator();
+        validateDataNode(it1.next().getValue(), "k1", LNS,
+                         SINGLE_INSTANCE_LEAF_VALUE_NODE, false, "1");
+        validateDataNode(it1.next().getValue(), "k2", LNS,
+                         SINGLE_INSTANCE_LEAF_VALUE_NODE, false, "2");
+        DataNode n1 = it1.next().getValue();
+        validateDataNode(n1, "c1", LNS,
+                         SINGLE_INSTANCE_NODE, true, null);
+        validateDataNode(it1.next().getValue(), "k3", LNS,
+                         SINGLE_INSTANCE_LEAF_VALUE_NODE, false, "3");
+
+        Iterator<Map.Entry<NodeKey, DataNode>> it2;
+        it2 = ((InnerNode) n1).childNodes().entrySet().iterator();
+        validateDataNode(it2.next().getValue(), "l1", LNS,
+                         SINGLE_INSTANCE_LEAF_VALUE_NODE, false, "0");
+        validateDataNode(it.next().getValue(), "leaf1", LNS,
+                         MULTI_INSTANCE_LEAF_VALUE_NODE, false, "1");
+        validateDataNode(it.next().getValue(), "leaf1", LNS,
+                         MULTI_INSTANCE_LEAF_VALUE_NODE, false, "2");
+        validateDataNode(it.next().getValue(), "leaf1", LNS,
+                         MULTI_INSTANCE_LEAF_VALUE_NODE, false, "3");
+        validateDataNode(it.next().getValue(), "leaf1", LNS,
+                         MULTI_INSTANCE_LEAF_VALUE_NODE, false, "4");
+    }
+}
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/AddToDataNodeRidTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeRidTest.java
similarity index 94%
rename from runtime/src/test/java/org/onosproject/yang/runtime/impl/AddToDataNodeRidTest.java
rename to runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeRidTest.java
index fdce7f3..f2a38ad 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/AddToDataNodeRidTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeRidTest.java
@@ -14,14 +14,13 @@
  * limitations under the License.
  */
 
-package org.onosproject.yang.runtime.impl;
+package org.onosproject.yang.runtime.impl.serializerhelper;
 
-import org.junit.FixMethodOrder;
 import org.junit.Test;
-import org.junit.runners.MethodSorters;
 import org.onosproject.yang.model.DataNode;
 import org.onosproject.yang.model.ResourceId;
 import org.onosproject.yang.runtime.helperutils.HelperContext;
+import org.onosproject.yang.runtime.impl.TestYangSerializerContext;
 
 import static org.onosproject.yang.runtime.helperutils.SerializerHelper.addDataNode;
 import static org.onosproject.yang.runtime.helperutils.SerializerHelper.addToResourceId;
@@ -33,8 +32,6 @@
 /**
  * Tests the serializer helper methods.
  */
-
-@FixMethodOrder(MethodSorters.DEFAULT)
 public class AddToDataNodeRidTest {
 
     public static final String LNS = "yrt:list";
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/AddToDataNodeRidTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToResourceIdTest.java
similarity index 65%
copy from runtime/src/test/java/org/onosproject/yang/runtime/impl/AddToDataNodeRidTest.java
copy to runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToResourceIdTest.java
index fdce7f3..271a649 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/AddToDataNodeRidTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToResourceIdTest.java
@@ -14,28 +14,25 @@
  * limitations under the License.
  */
 
-package org.onosproject.yang.runtime.impl;
+package org.onosproject.yang.runtime.impl.serializerhelper;
 
-import org.junit.FixMethodOrder;
 import org.junit.Test;
-import org.junit.runners.MethodSorters;
 import org.onosproject.yang.model.DataNode;
 import org.onosproject.yang.model.ResourceId;
 import org.onosproject.yang.runtime.helperutils.HelperContext;
+import org.onosproject.yang.runtime.impl.TestYangSerializerContext;
 
-import static org.onosproject.yang.runtime.helperutils.SerializerHelper.addDataNode;
+import java.util.LinkedList;
+import java.util.List;
+
 import static org.onosproject.yang.runtime.helperutils.SerializerHelper.addToResourceId;
-import static org.onosproject.yang.runtime.helperutils.SerializerHelper.getResourceId;
-import static org.onosproject.yang.runtime.helperutils.SerializerHelper.initializeDataNode;
 import static org.onosproject.yang.runtime.helperutils.SerializerHelper.initializeResourceId;
 import static org.onosproject.yang.runtime.impl.TestUtils.validateResourceId;
 
 /**
  * Tests the serializer helper methods.
  */
-
-@FixMethodOrder(MethodSorters.DEFAULT)
-public class AddToDataNodeRidTest {
+public class AddToResourceIdTest {
 
     public static final String LNS = "yrt:list";
 
@@ -69,24 +66,23 @@
     String[] valA;
 
     /**
-     * Test add to data node after initializing it with resource builder.
+     * Test add to data node builder.
      */
     @Test
     public void addToDataListTest() {
 
         ResourceId.Builder rIdBlr = initializeResourceId(context);
-        rIdBlr = addToResourceId(rIdBlr, "l1", LNS, value);
-        rIdBlr = addToResourceId(rIdBlr, "c1", LNS, value);
-        dBlr = initializeDataNode(rIdBlr);
-        value = "0";
-        dBlr = addDataNode(dBlr, "l1", null, value, null);
-        info = (HelperContext) dBlr.appInfo();
-        id = getResourceId(dBlr);
+        List<String> valueSet = new LinkedList<>();
+        valueSet.add("1");
+        valueSet.add("2");
+        valueSet.add("3");
+        rIdBlr = addToResourceId(rIdBlr, "l1", LNS, valueSet);
+        ResourceId id = rIdBlr.build();
 
         //Tree validation
-        nA = new String[]{"/", "l1", "c1", "l1", ""};
-        nsA = new String[]{null, LNS, LNS, LNS, ""};
-        valA = new String[]{"0", ""};
+        nA = new String[]{"/", "l1", "k1", "k2", "k3", ""};
+        nsA = new String[]{null, LNS, LNS, LNS, LNS, ""};
+        valA = new String[]{"1", "2", "3", ""};
         validateResourceId(nA, nsA, valA, id);
     }
 }
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/DataNodeInitializationTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/DataNodeInitializationTest.java
similarity index 93%
rename from runtime/src/test/java/org/onosproject/yang/runtime/impl/DataNodeInitializationTest.java
rename to runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/DataNodeInitializationTest.java
index e1d3fc2..4c95a74 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/DataNodeInitializationTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/DataNodeInitializationTest.java
@@ -14,15 +14,14 @@
  * limitations under the License.
  */
 
-package org.onosproject.yang.runtime.impl;
+package org.onosproject.yang.runtime.impl.serializerhelper;
 
-import org.junit.FixMethodOrder;
 import org.junit.Test;
-import org.junit.runners.MethodSorters;
 import org.onosproject.yang.model.DataNode;
 import org.onosproject.yang.model.ResourceId;
 import org.onosproject.yang.model.SchemaContext;
 import org.onosproject.yang.runtime.helperutils.HelperContext;
+import org.onosproject.yang.runtime.impl.TestYangSerializerContext;
 
 import static org.onosproject.yang.runtime.helperutils.SerializerHelper.initializeDataNode;
 import static org.onosproject.yang.runtime.helperutils.SerializerHelper.initializeResourceId;
@@ -31,8 +30,6 @@
 /**
  * Tests the initialize data node methods in serializer helper.
  */
-
-@FixMethodOrder(MethodSorters.DEFAULT)
 public class DataNodeInitializationTest {
 
     TestYangSerializerContext context = new TestYangSerializerContext();
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/DataNodeNegative1Test.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/DataNodeNegative1Test.java
new file mode 100644
index 0000000..39364b2
--- /dev/null
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/DataNodeNegative1Test.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.runtime.impl.serializerhelper;
+
+import org.junit.Test;
+import org.onosproject.yang.model.DataNode;
+import org.onosproject.yang.model.ResourceId;
+import org.onosproject.yang.runtime.impl.TestYangSerializerContext;
+
+import static org.junit.Assert.assertEquals;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.addDataNode;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.initializeDataNode;
+
+/**
+ * Tests the serializer helper methods.
+ */
+public class DataNodeNegative1Test {
+
+    TestYangSerializerContext context = new TestYangSerializerContext();
+
+    /*
+     * Reference for data node builder.
+     */
+    DataNode.Builder dBlr;
+
+    /*
+     * Reference for resource id.
+     */
+    ResourceId id;
+
+    /*
+     * Reference for the value.
+     */
+    String value;
+
+    private static final String E_NAMESPACE =
+            "NameSpace is mandatory to provide for first level node.";
+
+    /**
+     * Test adding a node null namespace negative scenario.
+     */
+    @Test
+    public void negativeTest() {
+
+        dBlr = initializeDataNode(context);
+        value = "1";
+        boolean isExpOccurred = false;
+        try {
+            dBlr = addDataNode(dBlr, "l1", null, value, null);
+        } catch (IllegalArgumentException e) {
+            isExpOccurred = true;
+            assertEquals(e.getMessage(), E_NAMESPACE);
+        }
+        assertEquals(isExpOccurred, true);
+    }
+}
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/DataNodeNegativeTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/DataNodeNegativeTest.java
new file mode 100644
index 0000000..7cef8a9
--- /dev/null
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/DataNodeNegativeTest.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.runtime.impl.serializerhelper;
+
+import org.junit.Test;
+import org.onosproject.yang.model.DataNode;
+import org.onosproject.yang.model.ResourceId;
+import org.onosproject.yang.runtime.impl.TestYangSerializerContext;
+
+import static org.junit.Assert.assertEquals;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.addDataNode;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.initializeDataNode;
+
+/**
+ * Tests the serializer helper methods.
+ */
+public class DataNodeNegativeTest {
+
+    public static final String LNS = "yrt:list";
+
+    TestYangSerializerContext context = new TestYangSerializerContext();
+
+    /*
+     * Reference for data node builder.
+     */
+    DataNode.Builder dBlr;
+
+    /*
+     * Reference for resource id.
+     */
+    ResourceId id;
+
+    /*
+     * Reference for the value.
+     */
+    String value;
+
+    private static final String FMT_NOT_EXIST =
+            "Schema node with name %s doesn't exist.";
+
+    /**
+     * Test adding a node with value negative scenario.
+     */
+    @Test
+    public void negative1Test() {
+
+        dBlr = initializeDataNode(context);
+        value = "1";
+        boolean isExpOccurred = false;
+        try {
+            dBlr = addDataNode(dBlr, "l1", LNS, value, null);
+        } catch (IllegalArgumentException e) {
+            isExpOccurred = true;
+            assertEquals(e.getMessage(), String.format(FMT_NOT_EXIST, "l1"));
+        }
+        assertEquals(isExpOccurred, true);
+    }
+}
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/ResourceIdInitializationTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/ResourceIdInitializationTest.java
similarity index 73%
rename from runtime/src/test/java/org/onosproject/yang/runtime/impl/ResourceIdInitializationTest.java
rename to runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/ResourceIdInitializationTest.java
index 7122c82..2ef2864 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/ResourceIdInitializationTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/ResourceIdInitializationTest.java
@@ -14,23 +14,22 @@
  * limitations under the License.
  */
 
-package org.onosproject.yang.runtime.impl;
+package org.onosproject.yang.runtime.impl.serializerhelper;
 
-import org.junit.FixMethodOrder;
 import org.junit.Test;
-import org.junit.runners.MethodSorters;
 import org.onosproject.yang.model.ResourceId;
 import org.onosproject.yang.model.SchemaContext;
+import org.onosproject.yang.runtime.impl.TestYangSerializerContext;
 
 import static org.onosproject.yang.runtime.helperutils.SerializerHelper.addToResourceId;
 import static org.onosproject.yang.runtime.helperutils.SerializerHelper.initializeResourceId;
-import static org.onosproject.yang.runtime.impl.SchemaContextTest.IETFNS;
+import static org.onosproject.yang.runtime.impl.schemacontext.SchemaContextTest.IETFNS;
 import static org.onosproject.yang.runtime.impl.TestUtils.checkRootLevelContext;
+import static org.onosproject.yang.runtime.impl.TestUtils.validateResourceId;
 
 /**
  * Tests the initialize resource id methods in serializer helper.
  */
-@FixMethodOrder(MethodSorters.DEFAULT)
 public class ResourceIdInitializationTest {
 
     TestYangSerializerContext context = new TestYangSerializerContext();
@@ -45,6 +44,13 @@
      */
     String value;
 
+    /*
+     * Reference for string array to used for resource id testing.
+     */
+    String[] nA;
+    String[] nsA;
+    String[] valA;
+
     /**
      * Checks initialize resource id.
      */
@@ -63,5 +69,11 @@
         rIdBlr = addToResourceId(rIdBlr, "network", null, value);
         value = "network1";
         rIdBlr = addToResourceId(rIdBlr, "network-id", null, value);
+        ResourceId id = rIdBlr.build();
+
+        nA = new String[]{"/", "networks", "network", "network-id", ""};
+        nsA = new String[]{null, IETFNS, IETFNS, IETFNS, ""};
+        valA = new String[]{"network1", ""};
+        validateResourceId(nA, nsA, valA, id);
     }
 }
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/ResourceIdNegative2Test.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/ResourceIdNegative2Test.java
new file mode 100644
index 0000000..655c9c8
--- /dev/null
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/ResourceIdNegative2Test.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.runtime.impl.serializerhelper;
+
+import org.junit.Test;
+import org.onosproject.yang.model.ResourceId;
+import org.onosproject.yang.runtime.impl.TestYangSerializerContext;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.addToResourceId;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.initializeResourceId;
+
+/**
+ * Tests the serializer helper methods.
+ */
+public class ResourceIdNegative2Test {
+
+    public static final String LNS = "yrt:list";
+
+    TestYangSerializerContext context = new TestYangSerializerContext();
+
+    private static final String E_TOO_MANY =
+            "Too many key parameters in l1. Expected 3; actual 4.";
+
+    /**
+     * Test adding list in resource id with more then expected key value
+     * negative scenario.
+     */
+    @Test
+    public void negative3Test() {
+
+        ResourceId.Builder rIdBlr = initializeResourceId(context);
+        List<String> valueSet = new LinkedList<>();
+        valueSet.add("1");
+        valueSet.add("2");
+        valueSet.add("3");
+        valueSet.add("4");
+        boolean isExpOccurred = false;
+        try {
+            addToResourceId(rIdBlr, "l1", LNS, valueSet);
+        } catch (IllegalArgumentException e) {
+            isExpOccurred = true;
+            assertEquals(e.getMessage(), E_TOO_MANY);
+        }
+        assertEquals(isExpOccurred, true);
+    }
+}
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/ResourceIdNegative3Test.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/ResourceIdNegative3Test.java
new file mode 100644
index 0000000..a7e39ca
--- /dev/null
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/ResourceIdNegative3Test.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.runtime.impl.serializerhelper;
+
+import org.junit.Test;
+import org.onosproject.yang.model.ResourceId;
+import org.onosproject.yang.runtime.impl.TestYangSerializerContext;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.addToResourceId;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.initializeResourceId;
+
+/**
+ * Tests the serializer helper methods.
+ */
+public class ResourceIdNegative3Test {
+
+    public static final String LNS = "yrt:list";
+
+    TestYangSerializerContext context = new TestYangSerializerContext();
+
+    private static final String E_TOO_FEW =
+            "Too few key parameters in l1. Expected 3; actual 2.";
+
+    /**
+     * Test adding list in resource id with less then expected key value
+     * negative scenario.
+     */
+    @Test
+    public void negativeTest() {
+
+        ResourceId.Builder rIdBlr = initializeResourceId(context);
+        List<String> valueSet = new LinkedList<>();
+        valueSet.add("1");
+        valueSet.add("2");
+        boolean isExpOccurred = false;
+        try {
+            rIdBlr = addToResourceId(rIdBlr, "l1", LNS, valueSet);
+        } catch (IllegalArgumentException e) {
+            isExpOccurred = true;
+            assertEquals(e.getMessage(), E_TOO_FEW);
+        }
+        assertEquals(isExpOccurred, true);
+    }
+}
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/ResourceIdNegativeTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/ResourceIdNegativeTest.java
new file mode 100644
index 0000000..2f09763
--- /dev/null
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/ResourceIdNegativeTest.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.runtime.impl.serializerhelper;
+
+import org.junit.Test;
+import org.onosproject.yang.model.ResourceId;
+import org.onosproject.yang.runtime.impl.TestYangSerializerContext;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.addToResourceId;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.initializeResourceId;
+
+/**
+ * Tests the serializer helper methods.
+ */
+public class ResourceIdNegativeTest {
+
+    public static final String LNS = "yrt:list";
+
+    TestYangSerializerContext context = new TestYangSerializerContext();
+
+    private static final String E_LEAFLIST =
+            "Method is not allowed to pass multiple values for leaf-list.";
+
+    /**
+     * Test adding a leaf-list node in resource id with list of values negative
+     * scenario.
+     */
+    @Test
+    public void negative1Test() {
+
+        ResourceId.Builder rIdBlr = initializeResourceId(context);
+        List<String> valueSet = new LinkedList<>();
+        valueSet.add("1");
+        valueSet.add("2");
+        boolean isExpOccurred = false;
+        try {
+            addToResourceId(rIdBlr, "leaf1", LNS, valueSet);
+        } catch (IllegalArgumentException e) {
+            isExpOccurred = true;
+            assertEquals(e.getMessage(), E_LEAFLIST);
+        }
+        assertEquals(isExpOccurred, true);
+    }
+}
diff --git a/runtime/src/test/resources/schemaProviderTestYangFiles/list.yang b/runtime/src/test/resources/schemaProviderTestYangFiles/list.yang
index fcc67eb..122ce11 100644
--- a/runtime/src/test/resources/schemaProviderTestYangFiles/list.yang
+++ b/runtime/src/test/resources/schemaProviderTestYangFiles/list.yang
@@ -34,4 +34,8 @@
                 }
             }
     }
+
+    leaf-list leaf1 {
+        type string;
+    }
 }
\ No newline at end of file