Replace calls of StmtTestUtils.parseYangSource(String) 36/100136/5
authorSamuel Schneider <samuel.schneider@pantheon.tech>
Wed, 16 Mar 2022 14:58:14 +0000 (15:58 +0100)
committerRobert Varga <nite@hq.sk>
Wed, 23 Mar 2022 18:27:05 +0000 (18:27 +0000)
Removes code duplicity in parser unit tests.

JIRA: YANGTOOLS-1345
Change-Id: I0d20bf4d023a07e87d3d8228e29aa26a6bdb2348
Signed-off-by: Samuel Schneider <samuel.schneider@pantheon.tech>
16 files changed:
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ElementCountConstraintsTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/ActionStatementTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6868Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6880Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug9241Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/IdentityStatementTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/IdentityrefStatementTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/LeafrefStatementTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug7424Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug8922Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/NameCollisionWithinCaseTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/RpcStmtTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1189Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT838Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT857Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT971Test.java

index 205580e02d48a72f006e5ddf943c17c76f282d1f..22345b38cea1f405ead9d273cceff29d8ad8334f 100644 (file)
@@ -9,28 +9,21 @@ package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
 
-import java.io.IOException;
-import java.net.URISyntaxException;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.Revision;
 import org.opendaylight.yangtools.yang.model.api.ElementCountConstraint;
 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
+import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
 
-public class ElementCountConstraintsTest {
+public class ElementCountConstraintsTest extends AbstractYangTest {
     @Test
-    public void testElementCountConstraints()
-            throws YangSyntaxErrorException, ReactorException, URISyntaxException, IOException {
-        final var schemaContext = StmtTestUtils.parseYangSource("/constraint-definitions-test/foo.yang");
-        assertNotNull(schemaContext);
+    public void testElementCountConstraints() {
+        final var context = assertEffectiveModel("/constraint-definitions-test/foo.yang");
 
-        final Module testModule = schemaContext.findModule("foo", Revision.of("2016-09-20")).get();
+        final Module testModule = context.findModule("foo", Revision.of("2016-09-20")).get();
         final LeafListSchemaNode constrainedLeafList1 = (LeafListSchemaNode) testModule.getDataChildByName(
                 QName.create(testModule.getQNameModule(), "constrained-leaf-list-1"));
         ElementCountConstraint constraints1 = constrainedLeafList1.getElementCountConstraint().get();
index f42e5225c0da7d4081abbbfeba48af0778172278..ce780273cc296fc58bfb0d602d7c48dbe8d178d9 100644 (file)
@@ -8,10 +8,9 @@
 
 package org.opendaylight.yangtools.yang.parser.stmt.rfc7950;
 
+import static org.hamcrest.CoreMatchers.startsWith;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 
 import java.util.Collection;
 import java.util.HashSet;
@@ -25,28 +24,26 @@ import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
+import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
 
-public class ActionStatementTest {
+public class ActionStatementTest extends AbstractYangTest {
 
     private static final String FOO_NS = "foo-namespace";
     private static final String FOO_REV = "2016-12-13";
 
     @Test
     public void testActionStatementInDataContainers() throws Exception {
-        final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/action-stmt/foo.yang");
-        assertNotNull(schemaContext);
+        final var context = assertEffectiveModel("/rfc7950/action-stmt/foo.yang");
 
-        assertContainsActions(schemaContext, "root", "grp-action", "aug-action");
-        assertContainsActions(schemaContext, "top-list", "top-list-action");
-        assertContainsActions(schemaContext, "top", "top-action");
+        assertContainsActions(context, "root", "grp-action", "aug-action");
+        assertContainsActions(context, "top-list", "top-list-action");
+        assertContainsActions(context, "top", "top-action");
 
-        final Collection<? extends GroupingDefinition> groupings = schemaContext.getGroupings();
+        final Collection<? extends GroupingDefinition> groupings = context.getGroupings();
         assertEquals(1, groupings.size());
         assertContainsActions(groupings.iterator().next(), "grp-action");
 
-        final Collection<? extends Module> modules = schemaContext.getModules();
+        final Collection<? extends Module> modules = context.getModules();
         assertEquals(1, modules.size());
         final Module foo = modules.iterator().next();
         final Collection<? extends AugmentationSchemaNode> augmentations = foo.getAugmentations();
@@ -76,58 +73,32 @@ public class ActionStatementTest {
     }
 
     @Test
-    public void testActionUnsupportedInYang10() throws Exception {
-        try {
-            StmtTestUtils.parseYangSource("/rfc7950/action-stmt/foo10.yang");
-            fail("Test should fail due to invalid Yang 1.0");
-        } catch (final ReactorException e) {
-            assertTrue(e.getCause().getMessage().startsWith("action is not a YANG statement or use of extension"));
-        }
+    public void testActionUnsupportedInYang10() {
+        assertSourceException(startsWith("action is not a YANG statement or use of extension"),
+                "/rfc7950/action-stmt/foo10.yang");
     }
 
     @Test
-    public void testActionWithinIllegalAncestor() throws Exception {
-        try {
-            StmtTestUtils.parseYangSource("/rfc7950/action-stmt/foo-invalid.yang");
-            fail("Test should fail due to invalid Yang 1.1");
-        } catch (final ReactorException e) {
-            assertTrue(e.getCause().getMessage().startsWith("Action (foo-namespace?revision=2016-12-13)"
-                    + "action-in-grouping is defined within a notification, rpc or another action"));
-        }
+    public void testActionWithinIllegalAncestor() {
+        assertSourceException(startsWith("Action (foo-namespace?revision=2016-12-13)action-in-grouping is defined"
+                + " within a notification, rpc or another action"), "/rfc7950/action-stmt/foo-invalid.yang");
     }
 
     @Test
-    public void testActionWithinListWithoutKey() throws Exception {
-        try {
-            StmtTestUtils.parseYangSource("/rfc7950/action-stmt/bar-invalid.yang");
-            fail("Test should fail due to invalid Yang 1.1");
-        } catch (final ReactorException e) {
-            assertTrue(e.getCause().getMessage().startsWith(
-                    "Action (bar-namespace?revision=2016-12-13)my-action is defined within a list"
-                            + " that has no key statement"));
-        }
+    public void testActionWithinListWithoutKey() {
+        assertSourceException(startsWith("Action (bar-namespace?revision=2016-12-13)my-action is defined within a list"
+                + " that has no key statement"), "/rfc7950/action-stmt/bar-invalid.yang");
     }
 
     @Test
-    public void testActionInUsedGroupingWithinCase() throws Exception {
-        try {
-            StmtTestUtils.parseYangSource("/rfc7950/action-stmt/baz-invalid.yang");
-            fail("Test should fail due to invalid Yang 1.1");
-        } catch (final ReactorException e) {
-            assertTrue(e.getCause().getMessage().startsWith(
-                    "Action (baz-namespace?revision=2016-12-13)action-in-grouping is defined within a "
-                            + "case statement"));
-        }
+    public void testActionInUsedGroupingWithinCase() {
+        assertSourceException(startsWith("Action (baz-namespace?revision=2016-12-13)action-in-grouping"
+                + " is defined within a case statement"), "/rfc7950/action-stmt/baz-invalid.yang");
     }
 
     @Test
-    public void testActionInUsedGroupingAtTopLevelOfModule() throws Exception {
-        try {
-            StmtTestUtils.parseYangSource("/rfc7950/action-stmt/foobar-invalid.yang");
-            fail("Test should fail due to invalid Yang 1.1");
-        } catch (final ReactorException e) {
-            assertTrue(e.getCause().getMessage().startsWith(
-                    "Action (foobar-namespace?revision=2016-12-13)my-action is defined at the top level of a module"));
-        }
+    public void testActionInUsedGroupingAtTopLevelOfModule() {
+        assertSourceException(startsWith("Action (foobar-namespace?revision=2016-12-13)my-action is defined"
+                + " at the top level of a module"), "/rfc7950/action-stmt/foobar-invalid.yang");
     }
 }
index 5fd7a70f7e3054dafc935e774e89109d9f76a8aa..24932d0be43524dce9be20cc5a702f8f9a9312d8 100644 (file)
@@ -12,7 +12,6 @@ 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 com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Sets;
@@ -24,10 +23,10 @@ import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
-import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
+import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
 
-public class Bug6868Test {
+public class Bug6868Test extends AbstractYangTest {
     private static final String FOO_NS = "foo";
     private static final String IMP_NS = "imp";
     private static final String IMP_REV = "2017-01-09";
@@ -86,8 +85,7 @@ public class Bug6868Test {
 
     @Test
     public void invalidYang10Test() {
-        SomeModifiersUnresolvedException ex = assertThrows(SomeModifiersUnresolvedException.class,
-            () -> StmtTestUtils.parseYangSource("/rfc7950/bug6868/invalid10.yang"));
-        assertThat(ex.getCause().getMessage(), startsWith("Invalid identifier '(not foo) or (bar and baz)' [at "));
+        assertSourceException(startsWith("Invalid identifier '(not foo) or (bar and baz)' [at "),
+                "/rfc7950/bug6868/invalid10.yang");
     }
 }
\ No newline at end of file
index b5c502ab89f57784610707aae764aba4cf15e46c..9ca49d7dc8166af922fda8362fe85703aebcaeae 100644 (file)
@@ -11,27 +11,21 @@ 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;
 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.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
-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 Bug6880Test {
+public class Bug6880Test extends AbstractYangTest {
     @Test
-    public void valid10Test() throws Exception {
-        final EffectiveModelContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6880/foo.yang");
-        assertNotNull(schemaContext);
+    public void valid10Test() {
+        final var context = assertEffectiveModel("/rfc7950/bug6880/foo.yang");
 
-        final DataSchemaNode findDataSchemaNode = schemaContext.findDataTreeChild(QName.create("foo", "my-leaf-list"))
+        final DataSchemaNode findDataSchemaNode = context.findDataTreeChild(QName.create("foo", "my-leaf-list"))
             .orElse(null);
         assertThat(findDataSchemaNode, instanceOf(LeafListSchemaNode.class));
         final LeafListSchemaNode myLeafList = (LeafListSchemaNode) findDataSchemaNode;
@@ -43,10 +37,7 @@ public class Bug6880Test {
 
     @Test
     public void invalid10Test() {
-        final ReactorException ex = assertThrows(ReactorException.class,
-            () -> StmtTestUtils.parseYangSource("/rfc7950/bug6880/invalid10.yang"));
-        final Throwable cause = ex.getCause();
-        assertThat(cause, instanceOf(SourceException.class));
-        assertThat(cause.getMessage(), startsWith("DEFAULT is not valid for LEAF_LIST"));
+        assertInvalidSubstatementException(startsWith("DEFAULT is not valid for LEAF_LIST"),
+                "/rfc7950/bug6880/invalid10.yang");
     }
 }
\ No newline at end of file
index 8b33a770a9ee55293c0037f8f85968e623bcc50f..297ab4c4e80d1367fd177322d97ee2b570f3090c 100644 (file)
@@ -18,19 +18,17 @@ import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.InputSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.OutputSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.StatementOrigin;
-import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
+import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
 
-public class Bug9241Test {
+public class Bug9241Test extends AbstractYangTest {
 
     @Test
-    public void testImplicitInputAndOutputInAction() throws Exception {
-        final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug9241/foo.yang");
-        assertNotNull(schemaContext);
+    public void testImplicitInputAndOutputInAction() {
+        final var context = assertEffectiveModel("/rfc7950/bug9241/foo.yang");
 
-        final Module fooModule = schemaContext.findModule("foo", Revision.of("2017-10-13")).get();
+        final Module fooModule = context.findModule("foo", Revision.of("2017-10-13")).get();
 
         final ContainerSchemaNode actionCont = (ContainerSchemaNode) fooModule.getDataChildByName(QName.create(
                 fooModule.getQNameModule(), "action-cont"));
index 8bce589e228d3e45822831f1ff51a5333be9eeb9..718e195def77d4a4eb8a8cd6777ffd58f608937d 100644 (file)
@@ -7,28 +7,23 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc7950;
 
+import static org.hamcrest.CoreMatchers.startsWith;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 
 import java.util.Collection;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.Revision;
 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
+import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
 
-public class IdentityStatementTest {
+public class IdentityStatementTest extends AbstractYangTest {
 
     @Test
-    public void testMultipleBaseIdentities() throws Exception {
-        final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/identity-stmt/foo.yang");
-        assertNotNull(schemaContext);
+    public void testMultipleBaseIdentities() {
+        final var context = assertEffectiveModel("/rfc7950/identity-stmt/foo.yang");
 
-        final Module foo = schemaContext.findModule("foo", Revision.of("2016-12-21")).get();
+        final Module foo = context.findModule("foo", Revision.of("2016-12-21")).get();
         for (final IdentitySchemaNode identity : foo.getIdentities()) {
             if ("derived-id".equals(identity.getQName().getLocalName())) {
                 final Collection<? extends IdentitySchemaNode> baseIdentities = identity.getBaseIdentities();
@@ -38,12 +33,8 @@ public class IdentityStatementTest {
     }
 
     @Test
-    public void testInvalidYang10() throws Exception {
-        try {
-            StmtTestUtils.parseYangSource("/rfc7950/identity-stmt/foo10.yang");
-            fail("Test should fail due to invalid Yang 1.0");
-        } catch (final ReactorException e) {
-            assertTrue(e.getCause().getMessage().startsWith("Maximal count of BASE for IDENTITY is 1, detected 3."));
-        }
+    public void testInvalidYang10() {
+        assertInvalidSubstatementException(startsWith("Maximal count of BASE for IDENTITY is 1, detected 3."),
+                "/rfc7950/identity-stmt/foo10.yang");
     }
 }
index 00ffe4e194c9c9082e5dc868cb4a945eae6f34d3..5b2ea8e6e26965eaa32989f09ee1e409ab2f3d7c 100644 (file)
@@ -7,12 +7,10 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc7950;
 
+import static org.hamcrest.CoreMatchers.startsWith;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 
 import java.util.Collection;
 import java.util.Set;
@@ -22,19 +20,16 @@ import org.opendaylight.yangtools.yang.common.Revision;
 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
 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.IdentityrefTypeDefinition;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
+import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
 
-public class IdentityrefStatementTest {
+public class IdentityrefStatementTest extends AbstractYangTest {
 
     @Test
-    public void testIdentityrefWithMultipleBaseIdentities() throws Exception {
-        final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/identityref-stmt/foo.yang");
-        assertNotNull(schemaContext);
+    public void testIdentityrefWithMultipleBaseIdentities() {
+        final var context = assertEffectiveModel("/rfc7950/identityref-stmt/foo.yang");
 
-        final Module foo = schemaContext.findModule("foo", Revision.of("2017-01-11")).get();
+        final Module foo = context.findModule("foo", Revision.of("2017-01-11")).get();
         final Collection<? extends IdentitySchemaNode> identities = foo.getIdentities();
         assertEquals(3, identities.size());
 
@@ -48,12 +43,8 @@ public class IdentityrefStatementTest {
     }
 
     @Test
-    public void testInvalidYang10() throws Exception {
-        try {
-            StmtTestUtils.parseYangSource("/rfc7950/identityref-stmt/foo10.yang");
-            fail("Test should fail due to invalid Yang 1.0");
-        } catch (final ReactorException e) {
-            assertTrue(e.getCause().getMessage().startsWith("Maximal count of BASE for TYPE is 1, detected 3."));
-        }
+    public void testInvalidYang10() {
+        assertInvalidSubstatementException(startsWith("Maximal count of BASE for TYPE is 1, detected 3."),
+                "/rfc7950/identityref-stmt/foo10.yang");
     }
 }
index 769f23030e338d042b0f6410cc3879b8ac87c5e2..84a0967a3f0e79a8ce306bff9f1b4437a63f97cc 100644 (file)
@@ -7,10 +7,9 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc7950;
 
+import static org.hamcrest.CoreMatchers.startsWith;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 
 import java.util.Collection;
 import org.junit.Test;
@@ -18,20 +17,17 @@ import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.Revision;
 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.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
+import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
 
-public class LeafrefStatementTest {
+public class LeafrefStatementTest extends AbstractYangTest {
 
     @Test
-    public void testRequireInstanceInLeafrefs() throws Exception {
-        final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/leafref-stmt/foo.yang");
-        assertNotNull(schemaContext);
+    public void testRequireInstanceInLeafrefs() {
+        final var context = assertEffectiveModel("/rfc7950/leafref-stmt/foo.yang");
 
-        final Module foo = schemaContext.findModule("foo", Revision.of("2016-12-20")).get();
+        final Module foo = context.findModule("foo", Revision.of("2016-12-20")).get();
         final Collection<? extends TypeDefinition<?>> typeDefinitions = foo.getTypeDefinitions();
         assertEquals(1, typeDefinitions.size());
 
@@ -58,12 +54,8 @@ public class LeafrefStatementTest {
     }
 
     @Test
-    public void testInvalidYang10() throws Exception {
-        try {
-            StmtTestUtils.parseYangSource("/rfc7950/leafref-stmt/foo10.yang");
-            fail("Test should fail due to invalid Yang 1.0");
-        } catch (final ReactorException e) {
-            assertTrue(e.getCause().getMessage().startsWith("REQUIRE_INSTANCE is not valid for TYPE"));
-        }
+    public void testInvalidYang10() {
+        assertInvalidSubstatementException(startsWith("REQUIRE_INSTANCE is not valid for TYPE"),
+                "/rfc7950/leafref-stmt/foo10.yang");
     }
 }
index 7dbc82c697b9ceb6d3db52dce776f3f7b2149273..2ad46f05f97a5d251b6a1b4a4b01405d0dec9740 100644 (file)
@@ -7,54 +7,32 @@
  */
 package org.opendaylight.yangtools.yang.stmt;
 
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.hamcrest.CoreMatchers.startsWith;
 
 import org.junit.Test;
-import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
 
-public class Bug7424Test {
+public class Bug7424Test extends AbstractYangTest {
     @Test
-    public void testRpc() throws Exception {
-        try {
-            StmtTestUtils.parseYangSource("/bugs/bug7424/foo-rpc.yang");
-            fail("Test should fail due to invalid yang model.");
-        } catch (final SomeModifiersUnresolvedException e) {
-            assertTrue(e.getCause().getMessage().startsWith(
-                "Error in module 'foo': cannot add '(foo)name'. Node name collision: '(foo)name' already declared"));
-        }
+    public void testRpc()throws Exception {
+        assertSourceException(startsWith("Error in module 'foo': cannot add '(foo)name'. Node name collision:"
+                + " '(foo)name' already declared"), "/bugs/bug7424/foo-rpc.yang");
     }
 
     @Test
-    public void testNotification() throws Exception {
-        try {
-            StmtTestUtils.parseYangSource("/bugs/bug7424/foo-notification.yang");
-            fail("Test should fail due to invalid yang model.");
-        } catch (final SomeModifiersUnresolvedException e) {
-            assertTrue(e.getCause().getMessage().startsWith(
-                "Error in module 'foo': cannot add '(foo)name'. Node name collision: '(foo)name' already declared"));
-        }
+    public void testNotification() {
+        assertSourceException(startsWith("Error in module 'foo': cannot add '(foo)name'. Node name collision:"
+                + " '(foo)name' already declared"), "/bugs/bug7424/foo-notification.yang");
     }
 
     @Test
-    public void testData() throws Exception {
-        try {
-            StmtTestUtils.parseYangSource("/bugs/bug7424/foo-data.yang");
-            fail("Test should fail due to invalid yang model.");
-        } catch (final SomeModifiersUnresolvedException e) {
-            assertTrue(e.getCause().getMessage().startsWith(
-                "Error in module 'foo': cannot add '(foo)name'. Node name collision: '(foo)name' already declared"));
-        }
+    public void testData() {
+        assertSourceException(startsWith("Error in module 'foo': cannot add '(foo)name'. Node name collision:"
+                + " '(foo)name' already declared"), "/bugs/bug7424/foo-data.yang");
     }
 
     @Test
-    public void testRpcUses() throws Exception {
-        try {
-            StmtTestUtils.parseYangSource("/bugs/bug7424/foo-rpc-uses.yang");
-            fail("Test should fail due to invalid yang model.");
-        } catch (final SomeModifiersUnresolvedException e) {
-            assertTrue(e.getCause().getMessage().startsWith(
-                "Error in module 'foo': cannot add '(foo)name'. Node name collision: '(foo)name' already declared"));
-        }
+    public void testRpcUses() {
+        assertSourceException(startsWith("Error in module 'foo': cannot add '(foo)name'. Node name collision:"
+                + " '(foo)name' already declared"), "/bugs/bug7424/foo-rpc-uses.yang");
     }
 }
index 5ca52d95a08fae717505b7a692bd67ea92675d98..1df7226f3744a4b09be4b6014ab8b714ef35cd3f 100644 (file)
@@ -20,14 +20,13 @@ import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.stmt.FeatureEffectiveStatement;
 
-public class Bug8922Test {
+public class Bug8922Test extends AbstractYangTest {
     private static final QName MY_CON = QName.create("foo", "my-con");
     private static final QName TARGET = QName.create("foo", "target");
 
     @Test
-    public void testAllFeaturesSupported() throws Exception {
-        final var context = StmtTestUtils.parseYangSource("/bugs/bug8922/foo.yang");
-        assertNotNull(context);
+    public void testAllFeaturesSupported() {
+        final var context = assertEffectiveModel("/bugs/bug8922/foo.yang");
         final var findNode = context.findDataTreeChild(TARGET, MY_CON).get();
         assertThat(findNode, instanceOf(ContainerSchemaNode.class));
         assertEquals(Optional.of("New description"), findNode.getDescription());
index 9fa1ef1b87fb8295a16c9254f7eb8616ad49fc47..a0c607a5544730f198e4d86b1f4e6095a4a8b0c2 100644 (file)
@@ -7,43 +7,26 @@
  */
 package org.opendaylight.yangtools.yang.stmt;
 
-import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.hamcrest.CoreMatchers.startsWith;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertThrows;
 
 import org.junit.Test;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 
-public class NameCollisionWithinCaseTest {
+public class NameCollisionWithinCaseTest extends AbstractYangTest {
     @Test
     public void testChildNameCollisionOfAugmentCase() {
-        final ReactorException ex = assertThrows(ReactorException.class,
-            () -> StmtTestUtils.parseYangSource("/bugs/name-collision-within-case/foo.yang"));
-        final Throwable cause = ex.getCause();
-        assertThat(cause, instanceOf(SourceException.class));
-        assertThat(cause.getMessage(), startsWith("Cannot add data tree child with name (foo?revision=2018-02-11)bar, "
-            + "a conflicting child already exists [at "));
+        assertSourceException(startsWith("Cannot add data tree child with name (foo?revision=2018-02-11)bar, "
+                + "a conflicting child already exists [at "), "/bugs/name-collision-within-case/foo.yang");
     }
 
     @Test
     public void testChildNameCollisionOfAugmentChoice() {
-        final ReactorException ex = assertThrows(ReactorException.class,
-            () -> StmtTestUtils.parseYangSource("/bugs/name-collision-within-case/bar.yang"));
-        final Throwable cause = ex.getCause();
-        assertThat(cause, instanceOf(SourceException.class));
-        assertThat(cause.getMessage(), startsWith("Cannot add data tree child with name (bar?revision=2018-02-11)bar, "
-            + "a conflicting child already exists [at "));
+        assertSourceException(startsWith("Cannot add data tree child with name (bar?revision=2018-02-11)bar, "
+                + "a conflicting child already exists [at "), "/bugs/name-collision-within-case/bar.yang");
     }
 
     @Test
-    public void testChildNameCollisionNormal() throws Exception {
-        final ReactorException ex = assertThrows(ReactorException.class,
-            () -> StmtTestUtils.parseYangSource("/bugs/name-collision-within-case/baz.yang"));
-        final Throwable cause = ex.getCause();
-        assertThat(cause, instanceOf(SourceException.class));
-        assertThat(cause.getMessage(), startsWith(
-            "Error in module 'baz': cannot add '(baz?revision=2018-02-28)bar'. Node name collision: "));
+    public void testChildNameCollisionNormal() {
+        assertSourceException(startsWith("Error in module 'baz': cannot add '(baz?revision=2018-02-28)bar'."
+                + " Node name collision: "), "/bugs/name-collision-within-case/baz.yang");
     }
 }
index 22e451cc28551c0a561180fd3c3b9a1f92ea60d4..3d8104c678f8bca6c6ccf8232ac13f0461e928b1 100644 (file)
@@ -25,13 +25,12 @@ import org.opendaylight.yangtools.yang.model.api.InputSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.OutputSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.StatementOrigin;
 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 
-public class RpcStmtTest {
+public class RpcStmtTest extends AbstractYangTest {
     @Test
     public void rpcTest() throws ReactorException {
         final EffectiveModelContext result = RFC7950Reactors.defaultReactor().newBuild()
@@ -99,11 +98,10 @@ public class RpcStmtTest {
     }
 
     @Test
-    public void testImplicitInputAndOutput() throws Exception {
-        final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rpc-stmt-test/bar.yang");
-        assertNotNull(schemaContext);
+    public void testImplicitInputAndOutput() {
+        final var context = assertEffectiveModel("/rpc-stmt-test/bar.yang");
 
-        final Module barModule = schemaContext.findModule("bar", Revision.of("2016-11-25")).get();
+        final Module barModule = context.findModule("bar", Revision.of("2016-11-25")).get();
         final Collection<? extends RpcDefinition> rpcs = barModule.getRpcs();
         assertEquals(1, rpcs.size());
 
index c87205066ea9b02dad6a6fc49085f4196100dd11..d5bb6390caa2c8eaa8030bc4f0cfbe31197ed691 100644 (file)
@@ -7,33 +7,20 @@
  */
 package org.opendaylight.yangtools.yang.stmt;
 
-import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.hamcrest.CoreMatchers.startsWith;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertThrows;
 
 import org.junit.Test;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 
-public class YT1189Test {
+public class YT1189Test extends AbstractYangTest {
     @Test
     public void testDescendantAugment() {
-        final ReactorException ex = assertThrows(ReactorException.class,
-            () -> StmtTestUtils.parseYangSource("/bugs/YT1189/foo.yang"));
-        final Throwable cause = ex.getCause();
-        assertThat(cause, instanceOf(SourceException.class));
-        assertThat(cause.getMessage(),
-            startsWith("Descendant schema node identifier is not allowed when used outside of a uses statement [at "));
+        assertSourceException(startsWith("Descendant schema node identifier is not allowed when used outside"
+                + " of a uses statement [at "), "/bugs/YT1189/foo.yang");
     }
 
     @Test
     public void testAbsoluteUsesAugment() {
-        final ReactorException ex = assertThrows(ReactorException.class,
-            () -> StmtTestUtils.parseYangSource("/bugs/YT1189/bar.yang"));
-        final Throwable cause = ex.getCause();
-        assertThat(cause, instanceOf(SourceException.class));
-        assertThat(cause.getMessage(),
-            startsWith("Absolute schema node identifier is not allowed when used within a uses statement [at "));
+        assertSourceException(startsWith("Absolute schema node identifier is not allowed when used within a"
+                + " uses statement [at "), "/bugs/YT1189/bar.yang");
     }
 }
index f21fe3e769e3ffcac7014a470119030b8b5bdff8..8af788d21208ae16bd17d695a4cd84035384c7a4 100644 (file)
@@ -7,17 +7,11 @@
  */
 package org.opendaylight.yangtools.yang.stmt;
 
-import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.hamcrest.CoreMatchers.startsWith;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
 
 import org.junit.Test;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 
-public class YT838Test {
+public class YT838Test extends AbstractYangTest {
     @Test
     public void testGroupingShadowing() {
         testGrouping("grouping.yang");
@@ -39,21 +33,12 @@ public class YT838Test {
     }
 
     private static void testGrouping(final String model) {
-        final ReactorException ex = assertThrows(ReactorException.class,
-            () -> StmtTestUtils.parseYangSource("/bugs/YT838/" + model));
-
-        final Throwable cause = ex.getCause();
-        assertThat(cause, instanceOf(SourceException.class));
-        assertThat(cause.getMessage(),
-            startsWith("Duplicate name for grouping (grouping?revision=2017-12-20)foo [at "));
+        assertSourceException(startsWith("Duplicate name for grouping (grouping?revision=2017-12-20)foo [at "),
+                "/bugs/YT838/" + model);
     }
 
     private static void testTypedef(final String model) {
-        final ReactorException ex = assertThrows(ReactorException.class,
-            () -> StmtTestUtils.parseYangSource("/bugs/YT838/" + model));
-        final Throwable cause = ex.getCause();
-        assertTrue(cause instanceof SourceException);
-        assertThat(cause, instanceOf(SourceException.class));
-        assertThat(cause.getMessage(), startsWith("Duplicate name for typedef (typedef?revision=2017-12-20)foo [at "));
+        assertSourceException(startsWith("Duplicate name for typedef (typedef?revision=2017-12-20)foo [at "),
+                "/bugs/YT838/" + model);
     }
 }
index 834aeac605b78a96b71c936128ed2f497d6ef6a3..c9e2c680b9e720e3885ad243e76826f1eb3b2b52 100644 (file)
@@ -7,26 +7,14 @@
  */
 package org.opendaylight.yangtools.yang.stmt;
 
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.instanceOf;
 import static org.hamcrest.Matchers.startsWith;
-import static org.junit.Assert.fail;
 
 import org.junit.Test;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 
-public class YT857Test {
+public class YT857Test extends AbstractYangTest {
     @Test
-    public void testConflictDetection() throws Exception {
-        try {
-            StmtTestUtils.parseYangSource("/bugs/YT857/foo.yang");
-            fail("Conflict on models should have been detected");
-        } catch (ReactorException e) {
-            final Throwable cause = e.getCause();
-            assertThat(cause, instanceOf(SourceException.class));
-            assertThat(cause.getMessage(),
-                startsWith("Cannot add data tree child with name (foo)one, a conflicting child already exists"));
-        }
+    public void testConflictDetection() {
+        assertSourceException(startsWith("Cannot add data tree child with name (foo)one, a conflicting"
+                + " child already exists"), "/bugs/YT857/foo.yang");
     }
 }
index 3644bd3daaab9cb7cd1f3afc5f4066c4be59f996..4a73a3dcaca3620e8986dd89ee0c3f3628474061 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.yangtools.yang.stmt;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.core.IsInstanceOf.instanceOf;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
 
 import java.util.Optional;
 import org.junit.Test;
@@ -21,19 +20,17 @@ import org.opendaylight.yangtools.yang.common.XMLNamespace;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.type.Int16TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.Int32TypeDefinition;
 
-public class YT971Test {
+public class YT971Test extends AbstractYangTest {
     private static final QNameModule NAMESPACE = QNameModule.create(XMLNamespace.of("test"), Revision.of("2019-03-25"));
 
     @Test
-    public void testEscapeLexer() throws Exception {
-        final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/bugs/YT971/test.yang");
-        assertNotNull(schemaContext);
+    public void testEscapeLexer() {
+        final var context = assertEffectiveModel("/bugs/YT971/test.yang");
 
-        final DataSchemaNode someContainer = schemaContext.getDataChildByName(
+        final DataSchemaNode someContainer = context.getDataChildByName(
             QName.create(NAMESPACE, "some-container"));
         assertThat(someContainer, instanceOf(ContainerSchemaNode.class));
         final ContainerSchemaNode containerSchemaNode = (ContainerSchemaNode) someContainer;