[ONOS-4563][ONOS-4564][ONOS-4551][ONOS-4538]defect fix

Change-Id: Ia3fe844e1e846d2e1d2c4359eefc815e7767aef9
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangEnum.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangEnum.java
index a9f80e3..df702e9 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangEnum.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangEnum.java
@@ -50,7 +50,7 @@
 /**
  * Represents the ENUM data type information.
  */
-public class YangEnum implements YangCommonInfo, Parsable {
+public class YangEnum implements YangCommonInfo, Parsable, Comparable<YangEnum> {
 
     /**
      * Named value for the ENUM.
@@ -226,4 +226,12 @@
     public void validateDataOnExit() throws DataModelException {
         // TODO auto-generated method stub, to be implemented by parser
     }
+
+    @Override
+    public int compareTo(YangEnum otherEnum) {
+        if (this.namedValue.equals(otherEnum.getNamedValue())) {
+            return 0;
+        }
+        return new Integer(this.value).compareTo(otherEnum.getValue());
+    }
 }
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangEnumeration.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangEnumeration.java
index 65f733c..9bf924a 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangEnumeration.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangEnumeration.java
@@ -16,8 +16,8 @@
 
 package org.onosproject.yangutils.datamodel;
 
-import java.util.HashSet;
-import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
 
 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
 import org.onosproject.yangutils.parser.Parsable;
@@ -34,7 +34,7 @@
 public class YangEnumeration extends YangNode implements Parsable, CollisionDetector {
 
     // Enumeration info set.
-    private Set<YangEnum> enumSet;
+    private SortedSet<YangEnum> enumSet;
 
     // Enumeration name.
     private String name;
@@ -44,7 +44,7 @@
      */
     public YangEnumeration() {
         super(YangNodeType.ENUMERATION_NODE);
-        setEnumSet(new HashSet<YangEnum>());
+        setEnumSet(new TreeSet<YangEnum>());
     }
 
     /**
@@ -52,7 +52,7 @@
      *
      * @return the ENUM set
      */
-    public Set<YangEnum> getEnumSet() {
+    public SortedSet<YangEnum> getEnumSet() {
         return enumSet;
     }
 
@@ -61,7 +61,7 @@
      *
      * @param enumSet the ENUM set to set
      */
-    private void setEnumSet(Set<YangEnum> enumSet) {
+    private void setEnumSet(SortedSet<YangEnum> enumSet) {
         this.enumSet = enumSet;
     }
 
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangTypeDef.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangTypeDef.java
index be2a5ed..a295b48 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangTypeDef.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangTypeDef.java
@@ -21,6 +21,8 @@
 import org.onosproject.yangutils.parser.Parsable;
 import org.onosproject.yangutils.utils.YangConstructType;
 
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
+
 /*-
  * Reference RFC 6020.
  *
@@ -54,7 +56,7 @@
 /**
  * Represents data model node to maintain information defined in YANG typedef.
  */
-public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable, YangTypeHolder {
+public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable, YangTypeHolder, CollisionDetector {
 
     /**
      * Default value in string, needs to be converted to the target object,
@@ -272,4 +274,18 @@
     public List<YangType<?>> getTypeList() {
         return typeList;
     }
+
+    @Override
+    public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
+        // Asks helper to detect colliding child.
+        detectCollidingChildUtil(identifierName, dataType, this);
+    }
+
+    @Override
+    public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
+        if (getName().equals(identifierName)) {
+            throw new DataModelException("YANG file error: Duplicate input identifier detected, same as typedef \""
+                    + getName() + "\"");
+        }
+    }
 }
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfo.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfo.java
index d838440..6332a99 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfo.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfo.java
@@ -34,6 +34,8 @@
 import static org.onosproject.yangutils.linker.impl.ResolvableStatus.LINKED;
 import static org.onosproject.yangutils.linker.impl.ResolvableStatus.RESOLVED;
 import static org.onosproject.yangutils.linker.impl.ResolvableStatus.UNRESOLVED;
+import static org.onosproject.yangutils.utils.UtilConstants.TYPEDEF_LINKER_ERROR;
+import static org.onosproject.yangutils.utils.UtilConstants.GROUPING_LINKER_ERROR;
 
 /**
  * Represents resolution object which will be resolved by linker.
@@ -180,9 +182,14 @@
 
                         if (resolvable.getResolvableStatus() == UNRESOLVED) {
                             // If current entity is still not resolved, then linking/resolution has failed.
+                            String errorInfo;
+                            if (resolvable instanceof YangType) {
+                                errorInfo = TYPEDEF_LINKER_ERROR;
+                            } else {
+                                errorInfo = GROUPING_LINKER_ERROR;
+                            }
                             DataModelException dataModelException =
-                                    new DataModelException("YANG file error: Unable to find base "
-                                            + "typedef/grouping for given type/uses");
+                                    new DataModelException(errorInfo);
                             dataModelException.setLine(getLineNumber());
                             dataModelException.setCharPosition(getCharPosition());
                             throw dataModelException;
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BitsListener.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BitsListener.java
index 07dba80..274e467 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BitsListener.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BitsListener.java
@@ -45,6 +45,8 @@
 import org.onosproject.yangutils.datamodel.YangLeaf;
 import org.onosproject.yangutils.datamodel.YangLeafList;
 import org.onosproject.yangutils.datamodel.YangType;
+import org.onosproject.yangutils.datamodel.YangTypeDef;
+import org.onosproject.yangutils.datamodel.YangUnion;
 import org.onosproject.yangutils.parser.Parsable;
 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
 import org.onosproject.yangutils.parser.exceptions.ParserException;
@@ -101,6 +103,12 @@
                 case LEAF_LIST_DATA:
                     bitsNode.setBitsName(((YangLeafList) tmpData).getName());
                     break;
+                case TYPEDEF_DATA:
+                    bitsNode.setBitsName(((YangTypeDef) tmpData).getName());
+                    break;
+                case UNION_DATA:
+                    bitsNode.setBitsName(((YangUnion) tmpData).getName());
+                    break;
                 // TODO typedef, union, deviate.
                 default:
                     throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, TYPE_DATA,
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/MaxElementsListener.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/MaxElementsListener.java
index efec3d1..eec78ba 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/MaxElementsListener.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/MaxElementsListener.java
@@ -106,7 +106,16 @@
         if (value.equals(UNBOUNDED_KEYWORD)) {
             maxElementsValue = Integer.MAX_VALUE;
         } else if (value.matches(POSITIVE_INTEGER_PATTERN)) {
-            maxElementsValue = Integer.parseInt(value);
+            try {
+                maxElementsValue = Integer.parseInt(value);
+            } catch (NumberFormatException e) {
+                ParserException parserException = new ParserException("YANG file error : " +
+                        YangConstructType.getYangConstructType(MAX_ELEMENT_DATA) + " value " + value + " is not " +
+                        "valid.");
+                parserException.setLine(ctx.getStart().getLine());
+                parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
+                throw parserException;
+            }
         } else {
             ParserException parserException = new ParserException("YANG file error : " +
                     YangConstructType.getYangConstructType(MAX_ELEMENT_DATA) + " value " + value + " is not " +
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeDefListener.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeDefListener.java
index b0a3b69..fc5dfef 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeDefListener.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeDefListener.java
@@ -35,6 +35,7 @@
 
 import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
 import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangTypeDefNode;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil;
 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
@@ -117,6 +118,11 @@
         // Validate sub statement cardinality.
         validateSubStatementsCardinality(ctx);
 
+        // Check for identifier collision
+        int line = ctx.getStart().getLine();
+        int charPositionInLine = ctx.getStart().getCharPositionInLine();
+        detectCollidingChildUtil(listener, line, charPositionInLine, identifier, TYPEDEF_DATA);
+
         /*
          * Create a derived type information, the base type must be set in type
          * listener.
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java
index 7f4e86b..a4ff8ae 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java
@@ -54,6 +54,7 @@
     private static final String DATE_PATTERN = "[0-9]{4}-([0-9]{2}|[0-9])-([0-9]{2}|[0-9])";
     private static final String NON_NEGATIVE_INTEGER_PATTERN = "[0-9]+";
     private static final Pattern INTEGER_PATTERN = Pattern.compile("[-][0-9]+|[0-9]+");
+    private static final String XML = "xml";
     private static final String ONE = "1";
     private static final int IDENTIFIER_LENGTH = 64;
     private static final String DATE_FORMAT = "yyyy-MM-dd";
@@ -102,6 +103,10 @@
             parserException = new ParserException("YANG file error : " +
                     YangConstructType.getYangConstructType(yangConstruct) + " name " + identifierString + " is not " +
                     "valid.");
+        } else if (identifierString.toLowerCase().startsWith(XML)) {
+            parserException = new ParserException("YANG file error : " +
+                    YangConstructType.getYangConstructType(yangConstruct) + " identifier " + identifierString +
+                    " must not start with (('X'|'x') ('M'|'m') ('L'|'l')).");
         } else {
             return identifierString;
         }
@@ -175,7 +180,18 @@
             throw parserException;
         }
 
-        return Integer.parseInt(value);
+        int valueInInteger;
+        try {
+            valueInInteger = Integer.parseInt(value);
+        } catch (NumberFormatException e) {
+            ParserException parserException = new ParserException("YANG file error : " +
+                    YangConstructType.getYangConstructType(yangConstruct) + " value " + value + " is not " +
+                    "valid.");
+            parserException.setLine(ctx.getStart().getLine());
+            parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
+            throw parserException;
+        }
+        return valueInInteger;
     }
 
     /**
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java
index 5c06f42..47e5c35 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java
@@ -251,8 +251,8 @@
      */
     private static void close(YangNode node)
             throws IOException {
-
-        if (((TempJavaCodeFragmentFilesContainer) node).getTempJavaCodeFragmentFiles() != null) {
+        if (node instanceof JavaCodeGenerator && ((TempJavaCodeFragmentFilesContainer) node)
+                .getTempJavaCodeFragmentFiles() != null) {
             ((TempJavaCodeFragmentFilesContainer) node).getTempJavaCodeFragmentFiles().freeTemporaryResources(true);
         }
     }
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java
index c35b744..023da61 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java
@@ -1337,19 +1337,6 @@
          */
         if ((fileType & INTERFACE_MASK) != 0 || (fileType &
                 BUILDER_INTERFACE_MASK) != 0) {
-            /*
-             * Adds import for case.
-             */
-            if (curNode instanceof YangCase) {
-                List<String> importData =
-                        ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
-                                .getBeanTempFiles().getJavaImportData().getImports();
-                for (String importInfo : importData) {
-                    if (!imports.contains(importInfo)) {
-                        imports.add(importInfo);
-                    }
-                }
-            }
 
             /*
              * Create interface file.
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/utils/YangJavaModelUtils.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/utils/YangJavaModelUtils.java
index 7bea5cd..8e02082 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/utils/YangJavaModelUtils.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/utils/YangJavaModelUtils.java
@@ -42,6 +42,7 @@
 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
 import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.addCurNodeInfoInParentTempFile;
 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage;
 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
 import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION_HOLDER;
@@ -279,7 +280,7 @@
         if (javaCodeGeneratorInfo instanceof YangCase) {
             YangNode parent = ((YangCase) javaCodeGeneratorInfo).getParent();
             JavaQualifiedTypeInfo parentsInfo = new JavaQualifiedTypeInfo();
-            String parentName = ((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName();
+            String parentName = getCapitalCase(((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName());
             String parentPkg = ((JavaFileInfoContainer) parent).getJavaFileInfo().getPackage();
             parentsInfo.setClassInfo(parentName);
             parentsInfo.setPkgInfo(parentPkg);
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
index c96a6ef..9ca906f 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
@@ -1122,6 +1122,18 @@
             " for YANG utils road map.";
 
     /**
+     * Static attribute for typedef linker error information.
+     */
+    public static final String TYPEDEF_LINKER_ERROR = "YANG file error: Unable to find base "
+            + "typedef for given type";
+
+    /**
+     * Static attribute for grouping linker error information.
+     */
+    public static final String GROUPING_LINKER_ERROR = "YANG file error: Unable to find base "
+            + "grouping for given uses";
+
+    /**
      * Creates an instance of util constants.
      */
     private UtilConstants() {
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/linker/IntraFileUsesLinkingTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/linker/IntraFileUsesLinkingTest.java
index e906afd..212a499 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/linker/IntraFileUsesLinkingTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/linker/IntraFileUsesLinkingTest.java
@@ -564,7 +564,7 @@
 
         thrown.expect(ParserException.class);
         thrown.expectMessage(
-                "YANG file error: Unable to find base typedef/grouping for given type/uses");
+                "YANG file error: Unable to find base grouping for given uses");
 
         YangNode node = manager
                 .getDataModel("src/test/resources/SelfResolutionNestedGroupingWithUnresolvedUses.yang");
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/BitListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/BitListenerTest.java
index 3aceb34..6487172 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/BitListenerTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/BitListenerTest.java
@@ -26,10 +26,14 @@
 import org.onosproject.yangutils.datamodel.YangModule;
 import org.onosproject.yangutils.datamodel.YangNode;
 import org.onosproject.yangutils.datamodel.YangNodeType;
+import org.onosproject.yangutils.datamodel.YangType;
+import org.onosproject.yangutils.datamodel.YangTypeDef;
+import org.onosproject.yangutils.datamodel.YangUnion;
 import org.onosproject.yangutils.parser.exceptions.ParserException;
 import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
 
 import java.io.IOException;
+import java.util.List;
 import java.util.ListIterator;
 import java.util.Set;
 
@@ -80,6 +84,84 @@
     }
 
     /**
+     * Checks bit statement with typedef.
+     */
+    @Test
+    public void processBitTypedefStatement() throws IOException, ParserException {
+
+        YangNode node = manager.getDataModel("src/test/resources/BitTypedefStatement.yang");
+
+        // Check whether the data model tree returned is of type module.
+        assertThat((node instanceof YangModule), is(true));
+
+        // Check whether the node type is set properly to module.
+        assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+
+        // Check whether the module name is set correctly.
+        YangModule yangNode = (YangModule) node;
+        assertThat(yangNode.getName(), is("Test"));
+
+        YangTypeDef typedef = (YangTypeDef) yangNode.getChild();
+        assertThat(typedef.getName(), is("type15"));
+
+        YangType type = typedef.getTypeList().iterator().next();
+        assertThat(type.getDataType(), is(YangDataTypes.BITS));
+        assertThat(type.getDataTypeName(), is("bits"));
+        Set<YangBit> bitSet = ((YangBits) type.getDataTypeExtendedInfo()).getBitSet();
+        for (YangBit tmp : bitSet) {
+            if (tmp.getBitName().equals("disable-nagle")) {
+                assertThat(tmp.getPosition(), is(0));
+            } else if (tmp.getBitName().equals("auto-sense-speed")) {
+                assertThat(tmp.getPosition(), is(1));
+            }
+        }
+    }
+
+    /**
+     * Checks bit statement with union.
+     */
+    @Test
+    public void processBitUnionStatement() throws IOException, ParserException {
+
+        YangNode node = manager.getDataModel("src/test/resources/BitUnionStatement.yang");
+
+        // Check whether the data model tree returned is of type module.
+        assertThat((node instanceof YangModule), is(true));
+
+        // Check whether the node type is set properly to module.
+        assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+
+        // Check whether the module name is set correctly.
+        YangModule yangNode = (YangModule) node;
+        assertThat(yangNode.getName(), is("Test"));
+
+        ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+        YangLeaf leafInfo = leafIterator.next();
+
+        assertThat(leafInfo.getName(), is("type15"));
+
+        assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UNION));
+        assertThat(leafInfo.getDataType().getDataTypeName(), is("union"));
+
+        YangUnion yangUnion = (YangUnion) leafInfo.getDataType().getDataTypeExtendedInfo();
+
+        List<YangType<?>> typeList = yangUnion.getTypeList();
+        ListIterator<YangType<?>> typeListIterator = typeList.listIterator();
+        YangType<?> yangType = typeListIterator.next();
+
+        assertThat(yangType.getDataType(), is(YangDataTypes.BITS));
+        assertThat(yangType.getDataTypeName(), is("bits"));
+        Set<YangBit> bitSet = ((YangBits) yangType.getDataTypeExtendedInfo()).getBitSet();
+        for (YangBit tmp : bitSet) {
+            if (tmp.getBitName().equals("disable-nagle")) {
+                assertThat(tmp.getPosition(), is(0));
+            } else if (tmp.getBitName().equals("auto-sense-speed")) {
+                assertThat(tmp.getPosition(), is(1));
+            }
+        }
+    }
+
+    /**
      * Checks if enum with same name is not allowed.
      */
     @Test(expected = ParserException.class)
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/EnumListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/EnumListenerTest.java
index a78c65f..a0bff1b 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/EnumListenerTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/EnumListenerTest.java
@@ -33,8 +33,9 @@
 import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
 
 import java.io.IOException;
+import java.util.Iterator;
 import java.util.ListIterator;
-import java.util.Set;
+import java.util.SortedSet;
 
 /**
  * Test cases for enum listener.
@@ -73,7 +74,7 @@
         assertThat(((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getName(),
                 is("speed_enum"));
 
-        Set<YangEnum> enumSet = ((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getEnumSet();
+        SortedSet<YangEnum> enumSet = ((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getEnumSet();
         for (YangEnum tmp : enumSet) {
             if (tmp.getNamedValue().equals("10m")) {
                 assertThat(tmp.getValue(), is(0));
@@ -114,4 +115,34 @@
                 + "with the current highest value");
         YangNode node = manager.getDataModel("src/test/resources/EnumMaxNextValue.yang");
     }
+
+    /**
+     * Checks enum values stored are sorted.
+     */
+    @Test
+    public void processEnumSorted() throws IOException, ParserException {
+        YangNode node = manager.getDataModel("src/test/resources/EnumSorted.yang");
+        // Check whether the data model tree returned is of type module.
+        assertThat((node instanceof YangModule), is(true));
+
+        // Check whether the node type is set properly to module.
+        assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+
+        // Check whether the module name is set correctly.
+        YangModule yangNode = (YangModule) node;
+        assertThat(yangNode.getName(), is("Test"));
+
+        ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+        YangLeaf leafInfo = leafIterator.next();
+
+        assertThat(leafInfo.getName(), is("ifType"));
+        assertThat(leafInfo.getDataType().getDataTypeName(), is("enumeration"));
+        assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.ENUMERATION));
+        assertThat(((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getName(),
+                is("ifType_enum"));
+
+        SortedSet<YangEnum> enumSet = ((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getEnumSet();
+        Iterator<YangEnum> enumIterator = enumSet.iterator();
+        assertThat(enumIterator.next().getNamedValue(), is("five"));
+    }
 }
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/MaxElementsListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/MaxElementsListenerTest.java
index c531b85..aa0cee2 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/MaxElementsListenerTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/MaxElementsListenerTest.java
@@ -176,4 +176,15 @@
         assertThat(leafListInfo.getName(), is("invalid-interval"));
         assertThat(leafListInfo.getMaxElelements(), is(2147483647));
     }
+
+    /**
+     * Checks whether exception is thrown when invalid min-elements value is
+     * given as input.
+     */
+    @Test
+    public void processMaxElementsMaxValue() throws IOException, ParserException {
+        thrown.expect(ParserException.class);
+        thrown.expectMessage("YANG file error : max-elements value 77777777777777777777777 is not valid.");
+        YangNode node = manager.getDataModel("src/test/resources/MaxElementsMaxValue.yang");
+    }
 }
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/MinElementsListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/MinElementsListenerTest.java
index bf1afb8..c2f668b 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/MinElementsListenerTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/MinElementsListenerTest.java
@@ -116,6 +116,17 @@
     }
 
     /**
+     * Checks whether exception is thrown when invalid min-elements value is
+     * given as input.
+     */
+    @Test
+    public void processMinElementsMaxValue() throws IOException, ParserException {
+        thrown.expect(ParserException.class);
+        thrown.expectMessage("YANG file error : min-elements value 77777777777777777777777 is not valid.");
+        YangNode node = manager.getDataModel("src/test/resources/MinElementsMaxValue.yang");
+    }
+
+    /**
      * Checks whether exception is thrown when min-elements statement without
      * statement end is given as input.
      */
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/parseutils/ListenerUtilTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/parseutils/ListenerUtilTest.java
new file mode 100644
index 0000000..c29b126
--- /dev/null
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/parseutils/ListenerUtilTest.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2016-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.yangutils.parser.impl.parseutils;
+
+import java.io.IOException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
+
+/**
+ * Test case for testing listener util.
+ */
+public class ListenerUtilTest {
+
+    @Rule
+    public ExpectedException thrown = ExpectedException.none();
+
+    private final YangUtilsParserManager manager = new YangUtilsParserManager();
+
+    /**
+     * Checks whether exception is thrown when identifier starts with xml.
+     */
+    @Test
+    public void validateIdentifierStartsWithXml() throws IOException {
+        thrown.expect(ParserException.class);
+        thrown.expectMessage("YANG file error : module identifier xMlTest must not start" +
+                " with (('X'|'x') ('M'|'m') ('L'|'l'))");
+        manager.getDataModel("src/test/resources/InValidIdentifierXML.yang");
+    }
+}
diff --git a/utils/yangutils/src/test/resources/BitTypedefStatement.yang b/utils/yangutils/src/test/resources/BitTypedefStatement.yang
new file mode 100644
index 0000000..d3dc26a
--- /dev/null
+++ b/utils/yangutils/src/test/resources/BitTypedefStatement.yang
@@ -0,0 +1,18 @@
+module Test {
+    yang-version 1;
+    namespace http://huawei.com;
+    prefix Ant;
+    typedef type15 { 
+        type bits {
+             bit disable-nagle {
+                 position 0;
+             }
+             bit auto-sense-speed {
+                 position 1;
+             }
+             bit Mb-only {
+                 position 2;
+             }
+         }
+    }
+}
diff --git a/utils/yangutils/src/test/resources/BitUnionStatement.yang b/utils/yangutils/src/test/resources/BitUnionStatement.yang
new file mode 100644
index 0000000..dd62eae
--- /dev/null
+++ b/utils/yangutils/src/test/resources/BitUnionStatement.yang
@@ -0,0 +1,20 @@
+module Test {
+    yang-version 1;
+    namespace http://huawei.com;
+    prefix Ant;
+    leaf type15 { 
+        type union {
+            type bits {
+                bit disable-nagle {
+                    position 0;
+                }
+                bit auto-sense-speed {
+                    position 1;
+                }
+                bit Mb-only {
+                    position 2;
+                }
+            }
+        }
+    }
+}
diff --git a/utils/yangutils/src/test/resources/EnumSorted.yang b/utils/yangutils/src/test/resources/EnumSorted.yang
new file mode 100644
index 0000000..3760e83
--- /dev/null
+++ b/utils/yangutils/src/test/resources/EnumSorted.yang
@@ -0,0 +1,18 @@
+module Test {
+    yang-version 1;
+    namespace http://huawei.com;
+    prefix Ant;
+    leaf ifType {
+        type enumeration {
+             enum four{
+                 value 7;
+             }
+             enum seven {
+                 value 2147483647;
+             }
+             enum five {
+                 value 5;
+             }       
+         }
+    }
+}
diff --git a/utils/yangutils/src/test/resources/InValidIdentifierXML.yang b/utils/yangutils/src/test/resources/InValidIdentifierXML.yang
new file mode 100644
index 0000000..c6a5a42
--- /dev/null
+++ b/utils/yangutils/src/test/resources/InValidIdentifierXML.yang
@@ -0,0 +1,5 @@
+module xMlTest {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix On;
+}
diff --git a/utils/yangutils/src/test/resources/MaxElementsMaxValue.yang b/utils/yangutils/src/test/resources/MaxElementsMaxValue.yang
new file mode 100644
index 0000000..7bdfbb0
--- /dev/null
+++ b/utils/yangutils/src/test/resources/MaxElementsMaxValue.yang
@@ -0,0 +1,9 @@
+module Test {
+    yang-version 1;
+    namespace http://huawei.com;
+    prefix Ant;
+    leaf-list invalid-interval {
+        type "uint16";
+        max-elements 77777777777777777777777;
+    }
+}
diff --git a/utils/yangutils/src/test/resources/MinElementsMaxValue.yang b/utils/yangutils/src/test/resources/MinElementsMaxValue.yang
new file mode 100644
index 0000000..785482b
--- /dev/null
+++ b/utils/yangutils/src/test/resources/MinElementsMaxValue.yang
@@ -0,0 +1,9 @@
+module Test {
+    yang-version 1;
+    namespace http://huawei.com;
+    prefix Ant;
+    leaf-list invalid-interval {
+        type "uint16";
+        min-elements 77777777777777777777777;
+    }
+}