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 JPackageCreateAppImageArgumentsBase {
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 = "argument";
36 private static final String ARGUMENT2 = "Some Arguments";
37 private static final String ARGUMENT3 = "Value \"with\" quotes";
38
39 private static final String ARGUMENT_CMD1 = "test";
40
41 private static final List<String> arguments = new ArrayList<>();
42 private static final List<String> argumentsCmd = new ArrayList<>();
43
44 public static void initArguments(boolean toolProvider, String[] cmd) {
45 if (arguments.isEmpty()) {
46 arguments.add(ARGUMENT1);
47 arguments.add(ARGUMENT2);
48 arguments.add(ARGUMENT3);
49 }
50
51 if (argumentsCmd.isEmpty()) {
52 argumentsCmd.add(ARGUMENT_CMD1);
53 }
79 "Unexpected result[" + index + "]: " + result[index]);
80 }
81 index++;
82 }
83 }
84
85 private static void validate(String arg, List<String> expectedArgs)
86 throws Exception {
87 int retVal;
88
89 if (arg == null) {
90 retVal = JPackageHelper.execute(null, app);
91 } else {
92 retVal = JPackageHelper.execute(null, app, arg);
93 }
94 if (retVal != 0) {
95 throw new AssertionError("Test application exited with error: "
96 + retVal);
97 }
98
99 File outfile = new File(appWorkingDir + File.separator + appOutput);
100 if (!outfile.exists()) {
101 throw new AssertionError(appOutput + " was not created");
102 }
103
104 String output = Files.readString(outfile.toPath());
105 String[] result = output.split("\n");
106 validateResult(result, expectedArgs);
107 }
108
109 public static void testCreateAppImage(String[] cmd) throws Exception {
110 initArguments(false, cmd);
111 JPackageHelper.executeCLI(true, cmd);
112 validate(null, arguments);
113 validate(ARGUMENT_CMD1, argumentsCmd);
114 }
115
116 public static void testCreateAppImageToolProvider(String[] cmd) throws Exception {
117 initArguments(true, cmd);
118 JPackageHelper.executeToolProvider(true, cmd);
119 validate(null, arguments);
|
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 JPackageCreateAppImageArgumentsBase {
30
31 private static final String app = JPackagePath.getApp();
32 private static final String appOutput = JPackagePath.getAppOutputFile();
33
34 private static final String ARGUMENT1 = "argument";
35 private static final String ARGUMENT2 = "Some Arguments";
36 private static final String ARGUMENT3 = "Value \"with\" quotes";
37
38 private static final String ARGUMENT_CMD1 = "test";
39
40 private static final List<String> arguments = new ArrayList<>();
41 private static final List<String> argumentsCmd = new ArrayList<>();
42
43 public static void initArguments(boolean toolProvider, String[] cmd) {
44 if (arguments.isEmpty()) {
45 arguments.add(ARGUMENT1);
46 arguments.add(ARGUMENT2);
47 arguments.add(ARGUMENT3);
48 }
49
50 if (argumentsCmd.isEmpty()) {
51 argumentsCmd.add(ARGUMENT_CMD1);
52 }
78 "Unexpected result[" + index + "]: " + result[index]);
79 }
80 index++;
81 }
82 }
83
84 private static void validate(String arg, List<String> expectedArgs)
85 throws Exception {
86 int retVal;
87
88 if (arg == null) {
89 retVal = JPackageHelper.execute(null, app);
90 } else {
91 retVal = JPackageHelper.execute(null, app, arg);
92 }
93 if (retVal != 0) {
94 throw new AssertionError("Test application exited with error: "
95 + retVal);
96 }
97
98 File outfile = new File(appOutput);
99 if (!outfile.exists()) {
100 throw new AssertionError(appOutput + " was not created");
101 }
102
103 String output = Files.readString(outfile.toPath());
104 String[] result = output.split("\n");
105 validateResult(result, expectedArgs);
106 }
107
108 public static void testCreateAppImage(String[] cmd) throws Exception {
109 initArguments(false, cmd);
110 JPackageHelper.executeCLI(true, cmd);
111 validate(null, arguments);
112 validate(ARGUMENT_CMD1, argumentsCmd);
113 }
114
115 public static void testCreateAppImageToolProvider(String[] cmd) throws Exception {
116 initArguments(true, cmd);
117 JPackageHelper.executeToolProvider(true, cmd);
118 validate(null, arguments);
|