author | herrick |
Thu, 20 Jun 2019 14:13:50 -0400 | |
branch | JDK-8200758-branch |
changeset 57414 | 6eda749d3117 |
parent 57395 | 521c02b9eed0 |
permissions | -rw-r--r-- |
57307 | 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 |
||
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57307
diff
changeset
|
24 |
import java.io.File; |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57307
diff
changeset
|
25 |
import java.nio.file.Files; |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57307
diff
changeset
|
26 |
|
57307 | 27 |
/* |
28 |
* @test |
|
29 |
* @summary jpackage create image --app-version test |
|
30 |
* @library ../helpers |
|
31 |
* @build JPackageHelper |
|
32 |
* @build JPackagePath |
|
33 |
* @modules jdk.jpackage |
|
34 |
* @run main/othervm -Xmx512m JPackageCreateAppImageVersionTest |
|
35 |
*/ |
|
36 |
public class JPackageCreateAppImageVersionTest { |
|
37 |
private static final String OUTPUT = "output"; |
|
38 |
private static final String appCfg = JPackagePath.getAppCfg(); |
|
39 |
private static final String VERSION = "2.3"; |
|
40 |
private static final String VERSION_DEFAULT = "1.0"; |
|
41 |
||
42 |
private static final String[] CMD = { |
|
43 |
"--input", "input", |
|
44 |
"--output", OUTPUT, |
|
45 |
"--name", "test", |
|
46 |
"--main-jar", "hello.jar", |
|
47 |
"--main-class", "Hello", |
|
48 |
}; |
|
49 |
||
50 |
private static final String[] CMD_VERSION = { |
|
51 |
"--input", "input", |
|
52 |
"--output", OUTPUT, |
|
53 |
"--name", "test", |
|
54 |
"--main-jar", "hello.jar", |
|
55 |
"--main-class", "Hello", |
|
56 |
"--app-version", VERSION}; |
|
57 |
||
58 |
private static void validate(String version) |
|
59 |
throws Exception { |
|
60 |
File outfile = new File(appCfg); |
|
61 |
if (!outfile.exists()) { |
|
62 |
throw new AssertionError(appCfg + " was not created"); |
|
63 |
} |
|
64 |
||
65 |
String output = Files.readString(outfile.toPath()); |
|
66 |
if (version == null) { |
|
67 |
version = VERSION_DEFAULT; |
|
68 |
} |
|
69 |
||
70 |
String expected = "app.version=" + version; |
|
71 |
if (!output.contains(expected)) { |
|
72 |
System.err.println("Expected: " + expected); |
|
73 |
throw new AssertionError("Cannot find expected entry in config file"); |
|
74 |
} |
|
75 |
} |
|
76 |
||
77 |
private static void testVersion() throws Exception { |
|
78 |
JPackageHelper.executeCLI(true, CMD); |
|
79 |
validate(null); |
|
80 |
JPackageHelper.deleteOutputFolder(OUTPUT); |
|
81 |
JPackageHelper.executeCLI(true, CMD_VERSION); |
|
82 |
validate(VERSION); |
|
83 |
} |
|
84 |
||
85 |
private static void testVersionToolProvider() throws Exception { |
|
86 |
JPackageHelper.deleteOutputFolder(OUTPUT); |
|
87 |
JPackageHelper.executeToolProvider(true, CMD); |
|
88 |
validate(null); |
|
89 |
JPackageHelper.deleteOutputFolder(OUTPUT); |
|
90 |
JPackageHelper.executeToolProvider(true, CMD_VERSION); |
|
91 |
validate(VERSION); |
|
92 |
} |
|
93 |
||
94 |
public static void main(String[] args) throws Exception { |
|
95 |
JPackageHelper.createHelloImageJar(); |
|
96 |
testVersion(); |
|
97 |
testVersionToolProvider(); |
|
98 |
} |
|
99 |
||
100 |
} |