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 private static final String modulePathScript2 = System.getProperty("launchertest.testscriptapp2.module.path"); 48 49 private static final String moduleName = "mymod"; 50 51 private final int testExitCode = ERROR_NONE; 52 53 private void doTestLaunchModule(String appModulePath, String testAppName) throws Exception { 54 final String javafxModulePath = System.getProperty("worker.module.path"); 55 String modulePath; 56 if (javafxModulePath != null) { 57 modulePath = javafxModulePath + File.pathSeparator + appModulePath; 58 } else { 59 modulePath = appModulePath; 60 } 61 assertNotNull(testAppName); 62 System.err.println("The following Unknown module WARNING messages are expected:"); 63 String mpArg = "--module-path=" + modulePath; 64 String moduleAppName = "--module=" + moduleName + "/" + testAppName; 65 final ArrayList<String> cmd = 66 test.util.Util.createApplicationLaunchCommand( 67 moduleAppName, 68 null, 69 null, 70 new String[] { mpArg } 71 ); 72 73 final ProcessBuilder builder = new ProcessBuilder(cmd); 74 75 builder.redirectError(ProcessBuilder.Redirect.INHERIT); 76 builder.redirectOutput(ProcessBuilder.Redirect.INHERIT); 77 Process process = builder.start(); 78 int retVal = process.waitFor(); 79 switch (retVal) { 80 case 0:// SUCCESS 81 case ERROR_NONE: 82 if (retVal != testExitCode) { 83 throw new AssertionFailedError(testAppName 84 + ": Unexpected 'success' exit; expected:" 85 + testExitCode + " was:" + retVal); 86 } 87 return; 88 89 case 1: 90 throw new AssertionFailedError(testAppName 91 + ": unable to launch java application"); 92 93 case ERROR_TOOLKIT_NOT_RUNNING: 94 throw new AssertionFailedError(testAppName 95 + ": Toolkit not running prior to loading application class"); 96 case ERROR_TOOLKIT_IS_RUNNING: 97 throw new AssertionFailedError(testAppName 98 + ": Toolkit is running but should not be"); 99 100 case ERROR_ASSERTION_FAILURE: 101 throw new AssertionFailedError(testAppName 102 + ": Assertion failure in test application"); 103 104 case ERROR_UNEXPECTED_EXCEPTION: 105 throw new AssertionFailedError(testAppName 106 + ": unexpected exception"); 107 108 default: 109 throw new AssertionFailedError(testAppName 110 + ": Unexpected error exit: " + retVal); 111 } 112 } 113 114 115 @Test (timeout = 15000) 116 public void testLaunchModule() throws Exception { 117 doTestLaunchModule(modulePath2, "testapp.TestApp"); 118 } 119 120 @Test (timeout = 15000) 121 public void testLaunchModuleNoMain() throws Exception { 122 doTestLaunchModule(modulePath2, "testapp.TestAppNoMain"); 123 } 124 125 @Test (timeout = 15000) 126 public void testLaunchModuleNotApplication() throws Exception { 127 doTestLaunchModule(modulePath2, "testapp.TestNotApplication"); 128 } 129 130 @Test (timeout = 15000) 131 public void testModuleTableViewUnexported() throws Exception { 132 doTestLaunchModule(modulePath3, "myapp3.AppTableViewUnexported"); 133 } 134 135 @Test (timeout = 15000) 136 public void testModuleTableViewExported() throws Exception { 137 doTestLaunchModule(modulePath3, "myapp3.AppTableViewExported"); 138 } 139 140 @Test (timeout = 15000) 141 public void testModuleTableViewQualExported() throws Exception { 142 doTestLaunchModule(modulePath3, "myapp3.AppTableViewQualExported"); 143 } 144 145 @Test (timeout = 15000) 146 public void testModuleTableViewOpened() throws Exception { 147 doTestLaunchModule(modulePath3, "myapp3.AppTableViewOpened"); 148 } 149 150 @Test (timeout = 15000) 151 public void testModuleTableViewQualOpened() throws Exception { 152 doTestLaunchModule(modulePath3, "myapp3.AppTableViewQualOpened"); 153 } 154 155 @Test (timeout = 15000) 156 public void testModuleTreeTableViewUnexported() throws Exception { 157 doTestLaunchModule(modulePath3, "myapp3.AppTreeTableViewUnexported"); 158 } 159 160 @Test (timeout = 15000) 161 public void testModuleTreeTableViewExported() throws Exception { 162 doTestLaunchModule(modulePath3, "myapp3.AppTreeTableViewExported"); 163 } 164 165 @Test (timeout = 15000) 166 public void testModuleTreeTableViewQualExported() throws Exception { 167 doTestLaunchModule(modulePath3, "myapp3.AppTreeTableViewQualExported"); 168 } 169 170 @Test (timeout = 15000) 171 public void testModuleTreeTableViewOpened() throws Exception { 172 doTestLaunchModule(modulePath3, "myapp3.AppTreeTableViewOpened"); 173 } 174 175 @Test (timeout = 15000) 176 public void testModuleTreeTableViewQualOpened() throws Exception { 177 doTestLaunchModule(modulePath3, "myapp3.AppTreeTableViewQualOpened"); 178 } 179 180 @Test (timeout = 15000) 181 public void testModuleBeansUnexported() throws Exception { 182 doTestLaunchModule(modulePath4, "myapp4.AppBeansUnexported"); 183 } 184 185 @Test (timeout = 15000) 186 public void testModuleBeansExported() throws Exception { 187 doTestLaunchModule(modulePath4, "myapp4.AppBeansExported"); 188 } 189 190 @Test (timeout = 15000) 191 public void testModuleBeansQualExported() throws Exception { 192 doTestLaunchModule(modulePath4, "myapp4.AppBeansQualExported"); 193 } 194 195 @Test (timeout = 15000) 196 public void testModuleBeansOpened() throws Exception { 197 doTestLaunchModule(modulePath4, "myapp4.AppBeansOpened"); 198 } 199 200 @Test (timeout = 15000) 201 public void testModuleBeansQualOpened() throws Exception { 202 doTestLaunchModule(modulePath4, "myapp4.AppBeansQualOpened"); 203 } 204 205 @Test (timeout = 15000) 206 public void testModuleBindingsUnexported() throws Exception { 207 doTestLaunchModule(modulePath4, "myapp4.AppBindingsUnexported"); 208 } 209 210 @Test (timeout = 15000) 211 public void testModuleBindingsExported() throws Exception { 212 doTestLaunchModule(modulePath4, "myapp4.AppBindingsExported"); 213 } 214 215 @Test (timeout = 15000) 216 public void testModuleBindingsQualExported() throws Exception { 217 doTestLaunchModule(modulePath4, "myapp4.AppBindingsQualExported"); 218 } 219 220 @Test (timeout = 15000) 221 public void testModuleBindingsOpened() throws Exception { 222 doTestLaunchModule(modulePath4, "myapp4.AppBindingsOpened"); 223 } 224 225 @Test (timeout = 15000) 226 public void testModuleBindingsQualOpened() throws Exception { 227 doTestLaunchModule(modulePath4, "myapp4.AppBindingsQualOpened"); 228 } 229 230 @Test (timeout = 15000) 231 public void testModuleJSCallbackUnexported() throws Exception { 232 doTestLaunchModule(modulePath5, "myapp5.AppJSCallbackUnexported"); 233 } 234 235 @Test (timeout = 15000) 236 public void testModuleJSCallbackExported() throws Exception { 237 doTestLaunchModule(modulePath5, "myapp5.AppJSCallbackExported"); 238 } 239 240 @Test (timeout = 15000) 241 public void testModuleJSCallbackQualExported() throws Exception { 242 doTestLaunchModule(modulePath5, "myapp5.AppJSCallbackQualExported"); 243 } 244 245 @Test (timeout = 15000) 246 public void testModuleJSCallbackOpened() throws Exception { 247 doTestLaunchModule(modulePath5, "myapp5.AppJSCallbackOpened"); 248 } 249 250 @Test (timeout = 15000) 251 public void testModuleJSCallbackQualOpened() throws Exception { 252 doTestLaunchModule(modulePath5, "myapp5.AppJSCallbackQualOpened"); 253 } 254 255 @Test (timeout = 15000) 256 public void testModuleFXMLUnexported() throws Exception { 257 doTestLaunchModule(modulePath6, "myapp6.AppFXMLUnexported"); 258 } 259 260 @Test (timeout = 15000) 261 public void testModuleFXMLExported() throws Exception { 262 doTestLaunchModule(modulePath6, "myapp6.AppFXMLExported"); 263 } 264 265 @Test (timeout = 15000) 266 public void testModuleFXMLQualExported() throws Exception { 267 doTestLaunchModule(modulePath6, "myapp6.AppFXMLQualExported"); 268 } 269 270 @Test (timeout = 15000) 271 public void testModuleFXMLOpened() throws Exception { 272 doTestLaunchModule(modulePath6, "myapp6.AppFXMLOpened"); 273 } 274 275 @Test (timeout = 15000) 276 public void testModuleFXMLQualOpened() throws Exception { 277 doTestLaunchModule(modulePath6, "myapp6.AppFXMLQualOpened"); 278 } 279 280 @Test (timeout = 15000) 281 public void testFXMLScriptDeployment() throws Exception { 282 doTestLaunchModule(modulePathScript1, "myapp1.FXMLScriptDeployment"); 283 } 284 285 @Test (timeout = 15000) 286 public void testFXMLScriptDeployment2Compile_On() throws Exception { 287 doTestLaunchModule(modulePathScript2, "myapp2.FXMLScriptDeployment2Compile_On"); 288 } 289 290 @Test (timeout = 15000) 291 public void testFXMLScriptDeployment2Compile_Off() throws Exception { 292 doTestLaunchModule(modulePathScript2, "myapp2.FXMLScriptDeployment2Compile_Off"); 293 } 294 295 @Test (timeout = 15000) 296 public void testFXMLScriptDeployment2Compile_On_Off() throws Exception { 297 doTestLaunchModule(modulePathScript2, "myapp2.FXMLScriptDeployment2Compile_On_Off"); 298 } 299 300 @Test (timeout = 15000) 301 public void testFXMLScriptDeployment2Compile_Off_On() throws Exception { 302 doTestLaunchModule(modulePathScript2, "myapp2.FXMLScriptDeployment2Compile_Off_On"); 303 } 304 @Test (timeout = 15000) 305 public void testFXMLScriptDeployment2Compile_Fail_Compilation() throws Exception { 306 doTestLaunchModule(modulePathScript2, "myapp2.FXMLScriptDeployment2Compile_Fail_Compilation"); 307 } 308 } 309 310