01: /*
02: * GuiTestUtil.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.gui;
13:
14: import org.netbeans.jemmy.ClassReference;
15: import org.netbeans.jemmy.JemmyProperties;
16: import org.netbeans.jemmy.QueueTool;
17: import org.netbeans.jemmy.TestOut;
18: import workbench.TestUtil;
19: import workbench.WbManager;
20: import workbench.gui.sql.SqlPanel;
21:
22: /**
23: *
24: * @author support@sql-workbench.net
25: */
26: public class GuiTestUtil extends TestUtil {
27: private QueueTool tool = new QueueTool();
28:
29: public GuiTestUtil(String name) {
30: super (name, false);
31: }
32:
33: public void startApplication() throws Exception {
34: new ClassReference("workbench.WbManager")
35: .startApplication(getArgs(false));
36: System.setProperty("workbench.system.doexit", "false");
37:
38: // JemmyProperties.getCurrentTimeouts().loadDebugTimeouts();
39: TestOut out = JemmyProperties.getProperties().getOutput()
40: .createErrorOutput();
41: JemmyProperties.getProperties().setOutput(out);
42: }
43:
44: public void execute(Runnable r) {
45: tool.invokeAndWait(r);
46: tool.waitEmpty();
47: }
48:
49: public void waitWhileBusy(SqlPanel panel) {
50: int count = 0;
51: int sleepTime = 10;
52: while (panel.isBusy()) {
53: try {
54: Thread.sleep(sleepTime);
55: } catch (Throwable th) {
56: }
57: count++;
58: if (count * sleepTime > 30000)
59: break;
60: }
61: }
62:
63: public void waitUntilConnected(SqlPanel panel) {
64: int count = 0;
65: int sleepTime = 10;
66: while (!panel.isConnected()) {
67: //Thread.yield();
68: try {
69: Thread.sleep(sleepTime);
70: } catch (Throwable th) {
71: }
72: count++;
73: if (count * sleepTime > 5000)
74: break;
75: }
76: }
77:
78: public void stopApplication() {
79: WbManager.getInstance().exitWorkbench(null);
80: }
81: }
|