< prev index next >
test/jdk/sun/net/www/protocol/jar/MultiReleaseJarURLConnection.java
Print this page
*** 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.
--- 1,7 ----
/*
! * Copyright (c) 2015, 2018, 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 8144062 8159785
* @summary Test that URL connections to multi-release jars can be runtime versioned
* @library /lib/testlibrary/java/util/jar
* @modules jdk.compiler
* jdk.httpserver
* jdk.jartool
--- 21,31 ----
* questions.
*/
/*
* @test
! * @bug 8132734 8144062 8159785 8194070
* @summary Test that URL connections to multi-release jars can be runtime versioned
* @library /lib/testlibrary/java/util/jar
* @modules jdk.compiler
* jdk.httpserver
* jdk.jartool
*** 94,104 ****
@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));
--- 94,104 ----
@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 " + Math.min(Runtime.version().major(), 10);
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));
*** 106,130 ****
Assert.assertTrue(readAndCompare(new URL(baseUrlEntry + "#fragment"), "return 8"));
// cached entities not affected
Assert.assertTrue(readAndCompare(new URL(baseUrlEntry), "return 8"));
// 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));
// it really doesn't change things
! versUrlEntry = urlFile + "META-INF/versions/10/version/Version.java";
! Assert.assertTrue(readAndCompare(new URL(versUrlEntry), "return 10"));
! Assert.assertTrue(readAndCompare(new URL(versUrlEntry + "#runtime"), "return 10"));
! Assert.assertTrue(readAndCompare(new URL(versUrlEntry + "#fragment"), "return 10"));
}
@Test(dataProvider = "data")
public void testCachedJars(String style, String file) throws Exception {
String urlFile = "jar:file:" + file + "!/";
--- 106,132 ----
Assert.assertTrue(readAndCompare(new URL(baseUrlEntry + "#fragment"), "return 8"));
// cached entities not affected
Assert.assertTrue(readAndCompare(new URL(baseUrlEntry), "return 8"));
// 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/" +
! Math.min(Runtime.version().major(), 10)
+ "/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));
// it really doesn't change things
! // versUrlEntry = urlFile + "META-INF/versions/10/version/Version.java";
! // Assert.assertTrue(readAndCompare(new URL(versUrlEntry), "return 10"));
! // Assert.assertTrue(readAndCompare(new URL(versUrlEntry + "#runtime"), "return 10"));
! // Assert.assertTrue(readAndCompare(new URL(versUrlEntry + "#fragment"), "return 10"));
}
@Test(dataProvider = "data")
public void testCachedJars(String style, String file) throws Exception {
String urlFile = "jar:file:" + file + "!/";
*** 187,197 ****
// 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
Enumeration<URL> vclsUrlEnum = cldr.getResources("version/Version.class");
Assert.assertTrue(vclsUrlEnum.hasMoreElements());
URL vclsUrls[] = new URL[] {
--- 189,201 ----
// 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 :
! Math.min(Runtime.version().major(), 10));
// now get a resource and verify that we don't have a fragment attached
Enumeration<URL> vclsUrlEnum = cldr.getResources("version/Version.class");
Assert.assertTrue(vclsUrlEnum.hasMoreElements());
URL vclsUrls[] = new URL[] {
*** 215,225 ****
}
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();
--- 219,229 ----
}
String suffix;
if (style.equals("unversioned")) {
suffix = ".jar!/version/Version.class";
} else {
! suffix = ".jar!/META-INF/versions/" + Math.min(Runtime.version().major(), 10)
+ "/version/Version.class";
}
Assert.assertTrue(rep.endsWith(suffix));
}
cldr.close();
< prev index next >