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.File;
25 import java.nio.file.Files;
26 import java.util.ArrayList;
27 import java.util.List;
28
29 public class JPackageCreateAppImageJavaOptionsBase {
30
31 private static final String app = JPackagePath.getApp();
32 private static final String appOutput = JPackagePath.getAppOutputFile();
33 private static final String appWorkingDir = JPackagePath.getAppWorkingDir();
34
35 private static final String ARGUMENT1 = "-Dparam1=Some Param 1";
36 private static final String ARGUMENT2 = "-Dparam2=Some \"Param\" 2";
37 private static final String ARGUMENT3 =
38 "-Dparam3=Some \"Param\" with \" 3";
39
40 private static final List<String> arguments = new ArrayList<>();
41
42 private static void initArguments(boolean toolProvider, String [] cmd) {
43 if (arguments.isEmpty()) {
44 arguments.add(ARGUMENT1);
45 arguments.add(ARGUMENT2);
46 arguments.add(ARGUMENT3);
47 }
48
49 String argumentsMap = JPackageHelper.listToArgumentsMap(arguments,
50 toolProvider);
51 cmd[cmd.length - 1] = argumentsMap;
52 }
53
96 throw new AssertionError("Unexpected result[1]: " + result[1]);
97 }
98
99 int index = 2;
100 for (String arg : args) {
101 if (!result[index].trim().equals(arg)) {
102 throw new AssertionError("Unexpected result[" + index + "]: "
103 + result[index]);
104 }
105 index++;
106 }
107 }
108
109 private static void validate(List<String> expectedArgs) throws Exception {
110 int retVal = JPackageHelper.execute(null, app);
111 if (retVal != 0) {
112 throw new AssertionError("Test application exited with error: "
113 + retVal);
114 }
115
116 File outfile = new File(appWorkingDir + File.separator + appOutput);
117 if (!outfile.exists()) {
118 throw new AssertionError(appOutput + " was not created");
119 }
120
121 String output = Files.readString(outfile.toPath());
122 String[] result = JPackageHelper.splitAndFilter(output);
123 validateResult(result, expectedArgs);
124 }
125
126 public static void testCreateAppImageJavaOptions(String [] cmd) throws Exception {
127 initArguments(false, cmd);
128 JPackageHelper.executeCLI(true, cmd);
129 validate(arguments);
130 }
131
132 public static void testCreateAppImageJavaOptionsToolProvider(String [] cmd) throws Exception {
133 initArguments(true, cmd);
134 JPackageHelper.executeToolProvider(true, cmd);
135 validate(arguments);
136 }
|
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.File;
25 import java.nio.file.Files;
26 import java.util.ArrayList;
27 import java.util.List;
28
29 public class JPackageCreateAppImageJavaOptionsBase {
30
31 private static final String app = JPackagePath.getApp();
32 private static final String appOutput = JPackagePath.getAppOutputFile();
33
34 private static final String ARGUMENT1 = "-Dparam1=Some Param 1";
35 private static final String ARGUMENT2 = "-Dparam2=Some \"Param\" 2";
36 private static final String ARGUMENT3 =
37 "-Dparam3=Some \"Param\" with \" 3";
38
39 private static final List<String> arguments = new ArrayList<>();
40
41 private static void initArguments(boolean toolProvider, String [] cmd) {
42 if (arguments.isEmpty()) {
43 arguments.add(ARGUMENT1);
44 arguments.add(ARGUMENT2);
45 arguments.add(ARGUMENT3);
46 }
47
48 String argumentsMap = JPackageHelper.listToArgumentsMap(arguments,
49 toolProvider);
50 cmd[cmd.length - 1] = argumentsMap;
51 }
52
95 throw new AssertionError("Unexpected result[1]: " + result[1]);
96 }
97
98 int index = 2;
99 for (String arg : args) {
100 if (!result[index].trim().equals(arg)) {
101 throw new AssertionError("Unexpected result[" + index + "]: "
102 + result[index]);
103 }
104 index++;
105 }
106 }
107
108 private static void validate(List<String> expectedArgs) throws Exception {
109 int retVal = JPackageHelper.execute(null, app);
110 if (retVal != 0) {
111 throw new AssertionError("Test application exited with error: "
112 + retVal);
113 }
114
115 File outfile = new File(appOutput);
116 if (!outfile.exists()) {
117 throw new AssertionError(appOutput + " was not created");
118 }
119
120 String output = Files.readString(outfile.toPath());
121 String[] result = JPackageHelper.splitAndFilter(output);
122 validateResult(result, expectedArgs);
123 }
124
125 public static void testCreateAppImageJavaOptions(String [] cmd) throws Exception {
126 initArguments(false, cmd);
127 JPackageHelper.executeCLI(true, cmd);
128 validate(arguments);
129 }
130
131 public static void testCreateAppImageJavaOptionsToolProvider(String [] cmd) throws Exception {
132 initArguments(true, cmd);
133 JPackageHelper.executeToolProvider(true, cmd);
134 validate(arguments);
135 }
|