[ONOS-7302] Add serializer helper implementation for value namespace

Change-Id: I2baf68b75b188568ffae42713ef6ad89dbba2241
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/DefaultYangNamespace.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/DefaultYangNamespace.java
index e0edb16..6b3b160 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/DefaultYangNamespace.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/DefaultYangNamespace.java
@@ -16,6 +16,8 @@
 
 package org.onosproject.yang.compiler.datamodel;
 
+import org.onosproject.yang.model.YangNamespace;
+
 /**
  * Represents YANG node identifier's namespace.
  */
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLeaf.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLeaf.java
index a82e9ce..9864f31 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLeaf.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLeaf.java
@@ -26,6 +26,7 @@
 import org.onosproject.yang.model.LeafType;
 import org.onosproject.yang.model.SchemaContext;
 import org.onosproject.yang.model.SchemaId;
+import org.onosproject.yang.model.YangNamespace;
 
 import java.io.Serializable;
 import java.util.LinkedList;
@@ -347,11 +348,6 @@
         return dataType;
     }
 
-    @Override
-    public boolean isEmptyDataType() {
-        return validateEmptyDataType(dataType);
-    }
-
     /**
      * Sets the data type.
      *
@@ -361,6 +357,11 @@
         this.dataType = dataType;
     }
 
+    @Override
+    public boolean isEmptyDataType() {
+        return validateEmptyDataType(dataType);
+    }
+
     /**
      * Retrieves the YANG node in which the leaf is defined.
      *
@@ -480,6 +481,11 @@
     }
 
     @Override
+    public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
+        this.ifFeatureList = ifFeatureList;
+    }
+
+    @Override
     public void addIfFeatureList(YangIfFeature ifFeature) {
         if (getIfFeatureList() == null) {
             setIfFeatureList(new LinkedList<>());
@@ -488,11 +494,6 @@
     }
 
     @Override
-    public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
-        this.ifFeatureList = ifFeatureList;
-    }
-
-    @Override
     public YangSchemaNodeContextInfo getChildSchema(
             YangSchemaNodeIdentifier dataNodeIdentifier)
             throws DataModelException {
@@ -676,8 +677,9 @@
     }
 
     @Override
-    public String getValueNamespace(String value) {
-        return LeafContextUtil.getValueNamespace(dataType, value, dataType.getDataType());
+    public YangNamespace getValueNamespace(String value) {
+        return LeafContextUtil.getValueNamespace(dataType, value,
+                                                 dataType.getDataType());
     }
 
     @Override
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLeafList.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLeafList.java
index c44973a..dc9bbf5 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLeafList.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLeafList.java
@@ -26,6 +26,7 @@
 import org.onosproject.yang.model.LeafType;
 import org.onosproject.yang.model.SchemaContext;
 import org.onosproject.yang.model.SchemaId;
+import org.onosproject.yang.model.YangNamespace;
 
 import java.io.Serializable;
 import java.util.LinkedList;
@@ -365,11 +366,6 @@
         return dataType;
     }
 
-    @Override
-    public boolean isEmptyDataType() {
-        return validateEmptyDataType(dataType);
-    }
-
     /**
      * Sets the data type.
      *
@@ -379,6 +375,11 @@
         this.dataType = dataType;
     }
 
+    @Override
+    public boolean isEmptyDataType() {
+        return validateEmptyDataType(dataType);
+    }
+
     /**
      * Retrieves the YANG node in which the leaf is defined.
      *
@@ -458,6 +459,11 @@
     }
 
     @Override
+    public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
+        this.ifFeatureList = ifFeatureList;
+    }
+
+    @Override
     public void addIfFeatureList(YangIfFeature ifFeature) {
         if (getIfFeatureList() == null) {
             setIfFeatureList(new LinkedList<>());
@@ -466,11 +472,6 @@
     }
 
     @Override
-    public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
-        this.ifFeatureList = ifFeatureList;
-    }
-
-    @Override
     public List<YangMust> getListOfMust() {
         return mustConstraintList;
     }
@@ -670,8 +671,9 @@
     }
 
     @Override
-    public String getValueNamespace(String value) {
-        return LeafContextUtil.getValueNamespace(dataType, value, dataType.getDataType());
+    public YangNamespace getValueNamespace(String value) {
+        return LeafContextUtil.getValueNamespace(dataType, value,
+                                                 dataType.getDataType());
     }
 
     @Override
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangModule.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangModule.java
index 8a33060..c12641e 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangModule.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangModule.java
@@ -18,6 +18,7 @@
 import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
 import org.onosproject.yang.compiler.datamodel.utils.Parsable;
 import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+import org.onosproject.yang.model.YangNamespace;
 
 import java.util.HashMap;
 import java.util.LinkedList;
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangNode.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangNode.java
index 8be0fe9..9e3d35b 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangNode.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangNode.java
@@ -21,6 +21,7 @@
 import org.onosproject.yang.model.DataNode;
 import org.onosproject.yang.model.SchemaContext;
 import org.onosproject.yang.model.SchemaId;
+import org.onosproject.yang.model.YangNamespace;
 
 import java.io.Serializable;
 import java.util.HashMap;
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangSchemaNode.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangSchemaNode.java
index 1444086..5287bcb 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangSchemaNode.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangSchemaNode.java
@@ -18,6 +18,7 @@
 
 import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
 import org.onosproject.yang.model.SchemaContext;
+import org.onosproject.yang.model.YangNamespace;
 
 import java.util.Map;
 
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangSchemaNodeIdentifier.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangSchemaNodeIdentifier.java
index 1ddd311..3867470 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangSchemaNodeIdentifier.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangSchemaNodeIdentifier.java
@@ -16,6 +16,8 @@
 
 package org.onosproject.yang.compiler.datamodel;
 
+import org.onosproject.yang.model.YangNamespace;
+
 import java.io.Serializable;
 import java.util.Objects;
 
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangSubModule.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangSubModule.java
index abce15c..58b88fd 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangSubModule.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangSubModule.java
@@ -18,6 +18,7 @@
 import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
 import org.onosproject.yang.compiler.datamodel.utils.Parsable;
 import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+import org.onosproject.yang.model.YangNamespace;
 
 import java.util.HashMap;
 import java.util.LinkedHashMap;
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/LeafContextUtil.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/LeafContextUtil.java
index 71d1ccd..51873ff 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/LeafContextUtil.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/LeafContextUtil.java
@@ -22,6 +22,7 @@
 import org.onosproject.yang.compiler.datamodel.YangLeafRef;
 import org.onosproject.yang.compiler.datamodel.YangType;
 import org.onosproject.yang.compiler.datamodel.YangUnion;
+import org.onosproject.yang.model.YangNamespace;
 
 import java.math.BigDecimal;
 import java.math.BigInteger;
@@ -115,11 +116,11 @@
      * @param typeInfo refers to YANG type information
      * @param v        v argument is leaf value used to set the value in method
      * @param dataType yang data type
-     * @return value namespace of corresponding given data type and value
+     * @return YANG namespace of corresponding given data type and value
      * @throws IllegalArgumentException if input is not valid
      */
-    public static String getValueNamespace(YangType typeInfo, String v,
-                                           YangDataTypes dataType)
+    public static YangNamespace getValueNamespace(YangType typeInfo, String v,
+                                                  YangDataTypes dataType)
             throws IllegalArgumentException {
         YangDataTypes type;
         if (dataType != null) {
@@ -166,23 +167,22 @@
         }
     }
 
-    private static String getReferIdNamespace(YangIdentity refId, String v) {
+    private static YangNamespace getReferIdNamespace(YangIdentity refId, String v) {
         String baseIdentity = refId.getYangSchemaNodeIdentifier().getName();
         if (v.equals(baseIdentity)) {
-            return refId.getYangSchemaNodeIdentifier().getNameSpace()
-                    .getModuleNamespace();
+            return refId.getYangSchemaNodeIdentifier().getNameSpace();
         }
         for (YangIdentity i : refId.getExtendList()) {
             String refIdentity = i.getYangSchemaNodeIdentifier().getName();
             if (v.equals(refIdentity)) {
-                return i.getYangSchemaNodeIdentifier().getNameSpace()
-                        .getModuleNamespace();
+                return i.getYangSchemaNodeIdentifier().getNameSpace();
             }
         }
         throw new IllegalArgumentException("Invalid value of data");
     }
 
-    private static String getUnionValNamespace(YangType type, String leafValue) {
+    private static YangNamespace getUnionValNamespace(YangType type,
+                                                      String leafValue) {
         Iterator<YangType<?>> it = ((YangUnion) type.getDataTypeExtendedInfo())
                 .getTypeList().listIterator();
         while (it.hasNext()) {
diff --git a/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/YangLinkerUtils.java b/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/YangLinkerUtils.java
index cc893db..e246f07 100644
--- a/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/YangLinkerUtils.java
+++ b/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/YangLinkerUtils.java
@@ -34,7 +34,7 @@
 import org.onosproject.yang.compiler.datamodel.YangLeafRef;
 import org.onosproject.yang.compiler.datamodel.YangLeavesHolder;
 import org.onosproject.yang.compiler.datamodel.YangList;
-import org.onosproject.yang.compiler.datamodel.YangNamespace;
+import org.onosproject.yang.model.YangNamespace;
 import org.onosproject.yang.compiler.datamodel.YangNode;
 import org.onosproject.yang.compiler.datamodel.YangNodeIdentifier;
 import org.onosproject.yang.compiler.datamodel.YangPathPredicate;
diff --git a/model/src/main/java/org/onosproject/yang/model/DataNode.java b/model/src/main/java/org/onosproject/yang/model/DataNode.java
index abeadf7..a998bab 100644
--- a/model/src/main/java/org/onosproject/yang/model/DataNode.java
+++ b/model/src/main/java/org/onosproject/yang/model/DataNode.java
@@ -209,10 +209,25 @@
          * @param value     value for leaf node
          * @return child node builder
          */
+        @Deprecated
         public abstract LeafNode.Builder createChildBuilder(
                 String name, String nameSpace, Object value);
 
         /**
+         * Creates a child build of type leaf node and set a back reference
+         * of parent node. it is used while creating a data tree. the value
+         * of leaf is set while creation.
+         *
+         * @param name         name of leaf node
+         * @param nameSpace    namespace of leaf node
+         * @param value        value for leaf node
+         * @param valNamespace leaf value namespace
+         * @return child node builder
+         */
+        public abstract LeafNode.Builder createChildBuilder(
+                String name, String nameSpace, Object value, String valNamespace);
+
+        /**
          * Deletes child node for a given node key from parent node.
          * <p>
          * for deleting a node from data tree , caller should parse resource
diff --git a/model/src/main/java/org/onosproject/yang/model/InnerNode.java b/model/src/main/java/org/onosproject/yang/model/InnerNode.java
index 7d07056..5b013d8 100644
--- a/model/src/main/java/org/onosproject/yang/model/InnerNode.java
+++ b/model/src/main/java/org/onosproject/yang/model/InnerNode.java
@@ -166,6 +166,15 @@
         }
 
         @Override
+        public LeafNode.Builder createChildBuilder(String name, String nameSpace,
+                                                   Object value, String valNamespace) {
+            return LeafNode.builder(name, nameSpace)
+                    .parent(this)
+                    .value(value)
+                    .valueNamespace(valNamespace);
+        }
+
+        @Override
         public InnerNode.Builder deleteChild(NodeKey key) {
             childNodes.remove(key);
             return this;
diff --git a/model/src/main/java/org/onosproject/yang/model/LeafNode.java b/model/src/main/java/org/onosproject/yang/model/LeafNode.java
index e0d0859..beeb165 100644
--- a/model/src/main/java/org/onosproject/yang/model/LeafNode.java
+++ b/model/src/main/java/org/onosproject/yang/model/LeafNode.java
@@ -211,6 +211,13 @@
         }
 
         @Override
+        public LeafNode.Builder createChildBuilder(String name, String nameSpace,
+                                                   Object value, String valNamespace) {
+            throw new IllegalStateException("leaf node can't have a child " +
+                                                    "node");
+        }
+
+        @Override
         public InnerNode.Builder deleteChild(NodeKey key) {
             throw new IllegalStateException("leaf node can't have a child " +
                                                     "node");
diff --git a/model/src/main/java/org/onosproject/yang/model/LeafSchemaContext.java b/model/src/main/java/org/onosproject/yang/model/LeafSchemaContext.java
index bf93ad2..f42250c 100644
--- a/model/src/main/java/org/onosproject/yang/model/LeafSchemaContext.java
+++ b/model/src/main/java/org/onosproject/yang/model/LeafSchemaContext.java
@@ -55,5 +55,5 @@
      * @return value namespace, null indicates that value namespace is same
      * as leaf namespace
      */
-    String getValueNamespace(String value);
+    YangNamespace getValueNamespace(String value);
 }
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangNamespace.java b/model/src/main/java/org/onosproject/yang/model/YangNamespace.java
similarity index 94%
rename from compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangNamespace.java
rename to model/src/main/java/org/onosproject/yang/model/YangNamespace.java
index 8609886..efa1890 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangNamespace.java
+++ b/model/src/main/java/org/onosproject/yang/model/YangNamespace.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package org.onosproject.yang.compiler.datamodel;
+package org.onosproject.yang.model;
 
 /**
  * Representation of YANG namespace.
diff --git a/model/src/test/java/org/onosproject/yang/model/DataTreeOperationTest.java b/model/src/test/java/org/onosproject/yang/model/DataTreeOperationTest.java
index 108bc7d..f937e9c 100644
--- a/model/src/test/java/org/onosproject/yang/model/DataTreeOperationTest.java
+++ b/model/src/test/java/org/onosproject/yang/model/DataTreeOperationTest.java
@@ -100,7 +100,7 @@
                 .exitNode()
 
                 //C1's child leaf L1
-                .createChildBuilder(L1, L1_NAMESPACE, 10)
+                .createChildBuilder(L1, L1_NAMESPACE, 10, null)
                 .type(SINGLE_INSTANCE_LEAF_VALUE_NODE)
 
                 //Builder l1 and traverse back to c1
@@ -114,7 +114,7 @@
                 .type(SINGLE_INSTANCE_NODE)
                 //C2's leaf l2
 
-                .createChildBuilder(L2, L2_NAMESPACE, "string")
+                .createChildBuilder(L2, L2_NAMESPACE, "string", null)
                 .type(MULTI_INSTANCE_LEAF_VALUE_NODE)
 
                 //build l2 and add it to c2 and traverse back to c2.
@@ -281,7 +281,7 @@
                 //Reach to c2 by fetching it from the map.
                 .getChildBuilder(keys.get(1))
                 //add l3 in c2.
-                .createChildBuilder(L3, L3_NAMESPACE, 15)
+                .createChildBuilder(L3, L3_NAMESPACE, 15, null)
                 .type(MULTI_INSTANCE_LEAF_VALUE_NODE)
                 .addLeafListValue(16)
 
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/SerializerHelper.java b/runtime/src/main/java/org/onosproject/yang/runtime/SerializerHelper.java
index 6c40db9..ecd1c3c 100644
--- a/runtime/src/main/java/org/onosproject/yang/runtime/SerializerHelper.java
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/SerializerHelper.java
@@ -29,6 +29,7 @@
 import org.onosproject.yang.model.SchemaContext;
 import org.onosproject.yang.model.SchemaId;
 import org.onosproject.yang.model.SingleInstanceNodeContext;
+import org.onosproject.yang.model.YangNamespace;
 import org.onosproject.yang.runtime.impl.DefaultYangModelRegistry;
 
 import java.util.Iterator;
@@ -278,6 +279,37 @@
     public static Builder addDataNode(Builder builder,
                                       String name, String namespace,
                                       String value, DataNode.Type type) {
+        return addDataNode(builder, name, namespace, value, null, type);
+    }
+
+    /**
+     * Adds a data node to a given data node builder.
+     * <p>
+     * Name and builder is mandatory inputs. If namespace is not provided
+     * parents namespace will be added for data node. Value should be
+     * provided for leaf/leaf-list. In case of leaf-list it's expected that this
+     * API is called for each leaf-list instance. Callers aware about the node
+     * type can opt to provide data node type, implementation will carry out
+     * validations based on input type and obtained type.
+     * <p>
+     * This API will also carry out necessary schema related validations.
+     *
+     * @param builder      data node builder
+     * @param name         name of data node
+     * @param namespace    namespace of data node
+     * @param value        value of data node
+     * @param valNamespace value's namespace, either module name of namespace,
+     *                     null indicates its same as leaf
+     * @param type         type of data node
+     * @return data node builder with added information
+     * @throws IllegalArgumentException when given input is not as per the
+     *                                  schema context
+     * @throws IllegalStateException    when a key is added under a atomic child
+     */
+    public static Builder addDataNode(Builder builder,
+                                      String name, String namespace,
+                                      String value, String valNamespace,
+                                      DataNode.Type type) {
         try {
             Object valObject;
             SchemaContext node;
@@ -326,13 +358,17 @@
                             throw new IllegalArgumentException(E_RESID);
                         }
                         valObject = getLeaf(value, childSchema);
+                        valNamespace = getValidValNamespace(value, childSchema,
+                                                            valNamespace);
                         builder = LeafNode.builder(name, namespace).type(nodeType)
-                                .value(valObject);
+                                .value(valObject).valueNamespace(valNamespace);
                         break;
                     case MULTI_INSTANCE_LEAF_VALUE_NODE:
                         valObject = getLeafList(value, childSchema);
+                        valNamespace = getValidValNamespace(value, childSchema,
+                                                            valNamespace);
                         builder = LeafNode.builder(name, namespace).type(nodeType)
-                                .value(valObject);
+                                .value(valObject).valueNamespace(valNamespace);
                         builder = builder.addLeafListValue(valObject);
                         break;
                     default:
@@ -348,17 +384,23 @@
                 switch (nodeType) {
                     case SINGLE_INSTANCE_LEAF_VALUE_NODE:
                         valObject = getLeaf(value, childSchema);
+                        valNamespace = getValidValNamespace(value, childSchema,
+                                                            valNamespace);
                         if (((YangLeaf) childSchema).isKeyLeaf()) {
                             builder = builder.addKeyLeaf(
                                     name, namespace, valObject);
                         }
                         builder = builder.createChildBuilder(
-                                name, namespace, valObject).type(nodeType);
+                                name, namespace, valObject, valNamespace)
+                                .type(nodeType);
                         break;
                     case MULTI_INSTANCE_LEAF_VALUE_NODE:
                         valObject = getLeafList(value, childSchema);
+                        valNamespace = getValidValNamespace(value, childSchema,
+                                                            valNamespace);
                         builder = builder.createChildBuilder(
-                                name, namespace, valObject).type(nodeType);
+                                name, namespace, valObject, valNamespace)
+                                .type(nodeType);
                         builder = builder.addLeafListValue(valObject);
                         break;
                     default:
@@ -416,6 +458,33 @@
         return schema.fromString(val);
     }
 
+
+    /**
+     * Returns valid value namespace which is module's namespace.
+     *
+     * @param val    value in string
+     * @param ctx    schema context
+     * @param actual valNamespace either module name of namespace
+     * @return validated value module's namespace
+     * @throws IllegalArgumentException if input namespace is invalid
+     */
+    private static String getValidValNamespace(String val, SchemaContext ctx,
+                                               String actual)
+            throws IllegalArgumentException {
+        LeafSchemaContext schema = (LeafSchemaContext) ctx;
+        YangNamespace expected = schema.getValueNamespace(val);
+        if (actual == null) {
+            if (expected == null ||
+                    expected.getModuleNamespace().equals(ctx.getSchemaId().namespace())) {
+                return null;
+            }
+        } else if (actual.equals(expected.getModuleName()) ||
+                actual.equals(expected.getModuleNamespace())) {
+            return expected.getModuleNamespace();
+        }
+        throw new IllegalArgumentException("Invalid input for value namespace");
+    }
+
     /**
      * Returns resource identifier for a given data node. This API will
      * be used by serializer to obtain the resource identifier in the
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/MoIdToRscIdTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/MoIdToRscIdTest.java
index acba744..3149618 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/MoIdToRscIdTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/MoIdToRscIdTest.java
@@ -21,7 +21,7 @@
 import org.onosproject.yang.compiler.datamodel.YangInput;
 import org.onosproject.yang.compiler.datamodel.YangLeaf;
 import org.onosproject.yang.compiler.datamodel.YangModule;
-import org.onosproject.yang.compiler.datamodel.YangNamespace;
+import org.onosproject.yang.model.YangNamespace;
 import org.onosproject.yang.compiler.datamodel.YangNode;
 import org.onosproject.yang.compiler.datamodel.YangNotification;
 import org.onosproject.yang.compiler.datamodel.YangOutput;
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/YobGroupingUsesTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/YobGroupingUsesTest.java
index fd9303e..a5ed7b0 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/YobGroupingUsesTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/YobGroupingUsesTest.java
@@ -145,7 +145,9 @@
         dBlr = addDataNode(dBlr, "name", TE, value, null);
         dBlr = exitDataNode(dBlr);
         value = "tunnel-p2p";
-        dBlr = addDataNode(dBlr, "type", TE, value, null);
+        dBlr = addDataNode(dBlr, "type", TE, value,
+                           "yrt-ietf-te-types",
+                           null);
         dBlr = exitDataNode(dBlr); // tunnel-p2p
         dBlr = exitDataNode(dBlr); // state
         dBlr = exitDataNode(dBlr); // tunnel
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/YobSimpleDataTypeTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/YobSimpleDataTypeTest.java
index 74e4253..29f3333 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/YobSimpleDataTypeTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/YobSimpleDataTypeTest.java
@@ -50,6 +50,7 @@
     private static final String DATA_TYPE_NAME_SPACE = "simple:data:types";
     private static final String DATA_TYPE_NAME_SPACE_LL =
             "simple:data:types:ll";
+    private static final String VALUE_NAMESPACE = "yms:test:ytb:data:types";
     TestYangSerializerContext context = new TestYangSerializerContext();
     private Builder dBlr;
     private String value;
@@ -248,197 +249,154 @@
         value = "8";
         dBlr = addDataNode(dBlr, "lref1", DATA_TYPE_NAME_SPACE, value, null);
         dBlr = exitDataNode(dBlr);
-
         value = "val";
         dBlr = addDataNode(dBlr, "lref2", DATA_TYPE_NAME_SPACE, value, null);
         dBlr = exitDataNode(dBlr);
-
         value = "zero";
         dBlr = addDataNode(dBlr, "lref3", DATA_TYPE_NAME_SPACE, value, null);
         dBlr = exitDataNode(dBlr);
-
         value = "b2 b3";
         dBlr = addDataNode(dBlr, "lref4", DATA_TYPE_NAME_SPACE, value, null);
         dBlr = exitDataNode(dBlr);
-
         value = "-92233720368547758.08";
         dBlr = addDataNode(dBlr, "lref5", DATA_TYPE_NAME_SPACE, value, null);
         dBlr = exitDataNode(dBlr);
-
         value = "10";
         dBlr = addDataNode(dBlr, "lref6", DATA_TYPE_NAME_SPACE, value, null);
         dBlr = exitDataNode(dBlr);
-
         value = "enum4";
         dBlr = addDataNode(dBlr, "lref7", DATA_TYPE_NAME_SPACE, value, null);
         dBlr = exitDataNode(dBlr);
-
         value = "-9223372036854.775808";
         dBlr = addDataNode(dBlr, "lref8", DATA_TYPE_NAME_SPACE, value, null);
         dBlr = exitDataNode(dBlr);
-
         value = "MTAxMDEwMTAx";
         dBlr = addDataNode(dBlr, "lref9", DATA_TYPE_NAME_SPACE, value, null);
         dBlr = exitDataNode(dBlr);
-
         value = "";
         dBlr = addDataNode(dBlr, "lref10", DATA_TYPE_NAME_SPACE, value, null);
         dBlr = exitDataNode(dBlr);
-
         value = "";
         dBlr = addDataNode(dBlr, "lref11", DATA_TYPE_NAME_SPACE, value, null);
         dBlr = exitDataNode(dBlr);
-
         value = "b3";
         dBlr = addDataNode(dBlr, "lref12", DATA_TYPE_NAME_SPACE, value, null);
         dBlr = exitDataNode(dBlr);
-
         value = "";
         dBlr = addDataNode(dBlr, "lref13", DATA_TYPE_NAME_SPACE, value, null);
         dBlr = exitDataNode(dBlr);
-
         value = "b1 b2 b3";
         dBlr = addDataNode(dBlr, "lref14", DATA_TYPE_NAME_SPACE, value, null);
         dBlr = exitDataNode(dBlr);
-
         value = "/cont";
         dBlr = addDataNode(dBlr, "lref15", DATA_TYPE_NAME_SPACE, value, null);
         dBlr = exitDataNode(dBlr);
-
         value = "physical";
-        dBlr = addDataNode(dBlr, "lref16", DATA_TYPE_NAME_SPACE, value, null);
+        dBlr = addDataNode(dBlr, "lref16", DATA_TYPE_NAME_SPACE, value,
+                           VALUE_NAMESPACE, null);
         dBlr = exitDataNode(dBlr);
-
         value = "784985";
         dBlr = addDataNode(dBlr, "lref17", DATA_TYPE_NAME_SPACE, value, null);
         dBlr = exitDataNode(dBlr);
-
         value = "MTExMTExMTE=";
         dBlr = addDataNode(dBlr, "lref18", DATA_TYPE_NAME_SPACE, value, null);
         dBlr = exitDataNode(dBlr);
-
         value = "hundred";
         dBlr = addDataNode(dBlr, "lref19", DATA_TYPE_NAME_SPACE, value, null);
         dBlr = exitDataNode(dBlr);
-
         value = "leafref";
         dBlr = addDataNode(dBlr, "lref20", DATA_TYPE_NAME_SPACE, value, null);
         dBlr = exitDataNode(dBlr);
-
         value = "val";
         dBlr = addDataNode(dBlr, "iref1", DATA_TYPE_NAME_SPACE, value, null);
         dBlr = exitDataNode(dBlr);
-
         value = "pro";
         dBlr = addDataNode(dBlr, "iref2", DATA_TYPE_NAME_SPACE, value, null);
         dBlr = exitDataNode(dBlr);
-
         value = "physical";
-        dBlr = addDataNode(dBlr, "iref3", DATA_TYPE_NAME_SPACE, value, null);
+        dBlr = addDataNode(dBlr, "iref3", DATA_TYPE_NAME_SPACE, value,
+                           VALUE_NAMESPACE, null);
         dBlr = exitDataNode(dBlr);
-
         value = "virtual";
-        dBlr = addDataNode(dBlr, "iref4", DATA_TYPE_NAME_SPACE, value, null);
+        dBlr = addDataNode(dBlr, "iref4", DATA_TYPE_NAME_SPACE, value,
+                           VALUE_NAMESPACE, null);
         dBlr = exitDataNode(dBlr);
-
         dBlr = addDataNode(dBlr, "cont3", DATA_TYPE_NAME_SPACE, null, null);
-
         value = "108";
         dBlr = addDataNode(dBlr, "llref1", DATA_TYPE_NAME_SPACE, value, null);
         dBlr = exitDataNode(dBlr);
-
         value = "val";
         dBlr = addDataNode(dBlr, "llref2", DATA_TYPE_NAME_SPACE, value, null);
         dBlr = exitDataNode(dBlr);
-
         value = "one";
         dBlr = addDataNode(dBlr, "llref3", DATA_TYPE_NAME_SPACE, value, null);
         dBlr = exitDataNode(dBlr);
-
         value = "b1 b3";
         dBlr = addDataNode(dBlr, "llref4", DATA_TYPE_NAME_SPACE, value, null);
         dBlr = exitDataNode(dBlr);
-
         value = "-922337203685470058.08";
         dBlr = addDataNode(dBlr, "llref5", DATA_TYPE_NAME_SPACE, value, null);
         dBlr = exitDataNode(dBlr);
-
         value = "121";
         dBlr = addDataNode(dBlr, "llref6", DATA_TYPE_NAME_SPACE, value, null);
         dBlr = exitDataNode(dBlr);
-
         value = "3.3ms";
         dBlr = addDataNode(dBlr, "llref7", DATA_TYPE_NAME_SPACE, value, null);
         dBlr = exitDataNode(dBlr);
-
         value = "-9223372036000.775808";
         dBlr = addDataNode(dBlr, "llref8", DATA_TYPE_NAME_SPACE, value, null);
         dBlr = exitDataNode(dBlr);
-
         value = "MTExMTExMTE=";
         dBlr = addDataNode(dBlr, "llref9", DATA_TYPE_NAME_SPACE, value, null);
         dBlr = exitDataNode(dBlr);
-
         value = "";
         dBlr = addDataNode(dBlr, "llref11", DATA_TYPE_NAME_SPACE, value, null);
         dBlr = exitDataNode(dBlr);
-
         value = "b2";
         dBlr = addDataNode(dBlr, "llref12", DATA_TYPE_NAME_SPACE, value, null);
         dBlr = exitDataNode(dBlr);
-
         value = "";
         dBlr = addDataNode(dBlr, "llref13", DATA_TYPE_NAME_SPACE, value, null);
         dBlr = exitDataNode(dBlr);
-
         value = "b1";
         dBlr = addDataNode(dBlr, "llref14", DATA_TYPE_NAME_SPACE, value, null);
         dBlr = exitDataNode(dBlr);
-
         value = "/cont/con2";
         dBlr = addDataNode(dBlr, "llref15", DATA_TYPE_NAME_SPACE, value, null);
         dBlr = exitDataNode(dBlr);
-
         value = "virtual";
-        dBlr = addDataNode(dBlr, "llref16", DATA_TYPE_NAME_SPACE, value, null);
+        dBlr = addDataNode(dBlr, "llref16", DATA_TYPE_NAME_SPACE, value,
+                           "yms:test:ytb:data:types", null);
         dBlr = exitDataNode(dBlr);
-
         value = "78498522";
         dBlr = addDataNode(dBlr, "llref17", DATA_TYPE_NAME_SPACE, value, null);
         dBlr = exitDataNode(dBlr);
-
         value = "MDEwMTAxMDEw";
         dBlr = addDataNode(dBlr, "llref18", DATA_TYPE_NAME_SPACE, value, null);
         dBlr = exitDataNode(dBlr);
-
         value = "ten";
         dBlr = addDataNode(dBlr, "llref19", DATA_TYPE_NAME_SPACE, value, null);
         dBlr = exitDataNode(dBlr);
-
         value = "leaflistref";
         dBlr = addDataNode(dBlr, "llref20", DATA_TYPE_NAME_SPACE, value, null);
         dBlr = exitDataNode(dBlr);
-
         value = "check";
         dBlr = addDataNode(dBlr, "lref21", DATA_TYPE_NAME_SPACE, value, null);
         dBlr = exitDataNode(dBlr);
-
         value = "val";
         dBlr = addDataNode(dBlr, "iref1", DATA_TYPE_NAME_SPACE, value, null);
         dBlr = exitDataNode(dBlr);
-
         value = "pro";
         dBlr = addDataNode(dBlr, "iref2", DATA_TYPE_NAME_SPACE, value, null);
         dBlr = exitDataNode(dBlr);
-
         value = "physical";
-        dBlr = addDataNode(dBlr, "iref3", DATA_TYPE_NAME_SPACE, value, null);
+        dBlr = addDataNode(dBlr, "iref3", DATA_TYPE_NAME_SPACE, value,
+                           VALUE_NAMESPACE, null);
         dBlr = exitDataNode(dBlr);
-
         value = "virtual";
-        dBlr = addDataNode(dBlr, "iref4", DATA_TYPE_NAME_SPACE, value, null);
+        dBlr = addDataNode(dBlr, "iref4", DATA_TYPE_NAME_SPACE, value,
+                           VALUE_NAMESPACE, null);
         dBlr = exitDataNode(dBlr);
-
         dBlr = exitDataNode(dBlr);
         return dBlr;
     }