[ONOS-4616] grouping linker issues fixed and other defect fixed.
Change-Id: I1b23f9ed0293edbc2d551efe82982559eb916ede
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/linker/IntraFileUsesLinkingTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/linker/IntraFileUsesLinkingTest.java
index e906afd..212a499 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/linker/IntraFileUsesLinkingTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/linker/IntraFileUsesLinkingTest.java
@@ -564,7 +564,7 @@
thrown.expect(ParserException.class);
thrown.expectMessage(
- "YANG file error: Unable to find base typedef/grouping for given type/uses");
+ "YANG file error: Unable to find base grouping for given uses");
YangNode node = manager
.getDataModel("src/test/resources/SelfResolutionNestedGroupingWithUnresolvedUses.yang");
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
index cebd680..874f8ed 100644
--- 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
@@ -52,4 +52,34 @@
thrown.expectMessage("YANG file error : \"anyxml\" is not supported.");
manager.getDataModel("src/test/resources/AnyxmlStatement.yang");
}
+
+ /**
+ * Checks whether exception is thrown when extra brace is added in the EOF.
+ */
+ @Test
+ public void processFileWithExtraBrace() throws IOException, ParserException {
+ thrown.expect(ParserException.class);
+ thrown.expectMessage("mismatched input '}' expecting <EOF>");
+ manager.getDataModel("src/test/resources/ProcessFileWithExtraBrace.yang");
+ }
+
+ /**
+ * Checks whether exception is thrown when leaf is given after module ends.
+ */
+ @Test
+ public void processFileWithExtraLeaf() throws IOException, ParserException {
+ thrown.expect(ParserException.class);
+ thrown.expectMessage("mismatched input 'leaf' expecting <EOF>");
+ manager.getDataModel("src/test/resources/ProcessFileWithExtraLeaf.yang");
+ }
+
+ /**
+ * Checks whether exception is thrown when extra brace is added in between the EOF.
+ */
+ @Test
+ public void processFileWithExtraBraceInBetween() throws IOException, ParserException {
+ thrown.expect(ParserException.class);
+ thrown.expectMessage("mismatched input 'container' expecting <EOF>");
+ manager.getDataModel("src/test/resources/ProcessFileWithExtraBraceInBetween.yang");
+ }
}
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/BitListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/BitListenerTest.java
index 3aceb34..6487172 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/BitListenerTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/BitListenerTest.java
@@ -26,10 +26,14 @@
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNodeType;
+import org.onosproject.yangutils.datamodel.YangType;
+import org.onosproject.yangutils.datamodel.YangTypeDef;
+import org.onosproject.yangutils.datamodel.YangUnion;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import java.io.IOException;
+import java.util.List;
import java.util.ListIterator;
import java.util.Set;
@@ -80,6 +84,84 @@
}
/**
+ * Checks bit statement with typedef.
+ */
+ @Test
+ public void processBitTypedefStatement() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/BitTypedefStatement.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"));
+
+ YangTypeDef typedef = (YangTypeDef) yangNode.getChild();
+ assertThat(typedef.getName(), is("type15"));
+
+ YangType type = typedef.getTypeList().iterator().next();
+ assertThat(type.getDataType(), is(YangDataTypes.BITS));
+ assertThat(type.getDataTypeName(), is("bits"));
+ Set<YangBit> bitSet = ((YangBits) type.getDataTypeExtendedInfo()).getBitSet();
+ for (YangBit tmp : bitSet) {
+ if (tmp.getBitName().equals("disable-nagle")) {
+ assertThat(tmp.getPosition(), is(0));
+ } else if (tmp.getBitName().equals("auto-sense-speed")) {
+ assertThat(tmp.getPosition(), is(1));
+ }
+ }
+ }
+
+ /**
+ * Checks bit statement with union.
+ */
+ @Test
+ public void processBitUnionStatement() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/BitUnionStatement.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("type15"));
+
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UNION));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("union"));
+
+ YangUnion yangUnion = (YangUnion) leafInfo.getDataType().getDataTypeExtendedInfo();
+
+ List<YangType<?>> typeList = yangUnion.getTypeList();
+ ListIterator<YangType<?>> typeListIterator = typeList.listIterator();
+ YangType<?> yangType = typeListIterator.next();
+
+ assertThat(yangType.getDataType(), is(YangDataTypes.BITS));
+ assertThat(yangType.getDataTypeName(), is("bits"));
+ Set<YangBit> bitSet = ((YangBits) yangType.getDataTypeExtendedInfo()).getBitSet();
+ for (YangBit tmp : bitSet) {
+ if (tmp.getBitName().equals("disable-nagle")) {
+ assertThat(tmp.getPosition(), is(0));
+ } else if (tmp.getBitName().equals("auto-sense-speed")) {
+ assertThat(tmp.getPosition(), is(1));
+ }
+ }
+ }
+
+ /**
* Checks if enum with same name is not allowed.
*/
@Test(expected = ParserException.class)
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 a78c65f..a0bff1b 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
@@ -33,8 +33,9 @@
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import java.io.IOException;
+import java.util.Iterator;
import java.util.ListIterator;
-import java.util.Set;
+import java.util.SortedSet;
/**
* Test cases for enum listener.
@@ -73,7 +74,7 @@
assertThat(((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getName(),
is("speed_enum"));
- Set<YangEnum> enumSet = ((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getEnumSet();
+ SortedSet<YangEnum> enumSet = ((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getEnumSet();
for (YangEnum tmp : enumSet) {
if (tmp.getNamedValue().equals("10m")) {
assertThat(tmp.getValue(), is(0));
@@ -114,4 +115,34 @@
+ "with the current highest value");
YangNode node = manager.getDataModel("src/test/resources/EnumMaxNextValue.yang");
}
+
+ /**
+ * Checks enum values stored are sorted.
+ */
+ @Test
+ public void processEnumSorted() throws IOException, ParserException {
+ YangNode node = manager.getDataModel("src/test/resources/EnumSorted.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("ifType"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("enumeration"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.ENUMERATION));
+ assertThat(((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getName(),
+ is("ifType_enum"));
+
+ SortedSet<YangEnum> enumSet = ((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getEnumSet();
+ Iterator<YangEnum> enumIterator = enumSet.iterator();
+ assertThat(enumIterator.next().getNamedValue(), is("five"));
+ }
}
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 ae15d0c..3df9c13 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
@@ -267,4 +267,36 @@
assertThat(((YangUint64) rangeInterval.getStartValue()).getValue(), is(BigInteger.valueOf(0)));
assertThat(((YangUint64) rangeInterval.getEndValue()).getValue(), is(BigInteger.valueOf(100)));
}
+
+ /**
+ * Checks whether space can be allowed when length statement is present.
+ */
+ @Test
+ public void processLengthStatementWithSpace() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/LengthStatementWithSpace.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();
+
+ 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/MaxElementsListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/MaxElementsListenerTest.java
index c531b85..aa0cee2 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/MaxElementsListenerTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/MaxElementsListenerTest.java
@@ -176,4 +176,15 @@
assertThat(leafListInfo.getName(), is("invalid-interval"));
assertThat(leafListInfo.getMaxElelements(), is(2147483647));
}
+
+ /**
+ * Checks whether exception is thrown when invalid min-elements value is
+ * given as input.
+ */
+ @Test
+ public void processMaxElementsMaxValue() throws IOException, ParserException {
+ thrown.expect(ParserException.class);
+ thrown.expectMessage("YANG file error : max-elements value 77777777777777777777777 is not valid.");
+ YangNode node = manager.getDataModel("src/test/resources/MaxElementsMaxValue.yang");
+ }
}
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/MinElementsListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/MinElementsListenerTest.java
index bf1afb8..c2f668b 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/MinElementsListenerTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/MinElementsListenerTest.java
@@ -116,6 +116,17 @@
}
/**
+ * Checks whether exception is thrown when invalid min-elements value is
+ * given as input.
+ */
+ @Test
+ public void processMinElementsMaxValue() throws IOException, ParserException {
+ thrown.expect(ParserException.class);
+ thrown.expectMessage("YANG file error : min-elements value 77777777777777777777777 is not valid.");
+ YangNode node = manager.getDataModel("src/test/resources/MinElementsMaxValue.yang");
+ }
+
+ /**
* Checks whether exception is thrown when min-elements statement without
* statement end is given as input.
*/
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/NotificationListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/NotificationListenerTest.java
index 3b9907e..7da2468 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/NotificationListenerTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/NotificationListenerTest.java
@@ -66,6 +66,6 @@
YangLeaf leafInfo = leafIterator.next();
assertThat(leafInfo.getName(), is("if-name"));
- assertThat(leafInfo.getDataType().getDataTypeName(), is("leafref"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
}
}
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 88672fd..466bb97 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
@@ -207,4 +207,33 @@
assertThat(((YangInt32) rangeInterval.getEndValue()).getValue(), is(4));
assertThat(((YangInt32) rangeInterval.getEndValue()).getValue(), is(4));
}
+
+ /**
+ * Checks whether space can be allowed when range statement is present.
+ */
+ @Test
+ public void processRangeStatementWithSpace() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/RangeStatementWithSpace.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();
+
+ ListIterator<YangRangeInterval> rangeListIterator = rangeRestriction.getAscendingRangeIntervals()
+ .listIterator();
+ YangRangeInterval rangeInterval = rangeListIterator.next();
+ assertThat(((YangInt32) rangeInterval.getStartValue()).getValue(), is(1));
+ assertThat(((YangInt32) rangeInterval.getEndValue()).getValue(), is(4));
+ }
}
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/TypeListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/TypeListenerTest.java
index 1737ea6..1b6a7c6 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/TypeListenerTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/TypeListenerTest.java
@@ -17,7 +17,9 @@
import java.io.IOException;
import java.util.ListIterator;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
import org.onosproject.yangutils.datamodel.YangDataTypes;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
@@ -35,6 +37,9 @@
*/
public class TypeListenerTest {
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
private final YangUtilsParserManager manager = new YangUtilsParserManager();
/**
@@ -114,4 +119,46 @@
assertThat(leafListInfo.getDataType().getDataTypeName(), is("uint16"));
assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
}
+
+ /**
+ * Checks for unsupported type leafref.
+ */
+ @Test
+ public void processLeafrefType() throws IOException, ParserException {
+
+ thrown.expect(ParserException.class);
+ thrown.expectMessage("YANG file error : \"leafref\" is not supported in current version,"
+ + " please check wiki for YANG utils road map.");
+
+ YangNode node = manager
+ .getDataModel("src/test/resources/LeafrefInvalidIdentifier.yang");
+ }
+
+ /**
+ * Checks for unsupported type identityref.
+ */
+ @Test
+ public void processIdentityrefType() throws IOException, ParserException {
+
+ thrown.expect(ParserException.class);
+ thrown.expectMessage("YANG file error : \"identityref\" is not supported in current version,"
+ + " please check wiki for YANG utils road map.");
+
+ YangNode node = manager
+ .getDataModel("src/test/resources/IdentityrefInvalidIdentifier.yang");
+ }
+
+ /**
+ * Checks for unsupported type instance identifier.
+ */
+ @Test
+ public void processInstanceIdentifierType() throws IOException, ParserException {
+
+ thrown.expect(ParserException.class);
+ thrown.expectMessage("YANG file error : \"instance-identifier\" is not supported in current version,"
+ + " please check wiki for YANG utils road map.");
+
+ YangNode node = manager
+ .getDataModel("src/test/resources/InstanceIdentifierInvalidIdentifier.yang");
+ }
}
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/parseutils/ListenerUtilTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/parseutils/ListenerUtilTest.java
new file mode 100644
index 0000000..c29b126
--- /dev/null
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/parseutils/ListenerUtilTest.java
@@ -0,0 +1,46 @@
+/*
+ * 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.parseutils;
+
+import java.io.IOException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
+
+/**
+ * Test case for testing listener util.
+ */
+public class ListenerUtilTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ private final YangUtilsParserManager manager = new YangUtilsParserManager();
+
+ /**
+ * Checks whether exception is thrown when identifier starts with xml.
+ */
+ @Test
+ public void validateIdentifierStartsWithXml() throws IOException {
+ thrown.expect(ParserException.class);
+ thrown.expectMessage("YANG file error : module identifier xMlTest must not start" +
+ " with (('X'|'x') ('M'|'m') ('L'|'l'))");
+ manager.getDataModel("src/test/resources/InValidIdentifierXML.yang");
+ }
+}
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/parseutils/ListenerErrorMessageConstructionTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/parseutils/ListenerErrorMessageConstructionTest.java
deleted file mode 100644
index d10e009..0000000
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/parseutils/ListenerErrorMessageConstructionTest.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * 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.parseutils;
-
-import org.junit.Test;
-
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
-import static org.onosproject.yangutils.utils.YangConstructType.CONTACT_DATA;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
-
-/**
- * Test case for testing listener error message construction util.
- */
-public class ListenerErrorMessageConstructionTest {
-
- /**
- * Checks for error message construction with parsable data type name.
- */
- @Test
- public void checkErrorMsgConstructionWithName() {
-
- // Create an test error message
- String testErrorMessage = constructListenerErrorMessage(INVALID_HOLDER, CONTACT_DATA, "Test Instance", ENTRY);
-
- // Check message.
- assertThat(testErrorMessage, is("Internal parser error detected: Invalid holder for contact "
- + "\"Test Instance\" before processing."));
- }
-
- /**
- * Checks for error message construction without parsable data type name.
- */
- @Test
- public void checkErrorMsgConstructionWithoutName() {
-
- // Create an test error message
- String testErrorMessage = constructListenerErrorMessage(INVALID_HOLDER, CONTACT_DATA, "Test Instance", ENTRY);
-
- // Check message.
- assertThat(testErrorMessage,
- is("Internal parser error detected: Invalid holder for contact \"Test Instance\""
- + " before processing."));
- }
-
- /**
- * Checks for extended error message construction with parsable data type
- * name.
- */
- @Test
- public void checkExtendedErrorMsgConstructionWithName() {
-
- // Create an test error message
- String testErrorMessage = constructExtendedListenerErrorMessage(INVALID_HOLDER, CONTACT_DATA,
- "Test Instance", ENTRY,
- "Extended Information");
-
- // Check message.
- assertThat(testErrorMessage,
- is("Internal parser error detected: Invalid holder for contact \"Test Instance\""
- + " before processing.\n" + "Error Information: Extended Information"));
- }
-
- /**
- * Checks for extended error message construction without parsable data type
- * name.
- */
- @Test
- public void checkExtendedErrorMsgConstructionWithoutName() {
-
- // Create an test error message
- String testErrorMessage = constructExtendedListenerErrorMessage(INVALID_HOLDER, CONTACT_DATA, "", ENTRY,
- "Extended Information");
-
- // Check message.
- assertThat(testErrorMessage, is("Internal parser error detected: Invalid holder for contact"
- + " before processing.\n" + "Error Information: Extended Information"));
- }
-}
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/parseutils/ListenerValidationTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/parseutils/ListenerValidationTest.java
deleted file mode 100644
index f4e284e..0000000
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/parseutils/ListenerValidationTest.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * 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.parseutils;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.onosproject.yangutils.datamodel.YangRevision;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.utils.YangConstructType.YANGBASE_DATA;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsEmpty;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-
-/**
- * Test case for testing listener validation util.
- */
-public class ListenerValidationTest {
-
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
- /**
- * Checks for exception in case parsable stack is empty while validating for
- * not empty scenario.
- */
- @Test
- public void validateStackIsNotEmptyForEmptyStack() {
-
- String expectedError = constructListenerErrorMessage(MISSING_HOLDER, YANGBASE_DATA, "", EXIT);
-
- // Get the exception occurred during parsing.
- thrown.expect(ParserException.class);
- thrown.expectMessage(expectedError);
-
- // Create test walker and assign test error to it.
- TreeWalkListener testWalker = new TreeWalkListener();
-
- checkStackIsNotEmpty(testWalker, MISSING_HOLDER, YANGBASE_DATA, "", EXIT);
- }
-
- /**
- * Checks if there is no exception in case parsable stack is not empty while
- * validating for not empty scenario.
- */
- @Test
- public void validateStackIsNotEmptyForNonEmptyStack() {
-
- // Create test walker and assign test error to it.
- TreeWalkListener testWalker = new TreeWalkListener();
-
- // Create a temporary node of parsable.
- YangRevision tmpNode = new YangRevision();
- testWalker.getParsedDataStack().push(tmpNode);
-
- checkStackIsNotEmpty(testWalker, MISSING_HOLDER, YANGBASE_DATA, "", EXIT);
- }
-
- /**
- * Checks for exception in case parsable stack is not empty while validating
- * for empty scenario.
- */
- @Test
- public void validateStackIsEmptyForNonEmptyStack() {
-
- String expectedError = constructListenerErrorMessage(MISSING_HOLDER, YANGBASE_DATA, "", EXIT);
-
- // Get the exception occurred during parsing.
- thrown.expect(ParserException.class);
- thrown.expectMessage(expectedError);
-
- // Create test walker and assign test error to it.
- TreeWalkListener testWalker = new TreeWalkListener();
-
- // Create a temporary node of parsable.
- YangRevision tmpNode = new YangRevision();
- testWalker.getParsedDataStack().push(tmpNode);
-
- checkStackIsEmpty(testWalker, MISSING_HOLDER, YANGBASE_DATA, "", EXIT);
- }
-
- /**
- * Checks if there is no exception in case parsable stack is empty while
- * validating for empty scenario.
- */
- @Test
- public void validateStackIsEmptyForEmptyStack() {
-
- // Create test walker and assign test error to it.
- TreeWalkListener testWalker = new TreeWalkListener();
-
- checkStackIsEmpty(testWalker, MISSING_HOLDER, YANGBASE_DATA, "", EXIT);
- }
-}
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/parseutils/ParseTreeErrorListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/parseutils/ParseTreeErrorListenerTest.java
deleted file mode 100644
index dd09247..0000000
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/parseutils/ParseTreeErrorListenerTest.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * 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.parseutils;
-
-import org.antlr.v4.runtime.ANTLRFileStream;
-import org.antlr.v4.runtime.ANTLRInputStream;
-import org.antlr.v4.runtime.CommonTokenStream;
-import org.antlr.v4.runtime.tree.ParseTree;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangLexer;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.CustomExceptionMatcher;
-import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
-import org.onosproject.yangutils.parser.impl.parserutils.ParseTreeErrorListener;
-
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.IOException;
-
-/**
- * Test case for testing parse tree error listener.
- */
-public class ParseTreeErrorListenerTest {
-
- YangUtilsParserManager manager = new YangUtilsParserManager();
- File file;
- BufferedWriter out;
-
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
- /**
- * Checks that no exception is generated for YANG file with valid syntax.
- */
- @Test
- public void checkValidYangFileForNoSyntaxError() throws IOException {
-
- ANTLRInputStream input = new ANTLRFileStream("src/test/resources/YangFileWithoutSyntaxError.yang");
-
- // Create a lexer that feeds off of input char stream.
- GeneratedYangLexer lexer = new GeneratedYangLexer(input);
- // Create a buffer of tokens pulled from the lexer.
- CommonTokenStream tokens = new CommonTokenStream(lexer);
- // Create a parser that feeds off the tokens buffer.
- GeneratedYangParser parser = new GeneratedYangParser(tokens);
- // Remove console error listener.
- parser.removeErrorListeners();
- // Create instance of customized error listener.
- ParseTreeErrorListener parseTreeErrorListener = new ParseTreeErrorListener();
- // Add customized error listener to catch errors during parsing.
- parser.addErrorListener(parseTreeErrorListener);
- // Begin parsing YANG file and generate parse tree.
- ParseTree tree = parser.yangfile();
- }
-
- /**
- * Checks that exception is generated for YANG file with invalid syntax.
- */
- @Test
- public void checkInvalidYangFileForSyntaxError() throws IOException {
-
- // Get the exception occurred during parsing.
- thrown.expect(ParserException.class);
- thrown.expect(CustomExceptionMatcher.errorLocation(3, 0));
- thrown.expectMessage("no viable alternative at input 'yang-version 1\\nnamespace'");
-
- ANTLRInputStream input = new ANTLRFileStream("src/test/resources/YangFileWithSyntaxError.yang");
-
- // Create a lexer that feeds off of input char stream.
- GeneratedYangLexer lexer = new GeneratedYangLexer(input);
- // Create a buffer of tokens pulled from the lexer.
- CommonTokenStream tokens = new CommonTokenStream(lexer);
- // Create a parser that feeds off the tokens buffer.
- GeneratedYangParser parser = new GeneratedYangParser(tokens);
- // Remove console error listener.
- parser.removeErrorListeners();
- // Create instance of customized error listener.
- ParseTreeErrorListener parseTreeErrorListener = new ParseTreeErrorListener();
- // Add customized error listener to catch errors during parsing.
- parser.addErrorListener(parseTreeErrorListener);
- // Begin parsing YANG file and generate parse tree.
- ParseTree tree = parser.yangfile();
- }
-}
\ No newline at end of file
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/AttributesJavaDataTypeTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/AttributesJavaDataTypeTest.java
index 00066f9..f2ca36e 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/AttributesJavaDataTypeTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/AttributesJavaDataTypeTest.java
@@ -59,6 +59,7 @@
private static final String CLASS_INFO5 = "Integer";
private static final String TYPE_DEF_PKG = "target.test";
private static String test = "";
+ private static YangToJavaNamingConflictUtil pluginConfig = null;
/**
* Unit test for private constructor.
@@ -71,7 +72,8 @@
* @throws InvocationTargetException when an exception occurs by the method or constructor
*/
@Test
- public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
+ public void callPrivateConstructors()
+ throws SecurityException, NoSuchMethodException, IllegalArgumentException,
InstantiationException, IllegalAccessException, InvocationTargetException {
Class<?>[] classesToConstruct = {AttributesJavaDataType.class };
@@ -87,16 +89,16 @@
*/
@Test
public void testgetJavaClassInfo() {
- test = getJavaImportClass(getStubYangType(TYPE1), false);
+ test = getJavaImportClass(getStubYangType(TYPE1), false, pluginConfig);
assertThat(true, is(test.equals(CLASS_INFO1)));
- test = getJavaImportClass(getStubYangType(TYPE2), true);
+ test = getJavaImportClass(getStubYangType(TYPE2), true, pluginConfig);
assertThat(true, is(test.equals(CLASS_INFO5)));
- test = getJavaImportClass(getStubYangType(TYPE3), false);
+ test = getJavaImportClass(getStubYangType(TYPE3), false, pluginConfig);
assertThat(null, is(test));
- test = getJavaImportClass(getStubYangType(TYPE4), false);
+ test = getJavaImportClass(getStubYangType(TYPE4), false, pluginConfig);
assertThat(null, is(test));
}
@@ -123,16 +125,16 @@
*/
@Test
public void testgetJavaPkgInfo() {
- test = getJavaImportPackage(getStubYangType(TYPE1), false, CLASS_INFO1);
+ test = getJavaImportPackage(getStubYangType(TYPE1), false, pluginConfig);
assertThat(true, is(test.equals(JAVA_LANG)));
- test = getJavaImportPackage(getStubYangType(TYPE2), true, CLASS_INFO5);
+ test = getJavaImportPackage(getStubYangType(TYPE2), true, pluginConfig);
assertThat(true, is(test.equals(JAVA_LANG)));
- test = getJavaImportPackage(getStubYangType(TYPE3), false, CLASS_INFO3);
+ test = getJavaImportPackage(getStubYangType(TYPE3), false, pluginConfig);
assertThat(null, is(test));
- test = getJavaImportPackage(getStubYangType(TYPE4), false, CLASS_INFO4);
+ test = getJavaImportPackage(getStubYangType(TYPE4), false, pluginConfig);
assertThat(null, is(test));
}
@@ -143,7 +145,7 @@
*/
@Test
public void testForTypeDef() throws DataModelException {
- test = getJavaImportPackage(getStubExtendedInfo(getStubYangType(TYPE_DEF)), false, TYPE_DEF_PKG);
+ test = getJavaImportPackage(getStubExtendedInfo(getStubYangType(TYPE_DEF)), false, pluginConfig);
assertThat(true, is(test.equals(TYPE_DEF_PKG)));
}
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ChoiceCaseTranslatorTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ChoiceCaseTranslatorTest.java
index 301c58a..74043f6 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ChoiceCaseTranslatorTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ChoiceCaseTranslatorTest.java
@@ -17,6 +17,7 @@
package org.onosproject.yangutils.translator.tojava.utils;
import java.io.IOException;
+
import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.parser.exceptions.ParserException;
@@ -44,7 +45,7 @@
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir(userDir + "/target/ChoiceCaseTestGenFile/");
- generateJavaCode(node, yangPluginConfig, "ChoiceCaseTranslator");
+ generateJavaCode(node, yangPluginConfig);
deleteDirectory(userDir + "/target/ChoiceCaseTestGenFile/");
}
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/EnumTranslatorTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/EnumTranslatorTest.java
index 2f81a60..2a950fc 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/EnumTranslatorTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/EnumTranslatorTest.java
@@ -46,7 +46,7 @@
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir(userDir + "/target/EnumTestGenFile/");
- generateJavaCode(node, yangPluginConfig, "EnumTranslator");
+ generateJavaCode(node, yangPluginConfig);
deleteDirectory(userDir + "/target/EnumTestGenFile/");
}
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntaxTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntaxTest.java
index a3b9200..6b86b9c 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntaxTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntaxTest.java
@@ -19,7 +19,10 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
@@ -38,6 +41,9 @@
*/
public final class JavaIdentifierSyntaxTest {
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
private static final String PARENT_PACKAGE = "test5/test6/test7";
private static final String CHILD_PACKAGE = "test1:test2:test3";
private static final String DATE1 = "2000-1-5";
@@ -47,10 +53,17 @@
private static final String DATE_WITH_REV1 = "rev20000105";
private static final String DATE_WITH_REV2 = "rev19920125";
private static final String VERSION_NUMBER = "v1";
+ private static final String VALID_PREFIX = "123add-prefix";
+ private static final String INVALID_PREFIX = "-*()&^&#$%";
+ private static final String INVALID_PREFIX1 = "abc~!@#$%^&*()_+}{:<>?`1234567890-=[]''|,./SS";
+ private static final String INVALID_NAME_SPACE_FOR_INVALID_PREFIX = "try:#test3:9case3";
private static final String INVALID_NAME_SPACE1 = "byte:#test2:9test3";
private static final String INVALID_NAME_SPACE2 = "const:#test2://9test3";
- private static final String VALID_NAME_SPACE1 = "yangautoprefixbyte.test2.yangautoprefix9test3";
+ private static final String INVALID_NAME_SPACE3 = "CONST:TRY://9test3";
+ private static final String VALID_NAME_SPACE1 = "123addprefixbyte.test2.123addprefix9test3";
private static final String VALID_NAME_SPACE2 = "yangautoprefixconst.test2.yangautoprefix9test3";
+ private static final String VALID_NAME_SPACE3 = "abc1234567890ssconst.test2.abc1234567890ss9test3";
+ private static final String VALID_NAME_SPACE4 = "yangautoprefixconst.yangautoprefixtry.yangautoprefix9test3";
private static final String WITHOUT_CAMEL_CASE = "test-camel-case-identifier";
private static final String WITH_CAMEL_CASE = "testCamelCaseIdentifier";
private static final String WITHOUT_CAMEL_CASE1 = ".-_try-._-.123";
@@ -77,9 +90,16 @@
private static final String WITH_CAMEL_CASE11 = "test3Name";
private static final String WITHOUT_CAMEL_CASE12 = "TEST3name";
private static final String WITH_CAMEL_CASE12 = "test3Name";
+ private static final String WITHOUT_CAMEL_CASE13 = "t-RY";
+ private static final String WITH_CAMEL_CASE13 = "tRy";
+ private static final String WITHOUT_CAMEL_CASE14 = "TRY";
+ private static final String WITH_CAMEL_CASE14 = "yangAutoPrefixTry";
private static final String WITHOUT_CAPITAL = "test_this";
private static final String WITH_CAPITAL = "Test_this";
private static final String WITH_SMALL = "test_this";
+ private static final String WITH_CAMEL_CASE_WITH_PREFIX = "123addPrefixTry";
+ private static final String WITH_CAMEL_CASE_WITH_PREFIX1 = "abc1234567890Ss1123G123Gaa";
+ private static YangToJavaNamingConflictUtil conflictResolver = new YangToJavaNamingConflictUtil();
/**
* Unit test for private constructor.
@@ -111,22 +131,44 @@
*/
@Test
public void getRootPackageTest() {
- String rootPackage = getRootPackage((byte) 1, CHILD_PACKAGE, DATE1);
+ conflictResolver.setPrefixForIdentifier(null);
+ String rootPackage = getRootPackage((byte) 1, CHILD_PACKAGE, DATE1, conflictResolver);
assertThat(rootPackage.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER
+ PERIOD + CHILD_WITH_PERIOD + PERIOD + DATE_WITH_REV1), is(true));
}
/**
+ * Unit test for root package generation with invalid prefix.
+ */
+ @Test
+ public void getRootPackageWithInvalidPrefix() throws TranslatorException {
+ thrown.expect(TranslatorException.class);
+ thrown.expectMessage("The given prefix in pom.xml is invalid.");
+ conflictResolver.setPrefixForIdentifier(INVALID_PREFIX);
+ String rootPackage1 = getRootPackage((byte) 1, INVALID_NAME_SPACE_FOR_INVALID_PREFIX, DATE1, conflictResolver);
+ }
+
+ /**
* Unit test for root package generation with special characters presence.
*/
@Test
public void getRootPackageWithSpecialCharactersTest() {
- String rootPackage = getRootPackage((byte) 1, INVALID_NAME_SPACE1, DATE1);
+ conflictResolver.setPrefixForIdentifier(VALID_PREFIX);
+ String rootPackage = getRootPackage((byte) 1, INVALID_NAME_SPACE1, DATE1, conflictResolver);
assertThat(rootPackage.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER
+ PERIOD + VALID_NAME_SPACE1 + PERIOD + DATE_WITH_REV1), is(true));
- String rootPackage1 = getRootPackage((byte) 1, INVALID_NAME_SPACE2, DATE1);
+ conflictResolver.setPrefixForIdentifier(null);
+ String rootPackage1 = getRootPackage((byte) 1, INVALID_NAME_SPACE2, DATE1, conflictResolver);
assertThat(rootPackage1.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER
+ PERIOD + VALID_NAME_SPACE2 + PERIOD + DATE_WITH_REV1), is(true));
+ String rootPackage2 = getRootPackage((byte) 1, INVALID_NAME_SPACE3, DATE1, conflictResolver);
+ assertThat(rootPackage2.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER
+ + PERIOD + VALID_NAME_SPACE4 + PERIOD + DATE_WITH_REV1), is(true));
+ conflictResolver.setPrefixForIdentifier(INVALID_PREFIX1);
+ String rootPackage3 = getRootPackage((byte) 1, INVALID_NAME_SPACE2, DATE1, conflictResolver);
+ assertThat(rootPackage3.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER
+ + PERIOD + VALID_NAME_SPACE3 + PERIOD + DATE_WITH_REV1), is(true));
+
}
/**
@@ -134,7 +176,7 @@
*/
@Test
public void getRootPackageWithRevTest() {
- String rootPkgWithRev = getRootPackage((byte) 1, CHILD_PACKAGE, DATE2);
+ String rootPkgWithRev = getRootPackage((byte) 1, CHILD_PACKAGE, DATE2, null);
assertThat(rootPkgWithRev.equals(
DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER + PERIOD + CHILD_WITH_PERIOD + PERIOD + DATE_WITH_REV2),
is(true));
@@ -154,32 +196,63 @@
*/
@Test
public void getCamelCaseTest() {
- String camelCase = getCamelCase(WITHOUT_CAMEL_CASE, null);
+ conflictResolver.setPrefixForIdentifier(null);
+ String camelCase = getCamelCase(WITHOUT_CAMEL_CASE, conflictResolver);
assertThat(camelCase.equals(WITH_CAMEL_CASE), is(true));
- String camelCase1 = getCamelCase(WITHOUT_CAMEL_CASE1, null);
+ String camelCase1 = getCamelCase(WITHOUT_CAMEL_CASE1, conflictResolver);
assertThat(camelCase1.equals(WITH_CAMEL_CASE1), is(true));
- String camelCase2 = getCamelCase(WITHOUT_CAMEL_CASE2, null);
+ String camelCase2 = getCamelCase(WITHOUT_CAMEL_CASE2, conflictResolver);
assertThat(camelCase2.equals(WITH_CAMEL_CASE2), is(true));
- String camelCase3 = getCamelCase(WITHOUT_CAMEL_CASE3, null);
+ String camelCase3 = getCamelCase(WITHOUT_CAMEL_CASE3, conflictResolver);
assertThat(camelCase3.equals(WITH_CAMEL_CASE3), is(true));
- String camelCase4 = getCamelCase(WITHOUT_CAMEL_CASE4, null);
+ String camelCase4 = getCamelCase(WITHOUT_CAMEL_CASE4, conflictResolver);
assertThat(camelCase4.equals(WITH_CAMEL_CASE4), is(true));
- String camelCase5 = getCamelCase(WITHOUT_CAMEL_CASE5, null);
+ String camelCase5 = getCamelCase(WITHOUT_CAMEL_CASE5, conflictResolver);
assertThat(camelCase5.equals(WITH_CAMEL_CASE5), is(true));
- String camelCase6 = getCamelCase(WITHOUT_CAMEL_CASE6, null);
+ String camelCase6 = getCamelCase(WITHOUT_CAMEL_CASE6, conflictResolver);
assertThat(camelCase6.equals(WITH_CAMEL_CASE6), is(true));
- String camelCase7 = getCamelCase(WITHOUT_CAMEL_CASE7, null);
+ String camelCase7 = getCamelCase(WITHOUT_CAMEL_CASE7, conflictResolver);
assertThat(camelCase7.equals(WITH_CAMEL_CASE7), is(true));
- String camelCase8 = getCamelCase(WITHOUT_CAMEL_CASE8, null);
+ String camelCase8 = getCamelCase(WITHOUT_CAMEL_CASE8, conflictResolver);
assertThat(camelCase8.equals(WITH_CAMEL_CASE8), is(true));
- String camelCase9 = getCamelCase(WITHOUT_CAMEL_CASE9, null);
+ String camelCase9 = getCamelCase(WITHOUT_CAMEL_CASE9, conflictResolver);
assertThat(camelCase9.equals(WITH_CAMEL_CASE9), is(true));
- String camelCase10 = getCamelCase(WITHOUT_CAMEL_CASE10, null);
+ String camelCase10 = getCamelCase(WITHOUT_CAMEL_CASE10, conflictResolver);
assertThat(camelCase10.equals(WITH_CAMEL_CASE10), is(true));
- String camelCase11 = getCamelCase(WITHOUT_CAMEL_CASE11, null);
+ String camelCase11 = getCamelCase(WITHOUT_CAMEL_CASE11, conflictResolver);
assertThat(camelCase11.equals(WITH_CAMEL_CASE11), is(true));
- String camelCase12 = getCamelCase(WITHOUT_CAMEL_CASE12, null);
+ String camelCase12 = getCamelCase(WITHOUT_CAMEL_CASE12, conflictResolver);
assertThat(camelCase12.equals(WITH_CAMEL_CASE12), is(true));
+ String camelCase13 = getCamelCase(WITHOUT_CAMEL_CASE13, conflictResolver);
+ assertThat(camelCase13.equals(WITH_CAMEL_CASE13), is(true));
+ String camelCase14 = getCamelCase(WITHOUT_CAMEL_CASE14, conflictResolver);
+ assertThat(camelCase14.equals(WITH_CAMEL_CASE14), is(true));
+ }
+
+ /**
+ * Unit test for getting the camel case along with the prefix provided.
+ */
+ @Test
+ public void getCamelCaseWithPrefixTest() {
+
+ conflictResolver.setPrefixForIdentifier(VALID_PREFIX);
+ String camelCase = getCamelCase(WITHOUT_CAMEL_CASE2, conflictResolver);
+ assertThat(camelCase.equals(WITH_CAMEL_CASE_WITH_PREFIX), is(true));
+ conflictResolver.setPrefixForIdentifier(INVALID_PREFIX1);
+ String camelCase2 = getCamelCase(WITHOUT_CAMEL_CASE3, conflictResolver);
+ assertThat(camelCase2.equals(WITH_CAMEL_CASE_WITH_PREFIX1), is(true));
+ }
+
+ /**
+ * Unit test for getting the camel case along with the invalid prefix provided.
+ */
+ @Test
+ public void getCamelCaseWithInvalidPrefixTest() throws TranslatorException {
+
+ thrown.expect(TranslatorException.class);
+ thrown.expectMessage("The given prefix in pom.xml is invalid.");
+ conflictResolver.setPrefixForIdentifier(INVALID_PREFIX);
+ String camelCase = getCamelCase(WITHOUT_CAMEL_CASE3, conflictResolver);
}
/**
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java
index 020ba44..05fe52d 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java
@@ -29,6 +29,7 @@
import static org.junit.Assert.assertThat;
import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuild;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuildForInterface;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getCheckNotNull;
@@ -105,7 +106,7 @@
throws SecurityException, NoSuchMethodException, IllegalArgumentException,
InstantiationException, IllegalAccessException, InvocationTargetException {
- Class<?>[] classesToConstruct = {MethodsGenerator.class};
+ Class<?>[] classesToConstruct = {MethodsGenerator.class };
for (Class<?> clazz : classesToConstruct) {
Constructor<?> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
@@ -118,8 +119,10 @@
*/
@Test
public void getTypeConstructorTest() {
+
+ YangPluginConfig pluginConfig = new YangPluginConfig();
JavaAttributeInfo testAttr = getTestAttribute();
- String test = getTypeConstructorStringAndJavaDoc(testAttr, CLASS_NAME);
+ String test = getTypeConstructorStringAndJavaDoc(testAttr, CLASS_NAME, pluginConfig);
assertThat(true, is(test.contains(PUBLIC + SPACE + CLASS_NAME + OPEN_PARENTHESIS)));
}
@@ -162,7 +165,8 @@
@Test
public void getConstructorTest() {
JavaAttributeInfo testAttr = getTestAttribute();
- String method = getConstructor(CLASS_NAME, testAttr, GENERATE_SERVICE_AND_MANAGER);
+ YangPluginConfig pluginConfig = new YangPluginConfig();
+ String method = getConstructor(CLASS_NAME, testAttr, GENERATE_SERVICE_AND_MANAGER, pluginConfig);
assertThat(true, is(method.contains(THIS + PERIOD + CLASS_NAME + SPACE + EQUAL + SPACE + "builder" + OBJECT
+ PERIOD + GET_METHOD_PREFIX + "Testname" + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN)));
}
@@ -172,7 +176,8 @@
*/
@Test
public void getConstructorStartTest() {
- String method = getConstructorStart(CLASS_NAME);
+ YangPluginConfig pluginConfig = new YangPluginConfig();
+ String method = getConstructorStart(CLASS_NAME, pluginConfig);
assertThat(true, is(method.contains(PUBLIC + SPACE + CLASS_NAME + IMPL + OPEN_PARENTHESIS + CLASS_NAME
+ BUILDER + SPACE + BUILDER.toLowerCase() + OBJECT + CLOSE_PARENTHESIS + SPACE
+ OPEN_CURLY_BRACKET + NEW_LINE)));
@@ -227,10 +232,10 @@
public void getSetterForClassTest() {
JavaAttributeInfo testAttr = getTestAttribute();
String method = getSetterForClass(testAttr, CLASS_NAME, GENERATE_SERVICE_AND_MANAGER);
-// assertThat(true, is(
-// method.contains(PUBLIC + SPACE + CLASS_NAME + BUILDER + SPACE + SET_METHOD_PREFIX
-// + getCaptialCase(ATTRIBUTE_NAME) + OPEN_PARENTHESIS + STRING_DATA_TYPE + SPACE
-// + ATTRIBUTE_NAME)));
+ assertThat(true, is(
+ method.contains(PUBLIC + SPACE + VOID + SPACE +
+ SET_METHOD_PREFIX + getCapitalCase(CLASS_NAME) + OPEN_PARENTHESIS +
+ STRING_DATA_TYPE + SPACE + ATTRIBUTE_NAME)));
}
/**
@@ -240,7 +245,8 @@
public void getSetterForInterfaceTest() {
String method = getSetterForInterface(CLASS_NAME, STRING_DATA_TYPE, CLASS_NAME, false,
GENERATE_SERVICE_AND_MANAGER);
-// assertThat(true, is(method.contains(CLASS_NAME + BUILDER + SPACE + SET_METHOD_PREFIX + "Testname")));
+ assertThat(true, is(method.contains(VOID + SPACE +
+ SET_METHOD_PREFIX + "Testname")));
}
/**
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/NotificationTranslatorTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/NotificationTranslatorTest.java
index 02ff5d8..f4d8bf8 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/NotificationTranslatorTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/NotificationTranslatorTest.java
@@ -46,7 +46,7 @@
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir(userDir + "/target/NotificationTest/");
- generateJavaCode(node, yangPluginConfig, "NotificationTest");
+ generateJavaCode(node, yangPluginConfig);
deleteDirectory(userDir + "/target/NotificationTest/");
}
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/RpcTranslatorTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/RpcTranslatorTest.java
index 8be657b..9b8077c 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/RpcTranslatorTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/RpcTranslatorTest.java
@@ -46,7 +46,7 @@
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir(userDir + "/target/RpcTestGenFile/");
- generateJavaCode(node, yangPluginConfig, "RpcTranslator");
+ generateJavaCode(node, yangPluginConfig);
deleteDirectory(userDir + "/target/RpcTestGenFile/");
}
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/UnionTranslatorTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/UnionTranslatorTest.java
index 9c0c42f..9dcdfdf 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/UnionTranslatorTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/UnionTranslatorTest.java
@@ -46,7 +46,7 @@
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/UnionTestGenFile/");
- generateJavaCode(node, yangPluginConfig, "UnionTranslator");
+ generateJavaCode(node, yangPluginConfig);
deleteDirectory(userDir + "/target/UnionTestGenFile/");
}
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtilTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtilTest.java
index 9819445..d0df0fd 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtilTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtilTest.java
@@ -25,6 +25,7 @@
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
+import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
@@ -125,7 +126,20 @@
javafileInfo.setJavaName(TEST_DATA_1);
javafileInfo.setBaseCodeGenPath("");
javafileInfo.setPackageFilePath(BASE_PKG);
+ javafileInfo.setPluginConfig(getStubPluginConfig());
module.setJavaFileInfo(javafileInfo);
return module;
}
+
+ /**
+ * Returns stub pluginConfig.
+ *
+ * @return stub pluginConfig
+ */
+ private YangPluginConfig getStubPluginConfig() {
+ YangPluginConfig pluginConfig = new YangPluginConfig();
+ pluginConfig.setConflictResolver(null);
+ return pluginConfig;
+ }
+
}
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/io/impl/JavaDocGenTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/io/impl/JavaDocGenTest.java
index 0284ea0..2e9f436 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/io/impl/JavaDocGenTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/io/impl/JavaDocGenTest.java
@@ -22,6 +22,7 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
@@ -55,7 +56,7 @@
*/
@Test
public void builderClassGenerationTest() {
- String builderClassJavaDoc = getJavaDoc(BUILDER_CLASS, TEST_NAME, false);
+ String builderClassJavaDoc = getJavaDoc(BUILDER_CLASS, TEST_NAME, false, getStubPluginConfig());
assertThat(true, is(builderClassJavaDoc.contains("Represents the builder implementation of")
&& builderClassJavaDoc.contains(END_STRING)));
}
@@ -65,9 +66,10 @@
*/
@Test
public void builderInterfaceGenerationTest() {
- String builderInterfaceJavaDoc = getJavaDoc(BUILDER_INTERFACE, TEST_NAME, false);
+ String builderInterfaceJavaDoc = getJavaDoc(BUILDER_INTERFACE, TEST_NAME, false, getStubPluginConfig());
assertThat(true,
- is(builderInterfaceJavaDoc.contains("Builder for") && builderInterfaceJavaDoc.contains(END_STRING)));
+ is(builderInterfaceJavaDoc.contains("Builder for")
+ && builderInterfaceJavaDoc.contains(END_STRING)));
}
/**
@@ -75,7 +77,7 @@
*/
@Test
public void buildGenerationTest() {
- String buildDoc = getJavaDoc(BUILD_METHOD, TEST_NAME, false);
+ String buildDoc = getJavaDoc(BUILD_METHOD, TEST_NAME, false, getStubPluginConfig());
assertThat(true, is(buildDoc.contains("Builds object of") && buildDoc.contains(END_STRING)));
}
@@ -90,7 +92,8 @@
* @throws InvocationTargetException when an exception occurs by the method or constructor
*/
@Test
- public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
+ public void callPrivateConstructors()
+ throws SecurityException, NoSuchMethodException, IllegalArgumentException,
InstantiationException, IllegalAccessException, InvocationTargetException {
Class<?>[] classesToConstruct = {JavaDocGen.class };
@@ -106,9 +109,10 @@
*/
@Test
public void constructorGenerationTest() {
- String constructorDoc = getJavaDoc(CONSTRUCTOR, TEST_NAME, false);
+ String constructorDoc = getJavaDoc(CONSTRUCTOR, TEST_NAME, false, getStubPluginConfig());
assertThat(true,
- is(constructorDoc.contains("Creates an instance of ") && constructorDoc.contains("builder object of")
+ is(constructorDoc.contains("Creates an instance of ")
+ && constructorDoc.contains("builder object of")
&& constructorDoc.contains("@param") && constructorDoc.contains("*/\n")));
}
@@ -117,7 +121,7 @@
*/
@Test
public void defaultConstructorGenerationTest() {
- String defaultConstructorDoc = getJavaDoc(DEFAULT_CONSTRUCTOR, TEST_NAME, false);
+ String defaultConstructorDoc = getJavaDoc(DEFAULT_CONSTRUCTOR, TEST_NAME, false, getStubPluginConfig());
assertThat(true, is(defaultConstructorDoc.contains("Creates an instance of ")
&& defaultConstructorDoc.contains(END_STRING)));
}
@@ -127,8 +131,9 @@
*/
@Test
public void getterGenerationTest() {
- String getterJavaDoc = getJavaDoc(GETTER_METHOD, TEST_NAME, false);
- assertThat(true, is(getterJavaDoc.contains("Returns the attribute") && getterJavaDoc.contains(END_STRING)));
+ String getterJavaDoc = getJavaDoc(GETTER_METHOD, TEST_NAME, false, getStubPluginConfig());
+ assertThat(true,
+ is(getterJavaDoc.contains("Returns the attribute") && getterJavaDoc.contains(END_STRING)));
}
/**
@@ -136,7 +141,7 @@
*/
@Test
public void implClassGenerationTest() {
- String implClassJavaDoc = getJavaDoc(IMPL_CLASS, TEST_NAME, false);
+ String implClassJavaDoc = getJavaDoc(IMPL_CLASS, TEST_NAME, false, getStubPluginConfig());
assertThat(true,
is(implClassJavaDoc.contains("Represents the implementation of")
&& implClassJavaDoc.contains(END_STRING)));
@@ -147,7 +152,7 @@
*/
@Test
public void interfaceGenerationTest() {
- String interfaceJavaDoc = getJavaDoc(INTERFACE, TEST_NAME, false);
+ String interfaceJavaDoc = getJavaDoc(INTERFACE, TEST_NAME, false, getStubPluginConfig());
assertThat(true,
is(interfaceJavaDoc.contains("Abstraction of an entity which represents the functionality of")
&& interfaceJavaDoc.contains(END_STRING)));
@@ -158,8 +163,9 @@
*/
@Test
public void packageInfoGenerationTest() {
- String packageInfo = getJavaDoc(PACKAGE_INFO, TEST_NAME, false);
- assertThat(true, is(packageInfo.contains("Implementation of YANG node") && packageInfo.contains(END_STRING)));
+ String packageInfo = getJavaDoc(PACKAGE_INFO, TEST_NAME, false, getStubPluginConfig());
+ assertThat(true,
+ is(packageInfo.contains("Implementation of YANG node") && packageInfo.contains(END_STRING)));
}
/**
@@ -167,7 +173,7 @@
*/
@Test
public void packageInfoGenerationForChildNodeTest() {
- String packageInfo = getJavaDoc(PACKAGE_INFO, TEST_NAME, true);
+ String packageInfo = getJavaDoc(PACKAGE_INFO, TEST_NAME, true, getStubPluginConfig());
assertThat(true, is(packageInfo.contains("Implementation of YANG node testName's children nodes")
&& packageInfo.contains(END_STRING)));
}
@@ -177,7 +183,7 @@
*/
@Test
public void setterGenerationTest() {
- String setterJavaDoc = getJavaDoc(SETTER_METHOD, TEST_NAME, false);
+ String setterJavaDoc = getJavaDoc(SETTER_METHOD, TEST_NAME, false, getStubPluginConfig());
assertThat(true,
is(setterJavaDoc.contains("Returns the builder object of") && setterJavaDoc.contains(END_STRING)));
}
@@ -187,7 +193,18 @@
*/
@Test
public void typeDefSetterGenerationTest() {
- String typeDefSetter = getJavaDoc(TYPE_DEF_SETTER_METHOD, TEST_NAME, false);
+ String typeDefSetter = getJavaDoc(TYPE_DEF_SETTER_METHOD, TEST_NAME, false, getStubPluginConfig());
assertThat(true, is(typeDefSetter.contains("Sets the value of") && typeDefSetter.contains(END_STRING)));
}
+
+ /**
+ * Returns stub pluginConfig.
+ *
+ * @return stub pluginConfig
+ */
+ private YangPluginConfig getStubPluginConfig() {
+ YangPluginConfig pluginConfig = new YangPluginConfig();
+ pluginConfig.setConflictResolver(null);
+ return pluginConfig;
+ }
}
\ No newline at end of file
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/io/impl/YangIoUtilsTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/io/impl/YangIoUtilsTest.java
index 204bd7b..c4558f6 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/io/impl/YangIoUtilsTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/io/impl/YangIoUtilsTest.java
@@ -25,6 +25,7 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import org.onosproject.yangutils.utils.UtilConstants;
import org.sonatype.plexus.build.incremental.BuildContext;
import org.sonatype.plexus.build.incremental.DefaultBuildContext;
@@ -68,7 +69,7 @@
File dirPath = new File(CREATE_PATH);
dirPath.mkdirs();
- addPackageInfo(dirPath, CHECK1, CREATE_PATH, false);
+ addPackageInfo(dirPath, CHECK1, CREATE_PATH, false, getStubPluginConfig());
File filePath = new File(dirPath + File.separator + PKG_INFO);
assertThat(filePath.isFile(), is(true));
}
@@ -83,7 +84,7 @@
File dirPath = new File(CREATE_PATH);
dirPath.mkdirs();
- addPackageInfo(dirPath, CHECK1, PATH + CREATE_PATH, false);
+ addPackageInfo(dirPath, CHECK1, PATH + CREATE_PATH, false, getStubPluginConfig());
File filePath = new File(dirPath + File.separator + PKG_INFO);
assertThat(filePath.isFile(), is(true));
}
@@ -98,7 +99,7 @@
File dirPath = new File(CREATE_PATH);
dirPath.mkdirs();
- addPackageInfo(dirPath, CHECK1, PATH + CREATE_PATH, true);
+ addPackageInfo(dirPath, CHECK1, PATH + CREATE_PATH, true, getStubPluginConfig());
File filePath = new File(dirPath + File.separator + PKG_INFO);
assertThat(filePath.isFile(), is(true));
}
@@ -114,7 +115,7 @@
File dirPath = new File("invalid/check");
thrown.expect(IOException.class);
thrown.expectMessage(MSG);
- addPackageInfo(dirPath, CHECK1, CREATE_PATH, false);
+ addPackageInfo(dirPath, CHECK1, CREATE_PATH, false, getStubPluginConfig());
File filePath1 = new File(dirPath + File.separator + PKG_INFO);
assertThat(filePath1.isFile(), is(false));
}
@@ -130,7 +131,8 @@
* @throws InvocationTargetException when an exception occurs by the method or constructor
*/
@Test
- public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
+ public void callPrivateConstructors()
+ throws SecurityException, NoSuchMethodException, IllegalArgumentException,
InstantiationException, IllegalAccessException, InvocationTargetException {
Class<?>[] classesToConstruct = {YangIoUtils.class };
@@ -192,7 +194,7 @@
addToSource(sourceDir.toString(), project, context);
}
- /*
+ /**
* Unit test case for trim at last method.
*/
@Test
@@ -202,4 +204,14 @@
assertThat(test.contains(TRIM_STRING), is(true));
}
+ /**
+ * Returns stub pluginConfig.
+ *
+ * @return stub pluginConfig
+ */
+ private YangPluginConfig getStubPluginConfig() {
+ YangPluginConfig pluginConfig = new YangPluginConfig();
+ pluginConfig.setConflictResolver(null);
+ return pluginConfig;
+ }
}
diff --git a/utils/yangutils/src/test/resources/BitTypedefStatement.yang b/utils/yangutils/src/test/resources/BitTypedefStatement.yang
new file mode 100644
index 0000000..d3dc26a
--- /dev/null
+++ b/utils/yangutils/src/test/resources/BitTypedefStatement.yang
@@ -0,0 +1,18 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ typedef type15 {
+ type bits {
+ bit disable-nagle {
+ position 0;
+ }
+ bit auto-sense-speed {
+ position 1;
+ }
+ bit Mb-only {
+ position 2;
+ }
+ }
+ }
+}
diff --git a/utils/yangutils/src/test/resources/BitUnionStatement.yang b/utils/yangutils/src/test/resources/BitUnionStatement.yang
new file mode 100644
index 0000000..dd62eae
--- /dev/null
+++ b/utils/yangutils/src/test/resources/BitUnionStatement.yang
@@ -0,0 +1,20 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ leaf type15 {
+ type union {
+ type bits {
+ bit disable-nagle {
+ position 0;
+ }
+ bit auto-sense-speed {
+ position 1;
+ }
+ bit Mb-only {
+ position 2;
+ }
+ }
+ }
+ }
+}
diff --git a/utils/yangutils/src/test/resources/EnumSorted.yang b/utils/yangutils/src/test/resources/EnumSorted.yang
new file mode 100644
index 0000000..3760e83
--- /dev/null
+++ b/utils/yangutils/src/test/resources/EnumSorted.yang
@@ -0,0 +1,18 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ leaf ifType {
+ type enumeration {
+ enum four{
+ value 7;
+ }
+ enum seven {
+ value 2147483647;
+ }
+ enum five {
+ value 5;
+ }
+ }
+ }
+}
diff --git a/utils/yangutils/src/test/resources/IdentityrefInvalidIdentifier.yang b/utils/yangutils/src/test/resources/IdentityrefInvalidIdentifier.yang
new file mode 100644
index 0000000..99a8129
--- /dev/null
+++ b/utils/yangutils/src/test/resources/IdentityrefInvalidIdentifier.yang
@@ -0,0 +1,11 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ grouping currentcheck {
+ leaf invalid-interval {
+ type identityref {
+ }
+ }
+ }
+}
diff --git a/utils/yangutils/src/test/resources/InValidIdentifierXML.yang b/utils/yangutils/src/test/resources/InValidIdentifierXML.yang
new file mode 100644
index 0000000..c6a5a42
--- /dev/null
+++ b/utils/yangutils/src/test/resources/InValidIdentifierXML.yang
@@ -0,0 +1,5 @@
+module xMlTest {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix On;
+}
diff --git a/utils/yangutils/src/test/resources/InstanceIdentifierInvalidIdentifier.yang b/utils/yangutils/src/test/resources/InstanceIdentifierInvalidIdentifier.yang
new file mode 100644
index 0000000..0bbe2f1
--- /dev/null
+++ b/utils/yangutils/src/test/resources/InstanceIdentifierInvalidIdentifier.yang
@@ -0,0 +1,10 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ container currentcheck {
+ leaf invalid-interval {
+ type instance-identifier;
+ }
+ }
+}
diff --git a/utils/yangutils/src/test/resources/LeafrefInvalidIdentifier.yang b/utils/yangutils/src/test/resources/LeafrefInvalidIdentifier.yang
new file mode 100644
index 0000000..4737b6c
--- /dev/null
+++ b/utils/yangutils/src/test/resources/LeafrefInvalidIdentifier.yang
@@ -0,0 +1,8 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ leaf-list invalid-interval {
+ type leafref;
+ }
+}
diff --git a/utils/yangutils/src/test/resources/LengthStatementWithSpace.yang b/utils/yangutils/src/test/resources/LengthStatementWithSpace.yang
new file mode 100644
index 0000000..e8612d1
--- /dev/null
+++ b/utils/yangutils/src/test/resources/LengthStatementWithSpace.yang
@@ -0,0 +1,10 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ leaf invalid-interval {
+ type string {
+ length " 0 .. 100 ";
+ }
+ }
+}
diff --git a/utils/yangutils/src/test/resources/MaxElementsMaxValue.yang b/utils/yangutils/src/test/resources/MaxElementsMaxValue.yang
new file mode 100644
index 0000000..7bdfbb0
--- /dev/null
+++ b/utils/yangutils/src/test/resources/MaxElementsMaxValue.yang
@@ -0,0 +1,9 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ leaf-list invalid-interval {
+ type "uint16";
+ max-elements 77777777777777777777777;
+ }
+}
diff --git a/utils/yangutils/src/test/resources/MinElementsMaxValue.yang b/utils/yangutils/src/test/resources/MinElementsMaxValue.yang
new file mode 100644
index 0000000..785482b
--- /dev/null
+++ b/utils/yangutils/src/test/resources/MinElementsMaxValue.yang
@@ -0,0 +1,9 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ leaf-list invalid-interval {
+ type "uint16";
+ min-elements 77777777777777777777777;
+ }
+}
diff --git a/utils/yangutils/src/test/resources/PositionImplicitAndExplicit.yang b/utils/yangutils/src/test/resources/PositionImplicitAndExplicit.yang
index 5be4cbb..bef9712 100644
--- a/utils/yangutils/src/test/resources/PositionImplicitAndExplicit.yang
+++ b/utils/yangutils/src/test/resources/PositionImplicitAndExplicit.yang
@@ -2,14 +2,14 @@
yang-version 1;
namespace http://huawei.com;
prefix Ant;
- leaf mybits {
- type bits {
- bit disable-nagle;
- bit auto-sense-speed {
- position 1;
- }
- bit Ten-Mb-only;
- }
- }
+ leaf mybits {
+ type bits {
+ bit disable-nagle;
+ bit auto-sense-speed {
+ position 1;
+ }
+ bit Ten-Mb-only;
+ }
}
}
+
diff --git a/utils/yangutils/src/test/resources/PositionStatement.yang b/utils/yangutils/src/test/resources/PositionStatement.yang
index 76c204d..afa0a4c 100644
--- a/utils/yangutils/src/test/resources/PositionStatement.yang
+++ b/utils/yangutils/src/test/resources/PositionStatement.yang
@@ -2,17 +2,17 @@
yang-version 1;
namespace http://huawei.com;
prefix Ant;
- leaf mybits {
- type bits {
- bit disable-nagle {
- position 0;
- }
- bit auto-sense-speed {
- position 1;
- }
- bit Ten-Mb-only {
- position 2;
- }
- }
+ leaf mybits {
+ type bits {
+ bit disable-nagle {
+ position 0;
+ }
+ bit auto-sense-speed {
+ position 1;
+ }
+ bit Ten-Mb-only {
+ position 2;
+ }
+ }
}
}
diff --git a/utils/yangutils/src/test/resources/ProcessFileWithExtraBrace.yang b/utils/yangutils/src/test/resources/ProcessFileWithExtraBrace.yang
new file mode 100644
index 0000000..ca3f0d0
--- /dev/null
+++ b/utils/yangutils/src/test/resources/ProcessFileWithExtraBrace.yang
@@ -0,0 +1,15 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ container food {
+ choice snack {
+ list sports-arena {
+ }
+ }
+ }
+ }
+}
+}
+}
+}
diff --git a/utils/yangutils/src/test/resources/ProcessFileWithExtraBraceInBetween.yang b/utils/yangutils/src/test/resources/ProcessFileWithExtraBraceInBetween.yang
new file mode 100644
index 0000000..580d270
--- /dev/null
+++ b/utils/yangutils/src/test/resources/ProcessFileWithExtraBraceInBetween.yang
@@ -0,0 +1,35 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ import ietf-yang-types {
+ prefix "P";
+ }
+ grouping Percentage {
+ leaf hello{
+ type string;
+ }
+ leaf invalid1{
+ type string;
+ }
+ }
+ leaf invalid2{
+ type string;
+ }
+ }
+ container ospf {
+ list valid {
+ key "invalid";
+ leaf invalid{
+ type string;
+ }
+ uses Ant:FirstClass;
+ grouping FirstClass {
+ uses P:PassingClass;
+ }
+ }
+ grouping PassingClass {
+ uses Ant:Percentage;
+ }
+ }
+}
diff --git a/utils/yangutils/src/test/resources/ProcessFileWithExtraLeaf.yang b/utils/yangutils/src/test/resources/ProcessFileWithExtraLeaf.yang
new file mode 100644
index 0000000..5624b7a
--- /dev/null
+++ b/utils/yangutils/src/test/resources/ProcessFileWithExtraLeaf.yang
@@ -0,0 +1,13 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ container food {
+ choice snack {
+ list sports-arena {
+ }
+ }
+ }
+}
+leaf invalid {
+
diff --git a/utils/yangutils/src/test/resources/RangeStatementWithSpace.yang b/utils/yangutils/src/test/resources/RangeStatementWithSpace.yang
new file mode 100644
index 0000000..a41d68a
--- /dev/null
+++ b/utils/yangutils/src/test/resources/RangeStatementWithSpace.yang
@@ -0,0 +1,11 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ leaf invalid-interval {
+ type int32 {
+ range " 1 .. 4 | 10 .. 20 ";
+ }
+ }
+}
+
diff --git a/utils/yangutils/src/test/resources/ShortCaseListenerWithContainer.yang b/utils/yangutils/src/test/resources/ShortCaseListenerWithContainer.yang
index 166eeb0..3322a66 100644
--- a/utils/yangutils/src/test/resources/ShortCaseListenerWithContainer.yang
+++ b/utils/yangutils/src/test/resources/ShortCaseListenerWithContainer.yang
@@ -2,12 +2,11 @@
yang-version 1;
namespace http://huawei.com;
prefix Ant;
- container food {
- choice snack {
- container sports-arena {
- leaf pretzel {
- type empty;
- }
+ container food {
+ choice snack {
+ container sports-arena {
+ leaf pretzel {
+ type empty;
}
}
}
diff --git a/utils/yangutils/src/test/resources/ShortCaseListenerWithList.yang b/utils/yangutils/src/test/resources/ShortCaseListenerWithList.yang
index eb03fca..6eeec79 100644
--- a/utils/yangutils/src/test/resources/ShortCaseListenerWithList.yang
+++ b/utils/yangutils/src/test/resources/ShortCaseListenerWithList.yang
@@ -2,15 +2,15 @@
yang-version 1;
namespace http://huawei.com;
prefix Ant;
- container food {
- choice snack {
- list sports-arena {
- key "pretzel";
- leaf pretzel {
- type int32;
- }
+ container food {
+ choice snack {
+ list sports-arena {
+ key "pretzel";
+ leaf pretzel {
+ type int32;
}
}
}
}
}
+
diff --git a/utils/yangutils/src/test/resources/ValidNotificationStatement.yang b/utils/yangutils/src/test/resources/ValidNotificationStatement.yang
index 7e6bc17..1e0f144 100644
--- a/utils/yangutils/src/test/resources/ValidNotificationStatement.yang
+++ b/utils/yangutils/src/test/resources/ValidNotificationStatement.yang
@@ -14,7 +14,7 @@
type int32;
}
leaf if-name {
- type leafref;
+ type string;
}
leaf if-admin-status {
type P:admin-status;