Fix DataTree indexing 83/96383/2
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 27 May 2021 22:34:47 +0000 (00:34 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 28 May 2021 08:16:30 +0000 (10:16 +0200)
Our indexing is broken here, as if we have a schema tree statement
which is not propagated to data tree, we should be indicating a
difference in maps. Fix that up.

JIRA: YANGTOOLS-1292
Change-Id: I19d80a11ef7114b0908766fa19df51604ca83f2e
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
model/yang-model-spi/src/main/java/org/opendaylight/yangtools/yang/model/spi/meta/AbstractEffectiveStatement.java
model/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/YT1292Test.java [new file with mode: 0644]
model/yang-model-util/src/test/resources/yt1292.yang [new file with mode: 0644]

index ffe226f74e129b1c2a7a225fb1fd240dfe714790..d46dbebbe7fbe42558cffddc00e2b3841f8a549f 100644 (file)
@@ -123,16 +123,13 @@ abstract class AbstractEffectiveStatement<A, D extends DeclaredStatement<A>>
                     }
                 }
             }
-            return false;
         } else if (stmt instanceof CaseEffectiveStatement) {
             // For case statements go through all their statements
             for (EffectiveStatement<?, ?> child : stmt.effectiveSubstatements()) {
                 indexDataTree(map, child);
             }
-            return false;
-        } else {
-            return true;
         }
+        return false;
     }
 
     private static <T extends SchemaTreeEffectiveStatement<?>> void putChild(final Map<QName, T> map, final T child,
diff --git a/model/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/YT1292Test.java b/model/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/YT1292Test.java
new file mode 100644 (file)
index 0000000..46d7e34
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2021 PANTHEON.tech, 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.model.util;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertEquals;
+
+import com.google.common.collect.Iterables;
+import java.util.Optional;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.stmt.ActionEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.DataTreeEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.RpcEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
+
+public class YT1292Test {
+    private static final QName FOO = QName.create("foo", "foo");
+    private static final QName BAR = QName.create("foo", "bar");
+    private static final QName BAZ = QName.create("foo", "baz");
+
+    private static ModuleEffectiveStatement module;
+
+    private ContainerEffectiveStatement baz;
+
+    @BeforeClass
+    public static void beforeClass() {
+        module = Iterables.getOnlyElement(YangParserTestUtils.parseYangResource("/yt1292.yang").getModuleStatements()
+            .values());
+    }
+
+    @Before
+    public void before() {
+        final DataTreeEffectiveStatement<?> tmp = module.findDataTreeNode(BAZ).orElseThrow();
+        assertThat(tmp, instanceOf(ContainerEffectiveStatement.class));
+        baz = (ContainerEffectiveStatement) tmp;
+    }
+
+    @Test
+    public void testRpc() {
+        assertEquals(Optional.empty(), module.findDataTreeNode(FOO));
+        final SchemaTreeEffectiveStatement<?> foo = module.findSchemaTreeNode(FOO).orElseThrow();
+        assertThat(foo, instanceOf(RpcEffectiveStatement.class));
+    }
+
+    @Test
+    public void testNotification() {
+        assertEquals(Optional.empty(), module.findDataTreeNode(BAR));
+        SchemaTreeEffectiveStatement<?> bar = module.findSchemaTreeNode(BAR).orElseThrow();
+        assertThat(bar, instanceOf(NotificationEffectiveStatement.class));
+
+        assertEquals(Optional.empty(), baz.findDataTreeNode(BAR));
+        bar = baz.findSchemaTreeNode(BAR).orElseThrow();
+        assertThat(bar, instanceOf(NotificationEffectiveStatement.class));
+    }
+
+    @Test
+    public void testAction() {
+        assertEquals(Optional.empty(), baz.findDataTreeNode(FOO));
+        final SchemaTreeEffectiveStatement<?> foo = baz.findSchemaTreeNode(FOO).orElseThrow();
+        assertThat(foo, instanceOf(ActionEffectiveStatement.class));
+    }
+}
diff --git a/model/yang-model-util/src/test/resources/yt1292.yang b/model/yang-model-util/src/test/resources/yt1292.yang
new file mode 100644 (file)
index 0000000..16a6e56
--- /dev/null
@@ -0,0 +1,15 @@
+module foo {
+  namespace foo;
+  prefix foo;
+  yang-version 1.1;
+
+  rpc foo;
+
+  notification bar;
+
+  container baz {
+    action foo;
+
+    notification bar;
+  }
+}