Further testing cleanup
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / AugmentTest.java
index 50f3e666e7288f7c77ffb1b8c65a15ead93eca30..b2a54ba4877ec26d4ad4b24963326484dc30f77b 100644 (file)
@@ -13,6 +13,7 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
 import java.util.Collection;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
@@ -24,16 +25,16 @@ 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;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.InputSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
 import org.opendaylight.yangtools.yang.model.api.type.TypeDefinitions;
 
-public class AugmentTest {
+public class AugmentTest extends AbstractYangTest {
     private static final QNameModule FOO = QNameModule.create(
         XMLNamespace.of("urn:opendaylight.foo"), Revision.of("2013-10-13"));
     private static final QNameModule BAR = QNameModule.create(
@@ -45,13 +46,17 @@ public class AugmentTest {
     private static final QName Q1 = QName.create(BAR, "ifEntry");
     private static final QName Q2 = QName.create(BAZ, "augment-holder");
 
-    @Test
-    public void testAugmentParsing() throws Exception {
-        final SchemaContext context = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment")
-            .toURI());
+    private static EffectiveModelContext AUGMENT_IN_AUGMENT;
+
+    @BeforeClass
+    public static void beforeClass() throws Exception {
+        AUGMENT_IN_AUGMENT = assertEffectiveModelDir("/augment-test/augment-in-augment");
+    }
 
+    @Test
+    public void testAugmentParsing() {
         // foo.yang
-        final Module module1 = context.findModules("foo").iterator().next();
+        final Module module1 = AUGMENT_IN_AUGMENT.findModules("foo").iterator().next();
         Collection<? extends AugmentationSchemaNode> augmentations = module1.getAugmentations();
         assertEquals(1, augmentations.size());
         final AugmentationSchemaNode augment = augmentations.iterator().next();
@@ -62,7 +67,7 @@ public class AugmentTest {
         final Collection<? extends DataSchemaNode> augmentChildren = augment.getChildNodes();
         assertEquals(4, augmentChildren.size());
         for (final DataSchemaNode dsn : augmentChildren) {
-            TestUtils.checkIsAugmenting(dsn, false);
+            checkIsAugmenting(dsn, false);
         }
 
         final LeafSchemaNode ds0ChannelNumber = (LeafSchemaNode) augment.getDataChildByName(QName.create(
@@ -98,7 +103,7 @@ public class AugmentTest {
         assertFalse(odl.isAugmenting());
 
         // baz.yang
-        final Module module3 = context.findModules("baz").iterator().next();
+        final Module module3 = AUGMENT_IN_AUGMENT.findModules("baz").iterator().next();
         augmentations = module3.getAugmentations();
         assertEquals(3, augmentations.size());
         AugmentationSchemaNode augment1 = null;
@@ -134,10 +139,8 @@ public class AugmentTest {
     }
 
     @Test
-    public void testAugmentResolving() throws Exception {
-        final SchemaContext context = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment")
-            .toURI());
-        final Module module2 = context.findModules("bar").iterator().next();
+    public void testAugmentResolving() {
+        final Module module2 = AUGMENT_IN_AUGMENT.findModules("bar").iterator().next();
         final ContainerSchemaNode interfaces = (ContainerSchemaNode) module2.getDataChildByName(QName.create(
                 module2.getQNameModule(), "interfaces"));
         final ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName(QName.create(
@@ -147,7 +150,7 @@ public class AugmentTest {
         // augment "/br:interfaces/br:ifEntry" {
         final ContainerSchemaNode augmentHolder = (ContainerSchemaNode) ifEntry.getDataChildByName(QName.create(BAZ,
                 "augment-holder"));
-        TestUtils.checkIsAugmenting(augmentHolder, true);
+        checkIsAugmenting(augmentHolder, true);
         assertEquals(Q2, augmentHolder.getQName());
 
         // foo.yang
@@ -179,17 +182,15 @@ public class AugmentTest {
     }
 
     @Test
-    public void testAugmentedChoice() throws Exception {
-        final SchemaContext context = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment")
-            .toURI());
-        final Module module2 = context.findModules("bar").iterator().next();
+    public void testAugmentedChoice() {
+        final Module module2 = AUGMENT_IN_AUGMENT.findModules("bar").iterator().next();
         final ContainerSchemaNode interfaces = (ContainerSchemaNode) module2.getDataChildByName(QName.create(
                 module2.getQNameModule(), "interfaces"));
         final ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName(QName.create(
                 module2.getQNameModule(), "ifEntry"));
         final ContainerSchemaNode augmentedHolder = (ContainerSchemaNode) ifEntry.getDataChildByName(QName.create(
                 BAZ, "augment-holder"));
-        TestUtils.checkIsAugmenting(augmentedHolder, true);
+        checkIsAugmenting(augmentedHolder, true);
 
         // foo.yang
         // augment "/br:interfaces/br:ifEntry/bz:augment-holder"
@@ -254,7 +255,7 @@ public class AugmentTest {
 
     @Test
     public void testAugmentRpc() throws Exception {
-        final SchemaContext context = TestUtils.loadModules(getClass().getResource("/augment-test/rpc").toURI());
+        final EffectiveModelContext context = assertEffectiveModelDir("/augment-test/rpc");
         final XMLNamespace NS_BAR = XMLNamespace.of("urn:opendaylight:bar");
         final XMLNamespace NS_FOO = XMLNamespace.of("urn:opendaylight:foo");
         final Revision revision = Revision.of("2013-10-11");
@@ -322,8 +323,7 @@ public class AugmentTest {
 
     @Test
     public void testAugmentInUsesResolving() throws Exception {
-        final SchemaContext context = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-uses")
-            .toURI());
+        final EffectiveModelContext context = assertEffectiveModelDir("/augment-test/augment-in-uses");
         assertEquals(1, context.getModules().size());
 
         final Module test = context.getModules().iterator().next();
@@ -341,4 +341,24 @@ public class AugmentTest {
         final LeafSchemaNode id = (LeafSchemaNode) node.getDataChildByName(QName.create(test.getQNameModule(), "id"));
         assertTrue(id.isAugmenting());
     }
+
+    /**
+     * Test if node has augmenting flag set to expected value. In case this is  DataNodeContainer/ChoiceNode, check its
+     * child nodes/case nodes too.
+     *
+     * @param node node to check
+     * @param expected expected value
+     */
+    private static void checkIsAugmenting(final DataSchemaNode node, final boolean expected) {
+        assertEquals(expected, node.isAugmenting());
+        if (node instanceof DataNodeContainer) {
+            for (DataSchemaNode child : ((DataNodeContainer) node).getChildNodes()) {
+                checkIsAugmenting(child, expected);
+            }
+        } else if (node instanceof ChoiceSchemaNode) {
+            for (CaseSchemaNode caseNode : ((ChoiceSchemaNode) node).getCases()) {
+                checkIsAugmenting(caseNode, expected);
+            }
+        }
+    }
 }