KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > search_replace > SearchTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package search_replace;
21
22 import java.awt.Component JavaDoc;
23 import java.awt.Window JavaDoc;
24 import java.awt.event.KeyEvent JavaDoc;
25 import org.netbeans.jellytools.EditorOperator;
26 import lib.EditorTestCase;
27 import org.netbeans.jellytools.HelpOperator;
28 import org.netbeans.jellytools.MainWindowOperator;
29 import org.netbeans.jellytools.actions.FindAction;
30 import org.netbeans.jellytools.modules.editor.Find;
31 import org.netbeans.jemmy.ComponentChooser;
32 import org.netbeans.jemmy.EventTool;
33 import org.netbeans.jemmy.TestOut;
34 import org.netbeans.jemmy.operators.JComboBoxOperator;
35 import org.netbeans.jemmy.operators.JEditorPaneOperator;
36 import org.netbeans.jemmy.operators.WindowOperator;
37
38 /**
39  * Test of find functionality in editor.
40  *
41  * @author Roman Strobl
42  */

43 public class SearchTest extends EditorTestCase {
44     
45     private static int FIND_TIMEOUT = 1000;
46     
47     /**
48      * Creates a new instance of Main
49      * @param testMethodName name of test
50      */

51     public SearchTest(String JavaDoc testMethodName) {
52         super(testMethodName);
53     }
54     
55     @Override JavaDoc
56     protected void setUp() throws Exception JavaDoc {
57         super.setUp();
58         closeFindDialogIfOpened();
59     }
60
61     
62     
63     
64     /**
65      * TC1 - open and close find dialog
66      */

67     public void testFindDialogOpenClose() {
68         openDefaultProject();
69         openDefaultSampleFile();
70         try {
71             EditorOperator editor = getDefaultSampleEditorOperator();
72             JEditorPaneOperator txtOper = editor.txtEditorPane();
73             
74             // open find and close
75
new FindAction().perform();
76             txtOper.pushKey(KeyEvent.VK_ESCAPE);
77             
78             // open find and open help
79
txtOper.pushKey(KeyEvent.VK_F, KeyEvent.CTRL_MASK);
80             Find find = new Find();
81             find.btHelp().doClick();
82             
83             // close help
84
HelpOperator help = new HelpOperator();
85             help.close();
86             
87             // close find
88
find.btClose().doClick();
89             
90         } finally {
91             closeFindDialogIfOpened();
92             closeFileWithDiscard();
93         }
94     }
95     
96     /**
97      * TC2 - Find Selection Repeated
98      */

99     public void testFindSelectionRepeated() {
100         openDefaultProject();
101         openDefaultSampleFile();
102         try {
103             EditorOperator editor = getDefaultSampleEditorOperator();
104             
105             // choose the "public" word
106
editor.select(13, 1, 6);
107             new FindAction().perform();
108             Find find = new Find();
109             String JavaDoc text = find.cboFindWhat().getTextField().getText();
110             // compare
111
assertEquals(text, "public");
112             find.find();
113             new EventTool().waitNoEvent(FIND_TIMEOUT);
114             find.close();
115             // check status bar
116
waitForLabel("'public' found at 16:5");
117             
118             // choose the "testFindSelectionRepeated" word
119
editor.select(13, 14, 38);
120             new FindAction().perform();
121             Find find2 = new Find();
122             text = find2.cboFindWhat().getTextField().getText();
123             // compare
124
assertEquals("testFindSelectionRepeated",text);
125             find2.find();
126             new EventTool().waitNoEvent(FIND_TIMEOUT);
127             find2.close();
128             // check status bar
129
waitForLabel("'testFindSelectionRepeated' found at 15:35");
130             
131         } finally {
132             closeFindDialogIfOpened();
133             closeFileWithDiscard();
134         }
135     }
136     
137     /**
138      * TC3 - Find Dialog Combo Box
139      */

140     public void testFindDialogComboBox() {
141         openDefaultProject();
142         openDefaultSampleFile();
143         try {
144             EditorOperator editor = getDefaultSampleEditorOperator();
145             
146             // first search
147
editor.setCaretPosition(1, 1);
148             new EventTool().waitNoEvent(FIND_TIMEOUT);
149             new FindAction().perform();
150             Find find = new Find();
151             find.cboFindWhat().typeText("package");
152             find.find();
153             new EventTool().waitNoEvent(FIND_TIMEOUT);
154             find.close();
155             
156             // second search
157
editor.setCaretPosition(1, 1);
158             new EventTool().waitNoEvent(FIND_TIMEOUT);
159             new FindAction().perform();
160             Find find2 = new Find();
161             find2.cboFindWhat().typeText("class");
162             find2.find();
163             new EventTool().waitNoEvent(FIND_TIMEOUT);
164             find2.close();
165             
166             // search for an item from history - word "package"
167
new FindAction().perform();
168             Find find3 = new Find();
169             JComboBoxOperator cbo = find3.cboFindWhat();
170             cbo.selectItem(1);
171             find3.cbWrapSearch().setSelected(true);
172             find3.find();
173             new EventTool().waitNoEvent(FIND_TIMEOUT);
174             find3.close();
175             // check status bar
176
waitForLabel("'package' found at 7:1; End of document reached. "
177                     +"Continuing search from beginning.");
178             
179         } finally {
180             closeFindDialogIfOpened();
181             closeFileWithDiscard();
182         }
183     }
184     
185     /**
186      * TC4 - Unselected All Options
187      */

188     public void testUnselectedAllOptions() {
189         openDefaultProject();
190         openDefaultSampleFile();
191         try {
192             EditorOperator editor = getDefaultSampleEditorOperator();
193             
194             // perform search with all options unselected
195
editor.setCaretPosition(1, 1);
196             new EventTool().waitNoEvent(FIND_TIMEOUT);
197             new FindAction().perform();
198             Find find = new Find();
199             find.cboFindWhat().typeText("cLaSs");
200             uncheckAll();
201             find.find();
202             new EventTool().waitNoEvent(FIND_TIMEOUT);
203             find.close();
204             // check status bar
205
waitForLabel("'cLaSs' found at 13:8");
206             
207         } finally {
208             closeFindDialogIfOpened();
209             closeFileWithDiscard();
210         }
211     }
212     
213     /**
214      * TC5 - Nothing Found
215      */

216     public void testNothingFound() {
217         openDefaultProject();
218         openDefaultSampleFile();
219         try {
220             EditorOperator editor = getDefaultSampleEditorOperator();
221             
222             // perform search for nonexistent word
223
new FindAction().perform();
224             Find find = new Find();
225             uncheckAll();
226             find.cboFindWhat().typeText("foo");
227             find.find();
228             new EventTool().waitNoEvent(FIND_TIMEOUT);
229             find.close();
230             // check status bar
231
waitForLabel("'foo' not found");
232             
233         } finally {
234             closeFindDialogIfOpened();
235             closeFileWithDiscard();
236         }
237     }
238     
239     /**
240      * TC6 - Match Case
241      */

242     public void testMatchCase() {
243         openDefaultProject();
244         openDefaultSampleFile();
245         try {
246             EditorOperator editor = getDefaultSampleEditorOperator();
247             
248             // perform case sensitive search - nothing found
249
new FindAction().perform();
250             Find find = new Find();
251             find.cboFindWhat().typeText("Package");
252             uncheckAll();
253             find.cbMatchCase().setSelected(true);
254             find.find();
255             new EventTool().waitNoEvent(FIND_TIMEOUT);
256             find.close();
257             // check status bar
258
waitForLabel("'Package' not found");
259             
260             // perform case sensitive search - package found
261
editor.setCaretPosition(1, 1);
262             new EventTool().waitNoEvent(FIND_TIMEOUT);
263             new FindAction().perform();
264             Find find2 = new Find();
265             find2.cboFindWhat().typeText("package");
266             find2.find();
267             new EventTool().waitNoEvent(FIND_TIMEOUT);
268             find2.close();
269             // check status bar
270
waitForLabel("'package' found at 7:1");
271             
272         } finally {
273             closeFindDialogIfOpened();
274             closeFileWithDiscard();
275         }
276     }
277     
278     /**
279      * TC7 - Smart Case
280      */

281     /*public void testSmartCase() {
282         openDefaultProject();
283         openDefaultSampleFile();
284         try {
285             EditorOperator editor = getDefaultSampleEditorOperator();
286             
287             // perform smart case search
288             new FindAction().perform();
289             Find find = new Find();
290             find.cboFindWhat().typeText("smarttest");
291             uncheckAll();
292             // check smart case
293             find.cbSmartCase().setSelected(true);
294             find.find();
295             new EventTool().waitNoEvent(FIND_TIMEOUT);
296             find.close();
297             // check status bar
298             waitForLabel("'smarttest' found at 17:16");
299             
300             // perform smart case search
301             new FindAction().perform();
302             Find find2 = new Find();
303             find2.cboFindWhat().typeText("smarttest");
304             find2.find();
305             new EventTool().waitNoEvent(FIND_TIMEOUT);
306             find2.close();
307             // check status bar
308             waitForLabel("'smarttest' found at 18:16");
309             
310             // perform smart case search
311             new FindAction().perform();
312             Find find3 = new Find();
313             find3.cboFindWhat().typeText("smarttest");
314             find3.find();
315             new EventTool().waitNoEvent(FIND_TIMEOUT);
316             find3.close();
317             // check status bar
318             waitForLabel("'smarttest' found at 19:16");
319             
320             // perform smart case search - negative
321             new FindAction().perform();
322             Find find4 = new Find();
323             find4.cboFindWhat().typeText("smarttest");
324             find4.find();
325             new EventTool().waitNoEvent(FIND_TIMEOUT);
326             find4.close();
327             // check status bar
328             waitForLabel("'smarttest' not found");
329             
330         } finally {
331             closeFindDialogIfOpened();
332             closeFileWithDiscard();
333         }
334     }*/

335     
336     /**
337      * TC8 - Smart Case Reverse
338      */

339     /*public void testSmartCaseReverse() {
340         openDefaultProject();
341         openDefaultSampleFile();
342         try {
343             EditorOperator editor = getDefaultSampleEditorOperator();
344             
345             // perform search for Smarttest (found Smarttest)
346             new FindAction().perform();
347             Find find = new Find();
348             uncheckAll();
349             // check smart case
350             find.cbSmartCase().setSelected(true);
351             find.cboFindWhat().typeText("Smarttest");
352             find.find();
353             new EventTool().waitNoEvent(FIND_TIMEOUT);
354             find.close();
355             // check status bar
356             waitForLabel("'Smarttest' found at 18:16");
357             
358             // perform smart case search - negative
359             new FindAction().perform();
360             Find find2 = new Find();
361             find2.cboFindWhat().typeText("Smarttest");
362             find2.find();
363             new EventTool().waitNoEvent(FIND_TIMEOUT);
364             find2.close();
365             // check status bar
366             waitForLabel("'Smarttest' not found");
367             
368         } finally {
369             closeFindDialogIfOpened();
370             closeFileWithDiscard();
371         }
372     }*/

373     
374     /**
375      * TC9 - Match Whole Words Only
376      */

377     public void testMatchWholeWordsOnly() {
378         openDefaultProject();
379         openDefaultSampleFile();
380         try {
381             EditorOperator editor = getDefaultSampleEditorOperator();
382             
383             // perform search for "word"
384
new FindAction().perform();
385             Find find = new Find();
386             uncheckAll();
387             find.cbMatchWholeWordsOnly().setSelected(true);
388             find.cboFindWhat().typeText("word");
389             find.find();
390             new EventTool().waitNoEvent(FIND_TIMEOUT);
391             find.close();
392             // check status bar
393
waitForLabel("'word' found at 18:16");
394             
395             // perform search for "word"
396
new FindAction().perform();
397             Find find2 = new Find();
398             find2.cboFindWhat().typeText("word");
399             find2.find();
400             new EventTool().waitNoEvent(FIND_TIMEOUT);
401             find2.close();
402             // check status bar
403
waitForLabel("'word' found at 18:24");
404             
405             // perform search for "word"
406
new FindAction().perform();
407             Find find3 = new Find();
408             find3.cboFindWhat().typeText("word");
409             find3.find();
410             new EventTool().waitNoEvent(FIND_TIMEOUT);
411             find3.close();
412             // check status bar
413
waitForLabel("'word' found at 19:25");
414             
415             // perform search for "word" - negative
416
new FindAction().perform();
417             Find find4 = new Find();
418             find4.cboFindWhat().typeText("word");
419             find4.find();
420             new EventTool().waitNoEvent(FIND_TIMEOUT);
421             find4.close();
422             // check status bar
423
waitForLabel("'word' not found");
424             
425         } finally {
426             closeFindDialogIfOpened();
427             closeFileWithDiscard();
428         }
429     }
430     
431     /**
432      * TC10 - Highlight Search
433      */

434     public void testHighlightSearch() {
435         openDefaultProject();
436         openDefaultSampleFile();
437         try {
438             EditorOperator editor = getDefaultSampleEditorOperator();
439             
440             // test search highlighting - only checkbox
441
new FindAction().perform();
442             Find find = new Find();
443             uncheckAll();
444             find.cbHighlightSearch().setSelected(true);
445             find.cboFindWhat().typeText("testHighlightSearch");
446             find.find();
447             waitForLabel("'testHighlightSearch' found at 2:4");
448             find.find();
449             waitForLabel("'testHighlightSearch' found at 13:14");
450             find.find();
451             waitForLabel("'testHighlightSearch' found at 15:35");
452             find.find();
453             waitForLabel("'testHighlightSearch' found at 16:12");
454             find.find();
455             waitForLabel("'testHighlightSearch' not found");
456             find.close();
457             
458         } finally {
459             closeFindDialogIfOpened();
460             closeFileWithDiscard();
461         }
462     }
463     
464     /**
465      * TC11 - Incremental Search
466      */

467     public void testIncrementalSearch() {
468         openDefaultProject();
469         openDefaultSampleFile();
470         try {
471             EditorOperator editor = getDefaultSampleEditorOperator();
472             
473             // perform search searched word, only checks checkbox
474
new FindAction().perform();
475             Find find = new Find();
476             uncheckAll();
477             find.cbHighlightSearch().setSelected(true);
478             find.cboFindWhat().typeText("searchedWord");
479             for (int i = 0; i<10; i++) {
480                 find.find();
481                 waitForLabel("'searchedWord' found at "+String.valueOf(i+17)
482                         +":12");
483             }
484             find.close();
485             
486         } finally {
487             closeFindDialogIfOpened();
488             closeFileWithDiscard();
489         }
490     }
491     
492     /**
493      * TC12 - Backward Search
494      */

495     public void testBackwardSearch() {
496         openDefaultProject();
497         openDefaultSampleFile();
498         try {
499             EditorOperator editor = getDefaultSampleEditorOperator();
500             
501             // perform backward search
502
new FindAction().perform();
503             Find find = new Find();
504             uncheckAll();
505             find.cboFindWhat().typeText("first");
506             find.find();
507             waitForLabel("'first' found at 21:12");
508             find.cboFindWhat().clearText();
509             find.cboFindWhat().typeText("second");
510             find.cbBackwardSearch().setSelected(true);
511             find.find();
512             waitForLabel("'second' found at 20:12");
513             find.cboFindWhat().clearText();
514             find.cboFindWhat().typeText("third");
515             find.find();
516             waitForLabel("'third' found at 19:12");
517             find.cboFindWhat().clearText();
518             find.cboFindWhat().typeText("fourth");
519             find.find();
520             waitForLabel("'fourth' found at 18:12");
521             find.close();
522             
523         } finally {
524             closeFindDialogIfOpened();
525             closeFileWithDiscard();
526         }
527     }
528     
529     /**
530      * TC13 - Wrap Search
531      */

532     public void testWrapSearch() {
533         openDefaultProject();
534         openDefaultSampleFile();
535         try {
536             EditorOperator editor = getDefaultSampleEditorOperator();
537             
538             // perform backward search
539
new FindAction().perform();
540             Find find = new Find();
541             uncheckAll();
542             find.cbWrapSearch().setSelected(true);
543             find.cboFindWhat().typeText("wrapWord");
544             for (int i = 0; i<4; i++) {
545                 find.find();
546                 waitForLabel("'wrapWord' found at "+String.valueOf(i+18)
547                         +":12");
548             }
549             find.find();
550             waitForLabel("'wrapWord' found at 18:12; End of document reached. "
551                     +"Continuing search from beginning.");
552             for (int i = 0; i<3; i++) {
553                 find.find();
554                 waitForLabel("'wrapWord' found at "+String.valueOf(i+19)
555                         +":12");
556             }
557             find.close();
558             
559         } finally {
560             closeFindDialogIfOpened();
561             closeFileWithDiscard();
562         }
563     }
564     
565     /**
566      * TC14 - Find Next - Previous
567      */

568     public void testFindNextPrevious() {
569         openDefaultProject();
570         openDefaultSampleFile();
571         try {
572             EditorOperator editor = getDefaultSampleEditorOperator();
573             
574             // search first word
575
editor.setCaretPosition(1, 1);
576             new FindAction().perform();
577             Find find = new Find();
578             uncheckAll();
579             find.cboFindWhat().clearText();
580             find.cboFindWhat().typeText("testWord");
581             find.find();
582             waitForLabel("'testWord' found at 18:12");
583             find.close();
584             new EventTool().waitNoEvent(FIND_TIMEOUT);
585             
586             // search next word
587
for (int i = 0; i<7; i++) {
588                 MainWindowOperator.getDefault().pushKey(KeyEvent.VK_F3);
589                 waitForLabel("'testWord' found at "+String.valueOf(i+19)
590                         +":12");
591             }
592             
593             // search previous word
594
for (int i = 7; i>0; i--) {
595                 MainWindowOperator.getDefault().pushKey(KeyEvent.VK_F3,
596                         KeyEvent.SHIFT_MASK);
597                 waitForLabel("'testWord' found at "+String.valueOf(i+17)
598                         +":12");
599             }
600         } finally {
601             closeFindDialogIfOpened();
602             closeFileWithDiscard();
603         }
604     }
605     
606     /**
607      * TC15 - Find Selection Without Dialog
608      */

609     public void testFindSelectionWithoutDialog() {
610         openDefaultProject();
611         openDefaultSampleFile();
612         try {
613             EditorOperator editor = getDefaultSampleEditorOperator();
614             
615             // perform backward search
616
editor.select(18, 12, 19);
617             for (int i = 0; i<7; i++) {
618                 MainWindowOperator.getDefault().pushKey(KeyEvent.VK_F3);
619                 waitForLabel("'testWord' found at "+String.valueOf(i+19)
620                         +":12");
621             }
622         } finally {
623             closeFindDialogIfOpened();
624             closeFileWithDiscard();
625         }
626     }
627     
628     /**
629      * TC16 - Search Selection
630      */

631     public void testSearchSelection() {
632         openDefaultProject();
633         openDefaultSampleFile();
634         try {
635             EditorOperator editor = getDefaultSampleEditorOperator();
636  
637             // perform selection search
638
editor.select(24, 20);
639             new EventTool().waitNoEvent(FIND_TIMEOUT);
640             new FindAction().perform();
641             Find find = new Find();
642             uncheckAll();
643             find.cbIncrementalSearch().setSelected(true);
644             find.cbBlockSearch().setSelected(true);
645             find.cboFindWhat().clearText();
646             find.cboFindWhat().typeText("testWord2");
647             find.find();
648             waitForLabel("'testWord2' found at 22:12");
649             find.close();
650  
651         } finally {
652             closeFindDialogIfOpened();
653             closeFileWithDiscard();
654         }
655     }
656     
657     /**
658      * TC17 - Search Selection Negative
659      */

660     public void testSearchSelectionNegative() {
661         openDefaultProject();
662         openDefaultSampleFile();
663         try {
664             EditorOperator editor = getDefaultSampleEditorOperator();
665  
666             // perform negative selection search
667
editor.select(25, 22);
668             new EventTool().waitNoEvent(FIND_TIMEOUT);
669             new FindAction().perform();
670             Find find2 = new Find();
671             uncheckAll();
672             find2.cbIncrementalSearch().setSelected(true);
673             find2.cbBlockSearch().setSelected(true);
674             find2.cboFindWhat().clearText();
675             find2.cboFindWhat().typeText("testWord2");
676             find2.find();
677             waitForLabel("'testWord2' not found");
678             find2.close();
679  
680         } finally {
681             closeFindDialogIfOpened();
682             closeFileWithDiscard();
683         }
684     }
685     
686     /**
687      * TC18 - Regexp Search - Simple
688      */

689     public void testRegexpSimple() {
690         openDefaultProject();
691         openDefaultSampleFile();
692         try {
693             EditorOperator editor = getDefaultSampleEditorOperator();
694             
695             // perform simple regexp search
696
editor.setCaretPosition(1, 1);
697             new FindAction().perform();
698             Find find = new Find();
699             uncheckAll();
700             find.cbRegularExpressions().setSelected(true);
701             find.cboFindWhat().clearText();
702             find.cboFindWhat().typeText("[aA][hH][oO][jJ][0-9]{1,3}");
703             find.find();
704             waitForLabel("'[aA][hH][oO][jJ][0-9]{1,3}' found at 18:12");
705             find.cboFindWhat().clearText();
706             find.cboFindWhat().typeText("[aA][hH][oO][jJ][0-9]{1,3}");
707             find.find();
708             waitForLabel("'[aA][hH][oO][jJ][0-9]{1,3}' found at 19:12");
709             find.cboFindWhat().clearText();
710             find.cboFindWhat().typeText("[aA][hH][oO][jJ][0-9]{1,3}");
711             find.find();
712             waitForLabel("'[aA][hH][oO][jJ][0-9]{1,3}' found at 20:12");
713             find.cboFindWhat().clearText();
714             find.cboFindWhat().typeText("[aA][hH][oO][jJ][0-9]{1,3}");
715             find.find();
716             waitForLabel("'[aA][hH][oO][jJ][0-9]{1,3}' found at 21:12");
717             find.cboFindWhat().clearText();
718             find.cboFindWhat().typeText("[aA][hH][oO][jJ][0-9]{1,3}");
719             find.find();
720             waitForLabel("'[aA][hH][oO][jJ][0-9]{1,3}' found at 23:12");
721             find.cboFindWhat().clearText();
722             find.cboFindWhat().typeText("[aA][hH][oO][jJ][0-9]{1,3}");
723             find.find();
724             waitForLabel("'[aA][hH][oO][jJ][0-9]{1,3}' not found");
725             find.close();
726             
727         } finally {
728             closeFindDialogIfOpened();
729             closeFileWithDiscard();
730         }
731     }
732     
733     /**
734      * TC19 - Regexp Search - Complex
735      */

736     public void testRegexpComplex() {
737         openDefaultProject();
738         openDefaultSampleFile();
739         try {
740             EditorOperator editor = getDefaultSampleEditorOperator();
741             
742             // perform simple regexp search
743
editor.setCaretPosition(1, 1);
744             new FindAction().perform();
745             Find find = new Find();
746             uncheckAll();
747             find.cbRegularExpressions().setSelected(true);
748             find.cboFindWhat().clearText();
749             find.cboFindWhat().typeText("a?B*c{2}[dD]e{1,}\\.F{1,2}\\s[^g]");
750             find.find();
751             waitForLabel("'a?B*c{2}[dD]e{1,}\\.F{1,2}\\s[^g]' found at 18:12");
752             find.cboFindWhat().clearText();
753             find.cboFindWhat().typeText("a?B*c{2}[dD]e{1,}\\.F{1,2}\\s[^g]");
754             find.find();
755             waitForLabel("'a?B*c{2}[dD]e{1,}\\.F{1,2}\\s[^g]' found at 19:12");
756             find.cboFindWhat().clearText();
757             find.cboFindWhat().typeText("a?B*c{2}[dD]e{1,}\\.F{1,2}\\s[^g]");
758             find.find();
759             waitForLabel("'a?B*c{2}[dD]e{1,}\\.F{1,2}\\s[^g]' found at 21:12");
760             find.cboFindWhat().clearText();
761             find.cboFindWhat().typeText("a?B*c{2}[dD]e{1,}\\.F{1,2}\\s[^g]");
762             find.find();
763             waitForLabel("'a?B*c{2}[dD]e{1,}\\.F{1,2}\\s[^g]' found at 23:12");
764             find.cboFindWhat().clearText();
765             find.cboFindWhat().typeText("a?B*c{2}[dD]e{1,}\\.F{1,2}\\s[^g]");
766             find.find();
767             waitForLabel("'a?B*c{2}[dD]e{1,}\\.F{1,2}\\s[^g]' not found");
768             find.close();
769             
770         } finally {
771             closeFindDialogIfOpened();
772             closeFileWithDiscard();
773         }
774     }
775     
776     /**
777      * Unchecks all checkboxes in find dialog.
778      */

779     public void uncheckAll() {
780         Find find = new Find();
781         find.cbBackwardSearch().setSelected(false);
782         find.cbBlockSearch().setSelected(false);
783         find.cbHighlightSearch().setSelected(false);
784         find.cbIncrementalSearch().setSelected(false);
785         find.cbMatchCase().setSelected(false);
786         find.cbMatchWholeWordsOnly().setSelected(false);
787         find.cbRegularExpressions().setSelected(false);
788         //find.cbSmartCase().setSelected(false);
789
find.cbWrapSearch().setSelected(false);
790     }
791     
792     /**
793      * Waits for label to appear on Status Bar, checks it 10 times before
794      * failing.
795      * @param label label which should be displayed on status bar
796      */

797     public void waitForLabel(String JavaDoc label) {
798         EditorOperator editor = getDefaultSampleEditorOperator();
799         for (int i = 0; i<10; i++) {
800             if (editor.lblStatusBar().getText().equals(label)) break;
801             new EventTool().waitNoEvent(FIND_TIMEOUT);
802         }
803         assertEquals(label,editor.lblStatusBar().getText());
804     }
805     
806     
807     /**
808      * Checks if a find dialog is opened and if yes it closes it.
809      */

810     public void closeFindDialogIfOpened() {
811         Window JavaDoc findWindow = WindowOperator.findWindow(
812                 new ComponentChooser() {
813             public boolean checkComponent(Component JavaDoc comp) {
814                 WindowOperator winOper = new WindowOperator((Window JavaDoc)comp);
815                 winOper.setOutput(TestOut.getNullOutput());
816                 return null != winOper.findSubComponent(
817                         new ComponentChooser() {
818                     public boolean checkComponent(Component JavaDoc comp) {
819                         return comp.getClass().getName().startsWith(
820                                 "org.netbeans.editor.ext.Find"); //NOI18N
821
}
822                     public String JavaDoc getDescription() {
823                         return("any find dialog"); //NOI18N
824
}
825                 });
826             }
827             public String JavaDoc getDescription() {
828                 return "containing any find dialog"; //NOI18N
829
}
830         });
831         if(findWindow != null) {
832             new Find().close();
833         }
834     }
835     
836 }
837
Popular Tags