[ONOS-4636]grouping and uses
Change-Id: Ic410d03a838003ad23b2b0e8874b91503da84153
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/exception/InvalidNodeForTranslatorException.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/exception/InvalidNodeForTranslatorException.java
new file mode 100644
index 0000000..03b0382
--- /dev/null
+++ b/utils/yangutils/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/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java
index 83a2999..04bb2e2 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java
+++ b/utils/yangutils/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/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaGrouping.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaGrouping.java
index 808c4c1..6a496ce 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaGrouping.java
+++ b/utils/yangutils/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/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaUses.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaUses.java
index cef6202..409688f 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaUses.java
+++ b/utils/yangutils/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/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/IntraFileUsesLinkingTest.java b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/IntraFileUsesLinkingTest.java
index 43a7c02..44ce858 100644
--- a/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/IntraFileUsesLinkingTest.java
+++ b/utils/yangutils/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/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/YangXpathLinkerTest.java b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/YangXpathLinkerTest.java
index 946bac1..5d1251a 100644
--- a/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/YangXpathLinkerTest.java
+++ b/utils/yangutils/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/"));