Fix {Input,Output}EffectiveStatement definition 82/96382/4
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 27 May 2021 22:32:45 +0000 (00:32 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 28 May 2021 08:34:13 +0000 (10:34 +0200)
{Rpc,Action}EffectiveStatements are DataTreeAwareEffectiveStatements
which can contain input/output statements only. This implies
{Input,Output}EffectiveStatement is a DataTreeEffectiveStatement such
that it can be looked up.

JIRA: YANGTOOLS-1291
Change-Id: I6f469a790ae901e4b492af0558354d39b5b9068e
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
model/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/InputEffectiveStatement.java
model/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/OutputEffectiveStatement.java
model/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/YT1291Test.java [new file with mode: 0644]
model/yang-model-util/src/test/resources/yt1291.yang [new file with mode: 0644]

index 72a54559dc67a262daa28eb36321edaadde27998..27b3eb8921d105061fcf8f8e0283176eb3681dd3 100644 (file)
@@ -14,7 +14,7 @@ import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
 
 @Beta
 public interface InputEffectiveStatement
-        extends SchemaTreeEffectiveStatement<InputStatement>, DataTreeAwareEffectiveStatement<QName, InputStatement> {
+        extends DataTreeEffectiveStatement<InputStatement>, DataTreeAwareEffectiveStatement<QName, InputStatement> {
     @Override
     default StatementDefinition statementDefinition() {
         return YangStmtMapping.INPUT;
index f1ba00bb7a2d4557ec206d4a14fa3db9122ba0ca..b9826b8e6f0b1f69699d1497d07b6fe322a9dad6 100644 (file)
@@ -14,7 +14,7 @@ import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
 
 @Beta
 public interface OutputEffectiveStatement
-        extends SchemaTreeEffectiveStatement<OutputStatement>, DataTreeAwareEffectiveStatement<QName, OutputStatement> {
+        extends DataTreeEffectiveStatement<OutputStatement>, DataTreeAwareEffectiveStatement<QName, OutputStatement> {
     @Override
     default StatementDefinition statementDefinition() {
         return YangStmtMapping.OUTPUT;
diff --git a/model/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/YT1291Test.java b/model/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/YT1291Test.java
new file mode 100644 (file)
index 0000000..54f2afc
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * 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 com.google.common.collect.Iterables;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.model.api.stmt.InputEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.OutputEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.RpcEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
+
+public class YT1291Test {
+    private static final QName FOO = QName.create("foo", "foo");
+    private static final QName INPUT = QName.create("foo", "input");
+    private static final QName OUTPUT = QName.create("foo", "output");
+
+    private static EffectiveModelContext context;
+
+    @BeforeClass
+    public static void beforeClass() {
+        context = YangParserTestUtils.parseYangResource("/yt1291.yang");
+    }
+
+    @Test
+    public void testRpcIndexing() {
+        final SchemaTreeEffectiveStatement<?> foo = Iterables.getOnlyElement(context.getModuleStatements().values())
+            .findSchemaTreeNode(FOO).orElseThrow();
+        assertThat(foo, instanceOf(RpcEffectiveStatement.class));
+        final RpcEffectiveStatement rpc = (RpcEffectiveStatement) foo;
+
+        assertThat(rpc.findDataTreeNode(INPUT).orElseThrow(), instanceOf(InputEffectiveStatement.class));
+        assertThat(rpc.findDataTreeNode(OUTPUT).orElseThrow(), instanceOf(OutputEffectiveStatement.class));
+    }
+
+    @Test
+    public void testEnterDataTree() {
+        final SchemaInferenceStack stack = SchemaInferenceStack.of(context, Absolute.of(FOO));
+        assertThat(stack.enterDataTree(INPUT), instanceOf(InputEffectiveStatement.class));
+        stack.exit();
+        assertThat(stack.enterDataTree(OUTPUT), instanceOf(OutputEffectiveStatement.class));
+    }
+}
diff --git a/model/yang-model-util/src/test/resources/yt1291.yang b/model/yang-model-util/src/test/resources/yt1291.yang
new file mode 100644 (file)
index 0000000..669998c
--- /dev/null
@@ -0,0 +1,6 @@
+module foo {
+  namespace foo;
+  prefix foo;
+
+  rpc foo;
+}