1 /* 2 * Copyright (c) 2014, 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 * @library ../../lib /lib/testlibrary 27 * @build UpgradeModulePathTest CompilerUtils jdk.testlibrary.* 28 * @run testng UpgradeModulePathTest 29 * @summary Basic test for java -upgrademodulepath 30 */ 31 32 import java.io.File; 33 import java.nio.file.Path; 34 import java.nio.file.Paths; 35 36 import static jdk.testlibrary.ProcessTools.executeTestJava; 37 38 import org.testng.annotations.BeforeTest; 39 import org.testng.annotations.Test; 40 import static org.testng.Assert.*; 41 42 /** 43 * This test upgrades module java.transaction. The upgraded module has a 44 * dependency on module java.enterprise that is deployed on the application 45 * modue path. 46 */ 47 48 49 @Test 50 public class UpgradeModulePathTest { 51 52 private static final String TEST_SRC = System.getProperty("test.src"); 53 private static final Path SRC_DIR = Paths.get(TEST_SRC, "src"); 54 private static final Path MODS_DIR = Paths.get("mods"); 55 private static final Path UPGRADEDMODS_DIR = Paths.get("upgradedmods"); 56 57 58 @BeforeTest 59 public void setup() throws Exception { 60 61 // javac -d mods/java.enterprise src/java.enterprise/** 62 boolean compiled = CompilerUtils.compile( 63 SRC_DIR.resolve("java.enterprise"), 64 MODS_DIR.resolve("java.enterprise")); 65 assertTrue(compiled); 66 67 // javac -d upgrademods/java.transaction -mp mods src/java.transaction/** 68 compiled = CompilerUtils.compile( 69 SRC_DIR.resolve("java.transaction"), 70 UPGRADEDMODS_DIR.resolve("java.transaction"), 71 "-mp", MODS_DIR.toString()); 72 assertTrue(compiled); 73 74 // javac -d mods -upgrademodulepath upgrademods -mp mods src/test/** 75 compiled = CompilerUtils.compile( 76 SRC_DIR.resolve("test"), 77 MODS_DIR.resolve("test"), 78 "-upgrademodulepath", UPGRADEDMODS_DIR.toString(), 79 "-mp", MODS_DIR.toString()); 80 assertTrue(compiled); 81 82 } 83 84 /** 85 * Run the test with an upgraded java.transaction module. 86 */ 87 public void testWithUpgradedModule() throws Exception { 88 89 String mid = "test/jdk.test.Main"; 90 91 int exitValue 92 = executeTestJava( 93 "-upgrademodulepath", UPGRADEDMODS_DIR.toString(), 94 "-mp", MODS_DIR.toString(), 95 "-m", mid) 96 .outputTo(System.out) 97 .errorTo(System.out) 98 .getExitValue(); 99 100 assertTrue(exitValue == 0); 101 102 } 103 104 /** 105 * Attempt to run the test with an non-existent directory on the upgrade 106 * module path. 107 */ 108 public void testWithBadUpgradeModulePath() throws Exception { 109 110 String upgrademodulepath 111 = "DoesNotExit" + File.pathSeparator + UPGRADEDMODS_DIR.toString(); 112 String mid = "test/jdk.test.Main"; 113 114 int exitValue 115 = executeTestJava( 116 "-upgrademodulepath", upgrademodulepath, 117 "-mp", MODS_DIR.toString(), 118 "-m", mid) 119 .outputTo(System.out) 120 .errorTo(System.out) 121 .getExitValue(); 122 123 assertTrue(exitValue != 0); 124 125 } 126 127 }