< prev index next >
jdk/test/sun/net/www/protocol/jar/MultiReleaseJarURLConnection.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
--- 1,7 ----
/*
! * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*** 21,31 ****
* questions.
*/
/*
* @test
! * @bug 8132734
* @summary Test that URL connections to multi-release jars can be runtime versioned
* @library /lib/testlibrary/java/util/jar
* @build Compiler JarBuilder CreateMultiReleaseTestJars SimpleHttpServer
* @run testng MultiReleaseJarURLConnection
*/
--- 21,31 ----
* questions.
*/
/*
* @test
! * @bug 8132734 8144062
* @summary Test that URL connections to multi-release jars can be runtime versioned
* @library /lib/testlibrary/java/util/jar
* @build Compiler JarBuilder CreateMultiReleaseTestJars SimpleHttpServer
* @run testng MultiReleaseJarURLConnection
*/
*** 41,52 ****
import java.net.URLConnection;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.jar.JarFile;
- import jdk.Version;
-
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
--- 41,50 ----
*** 92,102 ****
@Test(dataProvider = "data")
public void testRuntimeVersioning(String style, String file) throws Exception {
String urlFile = "jar:file:" + file + "!/";
String baseUrlEntry = urlFile + "version/Version.java";
! String rtreturn = "return " + Version.current().major();
Assert.assertTrue(readAndCompare(new URL(baseUrlEntry), "return 8"));
// #runtime is "magic" for a multi-release jar, but not for unversioned jar
Assert.assertTrue(readAndCompare(new URL(baseUrlEntry + "#runtime"),
style.equals("unversioned") ? "return 8" : rtreturn));
--- 90,100 ----
@Test(dataProvider = "data")
public void testRuntimeVersioning(String style, String file) throws Exception {
String urlFile = "jar:file:" + file + "!/";
String baseUrlEntry = urlFile + "version/Version.java";
! String rtreturn = "return " + Runtime.version().major();
Assert.assertTrue(readAndCompare(new URL(baseUrlEntry), "return 8"));
// #runtime is "magic" for a multi-release jar, but not for unversioned jar
Assert.assertTrue(readAndCompare(new URL(baseUrlEntry + "#runtime"),
style.equals("unversioned") ? "return 8" : rtreturn));
*** 107,117 ****
// the following tests will not work with unversioned jars
if (style.equals("unversioned")) return;
// direct access to versioned entry
! String versUrlEntry = urlFile + "META-INF/versions/" + Version.current().major()
+ "/version/Version.java";
Assert.assertTrue(readAndCompare(new URL(versUrlEntry), rtreturn));
// adding any fragment does not change things
Assert.assertTrue(readAndCompare(new URL(versUrlEntry + "#runtime"), rtreturn));
Assert.assertTrue(readAndCompare(new URL(versUrlEntry + "#fragment"), rtreturn));
--- 105,115 ----
// the following tests will not work with unversioned jars
if (style.equals("unversioned")) return;
// direct access to versioned entry
! String versUrlEntry = urlFile + "META-INF/versions/" + Runtime.version().major()
+ "/version/Version.java";
Assert.assertTrue(readAndCompare(new URL(versUrlEntry), rtreturn));
// adding any fragment does not change things
Assert.assertTrue(readAndCompare(new URL(versUrlEntry + "#runtime"), rtreturn));
Assert.assertTrue(readAndCompare(new URL(versUrlEntry + "#fragment"), rtreturn));
*** 185,195 ****
// verify we are loading a runtime versioned class
MethodType mt = MethodType.methodType(int.class);
MethodHandle mh = MethodHandles.lookup().findVirtual(vcls, "getVersion", mt);
Assert.assertEquals((int)mh.invoke(vcls.newInstance()),
! style.equals("unversioned") ? 8 : Version.current().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);
--- 183,193 ----
// verify we are loading a runtime versioned class
MethodType mt = MethodType.methodType(int.class);
MethodHandle mh = MethodHandles.lookup().findVirtual(vcls, "getVersion", mt);
Assert.assertEquals((int)mh.invoke(vcls.newInstance()),
! 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);
*** 204,214 ****
}
String suffix;
if (style.equals("unversioned")) {
suffix = ".jar!/version/Version.class";
} else {
! suffix = ".jar!/META-INF/versions/" + Version.current().major()
+ "/version/Version.class";
}
Assert.assertTrue(rep.endsWith(suffix));
cldr.close();
}
--- 202,212 ----
}
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();
}
< prev index next >