test/jdk/tools/jpackage/share/InstallDirTest.java
branchJDK-8200758-branch
changeset 58434 b00cbf427368
parent 58416 f09bf58c1f17
child 58464 d82489644b15
equal deleted inserted replaced
58419:18e27ee2276b 58434:b00cbf427368
    27 import java.util.function.Supplier;
    27 import java.util.function.Supplier;
    28 import jdk.jpackage.test.TKit;
    28 import jdk.jpackage.test.TKit;
    29 import jdk.jpackage.test.PackageTest;
    29 import jdk.jpackage.test.PackageTest;
    30 import jdk.jpackage.test.PackageType;
    30 import jdk.jpackage.test.PackageType;
    31 import jdk.jpackage.test.Functional;
    31 import jdk.jpackage.test.Functional;
       
    32 import jdk.jpackage.test.JPackageCommand;
       
    33 import jdk.jpackage.test.Annotations.Parameter;
    32 
    34 
    33 /**
    35 /**
    34  * Test --install-dir parameter. Output of the test should be installdirtest*.*
    36  * Test --install-dir parameter. Output of the test should be installdirtest*.*
    35  * package bundle. The output package should provide the same functionality as
    37  * package bundle. The output package should provide the same functionality as
    36  * the default package but install test application in specified directory.
    38  * the default package but install test application in specified directory.
    53 /*
    55 /*
    54  * @test
    56  * @test
    55  * @summary jpackage with --install-dir
    57  * @summary jpackage with --install-dir
    56  * @library ../helpers
    58  * @library ../helpers
    57  * @build jdk.jpackage.test.*
    59  * @build jdk.jpackage.test.*
       
    60  * @compile InstallDirTest.java
    58  * @modules jdk.jpackage/jdk.jpackage.internal
    61  * @modules jdk.jpackage/jdk.jpackage.internal
    59  * @run main/othervm/timeout=360 -Xmx512m InstallDirTest
    62  * @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main
       
    63  *  --jpt-run=InstallDirTest.testCommon
       
    64  */
       
    65 
       
    66 /*
       
    67  * @test
       
    68  * @summary jpackage with --install-dir
       
    69  * @library ../helpers
       
    70  * @build jdk.jpackage.test.*
       
    71  * @compile InstallDirTest.java
       
    72  * @modules jdk.jpackage/jdk.jpackage.internal
       
    73  * @requires (os.family == "linux")
       
    74  * @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main
       
    75  *  --jpt-run=InstallDirTest.testLinuxInvalid,testLinuxUnsupported
    60  */
    76  */
    61 public class InstallDirTest {
    77 public class InstallDirTest {
    62 
    78 
    63     public static void main(String[] args) {
    79     public static void testCommon() {
    64         final Map<PackageType, Path> INSTALL_DIRS = Functional.identity(() -> {
    80         final Map<PackageType, Path> INSTALL_DIRS = Functional.identity(() -> {
    65             Map<PackageType, Path> reply = new HashMap<>();
    81             Map<PackageType, Path> reply = new HashMap<>();
    66             reply.put(PackageType.WIN_MSI, Path.of("TestVendor\\InstallDirTest1234"));
    82             reply.put(PackageType.WIN_MSI, Path.of("TestVendor\\InstallDirTest1234"));
    67             reply.put(PackageType.WIN_EXE, reply.get(PackageType.WIN_MSI));
    83             reply.put(PackageType.WIN_EXE, reply.get(PackageType.WIN_MSI));
    68 
    84 
    73             reply.put(PackageType.MAC_DMG, reply.get(PackageType.MAC_PKG));
    89             reply.put(PackageType.MAC_DMG, reply.get(PackageType.MAC_PKG));
    74 
    90 
    75             return reply;
    91             return reply;
    76         }).get();
    92         }).get();
    77 
    93 
    78         TKit.run(args, () -> {
    94         new PackageTest().configureHelloApp()
    79             new PackageTest().configureHelloApp()
    95         .addInitializer(cmd -> {
    80             .addInitializer(cmd -> {
    96             cmd.addArguments("--install-dir", INSTALL_DIRS.get(
    81                 cmd.addArguments("--install-dir", INSTALL_DIRS.get(
    97                     cmd.packageType()));
    82                         cmd.packageType()));
    98         }).run();
    83             }).run();
    99     }
    84         });
   100 
       
   101     @Parameter("/")
       
   102     @Parameter(".")
       
   103     @Parameter("foo")
       
   104     @Parameter("/opt/foo/.././.")
       
   105     public static void testLinuxInvalid(String installDir) {
       
   106         testLinuxBad(installDir, "Invalid installation directory");
       
   107     }
       
   108 
       
   109     @Parameter("/usr")
       
   110     @Parameter("/usr/local")
       
   111     @Parameter("/usr/foo")
       
   112     public static void testLinuxUnsupported(String installDir) {
       
   113         testLinuxBad(installDir, "currently unsupported");
       
   114     }
       
   115 
       
   116     private static void testLinuxBad(String installDir,
       
   117             String errorMessageSubstring) {
       
   118         new PackageTest().configureHelloApp()
       
   119                 .setExpectedExitCode(1)
       
   120                 .forTypes(PackageType.LINUX)
       
   121                 .addInitializer(cmd -> {
       
   122                     cmd.addArguments("--install-dir", installDir);
       
   123                     cmd.saveConsoleOutput(true);
       
   124                 })
       
   125                 .addBundleVerifier((cmd, result) -> {
       
   126                     String errorMessage = JPackageCommand.filterOutput(result.
       
   127                             getOutput().stream()).filter(line -> line.contains(
       
   128                             errorMessageSubstring)).findFirst().orElse(null);
       
   129                     TKit.assertNotNull(errorMessage, String.format(
       
   130                             "Check output contains [%s] substring",
       
   131                             errorMessageSubstring));
       
   132                 })
       
   133                 .run();
    85     }
   134     }
    86 }
   135 }