tools/SharedTestUtilsOpen/src/test/javaclient/shared/AppLauncher.java

Print this page




  38 /**
  39  * Launcher class which is aware of different run modes we need for our tests
  40  *
  41  * @author Sergey Grinev
  42  */
  43 public class AppLauncher {
  44 
  45     /**
  46      * For tests, which will not wait for stage appearing, and need only toolkit start.
  47      */
  48     public static final String WAIT_TOOLKIT_START_ONLY = "WAIT_TOOLKIT_START_ONLY";
  49 
  50     public void launch(final Class cl, String[] args) {
  51         switch (mode) {
  52             case DEFAULT:
  53                 defaultLaunch(cl, args);
  54                 break;
  55             case SWING:
  56                 instantiateOnSwingQueue(cl, args);
  57                 break;

  58             case SWT:
  59                 instantiateOnSWTQueue(cl, args);
  60                 break;
  61             case REMOTE:
  62                 launchOnRemoteStage(cl, args);
  63                 break;
  64             default:
  65                 throw new IllegalStateException("Unknown launch mode: " + mode);
  66 
  67         }
  68     }
  69 
  70     public enum Mode {
  71 
  72         DEFAULT, SWING, SWT, REMOTE
  73     };
  74     private Mode mode = Mode.DEFAULT;
  75     private long testDelay = Long.getLong("test.javafx.testdelay", 1000);
  76     private long testDelayRemote = Long.getLong("test.javafx.testdelayremote", 4000);
  77 


  88             mode = Mode.SWING;
  89         }
  90         if (Boolean.getBoolean("javafx.swtinteroperability")) {
  91             mode = Mode.SWT;
  92         }
  93     }
  94     private final static AppLauncher INSTANCE = new AppLauncher();
  95 
  96     public static AppLauncher getInstance() {
  97         return INSTANCE;
  98     }
  99 
 100     private static void instantiateOnSwingQueue(final Class<? extends Interoperability> cl, String[] args) {
 101         try {
 102             SwingAWTUtils.instantiateOnSwingQueue(cl);
 103         } catch (Exception ex) {
 104             ex.printStackTrace();
 105         }
 106     }
 107 

 108     private static void instantiateOnSWTQueue(final Class<? extends Interoperability> cl, String[] args) {
 109         try {
 110             Interoperability obj = cl.newInstance();
 111             obj.startSWT();
 112         } catch (Exception ex) {
 113             ex.printStackTrace();
 114         }
 115     }
 116 
 117     private void launchOnRemoteStage(final Class<? extends Application> cl, final String[] args) {
 118         Platform.runLater(new Runnable() {
 119 
 120             public void run() {
 121                 try {
 122                     Application obj = (Application) cl.newInstance();
 123                     ParametersImpl.registerParameters(obj, new ParametersImpl(args));
 124                     obj.start(remoteStage);
 125                 } catch (Exception ex) {
 126                     ex.printStackTrace();
 127                 }


 137             public void run() {
 138                 Application.launch(cl, args);
 139             }
 140         }, "FXSQE app launch thread").start();
 141 
 142         new Waiter(new Timeout("FXSQE launch start waiter", TestUtil.isEmbedded() ? 600000 : 10000)).ensureState(new State<Boolean>() {
 143 
 144             public Boolean reached() {
 145 //                try {
 146 //                    Thread.sleep(100); // otherwise mac doesn't start
 147 //                } catch (InterruptedException ex) {
 148 //                }
 149                 if (waitToolkit) {
 150                     try {
 151                         final Toolkit toolkit = com.sun.javafx.tk.Toolkit.getToolkit();
 152                     } catch (Throwable ex) {
 153                         return null;
 154                     }
 155                     return Boolean.TRUE;
 156                 } else {
 157                     Iterator<Window> it = Stage.impl_getWindows();
 158                     while (it.hasNext()) {
 159 
 160                         if (it.next().isShowing()) {
 161                             return Boolean.TRUE;
 162                         }
 163                     }
 164                 }
 165 
 166                 // following wait method was changed due to problem on Mac+JDK7:
 167                 // we can't use AWT (and consequently Jemmy based on ATW Robot) before FX scene is shown
 168                 // otherwise FX hangs.
 169                 // Root.ROOT.lookup(new ByWindowType(Stage.class)).lookup(Scene.class).wrap(0).getControl();
 170                 return null;
 171             }
 172         });
 173     // more JDK7+Mac tricks
 174     // System.setProperty("java.awt.headless","false");
 175     // java.awt.GraphicsEnvironment.isHeadless();
 176     }
 177 
 178     /**
 179      * Setup stage to be used by launcher. E.g. stage provided by plugin
 180      * launcher


  38 /**
  39  * Launcher class which is aware of different run modes we need for our tests
  40  *
  41  * @author Sergey Grinev
  42  */
  43 public class AppLauncher {
  44     
  45     /**
  46      * For tests, which will not wait for stage appearing, and need only toolkit start.
  47      */
  48     public static final String WAIT_TOOLKIT_START_ONLY = "WAIT_TOOLKIT_START_ONLY";
  49 
  50     public void launch(final Class cl, String[] args) {
  51         switch (mode) {
  52             case DEFAULT:
  53                 defaultLaunch(cl, args);
  54                 break;
  55             case SWING:
  56                 instantiateOnSwingQueue(cl, args);
  57                 break;
  58             // https://bugs.openjdk.java.net/browse/JDK-8131888

  59             case SWT:
  60                 instantiateOnSWTQueue(cl, args);
  61                 break;
  62             case REMOTE:
  63                 launchOnRemoteStage(cl, args);
  64                 break;
  65             default:
  66                 throw new IllegalStateException("Unknown launch mode: " + mode);
  67 
  68         }
  69     }
  70 
  71     public enum Mode {
  72 
  73         DEFAULT, SWING, SWT, REMOTE
  74     };
  75     private Mode mode = Mode.DEFAULT;
  76     private long testDelay = Long.getLong("test.javafx.testdelay", 1000);
  77     private long testDelayRemote = Long.getLong("test.javafx.testdelayremote", 4000);
  78 


  89             mode = Mode.SWING;
  90         }
  91         if (Boolean.getBoolean("javafx.swtinteroperability")) {
  92             mode = Mode.SWT;
  93         }
  94     }
  95     private final static AppLauncher INSTANCE = new AppLauncher();
  96 
  97     public static AppLauncher getInstance() {
  98         return INSTANCE;
  99     }
 100 
 101     private static void instantiateOnSwingQueue(final Class<? extends Interoperability> cl, String[] args) {
 102         try {
 103             SwingAWTUtils.instantiateOnSwingQueue(cl);
 104         } catch (Exception ex) {
 105             ex.printStackTrace();
 106         }
 107     }
 108 
 109     // https://bugs.openjdk.java.net/browse/JDK-8131888

 110     private static void instantiateOnSWTQueue(final Class<? extends Interoperability> cl, String[] args) {
 111         try {
 112             Interoperability obj = cl.newInstance();
 113             obj.startSWT();
 114         } catch (Exception ex) {
 115             ex.printStackTrace();
 116         }
 117     }
 118 
 119     private void launchOnRemoteStage(final Class<? extends Application> cl, final String[] args) {
 120         Platform.runLater(new Runnable() {
 121 
 122             public void run() {
 123                 try {
 124                     Application obj = (Application) cl.newInstance();
 125                     ParametersImpl.registerParameters(obj, new ParametersImpl(args));
 126                     obj.start(remoteStage);
 127                 } catch (Exception ex) {
 128                     ex.printStackTrace();
 129                 }


 139             public void run() {
 140                 Application.launch(cl, args);
 141             }
 142         }, "FXSQE app launch thread").start();
 143 
 144         new Waiter(new Timeout("FXSQE launch start waiter", TestUtil.isEmbedded() ? 600000 : 10000)).ensureState(new State<Boolean>() {
 145 
 146             public Boolean reached() {
 147 //                try {
 148 //                    Thread.sleep(100); // otherwise mac doesn't start
 149 //                } catch (InterruptedException ex) {
 150 //                }
 151                 if (waitToolkit) {
 152                     try {
 153                         final Toolkit toolkit = com.sun.javafx.tk.Toolkit.getToolkit();
 154                     } catch (Throwable ex) {
 155                         return null;
 156                     }
 157                     return Boolean.TRUE;
 158                 } else {                    
 159                     for (Window w : Stage.getWindows()) {

 160                         if (w.isShowing()) {



 161                             return Boolean.TRUE;
 162                         }
 163                     }
 164                 }
 165 
 166                 // following wait method was changed due to problem on Mac+JDK7:
 167                 // we can't use AWT (and consequently Jemmy based on ATW Robot) before FX scene is shown
 168                 // otherwise FX hangs.
 169                 // Root.ROOT.lookup(new ByWindowType(Stage.class)).lookup(Scene.class).wrap(0).getControl();
 170                 return null;
 171             }
 172         });
 173     // more JDK7+Mac tricks
 174     // System.setProperty("java.awt.headless","false");
 175     // java.awt.GraphicsEnvironment.isHeadless();
 176     }
 177 
 178     /**
 179      * Setup stage to be used by launcher. E.g. stage provided by plugin
 180      * launcher