[ONOS-4798] Error Message implementation for YANG utils

Change-Id: Idb13e851258754773f8f447ace69a9393c7c1b3d
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"));