Change StmtTestUtils.sourceForResource() 43/93243/2
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 21 Oct 2020 21:14:06 +0000 (23:14 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 21 Oct 2020 23:26:35 +0000 (01:26 +0200)
We have a number of test resources which are considered in JPMS
world -- and hence we cannot rely on utilities to load them, as
those utilities are not authorized to use them.

Since we do not want to update massive amounts of tests, just change
how we load resources -- go through Class.getResource() and turn
that into a File and use that. That way StmtTestUtils is the caller
and it is inside our module and is allowed to do that.

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

index 3c784d309e3638b4601eb392acbd355ee9518939..13a1e12a984841f8ea055cdca5854485d35a44e1 100644 (file)
@@ -79,9 +79,9 @@ public final class StmtTestUtils {
 
     public static StatementStreamSource sourceForResource(final String resourceName) {
         try {
-            return YangStatementStreamSource.create(YangTextSchemaSource.forResource(
-                StmtTestUtils.class, resourceName));
-        } catch (IOException | YangSyntaxErrorException e) {
+            return YangStatementStreamSource.create(YangTextSchemaSource.forFile(new File(
+                StmtTestUtils.class.getResource(resourceName).toURI())));
+        } catch (IOException | YangSyntaxErrorException | URISyntaxException e) {
             throw new IllegalArgumentException("Failed to create source", e);
         }
     }