Source Code Cross Referenced for TestHierarchyTest.java in  » Testing » abbot-1.0.1 » abbot » finder » 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.finder 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package abbot.finder;
002:
003:        import java.awt.*;
004:        import java.awt.event.*;
005:        import javax.swing.*;
006:
007:        import junit.extensions.abbot.*;
008:        import abbot.Log;
009:        import abbot.tester.*;
010:        import abbot.util.AWT;
011:        import abbot.finder.matchers.*;
012:
013:        public class TestHierarchyTest extends ComponentTestFixture {
014:
015:            private TestHierarchy hierarchy;
016:
017:            protected Hierarchy createHierarchy() {
018:                return new TestHierarchy();
019:            }
020:
021:            protected void setUp() {
022:                hierarchy = (TestHierarchy) getHierarchy();
023:                Log.addDebugClass(TestHierarchy.class);
024:                Log.setShowThreads(true);
025:            }
026:
027:            protected void hideWindow(Window w) {
028:                // Explicitly wait for the window close event
029:                // before checking for results to avoid timing errors; not sure why
030:                // there's a delay though (waitForIdle doesn't work in this case).
031:                class Flag {
032:                    volatile boolean closed;
033:                }
034:                final Flag flag = new Flag();
035:                w.addWindowListener(new WindowAdapter() {
036:                    public void windowClosed(WindowEvent e) {
037:                        e.getWindow().removeWindowListener(this );
038:                        flag.closed = true;
039:                    }
040:                });
041:                super .hideWindow(w);
042:                while (!flag.closed) {
043:                    getRobot().sleep();
044:                }
045:            }
046:
047:            public void testFilterNewIgnoredWindows() throws Exception {
048:                TestHierarchy hierarchy = new TestHierarchy();
049:                Frame f = showFrame(new JLabel(getName()));
050:                assertTrue("Frame should be in hierarchy", hierarchy
051:                        .contains(f));
052:
053:                hierarchy.dispose(f);
054:                showWindow(f);
055:                assertTrue("Frame should no longer appear in hierarchy",
056:                        !hierarchy.contains(f));
057:
058:                JDialog d = new JDialog(f, getName());
059:                d.getContentPane().add(new JLabel("dialog"));
060:                showWindow(d);
061:                assertTrue(
062:                        "Filtered frame dialog should not appear in hierarchy",
063:                        !hierarchy.contains(d));
064:
065:                disposeWindow(d);
066:                assertTrue("Disposed dialog should not appear in hierarhcy",
067:                        !hierarchy.contains(d));
068:
069:                showWindow(d);
070:                assertTrue("Redisplayed dialog should not appear in hierarchy",
071:                        !hierarchy.contains(d));
072:            }
073:
074:            public void testAutoFilterDisposedWindows() throws Exception {
075:                JButton openButton = new JButton("open");
076:                final Frame f = showFrame(openButton);
077:                class Flag {
078:                    volatile boolean flag = true;
079:                }
080:                final Flag flag = new Flag();
081:                final String CLOSE = "close";
082:                class TestDialog extends JDialog {
083:                    public TestDialog(final boolean dispose) {
084:                        super (f, TestHierarchyTest.this .getName());
085:                        JButton close = new JButton(CLOSE);
086:                        close.setName(CLOSE);
087:                        getContentPane().add(close);
088:                        close.addActionListener(new ActionListener() {
089:                            public void actionPerformed(ActionEvent e) {
090:                                if (dispose)
091:                                    TestDialog.this .dispose();
092:                                else
093:                                    TestDialog.this .setVisible(false);
094:                            }
095:                        });
096:                        setModal(true);
097:                    }
098:                }
099:                openButton.addActionListener(new ActionListener() {
100:                    public void actionPerformed(ActionEvent e) {
101:                        JDialog d = new TestDialog(flag.flag);
102:                        d.pack();
103:                        d.setVisible(true);
104:                    }
105:                });
106:                ComponentTester tester = new ComponentTester();
107:                tester.actionClick(openButton);
108:                JButton closeButton = (JButton) getFinder().find(
109:                        new NameMatcher(CLOSE));
110:                tester.actionClick(closeButton);
111:
112:                // This will bring up a new dialog; matching should match the new
113:                // dialog 
114:                tester.actionClick(openButton);
115:                JButton closeButton2 = (JButton) getFinder().find(
116:                        new NameMatcher(CLOSE));
117:                assertTrue("Should pick up new button, not old one: "
118:                        + closeButton, !closeButton2.equals(closeButton));
119:                tester.actionClick(closeButton2);
120:
121:                // Now don't do the dispose, and we expect to always get the same match
122:                flag.flag = false;
123:                tester.actionClick(openButton);
124:                closeButton = (JButton) getFinder()
125:                        .find(new NameMatcher(CLOSE));
126:                tester.actionClick(closeButton);
127:
128:                tester.actionClick(openButton);
129:                closeButton2 = (JButton) getFinder().find(
130:                        new NameMatcher(CLOSE));
131:                assertEquals("Second lookup should match first", closeButton,
132:                        closeButton2);
133:            }
134:
135:            public void testFilterMenuItem() throws Exception {
136:                JFrame frame = new JFrame(getName());
137:                JMenuBar mb = new JMenuBar();
138:                JMenu menu = new JMenu("File");
139:                JMenuItem mi = new JMenuItem("Item");
140:                menu.add(mi);
141:                mb.add(menu);
142:                frame.setJMenuBar(mb);
143:                showWindow(frame);
144:                hierarchy.dispose(frame);
145:                assertTrue("Hierarchy should no longer contain frame",
146:                        !hierarchy.contains(frame));
147:                assertTrue("Hierarchy should no longer contain menu bar",
148:                        !hierarchy.contains(mb));
149:                assertTrue("Hierarchy should no longer contain menu",
150:                        !hierarchy.contains(menu));
151:                assertTrue("Hierarchy should no longer contain menu item",
152:                        !hierarchy.contains(mi));
153:            }
154:
155:            public void testAutoRemoveFileChooserDialogs() throws Exception {
156:                final JFileChooser chooser = new JFileChooser();
157:                final Frame frame = showFrame(new JLabel(getName()));
158:                Dialog d1 = showModalDialog(new Runnable() {
159:                    public void run() {
160:                        chooser.showOpenDialog(frame);
161:                    }
162:                });
163:                hideWindow(d1);
164:                assertTrue(
165:                        "Transient file chooser dialog should now be filtered: "
166:                                + d1.getName(), hierarchy.isFiltered(d1));
167:                assertTrue(
168:                        "Transient file chooser dialog should no longer be in the hierarchy",
169:                        !hierarchy.contains(d1));
170:            }
171:
172:            public void testAutoRemoveJOptionPaneShowConfirm() throws Exception {
173:                final JLabel confirm = new JLabel("confirm");
174:                Runnable r = new Runnable() {
175:                    public void run() {
176:                        JOptionPane.showConfirmDialog(null, confirm);
177:                    }
178:                };
179:                Dialog d = showModalDialog(r);
180:                hideWindow(d);
181:                assertTrue(
182:                        "Transient option pane dialog should now be filtered: "
183:                                + d.getName(), hierarchy.isFiltered(d));
184:                assertTrue(
185:                        "Transient option pane dialog should no longer be in the hierarchy",
186:                        !hierarchy.contains(d));
187:            }
188:
189:            public void testAutoRemoveJOptionPaneShowInput() throws Exception {
190:                final JLabel input = new JLabel("input");
191:                Runnable r = new Runnable() {
192:                    public void run() {
193:                        JOptionPane.showInputDialog(null, input);
194:                    }
195:                };
196:                Dialog d = showModalDialog(r);
197:                hideWindow(d);
198:                assertTrue(
199:                        "Transient option pane dialog should now be filtered: "
200:                                + d.getName(), hierarchy.isFiltered(d));
201:                assertTrue(
202:                        "Transient option pane dialog should no longer be in the hierarchy",
203:                        !hierarchy.contains(d));
204:            }
205:
206:            public void testAutoRemoveJOptionPaneShowMessage() throws Exception {
207:                final JLabel message = new JLabel("message");
208:                Runnable r = new Runnable() {
209:                    public void run() {
210:                        JOptionPane.showMessageDialog(null, message);
211:                    }
212:                };
213:                Dialog d = showModalDialog(r);
214:                hideWindow(d);
215:                assertTrue(
216:                        "Transient option pane dialog should now be filtered: "
217:                                + d.getName(), hierarchy.isFiltered(d));
218:                assertTrue(
219:                        "Transient option pane dialog should no longer be in the hierarchy",
220:                        !hierarchy.contains(d));
221:            }
222:
223:            // 1.4+ only
224:            private Popup p1, p2;
225:
226:            public void testFindReusedPopup() {
227:                final JFrame frame = (JFrame) showFrame(new JTextField(
228:                        getName()));
229:                final JLabel message = new JLabel(getName());
230:                message.setSize(message.getPreferredSize());
231:                final PopupFactory f = PopupFactory.getSharedInstance();
232:                invokeAndWait(new Runnable() {
233:                    public void run() {
234:                        p1 = f.getPopup(frame.getContentPane(), message, frame
235:                                .getX()
236:                                + frame.getWidth(), frame.getY());
237:                        p1.show();
238:                    }
239:                });
240:                try {
241:                    Component c = getFinder().find(
242:                            new ClassMatcher(JLabel.class));
243:                    assertEquals("Wrong component found", message, c);
244:                } catch (Exception e) {
245:                    fail("Popup and contents not found");
246:                }
247:                // force a redisplay before the dispose of the first gets processed
248:                invokeAndWait(new Runnable() {
249:                    public void run() {
250:                        p1.hide();
251:                        p2 = f.getPopup(frame.getContentPane(), message, frame
252:                                .getX()
253:                                + frame.getWidth(), frame.getY());
254:                        p2.show();
255:                    }
256:                });
257:                //getRobot().delay(300000);
258:                try {
259:                    Component c = getFinder().find(
260:                            new ClassMatcher(JLabel.class));
261:                    assertEquals("Wrong component found after hide/show",
262:                            message, c);
263:                } catch (Exception e) {
264:                    fail("Popup and contents not found after hide/show");
265:                }
266:            }
267:
268:            public static void main(String[] args) {
269:                RepeatHelper.runTests(args, TestHierarchyTest.class);
270:            }
271:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.