[ONOS-4798] Error Message implementation for YANG utils

Change-Id: Idb13e851258754773f8f447ace69a9393c7c1b3d
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java
index 3d81e0d..26e41c6 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java
@@ -88,7 +88,8 @@
 import org.onosproject.yangutils.parser.impl.listeners.ValueListener;
 import org.onosproject.yangutils.parser.impl.listeners.VersionListener;
 import org.onosproject.yangutils.parser.impl.listeners.WhenListener;
-
+import org.onosproject.yangutils.parser.impl.listeners.ErrorMessageListener;
+import org.onosproject.yangutils.parser.impl.listeners.ErrorAppTagListener;
 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.handleUnsupportedYangConstruct;
 import static org.onosproject.yangutils.utils.UtilConstants.CURRENTLY_UNSUPPORTED;
 import static org.onosproject.yangutils.utils.UtilConstants.UNSUPPORTED_YANG_CONSTRUCT;
@@ -845,7 +846,7 @@
 
     @Override
     public void enterErrorMessageStatement(GeneratedYangParser.ErrorMessageStatementContext ctx) {
-        handleUnsupportedYangConstruct(YangConstructType.ERROR_MESSAGE_DATA, ctx, CURRENTLY_UNSUPPORTED);
+        ErrorMessageListener.processErrorMessageEntry(this, ctx);
     }
 
     @Override
@@ -855,7 +856,7 @@
 
     @Override
     public void enterErrorAppTagStatement(GeneratedYangParser.ErrorAppTagStatementContext ctx) {
-        handleUnsupportedYangConstruct(YangConstructType.ERROR_APP_TAG_DATA, ctx, CURRENTLY_UNSUPPORTED);
+        ErrorAppTagListener.processErrorAppTagMessageEntry(this, ctx);
     }
 
     @Override
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ErrorAppTagListener.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ErrorAppTagListener.java
new file mode 100644
index 0000000..befc70a
--- /dev/null
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ErrorAppTagListener.java
@@ -0,0 +1,81 @@
+/*
+ * 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.listeners;
+
+import org.onosproject.yangutils.datamodel.YangAppErrorHolder;
+import org.onosproject.yangutils.datamodel.YangAppErrorInfo;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+
+import static org.onosproject.yangutils.datamodel.utils.YangConstructType.ERROR_APP_TAG_DATA;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
+
+/*
+ * Reference: RFC 6020 and YANG ANTLR Grammar
+ *
+ * ABNF grammar as per RFC 6020
+ *
+ *  error-app-tag-stmt  = error-app-tag-keyword sep string stmtend
+ *
+ * ANTLR grammar rule
+ * errorAppTagStatement : ERROR_APP_TAG_KEYWORD string STMTEND;
+ */
+
+/**
+ * Represents listener based call back function corresponding to the
+ * error app tag defined in ANTLR grammar file for corresponding ABNF rule
+ * in RFC 6020.
+ */
+public final class ErrorAppTagListener {
+
+    /**
+     * Creates a new error app tag listener.
+     */
+    private ErrorAppTagListener() {
+    }
+
+    /**
+     * Performs validations and updates the data model tree. It is called when parser
+     * receives an input matching the grammar rule error app tag.
+     *
+     * @param listener listener's object
+     * @param ctx      context object of the grammar rule
+     */
+    public static void processErrorAppTagMessageEntry(TreeWalkListener listener,
+                                                GeneratedYangParser.ErrorAppTagStatementContext ctx) {
+
+        // Check for stack to be non empty.
+        checkStackIsNotEmpty(listener, MISSING_HOLDER, ERROR_APP_TAG_DATA, ctx.string().getText(), ENTRY);
+        String errorMessage = removeQuotesAndHandleConcat(ctx.string().getText());
+        // Obtain the node of the stack.
+        Parsable tmpNode = listener.getParsedDataStack().peek();
+        if (tmpNode instanceof YangAppErrorHolder) {
+            YangAppErrorInfo yangAppErrorInfo = ((YangAppErrorHolder) tmpNode).getAppErrorInfo();
+            yangAppErrorInfo.setErrorAppTag(errorMessage);
+        } else {
+            throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, ERROR_APP_TAG_DATA,
+                    ctx.string().getText(), ENTRY));
+        }
+    }
+}
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ErrorMessageListener.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ErrorMessageListener.java
new file mode 100644
index 0000000..b6722b5
--- /dev/null
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ErrorMessageListener.java
@@ -0,0 +1,82 @@
+/*
+ * 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.listeners;
+
+import org.onosproject.yangutils.datamodel.YangAppErrorHolder;
+import org.onosproject.yangutils.datamodel.YangAppErrorInfo;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+
+import static org.onosproject.yangutils.datamodel.utils.YangConstructType.ERROR_MESSAGE_DATA;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
+
+/*
+ * Reference: RFC6020 and YANG ANTLR Grammar
+ *
+ * ABNF grammar as per RFC6020
+ *
+ *  error-message-stmt  = error-message-keyword sep string stmtend
+ *
+ * ANTLR grammar rule
+ * errorMessageStatement : ERROR_MESSAGE_KEYWORD string STMTEND;
+ */
+
+/**
+ * Represents listener based call back function corresponding to the
+ * app error message defined in ANTLR grammar file for corresponding ABNF rule
+ * in RFC 6020.
+ */
+public final class ErrorMessageListener {
+
+    /**
+     * Creates a new must listener.
+     */
+    private ErrorMessageListener() {
+    }
+
+    /**
+     * Performs validations and updates the data model tree. It is called when parser
+     * receives an input matching the grammar rule (app error message).
+     *
+     * @param listener listener's object
+     * @param ctx      context object of the grammar rule
+     */
+    public static void processErrorMessageEntry(TreeWalkListener listener,
+                                        GeneratedYangParser.ErrorMessageStatementContext ctx) {
+
+        // Check for stack to be non empty.
+        checkStackIsNotEmpty(listener, MISSING_HOLDER, ERROR_MESSAGE_DATA, ctx.string().getText(), ENTRY);
+        String errorMessage = removeQuotesAndHandleConcat(ctx.string().getText());
+
+        // Obtain the node of the stack.
+        Parsable tmpNode = listener.getParsedDataStack().peek();
+        if (tmpNode instanceof YangAppErrorHolder) {
+            YangAppErrorInfo yangAppErrorInfo = ((YangAppErrorHolder) tmpNode).getAppErrorInfo();
+            yangAppErrorInfo.setErrorMessage(errorMessage);
+        } else {
+            throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, ERROR_MESSAGE_DATA,
+                    ctx.string().getText(), ENTRY));
+        }
+    }
+}
\ No newline at end of file
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/MaxElementsListener.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/MaxElementsListener.java
index afb6dc3..90acba6 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/MaxElementsListener.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/MaxElementsListener.java
@@ -18,6 +18,7 @@
 
 import org.onosproject.yangutils.datamodel.YangLeafList;
 import org.onosproject.yangutils.datamodel.YangList;
+import org.onosproject.yangutils.datamodel.YangMaxElement;
 import org.onosproject.yangutils.datamodel.utils.Parsable;
 import org.onosproject.yangutils.datamodel.utils.YangConstructType;
 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
@@ -81,11 +82,15 @@
         switch (tmpData.getYangConstructType()) {
             case LEAF_LIST_DATA:
                 YangLeafList leafList = (YangLeafList) tmpData;
-                leafList.setMaxElelements(maxElementsValue);
+                YangMaxElement maxLeafListElement = new YangMaxElement();
+                maxLeafListElement.setMaxElement(maxElementsValue);
+                leafList.setMaxElements(maxLeafListElement);
                 break;
             case LIST_DATA:
                 YangList yangList = (YangList) tmpData;
-                yangList.setMaxElements(maxElementsValue);
+                YangMaxElement maxListElement = new YangMaxElement();
+                maxListElement.setMaxElement(maxElementsValue);
+                yangList.setMaxElements(maxListElement);
                 break;
             default:
                 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, MAX_ELEMENT_DATA, "", ENTRY));
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/MinElementsListener.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/MinElementsListener.java
index 7553aa2..7e7ed78 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/MinElementsListener.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/MinElementsListener.java
@@ -18,6 +18,7 @@
 
 import org.onosproject.yangutils.datamodel.YangLeafList;
 import org.onosproject.yangutils.datamodel.YangList;
+import org.onosproject.yangutils.datamodel.YangMinElement;
 import org.onosproject.yangutils.datamodel.utils.Parsable;
 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
 import org.onosproject.yangutils.parser.exceptions.ParserException;
@@ -78,11 +79,15 @@
         switch (tmpData.getYangConstructType()) {
             case LEAF_LIST_DATA:
                 YangLeafList leafList = (YangLeafList) tmpData;
-                leafList.setMinElements(minElementValue);
+                YangMinElement minLeafListElement = new YangMinElement();
+                minLeafListElement.setMinElement(minElementValue);
+                leafList.setMinElements(minLeafListElement);
                 break;
             case LIST_DATA:
                 YangList yangList = (YangList) tmpData;
-                yangList.setMinElements(minElementValue);
+                YangMinElement minElement = new YangMinElement();
+                minElement.setMinElement(minElementValue);
+                yangList.setMinElements(minElement);
                 break;
             default:
                 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, MIN_ELEMENT_DATA,
diff --git a/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/ErrorAppTagListenerTest.java b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/ErrorAppTagListenerTest.java
new file mode 100644
index 0000000..a367942
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/ErrorAppTagListenerTest.java
@@ -0,0 +1,83 @@
+/*
+ * 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.listeners;
+
+import org.junit.Test;
+import org.onosproject.yangutils.datamodel.YangMust;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangContainer;
+import org.onosproject.yangutils.datamodel.YangAppErrorInfo;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
+
+import java.io.IOException;
+import java.util.List;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test-cases for testing error app tag message listener functionality.
+ */
+public class ErrorAppTagListenerTest {
+    private final YangUtilsParserManager manager = new YangUtilsParserManager();
+
+    /**
+     * Checks if error app tag message is default updated in the data model.
+     */
+    @Test
+    public void processContainerSubStatementErrorDefaultAppTag() throws IOException, ParserException {
+        YangNode node = manager.getDataModel("src/test/resources/ContainerSubStatementErrorDefaultAppTag.yang");
+
+        YangModule yangNode = (YangModule) node;
+        assertThat(yangNode.getName(), is("ErrorAppTag"));
+
+        YangContainer yangContainer = (YangContainer) yangNode.getChild();
+        assertThat(yangContainer.getName(), is("interface"));
+
+        String expectedConstraint = "ifType != 'ethernet' or (ifType = 'ethernet' and ifMTU = 1500)";
+        List<YangMust> mustConstraintList = yangContainer.getListOfMust();
+        assertThat(mustConstraintList.iterator().next().getConstraint(), is(expectedConstraint));
+
+        YangAppErrorInfo yangAppErrorInfo = mustConstraintList.iterator().next().getAppErrorInfo();
+        assertThat(yangAppErrorInfo.getGetErrorAppTag(), is("must-violation"));
+        assertThat(yangAppErrorInfo.getGetErrorTag(), is("operation-failed"));
+    }
+
+    /**
+     * Checks if error app tag message listener updates the data model.
+     */
+    @Test
+    public void processContainerSubStatementErrorAppTag() throws IOException, ParserException {
+        YangNode node = manager.getDataModel("src/test/resources/ContainerSubStatementErrorAppTag.yang");
+
+        YangModule yangNode = (YangModule) node;
+        assertThat(yangNode.getName(), is("ErrorAppTag"));
+
+        YangContainer yangContainer = (YangContainer) yangNode.getChild();
+        assertThat(yangContainer.getName(), is("interface"));
+
+        String expectedConstraint = "ifType != 'ethernet' or (ifType = 'ethernet' and ifMTU = 1500)";
+        List<YangMust> mustConstraintList = yangContainer.getListOfMust();
+        assertThat(mustConstraintList.iterator().next().getConstraint(), is(expectedConstraint));
+
+        YangAppErrorInfo yangAppErrorInfo = mustConstraintList.iterator().next().getAppErrorInfo();
+        assertThat(yangAppErrorInfo.getGetErrorAppTag(), is("An ethernet MTU must be 1500"));
+        assertThat(yangAppErrorInfo.getGetErrorTag(), is("operation-failed"));
+    }
+}
\ No newline at end of file
diff --git a/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/ErrorMessageListnerTest.java b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/ErrorMessageListnerTest.java
new file mode 100644
index 0000000..bf53292
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/ErrorMessageListnerTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.listeners;
+
+import org.junit.Test;
+import org.onosproject.yangutils.datamodel.YangMust;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangContainer;
+import org.onosproject.yangutils.datamodel.YangAppErrorInfo;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
+
+import java.io.IOException;
+import java.util.List;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test-cases for testing error message listener functionality.
+ */
+public class ErrorMessageListnerTest {
+    private final YangUtilsParserManager manager = new YangUtilsParserManager();
+
+    /**
+     * Checks if error message listener updates the data model.
+     */
+    @Test
+    public void processContainerSubStatementErrorMessage() throws IOException, ParserException {
+        YangNode node = manager.getDataModel("src/test/resources/ContainerSubStatementErrorMessage.yang");
+
+        YangModule yangNode = (YangModule) node;
+        assertThat(yangNode.getName(), is("ErrorMessage"));
+
+        YangContainer yangContainer = (YangContainer) yangNode.getChild();
+        assertThat(yangContainer.getName(), is("interface"));
+
+        String expectedConstraint = "ifType != 'ethernet' or (ifType = 'ethernet' and ifMTU = 1500)";
+        List<YangMust> mustConstraintList = yangContainer.getListOfMust();
+        assertThat(mustConstraintList.iterator().next().getConstraint(), is(expectedConstraint));
+
+        YangAppErrorInfo yangAppErrorInfo = mustConstraintList.iterator().next().getAppErrorInfo();
+        assertThat(yangAppErrorInfo.getGetErrorMessage(), is("An ethernet MTU must be 1500"));
+        assertThat(yangAppErrorInfo.getGetErrorTag(), is("operation-failed"));
+    }
+}
diff --git a/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/InputListenerTest.java b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/InputListenerTest.java
index ade3747..9000235 100644
--- a/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/InputListenerTest.java
+++ b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/InputListenerTest.java
@@ -72,8 +72,8 @@
         assertThat(yangList.getName(), is("ospf"));
         assertThat(yangList.getKeyList().contains("invalid-interval"), is(true));
         assertThat(yangList.isConfig(), is(true));
-        assertThat(yangList.getMaxElements(), is(10));
-        assertThat(yangList.getMinElements(), is(3));
+        assertThat(yangList.getMaxElements().getMaxElement(), is(10));
+        assertThat(yangList.getMinElements().getMinElement(), is(3));
         leafIterator = yangList.getListOfLeaf().listIterator();
         leafInfo = leafIterator.next();
         assertThat(leafInfo.getName(), is("invalid-interval"));
diff --git a/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/LeafListListenerTest.java b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/LeafListListenerTest.java
index b156188..083bf81 100644
--- a/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/LeafListListenerTest.java
+++ b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/LeafListListenerTest.java
@@ -72,7 +72,7 @@
         assertThat(leafListInfo.getUnits(), is("\"seconds\""));
         assertThat(leafListInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
         assertThat(leafListInfo.isConfig(), is(true));
-        assertThat(leafListInfo.getMaxElelements(), is(3));
+        assertThat(leafListInfo.getMaxElements().getMaxElement(), is(3));
         assertThat(leafListInfo.getStatus(), is(YangStatusType.CURRENT));
         assertThat(leafListInfo.getReference(), is("\"RFC 6020\""));
     }
@@ -162,8 +162,8 @@
         assertThat(leafListInfo.getUnits(), is("\"seconds\""));
         assertThat(leafListInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
         assertThat(leafListInfo.isConfig(), is(true));
-        assertThat(leafListInfo.getMinElements(), is(1));
-        assertThat(leafListInfo.getMaxElelements(), is(2147483647));
+        assertThat(leafListInfo.getMinElements().getMinElement(), is(1));
+        assertThat(leafListInfo.getMaxElements().getMaxElement(), is(2147483647));
         assertThat(leafListInfo.getStatus(), is(YangStatusType.CURRENT));
         assertThat(leafListInfo.getReference(), is("\"RFC 6020\""));
     }
diff --git a/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/ListListenerTest.java b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/ListListenerTest.java
index ba7022a..2cde776 100644
--- a/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/ListListenerTest.java
+++ b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/ListListenerTest.java
@@ -151,8 +151,8 @@
         assertThat(yangList.getKeyList().contains("invalid-interval"), is(true));
 
         assertThat(yangList.isConfig(), is(true));
-        assertThat(yangList.getMaxElements(), is(10));
-        assertThat(yangList.getMinElements(), is(3));
+        assertThat(yangList.getMaxElements().getMaxElement(), is(10));
+        assertThat(yangList.getMinElements().getMinElement(), is(3));
         assertThat(yangList.getDescription(), is("\"list description\""));
         assertThat(yangList.getStatus(), is(YangStatusType.CURRENT));
         assertThat(yangList.getReference(), is("\"list reference\""));
diff --git a/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/MaxElementsListenerTest.java b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/MaxElementsListenerTest.java
index 29e4c63..ab47d2c 100644
--- a/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/MaxElementsListenerTest.java
+++ b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/MaxElementsListenerTest.java
@@ -65,7 +65,7 @@
         YangLeafList leafListInfo = leafListIterator.next();
 
         assertThat(leafListInfo.getName(), is("invalid-interval"));
-        assertThat(leafListInfo.getMaxElelements(), is(3));
+        assertThat(leafListInfo.getMaxElements().getMaxElement(), is(3));
     }
 
     /**
@@ -88,7 +88,7 @@
         // Check whether the list is child of module
         YangList yangList = (YangList) yangNode.getChild();
         assertThat(yangList.getName(), is("valid"));
-        assertThat(yangList.getMaxElements(), is(3));
+        assertThat(yangList.getMaxElements().getMaxElement(), is(3));
     }
 
     /**
@@ -136,7 +136,7 @@
         YangLeafList leafListInfo = leafListIterator.next();
 
         assertThat(leafListInfo.getName(), is("invalid-interval"));
-        assertThat(leafListInfo.getMaxElelements(), is(2147483647));
+        assertThat(leafListInfo.getMaxElements().getMaxElement(), is(2147483647));
     }
 
     /**
@@ -161,7 +161,7 @@
         YangLeafList leafListInfo = leafListIterator.next();
 
         assertThat(leafListInfo.getName(), is("invalid-interval"));
-        assertThat(leafListInfo.getMaxElelements(), is(2147483647));
+        assertThat(leafListInfo.getMaxElements().getMaxElement(), is(2147483647));
     }
 
     /**
diff --git a/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/MinElementsListenerTest.java b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/MinElementsListenerTest.java
index e362eeb..fcf6c39 100644
--- a/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/MinElementsListenerTest.java
+++ b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/MinElementsListenerTest.java
@@ -65,7 +65,7 @@
         YangLeafList leafListInfo = leafListIterator.next();
 
         assertThat(leafListInfo.getName(), is("invalid-interval"));
-        assertThat(leafListInfo.getMinElements(), is(3));
+        assertThat(leafListInfo.getMinElements().getMinElement(), is(3));
     }
 
     /**
@@ -88,7 +88,7 @@
         // Check whether the list is child of module
         YangList yangList = (YangList) yangNode.getChild();
         assertThat(yangList.getName(), is("valid"));
-        assertThat(yangList.getMinElements(), is(3));
+        assertThat(yangList.getMinElements().getMinElement(), is(3));
     }
 
     /**
@@ -158,6 +158,6 @@
         YangLeafList leafListInfo = leafListIterator.next();
 
         assertThat(leafListInfo.getName(), is("invalid-interval"));
-        assertThat(leafListInfo.getMinElements(), is(0));
+        assertThat(leafListInfo.getMinElements().getMinElement(), is(0));
     }
 }
diff --git a/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/OutputListenerTest.java b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/OutputListenerTest.java
index ea60935..e31f4c4 100644
--- a/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/OutputListenerTest.java
+++ b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/OutputListenerTest.java
@@ -71,8 +71,8 @@
         assertThat(yangList.getName(), is("ospf"));
         assertThat(yangList.getKeyList().contains("invalid-interval"), is(true));
         assertThat(yangList.isConfig(), is(true));
-        assertThat(yangList.getMaxElements(), is(10));
-        assertThat(yangList.getMinElements(), is(3));
+        assertThat(yangList.getMaxElements().getMaxElement(), is(10));
+        assertThat(yangList.getMinElements().getMinElement(), is(3));
         leafIterator = yangList.getListOfLeaf().listIterator();
         leafInfo = leafIterator.next();
         assertThat(leafInfo.getName(), is("invalid-interval"));
diff --git a/utils/yangutils/plugin/src/test/resources/ContainerSubStatementErrorAppTag.yang b/utils/yangutils/plugin/src/test/resources/ContainerSubStatementErrorAppTag.yang
new file mode 100644
index 0000000..644b890
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/ContainerSubStatementErrorAppTag.yang
@@ -0,0 +1,25 @@
+module ErrorAppTag {
+    yang-version 1;
+    namespace http://huawei.com;
+    prefix Ant;
+    container interface {
+        leaf ifType {
+            type enumeration {
+                enum ethernet;
+                enum atm;
+            }
+        }
+        leaf ifMTU {
+            type uint32;
+        }
+        must "ifType != 'ethernet' or " +
+             "(ifType = 'ethernet' and ifMTU = 1500)" {
+            description "An ethernet MTU must be 1500";
+            error-app-tag "An ethernet MTU must be 1500";
+        }
+        must "ifType != 'atm' or " +
+             "(ifType = 'atm' and ifMTU <= 17966 and ifMTU >= 64)" {
+            description "An atm MTU must be  64 .. 17966";
+        }
+    }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/ContainerSubStatementErrorDefaultAppTag.yang b/utils/yangutils/plugin/src/test/resources/ContainerSubStatementErrorDefaultAppTag.yang
new file mode 100644
index 0000000..c265ea2
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/ContainerSubStatementErrorDefaultAppTag.yang
@@ -0,0 +1,24 @@
+module ErrorAppTag {
+    yang-version 1;
+    namespace http://huawei.com;
+    prefix Ant;
+    container interface {
+        leaf ifType {
+            type enumeration {
+                enum ethernet;
+                enum atm;
+            }
+        }
+        leaf ifMTU {
+            type uint32;
+        }
+        must "ifType != 'ethernet' or " +
+             "(ifType = 'ethernet' and ifMTU = 1500)" {
+            description "An ethernet MTU must be 1500";
+        }
+        must "ifType != 'atm' or " +
+             "(ifType = 'atm' and ifMTU <= 17966 and ifMTU >= 64)" {
+            description "An atm MTU must be  64 .. 17966";
+        }
+    }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/ContainerSubStatementErrorMessage.yang b/utils/yangutils/plugin/src/test/resources/ContainerSubStatementErrorMessage.yang
new file mode 100644
index 0000000..4726d0c
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/ContainerSubStatementErrorMessage.yang
@@ -0,0 +1,25 @@
+module ErrorMessage {
+    yang-version 1;
+    namespace http://huawei.com;
+    prefix Ant;
+    container interface {
+        leaf ifType {
+            type enumeration {
+                enum ethernet;
+                enum atm;
+            }
+        }
+        leaf ifMTU {
+            type uint32;
+        }
+        must "ifType != 'ethernet' or " +
+             "(ifType = 'ethernet' and ifMTU = 1500)" {
+            description "An ethernet MTU must be 1500";
+            error-message "An ethernet MTU must be 1500";
+        }
+        must "ifType != 'atm' or " +
+             "(ifType = 'atm' and ifMTU <= 17966 and ifMTU >= 64)" {
+            description "An atm MTU must be  64 .. 17966";
+        }
+    }
+}