Path: blob/master/test/jdk/java/io/Serializable/evolution/RenamePackage/RenamePackageTest.java
41161 views
/*1* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 4087295 478547226* @library /test/lib27* @build jdk.test.lib.compiler.CompilerUtils28* jdk.test.lib.Utils29* jdk.test.lib.Asserts30* jdk.test.lib.JDKToolFinder31* jdk.test.lib.JDKToolLauncher32* jdk.test.lib.Platform33* jdk.test.lib.process.*34* @build RenamePackageTest35* @run main RenamePackageTest36* @summary Enable resolveClass() to accommodate package renaming.37* This fix enables one to implement a resolveClass method that maps a38* Serialiazable class within a serialization stream to the same class39* in a different package within the JVM runtime. See run shell script40* for instructions on how to run this test.41*/4243import java.io.File;44import java.nio.file.Path;45import java.nio.file.Paths;4647import jdk.test.lib.compiler.CompilerUtils;48import jdk.test.lib.process.ProcessTools;4950public class RenamePackageTest {51public static void main(String args[]) throws Exception {52setup();5354runTestSerialDriver();55runInstallSerialDriver();5657runInstallSerialDriver();58runTestSerialDriver();59}6061private static final Path SHARE = Paths.get(System.getProperty("test.classes"), "share");62private static final Path OCLASSES = Paths.get(System.getProperty("test.classes"), "oclasses");63private static final Path NCLASSES = Paths.get(System.getProperty("test.classes"), "nclasses");6465private static void setup() throws Exception {6667boolean b = CompilerUtils.compile(Paths.get(System.getProperty("test.src"), "extension"),68SHARE);69assertTrue(b);70b = CompilerUtils.compile(Paths.get(System.getProperty("test.src"), "test"),71OCLASSES,72"-classpath",73SHARE.toString());74assertTrue(b);75b = CompilerUtils.compile(Paths.get(System.getProperty("test.src"), "install"),76NCLASSES,77"-classpath",78SHARE.toString());79assertTrue(b);80}8182private static void runTestSerialDriver() throws Exception {83ProcessBuilder pb = ProcessTools.createTestJvm(84"-classpath",85SHARE.toString()86+ File.pathSeparator87+ OCLASSES.toString(),88"test.SerialDriver", "-s");89Process p = ProcessTools.startProcess("test SerialDriver", pb);90p.waitFor();91assertTrue(p.exitValue() == 0);92}9394private static void runInstallSerialDriver() throws Exception {95ProcessBuilder pb = ProcessTools.createTestJvm(96"-classpath",97SHARE.toString()98+ File.pathSeparator99+ NCLASSES.toString(),100"install.SerialDriver", "-d");101Process p = ProcessTools.startProcess("install SerialDriver", pb);102p.waitFor();103assertTrue(p.exitValue() == 0);104}105106private static void assertTrue(boolean b) {107if (!b) {108throw new RuntimeException("expected true, get false");109}110}111}112113114