Skip to content

Commit

Permalink
Add test to access resource in module via URL
Browse files Browse the repository at this point in the history
  • Loading branch information
olpaw committed Feb 2, 2022
1 parent 13dd2e2 commit ab38d52
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.oracle.svm.test;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Specifies packages concealed in JDK modules used by a test. The mx unit test runner will ensure
* the packages are exported to the module containing annotated test class.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface AddExports {
/**
* The qualified name of the concealed package in {@code <module>/<package>} format (e.g.,
* "jdk.internal.vm.ci/jdk.vm.ci.code").
*/
String[] value() default "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@

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

@AddExports("java.base/java.lang")
public class NativeImageResourceFileSystemProviderTest {

private static final String RESOURCE_DIR = "/resources";
Expand Down Expand Up @@ -572,4 +573,20 @@ public void writingFileAttributes() {
// 3. Closing file system.
closeFileSystem(fileSystem);
}

@Test
public void moduleResourceURLAccess() {
URL url = Class.class.getResource("uniName.dat");
System.out.println("URL is " + url);
Assert.assertNotNull("URL for resource java.base/java/lang/uniName.dat must not be null", url);
try (InputStream in = url.openStream()) {
try {
Assert.assertNotEquals("uniName.dat does not seem to contain valid data", in.read(), 0);
} catch (IOException e) {
Assert.fail("IOException in in.read(): " + e.getMessage());
}
} catch (IOException e) {
Assert.fail("IOException in url.openStream(): " + e.getMessage());
}
}
}

0 comments on commit ab38d52

Please sign in to comment.