Case statement has instantiated schema tree policy 47/94847/2
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 27 Jan 2021 17:51:16 +0000 (18:51 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 27 Jan 2021 18:26:24 +0000 (19:26 +0100)
Case statement does not do anything special convert it and add
a reuse test case.

JIRA: YANGTOOLS-1208
Change-Id: I9b4ec0311c14a091896678b39a3f21e260064d97
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/case_/CaseStatementSupport.java
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1208Test.java
yang/yang-parser-rfc7950/src/test/resources/bugs/YT1208/case.yang [new file with mode: 0644]

index 544a7c6cea99f624929b497a10b270c43537cb0d..3903e503eaa2e0f4221cec05e7a658ef5ffbe75c 100644 (file)
@@ -73,7 +73,7 @@ public final class CaseStatementSupport
     private final SubstatementValidator validator;
 
     private CaseStatementSupport(final SubstatementValidator validator) {
-        super(YangStmtMapping.CASE, StatementPolicy.legacyDeclaredCopy());
+        super(YangStmtMapping.CASE, instantiatedPolicy());
         this.validator = requireNonNull(validator);
     }
 
index 2792dde483775f254c999de7eacff7054aa7471e..aa57e7801dd7d2849d403ca0fe4ae7678fa5a8e6 100644 (file)
@@ -13,6 +13,8 @@ import static org.junit.Assert.assertSame;
 import java.net.URI;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.model.api.stmt.CaseEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ChoiceEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement;
@@ -20,6 +22,28 @@ import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement;
 
 public class YT1208Test {
+    @Test
+    public void testCaseStatementReuse() throws Exception {
+        final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1208/case.yang")
+            .getModuleStatements()
+            .get(QNameModule.create(URI.create("foo")));
+        assertNotNull(module);
+
+        final NotificationEffectiveStatement notif = module
+            .findFirstEffectiveSubstatement(NotificationEffectiveStatement.class).orElseThrow();
+
+        final CaseEffectiveStatement grpBar = notif
+            .findFirstEffectiveSubstatement(GroupingEffectiveStatement.class).orElseThrow()
+            .findFirstEffectiveSubstatement(ChoiceEffectiveStatement.class).orElseThrow()
+            .findFirstEffectiveSubstatement(CaseEffectiveStatement.class).orElseThrow();
+        final CaseEffectiveStatement contBar = notif
+            .findFirstEffectiveSubstatement(ContainerEffectiveStatement.class).orElseThrow()
+            .findFirstEffectiveSubstatement(ChoiceEffectiveStatement.class).orElseThrow()
+            .findFirstEffectiveSubstatement(CaseEffectiveStatement.class).orElseThrow();
+
+        assertSame(contBar, grpBar);
+    }
+
     @Test
     public void testGroupingStatementReuse() throws Exception {
         final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1208/grouping.yang")
diff --git a/yang/yang-parser-rfc7950/src/test/resources/bugs/YT1208/case.yang b/yang/yang-parser-rfc7950/src/test/resources/bugs/YT1208/case.yang
new file mode 100644 (file)
index 0000000..ce5eade
--- /dev/null
@@ -0,0 +1,22 @@
+module foo {
+  namespace foo;
+  prefix foo;
+
+  grouping grp {
+    choice bar {
+      case bar {
+        description "desc";
+      }
+    }
+  }
+
+  notification foo {
+    grouping foo {
+      uses grp;
+    }
+
+    container foo {
+      uses foo;
+    }
+  }
+}