test/jdk/tools/jpackage/share/InstallDirTest.java
author herrick
Wed, 16 Oct 2019 10:32:08 -0400
branchJDK-8200758-branch
changeset 58648 3bf53ffa9ae7
parent 58464 d82489644b15
child 58761 88e2753a2334
permissions -rw-r--r--
8232279 : Improve test helpers #2 Submitted-by: asemenyuk Reviewed-by: aherrick, almatvee
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
58416
f09bf58c1f17 8231605: Improve test helpers
herrick
parents: 58301
diff changeset
    60
 * @build jdk.jpackage.test.*
58434
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    61
 * @compile InstallDirTest.java
58113
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    62
 * @modules jdk.jpackage/jdk.jpackage.internal
58464
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents: 58434
diff changeset
    63
 * @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
    64
 *  --jpt-run=InstallDirTest.testCommon
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    65
 */
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
 * @test
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    69
 * @summary jpackage with --install-dir
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    70
 * @library ../helpers
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    71
 * @build jdk.jpackage.test.*
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    72
 * @compile InstallDirTest.java
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    73
 * @modules jdk.jpackage/jdk.jpackage.internal
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    74
 * @requires (os.family == "linux")
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    75
 * @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
    76
 *  --jpt-run=InstallDirTest.testLinuxInvalid,testLinuxUnsupported
58113
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    77
 */
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    78
public class InstallDirTest {
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    79
58434
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    80
    public static void testCommon() {
58416
f09bf58c1f17 8231605: Improve test helpers
herrick
parents: 58301
diff changeset
    81
        final Map<PackageType, Path> INSTALL_DIRS = Functional.identity(() -> {
f09bf58c1f17 8231605: Improve test helpers
herrick
parents: 58301
diff changeset
    82
            Map<PackageType, Path> reply = new HashMap<>();
f09bf58c1f17 8231605: Improve test helpers
herrick
parents: 58301
diff changeset
    83
            reply.put(PackageType.WIN_MSI, Path.of("TestVendor\\InstallDirTest1234"));
f09bf58c1f17 8231605: Improve test helpers
herrick
parents: 58301
diff changeset
    84
            reply.put(PackageType.WIN_EXE, reply.get(PackageType.WIN_MSI));
f09bf58c1f17 8231605: Improve test helpers
herrick
parents: 58301
diff changeset
    85
f09bf58c1f17 8231605: Improve test helpers
herrick
parents: 58301
diff changeset
    86
            reply.put(PackageType.LINUX_DEB, Path.of("/opt/jpackage"));
f09bf58c1f17 8231605: Improve test helpers
herrick
parents: 58301
diff changeset
    87
            reply.put(PackageType.LINUX_RPM, reply.get(PackageType.LINUX_DEB));
58113
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    88
58416
f09bf58c1f17 8231605: Improve test helpers
herrick
parents: 58301
diff changeset
    89
            reply.put(PackageType.MAC_PKG, Path.of("/Application/jpackage"));
f09bf58c1f17 8231605: Improve test helpers
herrick
parents: 58301
diff changeset
    90
            reply.put(PackageType.MAC_DMG, reply.get(PackageType.MAC_PKG));
58113
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    91
58416
f09bf58c1f17 8231605: Improve test helpers
herrick
parents: 58301
diff changeset
    92
            return reply;
f09bf58c1f17 8231605: Improve test helpers
herrick
parents: 58301
diff changeset
    93
        }).get();
58113
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    94
58434
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    95
        new PackageTest().configureHelloApp()
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    96
        .addInitializer(cmd -> {
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    97
            cmd.addArguments("--install-dir", INSTALL_DIRS.get(
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    98
                    cmd.packageType()));
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    99
        }).run();
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   100
    }
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   101
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   102
    @Parameter("/")
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   103
    @Parameter(".")
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   104
    @Parameter("foo")
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   105
    @Parameter("/opt/foo/.././.")
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   106
    public static void testLinuxInvalid(String installDir) {
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   107
        testLinuxBad(installDir, "Invalid installation directory");
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   108
    }
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   109
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   110
    @Parameter("/usr")
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   111
    @Parameter("/usr/local")
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   112
    @Parameter("/usr/foo")
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   113
    public static void testLinuxUnsupported(String installDir) {
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   114
        testLinuxBad(installDir, "currently unsupported");
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   115
    }
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   116
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   117
    private static void testLinuxBad(String installDir,
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   118
            String errorMessageSubstring) {
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   119
        new PackageTest().configureHelloApp()
58648
3bf53ffa9ae7 8232279 : Improve test helpers #2
herrick
parents: 58464
diff changeset
   120
        .setExpectedExitCode(1)
3bf53ffa9ae7 8232279 : Improve test helpers #2
herrick
parents: 58464
diff changeset
   121
        .forTypes(PackageType.LINUX)
3bf53ffa9ae7 8232279 : Improve test helpers #2
herrick
parents: 58464
diff changeset
   122
        .addInitializer(cmd -> {
3bf53ffa9ae7 8232279 : Improve test helpers #2
herrick
parents: 58464
diff changeset
   123
            cmd.addArguments("--install-dir", installDir);
3bf53ffa9ae7 8232279 : Improve test helpers #2
herrick
parents: 58464
diff changeset
   124
            cmd.saveConsoleOutput(true);
3bf53ffa9ae7 8232279 : Improve test helpers #2
herrick
parents: 58464
diff changeset
   125
        })
3bf53ffa9ae7 8232279 : Improve test helpers #2
herrick
parents: 58464
diff changeset
   126
        .addBundleVerifier((cmd, result) -> {
3bf53ffa9ae7 8232279 : Improve test helpers #2
herrick
parents: 58464
diff changeset
   127
            String errorMessage = JPackageCommand.filterOutput(
3bf53ffa9ae7 8232279 : Improve test helpers #2
herrick
parents: 58464
diff changeset
   128
                    result.getOutput().stream()).filter(line -> line.contains(
3bf53ffa9ae7 8232279 : Improve test helpers #2
herrick
parents: 58464
diff changeset
   129
                    errorMessageSubstring)).findFirst().orElse(null);
3bf53ffa9ae7 8232279 : Improve test helpers #2
herrick
parents: 58464
diff changeset
   130
            TKit.assertNotNull(errorMessage, String.format(
3bf53ffa9ae7 8232279 : Improve test helpers #2
herrick
parents: 58464
diff changeset
   131
                    "Check output contains [%s] substring",
3bf53ffa9ae7 8232279 : Improve test helpers #2
herrick
parents: 58464
diff changeset
   132
                    errorMessageSubstring));
3bf53ffa9ae7 8232279 : Improve test helpers #2
herrick
parents: 58464
diff changeset
   133
        })
3bf53ffa9ae7 8232279 : Improve test helpers #2
herrick
parents: 58464
diff changeset
   134
        .run();
58113
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
   135
    }
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
   136
}