Path: blob/master/test/jdk/tools/jpackage/share/InstallDirTest.java
41149 views
/*1* Copyright (c) 2018, 2020, 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*/2223import java.nio.file.Path;24import java.util.HashMap;25import java.util.Map;26import jdk.jpackage.test.TKit;27import jdk.jpackage.test.PackageTest;28import jdk.jpackage.test.PackageType;29import jdk.jpackage.test.Functional;30import jdk.jpackage.test.Annotations.Parameter;3132/**33* Test --install-dir parameter. Output of the test should be34* commoninstalldirtest*.* package bundle. The output package should provide the35* same functionality as the default package but install test application in36* specified directory.37*38* Linux:39*40* Application should be installed in /opt/jpackage/commoninstalldirtest folder.41*42* Mac:43*44* Application should be installed in /Applications/jpackage/commoninstalldirtest.app45* folder.46*47* Windows:48*49* Application should be installed in %ProgramFiles%/TestVendor/InstallDirTest123450* folder.51*/5253/*54* @test55* @summary jpackage with --install-dir56* @library ../helpers57* @key jpackagePlatformPackage58* @build jdk.jpackage.test.*59* @compile InstallDirTest.java60* @modules jdk.jpackage/jdk.jpackage.internal61* @run main/othervm/timeout=540 -Xmx512m jdk.jpackage.test.Main62* --jpt-run=InstallDirTest.testCommon63*/6465/*66* @test67* @summary jpackage with --install-dir68* @library ../helpers69* @key jpackagePlatformPackage70* @build jdk.jpackage.test.*71* @compile InstallDirTest.java72* @modules jdk.jpackage/jdk.jpackage.internal73* @requires (os.family == "linux")74* @requires (jpackage.test.SQETest == null)75* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main76* --jpt-run=InstallDirTest.testLinuxInvalid77*/78public class InstallDirTest {7980public static void testCommon() {81final Map<PackageType, Path> INSTALL_DIRS = Functional.identity(() -> {82Map<PackageType, Path> reply = new HashMap<>();83reply.put(PackageType.WIN_MSI, Path.of("TestVendor\\InstallDirTest1234"));84reply.put(PackageType.WIN_EXE, reply.get(PackageType.WIN_MSI));8586reply.put(PackageType.LINUX_DEB, Path.of("/opt/jpackage"));87reply.put(PackageType.LINUX_RPM, reply.get(PackageType.LINUX_DEB));8889reply.put(PackageType.MAC_PKG, Path.of("/Applications/jpackage"));90reply.put(PackageType.MAC_DMG, reply.get(PackageType.MAC_PKG));9192return reply;93}).get();9495new PackageTest().configureHelloApp()96.addInitializer(cmd -> {97cmd.addArguments("--install-dir", INSTALL_DIRS.get(98cmd.packageType()));99}).run();100}101102@Parameter("/")103@Parameter(".")104@Parameter("foo")105@Parameter("/opt/foo/.././.")106public static void testLinuxInvalid(String installDir) {107testLinuxBad(installDir, "Invalid installation directory");108}109110private static void testLinuxBad(String installDir,111String errorMessageSubstring) {112new PackageTest().configureHelloApp()113.setExpectedExitCode(1)114.forTypes(PackageType.LINUX)115.addInitializer(cmd -> {116cmd.addArguments("--install-dir", installDir);117cmd.saveConsoleOutput(true);118})119.addBundleVerifier((cmd, result) -> {120TKit.assertTextStream(errorMessageSubstring).apply(121result.getOutput().stream());122})123.run();124}125}126127128