1 /*
2 * Copyright (c) 2017, 2020, 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package test.launchertest;
27
28 import java.io.File;
29 import java.util.ArrayList;
30 import junit.framework.AssertionFailedError;
31 import org.junit.Test;
32
33 import static org.junit.Assert.*;
34 import static test.launchertest.Constants.*;
35
36 /**
37 * Unit test for launching modular FX applications
38 */
39 public class ModuleLauncherTest {
40
41 private static final String modulePath2 = System.getProperty("launchertest.testapp2.module.path");
42 private static final String modulePath3 = System.getProperty("launchertest.testapp3.module.path");
43 private static final String modulePath4 = System.getProperty("launchertest.testapp4.module.path");
44 private static final String modulePath5 = System.getProperty("launchertest.testapp5.module.path");
45 private static final String modulePath6 = System.getProperty("launchertest.testapp6.module.path");
46 private static final String modulePathScript1 = System.getProperty("launchertest.testscriptapp1.module.path");
47
48 private static final String moduleName = "mymod";
49
50 private final int testExitCode = ERROR_NONE;
51
52 private void doTestLaunchModule(String appModulePath, String testAppName) throws Exception {
53 final String javafxModulePath = System.getProperty("worker.module.path");
54 String modulePath;
55 if (javafxModulePath != null) {
56 modulePath = javafxModulePath + File.pathSeparator + appModulePath;
57 } else {
58 modulePath = appModulePath;
59 }
60 assertNotNull(testAppName);
61 System.err.println("The following Unknown module WARNING messages are expected:");
62 String mpArg = "--module-path=" + modulePath;
63 String moduleAppName = "--module=" + moduleName + "/" + testAppName;
64 final ArrayList<String> cmd =
65 test.util.Util.createApplicationLaunchCommand(
66 moduleAppName,
67 null,
68 null,
69 new String[] { mpArg }
70 );
71
72 final ProcessBuilder builder = new ProcessBuilder(cmd);
73
74 builder.redirectError(ProcessBuilder.Redirect.INHERIT);
75 builder.redirectOutput(ProcessBuilder.Redirect.INHERIT);
76 Process process = builder.start();
77 int retVal = process.waitFor();
78 switch (retVal) {
79 case 0:// SUCCESS
80 case ERROR_NONE:
81 if (retVal != testExitCode) {
82 throw new AssertionFailedError(testAppName
83 + ": Unexpected 'success' exit; expected:"
84 + testExitCode + " was:" + retVal);
85 }
86 return;
87
88 case 1:
89 throw new AssertionFailedError(testAppName
90 + ": unable to launch java application");
91
92 case ERROR_TOOLKIT_NOT_RUNNING:
93 throw new AssertionFailedError(testAppName
94 + ": Toolkit not running prior to loading application class");
95 case ERROR_TOOLKIT_IS_RUNNING:
96 throw new AssertionFailedError(testAppName
97 + ": Toolkit is running but should not be");
98
99 case ERROR_ASSERTION_FAILURE:
100 throw new AssertionFailedError(testAppName
101 + ": Assertion failure in test application");
102
103 case ERROR_UNEXPECTED_EXCEPTION:
104 throw new AssertionFailedError(testAppName
105 + ": unexpected exception");
106
107 default:
108 throw new AssertionFailedError(testAppName
109 + ": Unexpected error exit: " + retVal);
110 }
111 }
112
113
114 @Test (timeout = 15000)
115 public void testLaunchModule() throws Exception {
116 doTestLaunchModule(modulePath2, "testapp.TestApp");
117 }
118
119 @Test (timeout = 15000)
120 public void testLaunchModuleNoMain() throws Exception {
121 doTestLaunchModule(modulePath2, "testapp.TestAppNoMain");
122 }
123
124 @Test (timeout = 15000)
125 public void testLaunchModuleNotApplication() throws Exception {
126 doTestLaunchModule(modulePath2, "testapp.TestNotApplication");
127 }
128
129 @Test (timeout = 15000)
130 public void testModuleTableViewUnexported() throws Exception {
131 doTestLaunchModule(modulePath3, "myapp3.AppTableViewUnexported");
132 }
133
134 @Test (timeout = 15000)
135 public void testModuleTableViewExported() throws Exception {
136 doTestLaunchModule(modulePath3, "myapp3.AppTableViewExported");
137 }
138
139 @Test (timeout = 15000)
140 public void testModuleTableViewQualExported() throws Exception {
141 doTestLaunchModule(modulePath3, "myapp3.AppTableViewQualExported");
142 }
143
144 @Test (timeout = 15000)
145 public void testModuleTableViewOpened() throws Exception {
146 doTestLaunchModule(modulePath3, "myapp3.AppTableViewOpened");
147 }
148
149 @Test (timeout = 15000)
150 public void testModuleTableViewQualOpened() throws Exception {
151 doTestLaunchModule(modulePath3, "myapp3.AppTableViewQualOpened");
152 }
153
154 @Test (timeout = 15000)
155 public void testModuleTreeTableViewUnexported() throws Exception {
156 doTestLaunchModule(modulePath3, "myapp3.AppTreeTableViewUnexported");
157 }
158
159 @Test (timeout = 15000)
160 public void testModuleTreeTableViewExported() throws Exception {
161 doTestLaunchModule(modulePath3, "myapp3.AppTreeTableViewExported");
162 }
163
164 @Test (timeout = 15000)
165 public void testModuleTreeTableViewQualExported() throws Exception {
166 doTestLaunchModule(modulePath3, "myapp3.AppTreeTableViewQualExported");
167 }
168
169 @Test (timeout = 15000)
170 public void testModuleTreeTableViewOpened() throws Exception {
171 doTestLaunchModule(modulePath3, "myapp3.AppTreeTableViewOpened");
172 }
173
174 @Test (timeout = 15000)
175 public void testModuleTreeTableViewQualOpened() throws Exception {
176 doTestLaunchModule(modulePath3, "myapp3.AppTreeTableViewQualOpened");
177 }
178
179 @Test (timeout = 15000)
180 public void testModuleBeansUnexported() throws Exception {
181 doTestLaunchModule(modulePath4, "myapp4.AppBeansUnexported");
182 }
183
184 @Test (timeout = 15000)
185 public void testModuleBeansExported() throws Exception {
186 doTestLaunchModule(modulePath4, "myapp4.AppBeansExported");
187 }
188
189 @Test (timeout = 15000)
190 public void testModuleBeansQualExported() throws Exception {
191 doTestLaunchModule(modulePath4, "myapp4.AppBeansQualExported");
192 }
193
194 @Test (timeout = 15000)
195 public void testModuleBeansOpened() throws Exception {
196 doTestLaunchModule(modulePath4, "myapp4.AppBeansOpened");
197 }
198
199 @Test (timeout = 15000)
200 public void testModuleBeansQualOpened() throws Exception {
201 doTestLaunchModule(modulePath4, "myapp4.AppBeansQualOpened");
202 }
203
204 @Test (timeout = 15000)
205 public void testModuleBindingsUnexported() throws Exception {
206 doTestLaunchModule(modulePath4, "myapp4.AppBindingsUnexported");
207 }
208
209 @Test (timeout = 15000)
210 public void testModuleBindingsExported() throws Exception {
211 doTestLaunchModule(modulePath4, "myapp4.AppBindingsExported");
212 }
213
214 @Test (timeout = 15000)
215 public void testModuleBindingsQualExported() throws Exception {
216 doTestLaunchModule(modulePath4, "myapp4.AppBindingsQualExported");
217 }
218
219 @Test (timeout = 15000)
220 public void testModuleBindingsOpened() throws Exception {
221 doTestLaunchModule(modulePath4, "myapp4.AppBindingsOpened");
222 }
223
224 @Test (timeout = 15000)
225 public void testModuleBindingsQualOpened() throws Exception {
226 doTestLaunchModule(modulePath4, "myapp4.AppBindingsQualOpened");
227 }
228
229 @Test (timeout = 15000)
230 public void testModuleJSCallbackUnexported() throws Exception {
231 doTestLaunchModule(modulePath5, "myapp5.AppJSCallbackUnexported");
232 }
233
234 @Test (timeout = 15000)
235 public void testModuleJSCallbackExported() throws Exception {
236 doTestLaunchModule(modulePath5, "myapp5.AppJSCallbackExported");
237 }
238
239 @Test (timeout = 15000)
240 public void testModuleJSCallbackQualExported() throws Exception {
241 doTestLaunchModule(modulePath5, "myapp5.AppJSCallbackQualExported");
242 }
243
244 @Test (timeout = 15000)
245 public void testModuleJSCallbackOpened() throws Exception {
246 doTestLaunchModule(modulePath5, "myapp5.AppJSCallbackOpened");
247 }
248
249 @Test (timeout = 15000)
250 public void testModuleJSCallbackQualOpened() throws Exception {
251 doTestLaunchModule(modulePath5, "myapp5.AppJSCallbackQualOpened");
252 }
253
254 @Test (timeout = 15000)
255 public void testModuleFXMLUnexported() throws Exception {
256 doTestLaunchModule(modulePath6, "myapp6.AppFXMLUnexported");
257 }
258
259 @Test (timeout = 15000)
260 public void testModuleFXMLExported() throws Exception {
261 doTestLaunchModule(modulePath6, "myapp6.AppFXMLExported");
262 }
263
264 @Test (timeout = 15000)
265 public void testModuleFXMLQualExported() throws Exception {
266 doTestLaunchModule(modulePath6, "myapp6.AppFXMLQualExported");
267 }
268
269 @Test (timeout = 15000)
270 public void testModuleFXMLOpened() throws Exception {
271 doTestLaunchModule(modulePath6, "myapp6.AppFXMLOpened");
272 }
273
274 @Test (timeout = 15000)
275 public void testModuleFXMLQualOpened() throws Exception {
276 doTestLaunchModule(modulePath6, "myapp6.AppFXMLQualOpened");
277 }
278
279 @Test (timeout = 15000)
280 public void testFXMLScriptDeployment() throws Exception {
281 doTestLaunchModule(modulePathScript1, "myapp1.FXMLScriptDeployment");
282 }
283
284 }