Committed by
Gerrit Code Review
YANG uses and UT
Change-Id: Id3ec5cfed2b8e2a7d2d580786c70b5804f03ecfa
Showing
30 changed files
with
1252 additions
and
113 deletions
... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
16 | package org.onosproject.yangutils.datamodel; | 16 | package org.onosproject.yangutils.datamodel; |
17 | 17 | ||
18 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | 18 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
19 | +import org.onosproject.yangutils.parser.Parsable; | ||
19 | import org.onosproject.yangutils.translator.tojava.TraversalType; | 20 | import org.onosproject.yangutils.translator.tojava.TraversalType; |
20 | 21 | ||
21 | import static org.onosproject.yangutils.translator.tojava.TraversalType.CHILD; | 22 | import static org.onosproject.yangutils.translator.tojava.TraversalType.CHILD; |
... | @@ -281,9 +282,11 @@ public abstract class YangNode | ... | @@ -281,9 +282,11 @@ public abstract class YangNode |
281 | if (nextNodeToClone == null) { | 282 | if (nextNodeToClone == null) { |
282 | throw new DataModelException("Internal error: Cloning failed, source tree null pointer reached"); | 283 | throw new DataModelException("Internal error: Cloning failed, source tree null pointer reached"); |
283 | } | 284 | } |
284 | - | 285 | + if (curTraversal != PARENT) { |
285 | - if (curTraversal == CHILD) { | ||
286 | newNode = nextNodeToClone.clone(); | 286 | newNode = nextNodeToClone.clone(); |
287 | + detectCollisionWhileCloning(clonedTreeCurNode, newNode, curTraversal); | ||
288 | + } | ||
289 | + if (curTraversal == CHILD) { | ||
287 | 290 | ||
288 | /** | 291 | /** |
289 | * add the new node to the cloned tree. | 292 | * add the new node to the cloned tree. |
... | @@ -295,7 +298,6 @@ public abstract class YangNode | ... | @@ -295,7 +298,6 @@ public abstract class YangNode |
295 | */ | 298 | */ |
296 | clonedTreeCurNode = newNode; | 299 | clonedTreeCurNode = newNode; |
297 | } else if (curTraversal == SIBILING) { | 300 | } else if (curTraversal == SIBILING) { |
298 | - newNode = nextNodeToClone.clone(); | ||
299 | 301 | ||
300 | clonedTreeCurNode.addNextSibling(newNode); | 302 | clonedTreeCurNode.addNextSibling(newNode); |
301 | clonedTreeCurNode = newNode; | 303 | clonedTreeCurNode = newNode; |
... | @@ -328,6 +330,38 @@ public abstract class YangNode | ... | @@ -328,6 +330,38 @@ public abstract class YangNode |
328 | } | 330 | } |
329 | 331 | ||
330 | /** | 332 | /** |
333 | + * Detects collision when the grouping is deep copied to the uses's parent. | ||
334 | + * | ||
335 | + * @param currentNode parent/previous sibling node for the new node | ||
336 | + * @param newNode node which has to be added | ||
337 | + * @param addAs traversal type of the node | ||
338 | + * @throws DataModelException data model error | ||
339 | + */ | ||
340 | + private static void detectCollisionWhileCloning(YangNode currentNode, YangNode newNode, TraversalType addAs) | ||
341 | + throws DataModelException { | ||
342 | + if ((!(currentNode instanceof CollisionDetector)) | ||
343 | + || (!(newNode instanceof Parsable))) { | ||
344 | + throw new DataModelException("Node in data model tree does not support collision detection"); | ||
345 | + } | ||
346 | + | ||
347 | + CollisionDetector collisionDetector = (CollisionDetector) currentNode; | ||
348 | + Parsable parsable = (Parsable) newNode; | ||
349 | + if (addAs == TraversalType.CHILD) { | ||
350 | + collisionDetector.detectCollidingChild(newNode.getName(), parsable.getYangConstructType()); | ||
351 | + } else if (addAs == TraversalType.SIBILING) { | ||
352 | + currentNode = currentNode.getParent(); | ||
353 | + if (!(currentNode instanceof CollisionDetector)) { | ||
354 | + throw new DataModelException("Node in data model tree does not support collision detection"); | ||
355 | + } | ||
356 | + collisionDetector = (CollisionDetector) currentNode; | ||
357 | + collisionDetector.detectCollidingChild(newNode.getName(), parsable.getYangConstructType()); | ||
358 | + } else { | ||
359 | + throw new DataModelException("Errored tree cloning"); | ||
360 | + } | ||
361 | + | ||
362 | + } | ||
363 | + | ||
364 | + /** | ||
331 | * Add a new next sibling. | 365 | * Add a new next sibling. |
332 | * | 366 | * |
333 | * @param newSibling new sibling to be added | 367 | * @param newSibling new sibling to be added | ... | ... |
... | @@ -19,6 +19,7 @@ import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | ... | @@ -19,6 +19,7 @@ import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
19 | import org.onosproject.yangutils.parser.Parsable; | 19 | import org.onosproject.yangutils.parser.Parsable; |
20 | import org.onosproject.yangutils.utils.YangConstructType; | 20 | import org.onosproject.yangutils.utils.YangConstructType; |
21 | 21 | ||
22 | +import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil; | ||
22 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getParentNodeInGenCode; | 23 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getParentNodeInGenCode; |
23 | 24 | ||
24 | /*- | 25 | /*- |
... | @@ -56,7 +57,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSy | ... | @@ -56,7 +57,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSy |
56 | */ | 57 | */ |
57 | public class YangUses | 58 | public class YangUses |
58 | extends YangNode | 59 | extends YangNode |
59 | - implements YangCommonInfo, Parsable, Resolvable { | 60 | + implements YangCommonInfo, Parsable, Resolvable, CollisionDetector { |
60 | 61 | ||
61 | /** | 62 | /** |
62 | * YANG node identifier. | 63 | * YANG node identifier. |
... | @@ -267,18 +268,23 @@ public class YangUses | ... | @@ -267,18 +268,23 @@ public class YangUses |
267 | } | 268 | } |
268 | 269 | ||
269 | YangNode usesParentNode = getParentNodeInGenCode(this); | 270 | YangNode usesParentNode = getParentNodeInGenCode(this); |
270 | - if (!(usesParentNode instanceof YangLeavesHolder)) { | 271 | + if ((!(usesParentNode instanceof YangLeavesHolder)) |
272 | + || (!(usesParentNode instanceof CollisionDetector))) { | ||
271 | throw new DataModelException("YANG uses holder construct is wrong"); | 273 | throw new DataModelException("YANG uses holder construct is wrong"); |
272 | } | 274 | } |
273 | 275 | ||
274 | YangLeavesHolder usesParentLeavesHolder = (YangLeavesHolder) usesParentNode; | 276 | YangLeavesHolder usesParentLeavesHolder = (YangLeavesHolder) usesParentNode; |
275 | if (referredGrouping.getListOfLeaf() != null) { | 277 | if (referredGrouping.getListOfLeaf() != null) { |
276 | for (YangLeaf leaf : referredGrouping.getListOfLeaf()) { | 278 | for (YangLeaf leaf : referredGrouping.getListOfLeaf()) { |
279 | + ((CollisionDetector) usesParentLeavesHolder).detectCollidingChild(leaf.getLeafName(), | ||
280 | + YangConstructType.LEAF_DATA); | ||
277 | usesParentLeavesHolder.addLeaf(leaf); | 281 | usesParentLeavesHolder.addLeaf(leaf); |
278 | } | 282 | } |
279 | } | 283 | } |
280 | if (referredGrouping.getListOfLeafList() != null) { | 284 | if (referredGrouping.getListOfLeafList() != null) { |
281 | for (YangLeafList leafList : referredGrouping.getListOfLeafList()) { | 285 | for (YangLeafList leafList : referredGrouping.getListOfLeafList()) { |
286 | + ((CollisionDetector) usesParentLeavesHolder).detectCollidingChild(leafList.getLeafName(), | ||
287 | + YangConstructType.LEAF_LIST_DATA); | ||
282 | usesParentLeavesHolder.addLeafList(leafList); | 288 | usesParentLeavesHolder.addLeafList(leafList); |
283 | } | 289 | } |
284 | } | 290 | } |
... | @@ -295,4 +301,19 @@ public class YangUses | ... | @@ -295,4 +301,19 @@ public class YangUses |
295 | public void setResolvableStatus(ResolvableStatus resolvableStatus) { | 301 | public void setResolvableStatus(ResolvableStatus resolvableStatus) { |
296 | this.resolvableStatus = resolvableStatus; | 302 | this.resolvableStatus = resolvableStatus; |
297 | } | 303 | } |
304 | + | ||
305 | + @Override | ||
306 | + public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException { | ||
307 | + detectCollidingChildUtil(identifierName, dataType, this); | ||
308 | + } | ||
309 | + | ||
310 | + @Override | ||
311 | + public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException { | ||
312 | + | ||
313 | + if (getName().equals(identifierName)) { | ||
314 | + throw new DataModelException("YANG file error: Duplicate input identifier detected, same as uses \"" | ||
315 | + + getName() + "\""); | ||
316 | + } | ||
317 | + } | ||
318 | + | ||
298 | } | 319 | } | ... | ... |
... | @@ -27,9 +27,9 @@ import org.onosproject.yangutils.datamodel.YangLeavesHolder; | ... | @@ -27,9 +27,9 @@ import org.onosproject.yangutils.datamodel.YangLeavesHolder; |
27 | import org.onosproject.yangutils.datamodel.YangNode; | 27 | import org.onosproject.yangutils.datamodel.YangNode; |
28 | import org.onosproject.yangutils.datamodel.YangResolutionInfo; | 28 | import org.onosproject.yangutils.datamodel.YangResolutionInfo; |
29 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | 29 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
30 | +import org.onosproject.yangutils.parser.Parsable; | ||
30 | import org.onosproject.yangutils.utils.YangConstructType; | 31 | import org.onosproject.yangutils.utils.YangConstructType; |
31 | 32 | ||
32 | - | ||
33 | /** | 33 | /** |
34 | * Represents utilities for data model tree. | 34 | * Represents utilities for data model tree. |
35 | */ | 35 | */ |
... | @@ -53,21 +53,44 @@ public final class DataModelUtils { | ... | @@ -53,21 +53,44 @@ public final class DataModelUtils { |
53 | public static void detectCollidingChildUtil(String identifierName, YangConstructType dataType, YangNode node) | 53 | public static void detectCollidingChildUtil(String identifierName, YangConstructType dataType, YangNode node) |
54 | throws DataModelException { | 54 | throws DataModelException { |
55 | 55 | ||
56 | - if (dataType == YangConstructType.LEAF_DATA) { | 56 | + if (dataType == YangConstructType.USES_DATA || dataType == YangConstructType.GROUPING_DATA) { |
57 | + detectCollidingForUsesGrouping(identifierName, dataType, node); | ||
58 | + } else { | ||
59 | + if (node instanceof YangLeavesHolder) { | ||
57 | YangLeavesHolder leavesHolder = (YangLeavesHolder) node; | 60 | YangLeavesHolder leavesHolder = (YangLeavesHolder) node; |
58 | - if (leavesHolder.getListOfLeaf() != null) { | 61 | + detectCollidingLeaf(leavesHolder.getListOfLeaf(), identifierName); |
59 | - detectCollidingLeaf(leavesHolder, identifierName); | 62 | + detectCollidingLeafList(leavesHolder.getListOfLeafList(), identifierName); |
60 | } | 63 | } |
64 | + node = node.getChild(); | ||
65 | + while (node != null) { | ||
66 | + Parsable parsable = (Parsable) node; | ||
67 | + if (node instanceof CollisionDetector | ||
68 | + && (parsable.getYangConstructType() != YangConstructType.USES_DATA) | ||
69 | + && (parsable.getYangConstructType() != YangConstructType.GROUPING_DATA)) { | ||
70 | + ((CollisionDetector) node).detectSelfCollision(identifierName, dataType); | ||
61 | } | 71 | } |
62 | - if (dataType == YangConstructType.LEAF_LIST_DATA) { | 72 | + node = node.getNextSibling(); |
63 | - if (((YangLeavesHolder) node).getListOfLeafList() != null) { | ||
64 | - YangLeavesHolder leavesHolder = (YangLeavesHolder) node; | ||
65 | - detectCollidingLeafList(leavesHolder, identifierName); | ||
66 | } | 73 | } |
67 | } | 74 | } |
75 | + } | ||
76 | + | ||
77 | + /** | ||
78 | + * Detects colliding of uses and grouping only with uses and grouping respectively. | ||
79 | + * | ||
80 | + * @param identifierName name for which collision detection is to be | ||
81 | + * checked | ||
82 | + * @param dataType type of YANG node asking for detecting collision | ||
83 | + * @param node node instance of calling node | ||
84 | + * @throws DataModelException a violation of data model rules | ||
85 | + */ | ||
86 | + public static void detectCollidingForUsesGrouping(String identifierName, YangConstructType dataType, YangNode node) | ||
87 | + throws DataModelException { | ||
88 | + | ||
68 | node = node.getChild(); | 89 | node = node.getChild(); |
69 | while (node != null) { | 90 | while (node != null) { |
70 | - if (node instanceof CollisionDetector) { | 91 | + Parsable parsable = (Parsable) node; |
92 | + if (node instanceof CollisionDetector | ||
93 | + && (parsable.getYangConstructType() == dataType)) { | ||
71 | ((CollisionDetector) node).detectSelfCollision(identifierName, dataType); | 94 | ((CollisionDetector) node).detectSelfCollision(identifierName, dataType); |
72 | } | 95 | } |
73 | node = node.getNextSibling(); | 96 | node = node.getNextSibling(); |
... | @@ -77,15 +100,18 @@ public final class DataModelUtils { | ... | @@ -77,15 +100,18 @@ public final class DataModelUtils { |
77 | /** | 100 | /** |
78 | * Detects the colliding identifier name in a given leaf node. | 101 | * Detects the colliding identifier name in a given leaf node. |
79 | * | 102 | * |
80 | - * @param leavesHolder leaves node against which collision to be checked | 103 | + * @param listOfLeaf List of leaves to detect collision |
81 | * @param identifierName name for which collision detection is to be | 104 | * @param identifierName name for which collision detection is to be |
82 | * checked | 105 | * checked |
83 | * @throws DataModelException a violation of data model rules | 106 | * @throws DataModelException a violation of data model rules |
84 | */ | 107 | */ |
85 | - private static void detectCollidingLeaf(YangLeavesHolder leavesHolder, String identifierName) | 108 | + private static void detectCollidingLeaf(List<YangLeaf> listOfLeaf, String identifierName) |
86 | throws DataModelException { | 109 | throws DataModelException { |
87 | 110 | ||
88 | - for (YangLeaf leaf : leavesHolder.getListOfLeaf()) { | 111 | + if (listOfLeaf == null) { |
112 | + return; | ||
113 | + } | ||
114 | + for (YangLeaf leaf : listOfLeaf) { | ||
89 | if (leaf.getLeafName().equals(identifierName)) { | 115 | if (leaf.getLeafName().equals(identifierName)) { |
90 | throw new DataModelException("YANG file error: Duplicate input identifier detected, same as leaf \"" | 116 | throw new DataModelException("YANG file error: Duplicate input identifier detected, same as leaf \"" |
91 | + leaf.getLeafName() + "\""); | 117 | + leaf.getLeafName() + "\""); |
... | @@ -96,15 +122,18 @@ public final class DataModelUtils { | ... | @@ -96,15 +122,18 @@ public final class DataModelUtils { |
96 | /** | 122 | /** |
97 | * Detects the colliding identifier name in a given leaf-list node. | 123 | * Detects the colliding identifier name in a given leaf-list node. |
98 | * | 124 | * |
99 | - * @param leavesHolder leaves node against which collision to be checked | 125 | + * @param listOfLeafList list of leaf-lists to detect collision |
100 | * @param identifierName name for which collision detection is to be | 126 | * @param identifierName name for which collision detection is to be |
101 | * checked | 127 | * checked |
102 | * @throws DataModelException a violation of data model rules | 128 | * @throws DataModelException a violation of data model rules |
103 | */ | 129 | */ |
104 | - private static void detectCollidingLeafList(YangLeavesHolder leavesHolder, String identifierName) | 130 | + private static void detectCollidingLeafList(List<YangLeafList> listOfLeafList, String identifierName) |
105 | throws DataModelException { | 131 | throws DataModelException { |
106 | 132 | ||
107 | - for (YangLeafList leafList : leavesHolder.getListOfLeafList()) { | 133 | + if (listOfLeafList == null) { |
134 | + return; | ||
135 | + } | ||
136 | + for (YangLeafList leafList : listOfLeafList) { | ||
108 | if (leafList.getLeafName().equals(identifierName)) { | 137 | if (leafList.getLeafName().equals(identifierName)) { |
109 | throw new DataModelException("YANG file error: Duplicate input identifier detected, same as leaf " + | 138 | throw new DataModelException("YANG file error: Duplicate input identifier detected, same as leaf " + |
110 | "list \"" + leafList.getLeafName() + "\""); | 139 | "list \"" + leafList.getLeafName() + "\""); |
... | @@ -122,8 +151,6 @@ public final class DataModelUtils { | ... | @@ -122,8 +151,6 @@ public final class DataModelUtils { |
122 | public static void addResolutionInfo(YangResolutionInfo resolutionInfo) | 151 | public static void addResolutionInfo(YangResolutionInfo resolutionInfo) |
123 | throws DataModelException { | 152 | throws DataModelException { |
124 | 153 | ||
125 | - | ||
126 | - | ||
127 | /* get the module node to add maintain the list of nested reference */ | 154 | /* get the module node to add maintain the list of nested reference */ |
128 | YangNode curNode = resolutionInfo.getEntityToResolveInfo() | 155 | YangNode curNode = resolutionInfo.getEntityToResolveInfo() |
129 | .getHolderOfEntityToResolve(); | 156 | .getHolderOfEntityToResolve(); |
... | @@ -142,6 +169,13 @@ public final class DataModelUtils { | ... | @@ -142,6 +169,13 @@ public final class DataModelUtils { |
142 | resolutionNode.addToResolutionList(resolutionInfo); | 169 | resolutionNode.addToResolutionList(resolutionInfo); |
143 | } | 170 | } |
144 | 171 | ||
172 | + /** | ||
173 | + * Evaluates whether the prefix in uses/type is valid. | ||
174 | + * | ||
175 | + * @param entityPrefix prefix in the current module/sub-module | ||
176 | + * @param resolutionNode uses/type node which has the prefix with it | ||
177 | + * @return whether prefix is valid or not | ||
178 | + */ | ||
145 | private static boolean isPrefixValid(String entityPrefix, HasResolutionInfo resolutionNode) { | 179 | private static boolean isPrefixValid(String entityPrefix, HasResolutionInfo resolutionNode) { |
146 | if (entityPrefix == null) { | 180 | if (entityPrefix == null) { |
147 | return true; | 181 | return true; | ... | ... |
... | @@ -1565,22 +1565,6 @@ public interface GeneratedYangListener extends ParseTreeListener { | ... | @@ -1565,22 +1565,6 @@ public interface GeneratedYangListener extends ParseTreeListener { |
1565 | 1565 | ||
1566 | /** | 1566 | /** |
1567 | * Enter a parse tree produced by GeneratedYangParser for grammar rule | 1567 | * Enter a parse tree produced by GeneratedYangParser for grammar rule |
1568 | - * inputStatementBody. | ||
1569 | - * | ||
1570 | - * @param currentContext current context in the parsed tree | ||
1571 | - */ | ||
1572 | - void enterInputStatementBody(GeneratedYangParser.InputStatementBodyContext currentContext); | ||
1573 | - | ||
1574 | - /** | ||
1575 | - * Exit a parse tree produced by GeneratedYangParser for grammar rule | ||
1576 | - * inputStatementBody. | ||
1577 | - * | ||
1578 | - * @param currentContext current context in the parsed tree | ||
1579 | - */ | ||
1580 | - void exitInputStatementBody(GeneratedYangParser.InputStatementBodyContext currentContext); | ||
1581 | - | ||
1582 | - /** | ||
1583 | - * Enter a parse tree produced by GeneratedYangParser for grammar rule | ||
1584 | * outputStatement. | 1568 | * outputStatement. |
1585 | * | 1569 | * |
1586 | * @param currentContext current context in the parsed tree | 1570 | * @param currentContext current context in the parsed tree |
... | @@ -1597,22 +1581,6 @@ public interface GeneratedYangListener extends ParseTreeListener { | ... | @@ -1597,22 +1581,6 @@ public interface GeneratedYangListener extends ParseTreeListener { |
1597 | 1581 | ||
1598 | /** | 1582 | /** |
1599 | * Enter a parse tree produced by GeneratedYangParser for grammar rule | 1583 | * Enter a parse tree produced by GeneratedYangParser for grammar rule |
1600 | - * outputStatementBody. | ||
1601 | - * | ||
1602 | - * @param currentContext current context in the parsed tree | ||
1603 | - */ | ||
1604 | - void enterOutputStatementBody(GeneratedYangParser.OutputStatementBodyContext currentContext); | ||
1605 | - | ||
1606 | - /** | ||
1607 | - * Exit a parse tree produced by GeneratedYangParser for grammar rule | ||
1608 | - * outputStatementBody. | ||
1609 | - * | ||
1610 | - * @param currentContext current context in the parsed tree | ||
1611 | - */ | ||
1612 | - void exitOutputStatementBody(GeneratedYangParser.OutputStatementBodyContext currentContext); | ||
1613 | - | ||
1614 | - /** | ||
1615 | - * Enter a parse tree produced by GeneratedYangParser for grammar rule | ||
1616 | * notificationStatement. | 1584 | * notificationStatement. |
1617 | * | 1585 | * |
1618 | * @param currentContext current context in the parsed tree | 1586 | * @param currentContext current context in the parsed tree | ... | ... |
... | @@ -52,8 +52,8 @@ import org.onosproject.yangutils.parser.impl.listeners.MandatoryListener; | ... | @@ -52,8 +52,8 @@ import org.onosproject.yangutils.parser.impl.listeners.MandatoryListener; |
52 | import org.onosproject.yangutils.parser.impl.listeners.MaxElementsListener; | 52 | import org.onosproject.yangutils.parser.impl.listeners.MaxElementsListener; |
53 | import org.onosproject.yangutils.parser.impl.listeners.MinElementsListener; | 53 | import org.onosproject.yangutils.parser.impl.listeners.MinElementsListener; |
54 | import org.onosproject.yangutils.parser.impl.listeners.ModuleListener; | 54 | import org.onosproject.yangutils.parser.impl.listeners.ModuleListener; |
55 | -import org.onosproject.yangutils.parser.impl.listeners.NotificationListener; | ||
56 | import org.onosproject.yangutils.parser.impl.listeners.NamespaceListener; | 55 | import org.onosproject.yangutils.parser.impl.listeners.NamespaceListener; |
56 | +import org.onosproject.yangutils.parser.impl.listeners.NotificationListener; | ||
57 | import org.onosproject.yangutils.parser.impl.listeners.OrganizationListener; | 57 | import org.onosproject.yangutils.parser.impl.listeners.OrganizationListener; |
58 | import org.onosproject.yangutils.parser.impl.listeners.OutputListener; | 58 | import org.onosproject.yangutils.parser.impl.listeners.OutputListener; |
59 | import org.onosproject.yangutils.parser.impl.listeners.PatternRestrictionListener; | 59 | import org.onosproject.yangutils.parser.impl.listeners.PatternRestrictionListener; |
... | @@ -1087,14 +1087,6 @@ public class TreeWalkListener implements GeneratedYangListener { | ... | @@ -1087,14 +1087,6 @@ public class TreeWalkListener implements GeneratedYangListener { |
1087 | } | 1087 | } |
1088 | 1088 | ||
1089 | @Override | 1089 | @Override |
1090 | - public void enterInputStatementBody(GeneratedYangParser.InputStatementBodyContext ctx) { | ||
1091 | - } | ||
1092 | - | ||
1093 | - @Override | ||
1094 | - public void exitInputStatementBody(GeneratedYangParser.InputStatementBodyContext ctx) { | ||
1095 | - } | ||
1096 | - | ||
1097 | - @Override | ||
1098 | public void enterOutputStatement(GeneratedYangParser.OutputStatementContext ctx) { | 1090 | public void enterOutputStatement(GeneratedYangParser.OutputStatementContext ctx) { |
1099 | OutputListener.processOutputEntry(this, ctx); | 1091 | OutputListener.processOutputEntry(this, ctx); |
1100 | } | 1092 | } |
... | @@ -1105,14 +1097,6 @@ public class TreeWalkListener implements GeneratedYangListener { | ... | @@ -1105,14 +1097,6 @@ public class TreeWalkListener implements GeneratedYangListener { |
1105 | } | 1097 | } |
1106 | 1098 | ||
1107 | @Override | 1099 | @Override |
1108 | - public void enterOutputStatementBody(GeneratedYangParser.OutputStatementBodyContext ctx) { | ||
1109 | - } | ||
1110 | - | ||
1111 | - @Override | ||
1112 | - public void exitOutputStatementBody(GeneratedYangParser.OutputStatementBodyContext ctx) { | ||
1113 | - } | ||
1114 | - | ||
1115 | - @Override | ||
1116 | public void enterNotificationStatement(GeneratedYangParser.NotificationStatementContext ctx) { | 1100 | public void enterNotificationStatement(GeneratedYangParser.NotificationStatementContext ctx) { |
1117 | NotificationListener.processNotificationEntry(this, ctx); | 1101 | NotificationListener.processNotificationEntry(this, ctx); |
1118 | } | 1102 | } | ... | ... |
... | @@ -46,12 +46,10 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp | ... | @@ -46,12 +46,10 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp |
46 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; | 46 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; |
47 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; | 47 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; |
48 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne; | 48 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne; |
49 | -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateMutuallyExclusiveChilds; | ||
50 | import static org.onosproject.yangutils.utils.YangConstructType.DESCRIPTION_DATA; | 49 | import static org.onosproject.yangutils.utils.YangConstructType.DESCRIPTION_DATA; |
51 | import static org.onosproject.yangutils.utils.YangConstructType.GROUPING_DATA; | 50 | import static org.onosproject.yangutils.utils.YangConstructType.GROUPING_DATA; |
52 | import static org.onosproject.yangutils.utils.YangConstructType.REFERENCE_DATA; | 51 | import static org.onosproject.yangutils.utils.YangConstructType.REFERENCE_DATA; |
53 | import static org.onosproject.yangutils.utils.YangConstructType.STATUS_DATA; | 52 | import static org.onosproject.yangutils.utils.YangConstructType.STATUS_DATA; |
54 | -import static org.onosproject.yangutils.utils.YangConstructType.TYPEDEF_DATA; | ||
55 | 53 | ||
56 | /* | 54 | /* |
57 | * Reference: RFC6020 and YANG ANTLR Grammar | 55 | * Reference: RFC6020 and YANG ANTLR Grammar |
... | @@ -168,7 +166,5 @@ public final class GroupingListener { | ... | @@ -168,7 +166,5 @@ public final class GroupingListener { |
168 | validateCardinalityMaxOne(ctx.descriptionStatement(), DESCRIPTION_DATA, GROUPING_DATA, | 166 | validateCardinalityMaxOne(ctx.descriptionStatement(), DESCRIPTION_DATA, GROUPING_DATA, |
169 | ctx.identifier().getText()); | 167 | ctx.identifier().getText()); |
170 | validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, GROUPING_DATA, ctx.identifier().getText()); | 168 | validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, GROUPING_DATA, ctx.identifier().getText()); |
171 | - validateMutuallyExclusiveChilds(ctx.typedefStatement(), TYPEDEF_DATA, ctx.groupingStatement(), GROUPING_DATA, | ||
172 | - GROUPING_DATA, ctx.identifier().getText()); | ||
173 | } | 169 | } |
174 | } | 170 | } | ... | ... |
... | @@ -36,6 +36,8 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp | ... | @@ -36,6 +36,8 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp |
36 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; | 36 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; |
37 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA; | 37 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA; |
38 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; | 38 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; |
39 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityNonZero; | ||
40 | +import static org.onosproject.yangutils.utils.YangConstructType.DATA_DEF_DATA; | ||
39 | import static org.onosproject.yangutils.utils.YangConstructType.INPUT_DATA; | 41 | import static org.onosproject.yangutils.utils.YangConstructType.INPUT_DATA; |
40 | 42 | ||
41 | /* | 43 | /* |
... | @@ -86,6 +88,9 @@ public final class InputListener { | ... | @@ -86,6 +88,9 @@ public final class InputListener { |
86 | // Check for stack to be non empty. | 88 | // Check for stack to be non empty. |
87 | checkStackIsNotEmpty(listener, MISSING_HOLDER, INPUT_DATA, "", ENTRY); | 89 | checkStackIsNotEmpty(listener, MISSING_HOLDER, INPUT_DATA, "", ENTRY); |
88 | 90 | ||
91 | + validateCardinalityNonZero(ctx.dataDefStatement(), DATA_DEF_DATA, | ||
92 | + INPUT_DATA, "", ctx); | ||
93 | + | ||
89 | Parsable curData = listener.getParsedDataStack().peek(); | 94 | Parsable curData = listener.getParsedDataStack().peek(); |
90 | if (curData instanceof YangRpc) { | 95 | if (curData instanceof YangRpc) { |
91 | 96 | ... | ... |
... | @@ -19,6 +19,7 @@ package org.onosproject.yangutils.parser.impl.listeners; | ... | @@ -19,6 +19,7 @@ package org.onosproject.yangutils.parser.impl.listeners; |
19 | import org.onosproject.yangutils.datamodel.YangAugment; | 19 | import org.onosproject.yangutils.datamodel.YangAugment; |
20 | import org.onosproject.yangutils.datamodel.YangCase; | 20 | import org.onosproject.yangutils.datamodel.YangCase; |
21 | import org.onosproject.yangutils.datamodel.YangContainer; | 21 | import org.onosproject.yangutils.datamodel.YangContainer; |
22 | +import org.onosproject.yangutils.datamodel.YangGrouping; | ||
22 | import org.onosproject.yangutils.datamodel.YangInput; | 23 | import org.onosproject.yangutils.datamodel.YangInput; |
23 | import org.onosproject.yangutils.datamodel.YangList; | 24 | import org.onosproject.yangutils.datamodel.YangList; |
24 | import org.onosproject.yangutils.datamodel.YangModule; | 25 | import org.onosproject.yangutils.datamodel.YangModule; |
... | @@ -140,7 +141,7 @@ public final class ListListener { | ... | @@ -140,7 +141,7 @@ public final class ListListener { |
140 | if (curData instanceof YangModule || curData instanceof YangContainer | 141 | if (curData instanceof YangModule || curData instanceof YangContainer |
141 | || curData instanceof YangList || curData instanceof YangCase | 142 | || curData instanceof YangList || curData instanceof YangCase |
142 | || curData instanceof YangNotification || curData instanceof YangInput | 143 | || curData instanceof YangNotification || curData instanceof YangInput |
143 | - || curData instanceof YangOutput || curData instanceof YangAugment) { | 144 | + || curData instanceof YangOutput || curData instanceof YangAugment || curData instanceof YangGrouping) { |
144 | curNode = (YangNode) curData; | 145 | curNode = (YangNode) curData; |
145 | try { | 146 | try { |
146 | curNode.addChild(yangList); | 147 | curNode.addChild(yangList); | ... | ... |
... | @@ -40,13 +40,10 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp | ... | @@ -40,13 +40,10 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp |
40 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; | 40 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; |
41 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; | 41 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; |
42 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne; | 42 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne; |
43 | -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateMutuallyExclusiveChilds; | ||
44 | import static org.onosproject.yangutils.utils.YangConstructType.DESCRIPTION_DATA; | 43 | import static org.onosproject.yangutils.utils.YangConstructType.DESCRIPTION_DATA; |
45 | -import static org.onosproject.yangutils.utils.YangConstructType.GROUPING_DATA; | ||
46 | import static org.onosproject.yangutils.utils.YangConstructType.NOTIFICATION_DATA; | 44 | import static org.onosproject.yangutils.utils.YangConstructType.NOTIFICATION_DATA; |
47 | import static org.onosproject.yangutils.utils.YangConstructType.REFERENCE_DATA; | 45 | import static org.onosproject.yangutils.utils.YangConstructType.REFERENCE_DATA; |
48 | import static org.onosproject.yangutils.utils.YangConstructType.STATUS_DATA; | 46 | import static org.onosproject.yangutils.utils.YangConstructType.STATUS_DATA; |
49 | -import static org.onosproject.yangutils.utils.YangConstructType.TYPEDEF_DATA; | ||
50 | 47 | ||
51 | /* | 48 | /* |
52 | * Reference: RFC6020 and YANG ANTLR Grammar | 49 | * Reference: RFC6020 and YANG ANTLR Grammar |
... | @@ -159,7 +156,5 @@ public final class NotificationListener { | ... | @@ -159,7 +156,5 @@ public final class NotificationListener { |
159 | ctx.identifier().getText()); | 156 | ctx.identifier().getText()); |
160 | validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, NOTIFICATION_DATA, | 157 | validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, NOTIFICATION_DATA, |
161 | ctx.identifier().getText()); | 158 | ctx.identifier().getText()); |
162 | - validateMutuallyExclusiveChilds(ctx.typedefStatement(), TYPEDEF_DATA, ctx.groupingStatement(), GROUPING_DATA, | ||
163 | - NOTIFICATION_DATA, ctx.identifier().getText()); | ||
164 | } | 159 | } |
165 | } | 160 | } | ... | ... |
... | @@ -36,6 +36,8 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp | ... | @@ -36,6 +36,8 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp |
36 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; | 36 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; |
37 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA; | 37 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA; |
38 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; | 38 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; |
39 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityNonZero; | ||
40 | +import static org.onosproject.yangutils.utils.YangConstructType.DATA_DEF_DATA; | ||
39 | import static org.onosproject.yangutils.utils.YangConstructType.OUTPUT_DATA; | 41 | import static org.onosproject.yangutils.utils.YangConstructType.OUTPUT_DATA; |
40 | 42 | ||
41 | /* | 43 | /* |
... | @@ -86,6 +88,9 @@ public final class OutputListener { | ... | @@ -86,6 +88,9 @@ public final class OutputListener { |
86 | // Check for stack to be non empty. | 88 | // Check for stack to be non empty. |
87 | checkStackIsNotEmpty(listener, MISSING_HOLDER, OUTPUT_DATA, "", ENTRY); | 89 | checkStackIsNotEmpty(listener, MISSING_HOLDER, OUTPUT_DATA, "", ENTRY); |
88 | 90 | ||
91 | + validateCardinalityNonZero(ctx.dataDefStatement(), DATA_DEF_DATA, | ||
92 | + OUTPUT_DATA, "", ctx); | ||
93 | + | ||
89 | Parsable curData = listener.getParsedDataStack().peek(); | 94 | Parsable curData = listener.getParsedDataStack().peek(); |
90 | if (curData instanceof YangRpc) { | 95 | if (curData instanceof YangRpc) { |
91 | 96 | ... | ... |
... | @@ -37,12 +37,9 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp | ... | @@ -37,12 +37,9 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp |
37 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; | 37 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; |
38 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; | 38 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; |
39 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne; | 39 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne; |
40 | -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateMutuallyExclusiveChilds; | ||
41 | import static org.onosproject.yangutils.utils.YangConstructType.RPC_DATA; | 40 | import static org.onosproject.yangutils.utils.YangConstructType.RPC_DATA; |
42 | import static org.onosproject.yangutils.utils.YangConstructType.INPUT_DATA; | 41 | import static org.onosproject.yangutils.utils.YangConstructType.INPUT_DATA; |
43 | import static org.onosproject.yangutils.utils.YangConstructType.OUTPUT_DATA; | 42 | import static org.onosproject.yangutils.utils.YangConstructType.OUTPUT_DATA; |
44 | -import static org.onosproject.yangutils.utils.YangConstructType.TYPEDEF_DATA; | ||
45 | -import static org.onosproject.yangutils.utils.YangConstructType.GROUPING_DATA; | ||
46 | import static org.onosproject.yangutils.utils.YangConstructType.STATUS_DATA; | 43 | import static org.onosproject.yangutils.utils.YangConstructType.STATUS_DATA; |
47 | import static org.onosproject.yangutils.utils.YangConstructType.REFERENCE_DATA; | 44 | import static org.onosproject.yangutils.utils.YangConstructType.REFERENCE_DATA; |
48 | import static org.onosproject.yangutils.utils.YangConstructType.DESCRIPTION_DATA; | 45 | import static org.onosproject.yangutils.utils.YangConstructType.DESCRIPTION_DATA; |
... | @@ -157,8 +154,6 @@ public final class RpcListener { | ... | @@ -157,8 +154,6 @@ public final class RpcListener { |
157 | validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, RPC_DATA, ctx.identifier().getText()); | 154 | validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, RPC_DATA, ctx.identifier().getText()); |
158 | validateCardinalityMaxOne(ctx.inputStatement(), INPUT_DATA, RPC_DATA, ctx.identifier().getText()); | 155 | validateCardinalityMaxOne(ctx.inputStatement(), INPUT_DATA, RPC_DATA, ctx.identifier().getText()); |
159 | validateCardinalityMaxOne(ctx.outputStatement(), OUTPUT_DATA, RPC_DATA, ctx.identifier().getText()); | 156 | validateCardinalityMaxOne(ctx.outputStatement(), OUTPUT_DATA, RPC_DATA, ctx.identifier().getText()); |
160 | - validateMutuallyExclusiveChilds(ctx.typedefStatement(), TYPEDEF_DATA, ctx.groupingStatement(), GROUPING_DATA, | ||
161 | - RPC_DATA, ctx.identifier().getText()); | ||
162 | } | 157 | } |
163 | 158 | ||
164 | } | 159 | } | ... | ... |
... | @@ -17,6 +17,7 @@ | ... | @@ -17,6 +17,7 @@ |
17 | package org.onosproject.yangutils.parser.impl.listeners; | 17 | package org.onosproject.yangutils.parser.impl.listeners; |
18 | 18 | ||
19 | import org.onosproject.yangutils.datamodel.YangContainer; | 19 | import org.onosproject.yangutils.datamodel.YangContainer; |
20 | +import org.onosproject.yangutils.datamodel.YangGrouping; | ||
20 | import org.onosproject.yangutils.datamodel.YangInput; | 21 | import org.onosproject.yangutils.datamodel.YangInput; |
21 | import org.onosproject.yangutils.datamodel.YangList; | 22 | import org.onosproject.yangutils.datamodel.YangList; |
22 | import org.onosproject.yangutils.datamodel.YangModule; | 23 | import org.onosproject.yangutils.datamodel.YangModule; |
... | @@ -127,11 +128,8 @@ public final class TypeDefListener { | ... | @@ -127,11 +128,8 @@ public final class TypeDefListener { |
127 | 128 | ||
128 | if (curData instanceof YangModule || curData instanceof YangSubModule || curData instanceof YangContainer | 129 | if (curData instanceof YangModule || curData instanceof YangSubModule || curData instanceof YangContainer |
129 | || curData instanceof YangList || curData instanceof YangNotification || curData instanceof YangRpc | 130 | || curData instanceof YangList || curData instanceof YangNotification || curData instanceof YangRpc |
130 | - || curData instanceof YangInput || curData instanceof YangOutput) { | 131 | + || curData instanceof YangInput || curData instanceof YangOutput || curData instanceof YangGrouping) { |
131 | 132 | ||
132 | - /* | ||
133 | - * TODO YangGrouping. | ||
134 | - */ | ||
135 | YangNode curNode = (YangNode) curData; | 133 | YangNode curNode = (YangNode) curData; |
136 | try { | 134 | try { |
137 | curNode.addChild(typeDefNode); | 135 | curNode.addChild(typeDefNode); | ... | ... |
... | @@ -23,8 +23,10 @@ import org.onosproject.yangutils.datamodel.YangInput; | ... | @@ -23,8 +23,10 @@ import org.onosproject.yangutils.datamodel.YangInput; |
23 | import org.onosproject.yangutils.datamodel.YangList; | 23 | import org.onosproject.yangutils.datamodel.YangList; |
24 | import org.onosproject.yangutils.datamodel.YangModule; | 24 | import org.onosproject.yangutils.datamodel.YangModule; |
25 | import org.onosproject.yangutils.datamodel.YangNode; | 25 | import org.onosproject.yangutils.datamodel.YangNode; |
26 | +import org.onosproject.yangutils.datamodel.YangNodeIdentifier; | ||
26 | import org.onosproject.yangutils.datamodel.YangNotification; | 27 | import org.onosproject.yangutils.datamodel.YangNotification; |
27 | import org.onosproject.yangutils.datamodel.YangOutput; | 28 | import org.onosproject.yangutils.datamodel.YangOutput; |
29 | +import org.onosproject.yangutils.datamodel.YangResolutionInfo; | ||
28 | import org.onosproject.yangutils.datamodel.YangSubModule; | 30 | import org.onosproject.yangutils.datamodel.YangSubModule; |
29 | import org.onosproject.yangutils.datamodel.YangUses; | 31 | import org.onosproject.yangutils.datamodel.YangUses; |
30 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | 32 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
... | @@ -33,16 +35,18 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | ... | @@ -33,16 +35,18 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; |
33 | import org.onosproject.yangutils.parser.exceptions.ParserException; | 35 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
34 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; | 36 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
35 | 37 | ||
38 | +import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo; | ||
36 | import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION; | 39 | import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION; |
37 | import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangUsesNode; | 40 | import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangUsesNode; |
41 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil; | ||
38 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; | 42 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; |
39 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; | 43 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; |
40 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage; | 44 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage; |
41 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; | 45 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; |
42 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; | 46 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; |
43 | -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER; | ||
44 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; | 47 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; |
45 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA; | 48 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA; |
49 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidNodeIdentifier; | ||
46 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; | 50 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; |
47 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne; | 51 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne; |
48 | import static org.onosproject.yangutils.utils.YangConstructType.DESCRIPTION_DATA; | 52 | import static org.onosproject.yangutils.utils.YangConstructType.DESCRIPTION_DATA; |
... | @@ -116,6 +120,11 @@ public final class UsesListener { | ... | @@ -116,6 +120,11 @@ public final class UsesListener { |
116 | // Validate sub statement cardinality. | 120 | // Validate sub statement cardinality. |
117 | validateSubStatementsCardinality(ctx); | 121 | validateSubStatementsCardinality(ctx); |
118 | 122 | ||
123 | + // Check for identifier collision | ||
124 | + int line = ctx.getStart().getLine(); | ||
125 | + int charPositionInLine = ctx.getStart().getCharPositionInLine(); | ||
126 | + | ||
127 | + detectCollidingChildUtil(listener, line, charPositionInLine, ctx.string().getText(), USES_DATA); | ||
119 | Parsable curData = listener.getParsedDataStack().peek(); | 128 | Parsable curData = listener.getParsedDataStack().peek(); |
120 | 129 | ||
121 | if (curData instanceof YangModule || curData instanceof YangSubModule | 130 | if (curData instanceof YangModule || curData instanceof YangSubModule |
... | @@ -126,8 +135,8 @@ public final class UsesListener { | ... | @@ -126,8 +135,8 @@ public final class UsesListener { |
126 | || curData instanceof YangNotification) { | 135 | || curData instanceof YangNotification) { |
127 | 136 | ||
128 | YangUses usesNode = getYangUsesNode(JAVA_GENERATION); | 137 | YangUses usesNode = getYangUsesNode(JAVA_GENERATION); |
129 | - usesNode.setName(ctx.string().getText()); | 138 | + YangNodeIdentifier nodeIdentifier = getValidNodeIdentifier(ctx.string().getText(), USES_DATA, ctx); |
130 | - | 139 | + usesNode.setNodeIdentifier(nodeIdentifier); |
131 | YangNode curNode = (YangNode) curData; | 140 | YangNode curNode = (YangNode) curData; |
132 | 141 | ||
133 | try { | 142 | try { |
... | @@ -156,12 +165,29 @@ public final class UsesListener { | ... | @@ -156,12 +165,29 @@ public final class UsesListener { |
156 | // Check for stack to be non empty. | 165 | // Check for stack to be non empty. |
157 | checkStackIsNotEmpty(listener, MISSING_HOLDER, USES_DATA, ctx.string().getText(), EXIT); | 166 | checkStackIsNotEmpty(listener, MISSING_HOLDER, USES_DATA, ctx.string().getText(), EXIT); |
158 | 167 | ||
159 | - if (listener.getParsedDataStack().peek() instanceof YangUses) { | 168 | + Parsable parsableUses = listener.getParsedDataStack().pop(); |
160 | - listener.getParsedDataStack().pop(); | 169 | + if (!(parsableUses instanceof YangUses)) { |
161 | - } else { | 170 | + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, USES_DATA, |
162 | - throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, USES_DATA, | ||
163 | ctx.string().getText(), EXIT)); | 171 | ctx.string().getText(), EXIT)); |
164 | } | 172 | } |
173 | + YangUses uses = (YangUses) parsableUses; | ||
174 | + int errorLine = ctx.getStart().getLine(); | ||
175 | + int errorPosition = ctx.getStart().getCharPositionInLine(); | ||
176 | + | ||
177 | + // Parent YANG node of uses to be added in resolution information. | ||
178 | + Parsable parentNode = listener.getParsedDataStack().peek(); | ||
179 | + | ||
180 | + // Verify parent node of leaf | ||
181 | + if (!(parentNode instanceof YangNode)) { | ||
182 | + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, USES_DATA, | ||
183 | + ctx.string().getText(), EXIT)); | ||
184 | + } | ||
185 | + | ||
186 | + // Add resolution information to the list | ||
187 | + YangResolutionInfo resolutionInfo = new YangResolutionInfo<YangUses>(uses, | ||
188 | + (YangNode) parentNode, errorLine, | ||
189 | + errorPosition); | ||
190 | + addToResolutionList(resolutionInfo, ctx); | ||
165 | } | 191 | } |
166 | 192 | ||
167 | // TODO linker to handle collision scenarios like leaf obtained by uses, conflicts with some existing leaf. | 193 | // TODO linker to handle collision scenarios like leaf obtained by uses, conflicts with some existing leaf. |
... | @@ -175,5 +201,23 @@ public final class UsesListener { | ... | @@ -175,5 +201,23 @@ public final class UsesListener { |
175 | validateCardinalityMaxOne(ctx.whenStatement(), WHEN_DATA, USES_DATA, ctx.string().getText()); | 201 | validateCardinalityMaxOne(ctx.whenStatement(), WHEN_DATA, USES_DATA, ctx.string().getText()); |
176 | validateCardinalityMaxOne(ctx.statusStatement(), STATUS_DATA, USES_DATA, ctx.string().getText()); | 202 | validateCardinalityMaxOne(ctx.statusStatement(), STATUS_DATA, USES_DATA, ctx.string().getText()); |
177 | validateCardinalityMaxOne(ctx.descriptionStatement(), DESCRIPTION_DATA, USES_DATA, ctx.string().getText()); | 203 | validateCardinalityMaxOne(ctx.descriptionStatement(), DESCRIPTION_DATA, USES_DATA, ctx.string().getText()); |
178 | - validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, USES_DATA, ctx.string().getText()); } | 204 | + validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, USES_DATA, ctx.string().getText()); |
205 | + } | ||
206 | + | ||
207 | + /** | ||
208 | + * Add to resolution list. | ||
209 | + * | ||
210 | + * @param resolutionInfo resolution information. | ||
211 | + * @param ctx context object of the grammar rule | ||
212 | + */ | ||
213 | + private static void addToResolutionList(YangResolutionInfo<YangUses> resolutionInfo, | ||
214 | + GeneratedYangParser.UsesStatementContext ctx) { | ||
215 | + | ||
216 | + try { | ||
217 | + addResolutionInfo(resolutionInfo); | ||
218 | + } catch (DataModelException e) { | ||
219 | + throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA, | ||
220 | + USES_DATA, ctx.string().getText(), EXIT, e.getMessage())); | ||
221 | + } | ||
222 | + } | ||
179 | } | 223 | } | ... | ... |
... | @@ -1098,12 +1098,7 @@ package org.onosproject.yangutils.parser.antlrgencode; | ... | @@ -1098,12 +1098,7 @@ package org.onosproject.yangutils.parser.antlrgencode; |
1098 | * 1*(data-def-stmt stmtsep) | 1098 | * 1*(data-def-stmt stmtsep) |
1099 | * "}" | 1099 | * "}" |
1100 | */ | 1100 | */ |
1101 | - inputStatement : INPUT_KEYWORD LEFT_CURLY_BRACE inputStatementBody RIGHT_CURLY_BRACE; | 1101 | + inputStatement : INPUT_KEYWORD LEFT_CURLY_BRACE (typedefStatement | groupingStatement | dataDefStatement)* RIGHT_CURLY_BRACE; |
1102 | - | ||
1103 | - inputStatementBody : typedefStatement* dataDefStatement+ | ||
1104 | - | dataDefStatement+ typedefStatement* | ||
1105 | - | groupingStatement* dataDefStatement+ | ||
1106 | - | dataDefStatement+ groupingStatement*; | ||
1107 | 1102 | ||
1108 | /** | 1103 | /** |
1109 | * output-stmt = output-keyword optsep | 1104 | * output-stmt = output-keyword optsep |
... | @@ -1114,12 +1109,7 @@ package org.onosproject.yangutils.parser.antlrgencode; | ... | @@ -1114,12 +1109,7 @@ package org.onosproject.yangutils.parser.antlrgencode; |
1114 | * 1*(data-def-stmt stmtsep) | 1109 | * 1*(data-def-stmt stmtsep) |
1115 | * "}" | 1110 | * "}" |
1116 | */ | 1111 | */ |
1117 | - outputStatement : OUTPUT_KEYWORD LEFT_CURLY_BRACE outputStatementBody RIGHT_CURLY_BRACE; | 1112 | + outputStatement : OUTPUT_KEYWORD LEFT_CURLY_BRACE (typedefStatement | groupingStatement | dataDefStatement)* RIGHT_CURLY_BRACE; |
1118 | - | ||
1119 | - outputStatementBody : typedefStatement* dataDefStatement+ | ||
1120 | - | dataDefStatement+ typedefStatement* | ||
1121 | - | groupingStatement* dataDefStatement+ | ||
1122 | - | dataDefStatement+ groupingStatement*; | ||
1123 | 1113 | ||
1124 | /** | 1114 | /** |
1125 | * notification-stmt = notification-keyword sep | 1115 | * notification-stmt = notification-keyword sep | ... | ... |
utils/yangutils/src/test/java/org/onosproject/yangutils/linker/IntraFileUsesLinkingTest.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.linker; | ||
18 | + | ||
19 | +import java.io.IOException; | ||
20 | +import java.util.ListIterator; | ||
21 | + | ||
22 | +import org.junit.Rule; | ||
23 | +import org.junit.Test; | ||
24 | +import org.junit.rules.ExpectedException; | ||
25 | +import org.onosproject.yangutils.datamodel.ResolvableStatus; | ||
26 | +import org.onosproject.yangutils.datamodel.YangContainer; | ||
27 | +import org.onosproject.yangutils.datamodel.YangDataTypes; | ||
28 | +import org.onosproject.yangutils.datamodel.YangGrouping; | ||
29 | +import org.onosproject.yangutils.datamodel.YangLeaf; | ||
30 | +import org.onosproject.yangutils.datamodel.YangList; | ||
31 | +import org.onosproject.yangutils.datamodel.YangModule; | ||
32 | +import org.onosproject.yangutils.datamodel.YangNode; | ||
33 | +import org.onosproject.yangutils.datamodel.YangNodeType; | ||
34 | +import org.onosproject.yangutils.datamodel.YangTypeDef; | ||
35 | +import org.onosproject.yangutils.datamodel.YangUses; | ||
36 | +import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
37 | +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; | ||
38 | + | ||
39 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
40 | +import static org.hamcrest.core.Is.is; | ||
41 | + | ||
42 | +/** | ||
43 | + * Test cases for testing uses intra file linking. | ||
44 | + */ | ||
45 | +public class IntraFileUsesLinkingTest { | ||
46 | + | ||
47 | + @Rule | ||
48 | + public ExpectedException thrown = ExpectedException.none(); | ||
49 | + | ||
50 | + private final YangUtilsParserManager manager = new YangUtilsParserManager(); | ||
51 | + | ||
52 | + /** | ||
53 | + * Checks self resolution when grouping and uses are siblings. | ||
54 | + * Grouping followed by uses. | ||
55 | + */ | ||
56 | + @Test | ||
57 | + public void processSelfResolutionWhenUsesAndGroupingAtRootLevel() | ||
58 | + throws IOException, ParserException { | ||
59 | + | ||
60 | + YangNode node = manager.getDataModel("src/test/resources/SelfResolutionWhenUsesAndGroupingAtRootLevel.yang"); | ||
61 | + | ||
62 | + // Check whether the data model tree returned is of type module. | ||
63 | + assertThat((node instanceof YangModule), is(true)); | ||
64 | + | ||
65 | + // Check whether the node type is set properly to module. | ||
66 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
67 | + | ||
68 | + // Check whether the module name is set correctly. | ||
69 | + YangModule yangNode = (YangModule) node; | ||
70 | + assertThat(yangNode.getName(), is("Test")); | ||
71 | + | ||
72 | + ListIterator<YangLeaf> leafIterator; | ||
73 | + YangLeaf leafInfo; | ||
74 | + | ||
75 | + // Check whether grouping is the sibling of module's child. | ||
76 | + assertThat((yangNode.getChild().getNextSibling() instanceof YangGrouping), is(true)); | ||
77 | + | ||
78 | + YangGrouping grouping = (YangGrouping) yangNode.getChild().getNextSibling(); | ||
79 | + leafIterator = grouping.getListOfLeaf().listIterator(); | ||
80 | + leafInfo = leafIterator.next(); | ||
81 | + | ||
82 | + // Check whether the information in the leaf is correct under grouping. | ||
83 | + assertThat(leafInfo.getLeafName(), is("hello")); | ||
84 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("String")); | ||
85 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING)); | ||
86 | + | ||
87 | + // Check whether uses is module's child. | ||
88 | + assertThat((yangNode.getChild() instanceof YangUses), is(true)); | ||
89 | + YangUses uses = (YangUses) yangNode.getChild(); | ||
90 | + | ||
91 | + // Check whether uses get resolved. | ||
92 | + assertThat(uses.getResolvableStatus(), | ||
93 | + is(ResolvableStatus.RESOLVED)); | ||
94 | + | ||
95 | + leafIterator = yangNode.getListOfLeaf().listIterator(); | ||
96 | + leafInfo = leafIterator.next(); | ||
97 | + | ||
98 | + // Check whether the information in the leaf is correct under module. | ||
99 | + assertThat(leafInfo.getLeafName(), is("hello")); | ||
100 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("String")); | ||
101 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING)); | ||
102 | + | ||
103 | + } | ||
104 | + | ||
105 | + /** | ||
106 | + * Checks self resolution when grouping and uses are siblings. | ||
107 | + * Grouping has a child node. | ||
108 | + */ | ||
109 | + @Test | ||
110 | + public void processSelfResolutionWhenUsesAndGroupingAtRootLevelGroupingWithChild() | ||
111 | + throws IOException, ParserException { | ||
112 | + | ||
113 | + YangNode node = manager.getDataModel( | ||
114 | + "src/test/resources/SelfResolutionWhenUsesAndGroupingAtRootLevelGroupingWithChild.yang"); | ||
115 | + | ||
116 | + // Check whether the data model tree returned is of type module. | ||
117 | + assertThat((node instanceof YangModule), is(true)); | ||
118 | + | ||
119 | + // Check whether the node type is set properly to module. | ||
120 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
121 | + | ||
122 | + // Check whether the module name is set correctly. | ||
123 | + YangModule yangNode = (YangModule) node; | ||
124 | + assertThat(yangNode.getName(), is("Test")); | ||
125 | + | ||
126 | + ListIterator<YangLeaf> leafIterator; | ||
127 | + YangLeaf leafInfo; | ||
128 | + | ||
129 | + // Check whether grouping is the sibling of module's child. | ||
130 | + assertThat((yangNode.getChild().getNextSibling() instanceof YangGrouping), is(true)); | ||
131 | + | ||
132 | + YangGrouping grouping = (YangGrouping) yangNode.getChild().getNextSibling(); | ||
133 | + leafIterator = grouping.getListOfLeaf().listIterator(); | ||
134 | + leafInfo = leafIterator.next(); | ||
135 | + | ||
136 | + // Check whether the information in the leaf is correct under grouping. | ||
137 | + assertThat(leafInfo.getLeafName(), is("treat")); | ||
138 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("String")); | ||
139 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING)); | ||
140 | + | ||
141 | + // Check whether container is the child of grouping. | ||
142 | + assertThat((grouping.getChild() instanceof YangContainer), is(true)); | ||
143 | + YangContainer container = (YangContainer) grouping.getChild(); | ||
144 | + | ||
145 | + // Check whether the container name is set correctly which is under grouping. | ||
146 | + assertThat(container.getName(), is("test")); | ||
147 | + | ||
148 | + leafIterator = container.getListOfLeaf().listIterator(); | ||
149 | + leafInfo = leafIterator.next(); | ||
150 | + | ||
151 | + // Check whether the information in the leaf is correct under container which is under grouping. | ||
152 | + assertThat(leafInfo.getLeafName(), is("leaf2")); | ||
153 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("String")); | ||
154 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING)); | ||
155 | + | ||
156 | + // Check whether uses is module's child. | ||
157 | + assertThat((yangNode.getChild() instanceof YangUses), is(true)); | ||
158 | + YangUses uses = (YangUses) yangNode.getChild(); | ||
159 | + | ||
160 | + // Check whether uses get resolved. | ||
161 | + assertThat(uses.getResolvableStatus(), | ||
162 | + is(ResolvableStatus.RESOLVED)); | ||
163 | + | ||
164 | + leafIterator = yangNode.getListOfLeaf().listIterator(); | ||
165 | + leafInfo = leafIterator.next(); | ||
166 | + | ||
167 | + // Check whether the information in the leaf is correct under module. | ||
168 | + assertThat(leafInfo.getLeafName(), is("treat")); | ||
169 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("String")); | ||
170 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING)); | ||
171 | + | ||
172 | + // Check whether container is the child of module. | ||
173 | + assertThat((grouping.getNextSibling() instanceof YangContainer), is(true)); | ||
174 | + container = (YangContainer) grouping.getNextSibling(); | ||
175 | + | ||
176 | + // Check whether the container name is set correctly which is under module. | ||
177 | + assertThat(container.getName(), is("test")); | ||
178 | + | ||
179 | + leafIterator = container.getListOfLeaf().listIterator(); | ||
180 | + leafInfo = leafIterator.next(); | ||
181 | + | ||
182 | + // Check whether the information in the leaf is correct under container which is under module. | ||
183 | + assertThat(leafInfo.getLeafName(), is("leaf2")); | ||
184 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("String")); | ||
185 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING)); | ||
186 | + } | ||
187 | + | ||
188 | + /** | ||
189 | + * Checks self resolution when grouping in rpc and uses in output of the same rpc. | ||
190 | + * Uses is followed by grouping. | ||
191 | + */ | ||
192 | + @Test | ||
193 | + public void processSelfResolutionGroupingInRpcAndUsesInOutput() | ||
194 | + throws IOException, ParserException { | ||
195 | + | ||
196 | + YangNode node = manager | ||
197 | + .getDataModel("src/test/resources/SelfResolutionGroupingInRpcAndUsesInOutput.yang"); | ||
198 | + | ||
199 | + // Check whether the data model tree returned is of type module. | ||
200 | + assertThat((node instanceof YangModule), is(true)); | ||
201 | + | ||
202 | + // Check whether the node type is set properly to module. | ||
203 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
204 | + | ||
205 | + // Check whether the module name is set correctly. | ||
206 | + YangModule yangNode = (YangModule) node; | ||
207 | + assertThat(yangNode.getName(), is("rock")); | ||
208 | + | ||
209 | + ListIterator<YangLeaf> leafIterator; | ||
210 | + YangLeaf leafInfo; | ||
211 | + | ||
212 | + // Check whether grouping is the child of rpc. | ||
213 | + assertThat((yangNode.getChild().getChild() instanceof YangGrouping), is(true)); | ||
214 | + YangGrouping grouping = (YangGrouping) yangNode.getChild().getChild(); | ||
215 | + | ||
216 | + // Check whether the grouping name is set correctly. | ||
217 | + assertThat(grouping.getName(), is("hello")); | ||
218 | + | ||
219 | + // Check whether list is the child of grouping. | ||
220 | + assertThat((grouping.getChild() instanceof YangList), is(true)); | ||
221 | + YangList yangListNode = (YangList) grouping.getChild(); | ||
222 | + | ||
223 | + // Check whether the list name is set correctly. | ||
224 | + assertThat(yangListNode.getName(), is("valid")); | ||
225 | + | ||
226 | + leafIterator = yangListNode.getListOfLeaf().listIterator(); | ||
227 | + leafInfo = leafIterator.next(); | ||
228 | + | ||
229 | + // Check whether the information in the leaf is correct under list which is under grouping. | ||
230 | + assertThat(leafInfo.getLeafName(), is("invalid-interval")); | ||
231 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16")); | ||
232 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16)); | ||
233 | + assertThat(leafInfo.getUnits(), is("\"seconds\"")); | ||
234 | + assertThat(leafInfo.getReference(), is("\"RFC 6020\"")); | ||
235 | + | ||
236 | + // Check whether uses is input's child. | ||
237 | + assertThat((yangNode.getChild().getChild().getNextSibling().getChild() instanceof YangUses), is(true)); | ||
238 | + YangUses uses = (YangUses) yangNode.getChild().getChild().getNextSibling().getChild(); | ||
239 | + | ||
240 | + // Check whether uses get resolved. | ||
241 | + assertThat(uses.getResolvableStatus(), | ||
242 | + is(ResolvableStatus.RESOLVED)); | ||
243 | + | ||
244 | + // Check whether list is the sibling of uses which has been deep copied from grouping. | ||
245 | + assertThat((yangNode.getChild().getChild().getNextSibling().getChild().getNextSibling() instanceof YangList), | ||
246 | + is(true)); | ||
247 | + YangList yangList = (YangList) yangNode.getChild().getChild().getNextSibling().getChild().getNextSibling(); | ||
248 | + | ||
249 | + // Check whether the list name is set correctly. | ||
250 | + assertThat(yangList.getName(), is("valid")); | ||
251 | + | ||
252 | + leafIterator = yangList.getListOfLeaf().listIterator(); | ||
253 | + leafInfo = leafIterator.next(); | ||
254 | + | ||
255 | + // Check whether the information in the leaf is correct under list which is deep copied. | ||
256 | + assertThat(leafInfo.getLeafName(), is("invalid-interval")); | ||
257 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16")); | ||
258 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16)); | ||
259 | + assertThat(leafInfo.getUnits(), is("\"seconds\"")); | ||
260 | + assertThat(leafInfo.getReference(), is("\"RFC 6020\"")); | ||
261 | + | ||
262 | + // Check whether uses is output's child. | ||
263 | + assertThat((yangNode.getChild().getChild().getNextSibling().getNextSibling().getChild() instanceof YangUses), | ||
264 | + is(true)); | ||
265 | + YangUses usesInOuput = (YangUses) yangNode.getChild().getChild().getNextSibling().getNextSibling().getChild(); | ||
266 | + | ||
267 | + // Check whether uses get resolved. | ||
268 | + assertThat(usesInOuput.getResolvableStatus(), | ||
269 | + is(ResolvableStatus.RESOLVED)); | ||
270 | + | ||
271 | + // Check whether list is the sibling of uses which has been deep copied from grouping. | ||
272 | + assertThat((yangNode.getChild().getChild().getNextSibling().getChild().getNextSibling() instanceof YangList), | ||
273 | + is(true)); | ||
274 | + | ||
275 | + YangList yangListInOutput = (YangList) yangNode.getChild().getChild().getNextSibling().getNextSibling() | ||
276 | + .getChild().getNextSibling(); | ||
277 | + | ||
278 | + // Check whether the list name is set correctly. | ||
279 | + assertThat(yangListInOutput.getName(), is("valid")); | ||
280 | + | ||
281 | + leafIterator = yangListInOutput.getListOfLeaf().listIterator(); | ||
282 | + leafInfo = leafIterator.next(); | ||
283 | + | ||
284 | + // Check whether the information in the leaf is correct under list which is deep copied. | ||
285 | + assertThat(leafInfo.getLeafName(), is("invalid-interval")); | ||
286 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16")); | ||
287 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16)); | ||
288 | + assertThat(leafInfo.getUnits(), is("\"seconds\"")); | ||
289 | + assertThat(leafInfo.getReference(), is("\"RFC 6020\"")); | ||
290 | + } | ||
291 | + | ||
292 | + /** | ||
293 | + * Checks the failure scenario when uses is referring to its own grouping directly. | ||
294 | + */ | ||
295 | + @Test | ||
296 | + public void processSelfResolutionGroupingReferencingItselfFailureScenerio() | ||
297 | + throws IOException, ParserException { | ||
298 | + | ||
299 | + thrown.expect(ParserException.class); | ||
300 | + thrown.expectMessage( | ||
301 | + "YANG file error: Duplicate input identifier detected, same as leaf \"zip-code\""); | ||
302 | + YangNode node = manager | ||
303 | + .getDataModel("src/test/resources/SelfResolutionGroupingReferencingItselfFailureScenerio.yang"); | ||
304 | + | ||
305 | + } | ||
306 | + | ||
307 | + /** | ||
308 | + * Checks the when multiple uses are present and are referred to the grouping at different levels. | ||
309 | + */ | ||
310 | + @Test | ||
311 | + public void processSelfResolutionGroupingWithMultipleUses() | ||
312 | + throws IOException, ParserException { | ||
313 | + | ||
314 | + YangNode node = manager | ||
315 | + .getDataModel("src/test/resources/SelfResolutionGroupingWithMultipleUses.yang"); | ||
316 | + | ||
317 | + // Check whether the data model tree returned is of type module. | ||
318 | + assertThat((node instanceof YangModule), is(true)); | ||
319 | + | ||
320 | + // Check whether the node type is set properly to module. | ||
321 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
322 | + | ||
323 | + // Check whether the module name is set correctly. | ||
324 | + YangModule yangNode = (YangModule) node; | ||
325 | + assertThat(yangNode.getName(), is("Test")); | ||
326 | + | ||
327 | + ListIterator<YangLeaf> leafIterator; | ||
328 | + YangLeaf leafInfo; | ||
329 | + | ||
330 | + // Check whether grouping is the child of container. | ||
331 | + assertThat((yangNode.getChild().getChild() instanceof YangGrouping), is(true)); | ||
332 | + YangGrouping grouping = (YangGrouping) yangNode.getChild().getChild(); | ||
333 | + | ||
334 | + // Check whether the grouping name is set correctly. | ||
335 | + assertThat(grouping.getName(), is("endpoint")); | ||
336 | + | ||
337 | + // Check whether uses is endpoint-grouping's child. | ||
338 | + assertThat((grouping.getChild() instanceof YangUses), is(true)); | ||
339 | + YangUses firstUses = (YangUses) grouping.getChild(); | ||
340 | + | ||
341 | + // Check whether uses get resolved. | ||
342 | + assertThat(firstUses.getResolvableStatus(), | ||
343 | + is(ResolvableStatus.RESOLVED)); | ||
344 | + | ||
345 | + // Check whether container is the sibling of uses. | ||
346 | + assertThat((firstUses.getNextSibling() instanceof YangContainer), is(true)); | ||
347 | + YangContainer yangContainer = (YangContainer) firstUses.getNextSibling(); | ||
348 | + | ||
349 | + // Check whether the container name is set correctly. | ||
350 | + assertThat(yangContainer.getName(), is("design")); | ||
351 | + | ||
352 | + leafIterator = yangContainer.getListOfLeaf().listIterator(); | ||
353 | + leafInfo = leafIterator.next(); | ||
354 | + | ||
355 | + // Check whether the information in the leaf is correct under design-container. | ||
356 | + assertThat(leafInfo.getLeafName(), is("ink")); | ||
357 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("int32")); | ||
358 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.INT32)); | ||
359 | + | ||
360 | + // Check whether uses is design-container's child. | ||
361 | + assertThat((yangContainer.getChild() instanceof YangUses), is(true)); | ||
362 | + YangUses secondUses = (YangUses) yangContainer.getChild(); | ||
363 | + | ||
364 | + // Check whether uses get resolved. | ||
365 | + assertThat(secondUses.getResolvableStatus(), | ||
366 | + is(ResolvableStatus.RESOLVED)); | ||
367 | + | ||
368 | + // Check whether container is the sibling of uses. | ||
369 | + assertThat((secondUses.getNextSibling() instanceof YangContainer), is(true)); | ||
370 | + YangContainer yangContainer2 = (YangContainer) secondUses.getNextSibling(); | ||
371 | + assertThat(yangContainer2.getName(), is("correct")); | ||
372 | + | ||
373 | + leafIterator = yangContainer2.getListOfLeaf().listIterator(); | ||
374 | + leafInfo = leafIterator.next(); | ||
375 | + | ||
376 | + // Check whether the information in the leaf is correct under correct-container. | ||
377 | + assertThat(leafInfo.getLeafName(), is("newone")); | ||
378 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("string")); | ||
379 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING)); | ||
380 | + | ||
381 | + // Check whether uses is correct container's child. | ||
382 | + assertThat((yangContainer2.getChild() instanceof YangUses), is(true)); | ||
383 | + YangUses thirdUses = (YangUses) yangContainer2.getChild(); | ||
384 | + | ||
385 | + // Check whether uses get resolved. | ||
386 | + assertThat(thirdUses.getResolvableStatus(), | ||
387 | + is(ResolvableStatus.RESOLVED)); | ||
388 | + | ||
389 | + // Check whether container is the sibling of uses. | ||
390 | + assertThat((thirdUses.getNextSibling() instanceof YangContainer), is(true)); | ||
391 | + | ||
392 | + YangContainer yangContainer3 = (YangContainer) thirdUses.getNextSibling(); | ||
393 | + assertThat(yangContainer3.getName(), is("value")); | ||
394 | + | ||
395 | + leafIterator = yangContainer3.getListOfLeaf().listIterator(); | ||
396 | + leafInfo = leafIterator.next(); | ||
397 | + | ||
398 | + // Check whether the information in the leaf is correct under container | ||
399 | + // which has been deep copied from grouping. | ||
400 | + assertThat(leafInfo.getLeafName(), is("zip-code")); | ||
401 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("string")); | ||
402 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING)); | ||
403 | + | ||
404 | + // Check whether uses is the sibling of container-design. | ||
405 | + assertThat((yangContainer.getNextSibling() instanceof YangUses), is(true)); | ||
406 | + YangUses fourthUses = (YangUses) yangContainer.getNextSibling(); | ||
407 | + | ||
408 | + // Check whether uses get resolved. | ||
409 | + assertThat(fourthUses.getResolvableStatus(), | ||
410 | + is(ResolvableStatus.RESOLVED)); | ||
411 | + | ||
412 | + // Check whether uses is the sibling of previous uses. | ||
413 | + assertThat((fourthUses.getNextSibling() instanceof YangUses), is(true)); | ||
414 | + YangUses fifthUses = (YangUses) fourthUses.getNextSibling(); | ||
415 | + | ||
416 | + // Check whether uses get resolved. | ||
417 | + assertThat(fifthUses.getResolvableStatus(), | ||
418 | + is(ResolvableStatus.RESOLVED)); | ||
419 | + | ||
420 | + // Check whether list is the sibling of uses. | ||
421 | + assertThat((fifthUses.getNextSibling() instanceof YangList), is(true)); | ||
422 | + YangList yangList = (YangList) fifthUses.getNextSibling(); | ||
423 | + assertThat(yangList.getName(), is("valid")); | ||
424 | + | ||
425 | + leafIterator = yangList.getListOfLeaf().listIterator(); | ||
426 | + leafInfo = leafIterator.next(); | ||
427 | + | ||
428 | + // Check whether the information in the leaf is correct under list which has been deep copied from grouping. | ||
429 | + assertThat(leafInfo.getLeafName(), is("invalid-interval")); | ||
430 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16")); | ||
431 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16)); | ||
432 | + assertThat(leafInfo.getUnits(), is("\"seconds\"")); | ||
433 | + assertThat(leafInfo.getReference(), is("\"RFC 6020\"")); | ||
434 | + | ||
435 | + // Check whether typedef is the sibling of list. | ||
436 | + assertThat((yangList.getNextSibling() instanceof YangTypeDef), is(true)); | ||
437 | + YangTypeDef yangTypeDef = (YangTypeDef) yangList.getNextSibling(); | ||
438 | + assertThat(yangTypeDef.getName(), is("my-type")); | ||
439 | + | ||
440 | + leafIterator = grouping.getListOfLeaf().listIterator(); | ||
441 | + leafInfo = leafIterator.next(); | ||
442 | + | ||
443 | + // Check whether the information in the leaf is correct under grouping. | ||
444 | + assertThat(leafInfo.getLeafName(), is("zip-code")); | ||
445 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("string")); | ||
446 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING)); | ||
447 | + | ||
448 | + // Check whether uses is endpoint-grouping's sibling. | ||
449 | + assertThat((grouping.getNextSibling() instanceof YangUses), is(true)); | ||
450 | + YangUses endpointUses = (YangUses) grouping.getNextSibling(); | ||
451 | + | ||
452 | + // Check whether uses get resolved. | ||
453 | + assertThat(endpointUses.getResolvableStatus(), | ||
454 | + is(ResolvableStatus.RESOLVED)); | ||
455 | + | ||
456 | + assertThat((endpointUses.getNextSibling().getNextSibling().getNextSibling().getNextSibling().getNextSibling() | ||
457 | + .getNextSibling() instanceof YangUses), is(true)); | ||
458 | + | ||
459 | + YangUses yangUsesInEndpoint = (YangUses) endpointUses.getNextSibling().getNextSibling().getNextSibling() | ||
460 | + .getNextSibling().getNextSibling().getNextSibling(); | ||
461 | + assertThat(yangUsesInEndpoint.getResolvableStatus(), | ||
462 | + is(ResolvableStatus.RESOLVED)); | ||
463 | + | ||
464 | + assertThat((yangUsesInEndpoint.getNextSibling() instanceof YangContainer), is(true)); | ||
465 | + YangContainer yangContainerInEndPoint = (YangContainer) yangUsesInEndpoint.getNextSibling(); | ||
466 | + | ||
467 | + assertThat(yangContainerInEndPoint.getName(), is("design")); | ||
468 | + } | ||
469 | + | ||
470 | + /** | ||
471 | + * Checks the failure scenario when uses is present under the same node many times. | ||
472 | + */ | ||
473 | + @Test | ||
474 | + public void processSelfResolutionGroupingHavingSameUsesManyTimes() | ||
475 | + throws IOException, ParserException { | ||
476 | + | ||
477 | + thrown.expect(ParserException.class); | ||
478 | + thrown.expectMessage( | ||
479 | + "YANG file error: Duplicate input identifier detected, same as uses \"failure\""); | ||
480 | + YangNode node = manager | ||
481 | + .getDataModel("src/test/resources/SelfResolutionGroupingHavingSameUsesManyTimes.yang"); | ||
482 | + } | ||
483 | + | ||
484 | + /** | ||
485 | + * Checks the rpc having both typedef and grouping. | ||
486 | + * It also checks that the grouping under different nodes will not give any problem in resolving uses. | ||
487 | + */ | ||
488 | + @Test | ||
489 | + public void processSelfResolutionRpcWithOneTypedefAndTwoGroupingUnderDifferentNode() | ||
490 | + throws IOException, ParserException { | ||
491 | + | ||
492 | + YangNode node = manager | ||
493 | + .getDataModel( | ||
494 | + "src/test/resources/SelfResolutionRpcWithOneTypedefAndTwoGroupingUnderDifferentNode.yang"); | ||
495 | + | ||
496 | + // Check whether the data model tree returned is of type module. | ||
497 | + assertThat((node instanceof YangModule), is(true)); | ||
498 | + | ||
499 | + // Check whether the node type is set properly to module. | ||
500 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
501 | + | ||
502 | + // Check whether the module name is set correctly. | ||
503 | + YangModule yangNode = (YangModule) node; | ||
504 | + assertThat(yangNode.getName(), is("rock")); | ||
505 | + | ||
506 | + ListIterator<YangLeaf> leafIterator; | ||
507 | + YangLeaf leafInfo; | ||
508 | + | ||
509 | + // Check whether grouping is the child of input. | ||
510 | + assertThat((yangNode.getChild().getChild().getChild() instanceof YangGrouping), is(true)); | ||
511 | + YangGrouping groupingUnderInput = (YangGrouping) yangNode.getChild().getChild().getChild(); | ||
512 | + | ||
513 | + // Check whether the grouping name is set correctly. | ||
514 | + assertThat(groupingUnderInput.getName(), is("creative")); | ||
515 | + | ||
516 | + leafIterator = groupingUnderInput.getListOfLeaf().listIterator(); | ||
517 | + leafInfo = leafIterator.next(); | ||
518 | + | ||
519 | + // Check whether the information in the leaf is correct under grouping. | ||
520 | + assertThat(leafInfo.getLeafName(), is("carry")); | ||
521 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("string")); | ||
522 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING)); | ||
523 | + | ||
524 | + // Check whether grouping is the child of output. | ||
525 | + assertThat((yangNode.getChild().getChild().getNextSibling().getChild() instanceof YangGrouping), is(true)); | ||
526 | + YangGrouping grouping = (YangGrouping) yangNode.getChild().getChild().getNextSibling().getChild(); | ||
527 | + assertThat(grouping.getName(), is("creative")); | ||
528 | + | ||
529 | + // Check whether typedef is the sibling of grouping. | ||
530 | + assertThat((grouping.getNextSibling() instanceof YangTypeDef), is(true)); | ||
531 | + | ||
532 | + YangTypeDef typedef = (YangTypeDef) grouping.getNextSibling(); | ||
533 | + assertThat(typedef.getName(), is("my-type")); | ||
534 | + | ||
535 | + // Check whether uses is the sibling of typedef. | ||
536 | + assertThat((typedef.getNextSibling() instanceof YangUses), is(true)); | ||
537 | + | ||
538 | + // Check whether uses get resolved. | ||
539 | + YangUses uses = (YangUses) typedef.getNextSibling(); | ||
540 | + assertThat(uses.getName(), is("creative")); | ||
541 | + assertThat(uses.getResolvableStatus(), | ||
542 | + is(ResolvableStatus.RESOLVED)); | ||
543 | + | ||
544 | + // Check whether list is the sibling of uses. | ||
545 | + assertThat((uses.getNextSibling() instanceof YangList), is(true)); | ||
546 | + YangList list = (YangList) uses.getNextSibling(); | ||
547 | + assertThat(list.getName(), is("valid")); | ||
548 | + | ||
549 | + leafIterator = list.getListOfLeaf().listIterator(); | ||
550 | + leafInfo = leafIterator.next(); | ||
551 | + | ||
552 | + // Check whether the information in the leaf is correct under list. | ||
553 | + assertThat(leafInfo.getLeafName(), is("invalid-interval")); | ||
554 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16")); | ||
555 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16)); | ||
556 | + } | ||
557 | + | ||
558 | + /** | ||
559 | + * Checks the failure scenario when uses is cannot resolve its grouping. | ||
560 | + */ | ||
561 | + @Test | ||
562 | + public void processSelfResolutionNestedGroupingWithUnresolvedUses() | ||
563 | + throws IOException, ParserException { | ||
564 | + | ||
565 | + thrown.expect(ParserException.class); | ||
566 | + thrown.expectMessage( | ||
567 | + "YANG file error: Unable to find base typedef/grouping for given type/uses"); | ||
568 | + | ||
569 | + YangNode node = manager | ||
570 | + .getDataModel("src/test/resources/SelfResolutionNestedGroupingWithUnresolvedUses.yang"); | ||
571 | + } | ||
572 | + | ||
573 | + /** | ||
574 | + * Checks self resolution when typedef hierarchical references are present | ||
575 | + * with last type is unresolved. | ||
576 | + */ | ||
577 | + @Test | ||
578 | + public void processSelfFileLinkingWithGroupingHierarchicalRefUnresolved() | ||
579 | + throws IOException, ParserException { | ||
580 | + | ||
581 | + YangNode node = manager | ||
582 | + .getDataModel("src/test/resources/SelfFileLinkingWithGroupingHierarchicalRefUnresolved.yang"); | ||
583 | + | ||
584 | + // Check whether the data model tree returned is of type module. | ||
585 | + assertThat((node instanceof YangModule), is(true)); | ||
586 | + | ||
587 | + // Check whether the node type is set properly to module. | ||
588 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
589 | + | ||
590 | + // Check whether the module name is set correctly. | ||
591 | + YangModule yangNode = (YangModule) node; | ||
592 | + assertThat(yangNode.getName(), is("Test")); | ||
593 | + | ||
594 | + // Check whether container is the sibling of grouping. | ||
595 | + assertThat((yangNode.getChild().getNextSibling() instanceof YangContainer), is(true)); | ||
596 | + YangContainer containerWithUses = (YangContainer) yangNode.getChild().getNextSibling(); | ||
597 | + assertThat(containerWithUses.getName(), is("test")); | ||
598 | + | ||
599 | + // Check whether uses is the child of container. | ||
600 | + assertThat((containerWithUses.getChild() instanceof YangUses), is(true)); | ||
601 | + YangUses uses = (YangUses) containerWithUses.getChild(); | ||
602 | + assertThat(uses.getName(), is("create")); | ||
603 | + | ||
604 | + // Check whether uses is getting resolved. | ||
605 | + assertThat(uses.getResolvableStatus(), | ||
606 | + is(ResolvableStatus.RESOLVED)); | ||
607 | + | ||
608 | + // Check whether grouping is the child of module. | ||
609 | + assertThat((yangNode.getChild() instanceof YangGrouping), is(true)); | ||
610 | + YangGrouping groupingWithUses = (YangGrouping) yangNode.getChild(); | ||
611 | + assertThat(groupingWithUses.getName(), is("create")); | ||
612 | + | ||
613 | + // Check whether uses with prefix from from other file, is the child of grouping. | ||
614 | + assertThat((groupingWithUses.getChild() instanceof YangUses), is(true)); | ||
615 | + YangUses uses1 = (YangUses) groupingWithUses.getChild(); | ||
616 | + assertThat(uses1.getName(), is("valid")); | ||
617 | + | ||
618 | + // Check whether this uses is getting intra-file-resolved. | ||
619 | + assertThat(uses1.getResolvableStatus(), | ||
620 | + is(ResolvableStatus.INTRA_FILE_RESOLVED)); | ||
621 | + } | ||
622 | + | ||
623 | + /** | ||
624 | + * Checks self resolution when uses has prefix of self module. | ||
625 | + */ | ||
626 | + @Test | ||
627 | + public void processSelfFileLinkingWithGroupingWithSelfModulePrefix() | ||
628 | + throws IOException, ParserException { | ||
629 | + | ||
630 | + YangNode node = manager.getDataModel("src/test/resources/SelfFileLinkingWithGroupingWithSelfModulePrefix.yang"); | ||
631 | + | ||
632 | + // Check whether the data model tree returned is of type module. | ||
633 | + assertThat((node instanceof YangModule), is(true)); | ||
634 | + | ||
635 | + // Check whether the node type is set properly to module. | ||
636 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
637 | + | ||
638 | + // Check whether the module name is set correctly. | ||
639 | + YangModule yangNode = (YangModule) node; | ||
640 | + assertThat(yangNode.getName(), is("Test")); | ||
641 | + | ||
642 | + // Check whether container is the sibling of grouping. | ||
643 | + YangContainer yangContainer = (YangContainer) node.getChild().getNextSibling(); | ||
644 | + | ||
645 | + // Check whether list is the child of container. | ||
646 | + YangList yangList = (YangList) yangContainer.getChild(); | ||
647 | + | ||
648 | + // Check whether uses is the child of list. | ||
649 | + assertThat((yangList.getChild() instanceof YangUses), is(true)); | ||
650 | + YangUses yangUses1 = (YangUses) yangList.getChild(); | ||
651 | + assertThat(yangUses1.getName(), is("FirstClass")); | ||
652 | + | ||
653 | + // Check whether uses is getting resolved. | ||
654 | + assertThat(yangUses1.getResolvableStatus(), | ||
655 | + is(ResolvableStatus.RESOLVED)); | ||
656 | + | ||
657 | + // Check whether grouping is the sibling of uses. | ||
658 | + YangGrouping yangGrouping1 = (YangGrouping) yangUses1.getNextSibling(); | ||
659 | + assertThat(yangGrouping1.getName(), is("FirstClass")); | ||
660 | + | ||
661 | + // Check whether uses is the child of grouping. | ||
662 | + YangUses yangUses2 = (YangUses) yangGrouping1.getChild(); | ||
663 | + assertThat(yangUses2.getName(), is("PassingClass")); | ||
664 | + | ||
665 | + // Check the uses gets resolved. | ||
666 | + assertThat(yangUses2.getResolvableStatus(), | ||
667 | + is(ResolvableStatus.RESOLVED)); | ||
668 | + | ||
669 | + // Check whether grouping is the sibling of list. | ||
670 | + YangGrouping yangGrouping2 = (YangGrouping) yangList.getNextSibling(); | ||
671 | + assertThat(yangGrouping2.getName(), is("PassingClass")); | ||
672 | + | ||
673 | + // Check uses is the child of that grouping which has prefix of the same module. | ||
674 | + YangUses yangUses3 = (YangUses) yangGrouping2.getChild(); | ||
675 | + assertThat(yangUses3.getName(), is("Percentage")); | ||
676 | + | ||
677 | + // Check uses is getting resolved. | ||
678 | + assertThat(yangUses3.getResolvableStatus(), | ||
679 | + is(ResolvableStatus.RESOLVED)); | ||
680 | + | ||
681 | + // Check grouping is the child of module. | ||
682 | + YangGrouping yangGrouping3 = (YangGrouping) node.getChild(); | ||
683 | + | ||
684 | + ListIterator<YangLeaf> leafIterator; | ||
685 | + YangLeaf leafInfo; | ||
686 | + leafIterator = yangGrouping3.getListOfLeaf().listIterator(); | ||
687 | + leafInfo = leafIterator.next(); | ||
688 | + | ||
689 | + // Check whether the information in the leaf is correct under grouping. | ||
690 | + assertThat(leafInfo.getLeafName(), is("hello")); | ||
691 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("String")); | ||
692 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING)); | ||
693 | + | ||
694 | + } | ||
695 | + | ||
696 | + /** | ||
697 | + * Checks self resolution when some type uses prefix of self module | ||
698 | + * some uses external prefix. | ||
699 | + */ | ||
700 | + @Test | ||
701 | + public void processSelfFileLinkingWithGroupingWithSelfAndExternalPrefixMix() | ||
702 | + throws IOException, ParserException { | ||
703 | + | ||
704 | + YangNode node = manager | ||
705 | + .getDataModel("src/test/resources/SelfFileLinkingWithGroupingWithSelfAndExternalPrefixMix.yang"); | ||
706 | + | ||
707 | + // Check whether the data model tree returned is of type module. | ||
708 | + assertThat((node instanceof YangModule), is(true)); | ||
709 | + | ||
710 | + // Check whether the node type is set properly to module. | ||
711 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
712 | + | ||
713 | + // Check whether the module name is set correctly. | ||
714 | + YangModule yangNode = (YangModule) node; | ||
715 | + assertThat(yangNode.getName(), is("Test")); | ||
716 | + | ||
717 | + // Check whether container is the sibling of grouping. | ||
718 | + YangContainer yangContainer = (YangContainer) node.getChild().getNextSibling(); | ||
719 | + | ||
720 | + // Check whether list is the child of container. | ||
721 | + YangList yangList = (YangList) yangContainer.getChild(); | ||
722 | + | ||
723 | + // Check whether uses is the child of list. | ||
724 | + assertThat((yangList.getChild() instanceof YangUses), is(true)); | ||
725 | + YangUses yangUses1 = (YangUses) yangList.getChild(); | ||
726 | + assertThat(yangUses1.getName(), is("FirstClass")); | ||
727 | + | ||
728 | + // Check whether uses is getting resolved. | ||
729 | + assertThat(yangUses1.getResolvableStatus(), | ||
730 | + is(ResolvableStatus.RESOLVED)); | ||
731 | + | ||
732 | + // Check whether grouping is the sibling of uses. | ||
733 | + YangGrouping yangGrouping1 = (YangGrouping) yangUses1.getNextSibling(); | ||
734 | + assertThat(yangGrouping1.getName(), is("FirstClass")); | ||
735 | + | ||
736 | + // Check whether uses is the child of grouping which has prefix from other module. | ||
737 | + YangUses yangUses2 = (YangUses) yangGrouping1.getChild(); | ||
738 | + assertThat(yangUses2.getName(), is("PassingClass")); | ||
739 | + | ||
740 | + // Check whether uses gets intra-file-resolved. | ||
741 | + assertThat(yangUses2.getResolvableStatus(), | ||
742 | + is(ResolvableStatus.INTRA_FILE_RESOLVED)); | ||
743 | + | ||
744 | + // Check whether grouping is the sibling of list. | ||
745 | + YangGrouping yangGrouping2 = (YangGrouping) yangList.getNextSibling(); | ||
746 | + assertThat(yangGrouping2.getName(), is("PassingClass")); | ||
747 | + | ||
748 | + // Check uses is the child of that grouping which has prefix of the same module. | ||
749 | + YangUses yangUses3 = (YangUses) yangGrouping2.getChild(); | ||
750 | + assertThat(yangUses3.getName(), is("Percentage")); | ||
751 | + | ||
752 | + // Check uses is getting resolved. | ||
753 | + assertThat(yangUses3.getResolvableStatus(), | ||
754 | + is(ResolvableStatus.RESOLVED)); | ||
755 | + | ||
756 | + // Check grouping is the child of module. | ||
757 | + YangGrouping yangGrouping3 = (YangGrouping) node.getChild(); | ||
758 | + ListIterator<YangLeaf> leafIterator; | ||
759 | + YangLeaf leafInfo; | ||
760 | + leafIterator = yangGrouping3.getListOfLeaf().listIterator(); | ||
761 | + leafInfo = leafIterator.next(); | ||
762 | + | ||
763 | + // Check whether the information in the leaf is correct under grouping. | ||
764 | + assertThat(leafInfo.getLeafName(), is("hello")); | ||
765 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("String")); | ||
766 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING)); | ||
767 | + } | ||
768 | + | ||
769 | +} |
... | @@ -19,6 +19,7 @@ package org.onosproject.yangutils.parser.impl.listeners; | ... | @@ -19,6 +19,7 @@ package org.onosproject.yangutils.parser.impl.listeners; |
19 | import java.io.IOException; | 19 | import java.io.IOException; |
20 | import org.junit.Test; | 20 | import org.junit.Test; |
21 | import org.onosproject.yangutils.datamodel.YangContainer; | 21 | import org.onosproject.yangutils.datamodel.YangContainer; |
22 | +import org.onosproject.yangutils.datamodel.YangGrouping; | ||
22 | import org.onosproject.yangutils.datamodel.YangList; | 23 | import org.onosproject.yangutils.datamodel.YangList; |
23 | import org.onosproject.yangutils.datamodel.YangModule; | 24 | import org.onosproject.yangutils.datamodel.YangModule; |
24 | import org.onosproject.yangutils.datamodel.YangNode; | 25 | import org.onosproject.yangutils.datamodel.YangNode; |
... | @@ -56,7 +57,10 @@ public class UsesListenerTest { | ... | @@ -56,7 +57,10 @@ public class UsesListenerTest { |
56 | YangModule yangNode = (YangModule) node; | 57 | YangModule yangNode = (YangModule) node; |
57 | assertThat(yangNode.getName(), is("Test")); | 58 | assertThat(yangNode.getName(), is("Test")); |
58 | 59 | ||
59 | - YangUses yangUses = (YangUses) yangNode.getChild(); | 60 | + YangGrouping yangGrouping = (YangGrouping) yangNode.getChild(); |
61 | + assertThat(yangGrouping.getName(), is("endpoint")); | ||
62 | + | ||
63 | + YangUses yangUses = (YangUses) yangGrouping.getNextSibling(); | ||
60 | assertThat(yangUses.getName(), is("endpoint")); | 64 | assertThat(yangUses.getName(), is("endpoint")); |
61 | } | 65 | } |
62 | 66 | ||
... | @@ -78,7 +82,10 @@ public class UsesListenerTest { | ... | @@ -78,7 +82,10 @@ public class UsesListenerTest { |
78 | YangModule yangNode = (YangModule) node; | 82 | YangModule yangNode = (YangModule) node; |
79 | assertThat(yangNode.getName(), is("Test")); | 83 | assertThat(yangNode.getName(), is("Test")); |
80 | 84 | ||
81 | - YangContainer yangContainer = (YangContainer) yangNode.getChild(); | 85 | + YangGrouping yangGrouping = (YangGrouping) yangNode.getChild(); |
86 | + assertThat(yangGrouping.getName(), is("endpoint")); | ||
87 | + | ||
88 | + YangContainer yangContainer = (YangContainer) yangGrouping.getNextSibling(); | ||
82 | assertThat(yangContainer.getName(), is("valid")); | 89 | assertThat(yangContainer.getName(), is("valid")); |
83 | 90 | ||
84 | YangUses yangUses = (YangUses) yangContainer.getChild(); | 91 | YangUses yangUses = (YangUses) yangContainer.getChild(); |
... | @@ -108,7 +115,10 @@ public class UsesListenerTest { | ... | @@ -108,7 +115,10 @@ public class UsesListenerTest { |
108 | YangModule yangNode = (YangModule) node; | 115 | YangModule yangNode = (YangModule) node; |
109 | assertThat(yangNode.getName(), is("Test")); | 116 | assertThat(yangNode.getName(), is("Test")); |
110 | 117 | ||
111 | - YangList yangList = (YangList) yangNode.getChild(); | 118 | + YangGrouping yangGrouping = (YangGrouping) yangNode.getChild(); |
119 | + assertThat(yangGrouping.getName(), is("endpoint")); | ||
120 | + | ||
121 | + YangList yangList = (YangList) yangGrouping.getNextSibling(); | ||
112 | assertThat(yangList.getName(), is("valid")); | 122 | assertThat(yangList.getName(), is("valid")); |
113 | 123 | ||
114 | YangUses yangUses = (YangUses) yangList.getChild(); | 124 | YangUses yangUses = (YangUses) yangList.getChild(); | ... | ... |
utils/yangutils/src/test/resources/SelfFileLinkingWithGroupingWithSelfAndExternalPrefixMix.yang
0 → 100644
1 | +module Test { | ||
2 | + yang-version 1; | ||
3 | + namespace http://huawei.com; | ||
4 | + prefix Ant; | ||
5 | + import ietf-yang-types { | ||
6 | + prefix "P"; | ||
7 | + } | ||
8 | + grouping Percentage { | ||
9 | + leaf hello{ | ||
10 | + type String; | ||
11 | + } | ||
12 | + } | ||
13 | + container ospf { | ||
14 | + list valid { | ||
15 | + key "invalid"; | ||
16 | + leaf invalid{ | ||
17 | + type String; | ||
18 | + } | ||
19 | + uses Ant:FirstClass; | ||
20 | + grouping FirstClass { | ||
21 | + uses P:PassingClass; | ||
22 | + } | ||
23 | + } | ||
24 | + grouping PassingClass { | ||
25 | + uses Ant:Percentage; | ||
26 | + } | ||
27 | + } | ||
28 | +} |
1 | +module Test { | ||
2 | + yang-version 1; | ||
3 | + namespace http://huawei.com; | ||
4 | + prefix Ant; | ||
5 | + grouping Percentage { | ||
6 | + leaf hello{ | ||
7 | + type String; | ||
8 | + } | ||
9 | + } | ||
10 | + container ospf { | ||
11 | + list valid { | ||
12 | + key "invalid"; | ||
13 | + leaf invalid{ | ||
14 | + type String; | ||
15 | + } | ||
16 | + uses Ant:FirstClass; | ||
17 | + grouping FirstClass { | ||
18 | + uses PassingClass; | ||
19 | + } | ||
20 | + } | ||
21 | + grouping PassingClass { | ||
22 | + uses Ant:Percentage; | ||
23 | + } | ||
24 | + } | ||
25 | +} |
1 | +module Test { | ||
2 | + yang-version 1; | ||
3 | + namespace http://huawei.com; | ||
4 | + prefix Ant; | ||
5 | + container valid { | ||
6 | + grouping endpoint { | ||
7 | + leaf zip-code { | ||
8 | + type string; | ||
9 | + } | ||
10 | + uses failure; | ||
11 | + container hold { | ||
12 | + leaf newone { | ||
13 | + type string; | ||
14 | + } | ||
15 | + | ||
16 | + } | ||
17 | + uses failure; | ||
18 | + } | ||
19 | + grouping failure { | ||
20 | + leaf test { | ||
21 | + type string; | ||
22 | + } | ||
23 | + } | ||
24 | + } | ||
25 | +} |
1 | +module rock { | ||
2 | + namespace "http://example.net/rock"; | ||
3 | + prefix "rock"; | ||
4 | + | ||
5 | + rpc rock-the-house { | ||
6 | + description "description"; | ||
7 | + status current; | ||
8 | + reference "reference"; | ||
9 | + grouping hello { | ||
10 | + list valid { | ||
11 | + key invalid-interval; | ||
12 | + reference "RFC 6020"; | ||
13 | + leaf invalid-interval { | ||
14 | + type "uint16"; | ||
15 | + units "seconds"; | ||
16 | + status current; | ||
17 | + reference "RFC 6020"; | ||
18 | + } | ||
19 | + } | ||
20 | + } | ||
21 | + input { | ||
22 | + leaf zip-code { | ||
23 | + type string; | ||
24 | + } | ||
25 | + uses hello; | ||
26 | + } | ||
27 | + output { | ||
28 | + leaf status { | ||
29 | + type string; | ||
30 | + } | ||
31 | + uses hello; | ||
32 | + } | ||
33 | + } | ||
34 | +} |
1 | +module Test { | ||
2 | + yang-version 1; | ||
3 | + namespace http://huawei.com; | ||
4 | + prefix Ant; | ||
5 | + container valid { | ||
6 | + grouping endpoint { | ||
7 | + leaf zip-code { | ||
8 | + type string; | ||
9 | + } | ||
10 | + uses first; | ||
11 | + container design { | ||
12 | + uses second; | ||
13 | + container correct { | ||
14 | + leaf newone { | ||
15 | + type string; | ||
16 | + } | ||
17 | + uses third; | ||
18 | + } | ||
19 | + } | ||
20 | + uses fourth; | ||
21 | + uses fifth; | ||
22 | + } | ||
23 | + uses endpoint; | ||
24 | + grouping first { | ||
25 | + list valid { | ||
26 | + key invalid-interval; | ||
27 | + reference "RFC 6020"; | ||
28 | + leaf invalid-interval { | ||
29 | + type "uint16"; | ||
30 | + units "seconds"; | ||
31 | + status current; | ||
32 | + reference "RFC 6020"; | ||
33 | + } | ||
34 | + } | ||
35 | + } | ||
36 | + grouping second { | ||
37 | + leaf ink { | ||
38 | + type int32; | ||
39 | + } | ||
40 | + } | ||
41 | + grouping third { | ||
42 | + container value { | ||
43 | + leaf zip-code { | ||
44 | + type string; | ||
45 | + } | ||
46 | + } | ||
47 | + } | ||
48 | + grouping fourth { | ||
49 | + typedef my-type { | ||
50 | + status deprecated; | ||
51 | + type int32; | ||
52 | + } | ||
53 | + leaf correct { | ||
54 | + type my-type; | ||
55 | + } | ||
56 | + } | ||
57 | + grouping fifth { | ||
58 | + leaf abc { | ||
59 | + type string; | ||
60 | + } | ||
61 | + } | ||
62 | + } | ||
63 | +} |
1 | +module rock { | ||
2 | + namespace "http://example.net/rock"; | ||
3 | + prefix "rock"; | ||
4 | + | ||
5 | + rpc rock-the-house { | ||
6 | + description "description"; | ||
7 | + status current; | ||
8 | + reference "reference"; | ||
9 | + input { | ||
10 | + leaf zip-code { | ||
11 | + type string; | ||
12 | + } | ||
13 | + grouping creative { | ||
14 | + leaf carry { | ||
15 | + type string; | ||
16 | + } | ||
17 | + } | ||
18 | + } | ||
19 | + output { | ||
20 | + leaf status { | ||
21 | + type string; | ||
22 | + } | ||
23 | + grouping creative { | ||
24 | + list valid { | ||
25 | + key invalid-interval; | ||
26 | + leaf invalid-interval { | ||
27 | + type "uint16"; | ||
28 | + } | ||
29 | + } | ||
30 | + } | ||
31 | + typedef my-type { | ||
32 | + status deprecated; | ||
33 | + type int32; | ||
34 | + } | ||
35 | + uses creative; | ||
36 | + } | ||
37 | + } | ||
38 | +} |
... | @@ -2,6 +2,8 @@ module Test { | ... | @@ -2,6 +2,8 @@ module Test { |
2 | yang-version 1; | 2 | yang-version 1; |
3 | namespace http://huawei.com; | 3 | namespace http://huawei.com; |
4 | prefix Ant; | 4 | prefix Ant; |
5 | + grouping endpoint { | ||
6 | + } | ||
5 | container valid { | 7 | container valid { |
6 | uses endpoint { | 8 | uses endpoint { |
7 | description "grouping under test"; | 9 | description "grouping under test"; | ... | ... |
-
Please register or login to post a comment