Source Code Cross Referenced for SearchTest.java in  » IDE-Netbeans » editor » search_replace » 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 » IDE Netbeans » editor » search_replace 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        package search_replace;
043:
044:        import java.awt.Component;
045:        import java.awt.Window;
046:        import java.awt.event.KeyEvent;
047:        import org.netbeans.jellytools.EditorOperator;
048:        import lib.EditorTestCase;
049:        import org.netbeans.jellytools.HelpOperator;
050:        import org.netbeans.jellytools.MainWindowOperator;
051:        import org.netbeans.jellytools.actions.FindAction;
052:        import org.netbeans.jellytools.modules.editor.Find;
053:        import org.netbeans.jemmy.ComponentChooser;
054:        import org.netbeans.jemmy.EventTool;
055:        import org.netbeans.jemmy.TestOut;
056:        import org.netbeans.jemmy.TimeoutExpiredException;
057:        import org.netbeans.jemmy.operators.JComboBoxOperator;
058:        import org.netbeans.jemmy.operators.JEditorPaneOperator;
059:        import org.netbeans.jemmy.operators.WindowOperator;
060:
061:        /**
062:         * Test of find functionality in editor.
063:         *
064:         * @author Roman Strobl
065:         */
066:        public class SearchTest extends EditorTestCase {
067:
068:            private static int FIND_TIMEOUT = 1000;
069:
070:            /**
071:             * Creates a new instance of Main
072:             * @param testMethodName name of test
073:             */
074:            public SearchTest(String testMethodName) {
075:                super (testMethodName);
076:            }
077:
078:            @Override
079:            protected void setUp() throws Exception {
080:                super .setUp();
081:                closeFindDialogIfOpened();
082:            }
083:
084:            /**
085:             * TC1 - open and close find dialog
086:             */
087:            public void testFindDialogOpenClose() {
088:                openDefaultProject();
089:                openDefaultSampleFile();
090:                try {
091:                    EditorOperator editor = getDefaultSampleEditorOperator();
092:                    JEditorPaneOperator txtOper = editor.txtEditorPane();
093:
094:                    // open find and close
095:                    new FindAction().perform();
096:                    txtOper.pushKey(KeyEvent.VK_ESCAPE);
097:
098:                    // open find and open help
099:                    txtOper.pushKey(KeyEvent.VK_F, KeyEvent.CTRL_MASK);
100:                    Find find = getFindDialog();
101:                    find.btHelp().doClick();
102:
103:                    // close help
104:                    HelpOperator help = new HelpOperator();
105:                    help.close();
106:
107:                    // close find
108:                    find.btClose().doClick();
109:
110:                } finally {
111:                    closeFindDialogIfOpened();
112:                    closeFileWithDiscard();
113:                }
114:            }
115:
116:            private Find getFindDialog() {
117:                Find find = null;
118:                try {
119:                    find = new Find();
120:                } catch (TimeoutExpiredException tee) {
121:                    log("Find dialog not opened, one more try");
122:                    new FindAction().performMenu();
123:                    find = new Find();
124:                }
125:                return find;
126:            }
127:
128:            private void openFindDialog() {
129:                MainWindowOperator mwo = MainWindowOperator.getDefault();
130:                mwo.pushKey(KeyEvent.VK_E, KeyEvent.ALT_DOWN_MASK);
131:                new EventTool().waitNoEvent(100);
132:                mwo.pushKey(KeyEvent.VK_ESCAPE);
133:                new FindAction().perform();
134:            }
135:
136:            /**
137:             * TC2 - Find Selection Repeated
138:             */
139:            public void testFindSelectionRepeated() {
140:                openDefaultProject();
141:                openDefaultSampleFile();
142:                try {
143:                    EditorOperator editor = getDefaultSampleEditorOperator();
144:
145:                    // choose the "public" word
146:                    editor.select(13, 1, 6);
147:                    openFindDialog();
148:                    Find find = getFindDialog();
149:                    String text = find.cboFindWhat().getTextField().getText();
150:                    // compare
151:                    assertEquals(text, "public");
152:                    find.find();
153:                    new EventTool().waitNoEvent(FIND_TIMEOUT);
154:                    find.close();
155:                    // check status bar
156:                    waitForLabel("'public' found at 16:5");
157:
158:                    // choose the "testFindSelectionRepeated" word
159:                    editor.select(13, 14, 38);
160:                    openFindDialog();
161:                    Find find2 = getFindDialog();
162:                    text = find2.cboFindWhat().getTextField().getText();
163:                    // compare
164:                    assertEquals("testFindSelectionRepeated", text);
165:                    find2.find();
166:                    new EventTool().waitNoEvent(FIND_TIMEOUT);
167:                    find2.close();
168:                    // check status bar
169:                    waitForLabel("'testFindSelectionRepeated' found at 15:35");
170:
171:                } finally {
172:                    closeFindDialogIfOpened();
173:                    closeFileWithDiscard();
174:                }
175:            }
176:
177:            /**
178:             * TC3 - Find Dialog Combo Box
179:             */
180:            public void testFindDialogComboBox() {
181:                openDefaultProject();
182:                openDefaultSampleFile();
183:                try {
184:                    EditorOperator editor = getDefaultSampleEditorOperator();
185:
186:                    // first search
187:                    editor.setCaretPosition(1, 1);
188:                    new EventTool().waitNoEvent(FIND_TIMEOUT);
189:                    openFindDialog();
190:                    Find find = getFindDialog();
191:                    find.cboFindWhat().typeText("package");
192:                    find.find();
193:                    new EventTool().waitNoEvent(FIND_TIMEOUT);
194:                    find.close();
195:
196:                    // second search
197:                    editor.setCaretPosition(1, 1);
198:                    new EventTool().waitNoEvent(FIND_TIMEOUT);
199:                    openFindDialog();
200:                    Find find2 = getFindDialog();
201:                    find2.cboFindWhat().typeText("class");
202:                    find2.find();
203:                    new EventTool().waitNoEvent(FIND_TIMEOUT);
204:                    find2.close();
205:
206:                    // search for an item from history - word "package"
207:                    openFindDialog();
208:                    Find find3 = getFindDialog();
209:                    JComboBoxOperator cbo = find3.cboFindWhat();
210:                    cbo.selectItem(1);
211:                    find3.cbWrapSearch().setSelected(true);
212:                    find3.find();
213:                    new EventTool().waitNoEvent(FIND_TIMEOUT);
214:                    find3.close();
215:                    // check status bar
216:                    waitForLabel("'package' found at 7:1; End of document reached. "
217:                            + "Continuing search from beginning.");
218:
219:                } finally {
220:                    closeFindDialogIfOpened();
221:                    closeFileWithDiscard();
222:                }
223:            }
224:
225:            /**
226:             * TC4 - Unselected All Options
227:             */
228:            public void testUnselectedAllOptions() {
229:                openDefaultProject();
230:                openDefaultSampleFile();
231:                try {
232:                    EditorOperator editor = getDefaultSampleEditorOperator();
233:
234:                    // perform search with all options unselected
235:                    editor.setCaretPosition(1, 1);
236:                    new EventTool().waitNoEvent(FIND_TIMEOUT);
237:                    openFindDialog();
238:                    Find find = getFindDialog();
239:                    find.cboFindWhat().typeText("cLaSs");
240:                    uncheckAll();
241:                    find.find();
242:                    new EventTool().waitNoEvent(FIND_TIMEOUT);
243:                    find.close();
244:                    // check status bar
245:                    waitForLabel("'cLaSs' found at 13:8");
246:
247:                } finally {
248:                    closeFindDialogIfOpened();
249:                    closeFileWithDiscard();
250:                }
251:            }
252:
253:            /**
254:             * TC5 - Nothing Found
255:             */
256:            public void testNothingFound() {
257:                openDefaultProject();
258:                openDefaultSampleFile();
259:                try {
260:                    EditorOperator editor = getDefaultSampleEditorOperator();
261:
262:                    // perform search for nonexistent word
263:                    new FindAction().perform();
264:                    Find find = getFindDialog();
265:                    uncheckAll();
266:                    find.cboFindWhat().typeText("foo");
267:                    find.find();
268:                    new EventTool().waitNoEvent(FIND_TIMEOUT);
269:                    find.close();
270:                    // check status bar
271:                    waitForLabel("'foo' not found");
272:
273:                } finally {
274:                    closeFindDialogIfOpened();
275:                    closeFileWithDiscard();
276:                }
277:            }
278:
279:            /**
280:             * TC6 - Match Case
281:             */
282:            public void testMatchCase() {
283:                openDefaultProject();
284:                openDefaultSampleFile();
285:                try {
286:                    EditorOperator editor = getDefaultSampleEditorOperator();
287:
288:                    // perform case sensitive search - nothing found
289:                    openFindDialog();
290:                    Find find = getFindDialog();
291:                    find.cboFindWhat().typeText("Package");
292:                    uncheckAll();
293:                    find.cbMatchCase().setSelected(true);
294:                    find.find();
295:                    new EventTool().waitNoEvent(FIND_TIMEOUT);
296:                    find.close();
297:                    // check status bar
298:                    waitForLabel("'Package' not found");
299:
300:                    // perform case sensitive search - package found
301:                    editor.setCaretPosition(1, 1);
302:                    new EventTool().waitNoEvent(FIND_TIMEOUT);
303:                    openFindDialog();
304:                    Find find2 = getFindDialog();
305:                    find2.cboFindWhat().typeText("package");
306:                    find2.find();
307:                    new EventTool().waitNoEvent(FIND_TIMEOUT);
308:                    find2.close();
309:                    // check status bar
310:                    waitForLabel("'package' found at 7:1");
311:
312:                } finally {
313:                    closeFindDialogIfOpened();
314:                    closeFileWithDiscard();
315:                }
316:            }
317:
318:            /**
319:             * TC7 - Smart Case
320:             */
321:            /*public void testSmartCase() {
322:                openDefaultProject();
323:                openDefaultSampleFile();
324:                try {
325:                    EditorOperator editor = getDefaultSampleEditorOperator();
326:                    
327:                    // perform smart case search
328:                    performFind();
329:                    Find find = new Find();
330:                    find.cboFindWhat().typeText("smarttest");
331:                    uncheckAll();
332:                    // check smart case
333:                    find.cbSmartCase().setSelected(true);
334:                    find.find();
335:                    new EventTool().waitNoEvent(FIND_TIMEOUT);
336:                    find.close();
337:                    // check status bar
338:                    waitForLabel("'smarttest' found at 17:16");
339:                    
340:                    // perform smart case search
341:                    performFind();
342:                    Find find2 = new Find();
343:                    find2.cboFindWhat().typeText("smarttest");
344:                    find2.find();
345:                    new EventTool().waitNoEvent(FIND_TIMEOUT);
346:                    find2.close();
347:                    // check status bar
348:                    waitForLabel("'smarttest' found at 18:16");
349:                    
350:                    // perform smart case search
351:                    performFind();
352:                    Find find3 = new Find();
353:                    find3.cboFindWhat().typeText("smarttest");
354:                    find3.find();
355:                    new EventTool().waitNoEvent(FIND_TIMEOUT);
356:                    find3.close();
357:                    // check status bar
358:                    waitForLabel("'smarttest' found at 19:16");
359:                    
360:                    // perform smart case search - negative
361:                    performFind();
362:                    Find find4 = new Find();
363:                    find4.cboFindWhat().typeText("smarttest");
364:                    find4.find();
365:                    new EventTool().waitNoEvent(FIND_TIMEOUT);
366:                    find4.close();
367:                    // check status bar
368:                    waitForLabel("'smarttest' not found");
369:                    
370:                } finally {
371:                    closeFindDialogIfOpened();
372:                    closeFileWithDiscard();
373:                }
374:            }*/
375:
376:            /**
377:             * TC8 - Smart Case Reverse
378:             */
379:            /*public void testSmartCaseReverse() {
380:                openDefaultProject();
381:                openDefaultSampleFile();
382:                try {
383:                    EditorOperator editor = getDefaultSampleEditorOperator();
384:                    
385:                    // perform search for Smarttest (found Smarttest)
386:                    performFind();
387:                    Find find = new Find();
388:                    uncheckAll();
389:                    // check smart case
390:                    find.cbSmartCase().setSelected(true);
391:                    find.cboFindWhat().typeText("Smarttest");
392:                    find.find();
393:                    new EventTool().waitNoEvent(FIND_TIMEOUT);
394:                    find.close();
395:                    // check status bar
396:                    waitForLabel("'Smarttest' found at 18:16");
397:                    
398:                    // perform smart case search - negative
399:                    performFind();
400:                    Find find2 = new Find();
401:                    find2.cboFindWhat().typeText("Smarttest");
402:                    find2.find();
403:                    new EventTool().waitNoEvent(FIND_TIMEOUT);
404:                    find2.close();
405:                    // check status bar
406:                    waitForLabel("'Smarttest' not found");
407:                    
408:                } finally {
409:                    closeFindDialogIfOpened();
410:                    closeFileWithDiscard();
411:                }
412:            }*/
413:
414:            /**
415:             * TC9 - Match Whole Words Only
416:             */
417:            public void testMatchWholeWordsOnly() {
418:                openDefaultProject();
419:                openDefaultSampleFile();
420:                try {
421:                    EditorOperator editor = getDefaultSampleEditorOperator();
422:
423:                    // perform search for "word"
424:                    openFindDialog();
425:                    Find find = getFindDialog();
426:                    uncheckAll();
427:                    find.cbMatchWholeWordsOnly().setSelected(true);
428:                    find.cboFindWhat().typeText("word");
429:                    find.find();
430:                    new EventTool().waitNoEvent(FIND_TIMEOUT);
431:                    find.close();
432:                    // check status bar
433:                    waitForLabel("'word' found at 18:16");
434:
435:                    // perform search for "word"
436:                    openFindDialog();
437:                    Find find2 = getFindDialog();
438:                    find2.cboFindWhat().typeText("word");
439:                    find2.find();
440:                    new EventTool().waitNoEvent(FIND_TIMEOUT);
441:                    find2.close();
442:                    // check status bar
443:                    waitForLabel("'word' found at 18:24");
444:
445:                    // perform search for "word"
446:                    openFindDialog();
447:                    Find find3 = getFindDialog();
448:                    find3.cboFindWhat().typeText("word");
449:                    find3.find();
450:                    new EventTool().waitNoEvent(FIND_TIMEOUT);
451:                    find3.close();
452:                    // check status bar
453:                    waitForLabel("'word' found at 19:25");
454:
455:                    // perform search for "word" - negative
456:                    openFindDialog();
457:                    Find find4 = getFindDialog();
458:                    find4.cboFindWhat().typeText("word");
459:                    find4.find();
460:                    new EventTool().waitNoEvent(FIND_TIMEOUT);
461:                    find4.close();
462:                    // check status bar
463:                    waitForLabel("'word' not found");
464:
465:                } finally {
466:                    closeFindDialogIfOpened();
467:                    closeFileWithDiscard();
468:                }
469:            }
470:
471:            /**
472:             * TC10 - Highlight Search
473:             */
474:            public void testHighlightSearch() {
475:                openDefaultProject();
476:                openDefaultSampleFile();
477:                try {
478:                    EditorOperator editor = getDefaultSampleEditorOperator();
479:
480:                    // test search highlighting - only checkbox
481:                    openFindDialog();
482:                    Find find = getFindDialog();
483:                    uncheckAll();
484:                    find.cbHighlightSearch().setSelected(true);
485:                    find.cboFindWhat().typeText("testHighlightSearch");
486:                    find.find();
487:                    waitForLabel("'testHighlightSearch' found at 2:4");
488:                    find.find();
489:                    waitForLabel("'testHighlightSearch' found at 13:14");
490:                    find.find();
491:                    waitForLabel("'testHighlightSearch' found at 15:35");
492:                    find.find();
493:                    waitForLabel("'testHighlightSearch' found at 16:12");
494:                    find.find();
495:                    waitForLabel("'testHighlightSearch' not found");
496:                    find.close();
497:
498:                } finally {
499:                    closeFindDialogIfOpened();
500:                    closeFileWithDiscard();
501:                }
502:            }
503:
504:            /**
505:             * TC11 - Incremental Search
506:             */
507:            public void testIncrementalSearch() {
508:                openDefaultProject();
509:                openDefaultSampleFile();
510:                try {
511:                    EditorOperator editor = getDefaultSampleEditorOperator();
512:
513:                    // perform search searched word, only checks checkbox
514:                    openFindDialog();
515:                    Find find = getFindDialog();
516:                    uncheckAll();
517:                    find.cbHighlightSearch().setSelected(true);
518:                    find.cboFindWhat().typeText("searchedWord");
519:                    for (int i = 0; i < 10; i++) {
520:                        find.find();
521:                        waitForLabel("'searchedWord' found at "
522:                                + String.valueOf(i + 17) + ":12");
523:                    }
524:                    find.close();
525:
526:                } finally {
527:                    closeFindDialogIfOpened();
528:                    closeFileWithDiscard();
529:                }
530:            }
531:
532:            /**
533:             * TC12 - Backward Search
534:             */
535:            public void testBackwardSearch() {
536:                openDefaultProject();
537:                openDefaultSampleFile();
538:                try {
539:                    EditorOperator editor = getDefaultSampleEditorOperator();
540:
541:                    // perform backward search
542:                    openFindDialog();
543:                    Find find = getFindDialog();
544:                    uncheckAll();
545:                    find.cboFindWhat().typeText("first");
546:                    find.find();
547:                    waitForLabel("'first' found at 21:12");
548:                    find.cboFindWhat().clearText();
549:                    find.cboFindWhat().typeText("second");
550:                    find.cbBackwardSearch().setSelected(true);
551:                    find.find();
552:                    waitForLabel("'second' found at 20:12");
553:                    find.cboFindWhat().clearText();
554:                    find.cboFindWhat().typeText("third");
555:                    find.find();
556:                    waitForLabel("'third' found at 19:12");
557:                    find.cboFindWhat().clearText();
558:                    find.cboFindWhat().typeText("fourth");
559:                    find.find();
560:                    waitForLabel("'fourth' found at 18:12");
561:                    find.close();
562:
563:                } finally {
564:                    closeFindDialogIfOpened();
565:                    closeFileWithDiscard();
566:                }
567:            }
568:
569:            /**
570:             * TC13 - Wrap Search
571:             */
572:            public void testWrapSearch() {
573:                openDefaultProject();
574:                openDefaultSampleFile();
575:                try {
576:                    EditorOperator editor = getDefaultSampleEditorOperator();
577:
578:                    // perform backward search
579:                    openFindDialog();
580:                    Find find = getFindDialog();
581:                    uncheckAll();
582:                    find.cbWrapSearch().setSelected(true);
583:                    find.cboFindWhat().typeText("wrapWord");
584:                    for (int i = 0; i < 4; i++) {
585:                        find.find();
586:                        waitForLabel("'wrapWord' found at "
587:                                + String.valueOf(i + 18) + ":12");
588:                    }
589:                    find.find();
590:                    waitForLabel("'wrapWord' found at 18:12; End of document reached. "
591:                            + "Continuing search from beginning.");
592:                    for (int i = 0; i < 3; i++) {
593:                        find.find();
594:                        waitForLabel("'wrapWord' found at "
595:                                + String.valueOf(i + 19) + ":12");
596:                    }
597:                    find.close();
598:
599:                } finally {
600:                    closeFindDialogIfOpened();
601:                    closeFileWithDiscard();
602:                }
603:            }
604:
605:            /**
606:             * TC14 - Find Next - Previous
607:             */
608:            public void testFindNextPrevious() {
609:                openDefaultProject();
610:                openDefaultSampleFile();
611:                try {
612:                    EditorOperator editor = getDefaultSampleEditorOperator();
613:
614:                    // search first word
615:                    editor.setCaretPosition(1, 1);
616:                    openFindDialog();
617:                    Find find = getFindDialog();
618:                    uncheckAll();
619:                    find.cboFindWhat().clearText();
620:                    find.cboFindWhat().typeText("testWord");
621:                    find.find();
622:                    waitForLabel("'testWord' found at 18:12");
623:                    find.close();
624:                    new EventTool().waitNoEvent(FIND_TIMEOUT);
625:
626:                    // search next word
627:                    for (int i = 0; i < 7; i++) {
628:                        MainWindowOperator.getDefault().pushKey(KeyEvent.VK_F3);
629:                        waitForLabel("'testWord' found at "
630:                                + String.valueOf(i + 19) + ":12");
631:                    }
632:
633:                    // search previous word
634:                    for (int i = 7; i > 0; i--) {
635:                        MainWindowOperator.getDefault().pushKey(KeyEvent.VK_F3,
636:                                KeyEvent.SHIFT_MASK);
637:                        waitForLabel("'testWord' found at "
638:                                + String.valueOf(i + 17) + ":12");
639:                    }
640:                } finally {
641:                    closeFindDialogIfOpened();
642:                    closeFileWithDiscard();
643:                }
644:            }
645:
646:            /**
647:             * TC15 - Find Selection Without Dialog
648:             */
649:            public void testFindSelectionWithoutDialog() {
650:                openDefaultProject();
651:                openDefaultSampleFile();
652:                try {
653:                    EditorOperator editor = getDefaultSampleEditorOperator();
654:
655:                    // perform backward search
656:                    editor.select(18, 12, 19);
657:                    for (int i = 0; i < 7; i++) {
658:                        MainWindowOperator.getDefault().pushKey(KeyEvent.VK_F3);
659:                        waitForLabel("'testWord' found at "
660:                                + String.valueOf(i + 19) + ":12");
661:                    }
662:                } finally {
663:                    closeFindDialogIfOpened();
664:                    closeFileWithDiscard();
665:                }
666:            }
667:
668:            /**
669:             * TC16 - Search Selection
670:             */
671:            public void testSearchSelection() {
672:                openDefaultProject();
673:                openDefaultSampleFile();
674:                try {
675:                    EditorOperator editor = getDefaultSampleEditorOperator();
676:
677:                    // perform selection search
678:                    editor.select(24, 20);
679:                    new EventTool().waitNoEvent(FIND_TIMEOUT);
680:                    openFindDialog();
681:                    Find find = getFindDialog();
682:                    uncheckAll();
683:                    find.cbIncrementalSearch().setSelected(true);
684:                    find.cbBlockSearch().setSelected(true);
685:                    find.cboFindWhat().clearText();
686:                    find.cboFindWhat().typeText("testWord2");
687:                    find.find();
688:                    waitForLabel("'testWord2' found at 22:12");
689:                    find.close();
690:
691:                } finally {
692:                    closeFindDialogIfOpened();
693:                    closeFileWithDiscard();
694:                }
695:            }
696:
697:            /**
698:             * TC17 - Search Selection Negative
699:             */
700:            public void testSearchSelectionNegative() {
701:                openDefaultProject();
702:                openDefaultSampleFile();
703:                try {
704:                    EditorOperator editor = getDefaultSampleEditorOperator();
705:
706:                    // perform negative selection search
707:                    editor.select(25, 22);
708:                    new EventTool().waitNoEvent(FIND_TIMEOUT);
709:                    openFindDialog();
710:                    Find find2 = getFindDialog();
711:                    uncheckAll();
712:                    find2.cbIncrementalSearch().setSelected(true);
713:                    find2.cbBlockSearch().setSelected(true);
714:                    find2.cboFindWhat().clearText();
715:                    find2.cboFindWhat().typeText("testWord2");
716:                    find2.find();
717:                    waitForLabel("'testWord2' not found");
718:                    find2.close();
719:
720:                } finally {
721:                    closeFindDialogIfOpened();
722:                    closeFileWithDiscard();
723:                }
724:            }
725:
726:            /**
727:             * TC18 - Regexp Search - Simple
728:             */
729:            public void testRegexpSimple() {
730:                openDefaultProject();
731:                openDefaultSampleFile();
732:                try {
733:                    EditorOperator editor = getDefaultSampleEditorOperator();
734:
735:                    // perform simple regexp search
736:                    editor.setCaretPosition(1, 1);
737:                    openFindDialog();
738:                    Find find = getFindDialog();
739:                    uncheckAll();
740:                    find.cbRegularExpressions().setSelected(true);
741:                    find.cboFindWhat().clearText();
742:                    find.cboFindWhat().typeText("[aA][hH][oO][jJ][0-9]{1,3}");
743:                    find.find();
744:                    waitForLabel("'[aA][hH][oO][jJ][0-9]{1,3}' found at 18:12");
745:                    find.cboFindWhat().clearText();
746:                    find.cboFindWhat().typeText("[aA][hH][oO][jJ][0-9]{1,3}");
747:                    find.find();
748:                    waitForLabel("'[aA][hH][oO][jJ][0-9]{1,3}' found at 19:12");
749:                    find.cboFindWhat().clearText();
750:                    find.cboFindWhat().typeText("[aA][hH][oO][jJ][0-9]{1,3}");
751:                    find.find();
752:                    waitForLabel("'[aA][hH][oO][jJ][0-9]{1,3}' found at 20:12");
753:                    find.cboFindWhat().clearText();
754:                    find.cboFindWhat().typeText("[aA][hH][oO][jJ][0-9]{1,3}");
755:                    find.find();
756:                    waitForLabel("'[aA][hH][oO][jJ][0-9]{1,3}' found at 21:12");
757:                    find.cboFindWhat().clearText();
758:                    find.cboFindWhat().typeText("[aA][hH][oO][jJ][0-9]{1,3}");
759:                    find.find();
760:                    waitForLabel("'[aA][hH][oO][jJ][0-9]{1,3}' found at 23:12");
761:                    find.cboFindWhat().clearText();
762:                    find.cboFindWhat().typeText("[aA][hH][oO][jJ][0-9]{1,3}");
763:                    find.find();
764:                    waitForLabel("'[aA][hH][oO][jJ][0-9]{1,3}' not found");
765:                    find.close();
766:
767:                } finally {
768:                    closeFindDialogIfOpened();
769:                    closeFileWithDiscard();
770:                }
771:            }
772:
773:            /**
774:             * TC19 - Regexp Search - Complex
775:             */
776:            public void testRegexpComplex() {
777:                openDefaultProject();
778:                openDefaultSampleFile();
779:                try {
780:                    EditorOperator editor = getDefaultSampleEditorOperator();
781:
782:                    // perform simple regexp search
783:                    editor.setCaretPosition(1, 1);
784:                    openFindDialog();
785:                    Find find = getFindDialog();
786:                    uncheckAll();
787:                    find.cbRegularExpressions().setSelected(true);
788:                    find.cboFindWhat().clearText();
789:                    find.cboFindWhat().typeText(
790:                            "a?B*c{2}[dD]e{1,}\\.F{1,2}\\s[^g]");
791:                    find.find();
792:                    waitForLabel("'a?B*c{2}[dD]e{1,}\\.F{1,2}\\s[^g]' found at 18:12");
793:                    find.cboFindWhat().clearText();
794:                    find.cboFindWhat().typeText(
795:                            "a?B*c{2}[dD]e{1,}\\.F{1,2}\\s[^g]");
796:                    find.find();
797:                    waitForLabel("'a?B*c{2}[dD]e{1,}\\.F{1,2}\\s[^g]' found at 19:12");
798:                    find.cboFindWhat().clearText();
799:                    find.cboFindWhat().typeText(
800:                            "a?B*c{2}[dD]e{1,}\\.F{1,2}\\s[^g]");
801:                    find.find();
802:                    waitForLabel("'a?B*c{2}[dD]e{1,}\\.F{1,2}\\s[^g]' found at 21:12");
803:                    find.cboFindWhat().clearText();
804:                    find.cboFindWhat().typeText(
805:                            "a?B*c{2}[dD]e{1,}\\.F{1,2}\\s[^g]");
806:                    find.find();
807:                    waitForLabel("'a?B*c{2}[dD]e{1,}\\.F{1,2}\\s[^g]' found at 23:12");
808:                    find.cboFindWhat().clearText();
809:                    find.cboFindWhat().typeText(
810:                            "a?B*c{2}[dD]e{1,}\\.F{1,2}\\s[^g]");
811:                    find.find();
812:                    waitForLabel("'a?B*c{2}[dD]e{1,}\\.F{1,2}\\s[^g]' not found");
813:                    find.close();
814:
815:                } finally {
816:                    closeFindDialogIfOpened();
817:                    closeFileWithDiscard();
818:                }
819:            }
820:
821:            /**
822:             * Unchecks all checkboxes in find dialog.
823:             */
824:            public void uncheckAll() {
825:                Find find = getFindDialog();
826:                find.cbBackwardSearch().setSelected(false);
827:                find.cbBlockSearch().setSelected(false);
828:                find.cbHighlightSearch().setSelected(false);
829:                find.cbIncrementalSearch().setSelected(false);
830:                find.cbMatchCase().setSelected(false);
831:                find.cbMatchWholeWordsOnly().setSelected(false);
832:                find.cbRegularExpressions().setSelected(false);
833:                //find.cbSmartCase().setSelected(false);
834:                find.cbWrapSearch().setSelected(false);
835:            }
836:
837:            /**
838:             * Waits for label to appear on Status Bar, checks it 10 times before
839:             * failing.
840:             * @param label label which should be displayed on status bar
841:             */
842:            public void waitForLabel(String label) {
843:                EditorOperator editor = getDefaultSampleEditorOperator();
844:                for (int i = 0; i < 10; i++) {
845:                    if (editor.lblStatusBar().getText().equals(label))
846:                        break;
847:                    new EventTool().waitNoEvent(FIND_TIMEOUT);
848:                }
849:                assertEquals(label, editor.lblStatusBar().getText());
850:            }
851:
852:            /**
853:             * Checks if a find dialog is opened and if yes it closes it.
854:             */
855:            public void closeFindDialogIfOpened() {
856:                Window findWindow = WindowOperator
857:                        .findWindow(new ComponentChooser() {
858:                            public boolean checkComponent(Component comp) {
859:                                WindowOperator winOper = new WindowOperator(
860:                                        (Window) comp);
861:                                winOper.setOutput(TestOut.getNullOutput());
862:                                return null != winOper
863:                                        .findSubComponent(new ComponentChooser() {
864:                                            public boolean checkComponent(
865:                                                    Component comp) {
866:                                                return comp
867:                                                        .getClass()
868:                                                        .getName()
869:                                                        .startsWith(
870:                                                                "org.netbeans.editor.ext.Find"); //NOI18N
871:                                            }
872:
873:                                            public String getDescription() {
874:                                                return ("any find dialog"); //NOI18N
875:                                            }
876:                                        });
877:                            }
878:
879:                            public String getDescription() {
880:                                return "containing any find dialog"; //NOI18N
881:                            }
882:                        });
883:                if (findWindow != null) {
884:                    getFindDialog().close();
885:                }
886:            }
887:
888:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.