changeset 14870:5f83b44d70db

8159785: Add test that tests ClassLoader.getResource/getResources in Multi-Release Jar Reviewed-by: alanb
author mli
date Fri, 17 Jun 2016 04:35:09 -0700
parents d6059a61fee1
children ad9d6347b8a1
files test/sun/net/www/protocol/jar/MultiReleaseJarURLConnection.java
diffstat 1 files changed, 30 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/test/sun/net/www/protocol/jar/MultiReleaseJarURLConnection.java	Fri Jun 17 17:06:16 2016 +0900
+++ b/test/sun/net/www/protocol/jar/MultiReleaseJarURLConnection.java	Fri Jun 17 04:35:09 2016 -0700
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 8132734 8144062
+ * @bug 8132734 8144062 8159785
  * @summary Test that URL connections to multi-release jars can be runtime versioned
  * @library /lib/testlibrary/java/util/jar
  * @modules java.compiler
@@ -44,6 +44,7 @@
 import java.net.URLConnection;
 import java.nio.file.Files;
 import java.nio.file.Paths;
+import java.util.Enumeration;
 import java.util.jar.JarFile;
 
 import org.testng.Assert;
@@ -191,26 +192,36 @@
                 style.equals("unversioned") ? 8 : Runtime.version().major());
 
         // now get a resource and verify that we don't have a fragment attached
-        URL vclsUrl = vcls.getResource("/version/Version.class");
-        String fragment = vclsUrl.getRef();
-        Assert.assertNull(fragment);
+        Enumeration<URL> vclsUrlEnum = cldr.getResources("version/Version.class");
+        Assert.assertTrue(vclsUrlEnum.hasMoreElements());
+        URL vclsUrls[] = new URL[] {
+            vcls.getResource("/version/Version.class"),
+            vcls.getResource("Version.class"),
+            cldr.getResource("version/Version.class"),
+            vclsUrlEnum.nextElement()
+        };
+        Assert.assertFalse(vclsUrlEnum.hasMoreElements());
+        for (URL vclsUrl : vclsUrls) {
+            String fragment = vclsUrl.getRef();
+            Assert.assertNull(fragment);
 
-        // and verify that the the url is a reified pointer to the runtime entry
-        String rep = vclsUrl.toString();
-        //System.out.println("    getResource(\"/version/Version.class\") returned: " + rep);
-        if (style.equals("http")) {
-            Assert.assertTrue(rep.startsWith("jar:http:"));
-        } else {
-            Assert.assertTrue(rep.startsWith("jar:file:"));
+            // and verify that the the url is a reified pointer to the runtime entry
+            String rep = vclsUrl.toString();
+            //System.out.println("    getResource(\"/version/Version.class\") returned: " + rep);
+            if (style.equals("http")) {
+                Assert.assertTrue(rep.startsWith("jar:http:"));
+            } else {
+                Assert.assertTrue(rep.startsWith("jar:file:"));
+            }
+            String suffix;
+            if (style.equals("unversioned")) {
+                suffix = ".jar!/version/Version.class";
+            } else {
+                suffix = ".jar!/META-INF/versions/" + Runtime.version().major()
+                        + "/version/Version.class";
+            }
+            Assert.assertTrue(rep.endsWith(suffix));
         }
-        String suffix;
-        if (style.equals("unversioned")) {
-            suffix = ".jar!/version/Version.class";
-        } else {
-            suffix = ".jar!/META-INF/versions/" + Runtime.version().major()
-                    + "/version/Version.class";
-        }
-        Assert.assertTrue(rep.endsWith(suffix));
         cldr.close();
     }