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


001:        package abbot.editor.recorder;
002:
003:        import java.awt.*;
004:        import java.awt.event.*;
005:        import javax.swing.*;
006:        import java.util.*;
007:
008:        import junit.extensions.abbot.ComponentTestFixture;
009:        import junit.extensions.abbot.ResolverFixture;
010:        import abbot.*;
011:        import abbot.script.*;
012:        import abbot.tester.*;
013:        import abbot.tester.Robot;
014:        import abbot.util.*;
015:
016:        /** Provide generic support for checking contents of recorded steps. */
017:        // FIXME still needs some refactoring
018:        public abstract class AbstractRecorderFixture extends ResolverFixture {
019:
020:            private EventWatcher watcher;
021:            private Recorder recorder;
022:            private RecordingFailedException failure;
023:
024:            public AbstractRecorderFixture() {
025:            }
026:
027:            public AbstractRecorderFixture(String name) {
028:                super (name);
029:            }
030:
031:            /** Provide a recorder to handle the input stream. */
032:            protected abstract Recorder getRecorder();
033:
034:            public void runBare() throws Throwable {
035:                // Skip all recorder tests if not in robot mode, since there's no point
036:                // in recording AWT-stuffed events.
037:                if (Robot.getEventMode() == Robot.EM_ROBOT) {
038:                    try {
039:                        super .runBare();
040:                    } finally {
041:                        if (failure != null) {
042:                            throw failure.getReason() != null ? failure
043:                                    .getReason() : failure;
044:                        }
045:                    }
046:                }
047:            }
048:
049:            protected void fixtureTearDown() throws Throwable {
050:                stopRecording();
051:                recorder = null;
052:                if (watcher != null) {
053:                    watcher.clear();
054:                    watcher = null;
055:                }
056:                super .fixtureTearDown();
057:            }
058:
059:            protected void startRecording() {
060:                Log.debug("start recording");
061:                recorder = getRecorder();
062:                watcher = new EventWatcher();
063:                watcher.startListening(recorder.getEventMask());
064:            }
065:
066:            protected void stopRecording() {
067:                EventWatcher w = watcher;
068:                if (w != null)
069:                    w.stopListening();
070:            }
071:
072:            protected String bugInfo(String msg) {
073:                return "(" + new BugReport(msg) + ")";
074:            }
075:
076:            public void assertStep(String pattern, Step step) {
077:                assertStep(pattern, step, null);
078:            }
079:
080:            /** Clear the current state. */
081:            protected void clear() {
082:                clearEvents();
083:            }
084:
085:            /** Clear the event history. */
086:            protected synchronized void clearEvents() {
087:                if (watcher != null)
088:                    watcher.clear();
089:            }
090:
091:            /** Allow derived classes to insert an event into the event stream to be
092:                recorded. */
093:            protected void insertEvent(AWTEvent e) {
094:                if (watcher != null)
095:                    watcher.eventDispatched(e);
096:            }
097:
098:            protected synchronized String listEvents() {
099:                return watcher != null ? watcher.listEvents() : "<empty>";
100:            }
101:
102:            public synchronized void assertStep(String pattern, Step step,
103:                    String events) {
104:                String bugInfo;
105:                if (events == null) {
106:                    bugInfo = bugInfo(listEvents());
107:                    clearEvents();
108:                } else {
109:                    bugInfo = bugInfo(events);
110:                }
111:                Log.log(step != null ? ("Examining step: " + step)
112:                        : "No step available (expected '" + pattern + "')");
113:                assertTrue("Expected <" + pattern
114:                        + ">, but no step was captured " + bugInfo,
115:                        step != null);
116:                assertTrue("Incorrect step, expected <" + pattern
117:                        + ">, but got <" + step + "> " + bugInfo, Regexp
118:                        .stringContainsMatch(pattern, step.toString()));
119:            }
120:
121:            public String toString(Sequence seq) {
122:                String steps = "The recorded steps were the following:";
123:                for (int i = 0; i < seq.size(); i++) {
124:                    steps += "\n" + seq.getStep(i);
125:                }
126:                return steps;
127:            }
128:
129:            public void assertStepCount(int count, Sequence seq) {
130:                String steps = toString(seq);
131:                String bugInfo = bugInfo(listEvents() + "\n\n" + steps);
132:                assertTrue("Wrong number of steps captured, expected <" + count
133:                        + ">, but got <" + seq.size() + "> " + bugInfo,
134:                        count == seq.size());
135:            }
136:
137:            protected class EventWatcher implements  AWTEventListener {
138:                protected ArrayList events = new ArrayList();
139:                private EventNormalizer normalizer = new EventNormalizer(true);
140:
141:                public void startListening(long mask) {
142:                    Log.debug("start listening, mask=0x"
143:                            + Integer.toHexString((int) mask));
144:                    clear();
145:                    Log.debug("events cleared");
146:                    normalizer.startListening(this , mask);
147:                }
148:
149:                public void stopListening() {
150:                    normalizer.stopListening();
151:                }
152:
153:                public void eventDispatched(AWTEvent event) {
154:                    if (Boolean.getBoolean("abbot.recorder.log_events"))
155:                        Log.log(Robot.toString(event));
156:                    synchronized (events) {
157:                        events.add(event);
158:                    }
159:                    Recorder r = recorder;
160:                    if (r != null) {
161:                        try {
162:                            r.record(event);
163:                        } catch (RecordingFailedException e) {
164:                            failure = e;
165:                        }
166:                    }
167:                }
168:
169:                public void clear() {
170:                    synchronized (events) {
171:                        events.clear();
172:                    }
173:                }
174:
175:                public String listEvents() {
176:                    String msg = "The generated event stream was the following:";
177:                    Iterator iter;
178:                    synchronized (events) {
179:                        iter = new ArrayList(events).iterator();
180:                    }
181:                    if (!iter.hasNext()) {
182:                        msg += "\n(No events were captured)";
183:                    } else
184:                        while (iter.hasNext()) {
185:                            AWTEvent ev = (AWTEvent) iter.next();
186:                            msg += "\n" + ComponentTester.toString(ev);
187:                        }
188:                    return msg;
189:                }
190:            }
191:
192:            private abstract class PopupListener extends MouseAdapter {
193:                protected abstract void showPopup(MouseEvent e);
194:
195:                public void mousePressed(MouseEvent e) {
196:                    if (e.isPopupTrigger())
197:                        showPopup(e);
198:                }
199:
200:                public void mouseReleased(MouseEvent e) {
201:                    if (e.isPopupTrigger())
202:                        showPopup(e);
203:                }
204:            }
205:
206:            /** Hook up the popup to be displayed on the given component. */
207:            protected void addPopup(Component c, final PopupMenu popup) {
208:                c.add(popup);
209:                c.addMouseListener(new PopupListener() {
210:                    protected void showPopup(MouseEvent e) {
211:                        popup.show(e.getComponent(), e.getX(), e.getY());
212:                    }
213:                });
214:            }
215:
216:            /** Hook up the popup to be displayed on the given component. */
217:            protected void addPopup(Component c, final JPopupMenu popup) {
218:                c.addMouseListener(new PopupListener() {
219:                    protected void showPopup(MouseEvent e) {
220:                        popup.show(e.getComponent(), e.getX(), e.getY());
221:                    }
222:                });
223:            }
224:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.