Skip to content

Commit 81d957c

Browse files
committed
Add test to access resource in module via URL
1 parent 13dd2e2 commit 81d957c

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.oracle.svm.test;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
/**
9+
* Specifies packages concealed in JDK modules used by a test. The mx unit test runner will ensure
10+
* the packages are exported to the module containing annotated test class.
11+
*/
12+
@Retention(RetentionPolicy.RUNTIME)
13+
@Target(ElementType.TYPE)
14+
public @interface AddExports {
15+
/**
16+
* The qualified name of the concealed package in {@code <module>/<package>} format (e.g.,
17+
* "jdk.internal.vm.ci/jdk.vm.ci.code").
18+
*/
19+
String[] value() default "";
20+
}

substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/NativeImageResourceFileSystemProviderTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262

6363
import com.oracle.svm.core.configure.ResourcesRegistry;
6464

65+
@AddExports("java.base/java.lang")
6566
public class NativeImageResourceFileSystemProviderTest {
6667

6768
private static final String RESOURCE_DIR = "/resources";
@@ -572,4 +573,19 @@ public void writingFileAttributes() {
572573
// 3. Closing file system.
573574
closeFileSystem(fileSystem);
574575
}
576+
577+
@Test
578+
public void moduleResourceURLAccess() {
579+
URL url = Class.class.getResource("uniName.dat");
580+
Assert.assertNotNull("URL for resource java.base/java/lang/uniName.dat must not be null", url);
581+
try (InputStream in = url.openStream()) {
582+
try {
583+
Assert.assertNotEquals("uniName.dat does not seem to contain valid data", in.read(), 0);
584+
} catch (IOException e) {
585+
Assert.fail("IOException in in.read(): " + e.getMessage());
586+
}
587+
} catch (IOException e) {
588+
Assert.fail("IOException in url.openStream(): " + e.getMessage());
589+
}
590+
}
575591
}

0 commit comments

Comments
 (0)