Source Code Cross Referenced for RobotDragDropTest.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 javax.swing.event.*;
007:
008:        import junit.extensions.abbot.*;
009:        import junit.extensions.abbot.Timer;
010:        import abbot.util.Bugs;
011:
012:        /** Unit test to verify Robot drag/drop operation.  Include "Native" in 
013:         * the test name if the test depends on native drag and drop. 
014:         */
015:        // FIXME w32 has sporadic errors (4 failures on a repeat of 50) where the drag
016:        // gesture is not recognized (it might be that post-press mouse move is missed)
017:        // The failure is also present on non-native drags
018:        public class RobotDragDropTest extends ComponentTestFixture {
019:
020:            /** Ensure drag gestures are recognized. */
021:            public void testNativeDragDrop() throws Exception {
022:                DragLabel c = new DragLabel(getName());
023:                showFrame(c);
024:                robot.drag(c, c.getWidth() / 2, c.getHeight() / 2);
025:                Timer timer = new Timer();
026:                while (!c.dragStarted) {
027:                    if (timer.elapsed() > EVENT_GENERATION_DELAY) {
028:                        fail("Drag gesture not recognized");
029:                    }
030:                    if (c.exception != null)
031:                        throw c.exception;
032:                    robot.sleep();
033:                }
034:
035:                robot.drop(c, 1, 1);
036:                timer.reset();
037:                while (!c.dropAccepted || !c.dragEnded) {
038:                    if (timer.elapsed() > EVENT_GENERATION_DELAY) {
039:                        assertTrue("Drag never ended", c.dragEnded);
040:                        assertTrue("Drag not accepted", c.dropAccepted);
041:                    }
042:                    robot.sleep();
043:                }
044:                // Fails on OSX 1.3.1, 1.4.1 (VM bug)
045:                assertTrue("Drag ended, but drop failed", c.dropSuccessful);
046:            }
047:
048:            public void testNativeDragDropAcrossComponents() throws Exception {
049:                DragLabel c1 = new DragLabel("Start drag here", false);
050:                DropLabel c2 = new DropLabel("Drop here");
051:                JPanel pane = new JPanel();
052:                pane.add(c1);
053:                pane.add(c2);
054:
055:                showFrame(pane);
056:                robot.drag(c1, c1.getWidth() / 2, c1.getHeight() / 2);
057:                Timer timer = new Timer();
058:                while (!c1.dragStarted) {
059:                    if (timer.elapsed() > EVENT_GENERATION_DELAY) {
060:                        fail("Drag gesture not recognized");
061:                    }
062:                    if (c1.exception != null)
063:                        throw c1.exception;
064:                    robot.sleep();
065:                }
066:                robot.drop(c2, c2.getWidth() / 2, c2.getHeight() / 2);
067:                timer.reset();
068:                // source drag exit is not reliable; w32 sends it after drop accepted,
069:                // OSX never sends it
070:                while (!c2.dragEntered || !c2.dropAccepted || !c1.dragEnded) {
071:                    if (timer.elapsed() > EVENT_GENERATION_DELAY) {
072:                        assertTrue("Never received drag enter on target",
073:                                c2.dragEntered);
074:                        assertTrue("Never received drag end", c1.dragEnded);
075:                        assertTrue("Drop not accepted", c2.dropAccepted);
076:                    }
077:                    robot.sleep();
078:                }
079:                // Fails on OSX 1.3.1, 1.4.1 (VM bug)
080:                assertTrue("Drag ended, but drop failed", c1.dropSuccessful);
081:            }
082:
083:            public void testNativeDragDropToJTree() throws Exception {
084:                DragLabel label = new DragLabel("Start drag here", false);
085:                DropTree tree = new DropTree();
086:                JPanel pane = new JPanel();
087:                pane.add(label);
088:                pane.add(tree);
089:                showFrame(pane);
090:                robot.drag(label, label.getWidth() / 2, label.getHeight() / 2);
091:                Timer timer = new Timer();
092:                while (!label.dragStarted) {
093:                    if (timer.elapsed() > EVENT_GENERATION_DELAY) {
094:                        fail("Drag gesture not recognized");
095:                    }
096:                    if (label.exception != null)
097:                        throw label.exception;
098:                    robot.sleep();
099:                }
100:                Rectangle rect = tree.getRowBounds(2);
101:                robot.drop(tree, rect.x + rect.width / 2, rect.y + rect.height
102:                        / 2);
103:                timer.reset();
104:                while (!tree.dragEntered || !tree.dropAccepted
105:                        || !label.dragEnded) {
106:                    if (timer.elapsed() > EVENT_GENERATION_DELAY) {
107:                        assertTrue("Drag never entered drop target",
108:                                tree.dragEntered);
109:                        assertTrue("Drag never ended", label.dragEnded);
110:                        assertTrue("Drag not accepted", tree.dropAccepted);
111:                    }
112:                    robot.sleep();
113:                }
114:                // Fails on OSX 1.3.1, 1.4.1 (VM bug)
115:                assertTrue("Drag ended, but drop failed", label.dropSuccessful);
116:            }
117:
118:            public void testNativeDragDropToJTable() throws Exception {
119:                DragLabel label = new DragLabel("Start drag here", false);
120:                DropTable table = new DropTable();
121:                JPanel pane = new JPanel();
122:                pane.add(label);
123:                pane.add(table);
124:                showFrame(pane);
125:                robot.drag(label, label.getWidth() / 2, label.getHeight() / 2);
126:                Timer timer = new Timer();
127:                while (!label.dragStarted) {
128:                    if (timer.elapsed() > EVENT_GENERATION_DELAY) {
129:                        fail("Drag gesture not recognized");
130:                    }
131:                    if (label.exception != null)
132:                        throw label.exception;
133:                    robot.sleep();
134:                }
135:                Rectangle rect = table.getCellRect(1, 1, false);
136:                robot.drop(table, rect.x + rect.width / 2, rect.y + rect.height
137:                        / 2);
138:                timer.reset();
139:                while (!table.dragEntered || !table.dropAccepted
140:                        || !label.dragEnded) {
141:                    if (timer.elapsed() > EVENT_GENERATION_DELAY) {
142:                        assertTrue("Drag never entered drop target",
143:                                table.dragEntered);
144:                        assertTrue("Drag never ended", label.dragEnded);
145:                        assertTrue("Drag not accepted", table.dropAccepted);
146:                    }
147:                    robot.sleep();
148:                }
149:                // Fails on OSX 1.3.1, 1.4.1 (VM bug)
150:                assertTrue("Drag ended, but drop failed", label.dropSuccessful);
151:            }
152:
153:            public void testJavaDragDrop() {
154:                JLabel label = new JLabel(getName());
155:                showFrame(label);
156:                class DragListener extends MouseInputAdapter {
157:                    public boolean gotDrag = false;
158:
159:                    public void mouseDragged(MouseEvent me) {
160:                        gotDrag = true;
161:                    }
162:                }
163:                DragListener ma = new DragListener();
164:                label.addMouseListener(ma);
165:                label.addMouseMotionListener(ma);
166:                getRobot().drag(label, 1, 1);
167:                getRobot().waitForIdle();
168:                getRobot().drop(label, label.getWidth() / 2,
169:                        label.getHeight() / 2);
170:                getRobot().waitForIdle();
171:                assertTrue("Should have seen a drag event", ma.gotDrag);
172:            }
173:
174:            /** Note the event mode when reporting this test's name. */
175:            public String getName() {
176:                return Robot.getEventMode() == Robot.EM_AWT ? super .getName()
177:                        + " (AWT mode)" : super .getName();
178:            }
179:
180:            public void runBare() throws Throwable {
181:                if (!Bugs.dragDropRequiresNativeEvents()
182:                        || Robot.getEventMode() == Robot.EM_ROBOT
183:                        || getName().indexOf("Native") == -1) {
184:                    super .runBare();
185:                } else {
186:                    System.err.println("Skipping test " + getName());
187:                }
188:            }
189:
190:            private Frame frame;
191:
192:            protected Frame showFrame(Component c) {
193:                return frame = super .showFrame(c);
194:            }
195:
196:            private Robot robot;
197:
198:            protected void setUp() {
199:                robot = getRobot();
200:            }
201:
202:            protected void tearDown() {
203:                if (frame != null) {
204:                    // Clear the DnD state
205:                    robot.click(frame);
206:                }
207:            }
208:
209:            /** Provide for repetitive testing on individual tests. */
210:            public static void main(String[] args) {
211:                RepeatHelper.runTests(args, RobotDragDropTest.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.