test/jdk/sun/net/www/protocol/jar/MultiReleaseJarURLConnection.java
changeset 48690 374c63fbe652
parent 47216 71c04702a3d5
child 54841 43439afaab4a
equal deleted inserted replaced
48689:e704f48d8277 48690:374c63fbe652
     1 /*
     1 /*
     2  * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 
    23 
    24 /*
    24 /*
    25  * @test
    25  * @test
    26  * @bug 8132734 8144062 8159785
    26  * @bug 8132734 8144062 8159785 8194070
    27  * @summary Test that URL connections to multi-release jars can be runtime versioned
    27  * @summary Test that URL connections to multi-release jars can be runtime versioned
    28  * @library /lib/testlibrary/java/util/jar
    28  * @library /lib/testlibrary/java/util/jar
    29  * @modules jdk.compiler
    29  * @modules jdk.compiler
    30  *          jdk.httpserver
    30  *          jdk.httpserver
    31  *          jdk.jartool
    31  *          jdk.jartool
   106         Assert.assertTrue(readAndCompare(new URL(baseUrlEntry + "#fragment"), "return 8"));
   106         Assert.assertTrue(readAndCompare(new URL(baseUrlEntry + "#fragment"), "return 8"));
   107         // cached entities not affected
   107         // cached entities not affected
   108         Assert.assertTrue(readAndCompare(new URL(baseUrlEntry), "return 8"));
   108         Assert.assertTrue(readAndCompare(new URL(baseUrlEntry), "return 8"));
   109 
   109 
   110         // the following tests will not work with unversioned jars
   110         // the following tests will not work with unversioned jars
   111         if (style.equals("unversioned")) return;
   111         if (style.equals("unversioned"))
       
   112             return;
   112 
   113 
   113         // direct access to versioned entry
   114         // direct access to versioned entry
   114         String versUrlEntry = urlFile + "META-INF/versions/" + Runtime.version().major()
   115         String versUrlEntry = urlFile + "META-INF/versions/" + Runtime.version().major()
   115                 + "/version/Version.java";
   116                 + "/version/Version.java";
   116         Assert.assertTrue(readAndCompare(new URL(versUrlEntry), rtreturn));
   117         Assert.assertTrue(readAndCompare(new URL(versUrlEntry), rtreturn));
   117         // adding any fragment does not change things
   118         // adding any fragment does not change things
   118         Assert.assertTrue(readAndCompare(new URL(versUrlEntry + "#runtime"), rtreturn));
   119         Assert.assertTrue(readAndCompare(new URL(versUrlEntry + "#runtime"), rtreturn));
   119         Assert.assertTrue(readAndCompare(new URL(versUrlEntry + "#fragment"), rtreturn));
   120         Assert.assertTrue(readAndCompare(new URL(versUrlEntry + "#fragment"), rtreturn));
   120 
       
   121         // it really doesn't change things
       
   122         versUrlEntry = urlFile + "META-INF/versions/10/version/Version.java";
       
   123         Assert.assertTrue(readAndCompare(new URL(versUrlEntry), "return 10"));
       
   124         Assert.assertTrue(readAndCompare(new URL(versUrlEntry + "#runtime"), "return 10"));
       
   125         Assert.assertTrue(readAndCompare(new URL(versUrlEntry + "#fragment"), "return 10"));
       
   126     }
   121     }
   127 
   122 
   128     @Test(dataProvider = "data")
   123     @Test(dataProvider = "data")
   129     public void testCachedJars(String style, String file) throws Exception {
   124     public void testCachedJars(String style, String file) throws Exception {
   130         String urlFile = "jar:file:" + file + "!/";
   125         String urlFile = "jar:file:" + file + "!/";
   223             Assert.assertTrue(rep.endsWith(suffix));
   218             Assert.assertTrue(rep.endsWith(suffix));
   224         }
   219         }
   225         cldr.close();
   220         cldr.close();
   226     }
   221     }
   227 
   222 
   228 
       
   229     private boolean readAndCompare(URL url, String match) throws Exception {
   223     private boolean readAndCompare(URL url, String match) throws Exception {
   230         boolean result;
   224         boolean result;
   231         // necessary to do it this way, instead of openStream(), so we can
   225         // necessary to do it this way, instead of openStream(), so we can
   232         // close underlying JarFile, otherwise windows can't delete the file
   226         // close underlying JarFile, otherwise windows can't delete the file
   233         URLConnection conn = url.openConnection();
   227         URLConnection conn = url.openConnection();