Do not catch instantiation exceptions during augment 28/94628/5
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 14 Jan 2021 08:39:33 +0000 (09:39 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 14 Jan 2021 11:29:48 +0000 (12:29 +0100)
The try/catch block here is overly broad and ill-defined, as it
suppresses failures produced by onStatementAdded().

A number of test cases actually worked around this by checking
either effects of the omission or that the presence of a message
being logged. These are corrected to assert the equivalent failure.

This necessitates splitting Bug8126Test into legal and illegal parts.

JIRA: YANGTOOLS-1186
Change-Id: Icd7c15ed82df38ccbdbd64e635c5a479e5a180aa
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
14 files changed:
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/augment/AugmentInferenceAction.java
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6876Test.java
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5335Test.java
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug6669Test.java
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug8126Test.java
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserNegativeTest.java
yang/yang-parser-rfc7950/src/test/resources/bugs/bug8126/inv-choice/foo.yang [moved from yang/yang-parser-rfc7950/src/test/resources/bugs/bug8126/foo.yang with 100% similarity]
yang/yang-parser-rfc7950/src/test/resources/bugs/bug8126/inv-choice/ill1.yang [new file with mode: 0644]
yang/yang-parser-rfc7950/src/test/resources/bugs/bug8126/inv-cont/foo.yang [new file with mode: 0644]
yang/yang-parser-rfc7950/src/test/resources/bugs/bug8126/inv-cont/ill3.yang [new file with mode: 0644]
yang/yang-parser-rfc7950/src/test/resources/bugs/bug8126/inv-list/foo.yang [new file with mode: 0644]
yang/yang-parser-rfc7950/src/test/resources/bugs/bug8126/inv-list/ill2.yang [new file with mode: 0644]
yang/yang-parser-rfc7950/src/test/resources/bugs/bug8126/valid/bar.yang [moved from yang/yang-parser-rfc7950/src/test/resources/bugs/bug8126/bar.yang with 54% similarity]
yang/yang-parser-rfc7950/src/test/resources/bugs/bug8126/valid/foo.yang [new file with mode: 0644]

index f00172ffbc0b550aca1114024307426e8c9a92ef..028a216688601cb32f87206614d95da85ada5339 100644 (file)
@@ -34,7 +34,6 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.Prereq
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace.ValidationBundleType;
 import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
@@ -76,15 +75,8 @@ final class AugmentInferenceAction implements InferenceAction {
             augmentNode.addToNs(AugmentImplicitHandlingNamespace.class, Empty.getInstance(), augmentTargetCtx);
         }
 
-        // FIXME: this is a workaround for models which augment a node which is added via an extension
-        //        which we do not handle. This needs to be reworked in terms of unknown schema nodes.
-        try {
-            copyFromSourceToTarget((StatementContextBase<?, ?, ?>) augmentNode, augmentTargetCtx);
-            augmentTargetCtx.addEffectiveSubstatement(augmentNode.replicaAsChildOf(augmentTargetCtx));
-        } catch (final SourceException e) {
-            LOG.warn("Failed to add augmentation {} defined at {}", augmentTargetCtx.sourceReference(),
-                augmentNode.sourceReference(), e);
-        }
+        copyFromSourceToTarget((StatementContextBase<?, ?, ?>) augmentNode, augmentTargetCtx);
+        augmentTargetCtx.addEffectiveSubstatement(augmentNode.replicaAsChildOf(augmentTargetCtx));
     }
 
     @Override
index b74618d875d52ec2d11e7917a9e3c34ab047d7e3..4b059177edeb6da61d47a25f5fa66354052258c3 100644 (file)
@@ -7,9 +7,11 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc7950;
 
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.startsWith;
+import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertThrows;
 
 import com.google.common.collect.ImmutableList;
 import org.junit.Test;
@@ -19,6 +21,8 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
+import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
 
 public class Bug6876Test {
@@ -31,20 +35,20 @@ public class Bug6876Test {
         final SchemaContext context = StmtTestUtils.parseYangSources("/rfc7950/bug6876/yang11");
         assertNotNull(context);
 
-        assertTrue(findNode(context, ImmutableList.of(bar("augment-target"),
-            bar("my-leaf"))) instanceof LeafSchemaNode);
-        assertTrue(findNode(context, ImmutableList.of(bar("augment-target"),
-            foo("mandatory-leaf"))) instanceof LeafSchemaNode);
+        assertThat(findNode(context, ImmutableList.of(bar("augment-target"), bar("my-leaf"))),
+            instanceOf(LeafSchemaNode.class));
+        assertThat(findNode(context, ImmutableList.of(bar("augment-target"), foo("mandatory-leaf"))),
+            instanceOf(LeafSchemaNode.class));
     }
 
     @Test
-    public void yang10Test() throws Exception {
-        final SchemaContext context = StmtTestUtils.parseYangSources("/rfc7950/bug6876/yang10");
-        assertNotNull(context);
-
-        assertTrue(findNode(context, ImmutableList.of(bar("augment-target"),
-            bar("my-leaf"))) instanceof LeafSchemaNode);
-        assertNull(findNode(context, ImmutableList.of(bar("augment-target"), foo("mandatory-leaf"))));
+    public void yang10Test() {
+        final ReactorException ex = assertThrows(ReactorException.class,
+            () -> StmtTestUtils.parseYangSources("/rfc7950/bug6876/yang10"));
+        final Throwable cause = ex.getCause();
+        assertThat(cause, instanceOf(InferenceException.class));
+        assertThat(cause.getMessage(), startsWith(
+            "An augment cannot add node 'mandatory-leaf' because it is mandatory and in module different than target"));
     }
 
     private static SchemaNode findNode(final SchemaContext context, final Iterable<QName> qnames) {
index ac9912c4cc537af7e813f9f70fe5d2edd3f08563..a580748dcfe3a907b5f3ea5a3387ee04baa44c30 100644 (file)
@@ -7,16 +7,13 @@
  */
 package org.opendaylight.yangtools.yang.stmt;
 
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.startsWith;
+import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 
-import java.io.ByteArrayOutputStream;
-import java.io.PrintStream;
-import java.io.UnsupportedEncodingException;
-import java.nio.charset.StandardCharsets;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
@@ -24,6 +21,8 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
+import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 
 public class Bug5335Test {
     private static final String FOO = "foo";
@@ -31,66 +30,39 @@ public class Bug5335Test {
     private static final String REV = "2016-03-04";
 
     private static final QName ROOT = QName.create(FOO, REV, "root");
-    private static final QName PRESENCE_CONTAINER_F = QName.create(FOO, REV, "presence-container");
     private static final QName NON_PRESENCE_CONTAINER_F = QName.create(FOO, REV, "non-presence-container");
     private static final QName MANDATORY_LEAF_F = QName.create(FOO, REV, "mandatory-leaf");
     private static final QName PRESENCE_CONTAINER_B = QName.create(BAR, REV, "presence-container");
     private static final QName NON_PRESENCE_CONTAINER_B = QName.create(BAR, REV, "non-presence-container");
     private static final QName MANDATORY_LEAF_B = QName.create(BAR, REV, "mandatory-leaf");
 
-    private final ByteArrayOutputStream output = new ByteArrayOutputStream();
-
-    @Before
-    public void setUp() throws UnsupportedEncodingException {
-        System.setOut(new PrintStream(output, true, StandardCharsets.UTF_8));
-    }
-
-    @After
-    @SuppressWarnings("checkstyle:regexpSinglelineJava")
-    public void cleanUp() {
-        System.setOut(System.out);
-    }
-
     @Test
-    public void incorrectTest1() throws Exception {
-        final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug5335/incorrect/case-1");
-        assertNotNull(context);
-
-        final SchemaPath schemaPath = SchemaPath.create(true, ROOT, NON_PRESENCE_CONTAINER_B, MANDATORY_LEAF_B);
-        final SchemaNode mandatoryLeaf = SchemaContextUtil.findDataSchemaNode(context, schemaPath);
-        assertNull(mandatoryLeaf);
-
-        final String testLog = output.toString();
-        assertTrue(testLog.contains(
+    public void incorrectTest1() {
+        final ReactorException ex = assertThrows(ReactorException.class,
+            () -> StmtTestUtils.parseYangSources("/bugs/bug5335/incorrect/case-1"));
+        final Throwable cause = ex.getCause();
+        assertThat(cause, instanceOf(InferenceException.class));
+        assertThat(cause.getMessage(), startsWith(
             "An augment cannot add node 'mandatory-leaf' because it is mandatory and in module different than target"));
     }
 
     @Test
-    public void incorrectTest2() throws Exception {
-        final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug5335/incorrect/case-2");
-        assertNotNull(context);
-
-        final SchemaPath schemaPath = SchemaPath.create(true, ROOT, PRESENCE_CONTAINER_F, MANDATORY_LEAF_B);
-        final SchemaNode mandatoryLeaf = SchemaContextUtil.findDataSchemaNode(context, schemaPath);
-        assertNull(mandatoryLeaf);
-
-        final String testLog = output.toString();
-        assertTrue(testLog.contains(
+    public void incorrectTest2() {
+        final ReactorException ex = assertThrows(ReactorException.class,
+            () -> StmtTestUtils.parseYangSources("/bugs/bug5335/incorrect/case-2"));
+        final Throwable cause = ex.getCause();
+        assertThat(cause, instanceOf(InferenceException.class));
+        assertThat(cause.getMessage(), startsWith(
             "An augment cannot add node 'mandatory-leaf' because it is mandatory and in module different than target"));
     }
 
     @Test
     public void incorrectTest3() throws Exception {
-        final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug5335/incorrect/case-2");
-        assertNotNull(context);
-
-        final SchemaPath schemaPath = SchemaPath.create(true, ROOT, PRESENCE_CONTAINER_F, NON_PRESENCE_CONTAINER_B,
-                MANDATORY_LEAF_B);
-        final SchemaNode mandatoryLeaf = SchemaContextUtil.findDataSchemaNode(context, schemaPath);
-        assertNull(mandatoryLeaf);
-
-        final String testLog = output.toString();
-        assertTrue(testLog.contains(
+        final ReactorException ex = assertThrows(ReactorException.class,
+            () -> StmtTestUtils.parseYangSources("/bugs/bug5335/incorrect/case-2"));
+        final Throwable cause = ex.getCause();
+        assertThat(cause, instanceOf(InferenceException.class));
+        assertThat(cause.getMessage(), startsWith(
             "An augment cannot add node 'mandatory-leaf' because it is mandatory and in module different than target"));
     }
 
index 2e520c20db91ef51882a06e73a7a318748fd0b08..20bdd12f10a514420105ff99699c984443594fcb 100644 (file)
@@ -7,8 +7,11 @@
  */
 package org.opendaylight.yangtools.yang.stmt;
 
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.startsWith;
+import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 
 import org.junit.Test;
@@ -19,6 +22,8 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
+import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 
 public class Bug6669Test {
     private static final String REV = "2016-09-08";
@@ -29,36 +34,35 @@ public class Bug6669Test {
     private static final QName BAR_1 = QName.create(BAR_NS, REV, "bar1");
     private static final QName BAR_2 = QName.create(BAR_NS, REV, "bar2");
     private static final QName M = QName.create(BAR_NS, REV, "m");
-    private static final QName L = QName.create(BAR_NS, REV, "l");
 
     @Test
-    public void testInvalidAugment() throws Exception {
-        final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6669/invalid/test1");
-        assertNotNull(context);
-
-        final SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context,
-                SchemaPath.create(true, ROOT, BAR, BAR_1, M));
-        assertNull(findDataSchemaNode);
+    public void testInvalidAugment() {
+        final ReactorException ex = assertThrows(ReactorException.class,
+            () -> StmtTestUtils.parseYangSources("/bugs/bug6669/invalid/test1"));
+        final Throwable cause = ex.getCause();
+        assertThat(cause, instanceOf(InferenceException.class));
+        assertThat(cause.getMessage(), startsWith(
+            "An augment cannot add node 'm' because it is mandatory and in module different than target"));
     }
 
     @Test
-    public void testInvalidAugment2() throws Exception {
-        final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6669/invalid/test2");
-        assertNotNull(context);
-
-        final SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context,
-                SchemaPath.create(true, ROOT, BAR, BAR_1, BAR_2, M));
-        assertNull(findDataSchemaNode);
+    public void testInvalidAugment2() {
+        final ReactorException ex = assertThrows(ReactorException.class,
+            () -> StmtTestUtils.parseYangSources("/bugs/bug6669/invalid/test2"));
+        final Throwable cause = ex.getCause();
+        assertThat(cause, instanceOf(InferenceException.class));
+        assertThat(cause.getMessage(), startsWith(
+            "An augment cannot add node 'm' because it is mandatory and in module different than target"));
     }
 
     @Test
-    public void testInvalidAugment3() throws Exception {
-        final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6669/invalid/test3");
-        assertNotNull(context);
-
-        final SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context,
-                SchemaPath.create(true, ROOT, BAR, BAR_1, BAR_2, L));
-        assertNull(findDataSchemaNode);
+    public void testInvalidAugment3() {
+        final ReactorException ex = assertThrows(ReactorException.class,
+            () ->  StmtTestUtils.parseYangSources("/bugs/bug6669/invalid/test3"));
+        final Throwable cause = ex.getCause();
+        assertThat(cause, instanceOf(InferenceException.class));
+        assertThat(cause.getMessage(), startsWith(
+            "An augment cannot add node 'l' because it is mandatory and in module different than target"));
     }
 
     @Test
@@ -87,7 +91,7 @@ public class Bug6669Test {
         assertNotNull(context);
 
         final SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context,
-                SchemaPath.create(true, ROOT, BAR, BAR_1, BAR_2, L));
+                SchemaPath.create(true, ROOT, BAR, BAR_1, BAR_2, QName.create(BAR_NS, REV, "l")));
         assertTrue(findDataSchemaNode instanceof ListSchemaNode);
     }
 }
index f245320b74aee8d7ac0e0cda6ca46d67fcbd27a5..f513ed4ceb4677f66b564b6fc6862758739927f6 100644 (file)
@@ -7,9 +7,11 @@
  */
 package org.opendaylight.yangtools.yang.stmt;
 
-import static org.junit.Assert.assertNotNull;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.startsWith;
+import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertThrows;
 
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -18,25 +20,57 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
+import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 
 public class Bug8126Test {
     private static final String FOO_NS = "foo";
     private static final String BAR_NS = "bar";
 
     @Test
-    public void test() throws Exception {
-        final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug8126");
-        assertNotNull(context);
-        assertTrue(findNode(context, foo("root"), bar("my-container"), bar("my-choice"), bar("one"), bar("one"),
-            bar("mandatory-leaf")) instanceof LeafSchemaNode);
-        assertTrue(findNode(context, foo("root"), bar("my-list"), bar("two"), bar("mandatory-leaf-2"))
-            instanceof LeafSchemaNode);
+    public void testValidAugments() throws Exception {
+        final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug8126/valid");
+        assertThat(findNode(context, foo("root"), bar("my-container"), bar("my-choice"), bar("one"), bar("one"),
+            bar("mandatory-leaf")), instanceOf(LeafSchemaNode.class));
+        assertThat(findNode(context, foo("root"), bar("my-list"), bar("two"), bar("mandatory-leaf-2")),
+            instanceOf(LeafSchemaNode.class));
 
         assertNull(findNode(context, foo("root"), bar("mandatory-list")));
         assertNull(findNode(context, foo("root"), bar("mandatory-container"), bar("mandatory-choice")));
         assertNull(findNode(context, foo("root"), bar("mandatory-container-2"), bar("one"), bar("mandatory-leaf-3")));
     }
 
+    @Test
+    public void testAugmentMandatoryChoice() {
+        final ReactorException ex = assertThrows(ReactorException.class,
+            () -> StmtTestUtils.parseYangSources("/bugs/bug8126/inv-choice"));
+        final Throwable cause = ex.getCause();
+        assertThat(cause, instanceOf(InferenceException.class));
+        assertThat(cause.getMessage(), startsWith(
+            "An augment cannot add node 'mandatory-choice' because it is mandatory and in module different than "));
+    }
+
+    @Test
+    public void testAugmentMandatoryList() {
+        final ReactorException ex = assertThrows(ReactorException.class,
+            () -> StmtTestUtils.parseYangSources("/bugs/bug8126/inv-list"));
+        final Throwable cause = ex.getCause();
+        assertThat(cause, instanceOf(InferenceException.class));
+        assertThat(cause.getMessage(), startsWith(
+            "An augment cannot add node 'mandatory-list' because it is mandatory and in module different than "));
+    }
+
+    @Test
+    public void testAugmentMandatoryContainer() {
+        final ReactorException ex = assertThrows(ReactorException.class,
+            () -> StmtTestUtils.parseYangSources("/bugs/bug8126/inv-cont"));
+        final Throwable cause = ex.getCause();
+        assertThat(cause, instanceOf(InferenceException.class));
+        assertThat(cause.getMessage(), startsWith(
+            "An augment cannot add node 'mandatory-leaf-3' because it is mandatory and in module different than "));
+    }
+
+
     private static SchemaNode findNode(final SchemaContext context, final QName... qnames) {
         return SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(true, qnames));
     }
index 4808fdf6aa34af3794103a73c6a7250fbe14ab6e..e83bef0bc59b531eacf59009eac8f7278ac5c47e 100644 (file)
@@ -14,37 +14,13 @@ import static org.hamcrest.Matchers.isA;
 import static org.junit.Assert.assertThrows;
 
 import com.google.common.base.Throwables;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.PrintStream;
-import java.nio.charset.StandardCharsets;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.Test;
-import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.SubstatementIndexingException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 
 public class YangParserNegativeTest {
-
-    @SuppressWarnings("checkstyle:regexpSinglelineJava")
-    private final PrintStream stdout = System.out;
-    private final ByteArrayOutputStream output = new ByteArrayOutputStream();
-    private String testLog;
-
-    @Before
-    public void setUp() {
-        System.setOut(new PrintStream(output, true, StandardCharsets.UTF_8));
-    }
-
-    @After
-    public void cleanUp() {
-        System.setOut(stdout);
-    }
-
     @Test
     public void testInvalidImport() {
         final SomeModifiersUnresolvedException ex = assertThrows(SomeModifiersUnresolvedException.class,
@@ -150,11 +126,13 @@ public class YangParserNegativeTest {
     }
 
     @Test
-    public void testDuplicityInAugmentTarget1() throws IOException, ReactorException, YangSyntaxErrorException {
-        TestUtils.loadModuleResources(getClass(),
-            "/negative-scenario/duplicity/augment0.yang", "/negative-scenario/duplicity/augment1.yang");
-        testLog = output.toString();
-        assertThat(testLog, containsString(
+    public void testDuplicityInAugmentTarget1() {
+        final SomeModifiersUnresolvedException ex = assertThrows(SomeModifiersUnresolvedException.class,
+            () -> TestUtils.loadModuleResources(getClass(),
+                "/negative-scenario/duplicity/augment0.yang", "/negative-scenario/duplicity/augment1.yang"));
+        final Throwable cause = ex.getCause();
+        assertThat(cause, isA(InferenceException.class));
+        assertThat(cause.getMessage(), startsWith(
             "An augment cannot add node named 'id' because this name is already used in target"));
     }
 
@@ -170,12 +148,13 @@ public class YangParserNegativeTest {
     }
 
     @Test
-    public void testMandatoryInAugment() throws IOException, ReactorException, YangSyntaxErrorException {
-        TestUtils.loadModuleResources(getClass(),
-            "/negative-scenario/testfile8.yang",
-                "/negative-scenario/testfile7.yang");
-        testLog = output.toString();
-        assertThat(testLog, containsString(
+    public void testMandatoryInAugment() {
+        final SomeModifiersUnresolvedException ex = assertThrows(SomeModifiersUnresolvedException.class,
+            () -> TestUtils.loadModuleResources(getClass(),
+                "/negative-scenario/testfile8.yang", "/negative-scenario/testfile7.yang"));
+        final Throwable cause = ex.getCause();
+        assertThat(cause, isA(InferenceException.class));
+        assertThat(cause.getMessage(), startsWith(
             "An augment cannot add node 'linkleaf' because it is mandatory and in module different than target"));
     }
 
diff --git a/yang/yang-parser-rfc7950/src/test/resources/bugs/bug8126/inv-choice/ill1.yang b/yang/yang-parser-rfc7950/src/test/resources/bugs/bug8126/inv-choice/ill1.yang
new file mode 100644 (file)
index 0000000..df2198f
--- /dev/null
@@ -0,0 +1,16 @@
+module ill1 {
+    namespace ill1;
+    prefix ill1;
+
+    import foo { prefix foo; }
+
+    //invalid augment (mandatory choice)
+    augment "/foo:root" {
+        container mandatory-container {
+            choice mandatory-choice {
+                mandatory true;
+            }
+        }
+    }
+}
+
diff --git a/yang/yang-parser-rfc7950/src/test/resources/bugs/bug8126/inv-cont/foo.yang b/yang/yang-parser-rfc7950/src/test/resources/bugs/bug8126/inv-cont/foo.yang
new file mode 100644 (file)
index 0000000..b1b0df7
--- /dev/null
@@ -0,0 +1,7 @@
+module foo {
+    namespace foo;
+    prefix foo;
+
+    container root {
+    }
+}
diff --git a/yang/yang-parser-rfc7950/src/test/resources/bugs/bug8126/inv-cont/ill3.yang b/yang/yang-parser-rfc7950/src/test/resources/bugs/bug8126/inv-cont/ill3.yang
new file mode 100644 (file)
index 0000000..cd9856c
--- /dev/null
@@ -0,0 +1,22 @@
+module ill3 {
+    namespace ill3;
+    prefix ill3;
+
+    import foo { prefix foo; }
+
+    //invalid augments (mandatory container)
+    augment "/foo:root" {
+        container mandatory-container-2 {
+        }
+    }
+
+    augment "/foo:root/mandatory-container-2" {
+        container one {
+            leaf mandatory-leaf-3 {
+                mandatory true;
+                type empty;
+            }
+        }
+    }
+}
+
diff --git a/yang/yang-parser-rfc7950/src/test/resources/bugs/bug8126/inv-list/foo.yang b/yang/yang-parser-rfc7950/src/test/resources/bugs/bug8126/inv-list/foo.yang
new file mode 100644 (file)
index 0000000..b1b0df7
--- /dev/null
@@ -0,0 +1,7 @@
+module foo {
+    namespace foo;
+    prefix foo;
+
+    container root {
+    }
+}
diff --git a/yang/yang-parser-rfc7950/src/test/resources/bugs/bug8126/inv-list/ill2.yang b/yang/yang-parser-rfc7950/src/test/resources/bugs/bug8126/inv-list/ill2.yang
new file mode 100644 (file)
index 0000000..af790e3
--- /dev/null
@@ -0,0 +1,14 @@
+module ill2 {
+    namespace ill2;
+    prefix ill2;
+
+    import foo { prefix foo; }
+
+    //invalid augment (mandatory list)
+    augment "/foo:root" {
+        list mandatory-list {
+            min-elements 1;
+        }
+    }
+}
+
similarity index 54%
rename from yang/yang-parser-rfc7950/src/test/resources/bugs/bug8126/bar.yang
rename to yang/yang-parser-rfc7950/src/test/resources/bugs/bug8126/valid/bar.yang
index c142cbed06bd06d0dff7e92566eea1d5245e9d12..071f72902ec6362c3c4deb2a601bf2b2d9ff8e63 100644 (file)
@@ -38,35 +38,4 @@ module bar {
             }
         }
     }
-
-    //invalid augment (mandatory choice)
-    augment "/foo:root" {
-        container mandatory-container {
-            choice mandatory-choice {
-                mandatory true;
-            }
-        }
-    }
-
-    //invalid augment (mandatory list)    
-    augment "/foo:root" {
-        list mandatory-list {
-            min-elements 1;
-        }
-    }
-
-    //invalid augments (mandatory container)
-    augment "/foo:root" {
-        container mandatory-container-2 {
-        }
-    }
-
-    augment "/foo:root/mandatory-container-2" {
-        container one {
-            leaf mandatory-leaf-3 {
-                mandatory true;
-                type empty;
-            }
-        }
-    }
 }
diff --git a/yang/yang-parser-rfc7950/src/test/resources/bugs/bug8126/valid/foo.yang b/yang/yang-parser-rfc7950/src/test/resources/bugs/bug8126/valid/foo.yang
new file mode 100644 (file)
index 0000000..b1b0df7
--- /dev/null
@@ -0,0 +1,7 @@
+module foo {
+    namespace foo;
+    prefix foo;
+
+    container root {
+    }
+}