1 /* 2 * Copyright (c) 2009, 2012, 2013 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 */ 24 25 package test.javaclient.shared; 26 27 28 import javafx.application.Platform; 29 import javafx.event.EventHandler; 30 import javafx.scene.Node; 31 import javafx.scene.Scene; 32 import javafx.scene.control.Control; 33 import javafx.scene.input.MouseEvent; 34 import javafx.stage.Stage; 35 import org.jemmy.control.Wrap; 36 import org.jemmy.fx.ByWindowType; 37 import org.jemmy.fx.Root; 38 import org.jemmy.fx.control.ControlDock; 39 import org.jemmy.fx.control.ControlWrap; 40 import org.jemmy.interfaces.Parent; 41 import org.junit.Assert; 42 import static test.javaclient.shared.JemmyUtils.initJemmy; 43 import test.javaclient.shared.screenshots.ScreenshotUtils; 44 45 /** 46 * 47 * @author Andrey Glushchenko, Sergey Grinev 48 */ 49 public class TestBaseBase { 50 51 52 private static boolean jemmyStuffConfigured = false; 53 protected AbstractTestableApplication application; 54 private Wrap<? extends Scene> scene = null; 55 protected Wrap<? extends Scene> getScene() { 56 if (null == scene) 57 scene = Root.ROOT.lookup(new ByWindowType(Stage.class)).lookup(Scene.class).wrap(0); 58 return scene; 59 } 60 61 public static void setUpClass() { 62 jemmyStuffConfigured = false; 63 } 64 65 public void before() { 66 if (!jemmyStuffConfigured) { 67 //prepare env 68 initJemmy(); 69 jemmyStuffConfigured = true; 70 } 71 application = AbstractApp2.getLastInstance(); 72 ScreenshotUtils.setApplication(application); 73 Platform.runLater(new Runnable(){public void run(){ 74 scene = TestUtil.getScene(); 75 ScreenshotUtils.setScene(scene); 76 }}); 77 } 78 79 protected AbstractTestableApplication getApplication() { 80 return application; 81 } 82 83 protected String getName() { 84 return getClass().getSimpleName(); 85 } 86 protected void openPage(String name) { 87 if (application != null) { 88 application.openPage(name); 89 } else { 90 clickTextButton(name); 91 } 92 } 93 protected void clickTextButton(String name) { 94 /** 95 * new ControlDock because there is no ButtonDock Yet. 96 */ 97 final ControlWrap<? extends Control> label = 98 new ControlDock(scene.as(Parent.class, Node.class), name).wrap(); 99 label.mouse().move(); 100 Utils.deferAction(new Runnable() { 101 public void run() { 102 EventHandler<? super MouseEvent> hndlr = label.getControl().getOnMouseClicked(); 103 if (null == hndlr) { 104 hndlr = label.getControl().getOnMousePressed(); 105 } 106 hndlr.handle(null); 107 } 108 }); 109 } 110 protected void restoreSceneRoot() { 111 Utils.deferAction(new Runnable() { 112 public void run() { 113 ((BasicButtonChooserApp) application).restoreSceneRoot(); 114 } 115 }); 116 } 117 protected void verifyGetters() { 118 Assert.assertEquals("", application.getFailures()); 119 } 120 121 protected void verifyFailures() { 122 String failures = application.getFailures(); 123 Assert.assertEquals("", failures); 124 } 125 public String getNameForScreenShot(String toplevel_name, String innerlevel_name) { 126 String normalizedName = Utils.normalizeName(toplevel_name + (innerlevel_name != null ? innerlevel_name : "")); 127 return new StringBuilder(getName()).append("-").append(normalizedName).toString(); 128 } 129 }