From: Samuel Schneider Date: Tue, 22 Mar 2022 15:04:56 +0000 (+0100) Subject: Replace calls of StmtTestUtils.parseYangSource(String) two X-Git-Tag: v8.0.3~22 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=yangtools.git;a=commitdiff_plain;h=c382ad5ab30ab577d7dc055912241cb2b87ff6b3 Replace calls of StmtTestUtils.parseYangSource(String) two 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 --- diff --git a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/YT826Test.java b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/YT826Test.java index ff635c2baf..0cbe2b7b1f 100644 --- a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/YT826Test.java +++ b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/YT826Test.java @@ -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"); } } diff --git a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6878Test.java b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6878Test.java index b6201bca7b..ba946840cf 100644 --- a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6878Test.java +++ b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6878Test.java @@ -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); } diff --git a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6885Test.java b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6885Test.java index 4c7c5cd5c3..bd8814f64e 100644 --- a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6885Test.java +++ b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6885Test.java @@ -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"); } } diff --git a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6887Test.java b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6887Test.java index ad313a2fef..e638344486 100644 --- a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6887Test.java +++ b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6887Test.java @@ -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) { diff --git a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/AbstractYangTest.java b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/AbstractYangTest.java index 22602437e1..4f389f691d 100644 --- a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/AbstractYangTest.java +++ b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/AbstractYangTest.java @@ -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 @NonNull E assertException(final Class cause, + public static @NonNull E assertException(final Class 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 @NonNull E assertArgumentException(final Class cause, + final Matcher matcher, final String... yangResourceName) { + final var ret = assertException(cause, yangResourceName); + assertThat(ret.getMessage(), matcher); + return ret; + } + public static @NonNull E assertExceptionDir(final String yangResourceName, final Class 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 matcher, final String... yangResourceName) { + return assertArgumentException(InvalidEnumDefinitionException.class, matcher, yangResourceName); + } + + public static @NonNull InvalidBitDefinitionException assertInvalidBitDefinitionException( + final Matcher matcher, final String... yangResourceName) { + return assertArgumentException(InvalidBitDefinitionException.class, matcher, yangResourceName); + } + public static @NonNull SourceException assertSourceException(final Matcher matcher, final String... yangResourceName) { final var ret = assertException(SourceException.class, matcher, yangResourceName); diff --git a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5101Test.java b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5101Test.java index 6e87a45343..cb06b22ab7 100644 --- a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5101Test.java +++ b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5101Test.java @@ -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 diff --git a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveUsesRefineAndConstraintsTest.java b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveUsesRefineAndConstraintsTest.java index ad258004f0..4fbd64b52b 100644 --- a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveUsesRefineAndConstraintsTest.java +++ b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveUsesRefineAndConstraintsTest.java @@ -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(); diff --git a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/OrderingTest.java b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/OrderingTest.java index e861805730..f1b44c5cab 100644 --- a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/OrderingTest.java +++ b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/OrderingTest.java @@ -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> 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 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 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 childNodes = x.getChildNodes(); diff --git a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1089Test.java b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1089Test.java index 7fd4ad1bfa..91a224f7b3 100644 --- a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1089Test.java +++ b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1089Test.java @@ -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> it = diff --git a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1195Test.java b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1195Test.java index b17f4545fa..dd09165e78 100644 --- a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1195Test.java +++ b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1195Test.java @@ -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 diff --git a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1200Test.java b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1200Test.java index 5ae4351b0c..3b3b27979e 100644 --- a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1200Test.java +++ b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1200Test.java @@ -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()); diff --git a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1208Test.java b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1208Test.java index 295f3f341b..51845da11f 100644 --- a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1208Test.java +++ b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1208Test.java @@ -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 groupings = module diff --git a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1209Test.java b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1209Test.java index c22c2d5321..c07174293b 100644 --- a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1209Test.java +++ b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1209Test.java @@ -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 diff --git a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1212Test.java b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1212Test.java index 70c2d67d5e..1acc2143b2 100644 --- a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1212Test.java +++ b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1212Test.java @@ -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 = diff --git a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1312Test.java b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1312Test.java index 5141ef95c0..3ffc092e83 100644 --- a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1312Test.java +++ b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1312Test.java @@ -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 diff --git a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT893Test.java b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT893Test.java index 4c40428fee..f770e6ed23 100644 --- a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT893Test.java +++ b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT893Test.java @@ -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"); } } diff --git a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT911Test.java b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT911Test.java index 9b8e303b93..ccab32cedf 100644 --- a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT911Test.java +++ b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT911Test.java @@ -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); diff --git a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT983Test.java b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT983Test.java index 1a5f6f8eb8..b846ee2a33 100644 --- a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT983Test.java +++ b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT983Test.java @@ -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); } diff --git a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserIdentityTest.java b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserIdentityTest.java index f6dde62889..d5b95791f9 100644 --- a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserIdentityTest.java +++ b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserIdentityTest.java @@ -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