Fix SchemaTreeNamespace population via augment 37/100137/3
authorSangwook Ha <sangwook.ha@verizon.com>
Wed, 16 Mar 2022 16:39:14 +0000 (09:39 -0700)
committerRobert Varga <robert.varga@pantheon.tech>
Sat, 19 Mar 2022 13:01:14 +0000 (14:01 +0100)
This change adds 4 test cases to reproduce:
  - Deviation of a case node with case statement
  - Deviation of a case node without case statement
  - Deviation of an augmented case node with case statement
  - Deviation of an augmented case node without case statement

The only test case fails is the last one (deviation of an augmented
case node without case statement). There is another way to depreduce
the root cause, which is to use 'augment' instead of deviate.

The problem is that the implicit case statement does not trigger
onStatementAdded() and hence it does not get registered in the
namespace.

Fixing this issue changes behaviour in testDuplicityInAugmentTarget2(),
i.e. the schema tree overlap previously reported through
SchemaTreeIndexingException (when we are already building effective
view) gets flagged earlier with a SourceException, pointing to both the
place where the conflict occurs and which source statement is causing
it.

JIRA: YANGTOOLS-1408
Change-Id: I7c26399b07aaa142b5ab8191dab97e738118a14a
Signed-off-by: Sangwook Ha <sangwook.ha@verizon.com>
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1408Test.java [new file with mode: 0644]
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserNegativeTest.java
parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/aug-choice-case-deviate-case/deviate.yang [new file with mode: 0644]
parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/aug-choice-case-deviate-case/orig.yang [new file with mode: 0644]
parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/aug-choice-deviate-case/deviate.yang [new file with mode: 0644]
parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/aug-choice-deviate-case/orig.yang [new file with mode: 0644]
parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/choice-case-deviate-case/deviate.yang [new file with mode: 0644]
parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/choice-case-deviate-case/orig.yang [new file with mode: 0644]
parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/choice-deviate-case/deviate.yang [new file with mode: 0644]
parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/choice-deviate-case/orig.yang [new file with mode: 0644]

index eb072d9a319ee5e91798de5aedc4117263287b80..1be883cd2b2213fea83f50024247b09c67e87a7c 100644 (file)
@@ -827,6 +827,7 @@ abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E extends
 
             copy = new InferredStatementContext<>(result, original, childCopyType, type, targetModule);
             result.addEffectiveSubstatement(copy);
+            result.definition.onStatementAdded(result);
         } else {
             result = copy = new InferredStatementContext<>(this, original, type, type, targetModule);
         }
diff --git a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1408Test.java b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1408Test.java
new file mode 100644 (file)
index 0000000..bcfcb1c
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2022 Verizon 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 org.junit.Test;
+
+public class YT1408Test extends AbstractYangTest {
+    @Test
+    public void testChoiceCaseDeviateCase() throws AssertionError {
+        assertEffectiveModelDir("/bugs/YT1408/choice-case-deviate-case");
+    }
+
+    @Test
+    public void testChoiceDeviateCase() throws AssertionError {
+        assertEffectiveModelDir("/bugs/YT1408/choice-deviate-case");
+    }
+
+    @Test
+    public void testAugmentChoiceCaseDeviateCase() throws AssertionError {
+        assertEffectiveModelDir("/bugs/YT1408/aug-choice-case-deviate-case");
+    }
+
+    @Test
+    public void testAugmentChoiceDeviateCase() throws AssertionError {
+        assertEffectiveModelDir("/bugs/YT1408/aug-choice-deviate-case");
+    }
+}
index c2c4ab3f38323aa77f231281b5a4b0ff730f2783..ccd60e396c2db47ced76d0f60bc0b3ff56fdbff3 100644 (file)
@@ -7,7 +7,9 @@
  */
 package org.opendaylight.yangtools.yang.stmt;
 
+import static org.hamcrest.CoreMatchers.allOf;
 import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.endsWith;
 import static org.hamcrest.CoreMatchers.startsWith;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.isA;
@@ -15,7 +17,6 @@ import static org.junit.Assert.assertThrows;
 
 import com.google.common.base.Throwables;
 import org.junit.Test;
-import org.opendaylight.yangtools.yang.model.spi.meta.SubstatementIndexingException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
@@ -142,9 +143,12 @@ public class YangParserNegativeTest {
             () -> TestUtils.parseYangSource(
                 "/negative-scenario/duplicity/augment0.yang", "/negative-scenario/duplicity/augment2.yang"));
         final Throwable rootCause = Throwables.getRootCause(ex);
-        assertThat(rootCause, isA(SubstatementIndexingException.class));
-        assertThat(rootCause.getMessage(), containsString("Cannot add schema tree child with name "
-            + "(urn:simple.augment2.demo?revision=2014-06-02)delta, a conflicting child already exists"));
+        assertThat(rootCause, isA(SourceException.class));
+        assertThat(rootCause.getMessage(), allOf(
+            startsWith("Error in module 'augment0': cannot add "
+                + "'(urn:simple.augment2.demo?revision=2014-06-02)delta'. Node name collision: "
+                + "'(urn:simple.augment2.demo?revision=2014-06-02)delta' already declared at "),
+            endsWith("duplicity/augment2.yang:17:9]")));
     }
 
     @Test
diff --git a/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/aug-choice-case-deviate-case/deviate.yang b/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/aug-choice-case-deviate-case/deviate.yang
new file mode 100644 (file)
index 0000000..a8fd026
--- /dev/null
@@ -0,0 +1,12 @@
+module deviate {
+    namespace "urn:deviate";
+    prefix dev;
+
+    import orig {
+        prefix orig;
+    }
+
+    deviation /orig:foo/orig:bar/orig:bar2 {
+        deviate not-supported;
+    }
+}
diff --git a/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/aug-choice-case-deviate-case/orig.yang b/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/aug-choice-case-deviate-case/orig.yang
new file mode 100644 (file)
index 0000000..77c2a90
--- /dev/null
@@ -0,0 +1,22 @@
+module orig {
+    namespace "urn:orig";
+    prefix orig;
+
+    container foo {
+        choice bar {
+            case bar1 {
+                leaf bar1 {
+                    type string;
+                }
+            }
+        }
+    }
+
+    augment /foo/bar {
+        case bar2 {
+            leaf bar2 {
+                type string;
+            }
+        }
+    }
+}
diff --git a/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/aug-choice-deviate-case/deviate.yang b/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/aug-choice-deviate-case/deviate.yang
new file mode 100644 (file)
index 0000000..a8fd026
--- /dev/null
@@ -0,0 +1,12 @@
+module deviate {
+    namespace "urn:deviate";
+    prefix dev;
+
+    import orig {
+        prefix orig;
+    }
+
+    deviation /orig:foo/orig:bar/orig:bar2 {
+        deviate not-supported;
+    }
+}
diff --git a/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/aug-choice-deviate-case/orig.yang b/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/aug-choice-deviate-case/orig.yang
new file mode 100644 (file)
index 0000000..b0596cb
--- /dev/null
@@ -0,0 +1,18 @@
+module orig {
+    namespace "urn:orig";
+    prefix orig;
+
+    container foo {
+        choice bar {
+            leaf bar1 {
+                type string;
+            }
+        }
+    }
+
+    augment /foo/bar {
+        leaf bar2 {
+            type string;
+        }
+    }
+}
diff --git a/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/choice-case-deviate-case/deviate.yang b/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/choice-case-deviate-case/deviate.yang
new file mode 100644 (file)
index 0000000..a8fd026
--- /dev/null
@@ -0,0 +1,12 @@
+module deviate {
+    namespace "urn:deviate";
+    prefix dev;
+
+    import orig {
+        prefix orig;
+    }
+
+    deviation /orig:foo/orig:bar/orig:bar2 {
+        deviate not-supported;
+    }
+}
diff --git a/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/choice-case-deviate-case/orig.yang b/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/choice-case-deviate-case/orig.yang
new file mode 100644 (file)
index 0000000..1c3b873
--- /dev/null
@@ -0,0 +1,19 @@
+module orig {
+    namespace "urn:orig";
+    prefix orig;
+
+    container foo {
+        choice bar {
+            case bar1 {
+                leaf bar1 {
+                    type string;
+                }
+            }
+            case bar2 {
+                leaf bar2 {
+                    type string;
+                }
+            }
+        }
+    }
+}
diff --git a/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/choice-deviate-case/deviate.yang b/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/choice-deviate-case/deviate.yang
new file mode 100644 (file)
index 0000000..a8fd026
--- /dev/null
@@ -0,0 +1,12 @@
+module deviate {
+    namespace "urn:deviate";
+    prefix dev;
+
+    import orig {
+        prefix orig;
+    }
+
+    deviation /orig:foo/orig:bar/orig:bar2 {
+        deviate not-supported;
+    }
+}
diff --git a/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/choice-deviate-case/orig.yang b/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/choice-deviate-case/orig.yang
new file mode 100644 (file)
index 0000000..cd7fccf
--- /dev/null
@@ -0,0 +1,15 @@
+module orig {
+    namespace "urn:orig";
+    prefix orig;
+
+    container foo {
+        choice bar {
+            leaf bar1 {
+                type string;
+            }
+            leaf bar2 {
+                type string;
+            }
+        }
+    }
+}