Add AbstractYangTest 19/97719/6
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 2 Oct 2021 20:51:21 +0000 (22:51 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 5 Oct 2021 08:36:41 +0000 (10:36 +0200)
We have a number of common assertion patterns, let's start creating a
library.

Change-Id: Ieeccf260c638905fb7bdb77369ced8f845b01ca7
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
26 files changed:
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6867BasicTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6869Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6871Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6886Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6901Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/AbstractModelTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/AbstractYangTest.java [new file with mode: 0644]
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/AugmentTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/AugmentToExtensionTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug1412Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug1413Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug3859Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug394Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug4623Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug6771Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug7865Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug7879Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug8831Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/GroupingTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/ListKeysTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/ParsingExtensionValueTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/StmtTestUtils.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/SubstatementValidatorTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/TwoRevisionsTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/UsesAugmentTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserSimpleTest.java

index a154d46e19be3709fcf8c57bf2024802ec80eb70..9ee65ef787630ef40ee70b6bf3a30b22baa49ae8 100644 (file)
@@ -8,80 +8,57 @@
 
 package org.opendaylight.yangtools.yang.parser.stmt.rfc7950;
 
+import static org.hamcrest.CoreMatchers.startsWith;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 
 import org.junit.Test;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.InvalidSubstatementException;
+import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
 
-public class Bug6867BasicTest {
+public class Bug6867BasicTest extends AbstractYangTest {
 
     @Test
     public void valid10Test() throws Exception {
-        final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/basic-test/valid-10.yang");
-        assertNotNull(schemaContext);
+        assertEffectiveModel("/rfc7950/basic-test/valid-10.yang");
     }
 
     @Test
     public void valid11Test() throws Exception {
-        final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/basic-test/valid-11.yang");
-        assertNotNull(schemaContext);
+        assertEffectiveModel("/rfc7950/basic-test/valid-11.yang");
     }
 
     @Test
-    public void invalid10Test() throws Exception {
-        try {
-            StmtTestUtils.parseYangSource("/rfc7950/basic-test/invalid-10.yang");
-            fail("Test should fail due to invalid Yang 1.0");
-        } catch (final SomeModifiersUnresolvedException e) {
-            assertTrue(e.getCause().getMessage().startsWith("NOTIFICATION is not valid for CONTAINER"));
-        }
+    public void invalid10Test() {
+        assertException(InvalidSubstatementException.class, startsWith("NOTIFICATION is not valid for CONTAINER"),
+            "/rfc7950/basic-test/invalid-10.yang");
     }
 
     @Test
-    public void invalid11Test() throws Exception {
-        try {
-            StmtTestUtils.parseYangSource("/rfc7950/basic-test/invalid-11.yang");
-            fail("Test should fail due to invalid Yang 1.1");
-        } catch (final SomeModifiersUnresolvedException e) {
-            assertTrue(e.getCause().getMessage().startsWith("RPC is not valid for CONTAINER"));
-        }
+    public void invalid11Test() {
+        assertException(InvalidSubstatementException.class, startsWith("RPC is not valid for CONTAINER"),
+            "/rfc7950/basic-test/invalid-11.yang");
     }
 
     @Test
     public void anyData11Test() throws Exception {
-        final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/basic-test/anydata-11.yang");
-        assertNotNull(schemaContext);
+        assertEffectiveModel("/rfc7950/basic-test/anydata-11.yang");
     }
 
     @Test
-    public void anyData10Test() throws Exception {
-        try {
-            StmtTestUtils.parseYangSource("/rfc7950/basic-test/anydata-10.yang");
-            fail("Test should fail due to invalid Yang 1.0");
-        } catch (final SomeModifiersUnresolvedException e) {
-            assertTrue(e.getCause().getMessage().startsWith("anydata is not a YANG statement or use of extension"));
-        }
+    public void anyData10Test() {
+        assertSourceException(startsWith("anydata is not a YANG statement or use of extension"),
+            "/rfc7950/basic-test/anydata-10.yang");
     }
 
     @Test
     public void yangModelTest() throws Exception {
-        final SchemaContext schemaContext = StmtTestUtils.parseYangSources("/rfc7950/model");
-        assertNotNull(schemaContext);
+        assertNotNull(StmtTestUtils.parseYangSources("/rfc7950/model"));
     }
 
     @Test
-    public void unsupportedVersionTest() throws Exception {
-        try {
-            StmtTestUtils.parseYangSource("/rfc7950/basic-test/unsupported-version.yang");
-            fail("Test should fail due to unsupported Yang version");
-        } catch (final SomeModifiersUnresolvedException e) {
-            final Throwable cause = e.getCause();
-            assertNotNull(cause);
-            assertTrue(cause.getMessage().startsWith("Unsupported YANG version 2.3"));
-        }
+    public void unsupportedVersionTest() {
+        assertSourceException(startsWith("Unsupported YANG version 2.3"),
+            "/rfc7950/basic-test/unsupported-version.yang");
     }
 }
index cfbcc1d28151080f05fa894950d8d60cffe492ea..668f7db76a6c5fe11889bb6b01154e877d1bf42c 100644 (file)
@@ -13,7 +13,6 @@ import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 
 import com.google.common.collect.ImmutableSet;
@@ -27,11 +26,10 @@ import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 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.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
 
-public class Bug6869Test {
+public class Bug6869Test extends AbstractYangTest {
     private static final QName ROOT = QName.create("foo", "root");
     private static final QName GRP_LEAF = QName.create("foo", "grp-leaf");
 
@@ -83,10 +81,7 @@ public class Bug6869Test {
 
     @Test
     public void invalidYang10Test() {
-        final ReactorException ex = assertThrows(ReactorException.class,
-            () -> StmtTestUtils.parseYangSource("/rfc7950/bug6869/invalid10.yang"));
-        final Throwable cause = ex.getCause();
-        assertThat(cause, instanceOf(SourceException.class));
-        assertThat(cause.getMessage(), startsWith("IF_FEATURE is not valid for IDENTITY"));
+        assertInvalidSubstatementException(startsWith("IF_FEATURE is not valid for IDENTITY"),
+            "/rfc7950/bug6869/invalid10.yang");
     }
 }
\ No newline at end of file
index 3bc9772196c4149a5cd600923deac186b1b4dfc4..5270c9def97c796eb8ce845876e13d12d75be2ef 100644 (file)
@@ -7,40 +7,32 @@
  */
 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.InputSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.MustDefinition;
 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
 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.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
-
-public class Bug6871Test {
+import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
 
+public class Bug6871Test extends AbstractYangTest {
     @Test
     public void testValidYang11Model() throws Exception {
-        final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6871/foo.yang");
-        assertNotNull(schemaContext);
-
-        final Module foo = schemaContext.findModule("foo", Revision.of("2016-12-14")).get();
+        final Module foo = assertEffectiveModel("/rfc7950/bug6871/foo.yang")
+            .findModule("foo", Revision.of("2016-12-14")).orElseThrow();
 
-        final Collection<? extends NotificationDefinition> notifications = foo.getNotifications();
+        final var notifications = foo.getNotifications();
         assertEquals(1, notifications.size());
         final NotificationDefinition myNotification = notifications.iterator().next();
-        Collection<? extends MustDefinition> mustConstraints = myNotification.getMustConstraints();
+        var mustConstraints = myNotification.getMustConstraints();
         assertEquals(2, mustConstraints.size());
 
-        final Collection<? extends RpcDefinition> rpcs = foo.getRpcs();
+        final var rpcs = foo.getRpcs();
         assertEquals(1, rpcs.size());
         final RpcDefinition myRpc = rpcs.iterator().next();
 
@@ -56,18 +48,10 @@ public class Bug6871Test {
     }
 
     @Test
-    public void testInvalidYang10Model() throws Exception {
-        assertException("/rfc7950/bug6871/foo10.yang", "MUST is not valid for NOTIFICATION");
-        assertException("/rfc7950/bug6871/bar10.yang", "MUST is not valid for INPUT");
-        assertException("/rfc7950/bug6871/baz10.yang", "MUST is not valid for OUTPUT");
-    }
-
-    private static void assertException(final String sourcePath, final String exceptionMessage) throws Exception {
-        try {
-            StmtTestUtils.parseYangSource(sourcePath);
-            fail("Test should fail due to invalid Yang 1.0");
-        } catch (final ReactorException ex) {
-            assertTrue(ex.getCause().getMessage().startsWith(exceptionMessage));
-        }
+    public void testInvalidYang10Model() {
+        assertInvalidSubstatementException(startsWith("MUST is not valid for NOTIFICATION"),
+            "/rfc7950/bug6871/foo10.yang");
+        assertInvalidSubstatementException(startsWith("MUST is not valid for INPUT"), "/rfc7950/bug6871/bar10.yang");
+        assertInvalidSubstatementException(startsWith("MUST is not valid for OUTPUT"), "/rfc7950/bug6871/baz10.yang");
     }
 }
index f20b1aef7b974d2b6966080ab4ba7a15d22d8a8d..3663432823baebb3435fcc2440d427bcac9a6f08 100644 (file)
@@ -7,66 +7,44 @@
  */
 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 org.junit.Test;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
-import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
-
-public class Bug6886Test {
+import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
 
+public class Bug6886Test extends AbstractYangTest {
     @Test
-    public void yang11UnquotedStrTest() throws Exception {
-        try {
-            StmtTestUtils.parseYangSource("/rfc7950/bug6886/yang11/foo.yang");
-            fail("Test should fail due to invalid yang");
-        } catch (final SomeModifiersUnresolvedException e) {
-            assertTrue(e.getCause().getMessage()
-                    .startsWith("YANG 1.1: unquoted string (illegalchars\"test1) contains illegal characters"));
-        }
+    public void yang11UnquotedStrTest() {
+        assertSourceException(startsWith("YANG 1.1: unquoted string (illegalchars\"test1) contains illegal characters"),
+            "/rfc7950/bug6886/yang11/foo.yang");
     }
 
     @Test
     public void yang11UnquotedStrTest2() throws Exception {
-        try {
-            StmtTestUtils.parseYangSource("/rfc7950/bug6886/yang11/foo2.yang");
-            fail("Test should fail due to invalid yang");
-        } catch (final SomeModifiersUnresolvedException e) {
-            assertTrue(e.getCause().getMessage()
-                    .startsWith("YANG 1.1: unquoted string (illegalchars'test2) contains illegal characters"));
-        }
+        assertSourceException(startsWith("YANG 1.1: unquoted string (illegalchars'test2) contains illegal characters"),
+            "/rfc7950/bug6886/yang11/foo2.yang");
     }
 
     @Test
     public void yang11DoubleQuotedStrTest() throws Exception {
-        try {
-            StmtTestUtils.parseYangSource("/rfc7950/bug6886/yang11/foo3.yang");
-            fail("Test should fail due to invalid yang");
-        } catch (final SomeModifiersUnresolvedException e) {
-            assertTrue(e.getCause().getMessage().startsWith("YANG 1.1: illegal double quoted string "
-                    + "(i\\\\\\\\l\\nl\\te\\\"\\galcharstest1). In double quoted string the backslash must be followed "
-                    + "by one of the following character [n,t,\",\\], but was 'g'."));
-        }
+        assertSourceException(startsWith("YANG 1.1: illegal double quoted string "
+            + "(i\\\\\\\\l\\nl\\te\\\"\\galcharstest1). In double quoted string the backslash must be followed "
+            + "by one of the following character [n,t,\",\\], but was 'g'."),
+            "/rfc7950/bug6886/yang11/foo3.yang");
     }
 
     @Test
     public void yang10UnquotedStrTest() throws Exception {
-        final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6886/yang10/foo.yang");
-        assertNotNull(schemaContext);
+        assertEffectiveModel("/rfc7950/bug6886/yang10/foo.yang");
     }
 
     @Test
     public void yang10UnquotedStrTest2() throws Exception {
-        final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6886/yang10/foo2.yang");
-        assertNotNull(schemaContext);
+        assertEffectiveModel("/rfc7950/bug6886/yang10/foo2.yang");
     }
 
     @Test
     public void yang10DoubleQuotedStrTest() throws Exception {
-        final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6886/yang10/foo3.yang");
-        assertNotNull(schemaContext);
+        assertEffectiveModel("/rfc7950/bug6886/yang10/foo3.yang");
     }
 }
index 33ad7dbd0e032eba99017b91c8ece78965cc9457..645016ea7c8dc0b521c6d31a356a6407144e8ef1 100644 (file)
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.yangtools.yang.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.containsString;
+import static org.hamcrest.CoreMatchers.startsWith;
 
 import org.junit.Test;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
-import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
-
-public class Bug6901Test {
+import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
 
+public class Bug6901Test extends AbstractYangTest {
     @Test
     public void ifFeature11EnumBitTest() throws Exception {
-        final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6901/foo.yang");
-        assertNotNull(schemaContext);
+        assertEffectiveModel("/rfc7950/bug6901/foo.yang");
     }
 
     @Test
-    public void ifFeatureOnDefaultValueEnumTest() throws Exception {
-        try {
-            StmtTestUtils.parseYangSource("/rfc7950/bug6901/invalid-foo-enum.yang");
-            fail("Test should fail due to invalid Yang 1.1");
-        } catch (final SomeModifiersUnresolvedException e) {
-            assertTrue(e.getCause().getMessage().startsWith(
-                    "Leaf '(foo)enum-leaf' has default value 'two' marked with an if-feature statement."));
-        }
+    public void ifFeatureOnDefaultValueEnumTest() {
+        assertSourceException(
+            startsWith("Leaf '(foo)enum-leaf' has default value 'two' marked with an if-feature statement."),
+            "/rfc7950/bug6901/invalid-foo-enum.yang");
     }
 
     @Test
-    public void ifFeatureOnDefaultValueEnumTest2() throws Exception {
-        try {
-            StmtTestUtils.parseYangSource("/rfc7950/bug6901/invalid-foo-enum-2.yang");
-            fail("Test should fail due to invalid Yang 1.1");
-        } catch (final SomeModifiersUnresolvedException e) {
-            assertTrue(e.getCause().getMessage().startsWith(
-                    "Leaf '(foo)enum-leaf' has default value 'two' marked with an if-feature statement."));
-        }
+    public void ifFeatureOnDefaultValueEnumTest2() {
+        assertSourceException(
+            startsWith("Leaf '(foo)enum-leaf' has default value 'two' marked with an if-feature statement."),
+            "/rfc7950/bug6901/invalid-foo-enum-2.yang");
     }
 
     @Test
-    public void ifFeatureOnDefaultValueEnumTest3() throws Exception {
-        try {
-            StmtTestUtils.parseYangSource("/rfc7950/bug6901/invalid-foo-enum-3.yang");
-            fail("Test should fail due to invalid Yang 1.1");
-        } catch (final SomeModifiersUnresolvedException e) {
-            assertTrue(e.getCause().getMessage().startsWith(
-                    "Leaf '(foo)enum-leaf' has default value 'two' marked with an if-feature statement."));
-        }
+    public void ifFeatureOnDefaultValueEnumTest3() {
+        assertSourceException(startsWith(
+            "Leaf '(foo)enum-leaf' has default value 'two' marked with an if-feature statement."),
+            "/rfc7950/bug6901/invalid-foo-enum-3.yang");
     }
 
     @Test
-    public void ifFeatureOnDefaultValueBitTest() throws Exception {
-        try {
-            StmtTestUtils.parseYangSource("/rfc7950/bug6901/invalid-foo-bit.yang");
-            fail("Test should fail due to invalid Yang 1.1");
-        } catch (final SomeModifiersUnresolvedException e) {
-            assertTrue(e.getCause().getMessage().startsWith(
-                    "Typedef '(foo)bits-typedef-2' has default value 'two' marked with an if-feature statement."));
-        }
+    public void ifFeatureOnDefaultValueBitTest() {
+        assertSourceException(
+            startsWith("Typedef '(foo)bits-typedef-2' has default value 'two' marked with an if-feature statement."),
+            "/rfc7950/bug6901/invalid-foo-bit.yang");
     }
 
     @Test
-    public void ifFeatureOnDefaultValueUnionTest() throws Exception {
-        try {
-            StmtTestUtils.parseYangSource("/rfc7950/bug6901/invalid-foo-union.yang");
-            fail("Test should fail due to invalid Yang 1.1");
-        } catch (final SomeModifiersUnresolvedException e) {
-            assertTrue(e.getCause().getMessage().startsWith(
-                    "Leaf '(foo)union-leaf' has default value 'two' marked with an if-feature statement."));
-        }
+    public void ifFeatureOnDefaultValueUnionTest() {
+        assertSourceException(
+            startsWith("Leaf '(foo)union-leaf' has default value 'two' marked with an if-feature statement."),
+            "/rfc7950/bug6901/invalid-foo-union.yang");
     }
 
     @Test
-    public void unsupportedFeatureTest() throws Exception {
-        try {
-            StmtTestUtils.parseYangSource("/rfc7950/bug6901/invalid-foo-enum.yang");
-            fail("Test should fail due to invalid Yang 1.1");
-        } catch (final SomeModifiersUnresolvedException e) {
-            assertTrue(
-                    e.getCause().getMessage().contains("has default value 'two' marked with an if-feature statement"));
-        }
+    public void unsupportedFeatureTest() {
+        assertSourceException(containsString("has default value 'two' marked with an if-feature statement"),
+            "/rfc7950/bug6901/invalid-foo-enum.yang");
     }
 
     @Test
-    public void ifFeature10EnumTest() throws Exception {
-        try {
-            StmtTestUtils.parseYangSource("/rfc7950/bug6901/invalid-foo-10-enum.yang");
-            fail("Test should fail due to invalid Yang 1.0");
-        } catch (final SomeModifiersUnresolvedException e) {
-            assertTrue(e.getCause().getMessage().startsWith("IF_FEATURE is not valid for ENUM"));
-        }
+    public void ifFeature10EnumTest() {
+        assertInvalidSubstatementException(startsWith("IF_FEATURE is not valid for ENUM"),
+            "/rfc7950/bug6901/invalid-foo-10-enum.yang");
     }
 
     @Test
-    public void ifFeature10BitTest() throws Exception {
-        try {
-            StmtTestUtils.parseYangSource("/rfc7950/bug6901/invalid-foo-10-bit.yang");
-            fail("Test should fail due to invalid Yang 1.0");
-        } catch (final SomeModifiersUnresolvedException e) {
-            assertTrue(e.getCause().getMessage().startsWith("IF_FEATURE is not valid for BIT"));
-        }
+    public void ifFeature10BitTest() {
+        assertInvalidSubstatementException(startsWith("IF_FEATURE is not valid for BIT"),
+            "/rfc7950/bug6901/invalid-foo-10-bit.yang");
     }
 }
index 8d6527c692f9284f847f3ab21a027b44aaf41eec..72872fd8159462f8443fb4bcecd05ebe67f55f91 100644 (file)
@@ -21,7 +21,7 @@ import org.opendaylight.yangtools.yang.model.api.Module;
 /**
  * Abstract base class for tests of the model context available in {@code src/test/resources/model}.
  */
-public abstract class AbstractModelTest {
+public abstract class AbstractModelTest extends AbstractYangTest {
     private static final QNameModule FOO_NS =
         QNameModule.create(XMLNamespace.of("urn:opendaylight.foo"), Revision.of("2013-02-27"));
     private static final QNameModule BAR_NS =
@@ -36,7 +36,7 @@ public abstract class AbstractModelTest {
 
     @BeforeClass
     public static void beforeClass() throws Exception {
-        CTX = TestUtils.loadModules("/model");
+        CTX = assertEffectiveModelDir("/model");
         assertEquals(3, CTX.getModules().size());
 
         FOO = CTX.findModules("foo").iterator().next();
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
new file mode 100644 (file)
index 0000000..64e7a98
--- /dev/null
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.stmt;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+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 org.eclipse.jdt.annotation.NonNull;
+import org.hamcrest.Matcher;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+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;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+
+/**
+ * Abstract base class containing useful utilities and assertions.
+ */
+public abstract class AbstractYangTest {
+    public static @NonNull EffectiveModelContext assertEffectiveModel(final String... yangResourceName)
+            throws Exception {
+        final var ret = TestUtils.parseYangSource(yangResourceName);
+        assertNotNull(ret);
+        return ret;
+    }
+
+    public static @NonNull EffectiveModelContext assertEffectiveModelDir(final String resourceDirName)
+            throws Exception {
+        final var ret =  TestUtils.loadModules(resourceDirName);
+        assertNotNull(ret);
+        return ret;
+    }
+
+    public static <E extends SourceException> @NonNull E assertException(final Class<E> cause,
+            final String... yangResourceName) {
+        final var ex = assertThrows(SomeModifiersUnresolvedException.class,
+            () -> TestUtils.parseYangSource(yangResourceName));
+        final var actual = ex.getCause();
+        assertThat(actual, instanceOf(cause));
+        return cause.cast(actual);
+    }
+
+    public static <E extends SourceException> @NonNull E assertException(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,
+            () -> TestUtils.loadModules(yangResourceName));
+        final var actual = ex.getCause();
+        assertThat(actual, instanceOf(cause));
+        return cause.cast(actual);
+    }
+
+    public static <E extends SourceException> @NonNull E assertExceptionDir(final String yangResourceName,
+            final Class<E> cause, final Matcher<String> matcher) {
+        final var ret = assertExceptionDir(yangResourceName, cause);
+        assertThat(ret.getMessage(), matcher);
+        return ret;
+    }
+
+    public static @NonNull InferenceException assertInferenceException(final Matcher<String> matcher,
+            final String... yangResourceName) {
+        return assertException(InferenceException.class, matcher, yangResourceName);
+    }
+
+    public static @NonNull InferenceException assertInferenceExceptionDir(final String yangResourceName,
+            final Matcher<String> matcher) {
+        return assertExceptionDir(yangResourceName, InferenceException.class, matcher);
+    }
+
+    public static @NonNull InvalidSubstatementException assertInvalidSubstatementException(
+            final Matcher<String> matcher, final String... yangResourceName) {
+        return assertException(InvalidSubstatementException.class, matcher, yangResourceName);
+    }
+
+    public static @NonNull InvalidSubstatementException assertInvalidSubstatementExceptionDir(
+            final String yangResourceName, final Matcher<String> matcher) {
+        return assertExceptionDir(yangResourceName, InvalidSubstatementException.class, matcher);
+    }
+
+    public static @NonNull SourceException assertSourceException(final Matcher<String> matcher,
+            final String... yangResourceName) {
+        final var ret = assertException(SourceException.class, matcher, yangResourceName);
+        // SourceException is the base of the hierarchy, we should normally assert subclasses
+        assertEquals(SourceException.class, ret.getClass());
+        return ret;
+    }
+
+    public static @NonNull SourceException assertSourceExceptionDir(final String yangResourceName,
+            final Matcher<String> matcher) {
+        final var ret = assertExceptionDir(yangResourceName, SourceException.class, matcher);
+        // SourceException is the base of the hierarchy, we should normally assert subclasses
+        assertEquals(SourceException.class, ret.getClass());
+        return ret;
+    }
+}
index 16f4e438b190271fdf31b7e84a7c2b859e8cf5d8..b2a54ba4877ec26d4ad4b24963326484dc30f77b 100644 (file)
@@ -34,7 +34,7 @@ import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
 import org.opendaylight.yangtools.yang.model.api.type.TypeDefinitions;
 
-public class AugmentTest {
+public class AugmentTest extends AbstractYangTest {
     private static final QNameModule FOO = QNameModule.create(
         XMLNamespace.of("urn:opendaylight.foo"), Revision.of("2013-10-13"));
     private static final QNameModule BAR = QNameModule.create(
@@ -50,7 +50,7 @@ public class AugmentTest {
 
     @BeforeClass
     public static void beforeClass() throws Exception {
-        AUGMENT_IN_AUGMENT = TestUtils.loadModules("/augment-test/augment-in-augment");
+        AUGMENT_IN_AUGMENT = assertEffectiveModelDir("/augment-test/augment-in-augment");
     }
 
     @Test
@@ -255,7 +255,7 @@ public class AugmentTest {
 
     @Test
     public void testAugmentRpc() throws Exception {
-        final EffectiveModelContext context = TestUtils.loadModules("/augment-test/rpc");
+        final EffectiveModelContext context = assertEffectiveModelDir("/augment-test/rpc");
         final XMLNamespace NS_BAR = XMLNamespace.of("urn:opendaylight:bar");
         final XMLNamespace NS_FOO = XMLNamespace.of("urn:opendaylight:foo");
         final Revision revision = Revision.of("2013-10-11");
@@ -323,7 +323,7 @@ public class AugmentTest {
 
     @Test
     public void testAugmentInUsesResolving() throws Exception {
-        final EffectiveModelContext context = TestUtils.loadModules("/augment-test/augment-in-uses");
+        final EffectiveModelContext context = assertEffectiveModelDir("/augment-test/augment-in-uses");
         assertEquals(1, context.getModules().size());
 
         final Module test = context.getModules().iterator().next();
index 2f45aae367003aef36f00b28d7256ca3eab72e0f..bf8edd5e59426a7eaa0d349e40e2438b73938f69 100644 (file)
@@ -10,7 +10,6 @@ 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;
@@ -20,18 +19,13 @@ import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.UsesNode;
 import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
-import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
 
-public class AugmentToExtensionTest {
+public class AugmentToExtensionTest extends AbstractYangTest {
     @Test
     public void testIncorrectPath() throws Exception {
-        final var ex = assertThrows(SomeModifiersUnresolvedException.class,
-            () -> TestUtils.loadModules("/augment-to-extension-test/incorrect-path"));
-        final var cause = ex.getCause();
-
-        // FIXME: this should not be here
-        assertThat(cause, instanceOf(InferenceException.class));
-        assertThat(cause.getMessage(), startsWith("Yang model processing phase EFFECTIVE_MODEL failed [at "));
+        // FIXME: this should not be here, or why do we need encapsulation? Add asserts for that
+        final var cause = assertInferenceExceptionDir("/augment-to-extension-test/incorrect-path",
+            startsWith("Yang model processing phase EFFECTIVE_MODEL failed [at "));
 
         final var firstCause = cause.getCause();
         assertThat(firstCause, instanceOf(InferenceException.class));
@@ -46,7 +40,7 @@ public class AugmentToExtensionTest {
     @Test
     public void testCorrectPathIntoUnsupportedTarget() throws Exception {
         final Module devicesModule =
-            TestUtils.loadModules("/augment-to-extension-test/correct-path-into-unsupported-target")
+            assertEffectiveModelDir("/augment-to-extension-test/correct-path-into-unsupported-target")
             .findModules("augment-module").iterator().next();
         final ContainerSchemaNode devicesContainer = (ContainerSchemaNode) devicesModule.getDataChildByName(
             QName.create(devicesModule.getQNameModule(), "my-container"));
@@ -57,7 +51,7 @@ public class AugmentToExtensionTest {
 
     @Test
     public void testCorrectAugment() throws Exception {
-        final Module devicesModule = TestUtils.loadModules("/augment-to-extension-test/correct-augment")
+        final Module devicesModule = assertEffectiveModelDir("/augment-to-extension-test/correct-augment")
             .findModules("augment-module").iterator().next();
 
         final ContainerSchemaNode devicesContainer = (ContainerSchemaNode) devicesModule.getDataChildByName(QName
index 6a872ae0c2a1a3961175371b44db34860a0480b2..5911ea0ba9f3df2c3f0816b8c16eafd5b2715d68 100644 (file)
@@ -27,11 +27,10 @@ import org.opendaylight.yangtools.yang.model.api.stmt.UnrecognizedStatement;
  * <p>
  * Note: Everything under unknown node is unknown node.
  */
-public class Bug1412Test {
-
+public class Bug1412Test extends AbstractYangTest {
     @Test
     public void test() throws Exception {
-        final Module bug1412 = TestUtils.loadModules("/bugs/bug1412").findModules("bug1412").iterator().next();
+        final Module bug1412 = assertEffectiveModelDir("/bugs/bug1412").findModules("bug1412").iterator().next();
 
         final ContainerSchemaNode node = (ContainerSchemaNode) bug1412.getDataChildByName(QName.create(
                 bug1412.getQNameModule(), "node"));
@@ -41,8 +40,8 @@ public class Bug1412Test {
         final UnrecognizedStatement action = unknownNodes.iterator().next();
 
         final QNameModule qm = QNameModule.create(XMLNamespace.of("urn:test:bug1412"), Revision.of("2014-07-25"));
-        QName expectedNodeType = QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "action");
-        assertEquals(expectedNodeType, action.statementDefinition().getStatementName());
+        assertEquals(QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "action"),
+            action.statementDefinition().getStatementName());
         assertEquals("hello", action.argument());
 
         unknownNodes = action.declaredSubstatements(UnrecognizedStatement.class);
@@ -65,24 +64,23 @@ public class Bug1412Test {
         }
 
         assertNotNull(info);
-        assertNotNull(description);
-        assertNotNull(actionPoint);
-        assertNotNull(output);
-
-        expectedNodeType = QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "info");
-        assertEquals(expectedNodeType, info.statementDefinition().getStatementName());
+        assertEquals(QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "info"),
+            info.statementDefinition().getStatementName());
         assertEquals("greeting", info.argument());
 
-        expectedNodeType = QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "description");
-        assertEquals(expectedNodeType, description.statementDefinition().getStatementName());
+        assertNotNull(description);
+        assertEquals(QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "description"),
+            description.statementDefinition().getStatementName());
         assertEquals("say greeting", description.argument());
 
-        expectedNodeType = QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "actionpoint");
-        assertEquals(expectedNodeType, actionPoint.statementDefinition().getStatementName());
+        assertNotNull(actionPoint);
+        assertEquals(QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "actionpoint"),
+            actionPoint.statementDefinition().getStatementName());
         assertEquals("entry", actionPoint.argument());
 
-        expectedNodeType = QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "output");
-        assertEquals(expectedNodeType, output.statementDefinition().getStatementName());
+        assertNotNull(output);
+        assertEquals(QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "output"),
+            output.statementDefinition().getStatementName());
         assertEquals(Empty.getInstance(), output.argument());
     }
 }
index 2318eb4c5ef7542659472af55ff7e294ad80a41a..8bc384e0718e999e87c43eb062333af75c7562bd 100644 (file)
@@ -20,10 +20,10 @@ import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
  * <p>
  * Note: Everything under unknown node is unknown node.
  */
-public class Bug1413Test {
+public class Bug1413Test extends AbstractYangTest {
     @Test
     public void test() throws Exception {
-        var extensions = TestUtils.loadModules("/bugs/bug1413").findModules("bug1413").iterator().next()
+        var extensions = assertEffectiveModelDir("/bugs/bug1413").findModules("bug1413").iterator().next()
             .getExtensionSchemaNodes();
         assertEquals(1, extensions.size());
 
index d42755970ed37e885db64a85f73aba4a8c8c81d4..f5ca2985aaff826602ff7ecc9114522cd10ebdfb 100644 (file)
@@ -11,9 +11,9 @@ import static org.junit.Assert.assertEquals;
 
 import org.junit.Test;
 
-public class Bug3859Test {
+public class Bug3859Test extends AbstractYangTest {
     @Test
     public void test() throws Exception {
-        assertEquals(1, TestUtils.loadModules("/bugs/bug3859").findModules("reference-in-unknown").size());
+        assertEquals(1, assertEffectiveModelDir("/bugs/bug3859").findModules("reference-in-unknown").size());
     }
 }
index bda951ba7308a6bb590f7cdef8daf4d939a81af0..e18a0ba3b237492649801c98336332ee2698f0e6 100644 (file)
@@ -26,10 +26,10 @@ import org.opendaylight.yangtools.yang.model.api.stmt.UnrecognizedStatement;
 /**
  * Test antlr grammar capability to parse nested unknown nodes.
  */
-public class Bug394Test {
+public class Bug394Test extends AbstractYangTest {
     @Test
     public void testParseList() throws Exception {
-        final EffectiveModelContext context = TestUtils.loadModules("/bugs/bug394-retest");
+        final EffectiveModelContext context = assertEffectiveModelDir("/bugs/bug394-retest");
         final Module bug394 = context.findModules("bug394").iterator().next();
         final Module bug394_ext = context.findModules("bug394-ext").iterator().next();
 
index 9c2c8fcab1521a9f26a8204d946fb14fd4918482..ef661b8a4caac9ce67c773831cd04d95595c312b 100644 (file)
@@ -27,13 +27,13 @@ import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
 import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
 import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
 
-public class Bug4623Test {
+public class Bug4623Test extends AbstractYangTest {
     private static Module TYPES;
 
     @BeforeClass
     public static void beforeClass() throws Exception {
         // given
-        TYPES = TestUtils.loadModules("/bugs/bug4623").findModules("types").iterator().next();
+        TYPES = assertEffectiveModelDir("/bugs/bug4623").findModules("types").iterator().next();
     }
 
     @Test
@@ -103,8 +103,6 @@ public class Bug4623Test {
                 QName.create(XMLNamespace.of("urn:custom.types.demo"), "leaf-unknown-length-pattern"));
 
         // then
-        assertNotNull(leaf);
-
         final TypeDefinition<?> type = leaf.getType();
         assertNotNull(type);
         assertEquals(0, type.getUnknownSchemaNodes().size());
@@ -112,17 +110,14 @@ public class Bug4623Test {
 
         final LengthConstraint lengthConstraints =
                 ((StringTypeDefinition) type).getLengthConstraint().get();
-        final List<PatternConstraint> patternConstraints = ((StringTypeDefinition) type).getPatternConstraints();
-
-        assertNotNull(lengthConstraints);
-        assertNotNull(patternConstraints);
         assertEquals(1, lengthConstraints.getAllowedRanges().asRanges().size());
-        assertFalse(patternConstraints.size() == 0);
 
         final Range<Integer> lengthConstraint = lengthConstraints.getAllowedRanges().span();
         assertEquals(Integer.valueOf(2), lengthConstraint.lowerEndpoint());
         assertEquals(Integer.valueOf(10), lengthConstraint.upperEndpoint());
 
+        final List<PatternConstraint> patternConstraints = ((StringTypeDefinition) type).getPatternConstraints();
+        assertEquals(1, patternConstraints.size());
         final PatternConstraint patternConstraint = patternConstraints.get(0);
         assertEquals(patternConstraint.getRegularExpressionString(), "[0-9a-fA-F]");
     }
index e915511a1bef9576ff671afb0f938b480e8a4ccc..e7b693a3dbad08af7a364508fa6ad3af5dd19fb1 100644 (file)
@@ -28,7 +28,7 @@ public class Bug6771Test {
 
     @Test
     public void augmentTest() throws Exception {
-        final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/bug6771/augment.yang")
+        final ModuleEffectiveStatement module = TestUtils.parseYangSource("/bugs/bug6771/augment.yang")
             .getModuleStatement(NS);
 
         verifyLeafType(module, ROOT, CONT_B, LEAF_CONT_B);
@@ -37,7 +37,7 @@ public class Bug6771Test {
 
     @Test
     public void choiceCaseTest() throws Exception {
-        final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/bug6771/choice-case.yang")
+        final ModuleEffectiveStatement module = TestUtils.parseYangSource("/bugs/bug6771/choice-case.yang")
             .getModuleStatement(NS);
 
         final QName myChoice = QName.create(NS, "my-choice");
@@ -55,7 +55,7 @@ public class Bug6771Test {
 
     @Test
     public void groupingTest() throws Exception {
-        verifyLeafType(StmtTestUtils.parseYangSource("/bugs/bug6771/grouping.yang").getModuleStatement(NS),
+        verifyLeafType(TestUtils.parseYangSource("/bugs/bug6771/grouping.yang").getModuleStatement(NS),
             ROOT, CONT_B, LEAF_CONT_B);
     }
 
index 9ed0e4e02eb60ea746afad7b1532021846258b2c..3fe7fa38598f1b0bbada4934723de34921904b42 100644 (file)
@@ -18,10 +18,10 @@ import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.stmt.UnrecognizedStatement;
 
-public class Bug7865Test {
+public class Bug7865Test extends AbstractYangTest {
     @Test
     public void test() throws Exception {
-        final EffectiveModelContext context = TestUtils.loadModules("/bugs/bug7865");
+        final EffectiveModelContext context = assertEffectiveModelDir("/bugs/bug7865");
         final DataSchemaNode root = context.getDataChildByName(foo("root"));
         assertTrue(root instanceof ContainerSchemaNode);
         final Collection<? extends UnrecognizedStatement> unknownSchemaNodes = ((ContainerSchemaNode) root)
index 98d187645d961c785c7da6ca8655fb5a9bd5c8d9..c01a680baf5ee9de7e46ed05476209926d36293d 100644 (file)
@@ -20,25 +20,25 @@ import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement;
 
-public class Bug7879Test {
+public class Bug7879Test extends AbstractYangTest {
     private static final XMLNamespace NS = XMLNamespace.of("my-model-ns");
 
     @Test
     public void test() throws Exception {
-        final ModuleEffectiveStatement module = TestUtils.loadModules("/bugs/bug7879")
-            .getModuleStatement(QName.create(NS, "my-model"));
+        final ModuleEffectiveStatement module = assertEffectiveModelDir("/bugs/bug7879")
+            .getModuleStatement(qn("my-model"));
 
         final SchemaTreeEffectiveStatement<?> container = module.findSchemaTreeNode(
-            qN("my-alarm"), qN("my-content"), qN("my-event-container")).orElse(null);
+            qn("my-alarm"), qn("my-content"), qn("my-event-container")).orElse(null);
         assertThat(container, instanceOf(ContainerSchemaNode.class));
 
         final SchemaTreeEffectiveStatement<?> leaf = module.findSchemaTreeNode(
-            qN("my-alarm"), qN("my-content"), qN("my-event-value")).orElse(null);
+            qn("my-alarm"), qn("my-content"), qn("my-event-value")).orElse(null);
         assertThat(leaf, instanceOf(LeafSchemaNode.class));
         assertEquals(Optional.of("new description"), ((LeafSchemaNode) leaf).getDescription());
     }
 
-    private static QName qN(final String localName) {
+    private static QName qn(final String localName) {
         return QName.create(NS, localName);
     }
 }
index fd513b5b181955061ec26129e3ef2513ecad756e..3e63fdaf6750752857f175f5dfa57a5dd94df6cf 100644 (file)
@@ -8,36 +8,24 @@
 package org.opendaylight.yangtools.yang.stmt;
 
 import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThrows;
 
 import org.junit.Test;
-import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 
-public class Bug8831Test {
+public class Bug8831Test extends AbstractYangTest {
     @Test
     public void test() throws Exception {
-        assertNotNull(TestUtils.loadModules("/bugs/bug8831/valid"));
+        assertEffectiveModelDir("/bugs/bug8831/valid");
     }
 
     @Test
     public void invalidModelsTest() {
-        final var ex = assertThrows(SomeModifiersUnresolvedException.class,
-            () -> TestUtils.parseYangSource("/bugs/bug8831/invalid/inv-model.yang"));
-        final var cause = ex.getCause();
-        assertThat(cause, instanceOf(SourceException.class));
-        assertThat(cause.getMessage(), containsString("has default value 'any' marked with an if-feature statement"));
+        assertSourceException(containsString("has default value 'any' marked with an if-feature statement"),
+            "/bugs/bug8831/invalid/inv-model.yang");
     }
 
     @Test
     public void invalidModelsTest2() {
-        final var ex = assertThrows(SomeModifiersUnresolvedException.class,
-            () -> TestUtils.parseYangSource("/bugs/bug8831/invalid/inv-model2.yang"));
-        final var cause = ex.getCause();
-        assertThat(cause, instanceOf(SourceException.class));
-        assertThat(cause.getMessage(), containsString("has default value 'any' marked with an if-feature statement"));
+        assertSourceException(containsString("has default value 'any' marked with an if-feature statement"),
+            "/bugs/bug8831/invalid/inv-model2.yang");
     }
 }
index ecf521376f4d617d48c2a118516f0e15efd6c834..548dd417c2ba2f0f91b218ad9b4b6b0db709cc8b 100644 (file)
@@ -491,7 +491,7 @@ public class GroupingTest extends AbstractModelTest {
 
     @Test
     public void testAddedByUsesLeafTypeQName() throws Exception {
-        final EffectiveModelContext loadModules = TestUtils.loadModules("/added-by-uses-leaf-test");
+        final EffectiveModelContext loadModules = assertEffectiveModelDir("/added-by-uses-leaf-test");
         assertEquals(2, loadModules.getModules().size());
 
         final Module foo = Iterables.getOnlyElement(loadModules.findModules("foo"));
index 43e96ba619899b8ef4447f18c3908028deae3f42..dbd7816dc4fee38296be644d1b7848304159ea53 100644 (file)
@@ -19,13 +19,13 @@ import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 public class ListKeysTest {
     @Test
     public void correctListKeysTest() throws Exception {
-        StmtTestUtils.parseYangSource("/list-keys-test/correct-list-keys-test.yang");
+        TestUtils.parseYangSource("/list-keys-test/correct-list-keys-test.yang");
     }
 
     @Test
     public void incorrectListKeysTest1() {
         final ReactorException ex = assertThrows(ReactorException.class,
-            () -> StmtTestUtils.parseYangSource("/list-keys-test/incorrect-list-keys-test.yang"));
+            () -> TestUtils.parseYangSource("/list-keys-test/incorrect-list-keys-test.yang"));
         final Throwable cause = ex.getCause();
         assertThat(cause, instanceOf(SourceException.class));
         assertThat(cause.getMessage(), startsWith("Key 'test1_key1 test1_key2' misses node 'test1_key2'"));
@@ -34,7 +34,7 @@ public class ListKeysTest {
     @Test
     public void incorrectListKeysTest2() {
         final ReactorException ex = assertThrows(ReactorException.class,
-            () -> StmtTestUtils.parseYangSource("/list-keys-test/incorrect-list-keys-test2.yang"));
+            () -> TestUtils.parseYangSource("/list-keys-test/incorrect-list-keys-test2.yang"));
         final Throwable cause = ex.getCause();
         assertThat(cause, instanceOf(SourceException.class));
         assertThat(cause.getMessage(), startsWith("Key 'test1_key1 test1_key2' misses node 'test1_key2'"));
@@ -43,7 +43,7 @@ public class ListKeysTest {
     @Test
     public void incorrectListKeysTest3() {
         final ReactorException ex = assertThrows(ReactorException.class,
-            () -> StmtTestUtils.parseYangSource("/list-keys-test/incorrect-list-keys-test3.yang"));
+            () -> TestUtils.parseYangSource("/list-keys-test/incorrect-list-keys-test3.yang"));
         final Throwable cause = ex.getCause();
         assertThat(cause, instanceOf(SourceException.class));
         assertThat(cause.getMessage(), startsWith("Key 'grp_list' misses node 'grp_list'"));
@@ -52,7 +52,7 @@ public class ListKeysTest {
     @Test
     public void incorrectListKeysTest4()  {
         final ReactorException ex = assertThrows(ReactorException.class,
-            () -> StmtTestUtils.parseYangSource("/list-keys-test/incorrect-list-keys-test4.yang"));
+            () -> TestUtils.parseYangSource("/list-keys-test/incorrect-list-keys-test4.yang"));
         final Throwable cause = ex.getCause();
         assertThat(cause, instanceOf(SourceException.class));
         assertThat(cause.getMessage(), startsWith("Key 'grp_leaf' misses node 'grp_leaf'"));
index 6508e62038322e0e15e432652e7303a49843207d..a6541396aea9b4069bcec90f1fc9329be1a00369 100644 (file)
@@ -7,24 +7,16 @@
  */
 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.SomeModifiersUnresolvedException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 
 /**
  * Test for testing of extensions and their arguments.
  */
-public class ParsingExtensionValueTest {
+public class ParsingExtensionValueTest extends AbstractYangTest {
     @Test
     public void extensionTest() {
-        final var ex = assertThrows(SomeModifiersUnresolvedException.class, () -> TestUtils.loadModules("/extensions"));
-        final var cause = ex.getCause();
-        assertThat(cause, instanceOf(SourceException.class));
-        assertThat(cause.getMessage(), startsWith("ext:id is not a YANG statement or use of extension"));
+        assertSourceExceptionDir("/extensions", startsWith("ext:id is not a YANG statement or use of extension"));
     }
 }
index 4d4d046d5e1c3d8844876e637645c0061c47c1ab..1a6ddb260ad694b3eb56ba8a78431a96319a5175 100644 (file)
@@ -84,6 +84,8 @@ public final class StmtTestUtils {
         }
     }
 
+    @Deprecated(forRemoval = true)
+    // TestUtils.parseYangSource() instead, but callers need also further cleanup
     public static EffectiveModelContext parseYangSource(final String yangSourcePath) throws ReactorException,
             URISyntaxException, IOException, YangSyntaxErrorException {
         return parseYangSource(yangSourcePath, YangParserConfiguration.DEFAULT, null);
index 9b5f9215fc03f5e27d759c6ee71946cda3d2ce34..7969cc8a163719cdefe0d4898b78e92015bd1445 100644 (file)
@@ -7,66 +7,48 @@
  */
 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.assertEquals;
-import static org.junit.Assert.assertThrows;
 
 import org.junit.Test;
-import org.opendaylight.yangtools.yang.parser.spi.meta.InvalidSubstatementException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.MissingSubstatementException;
-import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 
-public class SubstatementValidatorTest {
+public class SubstatementValidatorTest extends AbstractYangTest {
     @Test
     public void noException() throws Exception {
-        assertEquals(3, TestUtils.loadModules("/augment-test/augment-in-augment").getModules().size());
+        assertEquals(3, assertEffectiveModelDir("/augment-test/augment-in-augment").getModules().size());
     }
 
     @Test
     public void undesirableElementException() throws Exception {
-        final var ex = assertThrows(SomeModifiersUnresolvedException.class,
-            () -> TestUtils.loadModules("/substatement-validator/undesirable-element"));
-        final var cause = ex.getCause();
-        assertThat(cause, instanceOf(InvalidSubstatementException.class));
-        assertThat(cause.getMessage(), startsWith("TYPE is not valid for REVISION. Error in module undesirable "
-            + "(QNameModule{ns=urn:opendaylight.undesirable, rev=2015-11-11}) [at "));
+        assertInvalidSubstatementExceptionDir("/substatement-validator/undesirable-element",
+            startsWith("TYPE is not valid for REVISION. Error in module undesirable "
+                + "(QNameModule{ns=urn:opendaylight.undesirable, rev=2015-11-11}) [at "));
     }
 
     @Test
     public void maximalElementCountException() throws Exception {
-        final var ex = assertThrows(SomeModifiersUnresolvedException.class,
-            () -> TestUtils.loadModules("/substatement-validator/maximal-element"));
-        final var cause = ex.getCause();
-        assertThat(cause, instanceOf(InvalidSubstatementException.class));
-        assertThat(cause.getMessage(), startsWith("Maximal count of DESCRIPTION for AUGMENT is 1, detected 2. Error in "
-            + "module baz (QNameModule{ns=urn:opendaylight.baz, rev=2015-11-11}) [at "));
+        assertInvalidSubstatementExceptionDir("/substatement-validator/maximal-element",
+            startsWith("Maximal count of DESCRIPTION for AUGMENT is 1, detected 2. Error in module baz "
+                + "(QNameModule{ns=urn:opendaylight.baz, rev=2015-11-11}) [at "));
     }
 
     @Test
     public void missingElementException() {
-        final var ex = assertThrows(SomeModifiersUnresolvedException.class,
-            () -> TestUtils.loadModules("/substatement-validator/missing-element"));
-        final var cause = ex.getCause();
         // FIXME: should be MissingSubstatementException?
-        assertThat(cause, instanceOf(SourceException.class));
-        assertThat(cause.getMessage(), startsWith("Missing prefix statement [at "));
+        assertSourceExceptionDir("/substatement-validator/missing-element",
+            startsWith("Missing prefix statement [at "));
     }
 
     @Test
     public void bug6173Test() throws Exception {
-        assertEquals(1, TestUtils.loadModules("/substatement-validator/empty-element").getModules().size());
+        assertEquals(1, assertEffectiveModelDir("/substatement-validator/empty-element").getModules().size());
     }
 
     @Test
     public void bug4310test() throws Exception {
-        final var ex = assertThrows(SomeModifiersUnresolvedException.class,
-            () -> TestUtils.loadModules("/substatement-validator/bug-4310"));
-        final var cause = ex.getCause();
-        assertThat(cause, instanceOf(MissingSubstatementException.class));
-        assertThat(cause.getMessage(), startsWith("TYPE is missing TYPE. Minimal count is 1. Error in module bug4310 "
-            + "(QNameModule{ns=urn:opendaylight.bug4310}) [at "));
+        assertExceptionDir("/substatement-validator/bug-4310", MissingSubstatementException.class,
+            startsWith("TYPE is missing TYPE. Minimal count is 1. Error in module bug4310 "
+                + "(QNameModule{ns=urn:opendaylight.bug4310}) [at "));
     }
 }
index 8046fec2658dfe143829d7a6a596db528deea7da..7e5ff6e24de0e3d3682dbaa9e3244a87749e5fec 100644 (file)
@@ -14,10 +14,10 @@ import static org.junit.Assert.assertTrue;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.Revision;
 
-public class TwoRevisionsTest {
+public class TwoRevisionsTest extends AbstractYangTest {
     @Test
     public void testTwoRevisions() throws Exception {
-        var it = TestUtils.loadModules("/ietf").findModuleStatements("network-topology").iterator();
+        var it = assertEffectiveModelDir("/ietf").findModuleStatements("network-topology").iterator();
         assertTrue(it.hasNext());
         assertEquals(Revision.ofNullable("2013-10-21"), it.next().localQNameModule().getRevision());
         assertTrue(it.hasNext());
index 4169541241f24e7cece0ed598dc7856620ce1fa4..70467aa67e13cc6019568fc7aaaac999648ccc89 100644 (file)
@@ -22,27 +22,27 @@ import org.opendaylight.yangtools.yang.common.XMLNamespace;
 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.Uint8TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
 import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes;
 
-public class UsesAugmentTest {
+public class UsesAugmentTest extends AbstractYangTest {
     private static final QNameModule UG = QNameModule.create(
         XMLNamespace.of("urn:opendaylight:params:xml:ns:yang:uses-grouping"), Revision.of("2013-07-30"));
     private static final QNameModule GD = QNameModule.create(
         XMLNamespace.of("urn:opendaylight:params:xml:ns:yang:grouping-definitions"), Revision.of("2013-09-04"));
 
-    private static SchemaContext CONTEXT;
+    private static EffectiveModelContext CONTEXT;
 
     @BeforeClass
     public static void beforeClass() throws Exception {
-        CONTEXT = TestUtils.loadModules("/grouping-test");
+        CONTEXT = assertEffectiveModelDir("/grouping-test");
     }
 
     /*
index 119ab35e0a099c24e765fa2d24886f6782897567..d431e541f6471a770ebad8c1d0e3ba412ebb9eaf 100644 (file)
@@ -28,30 +28,26 @@ import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.MustDefinition;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.Status;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.UsesNode;
 
-public class YangParserSimpleTest {
+public class YangParserSimpleTest extends AbstractYangTest {
     private static final XMLNamespace NS = XMLNamespace.of("urn:opendaylight:simple-nodes");
     private static final QNameModule SN = QNameModule.create(NS, Revision.of("2013-07-30"));
     private static final QName SN_NODES = QName.create(SN, "nodes");
 
-    private static SchemaContext CONTEXT;
     private static Module MODULE;
 
     @BeforeClass
     public static void beforeClass() throws Exception {
-        CONTEXT = TestUtils.loadModules("/simple-test");
-        MODULE = CONTEXT.findModules("simple-nodes").iterator().next();
+        MODULE = assertEffectiveModelDir("/simple-test").findModules("simple-nodes").iterator().next();
     }
 
     @Test
     public void testParseAnyXml() {
         final AnyxmlSchemaNode data = (AnyxmlSchemaNode) MODULE.getDataChildByName(
             QName.create(MODULE.getQNameModule(), "data"));
-        assertNotNull("'anyxml data not found'", data);
         assertFalse(data.equals(null));
         assertEquals("RegularAnyxmlEffectiveStatement{qname=(urn:opendaylight:simple-nodes?revision=2013-07-30)data}",
                 data.toString());