author | herrick |
Fri, 08 Nov 2019 14:53:03 -0500 | |
branch | JDK-8200758-branch |
changeset 58994 | b09ba68c6a19 |
parent 58888 | d802578912f3 |
permissions | -rw-r--r-- |
58113 | 1 |
/* |
2 |
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
import java.nio.file.Path; |
|
25 |
import java.util.HashMap; |
|
26 |
import java.util.Map; |
|
27 |
import java.util.function.Supplier; |
|
58416 | 28 |
import jdk.jpackage.test.TKit; |
58113 | 29 |
import jdk.jpackage.test.PackageTest; |
30 |
import jdk.jpackage.test.PackageType; |
|
58416 | 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 | 34 |
|
35 |
/** |
|
58648 | 36 |
* Test --install-dir parameter. Output of the test should be |
37 |
* commoninstalldirtest*.* package bundle. The output package should provide the |
|
38 |
* same functionality as the default package but install test application in |
|
39 |
* specified directory. |
|
58113 | 40 |
* |
41 |
* Linux: |
|
42 |
* |
|
58648 | 43 |
* Application should be installed in /opt/jpackage/commoninstalldirtest folder. |
58113 | 44 |
* |
45 |
* Mac: |
|
46 |
* |
|
58648 | 47 |
* Application should be installed in /Applications/jpackage/commoninstalldirtest.app |
58113 | 48 |
* folder. |
49 |
* |
|
50 |
* Windows: |
|
51 |
* |
|
52 |
* Application should be installed in %ProgramFiles%/TestVendor/InstallDirTest1234 |
|
53 |
* folder. |
|
54 |
*/ |
|
55 |
||
56 |
/* |
|
57 |
* @test |
|
58 |
* @summary jpackage with --install-dir |
|
59 |
* @library ../helpers |
|
58761
88e2753a2334
8231972: Build a stable list of jpackager tests for SQE
herrick
parents:
58648
diff
changeset
|
60 |
* @key jpackagePlatformPackage |
58416 | 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 | 80 |
*/ |
81 |
public class InstallDirTest { |
|
82 |
||
58434
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
83 |
public static void testCommon() { |
58416 | 84 |
final Map<PackageType, Path> INSTALL_DIRS = Functional.identity(() -> { |
85 |
Map<PackageType, Path> reply = new HashMap<>(); |
|
86 |
reply.put(PackageType.WIN_MSI, Path.of("TestVendor\\InstallDirTest1234")); |
|
87 |
reply.put(PackageType.WIN_EXE, reply.get(PackageType.WIN_MSI)); |
|
88 |
||
89 |
reply.put(PackageType.LINUX_DEB, Path.of("/opt/jpackage")); |
|
90 |
reply.put(PackageType.LINUX_RPM, reply.get(PackageType.LINUX_DEB)); |
|
58113 | 91 |
|
58888 | 92 |
reply.put(PackageType.MAC_PKG, Path.of("/Applications/jpackage")); |
58113 | 93 |
|
58416 | 94 |
return reply; |
95 |
}).get(); |
|
58113 | 96 |
|
58888 | 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 | 122 |
.setExpectedExitCode(1) |
123 |
.forTypes(PackageType.LINUX) |
|
124 |
.addInitializer(cmd -> { |
|
125 |
cmd.addArguments("--install-dir", installDir); |
|
126 |
cmd.saveConsoleOutput(true); |
|
127 |
}) |
|
128 |
.addBundleVerifier((cmd, result) -> { |
|
129 |
String errorMessage = JPackageCommand.filterOutput( |
|
130 |
result.getOutput().stream()).filter(line -> line.contains( |
|
131 |
errorMessageSubstring)).findFirst().orElse(null); |
|
132 |
TKit.assertNotNull(errorMessage, String.format( |
|
133 |
"Check output contains [%s] substring", |
|
134 |
errorMessageSubstring)); |
|
135 |
}) |
|
136 |
.run(); |
|
58113 | 137 |
} |
138 |
} |