[ONOS-4890/4891] Sub-module variable reference using self prefix
Change-Id: Idaa58e30f7742a54d5198887353934a5d9494631
diff --git a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfoImpl.java b/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfoImpl.java
index 00fb699..8f7a08a 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfoImpl.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfoImpl.java
@@ -21,7 +21,6 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Stack;
-
import org.onosproject.yangutils.datamodel.Resolvable;
import org.onosproject.yangutils.datamodel.ResolvableType;
import org.onosproject.yangutils.datamodel.TraversalType;
@@ -484,10 +483,10 @@
}
/*
- * In case prefix is not present it's a candidate for inter-file
+ * In case prefix is not present or it's self prefix it's a candidate for inter-file
* resolution via include list.
*/
- if (getRefPrefix() == null) {
+ if (getRefPrefix() == null || getRefPrefix().contentEquals(getCurReferenceResolver().getPrefix())) {
((Resolvable) getCurrentEntityToResolveFromStack()).setResolvableStatus(INTRA_FILE_RESOLVED);
}
}
@@ -525,8 +524,11 @@
return;
}
- //In case prefix is not present it's a candidate for inter-file resolution via include list.
- if (getRefPrefix() == null) {
+ /*
+ * In case prefix is not present or it's self prefix it's a candidate for inter-file
+ * resolution via include list.
+ */
+ if (getRefPrefix() == null || getRefPrefix().contentEquals(getCurReferenceResolver().getPrefix())) {
((Resolvable) getCurrentEntityToResolveFromStack()).setResolvableStatus(INTRA_FILE_RESOLVED);
}
}
@@ -579,10 +581,10 @@
}
/*
- * In case prefix is not present it's a candidate for inter-file
+ * In case prefix is not present or it's self prefix it's a candidate for inter-file
* resolution via include list.
*/
- if (getRefPrefix() == null) {
+ if (getRefPrefix() == null || getRefPrefix().contentEquals(getCurReferenceResolver().getPrefix())) {
((Resolvable) getCurrentEntityToResolveFromStack()).setResolvableStatus(INTRA_FILE_RESOLVED);
}
}
diff --git a/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/IncludeReferenceWithPrefix.java b/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/IncludeReferenceWithPrefix.java
new file mode 100644
index 0000000..4cc908d
--- /dev/null
+++ b/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/IncludeReferenceWithPrefix.java
@@ -0,0 +1,59 @@
+/*
+ * 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.plugin.manager;
+
+import java.io.IOException;
+import java.util.Iterator;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.junit.Test;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.utils.io.YangPluginConfig;
+import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
+
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
+
+/**
+ * Test cases for testing YANG schema node.
+ */
+public class IncludeReferenceWithPrefix {
+
+ private final YangUtilManager utilManager = new YangUtilManager();
+
+ /**
+ * Checks method to get schema node from map.
+ *
+ * @throws MojoExecutionException
+ */
+ @Test
+ public void processRefToIncludeWithPrefix() throws IOException, ParserException, MojoExecutionException {
+
+ String searchDir = "src/test/resources/refincludecontentwithprefix";
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+ utilManager.resolveDependenciesUsingLinker();
+ YangPluginConfig yangPluginConfig = new YangPluginConfig();
+ yangPluginConfig.setCodeGenDir("target/refincludecontentwithprefix/");
+ utilManager.translateToJava(yangPluginConfig);
+
+ Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator();
+ YangNode rootNode = yangNodeIterator.next();
+
+ deleteDirectory("target/schemaMap/");
+ }
+}
diff --git a/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/IntraFileTypeLinkingTest.java b/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/IntraFileTypeLinkingTest.java
index a9fcdd2..06111f8 100644
--- a/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/IntraFileTypeLinkingTest.java
+++ b/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/IntraFileTypeLinkingTest.java
@@ -33,13 +33,13 @@
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
+import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE;
+import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.INTRA_FILE_RESOLVED;
+import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.RESOLVED;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BINARY;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DERIVED;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT32;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.STRING;
-import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE;
-import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.INTRA_FILE_RESOLVED;
-import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.RESOLVED;
/**
* Test cases for testing "type" intra file linking.
@@ -487,9 +487,9 @@
/**
* Check self resolution when type referred typedef is not available in
- * file.
+ * file, it should not result in exception.
*/
- @Test(expected = LinkerException.class)
+ @Test
public void processSelfResolutionWhenTypeReferredTypedefNotDefined()
throws IOException, LinkerException {
@@ -499,9 +499,10 @@
/**
* Checks self resolution when typedef and leaf using type are at different
- * level where typedef is is not an ancestor of type.
+ * level where typedef is is not an ancestor of type, it should not result
+ * in exception.
*/
- @Test(expected = LinkerException.class)
+ @Test
public void processSelfFileLinkingTypedefNotFound()
throws IOException, LinkerException {
@@ -510,8 +511,9 @@
/**
* Checks hierarchical self resolution with self resolution failure scenario.
+ * It should not result in exception.
*/
- @Test(expected = LinkerException.class)
+ @Test
public void processSelfFileLinkingWithHierarchicalTypeFailureScenario()
throws IOException, LinkerException {
diff --git a/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/IntraFileUsesLinkingTest.java b/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/IntraFileUsesLinkingTest.java
index 075d2f9..716e21c 100644
--- a/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/IntraFileUsesLinkingTest.java
+++ b/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/IntraFileUsesLinkingTest.java
@@ -440,15 +440,12 @@
/**
* Checks the failure scenario when uses is cannot resolve its grouping.
+ * It shouldnt result in exception
*/
@Test
public void processSelfResolutionNestedGroupingWithUnresolvedUses()
throws IOException, LinkerException {
- thrown.expect(LinkerException.class);
- thrown.expectMessage(
- "YANG file error: Unable to find base grouping for given uses");
-
YangNode node = manager
.getDataModel("src/test/resources/SelfResolutionNestedGroupingWithUnresolvedUses.yang");
}
diff --git a/plugin/src/test/resources/refincludecontentwithprefix/ietf-snmp-common.yang b/plugin/src/test/resources/refincludecontentwithprefix/ietf-snmp-common.yang
new file mode 100644
index 0000000..ed382c8
--- /dev/null
+++ b/plugin/src/test/resources/refincludecontentwithprefix/ietf-snmp-common.yang
@@ -0,0 +1,60 @@
+submodule ietf-snmp-common {
+ belongs-to ietf-snmp {
+ prefix snmp;
+ }
+ organization
+ "IETF NETMOD (NETCONF Data Modeling Language) Working Group";
+ contact
+ "WG Web: <http://tools.ietf.org/wg/netmod/>
+ WG List: <mailto:netmod@ietf.org>
+ WG Chair: Thomas Nadeau
+ <mailto:tnadeau@lucidvision.com>
+ WG Chair: Juergen Schoenwaelder
+ <mailto:j.schoenwaelder@jacobs-university.de>
+ Editor: Martin Bjorklund
+ <mailto:mbj@tail-f.com>
+ Editor: Juergen Schoenwaelder
+ <mailto:j.schoenwaelder@jacobs-university.de>";
+ description
+ "This submodule contains a collection of common YANG definitions
+ for configuring SNMP engines.
+ Copyright (c) 2014 IETF Trust and the persons identified as
+ authors of the code. All rights reserved.
+ Redistribution and use in source and binary forms, with or
+ without modification, is permitted pursuant to, and subject
+ to the license terms contained in, the Simplified BSD License
+ set forth in Section 4.c of the IETF Trust's Legal Provisions
+ Relating to IETF Documents
+ (http://trustee.ietf.org/license-info).
+ This version of this YANG module is part of RFC 7407; see
+ the RFC itself for full legal notices.";
+ revision 2014-12-10 {
+ description
+ "Initial revision.";
+ reference
+ "RFC 7407: A YANG Data Model for SNMP Configuration";
+ }
+ /* Collection of SNMP-specific data types */
+ typedef admin-string {
+ type string {
+ length "0..255";
+ }
+ description
+ "Represents SnmpAdminString as defined in RFC 3411.
+ Note that the size of an SnmpAdminString is measured in
+ octets, not characters.";
+ reference
+ "RFC 3411: An Architecture for Describing Simple Network
+ Management Protocol (SNMP) Management Frameworks.
+ SNMP-FRAMEWORK-MIB.SnmpAdminString";
+ }
+ typedef identifier {
+ type admin-string {
+ length "1..32";
+ }
+ description
+ "Identifiers are used to name items in the SNMP configuration
+ datastore.";
+ }
+ feature testfeature;
+}
diff --git a/plugin/src/test/resources/refincludecontentwithprefix/ietf-snmp-vacm.yang b/plugin/src/test/resources/refincludecontentwithprefix/ietf-snmp-vacm.yang
new file mode 100644
index 0000000..5b6595d
--- /dev/null
+++ b/plugin/src/test/resources/refincludecontentwithprefix/ietf-snmp-vacm.yang
@@ -0,0 +1,51 @@
+submodule ietf-snmp-vacm {
+ belongs-to ietf-snmp {
+ prefix snmp;
+ }
+ include ietf-snmp-common;
+ organization
+ "IETF NETMOD (NETCONF Data Modeling Language) Working Group";
+ contact
+ "WG Web: <http://tools.ietf.org/wg/netmod/>
+ WG List: <mailto:netmod@ietf.org>
+ WG Chair: Thomas Nadeau
+ <mailto:tnadeau@lucidvision.com>
+ WG Chair: Juergen Schoenwaelder
+ <mailto:j.schoenwaelder@jacobs-university.de>
+ Editor: Martin Bjorklund
+ <mailto:mbj@tail-f.com>
+ Editor: Juergen Schoenwaelder
+ <mailto:j.schoenwaelder@jacobs-university.de>";
+ description
+ "This submodule contains a collection of YANG definitions
+ for configuring the View-based Access Control Model (VACM)
+ of SNMP.
+ Copyright (c) 2014 IETF Trust and the persons identified as
+ authors of the code. All rights reserved.
+ Redistribution and use in source and binary forms, with or
+ without modification, is permitted pursuant to, and subject
+ to the license terms contained in, the Simplified BSD License
+ set forth in Section 4.c of the IETF Trust's Legal Provisions
+ Relating to IETF Documents
+ (http://trustee.ietf.org/license-info).
+ This version of this YANG module is part of RFC 7407; see
+ the RFC itself for full legal notices.";
+ reference
+ "RFC 3415: View-based Access Control Model (VACM) for the
+ Simple Network Management Protocol (SNMP)";
+ revision 2014-12-10 {
+ description
+ "Initial revision.";
+ reference
+ "RFC 7407: A YANG Data Model for SNMP Configuration";
+ }
+ typedef view-name {
+ type snmp:identifier;
+ description
+ "The view-name type represents an SNMP VACM view name.";
+ }
+ leaf testleaf {
+ if-feature snmp:testfeature;
+ type string;
+ }
+}
diff --git a/plugin/src/test/resources/refincludecontentwithprefix/ietf-snmp.yang b/plugin/src/test/resources/refincludecontentwithprefix/ietf-snmp.yang
new file mode 100644
index 0000000..224849c
--- /dev/null
+++ b/plugin/src/test/resources/refincludecontentwithprefix/ietf-snmp.yang
@@ -0,0 +1,42 @@
+module ietf-snmp {
+ namespace "urn:ietf:params:xml:ns:yang:ietf-snmp";
+ prefix snmp;
+ include ietf-snmp-common {
+ revision-date 2014-12-10;
+ }
+ include ietf-snmp-vacm {
+ revision-date 2014-12-10;
+ }
+ organization
+ "IETF NETMOD (NETCONF Data Modeling Language) Working Group";
+ contact
+ "WG Web: <http://tools.ietf.org/wg/netmod/>
+ WG List: <mailto:netmod@ietf.org>
+ WG Chair: Thomas Nadeau
+ <mailto:tnadeau@lucidvision.com>
+ WG Chair: Juergen Schoenwaelder
+ <mailto:j.schoenwaelder@jacobs-university.de>
+ Editor: Martin Bjorklund
+ <mailto:mbj@tail-f.com>
+ Editor: Juergen Schoenwaelder
+ <mailto:j.schoenwaelder@jacobs-university.de>";
+ description
+ "This module contains a collection of YANG definitions for
+ configuring SNMP engines.
+ Copyright (c) 2014 IETF Trust and the persons identified as
+ authors of the code. All rights reserved.
+ Redistribution and use in source and binary forms, with or
+ without modification, is permitted pursuant to, and subject
+ to the license terms contained in, the Simplified BSD License
+ set forth in Section 4.c of the IETF Trust's Legal Provisions
+ Relating to IETF Documents
+ (http://trustee.ietf.org/license-info).
+ This version of this YANG module is part of RFC 7407; see
+ the RFC itself for full legal notices.";
+ revision 2014-12-10 {
+ description
+ "Initial revision.";
+ reference
+ "RFC 7407: A YANG Data Model for SNMP Configuration";
+ }
+}