handling of unique
Change-Id: Iadd216f2c8ada19a3b3c11a670497d1a493b8237
diff --git a/compiler/base/parser/src/test/java/org/onosproject/yang/compiler/parser/impl/listeners/DeviationListenerTest.java b/compiler/base/parser/src/test/java/org/onosproject/yang/compiler/parser/impl/listeners/DeviationListenerTest.java
index cca24d1..8b8e5ba 100644
--- a/compiler/base/parser/src/test/java/org/onosproject/yang/compiler/parser/impl/listeners/DeviationListenerTest.java
+++ b/compiler/base/parser/src/test/java/org/onosproject/yang/compiler/parser/impl/listeners/DeviationListenerTest.java
@@ -115,7 +115,6 @@
assertThat(deviateAdd.getUnits(), is("\"units\""));
assertThat(deviateAdd.getListOfMust().get(0).getConstraint(),
is("/base:system"));
- assertThat(deviateAdd.getUniqueList().get(0), is("id"));
assertThat(deviateAdd.getDefaultValueInString(), is("admin"));
assertThat(deviateAdd.isConfig(), is(true));
assertThat(deviateAdd.isMandatory(), is(true));
@@ -152,7 +151,6 @@
assertThat(deviateDelete.getUnits(), is("\"units\""));
assertThat(deviateDelete.getListOfMust().get(0).getConstraint(),
is("daytime or time"));
- assertThat(deviateDelete.getUniqueList().get(0), is("id"));
assertThat(deviateDelete.getDefaultValueInString(), is("defaultValue"));
assertThat(deviation.getResolvableStatus(), is(UNRESOLVED));
}
diff --git a/compiler/base/parser/src/test/java/org/onosproject/yang/compiler/parser/impl/listeners/UniqueListenerTest.java b/compiler/base/parser/src/test/java/org/onosproject/yang/compiler/parser/impl/listeners/UniqueListenerTest.java
index ababd08..7eeef04 100644
--- a/compiler/base/parser/src/test/java/org/onosproject/yang/compiler/parser/impl/listeners/UniqueListenerTest.java
+++ b/compiler/base/parser/src/test/java/org/onosproject/yang/compiler/parser/impl/listeners/UniqueListenerTest.java
@@ -19,6 +19,8 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.onosproject.yang.compiler.datamodel.YangAtomicPath;
+import org.onosproject.yang.compiler.datamodel.YangLeaf;
import org.onosproject.yang.compiler.datamodel.YangList;
import org.onosproject.yang.compiler.datamodel.YangModule;
import org.onosproject.yang.compiler.datamodel.YangNode;
@@ -27,7 +29,8 @@
import org.onosproject.yang.compiler.parser.impl.YangUtilsParserManager;
import java.io.IOException;
-import java.util.ListIterator;
+import java.util.Iterator;
+import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
@@ -62,7 +65,10 @@
// Check whether the list is child of module
YangList yangList = (YangList) yangNode.getChild();
assertThat(yangList.getName(), is("valid"));
- assertThat(yangList.getUniqueList().listIterator().next(), is("invalid-interval"));
+ List<YangLeaf> leaves = yangList.getListOfLeaf();
+ YangLeaf leaf = leaves.iterator().next();
+
+ List<List<YangAtomicPath>> uniLeaves = yangList.getPathList();
}
/**
@@ -85,12 +91,85 @@
// Check whether the list is child of module
YangList yangList = (YangList) yangNode.getChild();
assertThat(yangList.getName(), is("valid"));
- ListIterator<String> listIterator;
- String list;
- listIterator = yangList.getUniqueList().listIterator();
- list = listIterator.next();
- assertThat(list, is("ospf"));
- list = listIterator.next();
- assertThat(list, is("isis"));
+
+ Iterator<List<YangAtomicPath>> pathListIt;
+ Iterator<YangAtomicPath> pathIt;
+ List<YangAtomicPath> path;
+ YangAtomicPath atPath;
+
+ pathListIt = yangList.getPathList().iterator();
+ path = pathListIt.next();
+ assertThat(path.size(), is(1));
+ pathIt = path.iterator();
+ atPath = pathIt.next();
+ assertThat(atPath.getNodeIdentifier().getName(), is("ospf"));
+ path = pathListIt.next();
+ assertThat(path.size(), is(1));
+ pathIt = path.iterator();
+ atPath = pathIt.next();
+ assertThat(atPath.getNodeIdentifier().getName(), is("isis"));
+ }
+
+
+ /**
+ * Check single unique along its atomic path.
+ */
+ @Test
+ public void processParsingUniqueValues() throws IOException,
+ ParserException {
+ YangNode node = manager.getDataModel(
+ "src/test/resources/UniqueError.yang");
+ 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("TestUnique"));
+
+ //Check whether the list is child of module.
+ YangList yangList = (YangList) yangNode.getChild();
+ assertThat(yangList.getName(), is("resources"));
+
+ Iterator<List<YangAtomicPath>> pathListIt;
+ Iterator<YangAtomicPath> pathIt;
+ List<YangAtomicPath> path;
+ YangAtomicPath atPath;
+
+ pathListIt = yangList.getPathList().iterator();
+ path = pathListIt.next();
+ assertThat(path.size(), is(3));
+ pathIt = path.iterator();
+ atPath = pathIt.next();
+ assertThat(atPath.getNodeIdentifier().getName(), is("animal"));
+ atPath = pathIt.next();
+ assertThat(atPath.getNodeIdentifier().getName(), is("mammal"));
+ atPath = pathIt.next();
+ assertThat(atPath.getNodeIdentifier().getName(), is("abc"));
+ }
+
+ /**
+ * Check unique for its descendent.
+ */
+ @Test
+ public void processParsingUniqueDescendent() throws IOException,
+ ParserException {
+ thrown.expect(ParserException.class);
+ thrown.expectMessage("YANG file error : unique name is" +
+ " not valid.");
+ YangNode node = manager.getDataModel(
+ "src/test/resources/UniqueDescendent.yang");
+ }
+
+ /**
+ * Check the error for wrong holder of unique.
+ */
+ @Test
+ public void processWrongHolderOfUnique() throws IOException,
+ ParserException {
+ thrown.expect(ParserException.class);
+ YangNode node = manager.getDataModel(
+ "src/test/resources/WrongHolderOfUnique.yang");
}
}
\ No newline at end of file
diff --git a/compiler/base/parser/src/test/resources/UniqueDescendent.yang b/compiler/base/parser/src/test/resources/UniqueDescendent.yang
new file mode 100644
index 0000000..20409cb
--- /dev/null
+++ b/compiler/base/parser/src/test/resources/UniqueDescendent.yang
@@ -0,0 +1,12 @@
+module TestDescendent {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ list networks {
+ key "abc";
+ unique "/abc";
+ leaf abc {
+ type "String";
+ }
+ }
+}
\ No newline at end of file
diff --git a/compiler/base/parser/src/test/resources/UniqueError.yang b/compiler/base/parser/src/test/resources/UniqueError.yang
new file mode 100644
index 0000000..cd15de1
--- /dev/null
+++ b/compiler/base/parser/src/test/resources/UniqueError.yang
@@ -0,0 +1,20 @@
+module TestUnique {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Anim;
+ list resources {
+ key "count";
+ leaf count {
+ type int;
+ }
+ unique "animal/mammal/abc";
+ container animal {
+ list mammal {
+ key "abc";
+ leaf abc {
+ type "String";
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/compiler/base/parser/src/test/resources/WrongHolderOfUnique.yang b/compiler/base/parser/src/test/resources/WrongHolderOfUnique.yang
new file mode 100644
index 0000000..b259cc1
--- /dev/null
+++ b/compiler/base/parser/src/test/resources/WrongHolderOfUnique.yang
@@ -0,0 +1,11 @@
+module TestHolder {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Hold;
+ container birds {
+ unique "abc"
+ leaf abc {
+ type "String";
+ }
+ }
+}
\ No newline at end of file