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


001:        package abbot.editor;
002:
003:        import java.awt.*;
004:        import java.awt.event.InputEvent;
005:
006:        import junit.extensions.abbot.*;
007:        import abbot.util.Bugs;
008:        import abbot.script.*;
009:        import abbot.tester.*;
010:        import abbot.tester.Robot;
011:
012:        /** Verify operation of ScriptTable, and ScriptModel interactions. */
013:
014:        public class ScriptTableTest extends ComponentTestFixture {
015:
016:            private Script script;
017:            private ScriptModel model;
018:            private ScriptTable table;
019:            private JTableTester tester;
020:
021:            protected void setUp() {
022:                script = new Script(getHierarchy());
023:                model = new ScriptModel(script);
024:                table = new ScriptTable(model);
025:                tester = (JTableTester) ComponentTester.getTester(table);
026:            }
027:
028:            public void testInsertStep() {
029:                assertEquals("Wrong row count", 0, table.getRowCount());
030:                assertEquals("Wrong default cursor row", 0, table
031:                        .getCursorRow());
032:                model.insertStep(script, new Comment(script, "One"), 0);
033:                assertEquals("Wrong row count after insert", 1, table
034:                        .getRowCount());
035:            }
036:
037:            public void testToggle() {
038:                Sequence seq = new Sequence(script, getName());
039:                seq.addStep(new Comment(script, "One"));
040:                seq.addStep(new Comment(script, "Two"));
041:                seq.addStep(new Comment(script, "Three"));
042:                model.insertStep(script, seq, 0);
043:                assertEquals("Wrong row count after insert", 1, table
044:                        .getRowCount());
045:                showFrame(table, new Dimension(200, 200));
046:                // Double click to toggle
047:                tester.actionClick(table, new JTableLocation(0, 0),
048:                        InputEvent.BUTTON1_MASK, 2);
049:                assertEquals(
050:                        "Wrong row count after double click to toggle open", 4,
051:                        table.getRowCount());
052:                // Click on left end of cell to toggle
053:                openSequence(0);
054:                assertEquals("Wrong row count after click to toggle closed", 1,
055:                        table.getRowCount());
056:            }
057:
058:            public void testUpwardSelections() {
059:                Sequence seq1 = new Sequence(script, getName());
060:                seq1.addStep(new Comment(script, "One"));
061:                seq1.addStep(new Comment(script, "Two"));
062:                model.insertStep(script, seq1, 0);
063:                showFrame(table, new Dimension(200, 400));
064:                openSequence(0);
065:                assertEquals("All rows should be visible", 3, table
066:                        .getRowCount());
067:                tester.actionSelectCell(table, 1, 0);
068:                tester.actionClick(table, new JTableLocation(0, 0),
069:                        InputEvent.BUTTON1_MASK | InputEvent.SHIFT_MASK);
070:                assertEquals(
071:                        "Adding an ancestor to the selection should also select all the ancestor's children",
072:                        3, table.getSelectedRowCount());
073:            }
074:
075:            // FIXME interrmittent failure on linux 1.4.2_04 
076:            public void testDownwardSelections() {
077:                Sequence seq1 = new Sequence(script, getName());
078:                Sequence seq2 = new Sequence(script, getName());
079:                seq1.addStep(new Comment(script, "One"));
080:                seq1.addStep(seq2);
081:                seq2.addStep(new Comment(script, "Two"));
082:                seq2.addStep(new Comment(script, "Two and one half"));
083:                seq1.addStep(new Comment(script, "Three"));
084:                model.insertStep(script, seq1, 0);
085:                showFrame(table, new Dimension(200, 400));
086:                openSequence(0);
087:                assertEquals("All rows should be showing", 4, table
088:                        .getRowCount());
089:
090:                // Selecting the open sequence should result in all children selected
091:                tester.actionSelectCell(table, 0, 0);
092:                assertEquals(
093:                        "Full sequence should be selected when any one child is selected in conjunction with the parent",
094:                        4, table.getSelectedRowCount());
095:
096:                tester.actionSelectCell(table, 1, 0);
097:                int mask = InputEvent.BUTTON1_MASK | InputEvent.SHIFT_MASK;
098:                tester.actionClick(table, new JTableLocation(2, 0), mask);
099:                assertEquals(
100:                        "Sibling step selection should have no side effects",
101:                        2, table.getSelectedRowCount());
102:
103:                openSequence(2);
104:                tester.actionSelectCell(table, 1, 0);
105:                tester.actionClick(table, new JTableLocation(2, 0), mask);
106:                assertEquals(
107:                        "Sequence and all descendents should be selected when sequence is opened and it is not the only selection",
108:                        4, table.getSelectedRowCount());
109:            }
110:
111:            // FIXME sporadic w32 error
112:            public void testDragSingleStep() {
113:                if (Bugs.dragDropRequiresNativeEvents()
114:                        && Robot.getEventMode() != Robot.EM_ROBOT) {
115:                    System.err.println("Skipping " + getName());
116:                    return;
117:                }
118:
119:                Sequence seq = new Sequence(script, getName());
120:                seq.addStep(new Comment(script, "One"));
121:                seq.addStep(new Comment(script, "Two"));
122:                seq.addStep(new Comment(script, "Three"));
123:                seq.addStep(new Sequence(script, getName() + " inner"));
124:                model.insertStep(script, seq, 0);
125:                Comment c1 = new Comment(script, "first");
126:                Comment c2 = new Comment(script, "second");
127:                model.insertStep(script, c1, 1);
128:                model.insertStep(script, c2, 2);
129:                assertEquals("Wrong row count", 3, table.getRowCount());
130:                showFrame(table, new Dimension(200, 200));
131:                Rectangle rect = table.getCellRect(0, 0, false);
132:                tester.actionDrag(table, new JTableLocation(2, 0));
133:                tester.actionDrop(table, rect.x, rect.y + rect.height * 3 / 4);
134:                assertEquals("Last step incorrectly dragged", c2, model
135:                        .getStepAt(1));
136:                assertEquals("Displaced step incorrectly moved", c1, model
137:                        .getStepAt(2));
138:            }
139:
140:            public void testMoveUpSibling() {
141:                Step s1 = new Comment(script, "One");
142:                Step s2 = new Comment(script, "Two");
143:                model.insertStep(script, s1, 0);
144:                model.insertStep(script, s2, 1);
145:                table.setRowSelectionInterval(1, 1);
146:                table.moveUp();
147:                assertEquals("Step not moved", s2, table.getValueAt(0, 0));
148:                assertEquals("Wrong selection after move", 0, table
149:                        .getSelectedRow());
150:                assertEquals("Wrong selection size after move", 1, table
151:                        .getSelectedRowCount());
152:            }
153:
154:            // FIXME sporadic w32 failure
155:            public void testMoveUpOpenSequenceEmpty() {
156:                Sequence seq = new Sequence(script, getName());
157:                Step s1 = new Comment(script, "One");
158:                model.insertStep(script, seq, 0);
159:                model.insertStep(script, s1, 1);
160:                showFrame(table, new Dimension(200, 400));
161:                tester.actionClick(table, new JTableLocation(0, 0),
162:                        InputEvent.BUTTON1_MASK, 2);
163:                tester.actionSelectCell(table, 1, 0);
164:                table.moveUp();
165:                assertEquals("Step not moved into empty sequence", 1, seq
166:                        .size());
167:                assertEquals("Wrong selection after move", 1, table
168:                        .getSelectedRow());
169:                assertEquals("Wrong selection size after move", 1, table
170:                        .getSelectedRowCount());
171:            }
172:
173:            public void testMoveUpOpenSequence() {
174:                Sequence seq = new Sequence(script, getName());
175:                Step s1 = new Comment(script, "One");
176:                Step s2 = new Comment(script, "Two");
177:                seq.addStep(s2);
178:                model.insertStep(script, seq, 0);
179:                model.insertStep(script, s1, 1);
180:
181:                showFrame(table, new Dimension(200, 400));
182:                tester.actionClick(table, new JTableLocation(0, 0),
183:                        InputEvent.BUTTON1_MASK, 2);
184:                tester.actionSelectCell(table, 2, 0);
185:
186:                table.moveUp();
187:                assertEquals("Step not moved into sequence", 2, seq.size());
188:                assertEquals("Wrong selection after move", 2, table
189:                        .getSelectedRow());
190:                assertEquals("Wrong selection size after move", 1, table
191:                        .getSelectedRowCount());
192:                assertEquals("Wrong index in sequence", 1, seq.indexOf(s1));
193:            }
194:
195:            public void testMoveUpOut() {
196:                Sequence seq = new Sequence(script, getName());
197:                Step s1 = new Comment(script, "One");
198:                seq.addStep(s1);
199:                model.insertStep(script, seq, 0);
200:
201:                showFrame(table, new Dimension(200, 400));
202:                tester.actionClick(table, new JTableLocation(0, 0),
203:                        InputEvent.BUTTON1_MASK, 2);
204:                tester.actionSelectCell(table, 1, 0);
205:
206:                table.moveUp();
207:                assertEquals("Step not moved out of sequence", 0, seq.size());
208:                assertEquals("Wrong selection after move", 0, table
209:                        .getSelectedRow());
210:                assertEquals("Wrong selection size after move", 1, table
211:                        .getSelectedRowCount());
212:                assertEquals("Wrong index in script", 0, script.indexOf(s1));
213:            }
214:
215:            public void testMoveDownSibling() {
216:                Step s1 = new Comment(script, "One");
217:                Step s2 = new Comment(script, "Two");
218:                model.insertStep(script, s1, 0);
219:                model.insertStep(script, s2, 1);
220:                table.setRowSelectionInterval(0, 0);
221:                table.moveDown();
222:                assertEquals("Step not moved", s1, table.getValueAt(1, 0));
223:                assertEquals("Step not selected", 1, table.getSelectedRow());
224:                assertEquals("Wrong selection size", 1, table
225:                        .getSelectedRowCount());
226:            }
227:
228:            public void testMoveDownOpenSequence() {
229:                Step s1 = new Comment(script, "One");
230:                Sequence seq = new Sequence(script, getName());
231:                model.insertStep(script, s1, 0);
232:                model.insertStep(script, seq, 1);
233:
234:                showFrame(table, new Dimension(200, 400));
235:                tester.actionClick(table, new JTableLocation(1, 0),
236:                        InputEvent.BUTTON1_MASK, 2);
237:                tester.actionSelectCell(table, 0, 0);
238:
239:                table.moveDown();
240:                assertEquals("Stop should have moved into sequence", 1, seq
241:                        .size());
242:                assertEquals("Step not moved", s1, table.getValueAt(1, 0));
243:                assertEquals("Step not selected", 1, table.getSelectedRow());
244:                assertEquals("Wrong selection size", 1, table
245:                        .getSelectedRowCount());
246:            }
247:
248:            public void testSetCursorPrevious() {
249:                Step s1 = new Comment(script, "One");
250:                Step s2 = new Comment(script, "Two");
251:                model.insertStep(script, s1, 0);
252:                model.insertStep(script, s2, 1);
253:                showFrame(table, new Dimension(200, 400));
254:                Rectangle rect = table.getCellRect(1, 0, false);
255:                tester.actionClick(table, rect.x, rect.y);
256:                assertEquals("Wrong cursor row", 1, table.getCursorRow());
257:                assertEquals("Wrong cursor parent", script, table
258:                        .getCursorParent());
259:                assertEquals("Wrong cursor parent index", 1, table
260:                        .getCursorParentIndex());
261:                rect = table.getCellRect(0, 0, false);
262:                tester.actionClick(table, rect.x, rect.y);
263:                assertEquals("Wrong cursor row", 0, table.getCursorRow());
264:                assertEquals("Wrong cursor parent", script, table
265:                        .getCursorParent());
266:                assertEquals("Wrong cursor parent index", 0, table
267:                        .getCursorParentIndex());
268:            }
269:
270:            public void testSetCursorNext() {
271:                Step s1 = new Comment(script, "One");
272:                Step s2 = new Comment(script, "Two");
273:                model.insertStep(script, s1, 0);
274:                model.insertStep(script, s2, 1);
275:                showFrame(table, new Dimension(200, 400));
276:                Rectangle rect = table.getCellRect(1, 0, false);
277:                tester.actionClick(table, rect.x, rect.y + rect.height * 3 / 4);
278:                assertEquals("Wrong cursor row", 2, table.getCursorRow());
279:                assertEquals("Wrong cursor parent", script, table
280:                        .getCursorParent());
281:                assertEquals("Wrong cursor parent index", 2, table
282:                        .getCursorParentIndex());
283:                rect = table.getCellRect(0, 0, false);
284:                tester.actionClick(table, rect.x, rect.y + rect.height * 3 / 4);
285:                assertEquals("Wrong cursor row", 1, table.getCursorRow());
286:                assertEquals("Wrong cursor parent", script, table
287:                        .getCursorParent());
288:                assertEquals("Wrong cursor parent index", 1, table
289:                        .getCursorParentIndex());
290:            }
291:
292:            public void testDoubleClickOpenClose() {
293:                Sequence seq1 = new Sequence(script, "One");
294:                Sequence seq2 = new Sequence(script, "Two");
295:                seq1.addStep(seq2);
296:                Step s1 = new Comment(script, "A");
297:                model.insertStep(script, seq1, 0);
298:                model.insertStep(script, s1, 1);
299:                showFrame(table, new Dimension(200, 400));
300:
301:                tester.actionClick(table, new JTableLocation(0, 0),
302:                        InputEvent.BUTTON1_MASK, 2);
303:                assertTrue("First sequence not expanded on double click", model
304:                        .isOpen(seq1));
305:                assertEquals("Expanded sequence not reflected in table", 3,
306:                        table.getRowCount());
307:                assertTrue("Second sequence should be closed", !model
308:                        .isOpen(seq2));
309:
310:                tester.actionClick(table, new JTableLocation(1, 0),
311:                        InputEvent.BUTTON1_MASK, 2);
312:                assertTrue(
313:                        "Second sequence should have been opened on double click",
314:                        model.isOpen(seq2));
315:
316:                tester.actionClick(table, new JTableLocation(0, 0),
317:                        InputEvent.BUTTON1_MASK, 2);
318:                assertTrue("First sequence not closed on double click", !model
319:                        .isOpen(seq1));
320:                assertEquals("Closed sequence not reflected in table", 2, table
321:                        .getRowCount());
322:                assertTrue("Second sequence should still be open", model
323:                        .isOpen(seq2));
324:            }
325:
326:            public void testClickOpenClose() {
327:                Sequence seq1 = new Sequence(script, "One");
328:                Sequence seq2 = new Sequence(script, "Two");
329:                seq1.addStep(seq2);
330:                Step s1 = new Comment(script, "A");
331:                model.insertStep(script, seq1, 0);
332:                model.insertStep(script, s1, 1);
333:                showFrame(table, new Dimension(200, 400));
334:                Rectangle rect = table.getCellRect(0, 0, false);
335:                tester.actionClick(table, rect.x, rect.y + rect.height / 2);
336:                assertTrue("First sequence not expanded on icon click", model
337:                        .isOpen(seq1));
338:                assertEquals("Expanded sequence not reflected in table", 3,
339:                        table.getRowCount());
340:                Rectangle rect2 = table.getCellRect(1, 0, false);
341:                tester.actionClick(table, rect2.x, rect2.y + rect2.height / 2);
342:                assertTrue("Second sequence not opened on icon click", model
343:                        .isOpen(seq2));
344:
345:                tester.actionClick(table, rect.x, rect.y + rect.height / 2);
346:                assertTrue("First sequence not closed on icon click", !model
347:                        .isOpen(seq1));
348:                assertEquals("Closed sequence not reflected in table", 2, table
349:                        .getRowCount());
350:                assertTrue("Second sequence should still be open", model
351:                        .isOpen(seq2));
352:            }
353:
354:            public void testSetCursorNested() {
355:                Sequence seq1 = new Sequence(script, "One");
356:                Sequence seq2 = new Sequence(script, "Two");
357:                seq1.addStep(seq2);
358:                Step s1 = new Comment(script, "a");
359:                model.insertStep(script, seq1, 0);
360:                model.insertStep(script, s1, 1);
361:                showFrame(table, new Dimension(200, 400));
362:                tester.actionClick(table, new JTableLocation(0, 0),
363:                        InputEvent.BUTTON1_MASK, 2);
364:                assertTrue("First sequence not expanded", model.isOpen(seq1));
365:                assertEquals("Expanded sequence not reflected in table", 3,
366:                        table.getRowCount());
367:                tester.actionClick(table, new JTableLocation(1, 0),
368:                        InputEvent.BUTTON1_MASK, 2);
369:                assertTrue("Second sequence not opened", model.isOpen(seq2));
370:
371:                // (script)
372:                // sequence 1
373:                //   sequence 2
374:                //     (3)
375:                //   (2)
376:                // (1)
377:                // comment
378:                //
379:                // Should be three possible cursor positions on row 2
380:                // 1) sibling to seq1
381:                // 2) sibling to seq2
382:                // 3) child of seq2
383:                Rectangle rect = table.getCellRect(1, 0, false);
384:                Point target = new Point(table.getDepthIndentation(0), rect.y
385:                        + rect.height * 7 / 8);
386:
387:                table.setCursorLocation(target);
388:                assertEquals("Leftmost cursor should target script as parent",
389:                        script, table.getCursorParent());
390:                assertEquals("Wrong target index in parent", 1, table
391:                        .getCursorParentIndex());
392:                assertEquals("Wrong cursor row", 2, table.getCursorRow());
393:
394:                target.x = table.getDepthIndentation(1);
395:                table.setCursorLocation(target);
396:                assertEquals("Point at " + target
397:                        + " should target outer sequence", seq1, table
398:                        .getCursorParent());
399:                assertEquals("Wrong target index in parent", 1, table
400:                        .getCursorParentIndex());
401:                assertEquals("Wrong cursor row", 2, table.getCursorRow());
402:
403:                target.x = table.getDepthIndentation(2);
404:                table.setCursorLocation(target);
405:                assertEquals("Point at " + target
406:                        + " should target inner sequence", seq2, table
407:                        .getCursorParent());
408:                assertEquals("Wrong target index in parent", 0, table
409:                        .getCursorParentIndex());
410:                assertEquals("Wrong cursor row", 2, table.getCursorRow());
411:            }
412:
413:            // Showed up as a bug in 1.4.2_01 (w32)
414:            public void testHideSequence() {
415:                Sequence s1 = new Sequence(script, "Hide me");
416:                for (int i = 0; i < 100; i++) {
417:                    s1.addStep(new Comment(script, String.valueOf(i)));
418:                }
419:                model.insertStep(script, s1, 0);
420:                showFrame(table, new Dimension(200, 400));
421:                Rectangle rect = table.getCellRect(0, 0, false);
422:                tester.actionClick(table, rect.x, rect.y + rect.height / 2);
423:                // ensure it's not a double click
424:                tester.delay(500);
425:                tester.actionClick(table, rect.x, rect.y + rect.height / 2);
426:            }
427:
428:            private void openSequence(int row) {
429:                Rectangle rect = table.getCellRect(row, 0, false);
430:                tester.actionClick(table, rect.x + table.getIndentation(0),
431:                        rect.y + rect.height / 2);
432:            }
433:
434:            /** Run the default test suite. */
435:            public static void main(String[] args) {
436:                TestHelper.runTests(args, ScriptTableTest.class);
437:            }
438:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.