< prev index next >
test/jdk/jigsaw/scenarios/overlappingpackages/OverlappingPackagesTest.java
Print this page
*** 22,58 ****
*/
/**
* @test
* @library ../../lib /lib/testlibrary
! * @build OverlappingPackagesTest CompilerUtils
* @run testng OverlappingPackagesTest
* @summary Basic test to ensure that startup fails if two or more modules
* in the boot Layer have the same package
*/
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import static jdk.testlibrary.ProcessTools.*;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import static org.testng.Assert.*;
@Test
public class OverlappingPackagesTest {
private static final String TEST_SRC = System.getProperty("test.src");
private static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
private static final Path MODS_DIR = Paths.get("mods");
// the names of the modules in this test
! private static List<String> modules = Arrays.asList("m1", "m2", "misc", "test");
/**
* Compiles all modules used by the test
*/
--- 22,66 ----
*/
/**
* @test
* @library ../../lib /lib/testlibrary
! * @build OverlappingPackagesTest CompilerUtils jdk.testlibrary.OutputAnalyzer
* @run testng OverlappingPackagesTest
* @summary Basic test to ensure that startup fails if two or more modules
* in the boot Layer have the same package
*/
+ import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
+ import java.nio.file.Files;
import java.util.Arrays;
import java.util.List;
import static jdk.testlibrary.ProcessTools.*;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import static org.testng.Assert.*;
+ import jdk.testlibrary.OutputAnalyzer;
+
@Test
public class OverlappingPackagesTest {
private static final String TEST_SRC = System.getProperty("test.src");
private static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
private static final Path MODS_DIR = Paths.get("mods");
// the names of the modules in this test
! private static List<String> modules = Arrays.asList("m1", "m2", "misc",
! "test");
!
! private static final String DUP_P_MSG = "Package p in both module m2 and " +
! "module m1";
/**
* Compiles all modules used by the test
*/
*** 83,115 ****
/**
* Run the test with "-addmods misc", the misc module has package
* sun.misc and so should overlap with the base module.
*/
public void testOverlapWithBaseModule() throws Exception {
! int exitValue
= executeTestJava("-mp", MODS_DIR.toString(),
"-addmods", "misc",
"-m", "test/test.Main")
.outputTo(System.out)
! .errorTo(System.err)
! .getExitValue();
!
! assertTrue(exitValue != 0);
}
/**
* Run the test with "-addmods m1,m2". Both modules have package p.
*/
public void testOverlap() throws Exception {
! int exitValue
= executeTestJava("-mp", MODS_DIR.toString(),
"-addmods", "m1,m2",
"-m", "test/test.Main")
.outputTo(System.out)
.errorTo(System.err)
.getExitValue();
!
! assertTrue(exitValue != 0);
}
}
--- 91,178 ----
/**
* Run the test with "-addmods misc", the misc module has package
* sun.misc and so should overlap with the base module.
*/
public void testOverlapWithBaseModule() throws Exception {
! OutputAnalyzer output
= executeTestJava("-mp", MODS_DIR.toString(),
"-addmods", "misc",
"-m", "test/test.Main")
.outputTo(System.out)
! .errorTo(System.err);
! output.shouldContain("Module misc contains package sun.misc, " +
! "module java.base exports package sun.misc to misc");
! assertTrue(output.getExitValue() != 0);
}
/**
* Run the test with "-addmods m1,m2". Both modules have package p.
*/
public void testOverlap() throws Exception {
! OutputAnalyzer output
= executeTestJava("-mp", MODS_DIR.toString(),
"-addmods", "m1,m2",
"-m", "test/test.Main")
.outputTo(System.out)
+ .errorTo(System.err);
+ output.shouldContain(DUP_P_MSG);
+ assertTrue(output.getExitValue() != 0);
+ }
+
+ /**
+ * Run the test with m1 being on the modulepath. m1 module has package p.
+ * Package p is also present on the classpath.
+ */
+ public void testOverlapWithClasspath() throws Exception {
+ int exitValue
+ = executeTestJava("-mp", MODS_DIR.toString(),
+ "-classpath", MODS_DIR.resolve("m1").toString(),
+ "-addmods", "m2",
+ "-m", "test/test.Main")
+ .outputTo(System.out)
.errorTo(System.err)
.getExitValue();
! assertTrue(exitValue == 0);
}
+ /**
+ * Run with package p present two times on the classpath.
+ */
+ public void testOverlapWithDupsOnClasspath() throws Exception {
+ String cp = MODS_DIR.resolve("m1").toString() + File.pathSeparator +
+ MODS_DIR.resolve("m2");
+ int exitValue
+ = executeTestJava("-mp", MODS_DIR.toString(),
+ "-classpath", cp,
+ "-m", "test/test.Main")
+ .outputTo(System.out)
+ .errorTo(System.err)
+ .getExitValue();
+ assertTrue(exitValue == 0);
+ }
+ /**
+ * Run the test with "-addmods m1,m2" with one of the modules being
+ * on the module path and the other one - on the upgrade module path.
+ * Both modules have package p.
+ */
+ public void testOverlapUpgratePath() throws Exception {
+ Path upgradePath = Paths.get("up");
+ Path dest = upgradePath.resolve("m1");
+ Files.createDirectories(upgradePath);
+ Path src = MODS_DIR.resolve("m1");
+ Files.move(src, dest);
+ try {
+ OutputAnalyzer output
+ = executeTestJava("-mp", MODS_DIR.toString(),
+ "-upgrademodulepath", upgradePath.toString(),
+ "-addmods", "m1,m2",
+ "-m", "test/test.Main")
+ .outputTo(System.out)
+ .errorTo(System.err);
+ output.shouldContain(DUP_P_MSG);
+ assertTrue(output.getExitValue() != 0);
+ } finally {
+ Files.move(dest, src);
+ }
+ }
}
< prev index next >