YANG uses and UT
Change-Id: Id3ec5cfed2b8e2a7d2d580786c70b5804f03ecfa
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangNode.java b/src/main/java/org/onosproject/yangutils/datamodel/YangNode.java
index 0413e65..ae29433 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangNode.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangNode.java
@@ -16,6 +16,7 @@
package org.onosproject.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.translator.tojava.TraversalType;
import static org.onosproject.yangutils.translator.tojava.TraversalType.CHILD;
@@ -281,9 +282,11 @@
if (nextNodeToClone == null) {
throw new DataModelException("Internal error: Cloning failed, source tree null pointer reached");
}
-
- if (curTraversal == CHILD) {
+ if (curTraversal != PARENT) {
newNode = nextNodeToClone.clone();
+ detectCollisionWhileCloning(clonedTreeCurNode, newNode, curTraversal);
+ }
+ if (curTraversal == CHILD) {
/**
* add the new node to the cloned tree.
@@ -295,7 +298,6 @@
*/
clonedTreeCurNode = newNode;
} else if (curTraversal == SIBILING) {
- newNode = nextNodeToClone.clone();
clonedTreeCurNode.addNextSibling(newNode);
clonedTreeCurNode = newNode;
@@ -328,6 +330,38 @@
}
/**
+ * Detects collision when the grouping is deep copied to the uses's parent.
+ *
+ * @param currentNode parent/previous sibling node for the new node
+ * @param newNode node which has to be added
+ * @param addAs traversal type of the node
+ * @throws DataModelException data model error
+ */
+ private static void detectCollisionWhileCloning(YangNode currentNode, YangNode newNode, TraversalType addAs)
+ throws DataModelException {
+ if ((!(currentNode instanceof CollisionDetector))
+ || (!(newNode instanceof Parsable))) {
+ throw new DataModelException("Node in data model tree does not support collision detection");
+ }
+
+ CollisionDetector collisionDetector = (CollisionDetector) currentNode;
+ Parsable parsable = (Parsable) newNode;
+ if (addAs == TraversalType.CHILD) {
+ collisionDetector.detectCollidingChild(newNode.getName(), parsable.getYangConstructType());
+ } else if (addAs == TraversalType.SIBILING) {
+ currentNode = currentNode.getParent();
+ if (!(currentNode instanceof CollisionDetector)) {
+ throw new DataModelException("Node in data model tree does not support collision detection");
+ }
+ collisionDetector = (CollisionDetector) currentNode;
+ collisionDetector.detectCollidingChild(newNode.getName(), parsable.getYangConstructType());
+ } else {
+ throw new DataModelException("Errored tree cloning");
+ }
+
+ }
+
+ /**
* Add a new next sibling.
*
* @param newSibling new sibling to be added
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangUses.java b/src/main/java/org/onosproject/yangutils/datamodel/YangUses.java
index 7f9b4a3..16f45c4 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangUses.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangUses.java
@@ -19,6 +19,7 @@
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.utils.YangConstructType;
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getParentNodeInGenCode;
/*-
@@ -56,7 +57,7 @@
*/
public class YangUses
extends YangNode
- implements YangCommonInfo, Parsable, Resolvable {
+ implements YangCommonInfo, Parsable, Resolvable, CollisionDetector {
/**
* YANG node identifier.
@@ -267,18 +268,23 @@
}
YangNode usesParentNode = getParentNodeInGenCode(this);
- if (!(usesParentNode instanceof YangLeavesHolder)) {
+ if ((!(usesParentNode instanceof YangLeavesHolder))
+ || (!(usesParentNode instanceof CollisionDetector))) {
throw new DataModelException("YANG uses holder construct is wrong");
}
YangLeavesHolder usesParentLeavesHolder = (YangLeavesHolder) usesParentNode;
if (referredGrouping.getListOfLeaf() != null) {
for (YangLeaf leaf : referredGrouping.getListOfLeaf()) {
+ ((CollisionDetector) usesParentLeavesHolder).detectCollidingChild(leaf.getLeafName(),
+ YangConstructType.LEAF_DATA);
usesParentLeavesHolder.addLeaf(leaf);
}
}
if (referredGrouping.getListOfLeafList() != null) {
for (YangLeafList leafList : referredGrouping.getListOfLeafList()) {
+ ((CollisionDetector) usesParentLeavesHolder).detectCollidingChild(leafList.getLeafName(),
+ YangConstructType.LEAF_LIST_DATA);
usesParentLeavesHolder.addLeafList(leafList);
}
}
@@ -295,4 +301,19 @@
public void setResolvableStatus(ResolvableStatus resolvableStatus) {
this.resolvableStatus = resolvableStatus;
}
+
+ @Override
+ public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
+ detectCollidingChildUtil(identifierName, dataType, this);
+ }
+
+ @Override
+ public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
+
+ if (getName().equals(identifierName)) {
+ throw new DataModelException("YANG file error: Duplicate input identifier detected, same as uses \""
+ + getName() + "\"");
+ }
+ }
+
}
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java b/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java
index 643eda5..e848299 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java
@@ -27,9 +27,9 @@
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangResolutionInfo;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.utils.YangConstructType;
-
/**
* Represents utilities for data model tree.
*/
@@ -53,21 +53,44 @@
public static void detectCollidingChildUtil(String identifierName, YangConstructType dataType, YangNode node)
throws DataModelException {
- if (dataType == YangConstructType.LEAF_DATA) {
- YangLeavesHolder leavesHolder = (YangLeavesHolder) node;
- if (leavesHolder.getListOfLeaf() != null) {
- detectCollidingLeaf(leavesHolder, identifierName);
- }
- }
- if (dataType == YangConstructType.LEAF_LIST_DATA) {
- if (((YangLeavesHolder) node).getListOfLeafList() != null) {
+ if (dataType == YangConstructType.USES_DATA || dataType == YangConstructType.GROUPING_DATA) {
+ detectCollidingForUsesGrouping(identifierName, dataType, node);
+ } else {
+ if (node instanceof YangLeavesHolder) {
YangLeavesHolder leavesHolder = (YangLeavesHolder) node;
- detectCollidingLeafList(leavesHolder, identifierName);
+ detectCollidingLeaf(leavesHolder.getListOfLeaf(), identifierName);
+ detectCollidingLeafList(leavesHolder.getListOfLeafList(), identifierName);
+ }
+ node = node.getChild();
+ while (node != null) {
+ Parsable parsable = (Parsable) node;
+ if (node instanceof CollisionDetector
+ && (parsable.getYangConstructType() != YangConstructType.USES_DATA)
+ && (parsable.getYangConstructType() != YangConstructType.GROUPING_DATA)) {
+ ((CollisionDetector) node).detectSelfCollision(identifierName, dataType);
+ }
+ node = node.getNextSibling();
}
}
+ }
+
+ /**
+ * Detects colliding of uses and grouping only with uses and grouping respectively.
+ *
+ * @param identifierName name for which collision detection is to be
+ * checked
+ * @param dataType type of YANG node asking for detecting collision
+ * @param node node instance of calling node
+ * @throws DataModelException a violation of data model rules
+ */
+ public static void detectCollidingForUsesGrouping(String identifierName, YangConstructType dataType, YangNode node)
+ throws DataModelException {
+
node = node.getChild();
while (node != null) {
- if (node instanceof CollisionDetector) {
+ Parsable parsable = (Parsable) node;
+ if (node instanceof CollisionDetector
+ && (parsable.getYangConstructType() == dataType)) {
((CollisionDetector) node).detectSelfCollision(identifierName, dataType);
}
node = node.getNextSibling();
@@ -77,15 +100,18 @@
/**
* Detects the colliding identifier name in a given leaf node.
*
- * @param leavesHolder leaves node against which collision to be checked
+ * @param listOfLeaf List of leaves to detect collision
* @param identifierName name for which collision detection is to be
* checked
* @throws DataModelException a violation of data model rules
*/
- private static void detectCollidingLeaf(YangLeavesHolder leavesHolder, String identifierName)
+ private static void detectCollidingLeaf(List<YangLeaf> listOfLeaf, String identifierName)
throws DataModelException {
- for (YangLeaf leaf : leavesHolder.getListOfLeaf()) {
+ if (listOfLeaf == null) {
+ return;
+ }
+ for (YangLeaf leaf : listOfLeaf) {
if (leaf.getLeafName().equals(identifierName)) {
throw new DataModelException("YANG file error: Duplicate input identifier detected, same as leaf \""
+ leaf.getLeafName() + "\"");
@@ -96,15 +122,18 @@
/**
* Detects the colliding identifier name in a given leaf-list node.
*
- * @param leavesHolder leaves node against which collision to be checked
+ * @param listOfLeafList list of leaf-lists to detect collision
* @param identifierName name for which collision detection is to be
* checked
* @throws DataModelException a violation of data model rules
*/
- private static void detectCollidingLeafList(YangLeavesHolder leavesHolder, String identifierName)
+ private static void detectCollidingLeafList(List<YangLeafList> listOfLeafList, String identifierName)
throws DataModelException {
- for (YangLeafList leafList : leavesHolder.getListOfLeafList()) {
+ if (listOfLeafList == null) {
+ return;
+ }
+ for (YangLeafList leafList : listOfLeafList) {
if (leafList.getLeafName().equals(identifierName)) {
throw new DataModelException("YANG file error: Duplicate input identifier detected, same as leaf " +
"list \"" + leafList.getLeafName() + "\"");
@@ -122,8 +151,6 @@
public static void addResolutionInfo(YangResolutionInfo resolutionInfo)
throws DataModelException {
-
-
/* get the module node to add maintain the list of nested reference */
YangNode curNode = resolutionInfo.getEntityToResolveInfo()
.getHolderOfEntityToResolve();
@@ -142,6 +169,13 @@
resolutionNode.addToResolutionList(resolutionInfo);
}
+ /**
+ * Evaluates whether the prefix in uses/type is valid.
+ *
+ * @param entityPrefix prefix in the current module/sub-module
+ * @param resolutionNode uses/type node which has the prefix with it
+ * @return whether prefix is valid or not
+ */
private static boolean isPrefixValid(String entityPrefix, HasResolutionInfo resolutionNode) {
if (entityPrefix == null) {
return true;
diff --git a/src/main/java/org/onosproject/yangutils/parser/antlrgencode/GeneratedYangListener.java b/src/main/java/org/onosproject/yangutils/parser/antlrgencode/GeneratedYangListener.java
index 8304c8e..14c07b7 100644
--- a/src/main/java/org/onosproject/yangutils/parser/antlrgencode/GeneratedYangListener.java
+++ b/src/main/java/org/onosproject/yangutils/parser/antlrgencode/GeneratedYangListener.java
@@ -1565,22 +1565,6 @@
/**
* Enter a parse tree produced by GeneratedYangParser for grammar rule
- * inputStatementBody.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterInputStatementBody(GeneratedYangParser.InputStatementBodyContext currentContext);
-
- /**
- * Exit a parse tree produced by GeneratedYangParser for grammar rule
- * inputStatementBody.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitInputStatementBody(GeneratedYangParser.InputStatementBodyContext currentContext);
-
- /**
- * Enter a parse tree produced by GeneratedYangParser for grammar rule
* outputStatement.
*
* @param currentContext current context in the parsed tree
@@ -1597,22 +1581,6 @@
/**
* Enter a parse tree produced by GeneratedYangParser for grammar rule
- * outputStatementBody.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterOutputStatementBody(GeneratedYangParser.OutputStatementBodyContext currentContext);
-
- /**
- * Exit a parse tree produced by GeneratedYangParser for grammar rule
- * outputStatementBody.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitOutputStatementBody(GeneratedYangParser.OutputStatementBodyContext currentContext);
-
- /**
- * Enter a parse tree produced by GeneratedYangParser for grammar rule
* notificationStatement.
*
* @param currentContext current context in the parsed tree
diff --git a/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java b/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java
index 51f3928..c1c84a1 100644
--- a/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java
+++ b/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java
@@ -52,8 +52,8 @@
import org.onosproject.yangutils.parser.impl.listeners.MaxElementsListener;
import org.onosproject.yangutils.parser.impl.listeners.MinElementsListener;
import org.onosproject.yangutils.parser.impl.listeners.ModuleListener;
-import org.onosproject.yangutils.parser.impl.listeners.NotificationListener;
import org.onosproject.yangutils.parser.impl.listeners.NamespaceListener;
+import org.onosproject.yangutils.parser.impl.listeners.NotificationListener;
import org.onosproject.yangutils.parser.impl.listeners.OrganizationListener;
import org.onosproject.yangutils.parser.impl.listeners.OutputListener;
import org.onosproject.yangutils.parser.impl.listeners.PatternRestrictionListener;
@@ -1087,14 +1087,6 @@
}
@Override
- public void enterInputStatementBody(GeneratedYangParser.InputStatementBodyContext ctx) {
- }
-
- @Override
- public void exitInputStatementBody(GeneratedYangParser.InputStatementBodyContext ctx) {
- }
-
- @Override
public void enterOutputStatement(GeneratedYangParser.OutputStatementContext ctx) {
OutputListener.processOutputEntry(this, ctx);
}
@@ -1105,14 +1097,6 @@
}
@Override
- public void enterOutputStatementBody(GeneratedYangParser.OutputStatementBodyContext ctx) {
- }
-
- @Override
- public void exitOutputStatementBody(GeneratedYangParser.OutputStatementBodyContext ctx) {
- }
-
- @Override
public void enterNotificationStatement(GeneratedYangParser.NotificationStatementContext ctx) {
NotificationListener.processNotificationEntry(this, ctx);
}
diff --git a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/GroupingListener.java b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/GroupingListener.java
index c81e554..67dacbb 100644
--- a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/GroupingListener.java
+++ b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/GroupingListener.java
@@ -46,12 +46,10 @@
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateMutuallyExclusiveChilds;
import static org.onosproject.yangutils.utils.YangConstructType.DESCRIPTION_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.GROUPING_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.REFERENCE_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.STATUS_DATA;
-import static org.onosproject.yangutils.utils.YangConstructType.TYPEDEF_DATA;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
@@ -168,7 +166,5 @@
validateCardinalityMaxOne(ctx.descriptionStatement(), DESCRIPTION_DATA, GROUPING_DATA,
ctx.identifier().getText());
validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, GROUPING_DATA, ctx.identifier().getText());
- validateMutuallyExclusiveChilds(ctx.typedefStatement(), TYPEDEF_DATA, ctx.groupingStatement(), GROUPING_DATA,
- GROUPING_DATA, ctx.identifier().getText());
}
}
diff --git a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/InputListener.java b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/InputListener.java
index bb1ba85..78a5153 100644
--- a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/InputListener.java
+++ b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/InputListener.java
@@ -36,6 +36,8 @@
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityNonZero;
+import static org.onosproject.yangutils.utils.YangConstructType.DATA_DEF_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.INPUT_DATA;
/*
@@ -86,6 +88,9 @@
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, INPUT_DATA, "", ENTRY);
+ validateCardinalityNonZero(ctx.dataDefStatement(), DATA_DEF_DATA,
+ INPUT_DATA, "", ctx);
+
Parsable curData = listener.getParsedDataStack().peek();
if (curData instanceof YangRpc) {
diff --git a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ListListener.java b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ListListener.java
index a6c5496..42326b7 100644
--- a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ListListener.java
+++ b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ListListener.java
@@ -19,6 +19,7 @@
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangCase;
import org.onosproject.yangutils.datamodel.YangContainer;
+import org.onosproject.yangutils.datamodel.YangGrouping;
import org.onosproject.yangutils.datamodel.YangInput;
import org.onosproject.yangutils.datamodel.YangList;
import org.onosproject.yangutils.datamodel.YangModule;
@@ -140,7 +141,7 @@
if (curData instanceof YangModule || curData instanceof YangContainer
|| curData instanceof YangList || curData instanceof YangCase
|| curData instanceof YangNotification || curData instanceof YangInput
- || curData instanceof YangOutput || curData instanceof YangAugment) {
+ || curData instanceof YangOutput || curData instanceof YangAugment || curData instanceof YangGrouping) {
curNode = (YangNode) curData;
try {
curNode.addChild(yangList);
diff --git a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/NotificationListener.java b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/NotificationListener.java
index 58daefb..1bd7390 100644
--- a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/NotificationListener.java
+++ b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/NotificationListener.java
@@ -40,13 +40,10 @@
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateMutuallyExclusiveChilds;
import static org.onosproject.yangutils.utils.YangConstructType.DESCRIPTION_DATA;
-import static org.onosproject.yangutils.utils.YangConstructType.GROUPING_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.NOTIFICATION_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.REFERENCE_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.STATUS_DATA;
-import static org.onosproject.yangutils.utils.YangConstructType.TYPEDEF_DATA;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
@@ -159,7 +156,5 @@
ctx.identifier().getText());
validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, NOTIFICATION_DATA,
ctx.identifier().getText());
- validateMutuallyExclusiveChilds(ctx.typedefStatement(), TYPEDEF_DATA, ctx.groupingStatement(), GROUPING_DATA,
- NOTIFICATION_DATA, ctx.identifier().getText());
}
}
diff --git a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/OutputListener.java b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/OutputListener.java
index 2dfa2ed..83fec50 100644
--- a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/OutputListener.java
+++ b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/OutputListener.java
@@ -36,6 +36,8 @@
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityNonZero;
+import static org.onosproject.yangutils.utils.YangConstructType.DATA_DEF_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.OUTPUT_DATA;
/*
@@ -86,6 +88,9 @@
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, OUTPUT_DATA, "", ENTRY);
+ validateCardinalityNonZero(ctx.dataDefStatement(), DATA_DEF_DATA,
+ OUTPUT_DATA, "", ctx);
+
Parsable curData = listener.getParsedDataStack().peek();
if (curData instanceof YangRpc) {
diff --git a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RpcListener.java b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RpcListener.java
index ae9e04c..b440289 100644
--- a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RpcListener.java
+++ b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RpcListener.java
@@ -37,12 +37,9 @@
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateMutuallyExclusiveChilds;
import static org.onosproject.yangutils.utils.YangConstructType.RPC_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.INPUT_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.OUTPUT_DATA;
-import static org.onosproject.yangutils.utils.YangConstructType.TYPEDEF_DATA;
-import static org.onosproject.yangutils.utils.YangConstructType.GROUPING_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.STATUS_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.REFERENCE_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.DESCRIPTION_DATA;
@@ -157,8 +154,6 @@
validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, RPC_DATA, ctx.identifier().getText());
validateCardinalityMaxOne(ctx.inputStatement(), INPUT_DATA, RPC_DATA, ctx.identifier().getText());
validateCardinalityMaxOne(ctx.outputStatement(), OUTPUT_DATA, RPC_DATA, ctx.identifier().getText());
- validateMutuallyExclusiveChilds(ctx.typedefStatement(), TYPEDEF_DATA, ctx.groupingStatement(), GROUPING_DATA,
- RPC_DATA, ctx.identifier().getText());
}
}
diff --git a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeDefListener.java b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeDefListener.java
index bfa22a4..b0a3b69 100644
--- a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeDefListener.java
+++ b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeDefListener.java
@@ -17,6 +17,7 @@
package org.onosproject.yangutils.parser.impl.listeners;
import org.onosproject.yangutils.datamodel.YangContainer;
+import org.onosproject.yangutils.datamodel.YangGrouping;
import org.onosproject.yangutils.datamodel.YangInput;
import org.onosproject.yangutils.datamodel.YangList;
import org.onosproject.yangutils.datamodel.YangModule;
@@ -127,11 +128,8 @@
if (curData instanceof YangModule || curData instanceof YangSubModule || curData instanceof YangContainer
|| curData instanceof YangList || curData instanceof YangNotification || curData instanceof YangRpc
- || curData instanceof YangInput || curData instanceof YangOutput) {
+ || curData instanceof YangInput || curData instanceof YangOutput || curData instanceof YangGrouping) {
- /*
- * TODO YangGrouping.
- */
YangNode curNode = (YangNode) curData;
try {
curNode.addChild(typeDefNode);
diff --git a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/UsesListener.java b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/UsesListener.java
index 4e2925a..1658eee 100644
--- a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/UsesListener.java
+++ b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/UsesListener.java
@@ -23,8 +23,10 @@
import org.onosproject.yangutils.datamodel.YangList;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
import org.onosproject.yangutils.datamodel.YangNotification;
import org.onosproject.yangutils.datamodel.YangOutput;
+import org.onosproject.yangutils.datamodel.YangResolutionInfo;
import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.datamodel.YangUses;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
@@ -33,16 +35,18 @@
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo;
import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangUsesNode;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidNodeIdentifier;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne;
import static org.onosproject.yangutils.utils.YangConstructType.DESCRIPTION_DATA;
@@ -116,6 +120,11 @@
// Validate sub statement cardinality.
validateSubStatementsCardinality(ctx);
+ // Check for identifier collision
+ int line = ctx.getStart().getLine();
+ int charPositionInLine = ctx.getStart().getCharPositionInLine();
+
+ detectCollidingChildUtil(listener, line, charPositionInLine, ctx.string().getText(), USES_DATA);
Parsable curData = listener.getParsedDataStack().peek();
if (curData instanceof YangModule || curData instanceof YangSubModule
@@ -126,8 +135,8 @@
|| curData instanceof YangNotification) {
YangUses usesNode = getYangUsesNode(JAVA_GENERATION);
- usesNode.setName(ctx.string().getText());
-
+ YangNodeIdentifier nodeIdentifier = getValidNodeIdentifier(ctx.string().getText(), USES_DATA, ctx);
+ usesNode.setNodeIdentifier(nodeIdentifier);
YangNode curNode = (YangNode) curData;
try {
@@ -156,12 +165,29 @@
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, USES_DATA, ctx.string().getText(), EXIT);
- if (listener.getParsedDataStack().peek() instanceof YangUses) {
- listener.getParsedDataStack().pop();
- } else {
- throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, USES_DATA,
+ Parsable parsableUses = listener.getParsedDataStack().pop();
+ if (!(parsableUses instanceof YangUses)) {
+ throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, USES_DATA,
ctx.string().getText(), EXIT));
}
+ YangUses uses = (YangUses) parsableUses;
+ int errorLine = ctx.getStart().getLine();
+ int errorPosition = ctx.getStart().getCharPositionInLine();
+
+ // Parent YANG node of uses to be added in resolution information.
+ Parsable parentNode = listener.getParsedDataStack().peek();
+
+ // Verify parent node of leaf
+ if (!(parentNode instanceof YangNode)) {
+ throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, USES_DATA,
+ ctx.string().getText(), EXIT));
+ }
+
+ // Add resolution information to the list
+ YangResolutionInfo resolutionInfo = new YangResolutionInfo<YangUses>(uses,
+ (YangNode) parentNode, errorLine,
+ errorPosition);
+ addToResolutionList(resolutionInfo, ctx);
}
// TODO linker to handle collision scenarios like leaf obtained by uses, conflicts with some existing leaf.
@@ -175,5 +201,23 @@
validateCardinalityMaxOne(ctx.whenStatement(), WHEN_DATA, USES_DATA, ctx.string().getText());
validateCardinalityMaxOne(ctx.statusStatement(), STATUS_DATA, USES_DATA, ctx.string().getText());
validateCardinalityMaxOne(ctx.descriptionStatement(), DESCRIPTION_DATA, USES_DATA, ctx.string().getText());
- validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, USES_DATA, ctx.string().getText()); }
+ validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, USES_DATA, ctx.string().getText());
+ }
+
+ /**
+ * Add to resolution list.
+ *
+ * @param resolutionInfo resolution information.
+ * @param ctx context object of the grammar rule
+ */
+ private static void addToResolutionList(YangResolutionInfo<YangUses> resolutionInfo,
+ GeneratedYangParser.UsesStatementContext ctx) {
+
+ try {
+ addResolutionInfo(resolutionInfo);
+ } catch (DataModelException e) {
+ throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
+ USES_DATA, ctx.string().getText(), EXIT, e.getMessage()));
+ }
+ }
}
diff --git a/src/main/resources/GeneratedYang.g4 b/src/main/resources/GeneratedYang.g4
index 5ab42b5..11e7833 100644
--- a/src/main/resources/GeneratedYang.g4
+++ b/src/main/resources/GeneratedYang.g4
@@ -1098,12 +1098,7 @@
* 1*(data-def-stmt stmtsep)
* "}"
*/
- inputStatement : INPUT_KEYWORD LEFT_CURLY_BRACE inputStatementBody RIGHT_CURLY_BRACE;
-
- inputStatementBody : typedefStatement* dataDefStatement+
- | dataDefStatement+ typedefStatement*
- | groupingStatement* dataDefStatement+
- | dataDefStatement+ groupingStatement*;
+ inputStatement : INPUT_KEYWORD LEFT_CURLY_BRACE (typedefStatement | groupingStatement | dataDefStatement)* RIGHT_CURLY_BRACE;
/**
* output-stmt = output-keyword optsep
@@ -1114,12 +1109,7 @@
* 1*(data-def-stmt stmtsep)
* "}"
*/
- outputStatement : OUTPUT_KEYWORD LEFT_CURLY_BRACE outputStatementBody RIGHT_CURLY_BRACE;
-
- outputStatementBody : typedefStatement* dataDefStatement+
- | dataDefStatement+ typedefStatement*
- | groupingStatement* dataDefStatement+
- | dataDefStatement+ groupingStatement*;
+ outputStatement : OUTPUT_KEYWORD LEFT_CURLY_BRACE (typedefStatement | groupingStatement | dataDefStatement)* RIGHT_CURLY_BRACE;
/**
* notification-stmt = notification-keyword sep
diff --git a/src/test/java/org/onosproject/yangutils/linker/IntraFileUsesLinkingTest.java b/src/test/java/org/onosproject/yangutils/linker/IntraFileUsesLinkingTest.java
new file mode 100644
index 0000000..472d453
--- /dev/null
+++ b/src/test/java/org/onosproject/yangutils/linker/IntraFileUsesLinkingTest.java
@@ -0,0 +1,769 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.linker;
+
+import java.io.IOException;
+import java.util.ListIterator;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.onosproject.yangutils.datamodel.ResolvableStatus;
+import org.onosproject.yangutils.datamodel.YangContainer;
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+import org.onosproject.yangutils.datamodel.YangGrouping;
+import org.onosproject.yangutils.datamodel.YangLeaf;
+import org.onosproject.yangutils.datamodel.YangList;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangNodeType;
+import org.onosproject.yangutils.datamodel.YangTypeDef;
+import org.onosproject.yangutils.datamodel.YangUses;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+/**
+ * Test cases for testing uses intra file linking.
+ */
+public class IntraFileUsesLinkingTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ private final YangUtilsParserManager manager = new YangUtilsParserManager();
+
+ /**
+ * Checks self resolution when grouping and uses are siblings.
+ * Grouping followed by uses.
+ */
+ @Test
+ public void processSelfResolutionWhenUsesAndGroupingAtRootLevel()
+ throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/SelfResolutionWhenUsesAndGroupingAtRootLevel.yang");
+
+ // Check whether the data model tree returned is of type module.
+ assertThat((node instanceof YangModule), is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) node;
+ assertThat(yangNode.getName(), is("Test"));
+
+ ListIterator<YangLeaf> leafIterator;
+ YangLeaf leafInfo;
+
+ // Check whether grouping is the sibling of module's child.
+ assertThat((yangNode.getChild().getNextSibling() instanceof YangGrouping), is(true));
+
+ YangGrouping grouping = (YangGrouping) yangNode.getChild().getNextSibling();
+ leafIterator = grouping.getListOfLeaf().listIterator();
+ leafInfo = leafIterator.next();
+
+ // Check whether the information in the leaf is correct under grouping.
+ assertThat(leafInfo.getLeafName(), is("hello"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("String"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
+
+ // Check whether uses is module's child.
+ assertThat((yangNode.getChild() instanceof YangUses), is(true));
+ YangUses uses = (YangUses) yangNode.getChild();
+
+ // Check whether uses get resolved.
+ assertThat(uses.getResolvableStatus(),
+ is(ResolvableStatus.RESOLVED));
+
+ leafIterator = yangNode.getListOfLeaf().listIterator();
+ leafInfo = leafIterator.next();
+
+ // Check whether the information in the leaf is correct under module.
+ assertThat(leafInfo.getLeafName(), is("hello"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("String"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
+
+ }
+
+ /**
+ * Checks self resolution when grouping and uses are siblings.
+ * Grouping has a child node.
+ */
+ @Test
+ public void processSelfResolutionWhenUsesAndGroupingAtRootLevelGroupingWithChild()
+ throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel(
+ "src/test/resources/SelfResolutionWhenUsesAndGroupingAtRootLevelGroupingWithChild.yang");
+
+ // Check whether the data model tree returned is of type module.
+ assertThat((node instanceof YangModule), is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) node;
+ assertThat(yangNode.getName(), is("Test"));
+
+ ListIterator<YangLeaf> leafIterator;
+ YangLeaf leafInfo;
+
+ // Check whether grouping is the sibling of module's child.
+ assertThat((yangNode.getChild().getNextSibling() instanceof YangGrouping), is(true));
+
+ YangGrouping grouping = (YangGrouping) yangNode.getChild().getNextSibling();
+ leafIterator = grouping.getListOfLeaf().listIterator();
+ leafInfo = leafIterator.next();
+
+ // Check whether the information in the leaf is correct under grouping.
+ assertThat(leafInfo.getLeafName(), is("treat"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("String"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
+
+ // Check whether container is the child of grouping.
+ assertThat((grouping.getChild() instanceof YangContainer), is(true));
+ YangContainer container = (YangContainer) grouping.getChild();
+
+ // Check whether the container name is set correctly which is under grouping.
+ assertThat(container.getName(), is("test"));
+
+ leafIterator = container.getListOfLeaf().listIterator();
+ leafInfo = leafIterator.next();
+
+ // Check whether the information in the leaf is correct under container which is under grouping.
+ assertThat(leafInfo.getLeafName(), is("leaf2"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("String"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
+
+ // Check whether uses is module's child.
+ assertThat((yangNode.getChild() instanceof YangUses), is(true));
+ YangUses uses = (YangUses) yangNode.getChild();
+
+ // Check whether uses get resolved.
+ assertThat(uses.getResolvableStatus(),
+ is(ResolvableStatus.RESOLVED));
+
+ leafIterator = yangNode.getListOfLeaf().listIterator();
+ leafInfo = leafIterator.next();
+
+ // Check whether the information in the leaf is correct under module.
+ assertThat(leafInfo.getLeafName(), is("treat"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("String"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
+
+ // Check whether container is the child of module.
+ assertThat((grouping.getNextSibling() instanceof YangContainer), is(true));
+ container = (YangContainer) grouping.getNextSibling();
+
+ // Check whether the container name is set correctly which is under module.
+ assertThat(container.getName(), is("test"));
+
+ leafIterator = container.getListOfLeaf().listIterator();
+ leafInfo = leafIterator.next();
+
+ // Check whether the information in the leaf is correct under container which is under module.
+ assertThat(leafInfo.getLeafName(), is("leaf2"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("String"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
+ }
+
+ /**
+ * Checks self resolution when grouping in rpc and uses in output of the same rpc.
+ * Uses is followed by grouping.
+ */
+ @Test
+ public void processSelfResolutionGroupingInRpcAndUsesInOutput()
+ throws IOException, ParserException {
+
+ YangNode node = manager
+ .getDataModel("src/test/resources/SelfResolutionGroupingInRpcAndUsesInOutput.yang");
+
+ // Check whether the data model tree returned is of type module.
+ assertThat((node instanceof YangModule), is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) node;
+ assertThat(yangNode.getName(), is("rock"));
+
+ ListIterator<YangLeaf> leafIterator;
+ YangLeaf leafInfo;
+
+ // Check whether grouping is the child of rpc.
+ assertThat((yangNode.getChild().getChild() instanceof YangGrouping), is(true));
+ YangGrouping grouping = (YangGrouping) yangNode.getChild().getChild();
+
+ // Check whether the grouping name is set correctly.
+ assertThat(grouping.getName(), is("hello"));
+
+ // Check whether list is the child of grouping.
+ assertThat((grouping.getChild() instanceof YangList), is(true));
+ YangList yangListNode = (YangList) grouping.getChild();
+
+ // Check whether the list name is set correctly.
+ assertThat(yangListNode.getName(), is("valid"));
+
+ leafIterator = yangListNode.getListOfLeaf().listIterator();
+ leafInfo = leafIterator.next();
+
+ // Check whether the information in the leaf is correct under list which is under grouping.
+ assertThat(leafInfo.getLeafName(), is("invalid-interval"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
+ assertThat(leafInfo.getUnits(), is("\"seconds\""));
+ assertThat(leafInfo.getReference(), is("\"RFC 6020\""));
+
+ // Check whether uses is input's child.
+ assertThat((yangNode.getChild().getChild().getNextSibling().getChild() instanceof YangUses), is(true));
+ YangUses uses = (YangUses) yangNode.getChild().getChild().getNextSibling().getChild();
+
+ // Check whether uses get resolved.
+ assertThat(uses.getResolvableStatus(),
+ is(ResolvableStatus.RESOLVED));
+
+ // Check whether list is the sibling of uses which has been deep copied from grouping.
+ assertThat((yangNode.getChild().getChild().getNextSibling().getChild().getNextSibling() instanceof YangList),
+ is(true));
+ YangList yangList = (YangList) yangNode.getChild().getChild().getNextSibling().getChild().getNextSibling();
+
+ // Check whether the list name is set correctly.
+ assertThat(yangList.getName(), is("valid"));
+
+ leafIterator = yangList.getListOfLeaf().listIterator();
+ leafInfo = leafIterator.next();
+
+ // Check whether the information in the leaf is correct under list which is deep copied.
+ assertThat(leafInfo.getLeafName(), is("invalid-interval"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
+ assertThat(leafInfo.getUnits(), is("\"seconds\""));
+ assertThat(leafInfo.getReference(), is("\"RFC 6020\""));
+
+ // Check whether uses is output's child.
+ assertThat((yangNode.getChild().getChild().getNextSibling().getNextSibling().getChild() instanceof YangUses),
+ is(true));
+ YangUses usesInOuput = (YangUses) yangNode.getChild().getChild().getNextSibling().getNextSibling().getChild();
+
+ // Check whether uses get resolved.
+ assertThat(usesInOuput.getResolvableStatus(),
+ is(ResolvableStatus.RESOLVED));
+
+ // Check whether list is the sibling of uses which has been deep copied from grouping.
+ assertThat((yangNode.getChild().getChild().getNextSibling().getChild().getNextSibling() instanceof YangList),
+ is(true));
+
+ YangList yangListInOutput = (YangList) yangNode.getChild().getChild().getNextSibling().getNextSibling()
+ .getChild().getNextSibling();
+
+ // Check whether the list name is set correctly.
+ assertThat(yangListInOutput.getName(), is("valid"));
+
+ leafIterator = yangListInOutput.getListOfLeaf().listIterator();
+ leafInfo = leafIterator.next();
+
+ // Check whether the information in the leaf is correct under list which is deep copied.
+ assertThat(leafInfo.getLeafName(), is("invalid-interval"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
+ assertThat(leafInfo.getUnits(), is("\"seconds\""));
+ assertThat(leafInfo.getReference(), is("\"RFC 6020\""));
+ }
+
+ /**
+ * Checks the failure scenario when uses is referring to its own grouping directly.
+ */
+ @Test
+ public void processSelfResolutionGroupingReferencingItselfFailureScenerio()
+ throws IOException, ParserException {
+
+ thrown.expect(ParserException.class);
+ thrown.expectMessage(
+ "YANG file error: Duplicate input identifier detected, same as leaf \"zip-code\"");
+ YangNode node = manager
+ .getDataModel("src/test/resources/SelfResolutionGroupingReferencingItselfFailureScenerio.yang");
+
+ }
+
+ /**
+ * Checks the when multiple uses are present and are referred to the grouping at different levels.
+ */
+ @Test
+ public void processSelfResolutionGroupingWithMultipleUses()
+ throws IOException, ParserException {
+
+ YangNode node = manager
+ .getDataModel("src/test/resources/SelfResolutionGroupingWithMultipleUses.yang");
+
+ // Check whether the data model tree returned is of type module.
+ assertThat((node instanceof YangModule), is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) node;
+ assertThat(yangNode.getName(), is("Test"));
+
+ ListIterator<YangLeaf> leafIterator;
+ YangLeaf leafInfo;
+
+ // Check whether grouping is the child of container.
+ assertThat((yangNode.getChild().getChild() instanceof YangGrouping), is(true));
+ YangGrouping grouping = (YangGrouping) yangNode.getChild().getChild();
+
+ // Check whether the grouping name is set correctly.
+ assertThat(grouping.getName(), is("endpoint"));
+
+ // Check whether uses is endpoint-grouping's child.
+ assertThat((grouping.getChild() instanceof YangUses), is(true));
+ YangUses firstUses = (YangUses) grouping.getChild();
+
+ // Check whether uses get resolved.
+ assertThat(firstUses.getResolvableStatus(),
+ is(ResolvableStatus.RESOLVED));
+
+ // Check whether container is the sibling of uses.
+ assertThat((firstUses.getNextSibling() instanceof YangContainer), is(true));
+ YangContainer yangContainer = (YangContainer) firstUses.getNextSibling();
+
+ // Check whether the container name is set correctly.
+ assertThat(yangContainer.getName(), is("design"));
+
+ leafIterator = yangContainer.getListOfLeaf().listIterator();
+ leafInfo = leafIterator.next();
+
+ // Check whether the information in the leaf is correct under design-container.
+ assertThat(leafInfo.getLeafName(), is("ink"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("int32"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.INT32));
+
+ // Check whether uses is design-container's child.
+ assertThat((yangContainer.getChild() instanceof YangUses), is(true));
+ YangUses secondUses = (YangUses) yangContainer.getChild();
+
+ // Check whether uses get resolved.
+ assertThat(secondUses.getResolvableStatus(),
+ is(ResolvableStatus.RESOLVED));
+
+ // Check whether container is the sibling of uses.
+ assertThat((secondUses.getNextSibling() instanceof YangContainer), is(true));
+ YangContainer yangContainer2 = (YangContainer) secondUses.getNextSibling();
+ assertThat(yangContainer2.getName(), is("correct"));
+
+ leafIterator = yangContainer2.getListOfLeaf().listIterator();
+ leafInfo = leafIterator.next();
+
+ // Check whether the information in the leaf is correct under correct-container.
+ assertThat(leafInfo.getLeafName(), is("newone"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
+
+ // Check whether uses is correct container's child.
+ assertThat((yangContainer2.getChild() instanceof YangUses), is(true));
+ YangUses thirdUses = (YangUses) yangContainer2.getChild();
+
+ // Check whether uses get resolved.
+ assertThat(thirdUses.getResolvableStatus(),
+ is(ResolvableStatus.RESOLVED));
+
+ // Check whether container is the sibling of uses.
+ assertThat((thirdUses.getNextSibling() instanceof YangContainer), is(true));
+
+ YangContainer yangContainer3 = (YangContainer) thirdUses.getNextSibling();
+ assertThat(yangContainer3.getName(), is("value"));
+
+ leafIterator = yangContainer3.getListOfLeaf().listIterator();
+ leafInfo = leafIterator.next();
+
+ // Check whether the information in the leaf is correct under container
+ // which has been deep copied from grouping.
+ assertThat(leafInfo.getLeafName(), is("zip-code"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
+
+ // Check whether uses is the sibling of container-design.
+ assertThat((yangContainer.getNextSibling() instanceof YangUses), is(true));
+ YangUses fourthUses = (YangUses) yangContainer.getNextSibling();
+
+ // Check whether uses get resolved.
+ assertThat(fourthUses.getResolvableStatus(),
+ is(ResolvableStatus.RESOLVED));
+
+ // Check whether uses is the sibling of previous uses.
+ assertThat((fourthUses.getNextSibling() instanceof YangUses), is(true));
+ YangUses fifthUses = (YangUses) fourthUses.getNextSibling();
+
+ // Check whether uses get resolved.
+ assertThat(fifthUses.getResolvableStatus(),
+ is(ResolvableStatus.RESOLVED));
+
+ // Check whether list is the sibling of uses.
+ assertThat((fifthUses.getNextSibling() instanceof YangList), is(true));
+ YangList yangList = (YangList) fifthUses.getNextSibling();
+ assertThat(yangList.getName(), is("valid"));
+
+ leafIterator = yangList.getListOfLeaf().listIterator();
+ leafInfo = leafIterator.next();
+
+ // Check whether the information in the leaf is correct under list which has been deep copied from grouping.
+ assertThat(leafInfo.getLeafName(), is("invalid-interval"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
+ assertThat(leafInfo.getUnits(), is("\"seconds\""));
+ assertThat(leafInfo.getReference(), is("\"RFC 6020\""));
+
+ // Check whether typedef is the sibling of list.
+ assertThat((yangList.getNextSibling() instanceof YangTypeDef), is(true));
+ YangTypeDef yangTypeDef = (YangTypeDef) yangList.getNextSibling();
+ assertThat(yangTypeDef.getName(), is("my-type"));
+
+ leafIterator = grouping.getListOfLeaf().listIterator();
+ leafInfo = leafIterator.next();
+
+ // Check whether the information in the leaf is correct under grouping.
+ assertThat(leafInfo.getLeafName(), is("zip-code"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
+
+ // Check whether uses is endpoint-grouping's sibling.
+ assertThat((grouping.getNextSibling() instanceof YangUses), is(true));
+ YangUses endpointUses = (YangUses) grouping.getNextSibling();
+
+ // Check whether uses get resolved.
+ assertThat(endpointUses.getResolvableStatus(),
+ is(ResolvableStatus.RESOLVED));
+
+ assertThat((endpointUses.getNextSibling().getNextSibling().getNextSibling().getNextSibling().getNextSibling()
+ .getNextSibling() instanceof YangUses), is(true));
+
+ YangUses yangUsesInEndpoint = (YangUses) endpointUses.getNextSibling().getNextSibling().getNextSibling()
+ .getNextSibling().getNextSibling().getNextSibling();
+ assertThat(yangUsesInEndpoint.getResolvableStatus(),
+ is(ResolvableStatus.RESOLVED));
+
+ assertThat((yangUsesInEndpoint.getNextSibling() instanceof YangContainer), is(true));
+ YangContainer yangContainerInEndPoint = (YangContainer) yangUsesInEndpoint.getNextSibling();
+
+ assertThat(yangContainerInEndPoint.getName(), is("design"));
+ }
+
+ /**
+ * Checks the failure scenario when uses is present under the same node many times.
+ */
+ @Test
+ public void processSelfResolutionGroupingHavingSameUsesManyTimes()
+ throws IOException, ParserException {
+
+ thrown.expect(ParserException.class);
+ thrown.expectMessage(
+ "YANG file error: Duplicate input identifier detected, same as uses \"failure\"");
+ YangNode node = manager
+ .getDataModel("src/test/resources/SelfResolutionGroupingHavingSameUsesManyTimes.yang");
+ }
+
+ /**
+ * Checks the rpc having both typedef and grouping.
+ * It also checks that the grouping under different nodes will not give any problem in resolving uses.
+ */
+ @Test
+ public void processSelfResolutionRpcWithOneTypedefAndTwoGroupingUnderDifferentNode()
+ throws IOException, ParserException {
+
+ YangNode node = manager
+ .getDataModel(
+ "src/test/resources/SelfResolutionRpcWithOneTypedefAndTwoGroupingUnderDifferentNode.yang");
+
+ // Check whether the data model tree returned is of type module.
+ assertThat((node instanceof YangModule), is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) node;
+ assertThat(yangNode.getName(), is("rock"));
+
+ ListIterator<YangLeaf> leafIterator;
+ YangLeaf leafInfo;
+
+ // Check whether grouping is the child of input.
+ assertThat((yangNode.getChild().getChild().getChild() instanceof YangGrouping), is(true));
+ YangGrouping groupingUnderInput = (YangGrouping) yangNode.getChild().getChild().getChild();
+
+ // Check whether the grouping name is set correctly.
+ assertThat(groupingUnderInput.getName(), is("creative"));
+
+ leafIterator = groupingUnderInput.getListOfLeaf().listIterator();
+ leafInfo = leafIterator.next();
+
+ // Check whether the information in the leaf is correct under grouping.
+ assertThat(leafInfo.getLeafName(), is("carry"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
+
+ // Check whether grouping is the child of output.
+ assertThat((yangNode.getChild().getChild().getNextSibling().getChild() instanceof YangGrouping), is(true));
+ YangGrouping grouping = (YangGrouping) yangNode.getChild().getChild().getNextSibling().getChild();
+ assertThat(grouping.getName(), is("creative"));
+
+ // Check whether typedef is the sibling of grouping.
+ assertThat((grouping.getNextSibling() instanceof YangTypeDef), is(true));
+
+ YangTypeDef typedef = (YangTypeDef) grouping.getNextSibling();
+ assertThat(typedef.getName(), is("my-type"));
+
+ // Check whether uses is the sibling of typedef.
+ assertThat((typedef.getNextSibling() instanceof YangUses), is(true));
+
+ // Check whether uses get resolved.
+ YangUses uses = (YangUses) typedef.getNextSibling();
+ assertThat(uses.getName(), is("creative"));
+ assertThat(uses.getResolvableStatus(),
+ is(ResolvableStatus.RESOLVED));
+
+ // Check whether list is the sibling of uses.
+ assertThat((uses.getNextSibling() instanceof YangList), is(true));
+ YangList list = (YangList) uses.getNextSibling();
+ assertThat(list.getName(), is("valid"));
+
+ leafIterator = list.getListOfLeaf().listIterator();
+ leafInfo = leafIterator.next();
+
+ // Check whether the information in the leaf is correct under list.
+ assertThat(leafInfo.getLeafName(), is("invalid-interval"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
+ }
+
+ /**
+ * Checks the failure scenario when uses is cannot resolve its grouping.
+ */
+ @Test
+ public void processSelfResolutionNestedGroupingWithUnresolvedUses()
+ throws IOException, ParserException {
+
+ thrown.expect(ParserException.class);
+ thrown.expectMessage(
+ "YANG file error: Unable to find base typedef/grouping for given type/uses");
+
+ YangNode node = manager
+ .getDataModel("src/test/resources/SelfResolutionNestedGroupingWithUnresolvedUses.yang");
+ }
+
+ /**
+ * Checks self resolution when typedef hierarchical references are present
+ * with last type is unresolved.
+ */
+ @Test
+ public void processSelfFileLinkingWithGroupingHierarchicalRefUnresolved()
+ throws IOException, ParserException {
+
+ YangNode node = manager
+ .getDataModel("src/test/resources/SelfFileLinkingWithGroupingHierarchicalRefUnresolved.yang");
+
+ // Check whether the data model tree returned is of type module.
+ assertThat((node instanceof YangModule), is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) node;
+ assertThat(yangNode.getName(), is("Test"));
+
+ // Check whether container is the sibling of grouping.
+ assertThat((yangNode.getChild().getNextSibling() instanceof YangContainer), is(true));
+ YangContainer containerWithUses = (YangContainer) yangNode.getChild().getNextSibling();
+ assertThat(containerWithUses.getName(), is("test"));
+
+ // Check whether uses is the child of container.
+ assertThat((containerWithUses.getChild() instanceof YangUses), is(true));
+ YangUses uses = (YangUses) containerWithUses.getChild();
+ assertThat(uses.getName(), is("create"));
+
+ // Check whether uses is getting resolved.
+ assertThat(uses.getResolvableStatus(),
+ is(ResolvableStatus.RESOLVED));
+
+ // Check whether grouping is the child of module.
+ assertThat((yangNode.getChild() instanceof YangGrouping), is(true));
+ YangGrouping groupingWithUses = (YangGrouping) yangNode.getChild();
+ assertThat(groupingWithUses.getName(), is("create"));
+
+ // Check whether uses with prefix from from other file, is the child of grouping.
+ assertThat((groupingWithUses.getChild() instanceof YangUses), is(true));
+ YangUses uses1 = (YangUses) groupingWithUses.getChild();
+ assertThat(uses1.getName(), is("valid"));
+
+ // Check whether this uses is getting intra-file-resolved.
+ assertThat(uses1.getResolvableStatus(),
+ is(ResolvableStatus.INTRA_FILE_RESOLVED));
+ }
+
+ /**
+ * Checks self resolution when uses has prefix of self module.
+ */
+ @Test
+ public void processSelfFileLinkingWithGroupingWithSelfModulePrefix()
+ throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/SelfFileLinkingWithGroupingWithSelfModulePrefix.yang");
+
+ // Check whether the data model tree returned is of type module.
+ assertThat((node instanceof YangModule), is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) node;
+ assertThat(yangNode.getName(), is("Test"));
+
+ // Check whether container is the sibling of grouping.
+ YangContainer yangContainer = (YangContainer) node.getChild().getNextSibling();
+
+ // Check whether list is the child of container.
+ YangList yangList = (YangList) yangContainer.getChild();
+
+ // Check whether uses is the child of list.
+ assertThat((yangList.getChild() instanceof YangUses), is(true));
+ YangUses yangUses1 = (YangUses) yangList.getChild();
+ assertThat(yangUses1.getName(), is("FirstClass"));
+
+ // Check whether uses is getting resolved.
+ assertThat(yangUses1.getResolvableStatus(),
+ is(ResolvableStatus.RESOLVED));
+
+ // Check whether grouping is the sibling of uses.
+ YangGrouping yangGrouping1 = (YangGrouping) yangUses1.getNextSibling();
+ assertThat(yangGrouping1.getName(), is("FirstClass"));
+
+ // Check whether uses is the child of grouping.
+ YangUses yangUses2 = (YangUses) yangGrouping1.getChild();
+ assertThat(yangUses2.getName(), is("PassingClass"));
+
+ // Check the uses gets resolved.
+ assertThat(yangUses2.getResolvableStatus(),
+ is(ResolvableStatus.RESOLVED));
+
+ // Check whether grouping is the sibling of list.
+ YangGrouping yangGrouping2 = (YangGrouping) yangList.getNextSibling();
+ assertThat(yangGrouping2.getName(), is("PassingClass"));
+
+ // Check uses is the child of that grouping which has prefix of the same module.
+ YangUses yangUses3 = (YangUses) yangGrouping2.getChild();
+ assertThat(yangUses3.getName(), is("Percentage"));
+
+ // Check uses is getting resolved.
+ assertThat(yangUses3.getResolvableStatus(),
+ is(ResolvableStatus.RESOLVED));
+
+ // Check grouping is the child of module.
+ YangGrouping yangGrouping3 = (YangGrouping) node.getChild();
+
+ ListIterator<YangLeaf> leafIterator;
+ YangLeaf leafInfo;
+ leafIterator = yangGrouping3.getListOfLeaf().listIterator();
+ leafInfo = leafIterator.next();
+
+ // Check whether the information in the leaf is correct under grouping.
+ assertThat(leafInfo.getLeafName(), is("hello"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("String"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
+
+ }
+
+ /**
+ * Checks self resolution when some type uses prefix of self module
+ * some uses external prefix.
+ */
+ @Test
+ public void processSelfFileLinkingWithGroupingWithSelfAndExternalPrefixMix()
+ throws IOException, ParserException {
+
+ YangNode node = manager
+ .getDataModel("src/test/resources/SelfFileLinkingWithGroupingWithSelfAndExternalPrefixMix.yang");
+
+ // Check whether the data model tree returned is of type module.
+ assertThat((node instanceof YangModule), is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) node;
+ assertThat(yangNode.getName(), is("Test"));
+
+ // Check whether container is the sibling of grouping.
+ YangContainer yangContainer = (YangContainer) node.getChild().getNextSibling();
+
+ // Check whether list is the child of container.
+ YangList yangList = (YangList) yangContainer.getChild();
+
+ // Check whether uses is the child of list.
+ assertThat((yangList.getChild() instanceof YangUses), is(true));
+ YangUses yangUses1 = (YangUses) yangList.getChild();
+ assertThat(yangUses1.getName(), is("FirstClass"));
+
+ // Check whether uses is getting resolved.
+ assertThat(yangUses1.getResolvableStatus(),
+ is(ResolvableStatus.RESOLVED));
+
+ // Check whether grouping is the sibling of uses.
+ YangGrouping yangGrouping1 = (YangGrouping) yangUses1.getNextSibling();
+ assertThat(yangGrouping1.getName(), is("FirstClass"));
+
+ // Check whether uses is the child of grouping which has prefix from other module.
+ YangUses yangUses2 = (YangUses) yangGrouping1.getChild();
+ assertThat(yangUses2.getName(), is("PassingClass"));
+
+ // Check whether uses gets intra-file-resolved.
+ assertThat(yangUses2.getResolvableStatus(),
+ is(ResolvableStatus.INTRA_FILE_RESOLVED));
+
+ // Check whether grouping is the sibling of list.
+ YangGrouping yangGrouping2 = (YangGrouping) yangList.getNextSibling();
+ assertThat(yangGrouping2.getName(), is("PassingClass"));
+
+ // Check uses is the child of that grouping which has prefix of the same module.
+ YangUses yangUses3 = (YangUses) yangGrouping2.getChild();
+ assertThat(yangUses3.getName(), is("Percentage"));
+
+ // Check uses is getting resolved.
+ assertThat(yangUses3.getResolvableStatus(),
+ is(ResolvableStatus.RESOLVED));
+
+ // Check grouping is the child of module.
+ YangGrouping yangGrouping3 = (YangGrouping) node.getChild();
+ ListIterator<YangLeaf> leafIterator;
+ YangLeaf leafInfo;
+ leafIterator = yangGrouping3.getListOfLeaf().listIterator();
+ leafInfo = leafIterator.next();
+
+ // Check whether the information in the leaf is correct under grouping.
+ assertThat(leafInfo.getLeafName(), is("hello"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("String"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
+ }
+
+}
diff --git a/src/test/java/org/onosproject/yangutils/parser/impl/listeners/UsesListenerTest.java b/src/test/java/org/onosproject/yangutils/parser/impl/listeners/UsesListenerTest.java
index 0ced4d2..a20c43e 100644
--- a/src/test/java/org/onosproject/yangutils/parser/impl/listeners/UsesListenerTest.java
+++ b/src/test/java/org/onosproject/yangutils/parser/impl/listeners/UsesListenerTest.java
@@ -19,6 +19,7 @@
import java.io.IOException;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangContainer;
+import org.onosproject.yangutils.datamodel.YangGrouping;
import org.onosproject.yangutils.datamodel.YangList;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
@@ -56,7 +57,10 @@
YangModule yangNode = (YangModule) node;
assertThat(yangNode.getName(), is("Test"));
- YangUses yangUses = (YangUses) yangNode.getChild();
+ YangGrouping yangGrouping = (YangGrouping) yangNode.getChild();
+ assertThat(yangGrouping.getName(), is("endpoint"));
+
+ YangUses yangUses = (YangUses) yangGrouping.getNextSibling();
assertThat(yangUses.getName(), is("endpoint"));
}
@@ -78,7 +82,10 @@
YangModule yangNode = (YangModule) node;
assertThat(yangNode.getName(), is("Test"));
- YangContainer yangContainer = (YangContainer) yangNode.getChild();
+ YangGrouping yangGrouping = (YangGrouping) yangNode.getChild();
+ assertThat(yangGrouping.getName(), is("endpoint"));
+
+ YangContainer yangContainer = (YangContainer) yangGrouping.getNextSibling();
assertThat(yangContainer.getName(), is("valid"));
YangUses yangUses = (YangUses) yangContainer.getChild();
@@ -108,7 +115,10 @@
YangModule yangNode = (YangModule) node;
assertThat(yangNode.getName(), is("Test"));
- YangList yangList = (YangList) yangNode.getChild();
+ YangGrouping yangGrouping = (YangGrouping) yangNode.getChild();
+ assertThat(yangGrouping.getName(), is("endpoint"));
+
+ YangList yangList = (YangList) yangGrouping.getNextSibling();
assertThat(yangList.getName(), is("valid"));
YangUses yangUses = (YangUses) yangList.getChild();
diff --git a/src/test/resources/SelfFileLinkingWithGroupingHierarchicalRefUnresolved.yang b/src/test/resources/SelfFileLinkingWithGroupingHierarchicalRefUnresolved.yang
new file mode 100644
index 0000000..cd71621
--- /dev/null
+++ b/src/test/resources/SelfFileLinkingWithGroupingHierarchicalRefUnresolved.yang
@@ -0,0 +1,14 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ import ietf-yang-types {
+ prefix "P";
+ }
+ grouping create {
+ uses P:valid;
+ }
+ container test{
+ uses create;
+ }
+}
diff --git a/src/test/resources/SelfFileLinkingWithGroupingWithSelfAndExternalPrefixMix.yang b/src/test/resources/SelfFileLinkingWithGroupingWithSelfAndExternalPrefixMix.yang
new file mode 100644
index 0000000..84236a2
--- /dev/null
+++ b/src/test/resources/SelfFileLinkingWithGroupingWithSelfAndExternalPrefixMix.yang
@@ -0,0 +1,28 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ import ietf-yang-types {
+ prefix "P";
+ }
+ grouping Percentage {
+ leaf hello{
+ type String;
+ }
+ }
+ container ospf {
+ list valid {
+ key "invalid";
+ leaf invalid{
+ type String;
+ }
+ uses Ant:FirstClass;
+ grouping FirstClass {
+ uses P:PassingClass;
+ }
+ }
+ grouping PassingClass {
+ uses Ant:Percentage;
+ }
+ }
+}
diff --git a/src/test/resources/SelfFileLinkingWithGroupingWithSelfModulePrefix.yang b/src/test/resources/SelfFileLinkingWithGroupingWithSelfModulePrefix.yang
new file mode 100644
index 0000000..23f197b
--- /dev/null
+++ b/src/test/resources/SelfFileLinkingWithGroupingWithSelfModulePrefix.yang
@@ -0,0 +1,25 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ grouping Percentage {
+ leaf hello{
+ type String;
+ }
+ }
+ container ospf {
+ list valid {
+ key "invalid";
+ leaf invalid{
+ type String;
+ }
+ uses Ant:FirstClass;
+ grouping FirstClass {
+ uses PassingClass;
+ }
+ }
+ grouping PassingClass {
+ uses Ant:Percentage;
+ }
+ }
+}
diff --git a/src/test/resources/SelfResolutionGroupingHavingSameUsesManyTimes.yang b/src/test/resources/SelfResolutionGroupingHavingSameUsesManyTimes.yang
new file mode 100644
index 0000000..d449adf
--- /dev/null
+++ b/src/test/resources/SelfResolutionGroupingHavingSameUsesManyTimes.yang
@@ -0,0 +1,25 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ container valid {
+ grouping endpoint {
+ leaf zip-code {
+ type string;
+ }
+ uses failure;
+ container hold {
+ leaf newone {
+ type string;
+ }
+
+ }
+ uses failure;
+ }
+ grouping failure {
+ leaf test {
+ type string;
+ }
+ }
+ }
+}
diff --git a/src/test/resources/SelfResolutionGroupingInRpcAndUsesInOutput.yang b/src/test/resources/SelfResolutionGroupingInRpcAndUsesInOutput.yang
new file mode 100644
index 0000000..3589a9f
--- /dev/null
+++ b/src/test/resources/SelfResolutionGroupingInRpcAndUsesInOutput.yang
@@ -0,0 +1,34 @@
+module rock {
+ namespace "http://example.net/rock";
+ prefix "rock";
+
+ rpc rock-the-house {
+ description "description";
+ status current;
+ reference "reference";
+ grouping hello {
+ list valid {
+ key invalid-interval;
+ reference "RFC 6020";
+ leaf invalid-interval {
+ type "uint16";
+ units "seconds";
+ status current;
+ reference "RFC 6020";
+ }
+ }
+ }
+ input {
+ leaf zip-code {
+ type string;
+ }
+ uses hello;
+ }
+ output {
+ leaf status {
+ type string;
+ }
+ uses hello;
+ }
+ }
+}
diff --git a/src/test/resources/SelfResolutionGroupingReferencingItselfFailureScenerio.yang b/src/test/resources/SelfResolutionGroupingReferencingItselfFailureScenerio.yang
new file mode 100644
index 0000000..3e0ba3d
--- /dev/null
+++ b/src/test/resources/SelfResolutionGroupingReferencingItselfFailureScenerio.yang
@@ -0,0 +1,13 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ container valid {
+ grouping endpoint {
+ leaf zip-code {
+ type string;
+ }
+ uses endpoint;
+ }
+ }
+}
diff --git a/src/test/resources/SelfResolutionGroupingWithMultipleUses.yang b/src/test/resources/SelfResolutionGroupingWithMultipleUses.yang
new file mode 100644
index 0000000..906890f
--- /dev/null
+++ b/src/test/resources/SelfResolutionGroupingWithMultipleUses.yang
@@ -0,0 +1,63 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ container valid {
+ grouping endpoint {
+ leaf zip-code {
+ type string;
+ }
+ uses first;
+ container design {
+ uses second;
+ container correct {
+ leaf newone {
+ type string;
+ }
+ uses third;
+ }
+ }
+ uses fourth;
+ uses fifth;
+ }
+ uses endpoint;
+ grouping first {
+ list valid {
+ key invalid-interval;
+ reference "RFC 6020";
+ leaf invalid-interval {
+ type "uint16";
+ units "seconds";
+ status current;
+ reference "RFC 6020";
+ }
+ }
+ }
+ grouping second {
+ leaf ink {
+ type int32;
+ }
+ }
+ grouping third {
+ container value {
+ leaf zip-code {
+ type string;
+ }
+ }
+ }
+ grouping fourth {
+ typedef my-type {
+ status deprecated;
+ type int32;
+ }
+ leaf correct {
+ type my-type;
+ }
+ }
+ grouping fifth {
+ leaf abc {
+ type string;
+ }
+ }
+ }
+}
diff --git a/src/test/resources/SelfResolutionNestedGroupingWithUnresolvedUses.yang b/src/test/resources/SelfResolutionNestedGroupingWithUnresolvedUses.yang
new file mode 100644
index 0000000..4dbc1a2
--- /dev/null
+++ b/src/test/resources/SelfResolutionNestedGroupingWithUnresolvedUses.yang
@@ -0,0 +1,17 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ container test{
+ leaf leaf2{
+ type String;
+ }
+ grouping treat {
+ grouping create {
+ grouping mass {
+ }
+ }
+ }
+ }
+ uses treat;
+}
diff --git a/src/test/resources/SelfResolutionRpcWithOneTypedefAndTwoGroupingUnderDifferentNode.yang b/src/test/resources/SelfResolutionRpcWithOneTypedefAndTwoGroupingUnderDifferentNode.yang
new file mode 100644
index 0000000..91dc763
--- /dev/null
+++ b/src/test/resources/SelfResolutionRpcWithOneTypedefAndTwoGroupingUnderDifferentNode.yang
@@ -0,0 +1,38 @@
+module rock {
+ namespace "http://example.net/rock";
+ prefix "rock";
+
+ rpc rock-the-house {
+ description "description";
+ status current;
+ reference "reference";
+ input {
+ leaf zip-code {
+ type string;
+ }
+ grouping creative {
+ leaf carry {
+ type string;
+ }
+ }
+ }
+ output {
+ leaf status {
+ type string;
+ }
+ grouping creative {
+ list valid {
+ key invalid-interval;
+ leaf invalid-interval {
+ type "uint16";
+ }
+ }
+ }
+ typedef my-type {
+ status deprecated;
+ type int32;
+ }
+ uses creative;
+ }
+ }
+}
diff --git a/src/test/resources/SelfResolutionWhenUsesAndGroupingAtRootLevel.yang b/src/test/resources/SelfResolutionWhenUsesAndGroupingAtRootLevel.yang
new file mode 100644
index 0000000..52641d8
--- /dev/null
+++ b/src/test/resources/SelfResolutionWhenUsesAndGroupingAtRootLevel.yang
@@ -0,0 +1,11 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ uses hello;
+ grouping hello {
+ leaf hello{
+ type String;
+ }
+ }
+}
diff --git a/src/test/resources/SelfResolutionWhenUsesAndGroupingAtRootLevelGroupingWithChild.yang b/src/test/resources/SelfResolutionWhenUsesAndGroupingAtRootLevelGroupingWithChild.yang
new file mode 100644
index 0000000..f4f12b0
--- /dev/null
+++ b/src/test/resources/SelfResolutionWhenUsesAndGroupingAtRootLevelGroupingWithChild.yang
@@ -0,0 +1,16 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ uses treat;
+ grouping treat {
+ leaf treat{
+ type String;
+ }
+ container test{
+ leaf leaf2{
+ type String;
+ }
+ }
+ }
+}
diff --git a/src/test/resources/UsesInContainer.yang b/src/test/resources/UsesInContainer.yang
index 9fb5fbf..df52fd6 100644
--- a/src/test/resources/UsesInContainer.yang
+++ b/src/test/resources/UsesInContainer.yang
@@ -2,6 +2,8 @@
yang-version 1;
namespace http://huawei.com;
prefix Ant;
+ grouping endpoint {
+ }
container valid {
uses endpoint {
description "grouping under test";
diff --git a/src/test/resources/UsesInList.yang b/src/test/resources/UsesInList.yang
index b79e7b1..6ac7795 100644
--- a/src/test/resources/UsesInList.yang
+++ b/src/test/resources/UsesInList.yang
@@ -4,7 +4,9 @@
prefix Ant;
import ietf-yang-types {
prefix "P";
- }
+ }
+ grouping endpoint {
+ }
list valid {
key address;
leaf address {
diff --git a/src/test/resources/UsesInModule.yang b/src/test/resources/UsesInModule.yang
index a0a05f4..02b9f09 100644
--- a/src/test/resources/UsesInModule.yang
+++ b/src/test/resources/UsesInModule.yang
@@ -2,5 +2,7 @@
yang-version 1;
namespace http://huawei.com;
prefix Ant;
+ grouping endpoint {
+ }
uses endpoint;
}