1 /* 2 * Copyright (c) 2016, 2018, 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 /test/lib 27 * @build jdk.test.lib.process.ProcessTools 28 * jdk.test.lib.compiler.CompilerUtils 29 * jdk.test.lib.util.JarUtils 30 * ModuleTest 31 * @run testng ModuleTest 32 * @summary Basic tests for using rmi in module world 33 */ 34 35 import static jdk.test.lib.process.ProcessTools.executeTestJava; 36 import static org.testng.Assert.assertEquals; 37 import static org.testng.Assert.assertTrue; 38 39 import java.io.File; 40 import java.nio.file.Paths; 41 import jdk.test.lib.compiler.CompilerUtils; 42 import jdk.test.lib.util.JarUtils; 43 44 import org.testng.annotations.BeforeTest; 45 import org.testng.annotations.Test; 46 47 public class ModuleTest { 48 49 static String fileJoin(String... names) { 50 return String.join(File.separator, names); 51 } 52 53 static String pathJoin(String... paths) { 54 return String.join(File.pathSeparator, paths); 55 } 56 57 private static final String TEST_SRC = System.getProperty("test.src"); 58 private static final String CLIENT_EXP = fileJoin("exploded", "mclient"); 59 private static final String SERVER_EXP = fileJoin("exploded", "mserver"); 60 private static final String MTEST_EXP = fileJoin("exploded", "mtest"); 61 private static final String CLIENT_JAR = fileJoin("mods", "mclient.jar"); 62 private static final String SERVER_JAR = fileJoin("mods", "mserver.jar"); 63 private static final String MTEST_JAR = fileJoin("mods", "mtest.jar"); 64 65 private static final String DUMMY_MAIN = "testpkg.DummyApp"; 66 67 /** 68 * Compiles all sample classes 69 */ 70 @BeforeTest 71 public void compileAll() throws Exception { 72 assertTrue(CompilerUtils.compile( 73 Paths.get(TEST_SRC, "src", "mserver"), 74 Paths.get(SERVER_EXP))); 75 76 JarUtils.createJarFile( 77 Paths.get(SERVER_JAR), 78 Paths.get(SERVER_EXP)); 79 80 assertTrue(CompilerUtils.compile( 81 Paths.get(TEST_SRC, "src", "mclient"), 82 Paths.get(CLIENT_EXP), 83 "-cp", SERVER_JAR)); 84 85 JarUtils.createJarFile( 86 Paths.get(CLIENT_JAR), 87 Paths.get(CLIENT_EXP)); 88 89 assertTrue(CompilerUtils.compile(Paths.get(TEST_SRC, "src", "mtest"), 90 Paths.get(MTEST_EXP), 91 "-cp", pathJoin(CLIENT_JAR, SERVER_JAR))); 92 93 JarUtils.createJarFile( 94 Paths.get(MTEST_JAR), 95 Paths.get(MTEST_EXP)); 96 } 97 98 /** 99 * Test the client, server and dummy application in different modules 100 * @throws Exception 101 */ 102 @Test 103 public void testAllInModule() throws Exception { 104 assertEquals(executeTestJava("--module-path", pathJoin(MTEST_JAR, CLIENT_JAR, SERVER_JAR), 105 "--add-modules", "mclient,mserver", 106 "-m", "mtest/" + DUMMY_MAIN) 107 .outputTo(System.out) 108 .errorTo(System.out) 109 .getExitValue(), 110 0); 111 } 112 113 /** 114 * Test the client and server in unnamed modules, 115 * while the dummy application is in automatic module 116 * @throws Exception 117 */ 118 @Test 119 public void testAppInModule() throws Exception { 120 assertEquals(executeTestJava("--module-path", MTEST_JAR, 121 "-cp", pathJoin(CLIENT_JAR, SERVER_JAR), 122 "-m", "mtest/" + DUMMY_MAIN) 123 .outputTo(System.out) 124 .errorTo(System.out) 125 .getExitValue(), 126 0); 127 } 128 129 /** 130 * Test the client and server in automatic modules, 131 * while the dummy application is in unnamed module 132 * @throws Exception 133 */ 134 @Test 135 public void testAppInUnnamedModule() throws Exception { 136 assertEquals(executeTestJava("--module-path", pathJoin(CLIENT_JAR, SERVER_JAR), 137 "--add-modules", "mclient,mserver", 138 "-cp", MTEST_JAR, 139 DUMMY_MAIN) 140 .outputTo(System.out) 141 .errorTo(System.out) 142 .getExitValue(), 143 0); 144 } 145 146 /** 147 * Test the server and test application in automatic modules, 148 * with client in unnamed module 149 * @throws Exception 150 */ 151 @Test 152 public void testClientInUnamedModule() throws Exception { 153 assertEquals(executeTestJava("--module-path", pathJoin(MTEST_JAR, SERVER_JAR), 154 "--add-modules", "mserver", 155 "-cp", CLIENT_JAR, 156 "-m", "mtest/" + DUMMY_MAIN) 157 .outputTo(System.out) 158 .errorTo(System.out) 159 .getExitValue(), 160 0); 161 } 162 } 163