Workaround test model loading issues 44/93244/3
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 21 Oct 2020 20:59:15 +0000 (22:59 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 21 Oct 2020 23:26:35 +0000 (01:26 +0200)
Going to a JPMS module means our resources are subject to encapsulation
-- which means things like YangTextSchemaSource.forResource() actually
depend on where the resource if located.

If its location ends up being in a valid package, that request will fail,
as JRE will consider the resource encapsulated and will reject external
module's attempt to meddle with it (such as yang.model.api).

As it turns out some of models are matching this check and we load them
through such facilities. In some cases we can re-route in a way which
makes things less verbose -- and we do that in this patch.

JIRA: YANGTOOLS-1151
Change-Id: Ib55cadd9eba840980eeba3b9004d8f9c4101e33d
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5693Test.java
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/ChoiceStmtTest.java
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/StmtTestUtils.java

index 292a6c753bfaa544fa381f3c5b69962087361b44..509bb38151df35e3343652d5b4f568a6ffd0abaf 100644 (file)
@@ -5,17 +5,16 @@
  * 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;
 import static org.junit.Assert.assertNotNull;
 
 import java.io.IOException;
+import java.net.URISyntaxException;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.repo.api.YinTextSchemaSource;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 import org.xml.sax.SAXException;
 
@@ -27,8 +26,8 @@ public class Bug5693Test {
      * Use input stream to load Yin module.
      */
     @Before
-    public void initTest() throws ReactorException, SAXException, IOException {
-        foo = TestUtils.loadYinModule(YinTextSchemaSource.forResource(getClass(), "/bugs/bug5693/foo.yin"));
+    public void initTest() throws ReactorException, SAXException, IOException, URISyntaxException {
+        foo = StmtTestUtils.parseYinSources("/bugs/bug5693").getModules().iterator().next();
     }
 
     /**
index 23d504c51ebd80f357d440ac7444b017a0708bf0..f604cc8df37ea6b1378feef6f92763a144717446 100644 (file)
@@ -9,8 +9,9 @@ package org.opendaylight.yangtools.yang.stmt;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
-import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
 
+import java.io.IOException;
+import java.net.URISyntaxException;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
@@ -18,22 +19,13 @@ import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
+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.source.StatementStreamSource;
 
 public class ChoiceStmtTest {
-
-    private static final StatementStreamSource CHOICE_MODULE = sourceForResource("/model/foo.yang");
-    private static final StatementStreamSource IMPORTED_MODULE1 = sourceForResource("/model/bar.yang");
-    private static final StatementStreamSource IMPORTED_MODULE2 = sourceForResource("/model/baz.yang");
-    private static final StatementStreamSource INCLUDED_MODULE = sourceForResource("/model/subfoo.yang");
-
     @Test
-    public void choiceAndCaseTest() throws ReactorException {
-        final SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
-                .addSources(CHOICE_MODULE, IMPORTED_MODULE1, IMPORTED_MODULE2, INCLUDED_MODULE)
-                .buildEffective();
+    public void choiceAndCaseTest() throws ReactorException, YangSyntaxErrorException, URISyntaxException, IOException {
+        final SchemaContext result = StmtTestUtils.parseYangSources("/model");
         assertNotNull(result);
 
         final Module testModule = result.findModules("foo").iterator().next();
index 13a1e12a984841f8ea055cdca5854485d35a44e1..2b619e0f32d3fbe87a1000b20f51c51704f6aee5 100644 (file)
@@ -236,6 +236,11 @@ public final class StmtTestUtils {
         return reactor.buildEffective();
     }
 
+    public static EffectiveModelContext parseYinSources(final String yinSourcesDirectoryPath)
+            throws URISyntaxException, SAXException, IOException, ReactorException {
+        return parseYinSources(yinSourcesDirectoryPath, StatementParserMode.DEFAULT_MODE);
+    }
+
     public static EffectiveModelContext parseYinSources(final String yinSourcesDirectoryPath,
             final StatementParserMode statementParserMode) throws URISyntaxException, SAXException, IOException,
             ReactorException {