Address FIXME for QueuedNotificationManager
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / parser / impl / AugmentTest.java
index 30c46efc752a6d2fb0d1ae738fd9247f555d10bc..e53afc975d858d9f67c5c47002393586378dd72e 100644 (file)
@@ -11,7 +11,6 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
-
 import java.io.FileNotFoundException;
 import java.net.URI;
 import java.text.DateFormat;
@@ -19,6 +18,7 @@ import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Date;
 import java.util.List;
@@ -28,7 +28,7 @@ import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
-import org.opendaylight.yangtools.yang.model.api.ChoiceNode;
+import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
@@ -46,9 +46,6 @@ public class AugmentTest {
     private static Date fooRev;
     private static Date barRev;
     private static Date bazRev;
-    private static final String foo = "foo";
-    private static final String bar = "bar";
-    private static final String baz = "baz";
     private static QName q0;
     private static QName q1;
     private static QName q2;
@@ -62,9 +59,9 @@ public class AugmentTest {
         barRev = simpleDateFormat.parse("2013-10-14");
         bazRev = simpleDateFormat.parse("2013-10-15");
 
-        q0 = new QName(barNS, barRev, bar, "interfaces");
-        q1 = new QName(barNS, barRev, bar, "ifEntry");
-        q2 = new QName(bazNS, bazRev, baz, "augment-holder");
+        q0 = QName.create(barNS, barRev, "interfaces");
+        q1 = QName.create(barNS, barRev, "ifEntry");
+        q2 = QName.create(bazNS, bazRev, "augment-holder");
     }
 
     @Test
@@ -86,7 +83,7 @@ public class AugmentTest {
         expectedSchemaPath = SchemaPath.create(qnames, true);
         assertEquals(expectedSchemaPath, augment.getTargetPath());
 
-        Set<DataSchemaNode> augmentChildren = augment.getChildNodes();
+        Collection<DataSchemaNode> augmentChildren = augment.getChildNodes();
         assertEquals(4, augmentChildren.size());
         for (DataSchemaNode dsn : augmentChildren) {
             TestUtils.checkIsAugmenting(dsn, false);
@@ -95,7 +92,7 @@ public class AugmentTest {
         LeafSchemaNode ds0ChannelNumber = (LeafSchemaNode) augment.getDataChildByName("ds0ChannelNumber");
         LeafSchemaNode interfaceId = (LeafSchemaNode) augment.getDataChildByName("interface-id");
         ContainerSchemaNode schemas = (ContainerSchemaNode) augment.getDataChildByName("schemas");
-        ChoiceNode odl = (ChoiceNode) augment.getDataChildByName("odl");
+        ChoiceSchemaNode odl = (ChoiceSchemaNode) augment.getDataChildByName("odl");
 
         assertNotNull(ds0ChannelNumber);
         assertNotNull(interfaceId);
@@ -103,7 +100,7 @@ public class AugmentTest {
         assertNotNull(odl);
 
         // leaf ds0ChannelNumber
-        QName qname = new QName(fooNS, fooRev, foo, "ds0ChannelNumber");
+        QName qname = QName.create(fooNS, fooRev, "ds0ChannelNumber");
         qnames.add(qname);
         assertEquals(qname, ds0ChannelNumber.getQName());
         expectedSchemaPath = SchemaPath.create(qnames, true);
@@ -116,7 +113,7 @@ public class AugmentTest {
         assertEquals(expectedSchemaPath, ds0ChannelNumber.getType().getPath());
 
         // leaf interface-id
-        qname = new QName(fooNS, fooRev, foo, "interface-id");
+        qname = QName.create(fooNS, fooRev, "interface-id");
         assertEquals(qname, interfaceId.getQName());
         qnames.set(3, qname);
         expectedSchemaPath = SchemaPath.create(qnames, true);
@@ -124,7 +121,7 @@ public class AugmentTest {
         assertFalse(interfaceId.isAugmenting());
 
         // container schemas
-        qname = new QName(fooNS, fooRev, foo, "schemas");
+        qname = QName.create(fooNS, fooRev, "schemas");
         assertEquals(qname, schemas.getQName());
         qnames.set(3, qname);
         expectedSchemaPath = SchemaPath.create(qnames, true);
@@ -132,7 +129,7 @@ public class AugmentTest {
         assertFalse(schemas.isAugmenting());
 
         // choice odl
-        qname = new QName(fooNS, fooRev, foo, "odl");
+        qname = QName.create(fooNS, fooRev, "odl");
         assertEquals(qname, odl.getQName());
         qnames.set(3, qname);
         expectedSchemaPath = SchemaPath.create(qnames, true);
@@ -198,7 +195,7 @@ public class AugmentTest {
         LeafSchemaNode ds0ChannelNumber = (LeafSchemaNode) augmentHolder.getDataChildByName("ds0ChannelNumber");
         LeafSchemaNode interfaceId = (LeafSchemaNode) augmentHolder.getDataChildByName("interface-id");
         ContainerSchemaNode schemas = (ContainerSchemaNode) augmentHolder.getDataChildByName("schemas");
-        ChoiceNode odl = (ChoiceNode) augmentHolder.getDataChildByName("odl");
+        ChoiceSchemaNode odl = (ChoiceSchemaNode) augmentHolder.getDataChildByName("odl");
 
         assertNotNull(ds0ChannelNumber);
         assertNotNull(interfaceId);
@@ -206,28 +203,28 @@ public class AugmentTest {
         assertNotNull(odl);
 
         // leaf ds0ChannelNumber
-        QName qname = new QName(fooNS, fooRev, foo, "ds0ChannelNumber");
+        QName qname = QName.create(fooNS, fooRev, "ds0ChannelNumber");
         assertEquals(qname, ds0ChannelNumber.getQName());
         qnames.add(qname);
         expectedPath = SchemaPath.create(qnames, true);
         assertEquals(expectedPath, ds0ChannelNumber.getPath());
 
         // leaf interface-id
-        qname = new QName(fooNS, fooRev, foo, "interface-id");
+        qname = QName.create(fooNS, fooRev, "interface-id");
         assertEquals(qname, interfaceId.getQName());
         qnames.set(3, qname);
         expectedPath = SchemaPath.create(qnames, true);
         assertEquals(expectedPath, interfaceId.getPath());
 
         // container schemas
-        qname = new QName(fooNS, fooRev, foo, "schemas");
+        qname = QName.create(fooNS, fooRev, "schemas");
         assertEquals(qname, schemas.getQName());
         qnames.set(3, qname);
         expectedPath = SchemaPath.create(qnames, true);
         assertEquals(expectedPath, schemas.getPath());
 
         // choice odl
-        qname = new QName(fooNS, fooRev, foo, "odl");
+        qname = QName.create(fooNS, fooRev, "odl");
         assertEquals(qname, odl.getQName());
         qnames.set(3, qname);
         expectedPath = SchemaPath.create(qnames, true);
@@ -245,7 +242,7 @@ public class AugmentTest {
 
         // foo.yang
         // augment "/br:interfaces/br:ifEntry/bz:augment-holder"
-        ChoiceNode odl = (ChoiceNode) augmentedHolder.getDataChildByName("odl");
+        ChoiceSchemaNode odl = (ChoiceSchemaNode) augmentedHolder.getDataChildByName("odl");
         assertNotNull(odl);
         Set<ChoiceCaseNode> cases = odl.getCases();
         assertEquals(4, cases.size());
@@ -277,42 +274,42 @@ public class AugmentTest {
         qnames.add(q0);
         qnames.add(q1);
         qnames.add(q2);
-        qnames.add(new QName(fooNS, fooRev, foo, "odl"));
+        qnames.add(QName.create(fooNS, fooRev, "odl"));
 
         // case id
-        QName qname = new QName(fooNS, fooRev, foo, "id");
+        QName qname = QName.create(fooNS, fooRev, "id");
         assertEquals(qname, id.getQName());
         qnames.add(qname);
         expectedPath = SchemaPath.create(qnames, true);
         assertEquals(expectedPath, id.getPath());
-        Set<DataSchemaNode> idChildren = id.getChildNodes();
+        Collection<DataSchemaNode> idChildren = id.getChildNodes();
         assertEquals(1, idChildren.size());
 
         // case node1
-        qname = new QName(fooNS, fooRev, foo, "node1");
+        qname = QName.create(fooNS, fooRev, "node1");
         assertEquals(qname, node1.getQName());
         qnames.set(4, qname);
         expectedPath = SchemaPath.create(qnames, true);
         assertEquals(expectedPath, node1.getPath());
-        Set<DataSchemaNode> node1Children = node1.getChildNodes();
+        Collection<DataSchemaNode> node1Children = node1.getChildNodes();
         assertTrue(node1Children.isEmpty());
 
         // case node2
-        qname = new QName(fooNS, fooRev, foo, "node2");
+        qname = QName.create(fooNS, fooRev, "node2");
         assertEquals(qname, node2.getQName());
         qnames.set(4, qname);
         expectedPath = SchemaPath.create(qnames, true);
         assertEquals(expectedPath, node2.getPath());
-        Set<DataSchemaNode> node2Children = node2.getChildNodes();
+        Collection<DataSchemaNode> node2Children = node2.getChildNodes();
         assertTrue(node2Children.isEmpty());
 
         // case node3
-        qname = new QName(fooNS, fooRev, foo, "node3");
+        qname = QName.create(fooNS, fooRev, "node3");
         assertEquals(qname, node3.getQName());
         qnames.set(4, qname);
         expectedPath = SchemaPath.create(qnames, true);
         assertEquals(expectedPath, node3.getPath());
-        Set<DataSchemaNode> node3Children = node3.getChildNodes();
+        Collection<DataSchemaNode> node3Children = node3.getChildNodes();
         assertEquals(1, node3Children.size());
 
         // test cases
@@ -320,19 +317,19 @@ public class AugmentTest {
         qnames.add(q0);
         qnames.add(q1);
         qnames.add(q2);
-        qnames.add(new QName(fooNS, fooRev, foo, "odl"));
+        qnames.add(QName.create(fooNS, fooRev, "odl"));
 
         // case id child
-        qnames.add(new QName(fooNS, fooRev, foo, "id"));
-        qnames.add(new QName(fooNS, fooRev, foo, "id"));
+        qnames.add(QName.create(fooNS, fooRev, "id"));
+        qnames.add(QName.create(fooNS, fooRev, "id"));
         LeafSchemaNode caseIdChild = (LeafSchemaNode) idChildren.iterator().next();
         assertNotNull(caseIdChild);
         expectedPath = SchemaPath.create(qnames, true);
         assertEquals(expectedPath, caseIdChild.getPath());
 
         // case node3 child
-        qnames.set(4, new QName(fooNS, fooRev, foo, "node3"));
-        qnames.set(5, new QName(fooNS, fooRev, foo, "node3"));
+        qnames.set(4, QName.create(fooNS, fooRev, "node3"));
+        qnames.set(5, QName.create(fooNS, fooRev, "node3"));
         ContainerSchemaNode caseNode3Child = (ContainerSchemaNode) node3Children.iterator().next();
         assertNotNull(caseNode3Child);
         expectedPath = SchemaPath.create(qnames, true);
@@ -359,13 +356,13 @@ public class AugmentTest {
         }
         assertNotNull(submit);
 
-        QName submitQName = new QName(NS_BAR, revision, "b", "submit");
+        QName submitQName = QName.create(NS_BAR, revision, "submit");
         assertEquals(submitQName, submit.getQName());
         ContainerSchemaNode input = submit.getInput();
-        QName inputQName = new QName(NS_BAR, revision, "b", "input");
+        QName inputQName = QName.create(NS_BAR, revision, "input");
         assertEquals(inputQName, input.getQName());
-        ChoiceNode arguments = (ChoiceNode) input.getDataChildByName("arguments");
-        QName argumentsQName = new QName(NS_BAR, revision, "b", "arguments");
+        ChoiceSchemaNode arguments = (ChoiceSchemaNode) input.getDataChildByName("arguments");
+        QName argumentsQName = QName.create(NS_BAR, revision, "arguments");
         assertEquals(argumentsQName, arguments.getQName());
         assertFalse(arguments.isAugmenting());
         Set<ChoiceCaseNode> cases = arguments.getCases();
@@ -398,27 +395,27 @@ public class AugmentTest {
         qnames[2] = argumentsQName;
 
         // case attach
-        qnames[3] = new QName(NS_FOO, revision, "f", "attach");
+        qnames[3] = QName.create(NS_FOO, revision, "attach");
         assertEquals(qnames[3], attach.getQName());
         expectedPath = SchemaPath.create(Arrays.asList(qnames), true);
         assertEquals(expectedPath, attach.getPath());
-        Set<DataSchemaNode> attachChildren = attach.getChildNodes();
+        Collection<DataSchemaNode> attachChildren = attach.getChildNodes();
         assertEquals(1, attachChildren.size());
 
         // case create
-        qnames[3] = new QName(NS_FOO, revision, "f", "create");
+        qnames[3] = QName.create(NS_FOO, revision, "create");
         assertEquals(qnames[3], create.getQName());
         expectedPath = SchemaPath.create(Arrays.asList(qnames), true);
         assertEquals(expectedPath, create.getPath());
-        Set<DataSchemaNode> createChildren = create.getChildNodes();
+        Collection<DataSchemaNode> createChildren = create.getChildNodes();
         assertEquals(1, createChildren.size());
 
         // case attach
-        qnames[3] = new QName(NS_FOO, revision, "f", "destroy");
+        qnames[3] = QName.create(NS_FOO, revision, "destroy");
         assertEquals(qnames[3], destroy.getQName());
         expectedPath = SchemaPath.create(Arrays.asList(qnames), true);
         assertEquals(expectedPath, destroy.getPath());
-        Set<DataSchemaNode> destroyChildren = destroy.getChildNodes();
+        Collection<DataSchemaNode> destroyChildren = destroy.getChildNodes();
         assertEquals(1, destroyChildren.size());
     }
 
@@ -439,4 +436,22 @@ public class AugmentTest {
         assertTrue(id.isAugmenting());
     }
 
+    @Test
+    public void caseShortHandAugmentingTest() throws Exception {
+        modules = TestUtils.loadModules(getClass().getResource("/choice-case-type-test-models").toURI());
+
+        Module findModule = TestUtils.findModule(modules, "choice-monitoring");
+
+        ContainerSchemaNode netconf =  (ContainerSchemaNode) findModule.getDataChildByName("netconf-state");
+        ContainerSchemaNode datastores =  (ContainerSchemaNode) netconf.getDataChildByName("datastores");
+        ListSchemaNode datastore =  (ListSchemaNode) datastores.getDataChildByName("datastore");
+        ContainerSchemaNode locks =  (ContainerSchemaNode) datastore.getDataChildByName("locks");
+        ChoiceSchemaNode lockType =  (ChoiceSchemaNode)locks.getDataChildByName("lock-type");
+
+        ChoiceCaseNode leafAugCase = lockType.getCaseNodeByName("leaf-aug-case");
+        assertTrue(leafAugCase.isAugmenting());
+        DataSchemaNode leafAug = leafAugCase.getDataChildByName("leaf-aug-case");
+        assertFalse(leafAug.isAugmenting());
+    }
+
 }