Path: blob/master/test/jdk/java/rmi/module/ModuleTest.java
41149 views
/*1* Copyright (c) 2016, 2018, 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* @library /test/lib26* @build jdk.test.lib.process.ProcessTools27* jdk.test.lib.compiler.CompilerUtils28* jdk.test.lib.util.JarUtils29* ModuleTest30* @run testng ModuleTest31* @summary Basic tests for using rmi in module world32*/3334import static jdk.test.lib.process.ProcessTools.executeTestJava;35import static org.testng.Assert.assertEquals;36import static org.testng.Assert.assertTrue;3738import java.io.File;39import java.nio.file.Paths;40import jdk.test.lib.compiler.CompilerUtils;41import jdk.test.lib.util.JarUtils;4243import org.testng.annotations.BeforeTest;44import org.testng.annotations.Test;4546public class ModuleTest {4748static String fileJoin(String... names) {49return String.join(File.separator, names);50}5152static String pathJoin(String... paths) {53return String.join(File.pathSeparator, paths);54}5556private static final String TEST_SRC = System.getProperty("test.src");57private static final String CLIENT_EXP = fileJoin("exploded", "mclient");58private static final String SERVER_EXP = fileJoin("exploded", "mserver");59private static final String MTEST_EXP = fileJoin("exploded", "mtest");60private static final String CLIENT_JAR = fileJoin("mods", "mclient.jar");61private static final String SERVER_JAR = fileJoin("mods", "mserver.jar");62private static final String MTEST_JAR = fileJoin("mods", "mtest.jar");6364private static final String DUMMY_MAIN = "testpkg.DummyApp";6566/**67* Compiles all sample classes68*/69@BeforeTest70public void compileAll() throws Exception {71assertTrue(CompilerUtils.compile(72Paths.get(TEST_SRC, "src", "mserver"),73Paths.get(SERVER_EXP)));7475JarUtils.createJarFile(76Paths.get(SERVER_JAR),77Paths.get(SERVER_EXP));7879assertTrue(CompilerUtils.compile(80Paths.get(TEST_SRC, "src", "mclient"),81Paths.get(CLIENT_EXP),82"-cp", SERVER_JAR));8384JarUtils.createJarFile(85Paths.get(CLIENT_JAR),86Paths.get(CLIENT_EXP));8788assertTrue(CompilerUtils.compile(Paths.get(TEST_SRC, "src", "mtest"),89Paths.get(MTEST_EXP),90"-cp", pathJoin(CLIENT_JAR, SERVER_JAR)));9192JarUtils.createJarFile(93Paths.get(MTEST_JAR),94Paths.get(MTEST_EXP));95}9697/**98* Test the client, server and dummy application in different modules99* @throws Exception100*/101@Test102public void testAllInModule() throws Exception {103assertEquals(executeTestJava("--module-path", pathJoin(MTEST_JAR, CLIENT_JAR, SERVER_JAR),104"--add-modules", "mclient,mserver",105"-m", "mtest/" + DUMMY_MAIN)106.outputTo(System.out)107.errorTo(System.out)108.getExitValue(),1090);110}111112/**113* Test the client and server in unnamed modules,114* while the dummy application is in automatic module115* @throws Exception116*/117@Test118public void testAppInModule() throws Exception {119assertEquals(executeTestJava("--module-path", MTEST_JAR,120"-cp", pathJoin(CLIENT_JAR, SERVER_JAR),121"-m", "mtest/" + DUMMY_MAIN)122.outputTo(System.out)123.errorTo(System.out)124.getExitValue(),1250);126}127128/**129* Test the client and server in automatic modules,130* while the dummy application is in unnamed module131* @throws Exception132*/133@Test134public void testAppInUnnamedModule() throws Exception {135assertEquals(executeTestJava("--module-path", pathJoin(CLIENT_JAR, SERVER_JAR),136"--add-modules", "mclient,mserver",137"-cp", MTEST_JAR,138DUMMY_MAIN)139.outputTo(System.out)140.errorTo(System.out)141.getExitValue(),1420);143}144145/**146* Test the server and test application in automatic modules,147* with client in unnamed module148* @throws Exception149*/150@Test151public void testClientInUnamedModule() throws Exception {152assertEquals(executeTestJava("--module-path", pathJoin(MTEST_JAR, SERVER_JAR),153"--add-modules", "mserver",154"-cp", CLIENT_JAR,155"-m", "mtest/" + DUMMY_MAIN)156.outputTo(System.out)157.errorTo(System.out)158.getExitValue(),1590);160}161}162163164165