test/jdk/tools/jpackage/share/InstallDirTest.java
author herrick
Fri, 08 Nov 2019 14:53:03 -0500
branchJDK-8200758-branch
changeset 58994 b09ba68c6a19
parent 58888 d802578912f3
permissions -rw-r--r--
8233636 : Make jpackage an incubator and remove tool provider implementation Reviewed-by: asemenyuk, almatvee, kcr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
58113
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
     1
/*
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
     2
 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
     4
 *
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
     7
 * published by the Free Software Foundation.
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
     8
 *
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    13
 * accompanied this code).
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    14
 *
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    18
 *
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    21
 * questions.
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    22
 */
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    23
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    24
import java.nio.file.Path;
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    25
import java.util.HashMap;
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    26
import java.util.Map;
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    27
import java.util.function.Supplier;
58416
f09bf58c1f17 8231605: Improve test helpers
herrick
parents: 58301
diff changeset
    28
import jdk.jpackage.test.TKit;
58113
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    29
import jdk.jpackage.test.PackageTest;
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    30
import jdk.jpackage.test.PackageType;
58416
f09bf58c1f17 8231605: Improve test helpers
herrick
parents: 58301
diff changeset
    31
import jdk.jpackage.test.Functional;
58434
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    32
import jdk.jpackage.test.JPackageCommand;
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    33
import jdk.jpackage.test.Annotations.Parameter;
58113
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    34
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    35
/**
58648
3bf53ffa9ae7 8232279 : Improve test helpers #2
herrick
parents: 58464
diff changeset
    36
 * Test --install-dir parameter. Output of the test should be
3bf53ffa9ae7 8232279 : Improve test helpers #2
herrick
parents: 58464
diff changeset
    37
 * commoninstalldirtest*.* package bundle. The output package should provide the
3bf53ffa9ae7 8232279 : Improve test helpers #2
herrick
parents: 58464
diff changeset
    38
 * same functionality as the default package but install test application in
3bf53ffa9ae7 8232279 : Improve test helpers #2
herrick
parents: 58464
diff changeset
    39
 * specified directory.
58113
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    40
 *
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    41
 * Linux:
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    42
 *
58648
3bf53ffa9ae7 8232279 : Improve test helpers #2
herrick
parents: 58464
diff changeset
    43
 * Application should be installed in /opt/jpackage/commoninstalldirtest folder.
58113
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    44
 *
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    45
 * Mac:
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    46
 *
58648
3bf53ffa9ae7 8232279 : Improve test helpers #2
herrick
parents: 58464
diff changeset
    47
 * Application should be installed in /Applications/jpackage/commoninstalldirtest.app
58113
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    48
 * folder.
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    49
 *
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    50
 * Windows:
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    51
 *
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    52
 * Application should be installed in %ProgramFiles%/TestVendor/InstallDirTest1234
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    53
 * folder.
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    54
 */
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    55
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    56
/*
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    57
 * @test
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    58
 * @summary jpackage with --install-dir
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    59
 * @library ../helpers
58761
88e2753a2334 8231972: Build a stable list of jpackager tests for SQE
herrick
parents: 58648
diff changeset
    60
 * @key jpackagePlatformPackage
58416
f09bf58c1f17 8231605: Improve test helpers
herrick
parents: 58301
diff changeset
    61
 * @build jdk.jpackage.test.*
58434
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    62
 * @compile InstallDirTest.java
58994
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents: 58888
diff changeset
    63
 * @modules jdk.incubator.jpackage/jdk.incubator.jpackage.internal
58464
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents: 58434
diff changeset
    64
 * @run main/othervm/timeout=540 -Xmx512m jdk.jpackage.test.Main
58434
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    65
 *  --jpt-run=InstallDirTest.testCommon
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    66
 */
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    67
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    68
/*
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    69
 * @test
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    70
 * @summary jpackage with --install-dir
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    71
 * @library ../helpers
58761
88e2753a2334 8231972: Build a stable list of jpackager tests for SQE
herrick
parents: 58648
diff changeset
    72
 * @key jpackagePlatformPackage
58434
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    73
 * @build jdk.jpackage.test.*
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    74
 * @compile InstallDirTest.java
58994
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents: 58888
diff changeset
    75
 * @modules jdk.incubator.jpackage/jdk.incubator.jpackage.internal
58434
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    76
 * @requires (os.family == "linux")
58761
88e2753a2334 8231972: Build a stable list of jpackager tests for SQE
herrick
parents: 58648
diff changeset
    77
 * @requires (jpackage.test.SQETest == null)
58434
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    78
 * @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    79
 *  --jpt-run=InstallDirTest.testLinuxInvalid,testLinuxUnsupported
58113
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    80
 */
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    81
public class InstallDirTest {
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    82
58434
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    83
    public static void testCommon() {
58416
f09bf58c1f17 8231605: Improve test helpers
herrick
parents: 58301
diff changeset
    84
        final Map<PackageType, Path> INSTALL_DIRS = Functional.identity(() -> {
f09bf58c1f17 8231605: Improve test helpers
herrick
parents: 58301
diff changeset
    85
            Map<PackageType, Path> reply = new HashMap<>();
f09bf58c1f17 8231605: Improve test helpers
herrick
parents: 58301
diff changeset
    86
            reply.put(PackageType.WIN_MSI, Path.of("TestVendor\\InstallDirTest1234"));
f09bf58c1f17 8231605: Improve test helpers
herrick
parents: 58301
diff changeset
    87
            reply.put(PackageType.WIN_EXE, reply.get(PackageType.WIN_MSI));
f09bf58c1f17 8231605: Improve test helpers
herrick
parents: 58301
diff changeset
    88
f09bf58c1f17 8231605: Improve test helpers
herrick
parents: 58301
diff changeset
    89
            reply.put(PackageType.LINUX_DEB, Path.of("/opt/jpackage"));
f09bf58c1f17 8231605: Improve test helpers
herrick
parents: 58301
diff changeset
    90
            reply.put(PackageType.LINUX_RPM, reply.get(PackageType.LINUX_DEB));
58113
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    91
58888
d802578912f3 8232186 : Add verification for pkg and dmg tests
herrick
parents: 58761
diff changeset
    92
            reply.put(PackageType.MAC_PKG, Path.of("/Applications/jpackage"));
58113
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    93
58416
f09bf58c1f17 8231605: Improve test helpers
herrick
parents: 58301
diff changeset
    94
            return reply;
f09bf58c1f17 8231605: Improve test helpers
herrick
parents: 58301
diff changeset
    95
        }).get();
58113
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    96
58888
d802578912f3 8232186 : Add verification for pkg and dmg tests
herrick
parents: 58761
diff changeset
    97
        new PackageTest().excludeTypes(PackageType.MAC_DMG).configureHelloApp()
58434
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    98
        .addInitializer(cmd -> {
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    99
            cmd.addArguments("--install-dir", INSTALL_DIRS.get(
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   100
                    cmd.packageType()));
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   101
        }).run();
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   102
    }
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   103
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   104
    @Parameter("/")
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   105
    @Parameter(".")
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   106
    @Parameter("foo")
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   107
    @Parameter("/opt/foo/.././.")
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   108
    public static void testLinuxInvalid(String installDir) {
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   109
        testLinuxBad(installDir, "Invalid installation directory");
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   110
    }
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   111
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   112
    @Parameter("/usr")
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   113
    @Parameter("/usr/local")
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   114
    @Parameter("/usr/foo")
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   115
    public static void testLinuxUnsupported(String installDir) {
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   116
        testLinuxBad(installDir, "currently unsupported");
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   117
    }
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   118
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   119
    private static void testLinuxBad(String installDir,
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   120
            String errorMessageSubstring) {
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   121
        new PackageTest().configureHelloApp()
58648
3bf53ffa9ae7 8232279 : Improve test helpers #2
herrick
parents: 58464
diff changeset
   122
        .setExpectedExitCode(1)
3bf53ffa9ae7 8232279 : Improve test helpers #2
herrick
parents: 58464
diff changeset
   123
        .forTypes(PackageType.LINUX)
3bf53ffa9ae7 8232279 : Improve test helpers #2
herrick
parents: 58464
diff changeset
   124
        .addInitializer(cmd -> {
3bf53ffa9ae7 8232279 : Improve test helpers #2
herrick
parents: 58464
diff changeset
   125
            cmd.addArguments("--install-dir", installDir);
3bf53ffa9ae7 8232279 : Improve test helpers #2
herrick
parents: 58464
diff changeset
   126
            cmd.saveConsoleOutput(true);
3bf53ffa9ae7 8232279 : Improve test helpers #2
herrick
parents: 58464
diff changeset
   127
        })
3bf53ffa9ae7 8232279 : Improve test helpers #2
herrick
parents: 58464
diff changeset
   128
        .addBundleVerifier((cmd, result) -> {
3bf53ffa9ae7 8232279 : Improve test helpers #2
herrick
parents: 58464
diff changeset
   129
            String errorMessage = JPackageCommand.filterOutput(
3bf53ffa9ae7 8232279 : Improve test helpers #2
herrick
parents: 58464
diff changeset
   130
                    result.getOutput().stream()).filter(line -> line.contains(
3bf53ffa9ae7 8232279 : Improve test helpers #2
herrick
parents: 58464
diff changeset
   131
                    errorMessageSubstring)).findFirst().orElse(null);
3bf53ffa9ae7 8232279 : Improve test helpers #2
herrick
parents: 58464
diff changeset
   132
            TKit.assertNotNull(errorMessage, String.format(
3bf53ffa9ae7 8232279 : Improve test helpers #2
herrick
parents: 58464
diff changeset
   133
                    "Check output contains [%s] substring",
3bf53ffa9ae7 8232279 : Improve test helpers #2
herrick
parents: 58464
diff changeset
   134
                    errorMessageSubstring));
3bf53ffa9ae7 8232279 : Improve test helpers #2
herrick
parents: 58464
diff changeset
   135
        })
3bf53ffa9ae7 8232279 : Improve test helpers #2
herrick
parents: 58464
diff changeset
   136
        .run();
58113
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
   137
    }
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
   138
}