Source Code Cross Referenced for WindowTrackerTest.java in  » Testing » abbot-1.0.1 » abbot » tester » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Testing » abbot 1.0.1 » abbot.tester 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package abbot.tester;
002:
003:        import java.awt.*;
004:        import java.awt.event.*;
005:        import javax.swing.*;
006:        import junit.framework.*;
007:        import junit.extensions.abbot.*;
008:        import junit.extensions.abbot.Timer;
009:
010:        public class WindowTrackerTest extends ComponentTestFixture {
011:
012:            private class MouseWatcher extends MouseAdapter {
013:                private boolean gotClick = false;
014:
015:                public void mousePressed(MouseEvent e) {
016:                    gotClick = true;
017:                }
018:            }
019:
020:            private WindowTracker tracker;
021:
022:            private void wait(Window w, boolean state, String msg) {
023:                Timer timer = new Timer();
024:                while (tracker.isWindowReady(w) != state) {
025:                    if (timer.elapsed() > WindowTracker.WINDOW_READY_DELAY + 500)
026:                        fail(msg);
027:                    try {
028:                        Thread.sleep(10);
029:                    } catch (InterruptedException e) {
030:                    }
031:                }
032:            }
033:
034:            protected void setUp() {
035:                tracker = new WindowTracker();
036:            }
037:
038:            protected void tearDown() {
039:                tracker = null;
040:            }
041:
042:            private class MissedShow1 extends AssertionFailedError {
043:                public MissedShow1() {
044:                    super ("Window not ready after initial show");
045:                }
046:            }
047:
048:            private class MissedShow2 extends AssertionFailedError {
049:                public MissedShow2() {
050:                    super ("Window not ready after subsequent show");
051:                }
052:            }
053:
054:            public void testTrackWindowState() throws Throwable {
055:                Frame w = new Frame(getName());
056:                w.pack();
057:                w.setVisible(true);
058:                wait(w, true,
059:                        "WindowTracker didn't catch initial Window.show()");
060:                assertTrue("Window should be showing", w.isShowing());
061:
062:                w.setVisible(false);
063:                wait(w, false, "WindowTracker didn't catch Window.hide()");
064:                assertTrue("Window should not be showing", !w.isShowing());
065:
066:                w.setVisible(true);
067:                wait(w, true,
068:                        "WindowTracker didn't catch Window.show() after hide");
069:                assertTrue("Window should be showing", w.isShowing());
070:
071:                // Generates WINDOW_CLOSE, may or may not generate COMPONENT_HIDDEN
072:                w.dispose();
073:                wait(w, false, "WindowTracker didn't catch Window.dispose()");
074:                assertTrue("Window should not be showing", !w.isShowing());
075:            }
076:
077:            public void testSingleWindowReady() throws Throwable {
078:                JFrame f = new JFrame(getName());
079:                MouseWatcher watcher = new MouseWatcher();
080:                f.addMouseListener(watcher);
081:                f.getContentPane().add(new JLabel(getName()));
082:                f.pack();
083:                f.setSize(100, 100);
084:                f.setVisible(true);
085:                try {
086:                    wait(f, true,
087:                            "WindowTracker didn't catch initial Window.show");
088:                    getRobot().click(f);
089:                    getRobot().waitForIdle();
090:                    if (!watcher.gotClick)
091:                        throw new MissedShow1();
092:
093:                    watcher.gotClick = false;
094:                    f.setVisible(false);
095:                    wait(f, false,
096:                            "WindowTracker didn't catch Window.hide after show");
097:
098:                    f.setVisible(true);
099:                    wait(f, true,
100:                            "WindowTracker didn't catch Window.show after hide");
101:                    assertTrue("Window not ready", tracker.isWindowReady(f));
102:                    getRobot().click(f);
103:                    getRobot().waitForIdle();
104:                    if (!watcher.gotClick)
105:                        throw new MissedShow2();
106:                } finally {
107:                    f.dispose();
108:                }
109:            }
110:
111:            public void testComplexWindowReady() throws Throwable {
112:                JList list = new JList(new String[] { "one", "two", "three",
113:                        "four", "five" });
114:                JFrame f = new JFrame(getName() + "1");
115:                f.getContentPane().add(list);
116:                MouseWatcher watcher = new MouseWatcher();
117:                list.addMouseListener(watcher);
118:                f.pack();
119:                f.setLocation(100, 100);
120:                f.setVisible(true);
121:                try {
122:                    wait(f, true, "WindowTracker didn't catch window");
123:
124:                    getRobot().click(list);
125:                    getRobot().waitForIdle();
126:
127:                    assertTrue("Window not ready for click", watcher.gotClick);
128:                } finally {
129:                    f.dispose();
130:                }
131:            }
132:
133:            // Not required when using mouse motion to detect window readiness
134:            /*
135:            public void testTrackRepeatedWindowReady() throws Throwable {
136:                // This test is only required in Robot mode
137:                if (Robot.getEventMode() != Robot.EM_ROBOT)
138:                    return;
139:                int EXPECTED = 100;
140:                int count1 = EXPECTED;
141:                int count2 = EXPECTED;
142:                int count3 = EXPECTED;
143:                for (int i=0;i < EXPECTED;i++) {
144:                    try {
145:                        testSingleWindowReady();
146:                    }
147:                    catch(MissedShow1 e) {
148:                        --count1;
149:                    }
150:                    catch(MissedShow2 e) {
151:                        --count2;
152:                    }
153:                    try {
154:                        testComplexWindowReady();
155:                    }
156:                    catch(AssertionFailedError e) {
157:                        --count3;
158:                    }
159:                }
160:                assertEquals("Missed some clicks on initial show", EXPECTED, count1);
161:                assertEquals("Missed some clicks on subsequent show", EXPECTED, count2);
162:                assertEquals("Missed clicks on complex window", EXPECTED, count3);
163:            }
164:             */
165:            public void testTrackWindowReadyAfterDispose() throws Exception {
166:                final Frame w = new Frame(getName());
167:                getRobot().invokeAndWait(new Runnable() {
168:                    public void run() {
169:                        w.pack();
170:                        w.setVisible(true);
171:                    }
172:                });
173:                wait(w, true, "Didn't catch initial Window.show()");
174:                assertTrue("Window not showing", w.isShowing());
175:
176:                getRobot().invokeAndWait(new Runnable() {
177:                    public void run() {
178:                        w.dispose();
179:                    }
180:                });
181:                wait(w, false, "Didn't catch Window.dispose()");
182:                assertTrue("Window not hidden", !w.isShowing());
183:
184:                getRobot().invokeAndWait(new Runnable() {
185:                    public void run() {
186:                        w.pack();
187:                        w.setVisible(true);
188:                    }
189:                });
190:                wait(w, true,
191:                        "Didn't catch Window.show() after dispose(), pack()");
192:                assertTrue("Window not showing", w.isShowing());
193:            }
194:
195:            public void testDetectEmptyDialog() {
196:                final Frame w = new Frame(getName());
197:                final Dialog d = new Dialog(w, getName());
198:                getRobot().invokeAndWait(new Runnable() {
199:                    public void run() {
200:                        w.pack();
201:                        w.setVisible(true);
202:                        d.pack();
203:                        d.setVisible(true);
204:                    }
205:                });
206:                wait(d, true, "Didn't catch empty dialog");
207:                assertTrue("Dialog not showing", d.isShowing());
208:            }
209:
210:            public static void main(String[] args) {
211:                RepeatHelper.runTests(args, WindowTrackerTest.class);
212:            }
213:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.