[ONOS-4636]grouping and uses
Change-Id: Ic410d03a838003ad23b2b0e8874b91503da84153
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/TraversalType.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/TraversalType.java
new file mode 100644
index 0000000..e1a25c6
--- /dev/null
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/TraversalType.java
@@ -0,0 +1,43 @@
+/*
+ * 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.datamodel;
+
+/**
+ * Represents data model tree traversal types.
+ */
+public enum TraversalType {
+
+ /**
+ * Start of traversal at the tree root.
+ */
+ ROOT,
+
+ /**
+ * Child node traversal.
+ */
+ CHILD,
+
+ /**
+ * Sibling node traversal.
+ */
+ SIBILING,
+
+ /**
+ * Parent node traversal.
+ */
+ PARENT
+}
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNode.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNode.java
index 820b0b4..7a963f5 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNode.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNode.java
@@ -17,6 +17,13 @@
import java.io.Serializable;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+
+import static org.onosproject.yangutils.datamodel.TraversalType.CHILD;
+import static org.onosproject.yangutils.datamodel.TraversalType.PARENT;
+import static org.onosproject.yangutils.datamodel.TraversalType.SIBILING;
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.cloneLeaves;
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.updateClonedLeavesUnionEnumRef;
/**
* Represents base class of a node in data model tree.
@@ -226,4 +233,189 @@
newChild.setPreviousSibling(curNode);
}
}
+
+ /**
+ * Clones the current node contents and create a new node.
+ *
+ * @return cloned node
+ * @throws CloneNotSupportedException clone is not supported by the referred
+ * node
+ */
+ public YangNode clone()
+ throws CloneNotSupportedException {
+ YangNode clonedNode = (YangNode) super.clone();
+ if (clonedNode instanceof YangLeavesHolder) {
+ try {
+ cloneLeaves((YangLeavesHolder) clonedNode);
+ } catch (DataModelException e) {
+ throw new CloneNotSupportedException(e.getMessage());
+ }
+ }
+
+ clonedNode.setParent(null);
+ clonedNode.setChild(null);
+ clonedNode.setNextSibling(null);
+ clonedNode.setPreviousSibling(null);
+ return clonedNode;
+ }
+
+ /**
+ * Clones the subtree from the specified source node to the mentioned target
+ * node. The source and target root node cloning is carried out by the
+ * caller.
+ *
+ * @param srcRootNode source node for sub tree cloning
+ * @param dstRootNode destination node where the sub tree needs to be cloned
+ * @throws DataModelException data model error
+ */
+ public static void cloneSubTree(YangNode srcRootNode, YangNode dstRootNode)
+ throws DataModelException {
+
+ YangNode nextNodeToClone = srcRootNode;
+ TraversalType curTraversal;
+
+ YangNode clonedTreeCurNode = dstRootNode;
+ YangNode newNode = null;
+
+ nextNodeToClone = nextNodeToClone.getChild();
+ if (nextNodeToClone == null) {
+ return;
+ } else {
+ /**
+ * Root level cloning is taken care in the caller.
+ */
+ curTraversal = CHILD;
+ }
+
+ /**
+ * Caller ensures the cloning of the root nodes
+ */
+ try {
+ while (nextNodeToClone != srcRootNode) {
+ if (nextNodeToClone == null) {
+ throw new DataModelException("Internal error: Cloning failed, source tree null pointer reached");
+ }
+ if (curTraversal != PARENT) {
+ newNode = nextNodeToClone.clone();
+ detectCollisionWhileCloning(clonedTreeCurNode, newNode, curTraversal);
+ }
+
+ if (curTraversal == CHILD) {
+
+ /**
+ * add the new node to the cloned tree.
+ */
+ clonedTreeCurNode.addChild(newNode);
+
+ /**
+ * update the cloned tree's traversal current node as the
+ * new node.
+ */
+ clonedTreeCurNode = newNode;
+ } else if (curTraversal == SIBILING) {
+
+ clonedTreeCurNode.addNextSibling(newNode);
+ clonedTreeCurNode = newNode;
+ } else if (curTraversal == PARENT) {
+ if (clonedTreeCurNode instanceof YangLeavesHolder) {
+ updateClonedLeavesUnionEnumRef((YangLeavesHolder) clonedTreeCurNode);
+ }
+ clonedTreeCurNode = clonedTreeCurNode.getParent();
+ }
+
+ if (curTraversal != PARENT && nextNodeToClone.getChild() != null) {
+ curTraversal = CHILD;
+
+ /**
+ * update the traversal's current node.
+ */
+ nextNodeToClone = nextNodeToClone.getChild();
+
+ } else if (nextNodeToClone.getNextSibling() != null) {
+
+ curTraversal = SIBILING;
+
+ nextNodeToClone = nextNodeToClone.getNextSibling();
+ } else {
+ curTraversal = PARENT;
+ nextNodeToClone = nextNodeToClone.getParent();
+ }
+ }
+ } catch (CloneNotSupportedException e) {
+ throw new DataModelException("Failed to clone the tree");
+ }
+
+ }
+
+ /**
+ * 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");
+ }
+
+ }
+
+ /**
+ * Adds a new next sibling.
+ *
+ * @param newSibling new sibling to be added
+ * @throws DataModelException data model error
+ */
+ private void addNextSibling(YangNode newSibling)
+ throws DataModelException {
+
+ if (newSibling.getNodeType() == null) {
+ throw new DataModelException("Cloned abstract node cannot be inserted into a tree");
+ }
+
+ if (newSibling.getParent() == null) {
+ /**
+ * Since the siblings needs to have a common parent, set the parent
+ * as the current node's parent
+ */
+ newSibling.setParent(getParent());
+
+ } else {
+ throw new DataModelException("Node is already part of a tree, and cannot be added as a sibling");
+ }
+
+ if (newSibling.getPreviousSibling() == null) {
+ newSibling.setPreviousSibling(this);
+ setNextSibling(newSibling);
+ } else {
+ throw new DataModelException("New sibling to be added is not atomic, it already has a previous sibling");
+ }
+
+ if (newSibling.getChild() != null) {
+ throw new DataModelException("Sibling to be added is not atomic, it already has a child");
+ }
+
+ if (newSibling.getNextSibling() != null) {
+ throw new DataModelException("Sibling to be added is not atomic, it already has a next sibling");
+ }
+ }
}
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangUses.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangUses.java
index 6f7137d..51cd310 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangUses.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangUses.java
@@ -25,6 +25,7 @@
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParentNodeInGenCode;
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.updateClonedLeavesUnionEnumRef;
/*-
* Reference RFC 6020.
@@ -329,42 +330,45 @@
}
YangLeavesHolder usesParentLeavesHolder = (YangLeavesHolder) usesParentNode;
- if (referredGrouping.getListOfLeaf() != null
- && referredGrouping.getListOfLeaf().size() != 0) {
- addLeavesOfGrouping(
- cloneLeavesList(referredGrouping.getListOfLeaf(),
- usesParentLeavesHolder));
- }
+ if (referredGrouping.getListOfLeaf() != null) {
+ for (YangLeaf leaf : referredGrouping.getListOfLeaf()) {
+ YangLeaf clonedLeaf = null;
+ try {
+ ((CollisionDetector) usesParentLeavesHolder).detectCollidingChild(leaf.getName(),
+ YangConstructType.LEAF_DATA);
+ clonedLeaf = leaf.clone();
- if (referredGrouping.getListOfLeafList() != null
- && referredGrouping.getListOfLeafList().size() != 0) {
- addListOfLeafListOfGrouping(
- cloneListOfLeafList(referredGrouping.getListOfLeafList(),
- usesParentLeavesHolder));
- }
+ } catch (CloneNotSupportedException | DataModelException e) {
+ throw new DataModelException(e.getMessage());
+ }
- YangNode childInGrouping = referredGrouping.getChild();
-
- while (childInGrouping != null) {
- if (childInGrouping instanceof YangEnumeration
- || childInGrouping instanceof YangUnion
- || childInGrouping instanceof YangTypeDef) {
-
- /*
- * No need to copy the leaves, union / enum class, as these will
- * be generated in the scope of grouping
- */
- childInGrouping = childInGrouping.getNextSibling();
- continue;
- } else if (childInGrouping instanceof YangUses) {
- addResolvedUsesInfoOfGrouping((YangUses) childInGrouping,
- usesParentLeavesHolder);
- } else {
- addNodeOfGrouping(childInGrouping);
+ clonedLeaf.setContainedIn(usesParentLeavesHolder);
+ usesParentLeavesHolder.addLeaf(clonedLeaf);
}
-
- childInGrouping = childInGrouping.getNextSibling();
}
+ if (referredGrouping.getListOfLeafList() != null) {
+ for (YangLeafList leafList : referredGrouping.getListOfLeafList()) {
+ YangLeafList clonedLeafList = null;
+ try {
+ ((CollisionDetector) usesParentLeavesHolder).detectCollidingChild(leafList.getName(),
+ YangConstructType.LEAF_LIST_DATA);
+ clonedLeafList = leafList.clone();
+
+ } catch (CloneNotSupportedException | DataModelException e) {
+ throw new DataModelException(e.getMessage());
+ }
+
+ clonedLeafList.setContainedIn(usesParentLeavesHolder);
+ usesParentLeavesHolder.addLeafList(clonedLeafList);
+ }
+ }
+
+ try {
+ YangNode.cloneSubTree(referredGrouping, usesParentNode);
+ } catch (DataModelException e) {
+ throw new DataModelException(e.getMessage());
+ }
+ updateClonedLeavesUnionEnumRef(usesParentLeavesHolder);
}
/**
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java
index 410e025..1e15d1d 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java
@@ -20,6 +20,7 @@
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;
+import java.util.LinkedList;
import java.util.List;
import java.util.Set;
@@ -28,6 +29,7 @@
import org.onosproject.yangutils.datamodel.YangIfFeature;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangBase;
+import org.onosproject.yangutils.datamodel.YangEnumeration;
import org.onosproject.yangutils.datamodel.YangIdentityRef;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
@@ -38,8 +40,10 @@
import org.onosproject.yangutils.datamodel.YangResolutionInfo;
import org.onosproject.yangutils.datamodel.YangRpc;
import org.onosproject.yangutils.datamodel.YangType;
+import org.onosproject.yangutils.datamodel.YangUnion;
import org.onosproject.yangutils.datamodel.YangUses;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
/**
* Represents utilities for data model tree.
@@ -307,4 +311,104 @@
}
return nodes;
}
+
+ /**
+ * Clones the list of leaves and list of leaf list in the leaves holder.
+ *
+ * @param leavesHolder YANG node potentially containing leaves or leaf lists
+ * @throws CloneNotSupportedException clone is not supported
+ * @throws DataModelException data model error
+ */
+ public static void cloneLeaves(YangLeavesHolder leavesHolder)
+ throws CloneNotSupportedException, DataModelException {
+ List<YangLeaf> currentListOfLeaves = leavesHolder.getListOfLeaf();
+ if (currentListOfLeaves != null) {
+ List<YangLeaf> clonedLeavesList = new LinkedList<YangLeaf>();
+ for (YangLeaf leaf : currentListOfLeaves) {
+ YangLeaf clonedLeaf = leaf.clone();
+ clonedLeaf.setContainedIn(leavesHolder);
+ clonedLeavesList.add(clonedLeaf);
+ }
+ leavesHolder.setListOfLeaf(clonedLeavesList);
+ }
+
+ List<YangLeafList> currentListOfLeafList = leavesHolder.getListOfLeafList();
+ if (currentListOfLeafList != null) {
+ List<YangLeafList> clonedListOfLeafList = new LinkedList<YangLeafList>();
+ for (YangLeafList leafList : currentListOfLeafList) {
+ YangLeafList clonedLeafList = leafList.clone();
+ clonedLeafList.setContainedIn(leavesHolder);
+ clonedListOfLeafList.add(clonedLeafList);
+ }
+ leavesHolder.setListOfLeafList(clonedListOfLeafList);
+ }
+ }
+
+ /**
+ * Clones the union or enum leaves. If there is any cloned leaves whose type is union/enum then the corresponding
+ * type info needs to be updated to the cloned new type node.
+ *
+ * @param leavesHolder cloned leaves holder, for whom the leaves reference needs to be updated
+ */
+ public static void updateClonedLeavesUnionEnumRef(YangLeavesHolder leavesHolder) throws DataModelException {
+ List<YangLeaf> currentListOfLeaves = leavesHolder.getListOfLeaf();
+ if (currentListOfLeaves != null) {
+ for (YangLeaf leaf : currentListOfLeaves) {
+ if (leaf.getDataType().getDataType() == YangDataTypes.ENUMERATION
+ || leaf.getDataType().getDataType() == YangDataTypes.UNION) {
+ try {
+ updateClonedTypeRef(leaf.getDataType(), leavesHolder);
+ } catch (DataModelException e) {
+ throw e;
+ }
+ }
+ }
+
+ }
+
+ List<YangLeafList> currentListOfLeafList = leavesHolder.getListOfLeafList();
+ if (currentListOfLeafList != null) {
+ for (YangLeafList leafList : currentListOfLeafList) {
+ if (leafList.getDataType().getDataType() == YangDataTypes.ENUMERATION
+ || leafList.getDataType().getDataType() == YangDataTypes.UNION) {
+ try {
+ updateClonedTypeRef(leafList.getDataType(), leavesHolder);
+ } catch (DataModelException e) {
+ throw e;
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Updates the types extended info pointer to point to the cloned type node.
+ *
+ * @param dataType data type, whose extended info needs to be pointed to the cloned type
+ * @param leavesHolder the leaves holder having the cloned type
+ */
+ private static void updateClonedTypeRef(YangType dataType, YangLeavesHolder leavesHolder)
+ throws DataModelException {
+ if (!(leavesHolder instanceof YangNode)) {
+ throw new DataModelException("Data model error: cloned leaves holder is not a node");
+ }
+ YangNode potentialTypeNode = ((YangNode) leavesHolder).getChild();
+ while (potentialTypeNode != null) {
+ String dataTypeName = null;
+ if (dataType.getDataType() == YangDataTypes.ENUMERATION) {
+ YangEnumeration enumNode = (YangEnumeration) dataType.getDataTypeExtendedInfo();
+ dataTypeName = enumNode.getName();
+ } else if (dataType.getDataType() == YangDataTypes.UNION) {
+ YangUnion unionNode = (YangUnion) dataType.getDataTypeExtendedInfo();
+ dataTypeName = unionNode.getName();
+ }
+ if (potentialTypeNode.getName().contentEquals(dataTypeName)) {
+ dataType.setDataTypeExtendedInfo((Object) potentialTypeNode);
+ return;
+ }
+ potentialTypeNode = potentialTypeNode.getNextSibling();
+ }
+
+ throw new DataModelException("Data model error: cloned leaves type is not found");
+ }
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/exception/InvalidNodeForTranslatorException.java b/plugin/src/main/java/org/onosproject/yangutils/translator/exception/InvalidNodeForTranslatorException.java
new file mode 100644
index 0000000..03b0382
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/exception/InvalidNodeForTranslatorException.java
@@ -0,0 +1,79 @@
+/*
+ * 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.translator.exception;
+
+/**
+ * Represents custom translator exception for translator's operations.
+ */
+public class InvalidNodeForTranslatorException extends RuntimeException {
+
+ private static final long serialVersionUID = 20160311L;
+ private String fileName;
+
+ /**
+ * Create a new exception.
+ */
+ public InvalidNodeForTranslatorException() {
+ super();
+ }
+
+ /**
+ * Creates a new exception with given message.
+ *
+ * @param message the detail of exception in string
+ */
+ public InvalidNodeForTranslatorException(String message) {
+ super(message);
+ }
+
+ /**
+ * Creates a new exception from given message and cause.
+ *
+ * @param message the detail of exception in string
+ * @param cause underlying cause of the error
+ */
+ public InvalidNodeForTranslatorException(final String message, final Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Creates a new exception from cause.
+ *
+ * @param cause underlying cause of the error
+ */
+ public InvalidNodeForTranslatorException(final Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * Returns generated file name for the exception.
+ *
+ * @return generated file name for the exception
+ */
+ public String getFileName() {
+ return this.fileName;
+ }
+
+ /**
+ * Sets file name in translator exception.
+ *
+ * @param fileName generated file name
+ */
+ public void setFileName(String fileName) {
+ this.fileName = fileName;
+ }
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java
index 83a2999..04bb2e2 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java
@@ -17,17 +17,16 @@
package org.onosproject.yangutils.translator.tojava;
import java.io.IOException;
-
+import org.onosproject.yangutils.datamodel.TraversalType;
import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangTypeDef;
-import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
+import org.onosproject.yangutils.translator.exception.InvalidNodeForTranslatorException;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
-import static org.onosproject.yangutils.translator.tojava.TraversalType.CHILD;
-import static org.onosproject.yangutils.translator.tojava.TraversalType.PARENT;
-import static org.onosproject.yangutils.translator.tojava.TraversalType.ROOT;
-import static org.onosproject.yangutils.translator.tojava.TraversalType.SIBILING;
+import static org.onosproject.yangutils.datamodel.TraversalType.CHILD;
+import static org.onosproject.yangutils.datamodel.TraversalType.PARENT;
+import static org.onosproject.yangutils.datamodel.TraversalType.ROOT;
+import static org.onosproject.yangutils.datamodel.TraversalType.SIBILING;
/**
* Representation of java code generator based on application schema.
@@ -82,23 +81,18 @@
if (!(codeGenNode instanceof JavaCodeGenerator)) {
throw new TranslatorException("Unsupported node to generate code");
}
- if (codeGenNode instanceof YangTypeDef) {
- YangTypeDef typeDef = (YangTypeDef) codeGenNode;
- if (typeDef.getTypeDefBaseType().getDataType() == YangDataTypes.LEAFREF
- || typeDef.getTypeDefBaseType().getDataType() == YangDataTypes.IDENTITYREF) {
- if (codeGenNode.getNextSibling() != null) {
- curTraversal = SIBILING;
- codeGenNode = codeGenNode.getNextSibling();
- } else {
- curTraversal = PARENT;
- codeGenNode = codeGenNode.getParent();
- }
- continue;
- }
- }
setCurNode(codeGenNode);
try {
generateCodeEntry(codeGenNode, yangPlugin);
+ } catch (InvalidNodeForTranslatorException e) {
+ if (codeGenNode.getNextSibling() != null) {
+ curTraversal = SIBILING;
+ codeGenNode = codeGenNode.getNextSibling();
+ } else {
+ curTraversal = PARENT;
+ codeGenNode = codeGenNode.getParent();
+ }
+ continue;
} catch (Exception e) {
throw new TranslatorException(e.getMessage());
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaGrouping.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaGrouping.java
index 808c4c1..6a496ce 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaGrouping.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaGrouping.java
@@ -15,9 +15,8 @@
*/
package org.onosproject.yangutils.translator.tojava.javamodel;
-import java.io.IOException;
-
import org.onosproject.yangutils.datamodel.YangGrouping;
+import org.onosproject.yangutils.translator.exception.InvalidNodeForTranslatorException;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
@@ -25,8 +24,6 @@
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
-import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.updatePackageInfo;
-
/**
* Represents grouping information extended to support java code generation.
*/
@@ -102,11 +99,7 @@
@Override
public void generateCodeEntry(YangPluginConfig yangPlugin)
throws TranslatorException {
- try {
- updatePackageInfo(this, yangPlugin);
- } catch (IOException e) {
- throw new TranslatorException(e.getCause());
- }
+ throw new InvalidNodeForTranslatorException();
}
@Override
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaUses.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaUses.java
index cef6202..409688f 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaUses.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaUses.java
@@ -15,14 +15,8 @@
*/
package org.onosproject.yangutils.translator.tojava.javamodel;
-import java.io.IOException;
-import java.util.List;
-
-import org.onosproject.yangutils.datamodel.YangGrouping;
-import org.onosproject.yangutils.datamodel.YangLeaf;
-import org.onosproject.yangutils.datamodel.YangLeafList;
-import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangUses;
+import org.onosproject.yangutils.translator.exception.InvalidNodeForTranslatorException;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
@@ -30,10 +24,6 @@
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
-import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParentNodeInGenCode;
-import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.addCurNodeAsAttributeInTargetTempFile;
-import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.updatePackageInfo;
-
/**
* Represents uses information extended to support java code generation.
*/
@@ -108,42 +98,7 @@
@Override
public void generateCodeEntry(YangPluginConfig yangPlugin)
throws TranslatorException {
- try {
- updatePackageInfo(this, yangPlugin);
-
- if (!(getParentNodeInGenCode(this) instanceof JavaCodeGeneratorInfo)) {
- throw new TranslatorException("invalid container of uses");
- }
- JavaCodeGeneratorInfo javaCodeGeneratorInfo = (JavaCodeGeneratorInfo) getParentNodeInGenCode(this);
-
- if (javaCodeGeneratorInfo instanceof YangGrouping) {
- /*
- * Do nothing, since it will taken care in the groupings uses.
- */
- return;
- }
-
- for (List<YangLeaf> leavesList : getUsesResolvedLeavesList()) {
- // add the resolved leaves to the parent as an attribute
- javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
- .getBeanTempFiles().addLeavesInfoToTempFiles(leavesList, yangPlugin);
- }
-
- for (List<YangLeafList> listOfLeafLists : getUsesResolvedListOfLeafList()) {
- // add the resolved leaf-list to the parent as an attribute
- javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
- .getBeanTempFiles().addLeafListInfoToTempFiles(listOfLeafLists, yangPlugin);
- }
-
- for (YangNode usesResolvedNode : getUsesResolvedNodeList()) {
- // add the resolved nodes to the parent as an attribute
- addCurNodeAsAttributeInTargetTempFile(usesResolvedNode, yangPlugin,
- getParentNodeInGenCode(this));
- }
-
- } catch (IOException e) {
- throw new TranslatorException(e.getCause());
- }
+ throw new InvalidNodeForTranslatorException();
}
@Override
diff --git a/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/IntraFileUsesLinkingTest.java b/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/IntraFileUsesLinkingTest.java
index 43a7c02..44ce858 100644
--- a/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/IntraFileUsesLinkingTest.java
+++ b/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/IntraFileUsesLinkingTest.java
@@ -17,14 +17,13 @@
package org.onosproject.yangutils.plugin.manager;
import java.io.IOException;
-import java.util.List;
import java.util.ListIterator;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.onosproject.yangutils.datamodel.YangContainer;
-import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.datamodel.YangGrouping;
+import org.onosproject.yangutils.datamodel.YangInput;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangList;
import org.onosproject.yangutils.datamodel.YangModule;
@@ -33,6 +32,7 @@
import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.datamodel.YangUses;
import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
+import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.linker.exceptions.LinkerException;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
@@ -70,8 +70,13 @@
YangModule yangNode = (YangModule) node;
assertThat(yangNode.getName(), is("Test"));
- ListIterator<YangLeaf> leafIterator;
- YangLeaf leafInfo;
+ ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+ YangLeaf leafInfo = leafIterator.next();
+
+ // Check whether the information in the leaf is correct under module.
+ assertThat(leafInfo.getName(), is("hello"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
// Check whether grouping is the sibling of module's child.
assertThat((yangNode.getChild().getNextSibling() instanceof YangGrouping), is(true));
@@ -89,20 +94,9 @@
assertThat((yangNode.getChild() instanceof YangUses), is(true));
YangUses uses = (YangUses) yangNode.getChild();
- // Check whether uses get resolved.
+ // Check whether uses get resolved
assertThat(uses.getResolvableStatus(),
is(ResolvableStatus.RESOLVED));
-
- ListIterator<List<YangLeaf>> leafIterator1 = uses.getUsesResolvedLeavesList().listIterator();
- List<YangLeaf> leafInfo1 = leafIterator1.next();
- ListIterator<YangLeaf> leafIterator2 = leafInfo1.listIterator();
- YangLeaf leafInfo2 = leafIterator2.next();
-
- // Check whether the information in the leaf is correct under module.
- assertThat(leafInfo2.getName(), is("hello"));
- assertThat(leafInfo2.getDataType().getDataTypeName(), is("string"));
- assertThat(leafInfo2.getDataType().getDataType(), is(YangDataTypes.STRING));
-
}
/**
@@ -129,6 +123,27 @@
ListIterator<YangLeaf> leafIterator;
YangLeaf leafInfo;
+ ListIterator<YangLeaf> leafIterator1 = yangNode.getListOfLeaf().listIterator();
+ YangLeaf leafInfo1 = leafIterator1.next();
+
+ // Check whether the information in the leaf is correct under module.
+ assertThat(leafInfo1.getName(), is("treat"));
+ assertThat(leafInfo1.getDataType().getDataTypeName(), is("string"));
+ assertThat(leafInfo1.getDataType().getDataType(), is(YangDataTypes.STRING));
+
+ YangContainer container = (YangContainer) yangNode.getChild().getNextSibling().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.getName(), is("leaf2"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
+
// Check whether grouping is the sibling of module's child.
assertThat((yangNode.getChild().getNextSibling() instanceof YangGrouping), is(true));
@@ -143,7 +158,7 @@
// Check whether container is the child of grouping.
assertThat((grouping.getChild() instanceof YangContainer), is(true));
- YangContainer container = (YangContainer) grouping.getChild();
+ container = (YangContainer) grouping.getChild();
// Check whether the container name is set correctly which is under grouping.
assertThat(container.getName(), is("test"));
@@ -164,32 +179,6 @@
assertThat(uses.getResolvableStatus(),
is(ResolvableStatus.RESOLVED));
- ListIterator<List<YangLeaf>> leafIterator1 = uses.getUsesResolvedLeavesList().listIterator();
- List<YangLeaf> leafInfo1 = leafIterator1.next();
- ListIterator<YangLeaf> leafIterator2 = leafInfo1.listIterator();
- YangLeaf leafInfo2 = leafIterator2.next();
-
- // Check whether the information in the leaf is correct under module.
- assertThat(leafInfo2.getName(), is("treat"));
- assertThat(leafInfo2.getDataType().getDataTypeName(), is("string"));
- assertThat(leafInfo2.getDataType().getDataType(), is(YangDataTypes.STRING));
-
- ListIterator<YangNode> usesChildren = uses.getUsesResolvedNodeList().listIterator();
- YangNode usesChild = usesChildren.next();
- // Check whether container is the child of module.
- assertThat((usesChild instanceof YangContainer), is(true));
- container = (YangContainer) usesChild;
-
- // 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.getName(), is("leaf2"));
- assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
- assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
}
/**
@@ -245,18 +234,12 @@
YangUses uses = (YangUses) yangNode.getChild().getChild().getNextSibling().getChild();
// Check whether uses get resolved.
- assertThat(uses.getResolvableStatus(),
- is(ResolvableStatus.RESOLVED));
+ assertThat(uses.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
- ListIterator<YangNode> usesChildren = uses.getUsesResolvedNodeList().listIterator();
- YangNode usesChild = usesChildren.next();
+ YangInput inputNode = ((YangInput) yangNode.getChild().getChild().getNextSibling());
+ assertThat((inputNode.getChild() instanceof YangUses), is(true));
- // Check whether list is the sibling of uses which has been deep copied from grouping.
- assertThat((usesChild instanceof YangList), is(true));
-
- YangList yangList = (YangList) usesChild;
-
- // Check whether the list name is set correctly.
+ YangList yangList = ((YangList) inputNode.getChild().getNextSibling());
assertThat(yangList.getName(), is("valid"));
leafIterator = yangList.getListOfLeaf().listIterator();
@@ -268,36 +251,6 @@
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));
-
- ListIterator<YangNode> usesInOuputChildren = usesInOuput.getUsesResolvedNodeList().listIterator();
- YangNode usesInOuputChild = usesInOuputChildren.next();
-
- // Check whether list is the sibling of uses which has been deep copied from grouping.
- assertThat((usesInOuputChild instanceof YangList), is(true));
-
- YangList yangListInOutput = (YangList) usesInOuputChild;
-
- // 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.getName(), 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\""));
}
/**
@@ -350,18 +303,16 @@
YangUses firstUses = (YangUses) grouping.getChild();
// Check whether uses get resolved.
- assertThat(firstUses.getResolvableStatus(),
- is(ResolvableStatus.RESOLVED));
+ assertThat(firstUses.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
- ListIterator<YangNode> firstUsesChildren = firstUses.getUsesResolvedNodeList().listIterator();
- YangNode firstUsesChild = firstUsesChildren.next();
+ // Validate first uses child is cloned properly
+ assertThat((firstUses.getNextSibling().getNextSibling()
+ .getNextSibling().getNextSibling() instanceof YangList), is(true));
+ YangList firstUsesChild = ((YangList) firstUses.getNextSibling().getNextSibling().getNextSibling()
+ .getNextSibling());
+ assertThat(firstUsesChild.getName(), is("valid"));
- // Check whether list is the sibling of uses.
- assertThat((firstUsesChild instanceof YangList), is(true));
- YangList yangList = (YangList) firstUsesChild;
- assertThat(yangList.getName(), is("valid"));
-
- leafIterator = yangList.getListOfLeaf().listIterator();
+ leafIterator = firstUsesChild.getListOfLeaf().listIterator();
leafInfo = leafIterator.next();
// Check whether the information in the leaf is correct under list which has been deep copied from grouping.
@@ -371,134 +322,45 @@
assertThat(leafInfo.getUnits(), is("\"seconds\""));
assertThat(leafInfo.getReference(), is("\"RFC 6020\""));
- // Check whether container is the sibling of uses.
+ //validate uses second
assertThat((firstUses.getNextSibling() instanceof YangContainer), is(true));
- YangContainer yangContainer = (YangContainer) firstUses.getNextSibling();
+ YangContainer container = (YangContainer) firstUses.getNextSibling();
+ assertThat(container.getName(), is("design"));
- // Check whether the container name is set correctly.
- assertThat(yangContainer.getName(), is("design"));
+ assertThat((container.getChild() instanceof YangUses), is(true));
+ assertThat((container.getListOfLeaf().iterator().next().getName()), is("ink"));
- // Check whether uses is design-container's child.
- assertThat((yangContainer.getChild() instanceof YangUses), is(true));
- YangUses secondUses = (YangUses) yangContainer.getChild();
+ //validate uses third
+ assertThat((container.getChild().getNextSibling() instanceof YangContainer), is(true));
+ YangContainer container2 = ((YangContainer) container.getChild().getNextSibling());
+ assertThat(container2.getName(), is("correct"));
+ assertThat((container2.getChild() instanceof YangUses), is(true));
+ assertThat((container2.getChild().getNextSibling() instanceof YangContainer), is(true));
+ YangContainer thirdUsesChild = ((YangContainer) container2.getChild().getNextSibling());
+ assertThat(thirdUsesChild.getListOfLeaf().iterator().next().getName(), is("zip-code"));
- // Check whether uses get resolved.
- assertThat(secondUses.getResolvableStatus(),
- is(ResolvableStatus.RESOLVED));
+ //validate fourth uses
+ assertThat((firstUses.getNextSibling().getNextSibling() instanceof YangUses), is(true));
+ YangUses fourthUses = ((YangUses) firstUses.getNextSibling().getNextSibling());
+ assertThat((fourthUses.getNextSibling().getNextSibling().getNextSibling() instanceof YangTypeDef),
+ is(true));
+ assertThat(fourthUses.getNextSibling().getNextSibling().getNextSibling().getName(), is("my-type"));
- ListIterator<List<YangLeaf>> leafIterator1 = secondUses.getUsesResolvedLeavesList().listIterator();
- List<YangLeaf> leafInfo1 = leafIterator1.next();
- ListIterator<YangLeaf> leafIterator2 = leafInfo1.listIterator();
- YangLeaf leafInfo2 = leafIterator2.next();
+ //validate fifth uses
+ assertThat((firstUses.getNextSibling().getNextSibling().getNextSibling() instanceof YangUses),
+ is(true));
- // Check whether the information in the leaf is correct under design-container.
- assertThat(leafInfo2.getName(), is("ink"));
- assertThat(leafInfo2.getDataType().getDataTypeName(), is("int32"));
- assertThat(leafInfo2.getDataType().getDataType(), is(YangDataTypes.INT32));
-
- // 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.getName(), 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));
-
- ListIterator<YangNode> thirdUsesChildren = thirdUses.getUsesResolvedNodeList().listIterator();
- YangNode thirdUsesChild = thirdUsesChildren.next();
-
- // Check whether container is the child of uses.
- assertThat((thirdUsesChild instanceof YangContainer), is(true));
-
- YangContainer yangContainer3 = (YangContainer) thirdUsesChild;
- 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.getName(), 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();
- assertThat(fourthUses.getName(), is("fourth"));
- // Check whether uses get resolved.
- assertThat(fourthUses.getResolvableStatus(),
- is(ResolvableStatus.RESOLVED));
-
- ListIterator<List<YangLeaf>> fourthUsesChildren = fourthUses.getUsesResolvedLeavesList().listIterator();
- List<YangLeaf> fourthUsesChild = fourthUsesChildren.next();
- ListIterator<YangLeaf> fourthUsesChildren1 = fourthUsesChild.listIterator();
- YangLeaf fourthUsesChild1 = fourthUsesChildren1.next();
-
- // Check whether the information in the leaf is correct under correct-container.
- assertThat(fourthUsesChild1.getName(), is("correct"));
- assertThat(fourthUsesChild1.getDataType().getDataTypeName(), is("my-type"));
- assertThat(fourthUsesChild1.getDataType().getDataType(), is(YangDataTypes.DERIVED));
-
- // Check whether uses is the sibling of previous uses.
- assertThat((fourthUses.getNextSibling() instanceof YangUses), is(true));
- YangUses fifthUses = (YangUses) fourthUses.getNextSibling();
- assertThat(fifthUses.getName(), is("fifth"));
-
- // Check whether uses get resolved.
- assertThat(fifthUses.getResolvableStatus(),
- is(ResolvableStatus.RESOLVED));
-
- ListIterator<List<YangLeaf>> fifthUsesChildren = fifthUses.getUsesResolvedLeavesList().listIterator();
- List<YangLeaf> fifthUsesChild = fifthUsesChildren.next();
- ListIterator<YangLeaf> fifthUsesChildren1 = fifthUsesChild.listIterator();
- YangLeaf fifthUsesChild1 = fifthUsesChildren1.next();
-
- //Check whether the information in the leaf is correct under correct-container.
- assertThat(fifthUsesChild1.getName(), is("abc"));
- assertThat(fifthUsesChild1.getDataType().getDataTypeName(), is("string"));
- assertThat(fifthUsesChild1.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.getName(), is("endpoint"));
-
- ListIterator<YangNode> endpointUsesUsesChildren = endpointUses.getUsesResolvedNodeList().listIterator();
- YangNode endpointUsesUsesChild = endpointUsesUsesChildren.next();
-
- // Check whether list is the sibling of uses.
- assertThat((endpointUsesUsesChild instanceof YangList), is(true));
- YangList yangList1 = (YangList) firstUsesChild;
- assertThat(yangList1.getName(), is("valid"));
-
- leafIterator = yangList1.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.getName(), 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\""));
+ //validate end point uses
+ assertThat(grouping.getNextSibling() instanceof YangUses, is(true));
+ assertThat(grouping.getNextSibling().getNextSibling().getNextSibling().getNextSibling()
+ .getNextSibling().getNextSibling().getNextSibling().getNextSibling() instanceof YangContainer,
+ is(true));
+ container = (YangContainer) grouping.getNextSibling().getNextSibling().getNextSibling().getNextSibling()
+ .getNextSibling().getNextSibling().getNextSibling().getNextSibling();
+ assertThat(container.getName(), is("design"));
+ container2 = (YangContainer) container.getChild().getNextSibling();
+ assertThat(container2.getName(), is("correct"));
+ assertThat(container2.getChild().getNextSibling().getName(), is("value"));
}
/**
diff --git a/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/YangXpathLinkerTest.java b/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/YangXpathLinkerTest.java
index 946bac1..5d1251a 100644
--- a/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/YangXpathLinkerTest.java
+++ b/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/YangXpathLinkerTest.java
@@ -26,6 +26,7 @@
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangReferenceResolver;
import org.onosproject.yangutils.datamodel.YangResolutionInfo;
+import org.onosproject.yangutils.linker.exceptions.LinkerException;
import org.onosproject.yangutils.linker.impl.YangLinkerManager;
import org.onosproject.yangutils.linker.impl.YangXpathLinker;
import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
@@ -229,7 +230,7 @@
*
* @throws IOException when fails to do IO operations
*/
- @Test
+ @Test(expected = LinkerException.class)
public void processIntraFileLinkingInUsesSingleLevel() throws IOException {
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraSingleUses/"));
@@ -259,7 +260,7 @@
*
* @throws IOException when fails to do IO operations
*/
- @Test
+ @Test(expected = LinkerException.class)
public void processIntraFileLinkingInUsesMultiLevel() throws IOException {
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraMultiUses/"));
@@ -568,7 +569,7 @@
*
* @throws IOException when fails to do IO operations
*/
- @Test
+ @Test(expected = LinkerException.class)
public void processInterFileLinkingInUsesMultiLevel() throws IOException {
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterMultiUses/"));