Replace calls of StmtTestUtils.parseYangSource(String) two 17/100217/9
authorSamuel Schneider <samuel.schneider@pantheon.tech>
Tue, 22 Mar 2022 15:04:56 +0000 (16:04 +0100)
committerRobert Varga <nite@hq.sk>
Thu, 24 Mar 2022 15:10:39 +0000 (15:10 +0000)
Removes code duplicity in parser unit tests.
Part two of https://git.opendaylight.org/gerrit/c/yangtools/+/100136

JIRA: YANGTOOLS-1345
Change-Id: I31ec3700d425cb1e0732c9225a629d01b6d84b5c
Signed-off-by: Samuel Schneider <samuel.schneider@pantheon.tech>
19 files changed:
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/YT826Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6878Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6885Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6887Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/AbstractYangTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5101Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveUsesRefineAndConstraintsTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/OrderingTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1089Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1195Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1200Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1208Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1209Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1212Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1312Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT893Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT911Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT983Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserIdentityTest.java

index ff635c2bafda5193d46052328b0726d2057cb0b0..0cbe2b7b1ff3091c0b3e5c3116770f70fc27c307 100644 (file)
@@ -8,11 +8,11 @@
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
 
 import org.junit.Test;
-import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
+import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
 
-public class YT826Test {
+public class YT826Test extends AbstractYangTest {
     @Test
-    public void testWhenExpressionWhitespace() throws Exception {
-        StmtTestUtils.parseYangSource("/bugs/yangtools826/example.yang");
+    public void testWhenExpressionWhitespace() {
+        assertEffectiveModel("/bugs/yangtools826/example.yang");
     }
 }
index b6201bca7b9f28d7694b2f0bddedc4b7c160a735..ba946840cfcd7906ef48a95203bba6c581e9f0f3 100644 (file)
@@ -15,36 +15,36 @@ import java.io.ByteArrayOutputStream;
 import java.io.PrintStream;
 import java.nio.charset.StandardCharsets;
 import org.junit.Test;
-import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
+import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
 
-public class Bug6878Test {
+public class Bug6878Test extends AbstractYangTest {
 
     @Test
-    public void testParsingXPathWithYang11Functions() throws Exception {
+    public void testParsingXPathWithYang11Functions() {
         final String testLog = parseAndcaptureLog("/rfc7950/bug6878/foo.yang");
         assertFalse(testLog.contains("Could not find function: "));
     }
 
     @Test
-    public void shouldLogInvalidYang10XPath() throws Exception {
+    public void shouldLogInvalidYang10XPath() {
         final String testLog = parseAndcaptureLog("/rfc7950/bug6878/foo10-invalid.yang");
         assertThat(testLog, containsString("RFC7950 features required in RFC6020 context to parse expression "));
     }
 
     @Test
-    public void shouldLogInvalidYang10XPath2() throws Exception {
+    public void shouldLogInvalidYang10XPath2() {
         final String testLog = parseAndcaptureLog("/rfc7950/bug6878/foo10-invalid-2.yang");
         assertThat(testLog, containsString("RFC7950 features required in RFC6020 context to parse expression "));
     }
 
     @SuppressWarnings("checkstyle:regexpSinglelineJava")
-    private static String parseAndcaptureLog(final String yangFile) throws Exception {
+    private static String parseAndcaptureLog(final String yangFile) {
         final PrintStream stdout = System.out;
         final ByteArrayOutputStream output = new ByteArrayOutputStream();
 
         try (PrintStream out = new PrintStream(output, true, StandardCharsets.UTF_8)) {
             System.setOut(out);
-            StmtTestUtils.parseYangSource(yangFile);
+            assertEffectiveModel(yangFile);
         } finally {
             System.setOut(stdout);
         }
index 4c7c5cd5c385eaf23580c70a4a77d4f0f36ec352..bd8814f64e8230e9757cb67ff33063192eeac8be 100644 (file)
@@ -8,92 +8,58 @@
 
 package org.opendaylight.yangtools.yang.parser.stmt.rfc7950;
 
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.hamcrest.CoreMatchers.startsWith;
 
-import java.io.IOException;
-import java.net.URISyntaxException;
 import org.junit.Test;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
+import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
 
-public class Bug6885Test {
+public class Bug6885Test extends AbstractYangTest {
 
     @Test
-    public void validYang10Test() throws Exception {
+    public void validYang10Test() {
         // Yang 1.0 allows "if-feature" and "when" on list keys
-        final SchemaContext schemaContext =
-                StmtTestUtils.parseYangSource("/rfc7950/list-keys-test/correct-list-keys-test.yang");
-        assertNotNull(schemaContext);
+        assertEffectiveModel("/rfc7950/list-keys-test/correct-list-keys-test.yang");
     }
 
     @Test
-    public void invalidListLeafKeyTest1() throws Exception {
+    public void invalidListLeafKeyTest1() {
         final String exceptionMessage = "(urn:ietf:params:xml:ns:yang:yin:1)when statement is not allowed in "
                 + "(incorrect-list-keys-test?revision=2017-02-06)a2 leaf statement which is specified as a list key.";
-        testForWhen("/rfc7950/list-keys-test/incorrect-list-keys-test.yang", exceptionMessage);
+        assertSourceException(startsWith(exceptionMessage), "/rfc7950/list-keys-test/incorrect-list-keys-test.yang");
     }
 
     @Test
-    public void invalidListLeafKeyTest2() throws Exception {
+    public void invalidListLeafKeyTest2() {
         final String exceptionMessage = "(urn:ietf:params:xml:ns:yang:yin:1)if-feature statement is not allowed in "
                 + "(incorrect-list-keys-test1?revision=2017-02-06)b leaf statement which is specified as a list key.";
-        testForIfFeature("/rfc7950/list-keys-test/incorrect-list-keys-test1.yang", exceptionMessage);
+        assertSourceException(startsWith(exceptionMessage), "/rfc7950/list-keys-test/incorrect-list-keys-test1.yang");
     }
 
     @Test
-    public void invalidListUsesLeafKeyTest() throws Exception {
+    public void invalidListUsesLeafKeyTest() {
         final String exceptionMessage = "(urn:ietf:params:xml:ns:yang:yin:1)if-feature statement is not allowed in "
                 + "(incorrect-list-keys-test2?revision=2017-02-06)a1 leaf statement which is specified as a list key.";
-        testForIfFeature("/rfc7950/list-keys-test/incorrect-list-keys-test2.yang", exceptionMessage);
+        assertSourceException(startsWith(exceptionMessage), "/rfc7950/list-keys-test/incorrect-list-keys-test2.yang");
     }
 
     @Test
-    public void invalidListUsesLeafKeyTest1() throws Exception {
+    public void invalidListUsesLeafKeyTest1() {
         final String exceptionMessage = "(urn:ietf:params:xml:ns:yang:yin:1)when statement is not allowed in "
                 + "(incorrect-list-keys-test3?revision=2017-02-06)a2 leaf statement which is specified as a list key.";
-        testForWhen("/rfc7950/list-keys-test/incorrect-list-keys-test3.yang", exceptionMessage);
+        assertSourceException(startsWith(exceptionMessage), "/rfc7950/list-keys-test/incorrect-list-keys-test3.yang");
     }
 
     @Test
-    public void invalidListUsesLeafKeyTest2() throws Exception {
+    public void invalidListUsesLeafKeyTest2() {
         final String exceptionMessage = "(urn:ietf:params:xml:ns:yang:yin:1)if-feature statement is not allowed in "
                 + "(incorrect-list-keys-test4?revision=2017-02-06)a1 leaf statement which is specified as a list key.";
-        testForIfFeature("/rfc7950/list-keys-test/incorrect-list-keys-test4.yang", exceptionMessage);
+        assertSourceException(startsWith(exceptionMessage), "/rfc7950/list-keys-test/incorrect-list-keys-test4.yang");
     }
 
     @Test
-    public void invalidListUsesRefineLeafKeyTest() throws Exception {
+    public void invalidListUsesRefineLeafKeyTest() {
         final String exceptionMessage = "(urn:ietf:params:xml:ns:yang:yin:1)if-feature statement is not allowed in "
                 + "(incorrect-list-keys-test5?revision=2017-02-06)a1 leaf statement which is specified as a list key.";
-        testForIfFeature("/rfc7950/list-keys-test/incorrect-list-keys-test5.yang", exceptionMessage);
-    }
-
-    private static void testForIfFeature(final String yangSrcPath, final String exMsg) throws URISyntaxException,
-            SourceException, IOException, YangSyntaxErrorException {
-        try {
-            StmtTestUtils.parseYangSource(yangSrcPath);
-            fail("Test must fail: IF-FEATURE substatement is not allowed in LIST keys");
-        } catch (final ReactorException e) {
-            final Throwable cause = e.getCause();
-            assertTrue(cause instanceof SourceException);
-            assertTrue(cause.getMessage().startsWith(exMsg));
-        }
-    }
-
-    private static void testForWhen(final String yangSrcPath, final String exMsg) throws URISyntaxException,
-            SourceException, IOException, YangSyntaxErrorException {
-        try {
-            StmtTestUtils.parseYangSource(yangSrcPath);
-            fail("Test must fail: WHEN substatement is not allowed in LIST keys");
-        } catch (final ReactorException e) {
-            final Throwable cause = e.getCause();
-            assertTrue(cause instanceof SourceException);
-            assertTrue(cause.getMessage().startsWith(exMsg));
-        }
+        assertSourceException(startsWith(exceptionMessage), "/rfc7950/list-keys-test/incorrect-list-keys-test5.yang");
     }
 }
index ad313a2fefe4cec86b687e938f1a643a72f2a62c..e63834448624bba9f4dd5709573b0fad5e9c42f0 100644 (file)
@@ -7,12 +7,8 @@
  */
 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.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 
 import java.util.Collection;
@@ -23,27 +19,21 @@ import org.opendaylight.yangtools.yang.common.Revision;
 import org.opendaylight.yangtools.yang.common.Uint32;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition.Bit;
 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair;
 import org.opendaylight.yangtools.yang.model.ri.type.BitBuilder;
 import org.opendaylight.yangtools.yang.model.ri.type.EnumPairBuilder;
-import org.opendaylight.yangtools.yang.model.ri.type.InvalidBitDefinitionException;
-import org.opendaylight.yangtools.yang.model.ri.type.InvalidEnumDefinitionException;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
+import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
 
-public class Bug6887Test {
+public class Bug6887Test extends AbstractYangTest {
 
     @Test
-    public void testRestrictedEnumeration() throws Exception {
-        final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6887/foo.yang");
-        assertNotNull(schemaContext);
+    public void testRestrictedEnumeration() {
+        final var context = assertEffectiveModel("/rfc7950/bug6887/foo.yang");
 
-        final Module foo = schemaContext.findModule("foo", Revision.of("2017-01-26")).get();
+        final Module foo = context.findModule("foo", Revision.of("2017-01-26")).get();
         final LeafSchemaNode myEnumerationLeaf = (LeafSchemaNode) foo.getDataChildByName(
                 QName.create(foo.getQNameModule(), "my-enumeration-leaf"));
 
@@ -78,76 +68,52 @@ public class Bug6887Test {
 
     @Test
     public void testInvalidRestrictedEnumeration() {
-        final ReactorException ex = assertThrows(ReactorException.class,
-            () -> StmtTestUtils.parseYangSource("/rfc7950/bug6887/foo-invalid.yang"));
-        final Throwable cause = ex.getCause();
-        assertThat(cause, instanceOf(SourceException.class));
-        assertThat(cause.getMessage(), startsWith("Enum 'purple' is not a subset of its base enumeration type "
-            + "(foo?revision=2017-02-02)my-derived-enumeration-type."));
+        assertSourceException(startsWith("Enum 'purple' is not a subset of its base enumeration type "
+                + "(foo?revision=2017-02-02)my-derived-enumeration-type."), "/rfc7950/bug6887/foo-invalid.yang");
     }
 
     @Test
     public void testInvalidRestrictedEnumeration2() {
-        final ReactorException ex = assertThrows(ReactorException.class,
-            () -> StmtTestUtils.parseYangSource("/rfc7950/bug6887/foo-invalid-2.yang"));
-        final Throwable cause = ex.getCause();
-        assertThat(cause, instanceOf(InvalidEnumDefinitionException.class));
-        assertThat(cause.getMessage(), startsWith("Enum 'magenta' is not a subset of its base enumeration type "
-            + "(foo?revision=2017-02-02)my-base-enumeration-type."));
+        assertInvalidEnumDefinitionException(startsWith("Enum 'magenta' is not a subset of its base enumeration type "
+                + "(foo?revision=2017-02-02)my-base-enumeration-type."), "/rfc7950/bug6887/foo-invalid-2.yang");
     }
 
     @Test
     public void testInvalidRestrictedEnumeration3() {
-        final ReactorException ex = assertThrows(ReactorException.class,
-            () -> StmtTestUtils.parseYangSource("/rfc7950/bug6887/foo-invalid-3.yang"));
-        final Throwable cause = ex.getCause();
-        assertThat(cause, instanceOf(InvalidEnumDefinitionException.class));
-        assertThat(cause.getMessage(), startsWith("Value of enum 'red' must be the same as the value of "
-            + "corresponding enum in the base enumeration type (foo?revision=2017-02-02)"
-            + "my-derived-enumeration-type."));
+        assertInvalidEnumDefinitionException(startsWith("Value of enum 'red' must be the same as the value of "
+                + "corresponding enum in the base enumeration type (foo?revision=2017-02-02)"
+                + "my-derived-enumeration-type."), "/rfc7950/bug6887/foo-invalid-3.yang");
     }
 
     @Test
     public void testInvalidRestrictedEnumeration4() {
-        final ReactorException ex = assertThrows(ReactorException.class,
-            () -> StmtTestUtils.parseYangSource("/rfc7950/bug6887/foo-invalid-4.yang"));
-        final Throwable cause = ex.getCause();
-        assertThat(cause, instanceOf(InvalidEnumDefinitionException.class));
-        assertThat(cause.getMessage(), startsWith("Value of enum 'black' must be the same as the value of "
-            + "corresponding enum in the base enumeration type (foo?revision=2017-02-02)"
-            + "my-base-enumeration-type."));
+        assertInvalidEnumDefinitionException(startsWith("Value of enum 'black' must be the same as the value of "
+                + "corresponding enum in the base enumeration type (foo?revision=2017-02-02)"
+                + "my-base-enumeration-type."), "/rfc7950/bug6887/foo-invalid-4.yang");
     }
 
     @Test
-    public void testValidYang10EnumerationWithUnknownStatements() throws Exception {
-        final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6887/foo10-valid.yang");
-        assertNotNull(schemaContext);
+    public void testValidYang10EnumerationWithUnknownStatements() {
+        assertEffectiveModel("/rfc7950/bug6887/foo10-valid.yang");
     }
 
     @Test
     public void testInvalidYang10RestrictedEnumeration() {
-        final ReactorException ex = assertThrows(ReactorException.class,
-            () -> StmtTestUtils.parseYangSource("/rfc7950/bug6887/foo10-invalid.yang"));
-        final Throwable cause = ex.getCause();
-        assertThat(cause, instanceOf(SourceException.class));
-        assertThat(cause.getMessage(), startsWith("Restricted enumeration type is not allowed in YANG version 1 [at "));
+        assertSourceException(startsWith("Restricted enumeration type is not allowed in YANG version 1 [at "),
+                "/rfc7950/bug6887/foo10-invalid.yang");
     }
 
     @Test
     public void testInvalidYang10RestrictedEnumeration2() {
-        final ReactorException ex = assertThrows(ReactorException.class,
-            () -> StmtTestUtils.parseYangSource("/rfc7950/bug6887/foo10-invalid-2.yang"));
-        final Throwable cause = ex.getCause();
-        assertThat(cause, instanceOf(SourceException.class));
-        assertThat(cause.getMessage(), startsWith("Restricted enumeration type is not allowed in YANG version 1 [at "));
+        assertSourceException(startsWith("Restricted enumeration type is not allowed in YANG version 1 [at "),
+                "/rfc7950/bug6887/foo10-invalid-2.yang");
     }
 
     @Test
-    public void testRestrictedBits() throws Exception {
-        final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6887/bar.yang");
-        assertNotNull(schemaContext);
+    public void testRestrictedBits() {
+        final var context = assertEffectiveModel("/rfc7950/bug6887/bar.yang");
 
-        final Module bar = schemaContext.findModule("bar", Revision.of("2017-02-02")).get();
+        final Module bar = context.findModule("bar", Revision.of("2017-02-02")).get();
         final LeafSchemaNode myBitsLeaf = (LeafSchemaNode) bar.getDataChildByName(
                 QName.create(bar.getQNameModule(), "my-bits-leaf"));
 
@@ -190,66 +156,45 @@ public class Bug6887Test {
 
     @Test
     public void testInvalidRestrictedBits() {
-        final ReactorException ex = assertThrows(ReactorException.class,
-            () -> StmtTestUtils.parseYangSource("/rfc7950/bug6887/bar-invalid.yang"));
-        final Throwable cause = ex.getCause();
-        assertThat(cause, instanceOf(SourceException.class));
-        assertThat(cause.getMessage(), startsWith("Bit 'bit-w' is not a subset of its base bits type "
-            + "(bar?revision=2017-02-02)my-derived-bits-type."));
+        assertSourceException(startsWith("Bit 'bit-w' is not a subset of its base bits type "
+                + "(bar?revision=2017-02-02)my-derived-bits-type."), "/rfc7950/bug6887/bar-invalid.yang");
     }
 
     @Test
     public void testInvalidRestrictedBits2() {
-        final ReactorException ex = assertThrows(ReactorException.class,
-            () -> StmtTestUtils.parseYangSource("/rfc7950/bug6887/bar-invalid-2.yang"));
-        final Throwable cause = ex.getCause();
-        assertThat(cause, instanceOf(InvalidBitDefinitionException.class));
-        assertThat(cause.getMessage(), startsWith("Bit 'bit-x' is not a subset of its base bits type "
-            + "(bar?revision=2017-02-02)my-base-bits-type."));
+        assertInvalidBitDefinitionException(startsWith("Bit 'bit-x' is not a subset of its base bits type "
+                + "(bar?revision=2017-02-02)my-base-bits-type."), "/rfc7950/bug6887/bar-invalid-2.yang");
     }
 
     @Test
     public void testInvalidRestrictedBits3() {
-        final ReactorException ex = assertThrows(ReactorException.class,
-            () -> StmtTestUtils.parseYangSource("/rfc7950/bug6887/bar-invalid-3.yang"));
-        final Throwable cause = ex.getCause();
-        assertThat(cause, instanceOf(InvalidBitDefinitionException.class));
-        assertThat(cause.getMessage(), startsWith("Position of bit 'bit-c' must be the same as the position of "
-            + "corresponding bit in the base bits type (bar?revision=2017-02-02)my-derived-bits-type."));
+        assertInvalidBitDefinitionException(startsWith("Position of bit 'bit-c' must be the same as the position of "
+                + "corresponding bit in the base bits type (bar?revision=2017-02-02)my-derived-bits-type."),
+                "/rfc7950/bug6887/bar-invalid-3.yang");
     }
 
     @Test
     public void testInvalidRestrictedBits4() {
-        final ReactorException ex = assertThrows(ReactorException.class,
-            () -> StmtTestUtils.parseYangSource("/rfc7950/bug6887/bar-invalid-4.yang"));
-        final Throwable cause = ex.getCause();
-        assertThat(cause, instanceOf(InvalidBitDefinitionException.class));
-        assertThat(cause.getMessage(), startsWith("Position of bit 'bit-d' must be the same as the position of "
-            + "corresponding bit in the base bits type (bar?revision=2017-02-02)my-base-bits-type."));
+        assertInvalidBitDefinitionException(startsWith("Position of bit 'bit-d' must be the same as the position of "
+                + "corresponding bit in the base bits type (bar?revision=2017-02-02)my-base-bits-type."),
+                "/rfc7950/bug6887/bar-invalid-4.yang");
     }
 
     @Test
-    public void testValidYang10BitsWithUnknownStatements() throws Exception {
-        final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6887/bar10-valid.yang");
-        assertNotNull(schemaContext);
+    public void testValidYang10BitsWithUnknownStatements() {
+        assertEffectiveModel("/rfc7950/bug6887/bar10-valid.yang");
     }
 
     @Test
     public void testInvalidYang10RestrictedBits() {
-        final ReactorException ex = assertThrows(ReactorException.class,
-            () -> StmtTestUtils.parseYangSource("/rfc7950/bug6887/bar10-invalid.yang"));
-        final Throwable cause = ex.getCause();
-        assertThat(cause, instanceOf(SourceException.class));
-        assertThat(cause.getMessage(), startsWith("Restricted bits type is not allowed in YANG version 1 [at "));
+        assertSourceException(startsWith("Restricted bits type is not allowed in YANG version 1 [at "),
+                "/rfc7950/bug6887/bar10-invalid.yang");
     }
 
     @Test
     public void testInvalidYang10RestrictedBits2() {
-        final ReactorException ex = assertThrows(ReactorException.class,
-            () -> StmtTestUtils.parseYangSource("/rfc7950/bug6887/bar10-invalid-2.yang"));
-        final Throwable cause = ex.getCause();
-        assertThat(cause, instanceOf(SourceException.class));
-        assertThat(cause.getMessage(), startsWith("Restricted bits type is not allowed in YANG version 1 [at "));
+        assertSourceException(startsWith("Restricted bits type is not allowed in YANG version 1 [at "),
+                "/rfc7950/bug6887/bar10-invalid-2.yang");
     }
 
     private static EnumPair createEnumPair(final String name, final int value) {
index 22602437e1b8204dab6f215658ab4a2d2d6e8b6c..4f389f691dd0fd723344138991c822bf371c910f 100644 (file)
@@ -17,6 +17,8 @@ import com.google.common.base.Throwables;
 import org.eclipse.jdt.annotation.NonNull;
 import org.hamcrest.Matcher;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.model.ri.type.InvalidBitDefinitionException;
+import org.opendaylight.yangtools.yang.model.ri.type.InvalidEnumDefinitionException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.InvalidSubstatementException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
@@ -52,7 +54,7 @@ public abstract class AbstractYangTest {
         return ret;
     }
 
-    public static <E extends SourceException> @NonNull E assertException(final Class<E> cause,
+    public static <E extends RuntimeException> @NonNull E assertException(final Class<E> cause,
             final String... yangResourceName) {
         final var ex = assertThrows(SomeModifiersUnresolvedException.class,
             () -> TestUtils.parseYangSource(yangResourceName));
@@ -68,6 +70,13 @@ public abstract class AbstractYangTest {
         return ret;
     }
 
+    public static <E extends IllegalArgumentException> @NonNull E assertArgumentException(final Class<E> cause,
+            final Matcher<String> matcher, final String... yangResourceName) {
+        final var ret = assertException(cause, yangResourceName);
+        assertThat(ret.getMessage(), matcher);
+        return ret;
+    }
+
     public static <E extends SourceException> @NonNull E assertExceptionDir(final String yangResourceName,
             final Class<E> cause) {
         final var ex = assertThrows(SomeModifiersUnresolvedException.class,
@@ -104,6 +113,16 @@ public abstract class AbstractYangTest {
         return assertExceptionDir(yangResourceName, InvalidSubstatementException.class, matcher);
     }
 
+    public static @NonNull InvalidEnumDefinitionException assertInvalidEnumDefinitionException(
+            final Matcher<String> matcher, final String... yangResourceName) {
+        return assertArgumentException(InvalidEnumDefinitionException.class, matcher, yangResourceName);
+    }
+
+    public static @NonNull InvalidBitDefinitionException assertInvalidBitDefinitionException(
+            final Matcher<String> matcher, final String... yangResourceName) {
+        return assertArgumentException(InvalidBitDefinitionException.class, matcher, yangResourceName);
+    }
+
     public static @NonNull SourceException assertSourceException(final Matcher<String> matcher,
             final String... yangResourceName) {
         final var ret = assertException(SourceException.class, matcher, yangResourceName);
index 6e87a45343dbffc84a4c5a22a10a1715ce1efa7c..cb06b22ab7431c68a1e9f1a1b5f0194d91341261 100644 (file)
@@ -22,10 +22,10 @@ import org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatemen
 import org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
 
-public class Bug5101Test {
+public class Bug5101Test extends AbstractYangTest {
     @Test
     public void test() throws Exception {
-        final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/bug5101.yang")
+        final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/bug5101.yang")
             .getModuleStatement(QName.create("foo", "2016-01-29", "foo"));
 
         final ContainerEffectiveStatement myContainerInGrouping = module
index ad258004f02a5b617a2079ba0222e00440c0f15b..4fbd64b52bccbbcf4d7a8fbf378168d6660c9d15 100644 (file)
@@ -26,10 +26,10 @@ import org.opendaylight.yangtools.yang.model.api.SchemaNode;
 import org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
 
-public class EffectiveUsesRefineAndConstraintsTest {
+public class EffectiveUsesRefineAndConstraintsTest extends AbstractYangTest {
     @Test
     public void refineTest() throws Exception {
-        final EffectiveModelContext result = StmtTestUtils.parseYangSource("/stmt-test/uses/refine-test.yang");
+        final EffectiveModelContext result = assertEffectiveModel("/stmt-test/uses/refine-test.yang");
 
         final ModuleEffectiveStatement module = Iterables.getOnlyElement(result.getModuleStatements().values());
         final QNameModule qnameModule = module.localQNameModule();
index e861805730c832965cc85f05a3c058fa9bf0b736..f1b44c5cabea2704006430fbc6c078f5c9dda14f 100644 (file)
@@ -23,7 +23,7 @@ import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 
 public class OrderingTest extends AbstractModelTest {
     @Test
-    public void testOrderingTypedef() throws Exception {
+    public void testOrderingTypedef() {
         final Collection<? extends TypeDefinition<?>> typedefs = BAR.getTypeDefinitions();
         final String[] expectedOrder = { "int32-ext1", "int32-ext2", "string-ext1", "string-ext2", "string-ext3",
             "string-ext4", "multiple-pattern-string", "my-decimal-type", "my-union", "my-union-ext", "nested-union2"
@@ -39,7 +39,7 @@ public class OrderingTest extends AbstractModelTest {
     }
 
     @Test
-    public void testOrderingChildNodes() throws Exception {
+    public void testOrderingChildNodes() {
         AugmentationSchemaNode augment1 = null;
         for (final AugmentationSchemaNode as : FOO.getAugmentations()) {
             if (as.getChildNodes().size() == 5) {
@@ -62,7 +62,7 @@ public class OrderingTest extends AbstractModelTest {
     }
 
     @Test
-    public void testOrderingNestedChildNodes1() throws Exception {
+    public void testOrderingNestedChildNodes1() {
         final Collection<? extends DataSchemaNode> childNodes = FOO.getChildNodes();
         final String[] expectedOrder = { "int32-leaf", "string-leaf", "multiple-pattern-string-leaf",
             "multiple-pattern-direct-string-def-leaf", "length-leaf", "decimal-leaf", "decimal-leaf2", "ext",
@@ -80,7 +80,7 @@ public class OrderingTest extends AbstractModelTest {
     }
 
     @Test
-    public void testOrderingNestedChildNodes2() throws Exception {
+    public void testOrderingNestedChildNodes2() {
         final Collection<? extends GroupingDefinition> groupings = BAZ.getGroupings();
         assertEquals(1, groupings.size());
         final GroupingDefinition target = groupings.iterator().next();
@@ -98,8 +98,8 @@ public class OrderingTest extends AbstractModelTest {
     }
 
     @Test
-    public void testOrderingNestedChildNodes3() throws Exception {
-        final Module justFoo = StmtTestUtils.parseYangSource("/ordering/foo.yang").getModules().iterator().next();
+    public void testOrderingNestedChildNodes3() {
+        final Module justFoo = assertEffectiveModel("/ordering/foo.yang").getModules().iterator().next();
         final ContainerSchemaNode x = (ContainerSchemaNode) justFoo
                 .getDataChildByName(QName.create(justFoo.getQNameModule(), "x"));
         final Collection<? extends DataSchemaNode> childNodes = x.getChildNodes();
index 7fd4ad1bfaecd76c546f15e308b5d9e2d0275891..91a224f7b317dfed54aa9f1d519a9f222217e588 100644 (file)
@@ -26,10 +26,10 @@ import org.opendaylight.yangtools.yang.model.api.stmt.OrganizationEffectiveState
 import org.opendaylight.yangtools.yang.model.api.stmt.PrefixEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement;
 
-public class YT1089Test {
+public class YT1089Test extends AbstractYangTest {
     @Test
-    public void testPlusLexing() throws Exception {
-        final EffectiveModelContext ctx = StmtTestUtils.parseYangSource("/bugs/YT1089/foo.yang");
+    public void testPlusLexing() {
+        final EffectiveModelContext ctx = assertEffectiveModel("/bugs/YT1089/foo.yang");
         assertEquals(1, ctx.getModuleStatements().size());
 
         final Iterator<? extends EffectiveStatement<?, ?>> it =
index b17f4545fae0f1d6fccc928b96c9e4269a31f6c9..dd09165e78a579c82ff6fba07ddcd38650812881 100644 (file)
@@ -18,10 +18,10 @@ import org.opendaylight.yangtools.yang.model.api.stmt.KeyEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.ListEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
 
-public class YT1195Test {
+public class YT1195Test extends AbstractYangTest {
     @Test
-    public void testKeyStatementReuse() throws Exception {
-        final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1195/key.yang")
+    public void testKeyStatementReuse() {
+        final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1195/key.yang")
             .getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
 
         final ListEffectiveStatement grpFoo = module
index 5ae4351b0c7b92346bceb3f28c4bc286357a4520..3b3b27979e9ad43a77d3252dafdbd3cd28856318 100644 (file)
@@ -17,12 +17,12 @@ import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
 
-public class YT1200Test {
+public class YT1200Test extends AbstractYangTest {
     private static final QName FOO = QName.create("urn:foo", "foo");
 
     @Test
-    public void testKeyParsing() throws Exception {
-        final DataSchemaNode foo = StmtTestUtils.parseYangSource("/bugs/YT1200/foo.yang").getDataChildByName(FOO);
+    public void testKeyParsing() {
+        final DataSchemaNode foo = assertEffectiveModel("/bugs/YT1200/foo.yang").getDataChildByName(FOO);
         assertThat(foo, instanceOf(ListSchemaNode.class));
         assertEquals(List.of(FOO, QName.create(FOO, "bar"), QName.create(FOO, "baz")),
             ((ListSchemaNode) foo).getKeyDefinition());
index 295f3f341b13805375726d4fda00b43b538ec39d..51845da11f04f24be525877877bccc801d63cbc0 100644 (file)
@@ -30,10 +30,10 @@ import org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveState
 import org.opendaylight.yangtools.yang.model.api.stmt.TypedefEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.UsesEffectiveStatement;
 
-public class YT1208Test {
+public class YT1208Test extends AbstractYangTest {
     @Test
-    public void testAugmentStatementReuse() throws Exception {
-        final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1208/augment.yang")
+    public void testAugmentStatementReuse() {
+        final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1208/augment.yang")
             .getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
 
         final NotificationEffectiveStatement notif = module
@@ -52,8 +52,8 @@ public class YT1208Test {
     }
 
     @Test
-    public void testCaseStatementReuse() throws Exception {
-        final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1208/case.yang")
+    public void testCaseStatementReuse() {
+        final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1208/case.yang")
             .getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
 
         final NotificationEffectiveStatement notif = module
@@ -72,8 +72,8 @@ public class YT1208Test {
     }
 
     @Test
-    public void testChoiceStatementReuse() throws Exception {
-        final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1208/choice.yang")
+    public void testChoiceStatementReuse() {
+        final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1208/choice.yang")
             .getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
 
         final NotificationEffectiveStatement notif = module
@@ -90,8 +90,8 @@ public class YT1208Test {
     }
 
     @Test
-    public void testGroupingStatementReuse() throws Exception {
-        final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1208/grouping.yang")
+    public void testGroupingStatementReuse() {
+        final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1208/grouping.yang")
             .getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
 
         final NotificationEffectiveStatement notif = module
@@ -110,8 +110,8 @@ public class YT1208Test {
     }
 
     @Test
-    public void testLeafStatementReuse() throws Exception {
-        final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1208/leaf.yang")
+    public void testLeafStatementReuse() {
+        final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1208/leaf.yang")
             .getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
         assertNotNull(module);
 
@@ -129,8 +129,8 @@ public class YT1208Test {
     }
 
     @Test
-    public void testLeafListStatementReuse() throws Exception {
-        final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1208/leaflist.yang")
+    public void testLeafListStatementReuse() {
+        final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1208/leaflist.yang")
             .getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
 
         final NotificationEffectiveStatement notif = module
@@ -147,8 +147,8 @@ public class YT1208Test {
     }
 
     @Test
-    public void testListStatementReuse() throws Exception {
-        final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1208/list.yang")
+    public void testListStatementReuse() {
+        final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1208/list.yang")
             .getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
 
         final NotificationEffectiveStatement notif = module
@@ -165,8 +165,8 @@ public class YT1208Test {
     }
 
     @Test
-    public void testTypedefStatementReuse() throws Exception {
-        final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1208/typedef.yang")
+    public void testTypedefStatementReuse() {
+        final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1208/typedef.yang")
             .getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
 
         final TypedefEffectiveStatement grpBar = module
@@ -181,8 +181,8 @@ public class YT1208Test {
     }
 
     @Test
-    public void testUsesStatementReuse() throws Exception {
-        final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1208/uses.yang")
+    public void testUsesStatementReuse() {
+        final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1208/uses.yang")
             .getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
         assertNotNull(module);
         final List<GroupingEffectiveStatement> groupings = module
index c22c2d53218d986a5fd663ac41a355d95e42ea5a..c07174293bceee6ae3e98e7c36be799a8e077e8b 100644 (file)
@@ -18,10 +18,10 @@ import org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.WhenEffectiveStatement;
 
-public class YT1209Test {
+public class YT1209Test extends AbstractYangTest {
     @Test
-    public void testWhenStatementReuse() throws Exception {
-        final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1209/when.yang")
+    public void testWhenStatementReuse() {
+        final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1209/when.yang")
             .getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
 
         final LeafEffectiveStatement grpFoo = module
index 70c2d67d5e62ee140af5c1c9bec60e5d41345260..1acc2143b2a27cd169bb8eb870e69aaa382d4748 100644 (file)
@@ -23,10 +23,10 @@ import org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement;
 
-public class YT1212Test {
+public class YT1212Test extends AbstractYangTest {
     @Test
-    public void testActiontatementReuse() throws Exception {
-        final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1212/anyxml.yang")
+    public void testActiontatementReuse() {
+        final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1212/anyxml.yang")
             .getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
 
         final AnyxmlEffectiveStatement grpFoo = module
@@ -44,8 +44,8 @@ public class YT1212Test {
     }
 
     @Test
-    public void testLeafStatementReuse() throws Exception {
-        final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1212/leaf.yang")
+    public void testLeafStatementReuse() {
+        final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1212/leaf.yang")
             .getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
 
         final LeafEffectiveStatement grpFoo = module
@@ -63,8 +63,8 @@ public class YT1212Test {
     }
 
     @Test
-    public void testContainerStatementReuse() throws Exception {
-        final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1212/container.yang")
+    public void testContainerStatementReuse() {
+        final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1212/container.yang")
             .getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
 
         final NotificationEffectiveStatement notif =
index 5141ef95c04af44d9829ffd90ea02412f32f9462..3ffc092e837fe31adc0cd4ceab0c54cdf4b363c8 100644 (file)
@@ -19,10 +19,10 @@ import org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement
 import org.opendaylight.yangtools.yang.model.api.stmt.LeafListEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
 
-public class YT1312Test {
+public class YT1312Test extends AbstractYangTest {
     @Test
-    public void testRefineDefault() throws Exception {
-        final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1312/foo.yang")
+    public void testRefineDefault() {
+        final ModuleEffectiveStatement module = assertEffectiveModel("/bugs/YT1312/foo.yang")
             .getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
 
         final LeafListEffectiveStatement grpFoo = module
index 4c40428fee441c057c226bf1be25783a034ccec3..f770e6ed236e85188d179ee4a899573d0a53ea0b 100644 (file)
@@ -7,29 +7,28 @@
  */
 package org.opendaylight.yangtools.yang.stmt;
 
-import static org.junit.Assert.assertNotNull;
+import static org.hamcrest.CoreMatchers.startsWith;
 
 import org.junit.Test;
-import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
 
-public class YT893Test {
-    @Test(expected = SomeModifiersUnresolvedException.class)
-    public void testCR() throws Exception {
-        StmtTestUtils.parseYangSource("/bugs/YT893/cr.yang");
+public class YT893Test extends AbstractYangTest {
+    @Test
+    public void testCR() {
+        assertSourceException(startsWith("Failed to parse node"), "/bugs/YT893/cr.yang");
     }
 
     @Test
-    public void testCRLF() throws Exception {
-        assertNotNull(StmtTestUtils.parseYangSource("/bugs/YT893/crlf.yang"));
+    public void testCRLF() {
+        assertEffectiveModel("/bugs/YT893/crlf.yang");
     }
 
     @Test
-    public void testHTAB() throws Exception {
-        assertNotNull(StmtTestUtils.parseYangSource("/bugs/YT893/ht.yang"));
+    public void testHTAB() {
+        assertEffectiveModel("/bugs/YT893/ht.yang");
     }
 
     @Test
-    public void testLF() throws Exception {
-        assertNotNull(StmtTestUtils.parseYangSource("/bugs/YT893/lf.yang"));
+    public void testLF() {
+        assertEffectiveModel("/bugs/YT893/lf.yang");
     }
 }
index 9b8e303b9300f65a64d1c8916216933376fecf0d..ccab32cedf9320a932a34bbd09fef35500e34304 100644 (file)
@@ -16,15 +16,14 @@ import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
-public class YT911Test {
+public class YT911Test extends AbstractYangTest {
     private static final QName FOO = QName.create("foo", "2018-10-22", "foo");
     private static final QName BAR = QName.create(FOO, "bar");
 
     @Test
-    public void testAugmentationConfig() throws Exception {
-        final SchemaContext context = StmtTestUtils.parseYangSource("/bugs/YT911/foo.yang");
+    public void testAugmentationConfig() {
+        final var context = assertEffectiveModel("/bugs/YT911/foo.yang");
         final DataSchemaNode foo = context.findDataChildByName(FOO).get();
         assertEquals(Optional.of(Boolean.FALSE), foo.effectiveConfig());
         assertTrue(foo instanceof ContainerSchemaNode);
index 1a5f6f8eb80385767ec7c5eeec7c678f1e707640..b846ee2a336b8ecf585ad477b6c55924ad350b63 100644 (file)
@@ -13,14 +13,13 @@ import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
-public class YT983Test {
+public class YT983Test extends AbstractYangTest {
     private static final QName FOO = QName.create("foo", "2019-04-30", "foo");
 
     @Test
-    public void testAugmentationConfig() throws Exception {
-        final SchemaContext context = StmtTestUtils.parseYangSource("/bugs/YT983/foo.yang");
+    public void testAugmentationConfig() {
+        final var context = assertEffectiveModel("/bugs/YT983/foo.yang");
         final DataSchemaNode foo = context.findDataChildByName(FOO).get();
         assertTrue(foo instanceof LeafSchemaNode);
     }
index f6dde62889e037a3ff9aa8f9a5cbf0d88cc70517..d5b95791f9f550a0e37020a7c81bd287f94548c9 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.yangtools.yang.stmt;
 
+import static org.hamcrest.CoreMatchers.startsWith;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotEquals;
 
@@ -14,30 +15,21 @@ import java.util.Collection;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
-import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
 
-public class YangParserIdentityTest {
+public class YangParserIdentityTest extends AbstractYangTest {
 
     // base identity name equals identity name
-    @Test(expected = SomeModifiersUnresolvedException.class)
-    public void testParsingIdentityTestModule() throws Exception {
-        try {
-            StmtTestUtils.parseYangSource("/identity/identitytest.yang");
-        } catch (SomeModifiersUnresolvedException e) {
-            StmtTestUtils.log(e, "      ");
-            throw e;
-        }
+    @Test
+    public void testParsingIdentityTestModule() {
+        assertInferenceException(startsWith("Unable to resolve identity (urn:test.identitytest?revision="
+                + "2014-09-17)test and base identity"), "/identity/identitytest.yang");
     }
 
     // same module prefixed base identity name equals identity name
-    @Test(expected = SomeModifiersUnresolvedException.class)
-    public void testParsingPrefixIdentityTestModule() throws Exception {
-        try {
-            StmtTestUtils.parseYangSource("/identity/prefixidentitytest.yang");
-        } catch (SomeModifiersUnresolvedException e) {
-            StmtTestUtils.log(e, "      ");
-            throw e;
-        }
+    @Test
+    public void testParsingPrefixIdentityTestModule() {
+        assertInferenceException(startsWith("Unable to resolve identity (urn:test.prefixidentitytest?revision="
+                + "2014-09-24)prefixtest and base identity"), "/identity/prefixidentitytest.yang");
     }
 
     // imported module prefixed base identity name equals identity name, but