author | herrick |
Thu, 06 Jun 2019 19:31:11 -0400 | |
branch | JDK-8200758-branch |
changeset 57395 | 521c02b9eed0 |
parent 57330 | a30edd277572 |
child 57445 | 405ddd80496e |
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 |
||
24 |
import java.io.BufferedWriter; |
|
25 |
import java.io.File; |
|
26 |
import java.io.FileWriter; |
|
27 |
import java.io.PrintWriter; |
|
28 |
import java.nio.file.Files; |
|
29 |
import java.util.ArrayList; |
|
30 |
import java.util.List; |
|
31 |
||
32 |
public class JPackageCreateAppImageAddLauncherBase { |
|
33 |
private static final String app = JPackagePath.getApp(); |
|
34 |
private static final String appOutput = JPackagePath.getAppOutputFile(); |
|
35 |
private static final String appWorkingDir = JPackagePath.getAppWorkingDir(); |
|
36 |
||
37 |
// Note: quotes in argument for add launcher is not support by test |
|
38 |
private static final String ARGUMENT1 = "argument 1"; |
|
39 |
private static final String ARGUMENT2 = "argument 2"; |
|
40 |
private static final String ARGUMENT3 = "argument 3"; |
|
41 |
||
42 |
private static final List<String> arguments = new ArrayList<>(); |
|
43 |
||
44 |
private static final String PARAM1 = "-Dparam1=Some Param 1"; |
|
45 |
private static final String PARAM2 = "-Dparam2=Some Param 2"; |
|
46 |
private static final String PARAM3 = "-Dparam3=Some Param 3"; |
|
47 |
||
48 |
private static final List<String> vmArguments = new ArrayList<>(); |
|
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
49 |
private static final List<String> empty = new ArrayList<>(); |
57307 | 50 |
|
51 |
private static void validateResult(List<String> args, List<String> vmArgs) |
|
52 |
throws Exception { |
|
53 |
File outfile = new File(appWorkingDir + File.separator + appOutput); |
|
54 |
if (!outfile.exists()) { |
|
55 |
throw new AssertionError(appOutput + " was not created"); |
|
56 |
} |
|
57 |
||
58 |
String output = Files.readString(outfile.toPath()); |
|
59 |
String[] result = output.split("\n"); |
|
60 |
||
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
61 |
int expected = 2 + args.size() + vmArgs.size(); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
62 |
|
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
63 |
if (result.length != expected) { |
57307 | 64 |
throw new AssertionError("Unexpected number of lines: " |
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
65 |
+ result.length + " expected: " + expected + " - results: " + output); |
57307 | 66 |
} |
67 |
||
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
68 |
if (!result[0].trim().endsWith("jpackage test application")) { |
57307 | 69 |
throw new AssertionError("Unexpected result[0]: " + result[0]); |
70 |
} |
|
71 |
||
72 |
if (!result[1].trim().equals("args.length: " + args.size())) { |
|
73 |
throw new AssertionError("Unexpected result[1]: " + result[1]); |
|
74 |
} |
|
75 |
||
76 |
int index = 2; |
|
77 |
for (String arg : args) { |
|
78 |
if (!result[index].trim().equals(arg)) { |
|
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
79 |
throw new AssertionError("Unexpected result[" |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
80 |
+ index + "]: " + result[index]); |
57307 | 81 |
} |
82 |
index++; |
|
83 |
} |
|
84 |
||
85 |
for (String vmArg : vmArgs) { |
|
86 |
if (!result[index].trim().equals(vmArg)) { |
|
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
87 |
throw new AssertionError("Unexpected result[" |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
88 |
+ index + "]: " + result[index]); |
57307 | 89 |
} |
90 |
index++; |
|
91 |
} |
|
92 |
} |
|
93 |
||
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
94 |
private static void validate(boolean includeArgs, String name) |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
95 |
throws Exception { |
57307 | 96 |
int retVal = JPackageHelper.execute(null, app); |
97 |
if (retVal != 0) { |
|
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
98 |
throw new AssertionError("Test application " + app |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
99 |
+ " exited with error: " + retVal); |
57307 | 100 |
} |
101 |
validateResult(new ArrayList<>(), new ArrayList<>()); |
|
102 |
||
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
103 |
String app2 = JPackagePath.getAppSL(name); |
57307 | 104 |
retVal = JPackageHelper.execute(null, app2); |
105 |
if (retVal != 0) { |
|
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
106 |
throw new AssertionError("Test application " + app2 |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
107 |
+ " exited with error: " + retVal); |
57307 | 108 |
} |
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
109 |
if (includeArgs) { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
110 |
validateResult(arguments, vmArguments); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
111 |
} else { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
112 |
validateResult(empty, empty); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
113 |
} |
57307 | 114 |
} |
115 |
||
116 |
public static void testCreateAppImage(String [] cmd) throws Exception { |
|
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
117 |
testCreateAppImage(cmd, true, "test2"); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
118 |
} |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
119 |
|
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
120 |
public static void testCreateAppImage(String [] cmd, |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
121 |
boolean includeArgs, String name) throws Exception { |
57307 | 122 |
JPackageHelper.executeCLI(true, cmd); |
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
123 |
validate(includeArgs, name); |
57307 | 124 |
} |
125 |
||
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
126 |
public static void testCreateAppImageToolProvider(String [] cmd) |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
127 |
throws Exception { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
128 |
testCreateAppImageToolProvider(cmd, true, "test2"); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
129 |
} |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
130 |
|
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
131 |
public static void testCreateAppImageToolProvider(String [] cmd, |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
132 |
boolean includeArgs, String name) throws Exception { |
57307 | 133 |
JPackageHelper.executeToolProvider(true, cmd); |
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
134 |
validate(includeArgs, name); |
57307 | 135 |
} |
136 |
||
137 |
public static void createSLProperties() throws Exception { |
|
138 |
arguments.add(ARGUMENT1); |
|
139 |
arguments.add(ARGUMENT2); |
|
140 |
arguments.add(ARGUMENT3); |
|
141 |
||
142 |
String argumentsMap = |
|
143 |
JPackageHelper.listToArgumentsMap(arguments, true); |
|
144 |
||
145 |
vmArguments.add(PARAM1); |
|
146 |
vmArguments.add(PARAM2); |
|
147 |
vmArguments.add(PARAM3); |
|
148 |
||
149 |
String vmArgumentsMap = |
|
150 |
JPackageHelper.listToArgumentsMap(vmArguments, true); |
|
151 |
||
152 |
try (PrintWriter out = new PrintWriter(new BufferedWriter( |
|
153 |
new FileWriter("sl.properties")))) { |
|
154 |
out.println("arguments=" + argumentsMap); |
|
155 |
out.println("java-options=" + vmArgumentsMap); |
|
156 |
} |
|
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
157 |
|
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
158 |
try (PrintWriter out = new PrintWriter(new BufferedWriter( |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
159 |
new FileWriter("m1.properties")))) { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
160 |
out.println("module=com.hello/com.hello.Hello"); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
161 |
out.println("main-jar="); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
162 |
} |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
163 |
|
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
164 |
try (PrintWriter out = new PrintWriter(new BufferedWriter( |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
165 |
new FileWriter("j1.properties")))) { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
166 |
out.println("main-jar hello.jar"); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
167 |
out.println("main-class Hello"); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
168 |
} |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
169 |
|
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
170 |
|
57307 | 171 |
} |
172 |
||
173 |
} |