KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > utilities > search > BasicSearchTest


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  * BasicSearchTest.java
20  *
21  * Created on November 30, 2006, 3:31 PM
22  *
23  */

24
25 package org.netbeans.test.utilities.search;
26
27 import java.util.Hashtable JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import org.netbeans.jellytools.NbDialogOperator;
30 import org.netbeans.jemmy.ComponentChooser;
31 import org.netbeans.jemmy.ComponentChooser;
32 import org.netbeans.jemmy.operators.JComboBoxOperator;
33 import org.netbeans.jemmy.operators.JTabbedPaneOperator;
34 import org.netbeans.junit.NbTestCase;
35 import org.netbeans.junit.NbTestSuite;
36 import org.netbeans.test.utilities.operators.SearchResultsOperator;
37 import org.netbeans.test.utilities.testcase.Utilities;
38
39 /**
40  * Some search tests
41  * @author Max Sauer
42  */

43 public class BasicSearchTest extends NbTestCase {
44     
45     /** path to sample files */
46     private static final String JavaDoc TEST_PACKAGE_PATH =
47             "org.netbeans.test.utilities.basicsearch";
48     
49     /** Creates a new instance of BasicSearchTest */
50     public BasicSearchTest(String JavaDoc testName) {
51         super(testName);
52     }
53     
54     /**
55      * Adds tests to suite
56      * @return created suite
57      */

58     public static NbTestSuite suite() {
59         NbTestSuite suite = new NbTestSuite(BasicSearchTest.class);
60         return suite;
61     }
62     
63     public void testSearchForClass() {
64         NbDialogOperator ndo = Utilities.getFindDialog();
65         JTabbedPaneOperator jtpo = new JTabbedPaneOperator(ndo, 0);
66         jtpo.selectPage(0);
67         
68         JComboBoxOperator jcbo = new JComboBoxOperator(ndo,
69                 new JComboBoxOperator.JComboBoxFinder());
70         jcbo.enterText("class"); //enter 'class' in search comboBox and press [Enter]
71

72         SearchResultsOperator sro = new SearchResultsOperator();
73         assertTrue("Junit Output window should be visible", sro.isVisible());
74         System.out.println("## Search output opened");
75         Utilities.takeANap(1000);
76         sro.close();
77         assertFalse("Search window is visible," +
78                 "should be closed", sro.isShowing());
79     }
80     
81     /**
82      * Test if searched items are remembered inside combobox
83      */

84     public void testRememberSearchesInsideComboBox() {
85         //setup ten searches
86
for (int i = 0; i < 10; i++) {
87             NbDialogOperator ndo = Utilities.getFindDialog();
88             JTabbedPaneOperator jtpo = new JTabbedPaneOperator(ndo, 0);
89             jtpo.selectPage(0);
90             
91             JComboBoxOperator jcbo = new JComboBoxOperator(ndo,
92                     new JComboBoxOperator.JComboBoxFinder());
93             jcbo.enterText("a" + i);
94             Utilities.takeANap(500);
95         }
96         //check
97
NbDialogOperator ndo = Utilities.getFindDialog();
98         JTabbedPaneOperator jtpo = new JTabbedPaneOperator(ndo, 0);
99         jtpo.selectPage(0);
100         
101         JComboBoxOperator jcbo = new JComboBoxOperator(ndo,
102                 new JComboBoxOperator.JComboBoxFinder());
103                 
104         for (int i = 0; i < jcbo.getItemCount() - 1; i++) {
105             assertEquals("Found " + jcbo.getItemAt(i).toString() +" in search combo" +
106                     "expected" + new Integer JavaDoc(9-i).toString() + ".",
107                     jcbo.getItemAt(i).toString(), "a" + new Integer JavaDoc(9-i).toString());
108         }
109         assertEquals("Expected 'class', found: " +
110                 jcbo.getItemAt(jcbo.getItemCount()-1),
111                 jcbo.getItemAt(jcbo.getItemCount()-1), "class");
112
113     }
114     
115     
116     private String JavaDoc soutHashTable(Hashtable JavaDoc ht) {
117         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
118         Iterator JavaDoc itv = ht.values().iterator();
119         for (Iterator JavaDoc it = ht.keySet().iterator(); it.hasNext();) {
120             sb.append("KEY: " + it.next() + " Value: " + itv.next() + "\n");
121             
122         }
123         return sb.toString();
124     }
125     
126     
127 }
128
Popular Tags