Committed by
Ray Milkey
[ONOS-4563][ONOS-4564][ONOS-4551][ONOS-4538]defect fix
Change-Id: Ia3fe844e1e846d2e1d2c4359eefc815e7767aef9
Showing
24 changed files
with
360 additions
and
30 deletions
... | @@ -50,7 +50,7 @@ import org.onosproject.yangutils.utils.YangConstructType; | ... | @@ -50,7 +50,7 @@ import org.onosproject.yangutils.utils.YangConstructType; |
50 | /** | 50 | /** |
51 | * Represents the ENUM data type information. | 51 | * Represents the ENUM data type information. |
52 | */ | 52 | */ |
53 | -public class YangEnum implements YangCommonInfo, Parsable { | 53 | +public class YangEnum implements YangCommonInfo, Parsable, Comparable<YangEnum> { |
54 | 54 | ||
55 | /** | 55 | /** |
56 | * Named value for the ENUM. | 56 | * Named value for the ENUM. |
... | @@ -226,4 +226,12 @@ public class YangEnum implements YangCommonInfo, Parsable { | ... | @@ -226,4 +226,12 @@ public class YangEnum implements YangCommonInfo, Parsable { |
226 | public void validateDataOnExit() throws DataModelException { | 226 | public void validateDataOnExit() throws DataModelException { |
227 | // TODO auto-generated method stub, to be implemented by parser | 227 | // TODO auto-generated method stub, to be implemented by parser |
228 | } | 228 | } |
229 | + | ||
230 | + @Override | ||
231 | + public int compareTo(YangEnum otherEnum) { | ||
232 | + if (this.namedValue.equals(otherEnum.getNamedValue())) { | ||
233 | + return 0; | ||
234 | + } | ||
235 | + return new Integer(this.value).compareTo(otherEnum.getValue()); | ||
236 | + } | ||
229 | } | 237 | } | ... | ... |
... | @@ -16,8 +16,8 @@ | ... | @@ -16,8 +16,8 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.datamodel; | 17 | package org.onosproject.yangutils.datamodel; |
18 | 18 | ||
19 | -import java.util.HashSet; | 19 | +import java.util.SortedSet; |
20 | -import java.util.Set; | 20 | +import java.util.TreeSet; |
21 | 21 | ||
22 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | 22 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
23 | import org.onosproject.yangutils.parser.Parsable; | 23 | import org.onosproject.yangutils.parser.Parsable; |
... | @@ -34,7 +34,7 @@ import org.onosproject.yangutils.utils.YangConstructType; | ... | @@ -34,7 +34,7 @@ import org.onosproject.yangutils.utils.YangConstructType; |
34 | public class YangEnumeration extends YangNode implements Parsable, CollisionDetector { | 34 | public class YangEnumeration extends YangNode implements Parsable, CollisionDetector { |
35 | 35 | ||
36 | // Enumeration info set. | 36 | // Enumeration info set. |
37 | - private Set<YangEnum> enumSet; | 37 | + private SortedSet<YangEnum> enumSet; |
38 | 38 | ||
39 | // Enumeration name. | 39 | // Enumeration name. |
40 | private String name; | 40 | private String name; |
... | @@ -44,7 +44,7 @@ public class YangEnumeration extends YangNode implements Parsable, CollisionDete | ... | @@ -44,7 +44,7 @@ public class YangEnumeration extends YangNode implements Parsable, CollisionDete |
44 | */ | 44 | */ |
45 | public YangEnumeration() { | 45 | public YangEnumeration() { |
46 | super(YangNodeType.ENUMERATION_NODE); | 46 | super(YangNodeType.ENUMERATION_NODE); |
47 | - setEnumSet(new HashSet<YangEnum>()); | 47 | + setEnumSet(new TreeSet<YangEnum>()); |
48 | } | 48 | } |
49 | 49 | ||
50 | /** | 50 | /** |
... | @@ -52,7 +52,7 @@ public class YangEnumeration extends YangNode implements Parsable, CollisionDete | ... | @@ -52,7 +52,7 @@ public class YangEnumeration extends YangNode implements Parsable, CollisionDete |
52 | * | 52 | * |
53 | * @return the ENUM set | 53 | * @return the ENUM set |
54 | */ | 54 | */ |
55 | - public Set<YangEnum> getEnumSet() { | 55 | + public SortedSet<YangEnum> getEnumSet() { |
56 | return enumSet; | 56 | return enumSet; |
57 | } | 57 | } |
58 | 58 | ||
... | @@ -61,7 +61,7 @@ public class YangEnumeration extends YangNode implements Parsable, CollisionDete | ... | @@ -61,7 +61,7 @@ public class YangEnumeration extends YangNode implements Parsable, CollisionDete |
61 | * | 61 | * |
62 | * @param enumSet the ENUM set to set | 62 | * @param enumSet the ENUM set to set |
63 | */ | 63 | */ |
64 | - private void setEnumSet(Set<YangEnum> enumSet) { | 64 | + private void setEnumSet(SortedSet<YangEnum> enumSet) { |
65 | this.enumSet = enumSet; | 65 | this.enumSet = enumSet; |
66 | } | 66 | } |
67 | 67 | ... | ... |
... | @@ -21,6 +21,8 @@ import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | ... | @@ -21,6 +21,8 @@ import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
21 | import org.onosproject.yangutils.parser.Parsable; | 21 | import org.onosproject.yangutils.parser.Parsable; |
22 | import org.onosproject.yangutils.utils.YangConstructType; | 22 | import org.onosproject.yangutils.utils.YangConstructType; |
23 | 23 | ||
24 | +import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil; | ||
25 | + | ||
24 | /*- | 26 | /*- |
25 | * Reference RFC 6020. | 27 | * Reference RFC 6020. |
26 | * | 28 | * |
... | @@ -54,7 +56,7 @@ import org.onosproject.yangutils.utils.YangConstructType; | ... | @@ -54,7 +56,7 @@ import org.onosproject.yangutils.utils.YangConstructType; |
54 | /** | 56 | /** |
55 | * Represents data model node to maintain information defined in YANG typedef. | 57 | * Represents data model node to maintain information defined in YANG typedef. |
56 | */ | 58 | */ |
57 | -public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable, YangTypeHolder { | 59 | +public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable, YangTypeHolder, CollisionDetector { |
58 | 60 | ||
59 | /** | 61 | /** |
60 | * Default value in string, needs to be converted to the target object, | 62 | * Default value in string, needs to be converted to the target object, |
... | @@ -272,4 +274,18 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable, Y | ... | @@ -272,4 +274,18 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable, Y |
272 | public List<YangType<?>> getTypeList() { | 274 | public List<YangType<?>> getTypeList() { |
273 | return typeList; | 275 | return typeList; |
274 | } | 276 | } |
277 | + | ||
278 | + @Override | ||
279 | + public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException { | ||
280 | + // Asks helper to detect colliding child. | ||
281 | + detectCollidingChildUtil(identifierName, dataType, this); | ||
282 | + } | ||
283 | + | ||
284 | + @Override | ||
285 | + public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException { | ||
286 | + if (getName().equals(identifierName)) { | ||
287 | + throw new DataModelException("YANG file error: Duplicate input identifier detected, same as typedef \"" | ||
288 | + + getName() + "\""); | ||
289 | + } | ||
290 | + } | ||
275 | } | 291 | } | ... | ... |
... | @@ -34,6 +34,8 @@ import static org.onosproject.yangutils.linker.impl.ResolvableStatus.INTRA_FILE_ | ... | @@ -34,6 +34,8 @@ import static org.onosproject.yangutils.linker.impl.ResolvableStatus.INTRA_FILE_ |
34 | import static org.onosproject.yangutils.linker.impl.ResolvableStatus.LINKED; | 34 | import static org.onosproject.yangutils.linker.impl.ResolvableStatus.LINKED; |
35 | import static org.onosproject.yangutils.linker.impl.ResolvableStatus.RESOLVED; | 35 | import static org.onosproject.yangutils.linker.impl.ResolvableStatus.RESOLVED; |
36 | import static org.onosproject.yangutils.linker.impl.ResolvableStatus.UNRESOLVED; | 36 | import static org.onosproject.yangutils.linker.impl.ResolvableStatus.UNRESOLVED; |
37 | +import static org.onosproject.yangutils.utils.UtilConstants.TYPEDEF_LINKER_ERROR; | ||
38 | +import static org.onosproject.yangutils.utils.UtilConstants.GROUPING_LINKER_ERROR; | ||
37 | 39 | ||
38 | /** | 40 | /** |
39 | * Represents resolution object which will be resolved by linker. | 41 | * Represents resolution object which will be resolved by linker. |
... | @@ -180,9 +182,14 @@ public class YangResolutionInfo<T> implements LocationInfo { | ... | @@ -180,9 +182,14 @@ public class YangResolutionInfo<T> implements LocationInfo { |
180 | 182 | ||
181 | if (resolvable.getResolvableStatus() == UNRESOLVED) { | 183 | if (resolvable.getResolvableStatus() == UNRESOLVED) { |
182 | // If current entity is still not resolved, then linking/resolution has failed. | 184 | // If current entity is still not resolved, then linking/resolution has failed. |
185 | + String errorInfo; | ||
186 | + if (resolvable instanceof YangType) { | ||
187 | + errorInfo = TYPEDEF_LINKER_ERROR; | ||
188 | + } else { | ||
189 | + errorInfo = GROUPING_LINKER_ERROR; | ||
190 | + } | ||
183 | DataModelException dataModelException = | 191 | DataModelException dataModelException = |
184 | - new DataModelException("YANG file error: Unable to find base " | 192 | + new DataModelException(errorInfo); |
185 | - + "typedef/grouping for given type/uses"); | ||
186 | dataModelException.setLine(getLineNumber()); | 193 | dataModelException.setLine(getLineNumber()); |
187 | dataModelException.setCharPosition(getCharPosition()); | 194 | dataModelException.setCharPosition(getCharPosition()); |
188 | throw dataModelException; | 195 | throw dataModelException; | ... | ... |
... | @@ -45,6 +45,8 @@ import org.onosproject.yangutils.datamodel.YangBits; | ... | @@ -45,6 +45,8 @@ import org.onosproject.yangutils.datamodel.YangBits; |
45 | import org.onosproject.yangutils.datamodel.YangLeaf; | 45 | import org.onosproject.yangutils.datamodel.YangLeaf; |
46 | import org.onosproject.yangutils.datamodel.YangLeafList; | 46 | import org.onosproject.yangutils.datamodel.YangLeafList; |
47 | import org.onosproject.yangutils.datamodel.YangType; | 47 | import org.onosproject.yangutils.datamodel.YangType; |
48 | +import org.onosproject.yangutils.datamodel.YangTypeDef; | ||
49 | +import org.onosproject.yangutils.datamodel.YangUnion; | ||
48 | import org.onosproject.yangutils.parser.Parsable; | 50 | import org.onosproject.yangutils.parser.Parsable; |
49 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | 51 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; |
50 | import org.onosproject.yangutils.parser.exceptions.ParserException; | 52 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
... | @@ -101,6 +103,12 @@ public final class BitsListener { | ... | @@ -101,6 +103,12 @@ public final class BitsListener { |
101 | case LEAF_LIST_DATA: | 103 | case LEAF_LIST_DATA: |
102 | bitsNode.setBitsName(((YangLeafList) tmpData).getName()); | 104 | bitsNode.setBitsName(((YangLeafList) tmpData).getName()); |
103 | break; | 105 | break; |
106 | + case TYPEDEF_DATA: | ||
107 | + bitsNode.setBitsName(((YangTypeDef) tmpData).getName()); | ||
108 | + break; | ||
109 | + case UNION_DATA: | ||
110 | + bitsNode.setBitsName(((YangUnion) tmpData).getName()); | ||
111 | + break; | ||
104 | // TODO typedef, union, deviate. | 112 | // TODO typedef, union, deviate. |
105 | default: | 113 | default: |
106 | throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, TYPE_DATA, | 114 | throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, TYPE_DATA, | ... | ... |
... | @@ -106,7 +106,16 @@ public final class MaxElementsListener { | ... | @@ -106,7 +106,16 @@ public final class MaxElementsListener { |
106 | if (value.equals(UNBOUNDED_KEYWORD)) { | 106 | if (value.equals(UNBOUNDED_KEYWORD)) { |
107 | maxElementsValue = Integer.MAX_VALUE; | 107 | maxElementsValue = Integer.MAX_VALUE; |
108 | } else if (value.matches(POSITIVE_INTEGER_PATTERN)) { | 108 | } else if (value.matches(POSITIVE_INTEGER_PATTERN)) { |
109 | + try { | ||
109 | maxElementsValue = Integer.parseInt(value); | 110 | maxElementsValue = Integer.parseInt(value); |
111 | + } catch (NumberFormatException e) { | ||
112 | + ParserException parserException = new ParserException("YANG file error : " + | ||
113 | + YangConstructType.getYangConstructType(MAX_ELEMENT_DATA) + " value " + value + " is not " + | ||
114 | + "valid."); | ||
115 | + parserException.setLine(ctx.getStart().getLine()); | ||
116 | + parserException.setCharPosition(ctx.getStart().getCharPositionInLine()); | ||
117 | + throw parserException; | ||
118 | + } | ||
110 | } else { | 119 | } else { |
111 | ParserException parserException = new ParserException("YANG file error : " + | 120 | ParserException parserException = new ParserException("YANG file error : " + |
112 | YangConstructType.getYangConstructType(MAX_ELEMENT_DATA) + " value " + value + " is not " + | 121 | YangConstructType.getYangConstructType(MAX_ELEMENT_DATA) + " value " + value + " is not " + | ... | ... |
... | @@ -35,6 +35,7 @@ import org.onosproject.yangutils.parser.impl.TreeWalkListener; | ... | @@ -35,6 +35,7 @@ import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
35 | 35 | ||
36 | import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION; | 36 | import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION; |
37 | import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangTypeDefNode; | 37 | import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangTypeDefNode; |
38 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil; | ||
38 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; | 39 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; |
39 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; | 40 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; |
40 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage; | 41 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage; |
... | @@ -117,6 +118,11 @@ public final class TypeDefListener { | ... | @@ -117,6 +118,11 @@ public final class TypeDefListener { |
117 | // Validate sub statement cardinality. | 118 | // Validate sub statement cardinality. |
118 | validateSubStatementsCardinality(ctx); | 119 | validateSubStatementsCardinality(ctx); |
119 | 120 | ||
121 | + // Check for identifier collision | ||
122 | + int line = ctx.getStart().getLine(); | ||
123 | + int charPositionInLine = ctx.getStart().getCharPositionInLine(); | ||
124 | + detectCollidingChildUtil(listener, line, charPositionInLine, identifier, TYPEDEF_DATA); | ||
125 | + | ||
120 | /* | 126 | /* |
121 | * Create a derived type information, the base type must be set in type | 127 | * Create a derived type information, the base type must be set in type |
122 | * listener. | 128 | * listener. | ... | ... |
... | @@ -54,6 +54,7 @@ public final class ListenerUtil { | ... | @@ -54,6 +54,7 @@ public final class ListenerUtil { |
54 | private static final String DATE_PATTERN = "[0-9]{4}-([0-9]{2}|[0-9])-([0-9]{2}|[0-9])"; | 54 | private static final String DATE_PATTERN = "[0-9]{4}-([0-9]{2}|[0-9])-([0-9]{2}|[0-9])"; |
55 | private static final String NON_NEGATIVE_INTEGER_PATTERN = "[0-9]+"; | 55 | private static final String NON_NEGATIVE_INTEGER_PATTERN = "[0-9]+"; |
56 | private static final Pattern INTEGER_PATTERN = Pattern.compile("[-][0-9]+|[0-9]+"); | 56 | private static final Pattern INTEGER_PATTERN = Pattern.compile("[-][0-9]+|[0-9]+"); |
57 | + private static final String XML = "xml"; | ||
57 | private static final String ONE = "1"; | 58 | private static final String ONE = "1"; |
58 | private static final int IDENTIFIER_LENGTH = 64; | 59 | private static final int IDENTIFIER_LENGTH = 64; |
59 | private static final String DATE_FORMAT = "yyyy-MM-dd"; | 60 | private static final String DATE_FORMAT = "yyyy-MM-dd"; |
... | @@ -102,6 +103,10 @@ public final class ListenerUtil { | ... | @@ -102,6 +103,10 @@ public final class ListenerUtil { |
102 | parserException = new ParserException("YANG file error : " + | 103 | parserException = new ParserException("YANG file error : " + |
103 | YangConstructType.getYangConstructType(yangConstruct) + " name " + identifierString + " is not " + | 104 | YangConstructType.getYangConstructType(yangConstruct) + " name " + identifierString + " is not " + |
104 | "valid."); | 105 | "valid."); |
106 | + } else if (identifierString.toLowerCase().startsWith(XML)) { | ||
107 | + parserException = new ParserException("YANG file error : " + | ||
108 | + YangConstructType.getYangConstructType(yangConstruct) + " identifier " + identifierString + | ||
109 | + " must not start with (('X'|'x') ('M'|'m') ('L'|'l'))."); | ||
105 | } else { | 110 | } else { |
106 | return identifierString; | 111 | return identifierString; |
107 | } | 112 | } |
... | @@ -175,7 +180,18 @@ public final class ListenerUtil { | ... | @@ -175,7 +180,18 @@ public final class ListenerUtil { |
175 | throw parserException; | 180 | throw parserException; |
176 | } | 181 | } |
177 | 182 | ||
178 | - return Integer.parseInt(value); | 183 | + int valueInInteger; |
184 | + try { | ||
185 | + valueInInteger = Integer.parseInt(value); | ||
186 | + } catch (NumberFormatException e) { | ||
187 | + ParserException parserException = new ParserException("YANG file error : " + | ||
188 | + YangConstructType.getYangConstructType(yangConstruct) + " value " + value + " is not " + | ||
189 | + "valid."); | ||
190 | + parserException.setLine(ctx.getStart().getLine()); | ||
191 | + parserException.setCharPosition(ctx.getStart().getCharPositionInLine()); | ||
192 | + throw parserException; | ||
193 | + } | ||
194 | + return valueInInteger; | ||
179 | } | 195 | } |
180 | 196 | ||
181 | /** | 197 | /** | ... | ... |
utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java
... | @@ -251,8 +251,8 @@ public final class JavaCodeGeneratorUtil { | ... | @@ -251,8 +251,8 @@ public final class JavaCodeGeneratorUtil { |
251 | */ | 251 | */ |
252 | private static void close(YangNode node) | 252 | private static void close(YangNode node) |
253 | throws IOException { | 253 | throws IOException { |
254 | - | 254 | + if (node instanceof JavaCodeGenerator && ((TempJavaCodeFragmentFilesContainer) node) |
255 | - if (((TempJavaCodeFragmentFilesContainer) node).getTempJavaCodeFragmentFiles() != null) { | 255 | + .getTempJavaCodeFragmentFiles() != null) { |
256 | ((TempJavaCodeFragmentFilesContainer) node).getTempJavaCodeFragmentFiles().freeTemporaryResources(true); | 256 | ((TempJavaCodeFragmentFilesContainer) node).getTempJavaCodeFragmentFiles().freeTemporaryResources(true); |
257 | } | 257 | } |
258 | } | 258 | } | ... | ... |
utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java
... | @@ -1337,19 +1337,6 @@ public class TempJavaFragmentFiles { | ... | @@ -1337,19 +1337,6 @@ public class TempJavaFragmentFiles { |
1337 | */ | 1337 | */ |
1338 | if ((fileType & INTERFACE_MASK) != 0 || (fileType & | 1338 | if ((fileType & INTERFACE_MASK) != 0 || (fileType & |
1339 | BUILDER_INTERFACE_MASK) != 0) { | 1339 | BUILDER_INTERFACE_MASK) != 0) { |
1340 | - /* | ||
1341 | - * Adds import for case. | ||
1342 | - */ | ||
1343 | - if (curNode instanceof YangCase) { | ||
1344 | - List<String> importData = | ||
1345 | - ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() | ||
1346 | - .getBeanTempFiles().getJavaImportData().getImports(); | ||
1347 | - for (String importInfo : importData) { | ||
1348 | - if (!imports.contains(importInfo)) { | ||
1349 | - imports.add(importInfo); | ||
1350 | - } | ||
1351 | - } | ||
1352 | - } | ||
1353 | 1340 | ||
1354 | /* | 1341 | /* |
1355 | * Create interface file. | 1342 | * Create interface file. | ... | ... |
... | @@ -42,6 +42,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType. | ... | @@ -42,6 +42,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType. |
42 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; | 42 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; |
43 | import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.addCurNodeInfoInParentTempFile; | 43 | import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.addCurNodeInfoInParentTempFile; |
44 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | 44 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; |
45 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase; | ||
45 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage; | 46 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage; |
46 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; | 47 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; |
47 | import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION_HOLDER; | 48 | import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION_HOLDER; |
... | @@ -279,7 +280,7 @@ public final class YangJavaModelUtils { | ... | @@ -279,7 +280,7 @@ public final class YangJavaModelUtils { |
279 | if (javaCodeGeneratorInfo instanceof YangCase) { | 280 | if (javaCodeGeneratorInfo instanceof YangCase) { |
280 | YangNode parent = ((YangCase) javaCodeGeneratorInfo).getParent(); | 281 | YangNode parent = ((YangCase) javaCodeGeneratorInfo).getParent(); |
281 | JavaQualifiedTypeInfo parentsInfo = new JavaQualifiedTypeInfo(); | 282 | JavaQualifiedTypeInfo parentsInfo = new JavaQualifiedTypeInfo(); |
282 | - String parentName = ((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName(); | 283 | + String parentName = getCapitalCase(((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName()); |
283 | String parentPkg = ((JavaFileInfoContainer) parent).getJavaFileInfo().getPackage(); | 284 | String parentPkg = ((JavaFileInfoContainer) parent).getJavaFileInfo().getPackage(); |
284 | parentsInfo.setClassInfo(parentName); | 285 | parentsInfo.setClassInfo(parentName); |
285 | parentsInfo.setPkgInfo(parentPkg); | 286 | parentsInfo.setPkgInfo(parentPkg); | ... | ... |
... | @@ -1122,6 +1122,18 @@ public final class UtilConstants { | ... | @@ -1122,6 +1122,18 @@ public final class UtilConstants { |
1122 | " for YANG utils road map."; | 1122 | " for YANG utils road map."; |
1123 | 1123 | ||
1124 | /** | 1124 | /** |
1125 | + * Static attribute for typedef linker error information. | ||
1126 | + */ | ||
1127 | + public static final String TYPEDEF_LINKER_ERROR = "YANG file error: Unable to find base " | ||
1128 | + + "typedef for given type"; | ||
1129 | + | ||
1130 | + /** | ||
1131 | + * Static attribute for grouping linker error information. | ||
1132 | + */ | ||
1133 | + public static final String GROUPING_LINKER_ERROR = "YANG file error: Unable to find base " | ||
1134 | + + "grouping for given uses"; | ||
1135 | + | ||
1136 | + /** | ||
1125 | * Creates an instance of util constants. | 1137 | * Creates an instance of util constants. |
1126 | */ | 1138 | */ |
1127 | private UtilConstants() { | 1139 | private UtilConstants() { | ... | ... |
... | @@ -564,7 +564,7 @@ public class IntraFileUsesLinkingTest { | ... | @@ -564,7 +564,7 @@ public class IntraFileUsesLinkingTest { |
564 | 564 | ||
565 | thrown.expect(ParserException.class); | 565 | thrown.expect(ParserException.class); |
566 | thrown.expectMessage( | 566 | thrown.expectMessage( |
567 | - "YANG file error: Unable to find base typedef/grouping for given type/uses"); | 567 | + "YANG file error: Unable to find base grouping for given uses"); |
568 | 568 | ||
569 | YangNode node = manager | 569 | YangNode node = manager |
570 | .getDataModel("src/test/resources/SelfResolutionNestedGroupingWithUnresolvedUses.yang"); | 570 | .getDataModel("src/test/resources/SelfResolutionNestedGroupingWithUnresolvedUses.yang"); | ... | ... |
... | @@ -26,10 +26,14 @@ import org.onosproject.yangutils.datamodel.YangLeaf; | ... | @@ -26,10 +26,14 @@ import org.onosproject.yangutils.datamodel.YangLeaf; |
26 | import org.onosproject.yangutils.datamodel.YangModule; | 26 | import org.onosproject.yangutils.datamodel.YangModule; |
27 | import org.onosproject.yangutils.datamodel.YangNode; | 27 | import org.onosproject.yangutils.datamodel.YangNode; |
28 | import org.onosproject.yangutils.datamodel.YangNodeType; | 28 | import org.onosproject.yangutils.datamodel.YangNodeType; |
29 | +import org.onosproject.yangutils.datamodel.YangType; | ||
30 | +import org.onosproject.yangutils.datamodel.YangTypeDef; | ||
31 | +import org.onosproject.yangutils.datamodel.YangUnion; | ||
29 | import org.onosproject.yangutils.parser.exceptions.ParserException; | 32 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
30 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; | 33 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; |
31 | 34 | ||
32 | import java.io.IOException; | 35 | import java.io.IOException; |
36 | +import java.util.List; | ||
33 | import java.util.ListIterator; | 37 | import java.util.ListIterator; |
34 | import java.util.Set; | 38 | import java.util.Set; |
35 | 39 | ||
... | @@ -80,6 +84,84 @@ public class BitListenerTest { | ... | @@ -80,6 +84,84 @@ public class BitListenerTest { |
80 | } | 84 | } |
81 | 85 | ||
82 | /** | 86 | /** |
87 | + * Checks bit statement with typedef. | ||
88 | + */ | ||
89 | + @Test | ||
90 | + public void processBitTypedefStatement() throws IOException, ParserException { | ||
91 | + | ||
92 | + YangNode node = manager.getDataModel("src/test/resources/BitTypedefStatement.yang"); | ||
93 | + | ||
94 | + // Check whether the data model tree returned is of type module. | ||
95 | + assertThat((node instanceof YangModule), is(true)); | ||
96 | + | ||
97 | + // Check whether the node type is set properly to module. | ||
98 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
99 | + | ||
100 | + // Check whether the module name is set correctly. | ||
101 | + YangModule yangNode = (YangModule) node; | ||
102 | + assertThat(yangNode.getName(), is("Test")); | ||
103 | + | ||
104 | + YangTypeDef typedef = (YangTypeDef) yangNode.getChild(); | ||
105 | + assertThat(typedef.getName(), is("type15")); | ||
106 | + | ||
107 | + YangType type = typedef.getTypeList().iterator().next(); | ||
108 | + assertThat(type.getDataType(), is(YangDataTypes.BITS)); | ||
109 | + assertThat(type.getDataTypeName(), is("bits")); | ||
110 | + Set<YangBit> bitSet = ((YangBits) type.getDataTypeExtendedInfo()).getBitSet(); | ||
111 | + for (YangBit tmp : bitSet) { | ||
112 | + if (tmp.getBitName().equals("disable-nagle")) { | ||
113 | + assertThat(tmp.getPosition(), is(0)); | ||
114 | + } else if (tmp.getBitName().equals("auto-sense-speed")) { | ||
115 | + assertThat(tmp.getPosition(), is(1)); | ||
116 | + } | ||
117 | + } | ||
118 | + } | ||
119 | + | ||
120 | + /** | ||
121 | + * Checks bit statement with union. | ||
122 | + */ | ||
123 | + @Test | ||
124 | + public void processBitUnionStatement() throws IOException, ParserException { | ||
125 | + | ||
126 | + YangNode node = manager.getDataModel("src/test/resources/BitUnionStatement.yang"); | ||
127 | + | ||
128 | + // Check whether the data model tree returned is of type module. | ||
129 | + assertThat((node instanceof YangModule), is(true)); | ||
130 | + | ||
131 | + // Check whether the node type is set properly to module. | ||
132 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
133 | + | ||
134 | + // Check whether the module name is set correctly. | ||
135 | + YangModule yangNode = (YangModule) node; | ||
136 | + assertThat(yangNode.getName(), is("Test")); | ||
137 | + | ||
138 | + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); | ||
139 | + YangLeaf leafInfo = leafIterator.next(); | ||
140 | + | ||
141 | + assertThat(leafInfo.getName(), is("type15")); | ||
142 | + | ||
143 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UNION)); | ||
144 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("union")); | ||
145 | + | ||
146 | + YangUnion yangUnion = (YangUnion) leafInfo.getDataType().getDataTypeExtendedInfo(); | ||
147 | + | ||
148 | + List<YangType<?>> typeList = yangUnion.getTypeList(); | ||
149 | + ListIterator<YangType<?>> typeListIterator = typeList.listIterator(); | ||
150 | + YangType<?> yangType = typeListIterator.next(); | ||
151 | + | ||
152 | + assertThat(yangType.getDataType(), is(YangDataTypes.BITS)); | ||
153 | + assertThat(yangType.getDataTypeName(), is("bits")); | ||
154 | + Set<YangBit> bitSet = ((YangBits) yangType.getDataTypeExtendedInfo()).getBitSet(); | ||
155 | + for (YangBit tmp : bitSet) { | ||
156 | + if (tmp.getBitName().equals("disable-nagle")) { | ||
157 | + assertThat(tmp.getPosition(), is(0)); | ||
158 | + } else if (tmp.getBitName().equals("auto-sense-speed")) { | ||
159 | + assertThat(tmp.getPosition(), is(1)); | ||
160 | + } | ||
161 | + } | ||
162 | + } | ||
163 | + | ||
164 | + /** | ||
83 | * Checks if enum with same name is not allowed. | 165 | * Checks if enum with same name is not allowed. |
84 | */ | 166 | */ |
85 | @Test(expected = ParserException.class) | 167 | @Test(expected = ParserException.class) | ... | ... |
... | @@ -33,8 +33,9 @@ import org.onosproject.yangutils.parser.exceptions.ParserException; | ... | @@ -33,8 +33,9 @@ import org.onosproject.yangutils.parser.exceptions.ParserException; |
33 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; | 33 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; |
34 | 34 | ||
35 | import java.io.IOException; | 35 | import java.io.IOException; |
36 | +import java.util.Iterator; | ||
36 | import java.util.ListIterator; | 37 | import java.util.ListIterator; |
37 | -import java.util.Set; | 38 | +import java.util.SortedSet; |
38 | 39 | ||
39 | /** | 40 | /** |
40 | * Test cases for enum listener. | 41 | * Test cases for enum listener. |
... | @@ -73,7 +74,7 @@ public class EnumListenerTest { | ... | @@ -73,7 +74,7 @@ public class EnumListenerTest { |
73 | assertThat(((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getName(), | 74 | assertThat(((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getName(), |
74 | is("speed_enum")); | 75 | is("speed_enum")); |
75 | 76 | ||
76 | - Set<YangEnum> enumSet = ((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getEnumSet(); | 77 | + SortedSet<YangEnum> enumSet = ((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getEnumSet(); |
77 | for (YangEnum tmp : enumSet) { | 78 | for (YangEnum tmp : enumSet) { |
78 | if (tmp.getNamedValue().equals("10m")) { | 79 | if (tmp.getNamedValue().equals("10m")) { |
79 | assertThat(tmp.getValue(), is(0)); | 80 | assertThat(tmp.getValue(), is(0)); |
... | @@ -114,4 +115,34 @@ public class EnumListenerTest { | ... | @@ -114,4 +115,34 @@ public class EnumListenerTest { |
114 | + "with the current highest value"); | 115 | + "with the current highest value"); |
115 | YangNode node = manager.getDataModel("src/test/resources/EnumMaxNextValue.yang"); | 116 | YangNode node = manager.getDataModel("src/test/resources/EnumMaxNextValue.yang"); |
116 | } | 117 | } |
118 | + | ||
119 | + /** | ||
120 | + * Checks enum values stored are sorted. | ||
121 | + */ | ||
122 | + @Test | ||
123 | + public void processEnumSorted() throws IOException, ParserException { | ||
124 | + YangNode node = manager.getDataModel("src/test/resources/EnumSorted.yang"); | ||
125 | + // Check whether the data model tree returned is of type module. | ||
126 | + assertThat((node instanceof YangModule), is(true)); | ||
127 | + | ||
128 | + // Check whether the node type is set properly to module. | ||
129 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
130 | + | ||
131 | + // Check whether the module name is set correctly. | ||
132 | + YangModule yangNode = (YangModule) node; | ||
133 | + assertThat(yangNode.getName(), is("Test")); | ||
134 | + | ||
135 | + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); | ||
136 | + YangLeaf leafInfo = leafIterator.next(); | ||
137 | + | ||
138 | + assertThat(leafInfo.getName(), is("ifType")); | ||
139 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("enumeration")); | ||
140 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.ENUMERATION)); | ||
141 | + assertThat(((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getName(), | ||
142 | + is("ifType_enum")); | ||
143 | + | ||
144 | + SortedSet<YangEnum> enumSet = ((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getEnumSet(); | ||
145 | + Iterator<YangEnum> enumIterator = enumSet.iterator(); | ||
146 | + assertThat(enumIterator.next().getNamedValue(), is("five")); | ||
147 | + } | ||
117 | } | 148 | } | ... | ... |
... | @@ -176,4 +176,15 @@ public class MaxElementsListenerTest { | ... | @@ -176,4 +176,15 @@ public class MaxElementsListenerTest { |
176 | assertThat(leafListInfo.getName(), is("invalid-interval")); | 176 | assertThat(leafListInfo.getName(), is("invalid-interval")); |
177 | assertThat(leafListInfo.getMaxElelements(), is(2147483647)); | 177 | assertThat(leafListInfo.getMaxElelements(), is(2147483647)); |
178 | } | 178 | } |
179 | + | ||
180 | + /** | ||
181 | + * Checks whether exception is thrown when invalid min-elements value is | ||
182 | + * given as input. | ||
183 | + */ | ||
184 | + @Test | ||
185 | + public void processMaxElementsMaxValue() throws IOException, ParserException { | ||
186 | + thrown.expect(ParserException.class); | ||
187 | + thrown.expectMessage("YANG file error : max-elements value 77777777777777777777777 is not valid."); | ||
188 | + YangNode node = manager.getDataModel("src/test/resources/MaxElementsMaxValue.yang"); | ||
189 | + } | ||
179 | } | 190 | } | ... | ... |
... | @@ -116,6 +116,17 @@ public class MinElementsListenerTest { | ... | @@ -116,6 +116,17 @@ public class MinElementsListenerTest { |
116 | } | 116 | } |
117 | 117 | ||
118 | /** | 118 | /** |
119 | + * Checks whether exception is thrown when invalid min-elements value is | ||
120 | + * given as input. | ||
121 | + */ | ||
122 | + @Test | ||
123 | + public void processMinElementsMaxValue() throws IOException, ParserException { | ||
124 | + thrown.expect(ParserException.class); | ||
125 | + thrown.expectMessage("YANG file error : min-elements value 77777777777777777777777 is not valid."); | ||
126 | + YangNode node = manager.getDataModel("src/test/resources/MinElementsMaxValue.yang"); | ||
127 | + } | ||
128 | + | ||
129 | + /** | ||
119 | * Checks whether exception is thrown when min-elements statement without | 130 | * Checks whether exception is thrown when min-elements statement without |
120 | * statement end is given as input. | 131 | * statement end is given as input. |
121 | */ | 132 | */ | ... | ... |
utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/parseutils/ListenerUtilTest.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.yangutils.parser.impl.parseutils; | ||
18 | + | ||
19 | +import java.io.IOException; | ||
20 | +import org.junit.Rule; | ||
21 | +import org.junit.Test; | ||
22 | +import org.junit.rules.ExpectedException; | ||
23 | +import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
24 | +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; | ||
25 | + | ||
26 | +/** | ||
27 | + * Test case for testing listener util. | ||
28 | + */ | ||
29 | +public class ListenerUtilTest { | ||
30 | + | ||
31 | + @Rule | ||
32 | + public ExpectedException thrown = ExpectedException.none(); | ||
33 | + | ||
34 | + private final YangUtilsParserManager manager = new YangUtilsParserManager(); | ||
35 | + | ||
36 | + /** | ||
37 | + * Checks whether exception is thrown when identifier starts with xml. | ||
38 | + */ | ||
39 | + @Test | ||
40 | + public void validateIdentifierStartsWithXml() throws IOException { | ||
41 | + thrown.expect(ParserException.class); | ||
42 | + thrown.expectMessage("YANG file error : module identifier xMlTest must not start" + | ||
43 | + " with (('X'|'x') ('M'|'m') ('L'|'l'))"); | ||
44 | + manager.getDataModel("src/test/resources/InValidIdentifierXML.yang"); | ||
45 | + } | ||
46 | +} |
1 | +module Test { | ||
2 | + yang-version 1; | ||
3 | + namespace http://huawei.com; | ||
4 | + prefix Ant; | ||
5 | + leaf type15 { | ||
6 | + type union { | ||
7 | + type bits { | ||
8 | + bit disable-nagle { | ||
9 | + position 0; | ||
10 | + } | ||
11 | + bit auto-sense-speed { | ||
12 | + position 1; | ||
13 | + } | ||
14 | + bit Mb-only { | ||
15 | + position 2; | ||
16 | + } | ||
17 | + } | ||
18 | + } | ||
19 | + } | ||
20 | +} |
-
Please register or login to post a comment