Fixup resource loading in yang-parser-rfc7950 42/93242/3
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 21 Oct 2020 20:07:31 +0000 (22:07 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 21 Oct 2020 23:26:35 +0000 (01:26 +0200)
Going towards modular world requires proper context for resource
loading, as we will be on our class loader. Make sure we centralize
the policy in StmtTestUtils. This removes a bit of verbosity from
individual tests.

JIRA: YANGTOOLS-1151
Change-Id: I981245ba93826222950a764e2f9556421e90fc95
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ElementCountConstraintsTest.java
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveSchemaContextTest.java
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/OrderingTest.java
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/StmtTestUtils.java
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserIdentityTest.java
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/thirdparty/plugin/ThirdPartyExtensionPluginTest.java

index 9b2e7a912be241af53e4a5ce2407d02e39127ab5..c4c49409c0065def93486238951e98d64c0056ca 100644 (file)
@@ -13,29 +13,21 @@ import static org.junit.Assert.assertNotNull;
 
 import java.io.IOException;
 import java.net.URISyntaxException;
-import java.text.ParseException;
 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.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
-import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
-import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
 
 public class ElementCountConstraintsTest {
-
     @Test
-    public void testElementCountConstraints() throws ParseException, ReactorException, URISyntaxException, IOException,
-            YangSyntaxErrorException {
-        final SchemaContext schemaContext = RFC7950Reactors.defaultReactor().newBuild()
-                .addSource(YangStatementStreamSource.create(
-                    YangTextSchemaSource.forResource("/constraint-definitions-test/foo.yang")))
-                .buildEffective();
+    public void testElementCountConstraints()
+            throws YangSyntaxErrorException, ReactorException, URISyntaxException, IOException {
+        final var schemaContext = StmtTestUtils.parseYangSource("/constraint-definitions-test/foo.yang");
         assertNotNull(schemaContext);
 
         final Module testModule = schemaContext.findModule("foo", Revision.of("2016-09-20")).get();
index 896a37e951f2fe7f73c4d48fe312aef63675b9b1..d202952d8855a56345002b5b9af667ba1c61cae1 100644 (file)
@@ -5,7 +5,6 @@
  * 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.junit.Assert.assertEquals;
@@ -33,26 +32,20 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.api.Status;
 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
 import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
 import org.opendaylight.yangtools.yang.model.util.SimpleSchemaContext;
 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
-import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveSchemaContext;
 
 public class EffectiveSchemaContextTest {
-
     @Test
     public void testEffectiveSchemaContext() throws ReactorException, ParseException, URISyntaxException, IOException,
             YangSyntaxErrorException {
         final EffectiveSchemaContext schemaContext = RFC7950Reactors.defaultReactor().newBuild()
-                .addSource(YangStatementStreamSource.create(YangTextSchemaSource.forResource(
-                        "/effective-schema-context-test/foo.yang")))
-                .addSource(YangStatementStreamSource.create(YangTextSchemaSource.forResource(
-                        "/effective-schema-context-test/bar.yang")))
-                .addSource(YangStatementStreamSource.create(YangTextSchemaSource.forResource(
-                        "/effective-schema-context-test/baz.yang")))
-                .buildEffective();
+            .addSource(StmtTestUtils.sourceForResource("/effective-schema-context-test/foo.yang"))
+            .addSource(StmtTestUtils.sourceForResource("/effective-schema-context-test/bar.yang"))
+            .addSource(StmtTestUtils.sourceForResource("/effective-schema-context-test/baz.yang"))
+            .buildEffective();
         assertNotNull(schemaContext);
 
         final Collection<? extends DataSchemaNode> dataDefinitions = schemaContext.getDataDefinitions();
index 503c1b52a5012336afbb445cee4663da3f5c4c08..75d763a232e44b590f44ea0359f7d110176fe5fe 100644 (file)
@@ -119,8 +119,7 @@ public class OrderingTest {
 
     @Test
     public void testOrderingNestedChildNodes3() throws Exception {
-        final Module justFoo = TestUtils.loadModuleResources(getClass(), "/ordering/foo.yang")
-                .getModules().iterator().next();
+        final Module justFoo = StmtTestUtils.parseYangSource("/ordering/foo.yang").getModules().iterator().next();
         final ContainerSchemaNode x = (ContainerSchemaNode) justFoo
                 .getDataChildByName(QName.create(justFoo.getQNameModule(), "x"));
         final Collection<? extends DataSchemaNode> childNodes = x.getChildNodes();
index a4c26fb24f22bb0a17164819e88ad2fed03ec942..3c784d309e3638b4601eb392acbd355ee9518939 100644 (file)
@@ -79,7 +79,8 @@ public final class StmtTestUtils {
 
     public static StatementStreamSource sourceForResource(final String resourceName) {
         try {
-            return YangStatementStreamSource.create(YangTextSchemaSource.forResource(resourceName));
+            return YangStatementStreamSource.create(YangTextSchemaSource.forResource(
+                StmtTestUtils.class, resourceName));
         } catch (IOException | YangSyntaxErrorException e) {
             throw new IllegalArgumentException("Failed to create source", e);
         }
index 1da4672592bd885de09356c056abbb4f43ab876b..073bccfeb26a5473c1905852966b092258160e44 100644 (file)
@@ -10,22 +10,19 @@ package org.opendaylight.yangtools.yang.stmt;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotEquals;
 
-import java.io.IOException;
 import java.util.Collection;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
-import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
 
 public class YangParserIdentityTest {
 
     // base identity name equals identity name
     @Test(expected = SomeModifiersUnresolvedException.class)
-    public void testParsingIdentityTestModule() throws IOException, ReactorException, YangSyntaxErrorException {
+    public void testParsingIdentityTestModule() throws Exception {
         try {
-            TestUtils.loadModuleResources(getClass(), "/identity/identitytest.yang");
+            StmtTestUtils.parseYangSource("/identity/identitytest.yang");
         } catch (SomeModifiersUnresolvedException e) {
             StmtTestUtils.log(e, "      ");
             throw e;
@@ -34,9 +31,9 @@ public class YangParserIdentityTest {
 
     // same module prefixed base identity name equals identity name
     @Test(expected = SomeModifiersUnresolvedException.class)
-    public void testParsingPrefixIdentityTestModule() throws IOException, ReactorException, YangSyntaxErrorException  {
+    public void testParsingPrefixIdentityTestModule() throws Exception {
         try {
-            TestUtils.loadModuleResources(getClass(), "/identity/prefixidentitytest.yang");
+            StmtTestUtils.parseYangSource("/identity/prefixidentitytest.yang");
         } catch (SomeModifiersUnresolvedException e) {
             StmtTestUtils.log(e, "      ");
             throw e;
@@ -47,7 +44,7 @@ public class YangParserIdentityTest {
     // prefix differs
     @Test
     public void testParsingImportPrefixIdentityTestModule() throws Exception {
-        Module module = TestUtils.findModule(TestUtils.loadModules(getClass().getResource("/identity/import").toURI()),
+        Module module = TestUtils.findModule(StmtTestUtils.parseYangSources("/identity/import"),
             "prefiximportidentitytest").get();
         Collection<? extends ModuleImport> imports = module.getImports();
         assertEquals(imports.size(), 1);
index f82cb522cb080b6ce043f2e22b0b52bbf12cf17a..b680c3b8d38d8a5b03e99d2de55d43890fb2879f 100644 (file)
@@ -21,10 +21,9 @@ import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
 import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
-import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
+import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
 
 public class ThirdPartyExtensionPluginTest {
     private static final String NS = "urn:opendaylight:yang:extension:third-party";
@@ -33,7 +32,7 @@ public class ThirdPartyExtensionPluginTest {
     @Test
     public void test() throws URISyntaxException, ReactorException, IOException, YangSyntaxErrorException {
         final CrossSourceStatementReactor.BuildAction reactor = CustomInferencePipeline.CUSTOM_REACTOR.newBuild();
-        reactor.addSource(YangStatementStreamSource.create(YangTextSchemaSource.forResource("/plugin-test/foo.yang")));
+        reactor.addSource(StmtTestUtils.sourceForResource("/plugin-test/foo.yang"));
 
         final SchemaContext schema = reactor.buildEffective();
         final DataSchemaNode dataChildByName = schema.getDataChildByName(QName.create(NS, REV, "root"));