Update ChoiceSchemaNode design
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / parser / util / SchemaContextUtilTest.java
index 3425c68280cac68bdfcb35a23b9f2cfc18a3ed8a..dcb9f2bdd30d9cd39e0c16dee13af6e810daa834 100644 (file)
@@ -16,7 +16,6 @@ import static org.mockito.Mockito.doReturn;
 import java.io.IOException;
 import java.net.URI;
 import java.net.URISyntaxException;
-import java.text.ParseException;
 import java.util.Collections;
 import java.util.Optional;
 import org.junit.Test;
@@ -25,6 +24,7 @@ import org.mockito.Mockito;
 import org.mockito.MockitoAnnotations;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.common.Revision;
 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
@@ -55,8 +55,10 @@ public class SchemaContextUtilTest {
     public void testFindDummyData() {
         MockitoAnnotations.initMocks(this);
         doReturn(Optional.empty()).when(mockSchemaContext).findModule(any(QNameModule.class));
+        doReturn(URI.create("dummy")).when(mockModule).getNamespace();
+        doReturn(Optional.empty()).when(mockModule).getRevision();
 
-        final QName qName = QName.create("TestQName");
+        final QName qName = QName.create("dummy", "TestQName");
         final SchemaPath schemaPath = SchemaPath.create(Collections.singletonList(qName), true);
         assertEquals("Should be null. Module TestQName not found", null,
                 SchemaContextUtil.findDataSchemaNode(mockSchemaContext, schemaPath));
@@ -79,11 +81,11 @@ public class SchemaContextUtilTest {
 
     @Test
     public void findNodeInSchemaContextTest() throws URISyntaxException, IOException, YangSyntaxErrorException,
-            ParseException, ReactorException {
+            ReactorException {
 
         final SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
 
-        final Module myModule = context.findModule(new URI("uri:my-module"), QName.parseRevision("2014-10-07")).get();
+        final Module myModule = context.findModule(new URI("uri:my-module"),Revision.of("2014-10-07")).get();
 
         SchemaNode testNode = ((ContainerSchemaNode) myModule.getDataChildByName(QName.create(
                 myModule.getQNameModule(), "my-container"))).getDataChildByName(QName.create(myModule.getQNameModule(),
@@ -151,7 +153,8 @@ public class SchemaContextUtilTest {
         assertEquals(testNode, foundNode);
 
         testNode = ((ChoiceSchemaNode) myModule
-                .getDataChildByName(QName.create(myModule.getQNameModule(), "my-choice"))).getCaseNodeByName("one")
+                .getDataChildByName(QName.create(myModule.getQNameModule(), "my-choice")))
+                .findCaseNodes("one").iterator().next()
                 .getDataChildByName(QName.create(myModule.getQNameModule(), "my-choice-leaf-one"));
 
         path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-choice"),
@@ -197,11 +200,11 @@ public class SchemaContextUtilTest {
 
     @Test
     public void findNodeInSchemaContextTest2() throws URISyntaxException, IOException, YangSyntaxErrorException,
-            ParseException, ReactorException {
+            ReactorException {
 
         final SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
 
-        final Module myModule = context.findModule(new URI("uri:my-module"), QName.parseRevision("2014-10-07")).get();
+        final Module myModule = context.findModule(new URI("uri:my-module"), Revision.of("2014-10-07")).get();
 
         SchemaNode testNode = ((ContainerSchemaNode) myModule.getDataChildByName(QName.create(
                 myModule.getQNameModule(), "my-container"))).getDataChildByName(QName.create(myModule.getQNameModule(),
@@ -252,7 +255,8 @@ public class SchemaContextUtilTest {
         assertNull(foundNode);
 
         testNode = ((ChoiceSchemaNode) myModule
-                .getDataChildByName(QName.create(myModule.getQNameModule(), "my-choice"))).getCaseNodeByName("one")
+                .getDataChildByName(QName.create(myModule.getQNameModule(), "my-choice")))
+                .findCaseNodes("one").iterator().next()
                 .getDataChildByName(QName.create(myModule.getQNameModule(), "no-choice-leaf"));
 
         path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-choice"),
@@ -295,11 +299,11 @@ public class SchemaContextUtilTest {
 
     @Test
     public void findNodeInSchemaContextTest3() throws URISyntaxException, IOException, YangSyntaxErrorException,
-            ParseException, ReactorException {
+            ReactorException {
 
         final SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
 
-        final Module myModule = context.findModule(new URI("uri:my-module"), QName.parseRevision("2014-10-07")).get();
+        final Module myModule = context.findModule(new URI("uri:my-module"), Revision.of("2014-10-07")).get();
 
         SchemaNode testNode = myModule.getDataChildByName(QName.create(myModule.getQNameModule(), "my-container"));
 
@@ -361,14 +365,14 @@ public class SchemaContextUtilTest {
 
     @Test
     public void findParentModuleTest() throws URISyntaxException, IOException, YangSyntaxErrorException,
-            ParseException, ReactorException {
+            ReactorException {
 
         final SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
 
-        final Module myModule = context.findModule(new URI("uri:my-module"), QName.parseRevision("2014-10-07")).get();
+        final Module myModule = context.findModule(new URI("uri:my-module"), Revision.of("2014-10-07")).get();
 
-        final DataSchemaNode node = myModule
-                .getDataChildByName(QName.create(myModule.getQNameModule(), "my-container"));
+        final DataSchemaNode node = myModule.getDataChildByName(QName.create(myModule.getQNameModule(),
+            "my-container"));
 
         final Module foundModule = SchemaContextUtil.findParentModule(context, node);
 
@@ -421,9 +425,9 @@ public class SchemaContextUtilTest {
     public void findDataSchemaNodeTest() throws URISyntaxException, IOException, YangSyntaxErrorException,
             ReactorException {
         final SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
-        final Module module = context.findModule(new URI("uri:my-module"), QName.parseRevision("2014-10-07")).get();
+        final Module module = context.findModule(new URI("uri:my-module"), Revision.of("2014-10-07")).get();
         final Module importedModule = context.findModule(new URI("uri:imported-module"),
-            QName.parseRevision("2014-10-07")).get();
+            Revision.of("2014-10-07")).get();
 
         final SchemaNode testNode = ((ContainerSchemaNode) importedModule.getDataChildByName(QName.create(
                 importedModule.getQNameModule(), "my-imported-container"))).getDataChildByName(QName.create(
@@ -446,7 +450,7 @@ public class SchemaContextUtilTest {
         // final RevisionAwareXPath nonCondXPath) {
 
         final SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
-        final Module module = context.findModule(new URI("uri:my-module"), QName.parseRevision("2014-10-07")).get();
+        final Module module = context.findModule(new URI("uri:my-module"), Revision.of("2014-10-07")).get();
 
         final GroupingDefinition grouping = getGroupingByName(module, "my-grouping");
         final SchemaNode testNode = grouping.getDataChildByName(QName.create(module.getQNameModule(),
@@ -529,10 +533,10 @@ public class SchemaContextUtilTest {
 
     @Test
     public void findNodeInSchemaContextGroupingsTest() throws URISyntaxException, IOException,
-            YangSyntaxErrorException, ParseException, ReactorException {
+            YangSyntaxErrorException, ReactorException {
 
         final SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
-        final Module myModule = context.findModule(new URI("uri:my-module"), QName.parseRevision("2014-10-07")).get();
+        final Module myModule = context.findModule(URI.create("uri:my-module"), Revision.of("2014-10-07")).get();
 
         // find grouping in container
         DataNodeContainer dataContainer = (DataNodeContainer) myModule.getDataChildByName(QName.create(
@@ -699,9 +703,10 @@ public class SchemaContextUtilTest {
         assertEquals(testNode, foundNode);
 
         // find grouping in case
-        dataContainer = (DataNodeContainer) ((ChoiceSchemaNode) myModule.getDataChildByName(QName.create(
-                myModule.getQNameModule(), "my-choice"))).getCaseNodeByName("one").getDataChildByName(
-                QName.create(myModule.getQNameModule(), "my-container-in-case"));
+        dataContainer = (DataNodeContainer) ((ChoiceSchemaNode) myModule.getDataChildByName(
+            QName.create(myModule.getQNameModule(), "my-choice")))
+                .findCaseNodes("one").iterator().next()
+                .getDataChildByName(QName.create(myModule.getQNameModule(), "my-container-in-case"));
         testNode = getGroupingByName(dataContainer, "my-grouping-in-case");
 
         path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-choice"),
@@ -728,11 +733,11 @@ public class SchemaContextUtilTest {
 
     @Test
     public void findNodeInSchemaContextGroupingsTest2() throws URISyntaxException, IOException,
-            YangSyntaxErrorException, ParseException, ReactorException {
+            YangSyntaxErrorException, ReactorException {
 
         final SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
 
-        final Module myModule = context.findModule(new URI("uri:my-module"), QName.parseRevision("2014-10-07")).get();
+        final Module myModule = context.findModule(new URI("uri:my-module"), Revision.of("2014-10-07")).get();
 
         // find grouping in container
         DataNodeContainer dataContainer = (DataNodeContainer) myModule.getDataChildByName(QName.create(
@@ -822,9 +827,10 @@ public class SchemaContextUtilTest {
         assertNull(foundNode);
 
         // find grouping in case
-        dataContainer = (DataNodeContainer) ((ChoiceSchemaNode) myModule.getDataChildByName(QName.create(
-                myModule.getQNameModule(), "my-choice"))).getCaseNodeByName("one").getDataChildByName(
-                QName.create(myModule.getQNameModule(), "my-container-in-case"));
+        dataContainer = (DataNodeContainer) ((ChoiceSchemaNode) myModule.getDataChildByName(
+            QName.create(myModule.getQNameModule(), "my-choice")))
+                .findCaseNodes("one").iterator().next()
+                .getDataChildByName(QName.create(myModule.getQNameModule(), "my-container-in-case"));
         testNode = getGroupingByName(dataContainer, "my-grouping-in-case2");
 
         path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-choice"),
@@ -867,15 +873,15 @@ public class SchemaContextUtilTest {
 
     @Test
     public void findNodeInSchemaContextTheSameNameOfSiblingsTest() throws URISyntaxException, IOException,
-            YangSyntaxErrorException, ParseException, ReactorException {
+            YangSyntaxErrorException, ReactorException {
 
         final SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
 
-        final Module myModule = context.findModule(new URI("uri:my-module"), QName.parseRevision("2014-10-07")).get();
+        final Module myModule = context.findModule(new URI("uri:my-module"), Revision.of("2014-10-07")).get();
         final ChoiceSchemaNode choice = (ChoiceSchemaNode) getRpcByName(myModule, "my-name").getInput()
                 .getDataChildByName(QName.create(myModule.getQNameModule(), "my-choice"));
-        final SchemaNode testNode = choice.getCaseNodeByName("case-two").getDataChildByName(
-                QName.create(myModule.getQNameModule(), "two"));
+        final SchemaNode testNode = choice.findCaseNodes("case-two").iterator().next()
+                .getDataChildByName(QName.create(myModule.getQNameModule(), "two"));
 
         final SchemaPath path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-name"),
                 QName.create(myModule.getQNameModule(), "input"), QName.create(myModule.getQNameModule(), "my-choice"),