jdk/test/java/util/jar/JarFile/MultiReleaseJarHttpProperties.java
changeset 37947 f69560487686
parent 37946 e420b9f05aaf
parent 37936 428ebc487445
child 37948 caf97b37ebec
equal deleted inserted replaced
37946:e420b9f05aaf 37947:f69560487686
     1 /*
       
     2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     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
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 /*
       
    25  * @test
       
    26  * @bug 8132734
       
    27  * @summary Test the System properties for JarFile that support multi-release jar files
       
    28  * @library /lib/testlibrary/java/util/jar
       
    29  * @build Compiler JarBuilder CreateMultiReleaseTestJars SimpleHttpServer
       
    30  * @run testng MultiReleaseJarHttpProperties
       
    31  * @run testng/othervm -Djdk.util.jar.version=0 MultiReleaseJarHttpProperties
       
    32  * @run testng/othervm -Djdk.util.jar.version=8 MultiReleaseJarHttpProperties
       
    33  * @run testng/othervm -Djdk.util.jar.version=9 MultiReleaseJarHttpProperties
       
    34  * @run testng/othervm -Djdk.util.jar.version=10 MultiReleaseJarHttpProperties
       
    35  * @run testng/othervm -Djdk.util.jar.version=100 MultiReleaseJarHttpProperties
       
    36  * @run testng/othervm -Djdk.util.jar.version=8 -Djdk.util.jar.enableMultiRelease=false MultiReleaseJarHttpProperties
       
    37  * @run testng/othervm -Djdk.util.jar.version=9 -Djdk.util.jar.enableMultiRelease=false MultiReleaseJarHttpProperties
       
    38  * @run testng/othervm -Djdk.util.jar.version=10 -Djdk.util.jar.enableMultiRelease=false MultiReleaseJarHttpProperties
       
    39  * @run testng/othervm -Djdk.util.jar.version=8 -Djdk.util.jar.enableMultiRelease=force MultiReleaseJarHttpProperties
       
    40  * @run testng/othervm -Djdk.util.jar.version=9 -Djdk.util.jar.enableMultiRelease=force MultiReleaseJarHttpProperties
       
    41  * @run testng/othervm -Djdk.util.jar.version=10 -Djdk.util.jar.enableMultiRelease=force MultiReleaseJarHttpProperties
       
    42  * @run testng/othervm -Djdk.util.jar.enableMultiRelease=false MultiReleaseJarHttpProperties
       
    43  * @run testng/othervm -Djdk.util.jar.enableMultiRelease=force MultiReleaseJarHttpProperties
       
    44  */
       
    45 
       
    46 import java.io.IOException;
       
    47 import java.io.InputStream;
       
    48 import java.io.OutputStream;
       
    49 import java.net.InetSocketAddress;
       
    50 import java.net.URL;
       
    51 import java.net.URLClassLoader;
       
    52 import java.nio.file.Files;
       
    53 import java.nio.file.Path;
       
    54 import java.nio.file.Paths;
       
    55 
       
    56 import org.testng.Assert;
       
    57 import org.testng.annotations.AfterClass;
       
    58 import org.testng.annotations.BeforeClass;
       
    59 import org.testng.annotations.Test;
       
    60 
       
    61 public class MultiReleaseJarHttpProperties extends MultiReleaseJarProperties {
       
    62     private SimpleHttpServer server;
       
    63 
       
    64     @BeforeClass
       
    65     public void initialize() throws Exception {
       
    66         server = new SimpleHttpServer();
       
    67         server.start();
       
    68         super.initialize();
       
    69     }
       
    70 
       
    71     @Override
       
    72     protected void initializeClassLoader() throws Exception {
       
    73         URL[] urls = new URL[]{
       
    74                 new URL("http://localhost:" + server.getPort() + "/multi-release.jar")
       
    75         };
       
    76         cldr = new URLClassLoader(urls);
       
    77         // load any class, Main is convenient and in the root entries
       
    78         rootClass = cldr.loadClass("version.Main");
       
    79     }
       
    80 
       
    81     @AfterClass
       
    82     public void close() throws IOException {
       
    83         // Windows requires server to stop before file is deleted
       
    84         if (server != null)
       
    85             server.stop();
       
    86         super.close();
       
    87     }
       
    88 
       
    89     /*
       
    90      * jdk.util.jar.enableMultiRelease=force is a no-op for URLClassLoader
       
    91      */
       
    92 
       
    93     @Test
       
    94     public void testURLClassLoader() throws Throwable {
       
    95         Class<?> vcls = cldr.loadClass("version.Version");
       
    96         invokeMethod(vcls, rtVersion);
       
    97     }
       
    98 
       
    99     @Test
       
   100     public void testGetResourceAsStream() throws Exception {
       
   101         String resource = rtVersion == 9 ? "/version/PackagePrivate.java" : "/version/Version.java";
       
   102         // use rootClass as a base for getting resources
       
   103         getResourceAsStream(rootClass, resource);
       
   104     }
       
   105 
       
   106     @Test
       
   107     public void testGetResource() throws Exception {
       
   108         String resource = rtVersion == 9 ? "/version/PackagePrivate.java" : "/version/Version.java";
       
   109         // use rootClass as a base for getting resources
       
   110         getResource(rootClass, resource);
       
   111     }
       
   112 }