29 import java.util.ArrayList; |
29 import java.util.ArrayList; |
30 import java.util.List; |
30 import java.util.List; |
31 |
31 |
32 public class JPackageCreateAppImageAddLauncherBase { |
32 public class JPackageCreateAppImageAddLauncherBase { |
33 private static final String app = JPackagePath.getApp(); |
33 private static final String app = JPackagePath.getApp(); |
34 private static final String app2 = JPackagePath.getAppSL(); |
|
35 private static final String appOutput = JPackagePath.getAppOutputFile(); |
34 private static final String appOutput = JPackagePath.getAppOutputFile(); |
36 private static final String appWorkingDir = JPackagePath.getAppWorkingDir(); |
35 private static final String appWorkingDir = JPackagePath.getAppWorkingDir(); |
37 |
36 |
38 // Note: quotes in argument for add launcher is not support by test |
37 // Note: quotes in argument for add launcher is not support by test |
39 private static final String ARGUMENT1 = "argument 1"; |
38 private static final String ARGUMENT1 = "argument 1"; |
45 private static final String PARAM1 = "-Dparam1=Some Param 1"; |
44 private static final String PARAM1 = "-Dparam1=Some Param 1"; |
46 private static final String PARAM2 = "-Dparam2=Some Param 2"; |
45 private static final String PARAM2 = "-Dparam2=Some Param 2"; |
47 private static final String PARAM3 = "-Dparam3=Some Param 3"; |
46 private static final String PARAM3 = "-Dparam3=Some Param 3"; |
48 |
47 |
49 private static final List<String> vmArguments = new ArrayList<>(); |
48 private static final List<String> vmArguments = new ArrayList<>(); |
|
49 private static final List<String> empty = new ArrayList<>(); |
50 |
50 |
51 private static void validateResult(List<String> args, List<String> vmArgs) |
51 private static void validateResult(List<String> args, List<String> vmArgs) |
52 throws Exception { |
52 throws Exception { |
53 File outfile = new File(appWorkingDir + File.separator + appOutput); |
53 File outfile = new File(appWorkingDir + File.separator + appOutput); |
54 if (!outfile.exists()) { |
54 if (!outfile.exists()) { |
56 } |
56 } |
57 |
57 |
58 String output = Files.readString(outfile.toPath()); |
58 String output = Files.readString(outfile.toPath()); |
59 String[] result = output.split("\n"); |
59 String[] result = output.split("\n"); |
60 |
60 |
61 if (result.length != (args.size() + vmArgs.size() + 2)) { |
61 int expected = 2 + args.size() + vmArgs.size(); |
|
62 |
|
63 if (result.length != expected) { |
62 throw new AssertionError("Unexpected number of lines: " |
64 throw new AssertionError("Unexpected number of lines: " |
63 + result.length); |
65 + result.length + " expected: " + expected + " - results: " + output); |
64 } |
66 } |
65 |
67 |
66 if (!result[0].trim().equals("jpackage test application")) { |
68 if (!result[0].trim().endsWith("jpackage test application")) { |
67 throw new AssertionError("Unexpected result[0]: " + result[0]); |
69 throw new AssertionError("Unexpected result[0]: " + result[0]); |
68 } |
70 } |
69 |
71 |
70 if (!result[1].trim().equals("args.length: " + args.size())) { |
72 if (!result[1].trim().equals("args.length: " + args.size())) { |
71 throw new AssertionError("Unexpected result[1]: " + result[1]); |
73 throw new AssertionError("Unexpected result[1]: " + result[1]); |
72 } |
74 } |
73 |
75 |
74 int index = 2; |
76 int index = 2; |
75 for (String arg : args) { |
77 for (String arg : args) { |
76 if (!result[index].trim().equals(arg)) { |
78 if (!result[index].trim().equals(arg)) { |
77 throw new AssertionError("Unexpected result[" + index + "]: " |
79 throw new AssertionError("Unexpected result[" |
78 + result[index]); |
80 + index + "]: " + result[index]); |
79 } |
81 } |
80 index++; |
82 index++; |
81 } |
83 } |
82 |
84 |
83 for (String vmArg : vmArgs) { |
85 for (String vmArg : vmArgs) { |
84 if (!result[index].trim().equals(vmArg)) { |
86 if (!result[index].trim().equals(vmArg)) { |
85 throw new AssertionError("Unexpected result[" + index + "]: " |
87 throw new AssertionError("Unexpected result[" |
86 + result[index]); |
88 + index + "]: " + result[index]); |
87 } |
89 } |
88 index++; |
90 index++; |
89 } |
91 } |
90 } |
92 } |
91 |
93 |
92 private static void validate() throws Exception { |
94 private static void validate(boolean includeArgs, String name) |
|
95 throws Exception { |
93 int retVal = JPackageHelper.execute(null, app); |
96 int retVal = JPackageHelper.execute(null, app); |
94 if (retVal != 0) { |
97 if (retVal != 0) { |
95 throw new AssertionError("Test application exited with error: " |
98 throw new AssertionError("Test application " + app |
96 + retVal); |
99 + " exited with error: " + retVal); |
97 } |
100 } |
98 validateResult(new ArrayList<>(), new ArrayList<>()); |
101 validateResult(new ArrayList<>(), new ArrayList<>()); |
99 |
102 |
|
103 String app2 = JPackagePath.getAppSL(name); |
100 retVal = JPackageHelper.execute(null, app2); |
104 retVal = JPackageHelper.execute(null, app2); |
101 if (retVal != 0) { |
105 if (retVal != 0) { |
102 throw new AssertionError("Test application exited with error: " |
106 throw new AssertionError("Test application " + app2 |
103 + retVal); |
107 + " exited with error: " + retVal); |
104 } |
108 } |
105 validateResult(arguments, vmArguments); |
109 if (includeArgs) { |
|
110 validateResult(arguments, vmArguments); |
|
111 } else { |
|
112 validateResult(empty, empty); |
|
113 } |
106 } |
114 } |
107 |
115 |
108 public static void testCreateAppImage(String [] cmd) throws Exception { |
116 public static void testCreateAppImage(String [] cmd) throws Exception { |
109 JPackageHelper.executeCLI(true, cmd); |
117 testCreateAppImage(cmd, true, "test2"); |
110 validate(); |
|
111 } |
118 } |
112 |
119 |
113 public static void testCreateAppImageToolProvider(String [] cmd) throws Exception { |
120 public static void testCreateAppImage(String [] cmd, |
|
121 boolean includeArgs, String name) throws Exception { |
|
122 JPackageHelper.executeCLI(true, cmd); |
|
123 validate(includeArgs, name); |
|
124 } |
|
125 |
|
126 public static void testCreateAppImageToolProvider(String [] cmd) |
|
127 throws Exception { |
|
128 testCreateAppImageToolProvider(cmd, true, "test2"); |
|
129 } |
|
130 |
|
131 public static void testCreateAppImageToolProvider(String [] cmd, |
|
132 boolean includeArgs, String name) throws Exception { |
114 JPackageHelper.executeToolProvider(true, cmd); |
133 JPackageHelper.executeToolProvider(true, cmd); |
115 validate(); |
134 validate(includeArgs, name); |
116 } |
135 } |
117 |
136 |
118 public static void createSLProperties() throws Exception { |
137 public static void createSLProperties() throws Exception { |
119 arguments.add(ARGUMENT1); |
138 arguments.add(ARGUMENT1); |
120 arguments.add(ARGUMENT2); |
139 arguments.add(ARGUMENT2); |