[ONOS-4894][ONOS-4890][ONOS-4887][ONOS-4923]extension and argument
datamodel and listener + defect fix

Change-Id: Icefe046d9848935bb6c40a6d7688feb084edd65d
diff --git a/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/CaseListenerTest.java b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/CaseListenerTest.java
index 675a9e9..9ebf0df 100644
--- a/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/CaseListenerTest.java
+++ b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/CaseListenerTest.java
@@ -16,9 +16,10 @@
 
 package org.onosproject.yangutils.parser.impl.listeners;
 
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.core.Is.is;
+import java.io.IOException;
+import java.util.ListIterator;
 import org.junit.Test;
+import org.onosproject.yangutils.datamodel.YangAugment;
 import org.onosproject.yangutils.datamodel.YangCase;
 import org.onosproject.yangutils.datamodel.YangChoice;
 import org.onosproject.yangutils.datamodel.YangContainer;
@@ -29,8 +30,8 @@
 import org.onosproject.yangutils.parser.exceptions.ParserException;
 import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
 
-import java.io.IOException;
-import java.util.ListIterator;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
 
 /**
  * Test cases for case listener.
@@ -202,4 +203,36 @@
         YangLeaf leafInfo2 = leafIterator2.next();
         assertThat(leafInfo2.getName(), is("beer"));
     }
+
+    /**
+     * Checks case substatement of augment.
+     */
+    @Test
+    public void processCaseSubStatementOfAugment() throws IOException, ParserException {
+
+        YangNode node = manager.getDataModel("src/test/resources/CaseSubStatementOfAugment.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("event"));
+
+        YangAugment augment = ((YangAugment) yangNode.getChild());
+        assertThat(augment.getName(), is("/snmp:snmp/snmp:engine/snmp:listen/snmp:transport"));
+
+        YangCase yangCase = ((YangCase) augment.getChild());
+        assertThat(yangCase.getName(), is("tls"));
+
+        YangCase yangCase1 = ((YangCase) yangCase.getNextSibling());
+        assertThat(yangCase1.getName(), is("dtls"));
+
+        YangContainer container = ((YangContainer) yangCase.getChild());
+        assertThat(container.getName(), is("tls"));
+        assertThat(container.getListOfLeaf().iterator().next().getName(), is("ip"));
+    }
 }
diff --git a/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/ExtensionListenerTest.java b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/ExtensionListenerTest.java
new file mode 100644
index 0000000..d5c3c83
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/ExtensionListenerTest.java
@@ -0,0 +1,60 @@
+/*
+ * 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 java.io.IOException;
+import org.junit.Test;
+import org.onosproject.yangutils.datamodel.YangExtension;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangNodeType;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+/**
+ * Test cases for testing extension listener.
+ */
+public class ExtensionListenerTest {
+
+    private final YangUtilsParserManager manager = new YangUtilsParserManager();
+
+    /**
+     * Checks extension statement as sub-statement of module.
+     */
+    @Test
+    public void processValidExtensionStatement() throws IOException, ParserException {
+
+        YangNode node = manager.getDataModel("src/test/resources/ValidExtensionStatement.yang");
+
+        assertThat((node instanceof YangModule), is(true));
+
+        // Check whether the node type is set properly to module.
+        assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+
+        YangModule yangNode = (YangModule) node;
+        assertThat(yangNode.getName(), is("ietf-yang-compiler-annotation"));
+
+        YangExtension extension = yangNode.getExtensionList().iterator().next();
+        assertThat(extension.getName(), is("compiler-annotation"));
+        assertThat(extension.getArgumentName(), is("target"));
+        assertThat(extension.getDescription(), is("\"This extension allows for defining compiler annotations\""));
+    }
+}
+
diff --git a/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/InterFileLinkingTest.java b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/InterFileLinkingTest.java
index 8052f30..7379074 100644
--- a/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/InterFileLinkingTest.java
+++ b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/InterFileLinkingTest.java
@@ -16,13 +16,19 @@
 
 package org.onosproject.yangutils.plugin.manager;
 
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.ListIterator;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
+import org.onosproject.yangutils.datamodel.YangAugment;
+import org.onosproject.yangutils.datamodel.YangContainer;
 import org.onosproject.yangutils.datamodel.YangDerivedInfo;
 import org.onosproject.yangutils.datamodel.YangGrouping;
 import org.onosproject.yangutils.datamodel.YangLeaf;
+import org.onosproject.yangutils.datamodel.YangList;
 import org.onosproject.yangutils.datamodel.YangModule;
 import org.onosproject.yangutils.datamodel.YangNode;
 import org.onosproject.yangutils.datamodel.YangNodeType;
@@ -36,10 +42,6 @@
 import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
 import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
 
-import java.io.IOException;
-import java.util.Iterator;
-import java.util.ListIterator;
-
 import static org.hamcrest.CoreMatchers.nullValue;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.core.Is.is;
@@ -779,4 +781,60 @@
         assertThat(referredNode1.getName(), is("module2"));
         assertThat(referredNode1.getPriority(), is(3));
     }
+
+    /**
+     * Checks contents of uses are copied as child of grouping.
+     */
+    @Test
+    public void usesInsideChildOfGrouping()
+            throws IOException, ParserException, MojoExecutionException {
+
+        String searchDir = "src/test/resources/usesInsideChildOfGrouping";
+        utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+        utilManager.parseYangFileInfoSet();
+        utilManager.resolveDependenciesUsingLinker();
+
+        YangNode selfNode = null;
+        YangNode refNode1 = null;
+
+        for (YangNode rootNode : utilManager.getYangNodeSet()) {
+            if (rootNode.getName().equals("ietf-network")) {
+                selfNode = rootNode;
+            } else if (rootNode.getName().equals("ietf-te-topology")) {
+                refNode1 = rootNode;
+            }
+        }
+
+        // Check whether the data model tree returned is of type module.
+        assertThat(selfNode instanceof YangModule, is(true));
+        assertThat(selfNode.getNodeType(), is(MODULE_NODE));
+        YangModule yangNode = (YangModule) selfNode;
+        assertThat(yangNode.getName(), is("ietf-network"));
+
+        YangModule refNode = (YangModule) refNode1;
+        assertThat(refNode.getName(), is("ietf-te-topology"));
+
+        YangAugment augment = ((YangAugment) refNode.getChild().getNextSibling().
+                getNextSibling().getNextSibling().getNextSibling());
+        assertThat(augment.getName(), is("/nw:networks/nw:network/nw:node"));
+
+        YangUses uses = ((YangUses) augment.getChild());
+        YangContainer container = ((YangContainer) uses.getNextSibling());
+        assertThat(container.getName(), is("te"));
+
+        container = ((YangContainer) container.getChild());
+        assertThat(container.getName(), is("config"));
+
+        uses = ((YangUses) container.getChild().getNextSibling());
+        assertThat(uses.getName(), is("te-node-config-attributes"));
+
+        YangContainer container1 = ((YangContainer) uses.getNextSibling());
+        assertThat(container1.getName(), is("te-node-attributes"));
+
+        uses = ((YangUses) container1.getChild());
+        assertThat(uses.getName(), is("te-node-connectivity-matrix"));
+
+        YangList list = ((YangList) uses.getNextSibling());
+        assertThat(list.getName(), is("connectivity-matrix"));
+    }
 }
diff --git a/utils/yangutils/plugin/src/test/resources/CaseSubStatementOfAugment.yang b/utils/yangutils/plugin/src/test/resources/CaseSubStatementOfAugment.yang
new file mode 100644
index 0000000..7123f91
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/CaseSubStatementOfAugment.yang
@@ -0,0 +1,58 @@
+module event {
+
+    namespace "http://example.com/event";
+    prefix "ev";
+
+    augment /snmp:snmp/snmp:engine/snmp:listen/snmp:transport {
+    if-feature tlstm;
+    case tls {
+      container tls {
+        description
+          "A list of IPv4 and IPv6 addresses and ports to which the
+           engine listens for SNMP messages over TLS.";
+        leaf ip {
+          type inet:ip-address;
+          mandatory true;
+          description
+            "The IPv4 or IPv6 address on which the engine listens
+             for SNMP messages over TLS.";
+        }
+        leaf port {
+          type inet:port-number;
+          description
+            "The TCP port on which the engine listens for SNMP
+             messages over TLS.
+             If the port is not configured, an engine that
+             acts as a Command Responder uses port 10161, and
+             an engine that acts as a Notification Receiver
+             uses port 10162.";
+        }
+      }
+    }
+    case dtls {
+      container dtls1 {
+        description
+          "A list of IPv4 and IPv6 addresses and ports to which the
+           engine listens for SNMP messages over DTLS.";
+        leaf ip {
+          type inet:ip-address;
+          mandatory true;
+          description
+            "The IPv4 or IPv6 address on which the engine listens
+             for SNMP messages over DTLS.";
+        }
+        leaf port {
+          type inet:port-number;
+          description
+            "The UDP port on which the engine listens for SNMP
+             messages over DTLS.
+             If the port is not configured, an engine that
+             acts as a Command Responder uses port 10161, and
+             an engine that acts as a Notification Receiver
+             uses port 10162.";
+        }
+      }
+    }
+  }
+}
+
diff --git a/utils/yangutils/plugin/src/test/resources/ValidExtensionStatement.yang b/utils/yangutils/plugin/src/test/resources/ValidExtensionStatement.yang
new file mode 100644
index 0000000..ca134fa
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/ValidExtensionStatement.yang
@@ -0,0 +1,36 @@
+module ietf-yang-compiler-annotation {
+
+   namespace "urn:ietf:params:xml:ns:yang:ietf-yang-compiler-annotation";
+
+   prefix "ca";
+
+   organization
+     "IETF NETMOD (NETCONF Data Modeling Language) Working Group";
+
+   contact
+     "WG Web:   <http://tools.ietf.org/wg/netmod/>
+      WG List:  <mailto:netmod@ietf.org>";
+
+   description
+     "This YANG module defines an extension statement that allows for
+      defining compiler annotations.
+
+      The key words 'MUST', 'MUST NOT', 'REQUIRED', 'SHALL', 'SHALL
+      NOT', 'SHOULD', 'SHOULD NOT', 'RECOMMENDED', 'MAY', and
+      'OPTIONAL' in the module text are to be interpreted as described
+      in RFC 2119 (http://tools.ietf.org/html/rfc2119).";
+
+     revision 2016-07-08 {
+     description
+       "Initial revision.";
+     reference
+       "draft-agv-netmod-yang-compiler-metadata:
+        Defining and Using compiler annotations with YANG";
+     }
+
+     extension compiler-annotation {
+        argument target;
+        description "This extension allows for defining compiler annotations";
+      } // compiler-annotation
+   } //module agv-yang-compiler-annotation
+
diff --git a/utils/yangutils/plugin/src/test/resources/usesInsideChildOfGrouping/ietf-network.yang b/utils/yangutils/plugin/src/test/resources/usesInsideChildOfGrouping/ietf-network.yang
new file mode 100644
index 0000000..8fb2bc0
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/usesInsideChildOfGrouping/ietf-network.yang
@@ -0,0 +1,28 @@
+module ietf-network {
+    yang-version 1;
+    namespace "urn:ietf:params:xml:ns:yang:ietf-network";
+    prefix nd;
+
+    revision 2015-12-08 {
+       description
+         "Initial revision.
+          NOTE TO RFC EDITOR: Please replace the following reference
+          to draft-ietf-i2rs-yang-network-topo-02 with
+          RFC number when published (i.e. RFC xxxx).";
+    }
+
+    container networks {
+        list network {
+            key "network-id";
+            leaf network-id {
+                type string;
+            }
+            list node {
+                key "node-id";
+                leaf node-id {
+                    type string;
+                }
+            }
+        }
+    }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/usesInsideChildOfGrouping/ietf-te-topology.yang b/utils/yangutils/plugin/src/test/resources/usesInsideChildOfGrouping/ietf-te-topology.yang
new file mode 100644
index 0000000..f1776fb
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/usesInsideChildOfGrouping/ietf-te-topology.yang
@@ -0,0 +1,60 @@
+module ietf-te-topology {
+    yang-version 1;
+    namespace "urn:ietf:params:xml:ns:yang:ietf-te-topology";
+
+    prefix "tet";
+
+    import ietf-network {
+        prefix "nw";
+    }
+
+    revision "2016-03-17" {
+        description "Initial revision";
+    }
+
+    grouping te-node-augment {
+        container te {
+            presence "TE support.";
+
+            leaf te-node-id {
+                type string;
+                mandatory true;
+            }
+
+            container config {
+                uses te-node-config;
+            } // config
+        } // te
+    } // te-node-augment
+
+    grouping te-node-config {
+        leaf-list te-node-template {
+            if-feature template;
+            type string;
+        }
+        uses te-node-config-attributes;
+    } // te-node-config
+
+    grouping te-node-config-attributes {
+        container te-node-attributes {
+            leaf admin-status {
+               type string;
+            }
+            uses te-node-connectivity-matrix;
+        } // te-node-attributes
+    } // te-node-config-attributes
+
+    grouping te-node-connectivity-matrix {
+        list connectivity-matrix {
+            key "id";
+            leaf id {
+                type uint32;
+                description "Identifies the connectivity-matrix entry.";
+            }
+        }
+    } // te-node-connectivity-matrix
+
+    augment "/nw:networks/nw:network/nw:node" {
+        uses te-node-augment;
+    }
+}