1 /*
   2  * Copyright (c) 2017, 2018, 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.util.ArrayList;
  29 import junit.framework.AssertionFailedError;
  30 import org.junit.Test;
  31 
  32 import static org.junit.Assert.*;
  33 import static test.launchertest.Constants.*;
  34 
  35 /**
  36  * Unit test for launching modular FX applications
  37  */
  38 public class ModuleLauncherTest {
  39 
  40     private static final String modulePath2 = System.getProperty("launchertest.testapp2.module.path");
  41     private static final String modulePath3 = System.getProperty("launchertest.testapp3.module.path");
  42     private static final String modulePath4 = System.getProperty("launchertest.testapp4.module.path");
  43     private static final String modulePath5 = System.getProperty("launchertest.testapp5.module.path");
  44     private static final String modulePath6 = System.getProperty("launchertest.testapp6.module.path");
  45     private static final String moduleName = "mymod";
  46 
  47     private final int testExitCode = ERROR_NONE;
  48 
  49     private void doTestLaunchModule(String modulePath, String testAppName) throws Exception {
  50         assertNotNull(testAppName);
  51         System.err.println("The following Unknown module WARNING messages are expected:");
  52         String mpArg = "--module-path=" + modulePath;
  53         String moduleAppName = "--module=" + moduleName + "/" + testAppName;
  54         final ArrayList<String> cmd =
  55                 test.util.Util.createApplicationLaunchCommand(
  56                         moduleAppName,
  57                         null,
  58                         null,
  59                         new String[] { mpArg }
  60                         );
  61 
  62         final ProcessBuilder builder = new ProcessBuilder(cmd);
  63 
  64         builder.redirectError(ProcessBuilder.Redirect.INHERIT);
  65         builder.redirectOutput(ProcessBuilder.Redirect.INHERIT);
  66         Process process = builder.start();
  67         int retVal = process.waitFor();
  68         switch (retVal) {
  69             case 0:// SUCCESS
  70             case ERROR_NONE:
  71                 if (retVal != testExitCode) {
  72                     throw new AssertionFailedError(testAppName
  73                             + ": Unexpected 'success' exit; expected:"
  74                             + testExitCode + " was:" + retVal);
  75                 }
  76                 return;
  77 
  78             case 1:
  79                 throw new AssertionFailedError(testAppName
  80                         + ": unable to launch java application");
  81 
  82             case ERROR_TOOLKIT_NOT_RUNNING:
  83                 throw new AssertionFailedError(testAppName
  84                         + ": Toolkit not running prior to loading application class");
  85             case ERROR_TOOLKIT_IS_RUNNING:
  86                 throw new AssertionFailedError(testAppName
  87                         + ": Toolkit is running but should not be");
  88 
  89             case ERROR_ASSERTION_FAILURE:
  90                 throw new AssertionFailedError(testAppName
  91                 + ": Assertion failure in test application");
  92 
  93             case ERROR_UNEXPECTED_EXCEPTION:
  94                 throw new AssertionFailedError(testAppName
  95                 + ": unexpected exception");
  96 
  97             default:
  98                 throw new AssertionFailedError(testAppName
  99                         + ": Unexpected error exit: " + retVal);
 100         }
 101     }
 102 
 103 
 104     @Test (timeout = 15000)
 105     public void testLaunchModule() throws Exception {
 106         doTestLaunchModule(modulePath2, "testapp.TestApp");
 107     }
 108 
 109     @Test (timeout = 15000)
 110     public void testLaunchModuleNoMain() throws Exception {
 111         doTestLaunchModule(modulePath2, "testapp.TestAppNoMain");
 112     }
 113 
 114     @Test (timeout = 15000)
 115     public void testLaunchModuleNotApplication() throws Exception {
 116         doTestLaunchModule(modulePath2, "testapp.TestNotApplication");
 117     }
 118 
 119     @Test (timeout = 15000)
 120     public void testModuleTableViewUnexported() throws Exception {
 121         doTestLaunchModule(modulePath3, "myapp3.AppTableViewUnexported");
 122     }
 123 
 124     @Test (timeout = 15000)
 125     public void testModuleTableViewExported() throws Exception {
 126         doTestLaunchModule(modulePath3, "myapp3.AppTableViewExported");
 127     }
 128 
 129     @Test (timeout = 15000)
 130     public void testModuleTableViewQualExported() throws Exception {
 131         doTestLaunchModule(modulePath3, "myapp3.AppTableViewQualExported");
 132     }
 133 
 134     @Test (timeout = 15000)
 135     public void testModuleTableViewOpened() throws Exception {
 136         doTestLaunchModule(modulePath3, "myapp3.AppTableViewOpened");
 137     }
 138 
 139     @Test (timeout = 15000)
 140     public void testModuleTableViewQualOpened() throws Exception {
 141         doTestLaunchModule(modulePath3, "myapp3.AppTableViewQualOpened");
 142     }
 143 
 144     @Test (timeout = 15000)
 145     public void testModuleTreeTableViewUnexported() throws Exception {
 146         doTestLaunchModule(modulePath3, "myapp3.AppTreeTableViewUnexported");
 147     }
 148 
 149     @Test (timeout = 15000)
 150     public void testModuleTreeTableViewExported() throws Exception {
 151         doTestLaunchModule(modulePath3, "myapp3.AppTreeTableViewExported");
 152     }
 153 
 154     @Test (timeout = 15000)
 155     public void testModuleTreeTableViewQualExported() throws Exception {
 156         doTestLaunchModule(modulePath3, "myapp3.AppTreeTableViewQualExported");
 157     }
 158 
 159     @Test (timeout = 15000)
 160     public void testModuleTreeTableViewOpened() throws Exception {
 161         doTestLaunchModule(modulePath3, "myapp3.AppTreeTableViewOpened");
 162     }
 163 
 164     @Test (timeout = 15000)
 165     public void testModuleTreeTableViewQualOpened() throws Exception {
 166         doTestLaunchModule(modulePath3, "myapp3.AppTreeTableViewQualOpened");
 167     }
 168 
 169     @Test (timeout = 15000)
 170     public void testModuleBeansUnexported() throws Exception {
 171         doTestLaunchModule(modulePath4, "myapp4.AppBeansUnexported");
 172     }
 173 
 174     @Test (timeout = 15000)
 175     public void testModuleBeansExported() throws Exception {
 176         doTestLaunchModule(modulePath4, "myapp4.AppBeansExported");
 177     }
 178 
 179     @Test (timeout = 15000)
 180     public void testModuleBeansQualExported() throws Exception {
 181         doTestLaunchModule(modulePath4, "myapp4.AppBeansQualExported");
 182     }
 183 
 184     @Test (timeout = 15000)
 185     public void testModuleBeansOpened() throws Exception {
 186         doTestLaunchModule(modulePath4, "myapp4.AppBeansOpened");
 187     }
 188 
 189     @Test (timeout = 15000)
 190     public void testModuleBeansQualOpened() throws Exception {
 191         doTestLaunchModule(modulePath4, "myapp4.AppBeansQualOpened");
 192     }
 193 
 194     @Test (timeout = 15000)
 195     public void testModuleBindingsUnexported() throws Exception {
 196         doTestLaunchModule(modulePath4, "myapp4.AppBindingsUnexported");
 197     }
 198 
 199     @Test (timeout = 15000)
 200     public void testModuleBindingsExported() throws Exception {
 201         doTestLaunchModule(modulePath4, "myapp4.AppBindingsExported");
 202     }
 203 
 204     @Test (timeout = 15000)
 205     public void testModuleBindingsQualExported() throws Exception {
 206         doTestLaunchModule(modulePath4, "myapp4.AppBindingsQualExported");
 207     }
 208 
 209     @Test (timeout = 15000)
 210     public void testModuleBindingsOpened() throws Exception {
 211         doTestLaunchModule(modulePath4, "myapp4.AppBindingsOpened");
 212     }
 213 
 214     @Test (timeout = 15000)
 215     public void testModuleBindingsQualOpened() throws Exception {
 216         doTestLaunchModule(modulePath4, "myapp4.AppBindingsQualOpened");
 217     }
 218 
 219     @Test (timeout = 15000)
 220     public void testModuleJSCallbackUnexported() throws Exception {
 221         doTestLaunchModule(modulePath5, "myapp5.AppJSCallbackUnexported");
 222     }
 223 
 224     @Test (timeout = 15000)
 225     public void testModuleJSCallbackExported() throws Exception {
 226         doTestLaunchModule(modulePath5, "myapp5.AppJSCallbackExported");
 227     }
 228 
 229     @Test (timeout = 15000)
 230     public void testModuleJSCallbackQualExported() throws Exception {
 231         doTestLaunchModule(modulePath5, "myapp5.AppJSCallbackQualExported");
 232     }
 233 
 234     @Test (timeout = 15000)
 235     public void testModuleJSCallbackOpened() throws Exception {
 236         doTestLaunchModule(modulePath5, "myapp5.AppJSCallbackOpened");
 237     }
 238 
 239     @Test (timeout = 15000)
 240     public void testModuleJSCallbackQualOpened() throws Exception {
 241         doTestLaunchModule(modulePath5, "myapp5.AppJSCallbackQualOpened");
 242     }
 243 
 244     @Test (timeout = 15000)
 245     public void testModuleFXMLUnexported() throws Exception {
 246         doTestLaunchModule(modulePath6, "myapp6.AppFXMLUnexported");
 247     }
 248 
 249     @Test (timeout = 15000)
 250     public void testModuleFXMLExported() throws Exception {
 251         doTestLaunchModule(modulePath6, "myapp6.AppFXMLExported");
 252     }
 253 
 254     @Test (timeout = 15000)
 255     public void testModuleFXMLQualExported() throws Exception {
 256         doTestLaunchModule(modulePath6, "myapp6.AppFXMLQualExported");
 257     }
 258 
 259     @Test (timeout = 15000)
 260     public void testModuleFXMLOpened() throws Exception {
 261         doTestLaunchModule(modulePath6, "myapp6.AppFXMLOpened");
 262     }
 263 
 264     @Test (timeout = 15000)
 265     public void testModuleFXMLQualOpened() throws Exception {
 266         doTestLaunchModule(modulePath6, "myapp6.AppFXMLQualOpened");
 267     }
 268 
 269 }