YANG sub module linking + unsupported yang construct + defect fix
Change-Id: I224c8c14ee2111f6844278cb540c48651544f59b
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/TreeWalkListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/TreeWalkListenerTest.java
new file mode 100644
index 0000000..cebd680
--- /dev/null
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/TreeWalkListenerTest.java
@@ -0,0 +1,55 @@
+/*
+ * 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;
+
+import java.io.IOException;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+
+/**
+ * Test cases for testing tree walk listener functionality.
+ */
+public class TreeWalkListenerTest {
+
+ private final YangUtilsParserManager manager = new YangUtilsParserManager();
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+ /**
+ * Checks whether exception is thrown for ordered statement.
+ */
+ @Test
+ public void processOrderedByStatement() throws IOException, ParserException {
+ thrown.expect(ParserException.class);
+ thrown.expectMessage("YANG file error : \"ordered-by\" is not supported in current version, please check wiki" +
+ " for YANG utils road map.");
+ manager.getDataModel("src/test/resources/OrderedByStatement.yang");
+ }
+
+ /**
+ * Checks whether exception is thrown for anyxml statement.
+ */
+ @Test
+ public void processAnyXmlStatement() throws IOException, ParserException {
+ thrown.expect(ParserException.class);
+ thrown.expectMessage("YANG file error : \"anyxml\" is not supported.");
+ manager.getDataModel("src/test/resources/AnyxmlStatement.yang");
+ }
+}
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/ConfigListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/ConfigListenerTest.java
index 439832f..d129e38 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/ConfigListenerTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/ConfigListenerTest.java
@@ -134,9 +134,9 @@
@Test
public void processModuleSubStatementConfig() throws IOException, ParserException {
thrown.expect(ParserException.class);
- thrown.expectMessage("mismatched input 'config' expecting {'augment', 'choice', 'contact', 'container',"
- + " 'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import', 'include', "
- + "'leaf', 'leaf-list', 'list', 'notification', 'organization', 'reference',"
+ thrown.expectMessage("mismatched input 'config' expecting {'anyxml', 'augment', 'choice', 'contact', "
+ + "'container', 'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import',"
+ + " 'include', 'leaf', 'leaf-list', 'list', 'notification', 'organization', 'reference',"
+ " 'revision', 'rpc', 'typedef', 'uses', '}'}");
YangNode node = manager.getDataModel("src/test/resources/ModuleSubStatementConfig.yang");
}
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/DefaultListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/DefaultListenerTest.java
new file mode 100644
index 0000000..2aab556
--- /dev/null
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/DefaultListenerTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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 java.util.ListIterator;
+
+import org.junit.Test;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangLeaf;
+import org.onosproject.yangutils.datamodel.YangChoice;
+import org.onosproject.yangutils.datamodel.YangContainer;
+import org.onosproject.yangutils.datamodel.YangNodeType;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test cases for testing default listener functionality.
+ */
+public class DefaultListenerTest {
+
+ private final YangUtilsParserManager manager = new YangUtilsParserManager();
+
+ /**
+ * Checks if default value is set correctly.
+ */
+ @Test
+ public void processLeafSubStatementDefault() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/LeafSubStatementDefault.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("Test"));
+
+ ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+ YangLeaf leafInfo = leafIterator.next();
+
+ assertThat(leafInfo.getName(), is("invalid-interval"));
+ assertThat(leafInfo.getDefaultValueInString(), is("\"1\""));
+ }
+
+ /**
+ * Checks if default value is set correctly.
+ */
+ @Test
+ public void processChoiceSubStatementDefault() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/ChoiceSubStatementDefault.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("Test"));
+
+ YangContainer yangContainer = (YangContainer) yangNode.getChild();
+ assertThat(yangContainer.getName(), is("food"));
+
+ YangChoice yangChoice = (YangChoice) yangContainer.getChild();
+ assertThat(yangChoice.getName(), is("snack"));
+ assertThat(yangChoice.getDefaultValueInString(), is("\"hello\""));
+ }
+}
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/EnumListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/EnumListenerTest.java
index 6f13667..a78c65f 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/EnumListenerTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/EnumListenerTest.java
@@ -18,7 +18,10 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
+
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
import org.onosproject.yangutils.datamodel.YangDataTypes;
import org.onosproject.yangutils.datamodel.YangEnum;
import org.onosproject.yangutils.datamodel.YangEnumeration;
@@ -38,6 +41,9 @@
*/
public class EnumListenerTest {
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
private final YangUtilsParserManager manager = new YangUtilsParserManager();
/**
@@ -84,7 +90,28 @@
*/
@Test(expected = ParserException.class)
public void processEnumWithDuplicateName() throws IOException, ParserException {
-
YangNode node = manager.getDataModel("src/test/resources/EnumWithDuplicateName.yang");
}
+
+ /**
+ * Checks enum boundary value.
+ */
+ @Test
+ public void processEnumBoundaryValue() throws IOException, ParserException {
+ thrown.expect(ParserException.class);
+ thrown.expectMessage("YANG file error : value value 21474836472147483647 is not valid.");
+ YangNode node = manager.getDataModel("src/test/resources/EnumBoundaryValue.yang");
+ }
+
+ /**
+ * Checks whether exception is thrown if value is not specified following max enum value.
+ */
+ @Test
+ public void processEnumMaxNextValue() throws IOException, ParserException {
+ thrown.expect(ParserException.class);
+ thrown.expectMessage("YANG file error : "
+ + "An enum value MUST be specified for enum substatements following the one"
+ + "with the current highest value");
+ YangNode node = manager.getDataModel("src/test/resources/EnumMaxNextValue.yang");
+ }
}
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/KeyListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/KeyListenerTest.java
index 37b4733..510b313 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/KeyListenerTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/KeyListenerTest.java
@@ -203,12 +203,32 @@
}
/**
+ * Checks key values are set correctly.
+ */
+ @Test
+ public void processKeyWithUsesInList() throws IOException, ParserException {
+ YangNode node = manager.getDataModel("src/test/resources/KeyWithUsesInList.yang");
+
+ assertThat((node instanceof YangModule), is(true));
+ assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+ YangModule yangNode = (YangModule) node;
+ assertThat(yangNode.getName(), is("Test"));
+
+ // Check whether the list is child of module
+ YangList yangList = (YangList) yangNode.getChild().getNextSibling();
+ assertThat(yangList.getName(), is("valid"));
+
+ ListIterator<String> keyList = yangList.getKeyList().listIterator();
+ assertThat(keyList.next(), is("invalid-interval"));
+ }
+
+ /**
* Checks whether exception is thrown when key leaf identifier is not found in list.
*/
@Test
public void processInvalidLeafIdentifier() throws IOException, ParserException {
thrown.expect(ParserException.class);
- thrown.expectMessage("Leaf identifier must refer to a child leaf of the list");
+ thrown.expectMessage("An identifier, in key, must refer to a child leaf of the list");
YangNode node = manager.getDataModel("src/test/resources/InvalidLeafIdentifier.yang");
}
@@ -218,7 +238,7 @@
@Test
public void processInvalidLeafListIdentifier() throws IOException, ParserException {
thrown.expect(ParserException.class);
- thrown.expectMessage("Leaf-list identifier must refer to a child leaf of the list");
+ thrown.expectMessage("An identifier, in key, must refer to a child leaf of the list");
YangNode node = manager.getDataModel("src/test/resources/InvalidLeafListIdentifier.yang");
}
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/LeafListListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/LeafListListenerTest.java
index fe918fa..8e7489b 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/LeafListListenerTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/LeafListListenerTest.java
@@ -94,9 +94,9 @@
@Test
public void processLeafListInvalidStatement() throws IOException, ParserException {
thrown.expect(ParserException.class);
- thrown.expectMessage("mismatched input 'leaflist' expecting {'augment', 'choice', 'contact', 'container',"
- + " 'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import', 'include',"
- + " 'leaf', 'leaf-list', 'list', 'notification', 'organization', 'reference',"
+ thrown.expectMessage("mismatched input 'leaflist' expecting {'anyxml', 'augment', 'choice', 'contact', "
+ + "'container', 'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import',"
+ + " 'include', 'leaf', 'leaf-list', 'list', 'notification', 'organization', 'reference',"
+ " 'revision', 'rpc', 'typedef', 'uses', '}'}");
YangNode node = manager.getDataModel("src/test/resources/LeafListInvalidStatement.yang");
}
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/LeafListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/LeafListenerTest.java
index 186d549..b330e53 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/LeafListenerTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/LeafListenerTest.java
@@ -95,9 +95,9 @@
@Test
public void processLeafInvalidStatement() throws IOException, ParserException {
thrown.expect(ParserException.class);
- thrown.expectMessage("mismatched input 'leafs' expecting {'augment', 'choice', 'contact', 'container',"
- + " 'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import', 'include',"
- + " 'leaf', 'leaf-list', 'list', 'notification', 'organization', 'reference',"
+ thrown.expectMessage("mismatched input 'leafs' expecting {'anyxml', 'augment', 'choice', 'contact', "
+ + "'container', 'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import',"
+ + " 'include', 'leaf', 'leaf-list', 'list', 'notification', 'organization', 'reference',"
+ " 'revision', 'rpc', 'typedef', 'uses', '}'}");
YangNode node = manager.getDataModel("src/test/resources/LeafInvalidStatement.yang");
}
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListenerTest.java
index 3c01335..40036f5 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListenerTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListenerTest.java
@@ -232,4 +232,39 @@
" 18446744073709551615.");
YangNode node = manager.getDataModel("src/test/resources/LengthWithInvalidInterval.yang");
}
+
+ /**
+ * Checks valid length substatements.
+ */
+ @Test
+ public void processLengthSubStatements() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/LengthSubStatements.yang");
+
+ assertThat((node instanceof YangModule), is(true));
+ assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+ YangModule yangNode = (YangModule) node;
+ assertThat(yangNode.getName(), is("Test"));
+
+ ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+ YangLeaf leafInfo = leafIterator.next();
+
+ assertThat(leafInfo.getName(), is("invalid-interval"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
+ YangStringRestriction stringRestriction = (YangStringRestriction) leafInfo
+ .getDataType().getDataTypeExtendedInfo();
+ YangRangeRestriction lengthRestriction = stringRestriction.getLengthRestriction();
+
+ assertThat(lengthRestriction.getDescription(), is("\"length description\""));
+ assertThat(lengthRestriction.getReference(), is("\"length reference\""));
+
+ ListIterator<YangRangeInterval> lengthListIterator = lengthRestriction.getAscendingRangeIntervals()
+ .listIterator();
+
+ YangRangeInterval rangeInterval = lengthListIterator.next();
+
+ assertThat(((YangUint64) rangeInterval.getStartValue()).getValue(), is(BigInteger.valueOf(0)));
+ assertThat(((YangUint64) rangeInterval.getEndValue()).getValue(), is(BigInteger.valueOf(100)));
+ }
}
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/MandatoryListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/MandatoryListenerTest.java
index 246d4b0..52e43a9 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/MandatoryListenerTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/MandatoryListenerTest.java
@@ -148,9 +148,9 @@
@Test
public void processModuleSubStatementMandatory() throws IOException, ParserException {
thrown.expect(ParserException.class);
- thrown.expectMessage("mismatched input 'mandatory' expecting {'augment', 'choice', 'contact', 'container',"
- + " 'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import', 'include',"
- + " 'leaf', 'leaf-list', 'list', 'notification', 'organization', 'reference',"
+ thrown.expectMessage("mismatched input 'mandatory' expecting {'anyxml', 'augment', 'choice', 'contact',"
+ + " 'container', 'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import',"
+ + " 'include', 'leaf', 'leaf-list', 'list', 'notification', 'organization', 'reference',"
+ " 'revision', 'rpc', 'typedef', 'uses', '}'}");
YangNode node = manager.getDataModel("src/test/resources/ModuleSubStatementMandatory.yang");
}
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/PatternRestrictionListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/PatternRestrictionListenerTest.java
index 00db373..928af5c 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/PatternRestrictionListenerTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/PatternRestrictionListenerTest.java
@@ -166,4 +166,32 @@
.getPatternList().listIterator();
assertThat(patternListIterator.next(), is("-[0-9]+|[0-9]+"));
}
+
+ /**
+ * Checks valid pattern substatement.
+ */
+ @Test
+ public void processPatternSubStatements() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/PatternSubStatements.yang");
+
+ assertThat((node instanceof YangModule), is(true));
+ assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+ YangModule yangNode = (YangModule) node;
+ assertThat(yangNode.getName(), is("Test"));
+
+ ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+ YangLeaf leafInfo = leafIterator.next();
+
+ assertThat(leafInfo.getName(), is("invalid-interval"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
+ YangStringRestriction stringRestriction = (YangStringRestriction) leafInfo
+ .getDataType().getDataTypeExtendedInfo();
+ assertThat(stringRestriction.getDescription(), is("\"pattern description\""));
+ assertThat(stringRestriction.getReference(), is("\"pattern reference\""));
+ ListIterator<String> patternListIterator = stringRestriction.getPatternRestriction()
+ .getPatternList().listIterator();
+ assertThat(patternListIterator.next(), is("[a-zA-Z]"));
+ }
}
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/RangeRestrictionListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/RangeRestrictionListenerTest.java
index 76da997..88672fd 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/RangeRestrictionListenerTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/RangeRestrictionListenerTest.java
@@ -174,4 +174,37 @@
thrown.expectMessage("YANG file error : Input value \"a\" is not a valid int32.");
YangNode node = manager.getDataModel("src/test/resources/RangeWithInvalidIntegerPattern.yang");
}
+
+ /**
+ * Checks valid range statement with description.
+ */
+ @Test
+ public void processRangeSubStatements() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/RangeSubStatements.yang");
+
+ assertThat((node instanceof YangModule), is(true));
+ assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+ YangModule yangNode = (YangModule) node;
+ assertThat(yangNode.getName(), is("Test"));
+
+ ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+ YangLeaf leafInfo = leafIterator.next();
+
+ assertThat(leafInfo.getName(), is("invalid-interval"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("int32"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.INT32));
+ YangRangeRestriction rangeRestriction = (YangRangeRestriction) leafInfo
+ .getDataType().getDataTypeExtendedInfo();
+
+ assertThat(rangeRestriction.getDescription(), is("\"range description\""));
+ assertThat(rangeRestriction.getReference(), is("\"range reference\""));
+
+ ListIterator<YangRangeInterval> rangeListIterator = rangeRestriction.getAscendingRangeIntervals()
+ .listIterator();
+ YangRangeInterval rangeInterval = rangeListIterator.next();
+ assertThat(((YangInt32) rangeInterval.getStartValue()).getValue(), is(1));
+ assertThat(((YangInt32) rangeInterval.getEndValue()).getValue(), is(4));
+ assertThat(((YangInt32) rangeInterval.getEndValue()).getValue(), is(4));
+ }
}
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/StatusListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/StatusListenerTest.java
index 7f0d1ea..b2cbd71 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/StatusListenerTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/StatusListenerTest.java
@@ -150,9 +150,9 @@
@Test
public void processModuleSubStatementStatus() throws IOException, ParserException {
thrown.expect(ParserException.class);
- thrown.expectMessage("mismatched input 'status' expecting {'augment', 'choice', 'contact', 'container', "
- + "'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import', 'include',"
- + " 'leaf', 'leaf-list', 'list', 'notification', 'organization', 'reference', "
+ thrown.expectMessage("mismatched input 'status' expecting {'anyxml', 'augment', 'choice', 'contact', "
+ + "'container', 'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import',"
+ + " 'include', 'leaf', 'leaf-list', 'list', 'notification', 'organization', 'reference', "
+ "'revision', 'rpc', 'typedef', 'uses', '}'}");
YangNode node = manager.getDataModel("src/test/resources/ModuleSubStatementStatus.yang");
}
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/UnitsListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/UnitsListenerTest.java
index 6479991..6684df5 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/UnitsListenerTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/UnitsListenerTest.java
@@ -76,9 +76,9 @@
@Test
public void processModuleSubStatementUnits() throws IOException, ParserException {
thrown.expect(ParserException.class);
- thrown.expectMessage("mismatched input 'type' expecting {'augment', 'choice', 'contact', 'container', "
- + "'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import', "
- + "'include', 'leaf', 'leaf-list', 'list', 'notification', 'organization', "
+ thrown.expectMessage("mismatched input 'type' expecting {'anyxml', 'augment', 'choice', 'contact', "
+ + "'container', 'description', 'extension', 'deviation', 'feature', 'grouping', 'identity',"
+ + " 'import', 'include', 'leaf', 'leaf-list', 'list', 'notification', 'organization', "
+ "'reference', 'revision', 'rpc', 'typedef', 'uses', '}'}");
YangNode node = manager.getDataModel("src/test/resources/ModuleSubStatementUnits.yang");
}
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/ValueListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/ValueListenerTest.java
index f0d5357..6dae702 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/ValueListenerTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/ValueListenerTest.java
@@ -80,6 +80,84 @@
}
/**
+ * Checks explicitly configured negative value.
+ */
+ @Test
+ public void processValueStatementWithNegativeValue() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/ValueStatementWithNegativeValue.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("Test"));
+
+ ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+ YangLeaf leafInfo = leafIterator.next();
+
+ assertThat(leafInfo.getName(), is("speed"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("enumeration"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.ENUMERATION));
+ assertThat(((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getName(),
+ is("speed_enum"));
+
+ Set<YangEnum> enumSet = ((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getEnumSet();
+ for (YangEnum tmp : enumSet) {
+ if (tmp.getNamedValue().equals("10m")) {
+ assertThat(tmp.getValue(), is(-2));
+ } else if (tmp.getNamedValue().equals("100m")) {
+ assertThat(tmp.getValue(), is(-1));
+ } else if (tmp.getNamedValue().equals("auto")) {
+ assertThat(tmp.getValue(), is(0));
+ }
+ }
+ }
+
+ /**
+ * Checks explicitly configured value with double quotes.
+ */
+ @Test
+ public void processValueStatementWithQuotes() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/ValueStatementWithQuotes.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("Test"));
+
+ ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+ YangLeaf leafInfo = leafIterator.next();
+
+ assertThat(leafInfo.getName(), is("speed"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("enumeration"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.ENUMERATION));
+ assertThat(((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getName(),
+ is("speed_enum"));
+
+ Set<YangEnum> enumSet = ((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getEnumSet();
+ for (YangEnum tmp : enumSet) {
+ if (tmp.getNamedValue().equals("10m")) {
+ assertThat(tmp.getValue(), is(10));
+ } else if (tmp.getNamedValue().equals("100m")) {
+ assertThat(tmp.getValue(), is(100));
+ } else if (tmp.getNamedValue().equals("auto")) {
+ assertThat(tmp.getValue(), is(1000));
+ }
+ }
+ }
+
+ /**
* Checks explicit value and auto generated value.
*/
@Test
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/io/impl/YangFileScannerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/io/impl/YangFileScannerTest.java
index d3137b3..7d199b9 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/io/impl/YangFileScannerTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/io/impl/YangFileScannerTest.java
@@ -26,6 +26,7 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.onosproject.yangutils.plugin.manager.YangFileInfo;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
@@ -135,7 +136,7 @@
String emptyYangDir = baseDir + separator + "scanner1";
File path = createDirectory(emptyYangDir);
- List<String> emptyDirContents = getYangFiles(path.toString());
+ List<YangFileInfo> emptyDirContents = getYangFiles(path.toString());
List<String> expectedContents = new LinkedList<>();
assertThat(true, is(emptyDirContents.equals(expectedContents)));
}
diff --git a/utils/yangutils/src/test/resources/AnyxmlStatement.yang b/utils/yangutils/src/test/resources/AnyxmlStatement.yang
new file mode 100644
index 0000000..4b1e421
--- /dev/null
+++ b/utils/yangutils/src/test/resources/AnyxmlStatement.yang
@@ -0,0 +1,16 @@
+module event {
+
+ namespace "http://example.com/event";
+ prefix "ev";
+
+ notification event {
+ leaf event-class {
+ type string;
+ }
+ anyxml reporting-entity;
+ leaf severity {
+ type string;
+ }
+ }
+}
+
diff --git a/utils/yangutils/src/test/resources/ChoiceSubStatementDefault.yang b/utils/yangutils/src/test/resources/ChoiceSubStatementDefault.yang
new file mode 100644
index 0000000..b9fd60d
--- /dev/null
+++ b/utils/yangutils/src/test/resources/ChoiceSubStatementDefault.yang
@@ -0,0 +1,23 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ container food {
+ choice snack {
+ case sports-arena {
+ leaf pretzel {
+ type string;
+ }
+ leaf beer {
+ type string;
+ }
+ }
+ case late-night {
+ leaf chocolate {
+ type string;
+ }
+ }
+ default "hello";
+ }
+ }
+}
diff --git a/utils/yangutils/src/test/resources/EnumBoundaryValue.yang b/utils/yangutils/src/test/resources/EnumBoundaryValue.yang
new file mode 100644
index 0000000..ac87ef0
--- /dev/null
+++ b/utils/yangutils/src/test/resources/EnumBoundaryValue.yang
@@ -0,0 +1,16 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ leaf ifType {
+ type enumeration {
+ enum "unbounded";
+ enum ZERO;
+ enum two;
+ enum four;
+ enum seven {
+ value 21474836472147483647;
+ }
+ }
+ }
+}
diff --git a/utils/yangutils/src/test/resources/EnumMaxNextValue.yang b/utils/yangutils/src/test/resources/EnumMaxNextValue.yang
new file mode 100644
index 0000000..4e4a373
--- /dev/null
+++ b/utils/yangutils/src/test/resources/EnumMaxNextValue.yang
@@ -0,0 +1,18 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ leaf ifType {
+ type enumeration {
+ enum "unbounded";
+ enum ZERO;
+ enum two;
+ enum four;
+ enum seven {
+ value 2147483647;
+ }
+ enum five;
+
+ }
+ }
+}
diff --git a/utils/yangutils/src/test/resources/KeyWithUsesInList.yang b/utils/yangutils/src/test/resources/KeyWithUsesInList.yang
new file mode 100644
index 0000000..d076d0a
--- /dev/null
+++ b/utils/yangutils/src/test/resources/KeyWithUsesInList.yang
@@ -0,0 +1,23 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ grouping network {
+ leaf invalid-interval {
+ type "string";
+ units "seconds";
+ status current;
+ reference "RFC 6020";
+ }
+ }
+ list valid {
+ key "invalid-interval";
+ leaf invalid {
+ type "string";
+ units "seconds";
+ status current;
+ reference "RFC 6020";
+ }
+ uses "network";
+ }
+}
diff --git a/utils/yangutils/src/test/resources/LeafSubStatementDefault.yang b/utils/yangutils/src/test/resources/LeafSubStatementDefault.yang
new file mode 100644
index 0000000..a78131d
--- /dev/null
+++ b/utils/yangutils/src/test/resources/LeafSubStatementDefault.yang
@@ -0,0 +1,15 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ leaf invalid-interval {
+ type "uint16";
+ units "seconds";
+ default "1";
+ description "Interval before a route is declared invalid";
+ config true;
+ mandatory true;
+ status current;
+ reference "RFC 6020";
+ }
+}
diff --git a/utils/yangutils/src/test/resources/LengthSubStatements.yang b/utils/yangutils/src/test/resources/LengthSubStatements.yang
new file mode 100644
index 0000000..f61f979
--- /dev/null
+++ b/utils/yangutils/src/test/resources/LengthSubStatements.yang
@@ -0,0 +1,13 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ leaf invalid-interval {
+ type string {
+ length "0..100" {
+ description "length description";
+ reference "length reference";
+ }
+ }
+ }
+}
diff --git a/utils/yangutils/src/test/resources/OrderedByStatement.yang b/utils/yangutils/src/test/resources/OrderedByStatement.yang
new file mode 100644
index 0000000..f6b4336
--- /dev/null
+++ b/utils/yangutils/src/test/resources/OrderedByStatement.yang
@@ -0,0 +1,10 @@
+module rock {
+ namespace "http://example.net/rock";
+ prefix "rock";
+ leaf-list cipher {
+ type string;
+ ordered-by user;
+ description "A list of ciphers";
+ }
+}
+
diff --git a/utils/yangutils/src/test/resources/PatternSubStatements.yang b/utils/yangutils/src/test/resources/PatternSubStatements.yang
new file mode 100644
index 0000000..3e792c6
--- /dev/null
+++ b/utils/yangutils/src/test/resources/PatternSubStatements.yang
@@ -0,0 +1,13 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ leaf invalid-interval {
+ type string {
+ pattern "[a-zA-Z]" {
+ description "pattern description";
+ reference "pattern reference";
+ }
+ }
+ }
+}
diff --git a/utils/yangutils/src/test/resources/RangeSubStatements.yang b/utils/yangutils/src/test/resources/RangeSubStatements.yang
new file mode 100644
index 0000000..4b57bd0
--- /dev/null
+++ b/utils/yangutils/src/test/resources/RangeSubStatements.yang
@@ -0,0 +1,14 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ leaf invalid-interval {
+ type int32 {
+ range "1..4 | 10..20" {
+ description "range description";
+ reference "range reference";
+ }
+ }
+ }
+}
+
diff --git a/utils/yangutils/src/test/resources/ValidAugmentStatement.yang b/utils/yangutils/src/test/resources/ValidAugmentStatement.yang
index 6175c35..f6c247e 100644
--- a/utils/yangutils/src/test/resources/ValidAugmentStatement.yang
+++ b/utils/yangutils/src/test/resources/ValidAugmentStatement.yang
@@ -10,7 +10,6 @@
prefix "P";
}
augment "/if:interfaces/if:ifEntry" {
- when "if:ifType='ds0'";
leaf ds0ChannelNumber {
type P:ChannelNumber;
}
diff --git a/utils/yangutils/src/test/resources/ValidNotificationStatement.yang b/utils/yangutils/src/test/resources/ValidNotificationStatement.yang
index 072df23..7e6bc17 100644
--- a/utils/yangutils/src/test/resources/ValidNotificationStatement.yang
+++ b/utils/yangutils/src/test/resources/ValidNotificationStatement.yang
@@ -14,9 +14,7 @@
type int32;
}
leaf if-name {
- type leafref {
- path "/interface/name";
- }
+ type leafref;
}
leaf if-admin-status {
type P:admin-status;
diff --git a/utils/yangutils/src/test/resources/ValueStatementWithNegativeValue.yang b/utils/yangutils/src/test/resources/ValueStatementWithNegativeValue.yang
new file mode 100644
index 0000000..a3f236b
--- /dev/null
+++ b/utils/yangutils/src/test/resources/ValueStatementWithNegativeValue.yang
@@ -0,0 +1,18 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ leaf speed {
+ type enumeration {
+ enum 10m {
+ value -2;
+ }
+ enum 100m {
+ value "-1";
+ }
+ enum auto {
+ value 0;
+ }
+ }
+ }
+}
diff --git a/utils/yangutils/src/test/resources/ValueStatementWithQuotes.yang b/utils/yangutils/src/test/resources/ValueStatementWithQuotes.yang
new file mode 100644
index 0000000..e166ca4
--- /dev/null
+++ b/utils/yangutils/src/test/resources/ValueStatementWithQuotes.yang
@@ -0,0 +1,18 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ leaf speed {
+ type enumeration {
+ enum 10m {
+ value "10";
+ }
+ enum 100m {
+ value "100";
+ }
+ enum auto {
+ value "1000";
+ }
+ }
+ }
+}