[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"));
+ }
}