jdk/test/java/io/Serializable/evolution/RenamePackage/RenamePackageTest.java
author iignatyev
Mon, 12 Jun 2017 12:43:26 -0700
changeset 45467 99c87a16a8e4
parent 45295 c2764290902a
permissions -rw-r--r--
8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
45295
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
     1
/*
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
     4
 *
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
     7
 * published by the Free Software Foundation.
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
     8
 *
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    13
 * accompanied this code).
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    14
 *
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    18
 *
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    21
 * questions.
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    22
 */
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    23
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    24
/*
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    25
 * @test
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    26
 * @bug 4087295 4785472
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    27
 * @library /test/lib
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    28
 * @build jdk.test.lib.compiler.CompilerUtils
45467
99c87a16a8e4 8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents: 45295
diff changeset
    29
 *        jdk.test.lib.Utils
99c87a16a8e4 8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents: 45295
diff changeset
    30
 *        jdk.test.lib.Asserts
99c87a16a8e4 8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents: 45295
diff changeset
    31
 *        jdk.test.lib.JDKToolFinder
99c87a16a8e4 8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents: 45295
diff changeset
    32
 *        jdk.test.lib.JDKToolLauncher
99c87a16a8e4 8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents: 45295
diff changeset
    33
 *        jdk.test.lib.Platform
99c87a16a8e4 8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents: 45295
diff changeset
    34
 *        jdk.test.lib.process.*
45295
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    35
 * @build RenamePackageTest
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    36
 * @run main RenamePackageTest
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    37
 * @summary Enable resolveClass() to accommodate package renaming.
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    38
 *          This fix enables one to implement a resolveClass method that maps a
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    39
 *          Serialiazable class within a serialization stream to the same class
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    40
 *          in a different package within the JVM runtime. See run shell script
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    41
 *          for instructions on how to run this test.
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    42
 */
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    43
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    44
import java.io.File;
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    45
import java.nio.file.Path;
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    46
import java.nio.file.Paths;
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    47
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    48
import jdk.test.lib.compiler.CompilerUtils;
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    49
import jdk.test.lib.process.ProcessTools;
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    50
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    51
public class RenamePackageTest {
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    52
    public static void main(String args[]) throws Exception {
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    53
        setup();
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    54
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    55
        runTestSerialDriver();
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    56
        runInstallSerialDriver();
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    57
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    58
        runInstallSerialDriver();
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    59
        runTestSerialDriver();
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    60
    }
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    61
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    62
    private static final Path SHARE = Paths.get(System.getProperty("test.classes"), "share");
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    63
    private static final Path OCLASSES = Paths.get(System.getProperty("test.classes"), "oclasses");
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    64
    private static final Path NCLASSES = Paths.get(System.getProperty("test.classes"), "nclasses");
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    65
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    66
    private static void setup() throws Exception {
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    67
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    68
        boolean b = CompilerUtils.compile(Paths.get(System.getProperty("test.src"), "extension"),
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    69
                                          SHARE);
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    70
        assertTrue(b);
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    71
        b = CompilerUtils.compile(Paths.get(System.getProperty("test.src"), "test"),
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    72
                                  OCLASSES,
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    73
                                  "-classpath",
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    74
                                  SHARE.toString());
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    75
        assertTrue(b);
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    76
        b = CompilerUtils.compile(Paths.get(System.getProperty("test.src"), "install"),
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    77
                                  NCLASSES,
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    78
                                  "-classpath",
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    79
                                  SHARE.toString());
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    80
        assertTrue(b);
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    81
    }
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    82
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    83
    private static void runTestSerialDriver() throws Exception {
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    84
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true,
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    85
                "-classpath",
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    86
                SHARE.toString()
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    87
                    + File.pathSeparator
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    88
                    + OCLASSES.toString(),
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    89
                "test.SerialDriver", "-s");
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    90
        Process p = ProcessTools.startProcess("test SerialDriver", pb);
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    91
        p.waitFor();
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    92
        assertTrue(p.exitValue() == 0);
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    93
    }
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    94
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    95
    private static void runInstallSerialDriver() throws Exception {
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    96
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true,
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    97
                "-classpath",
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    98
                SHARE.toString()
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
    99
                    + File.pathSeparator
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
   100
                    + NCLASSES.toString(),
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
   101
                "install.SerialDriver", "-d");
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
   102
        Process p = ProcessTools.startProcess("install SerialDriver", pb);
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
   103
        p.waitFor();
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
   104
        assertTrue(p.exitValue() == 0);
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
   105
    }
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
   106
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
   107
    private static void assertTrue(boolean b) {
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
   108
        if (!b) {
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
   109
            throw new RuntimeException("expected true, get false");
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
   110
        }
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
   111
    }
c2764290902a 8166142: Refactor java.io.serialization shell tests to java
mli
parents:
diff changeset
   112
}