Add a unit test showing augmentation handling 72/77172/2
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 22 Oct 2018 11:40:03 +0000 (13:40 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 22 Oct 2018 11:41:04 +0000 (13:41 +0200)
There is a world of difference between augmentations added to
a node vs. instantiated nodes. This patch adds a test which shows
it.

JIRA: YANGTOOLS-911
Change-Id: Ida3ce1fab8db09470e09d101de740b9b7d27a687
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT911Test.java [new file with mode: 0644]
yang/yang-parser-rfc7950/src/test/resources/bugs/YT911/foo.yang [new file with mode: 0644]

diff --git a/yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT911Test.java b/yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT911Test.java
new file mode 100644 (file)
index 0000000..d475d51
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.stmt;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+
+public class YT911Test {
+    private static final QName FOO = QName.create("foo", "2018-10-22", "foo");
+    private static final QName BAR = QName.create(FOO, "bar");
+
+    @Test
+    public void testAugmentationConfig() throws Exception {
+        final SchemaContext context = StmtTestUtils.parseYangSource("/bugs/YT911/foo.yang");
+        final DataSchemaNode foo = context.findDataChildByName(FOO).get();
+        assertFalse(foo.isConfiguration());
+        assertTrue(foo instanceof ContainerSchemaNode);
+
+        // Instantiated node
+        final DataSchemaNode bar = ((ContainerSchemaNode) foo).findDataTreeChild(BAR).get();
+        assertFalse(bar.isConfiguration());
+        assertTrue(foo instanceof ContainerSchemaNode);
+
+        // Original augmentation node
+        final AugmentationSchemaNode aug = ((ContainerSchemaNode) foo).getAvailableAugmentations().iterator().next();
+        final DataSchemaNode augBar = aug.findDataTreeChild(BAR).get();
+        assertTrue(augBar.isConfiguration());
+        assertTrue(foo instanceof ContainerSchemaNode);
+    }
+}
diff --git a/yang/yang-parser-rfc7950/src/test/resources/bugs/YT911/foo.yang b/yang/yang-parser-rfc7950/src/test/resources/bugs/YT911/foo.yang
new file mode 100644 (file)
index 0000000..ee9224d
--- /dev/null
@@ -0,0 +1,14 @@
+module foo {
+    namespace foo;
+    prefix foo;
+
+    revision "2018-10-22";
+
+    container foo {
+        config false;
+    }
+
+    augment /foo {
+        container bar;
+    }
+}