Line 0
Link Here
|
|
|
1 |
/* |
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
3 |
* |
4 |
* Copyright 2012 Oracle and/or its affiliates. All rights reserved. |
5 |
* |
6 |
* Oracle and Java are registered trademarks of Oracle and/or its affiliates. |
7 |
* Other names may be trademarks of their respective owners. |
8 |
* |
9 |
* The contents of this file are subject to the terms of either the GNU |
10 |
* General Public License Version 2 only ("GPL") or the Common |
11 |
* Development and Distribution License("CDDL") (collectively, the |
12 |
* "License"). You may not use this file except in compliance with the |
13 |
* License. You can obtain a copy of the License at |
14 |
* http://www.netbeans.org/cddl-gplv2.html |
15 |
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the |
16 |
* specific language governing permissions and limitations under the |
17 |
* License. When distributing the software, include this License Header |
18 |
* Notice in each file and include the License file at |
19 |
* nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this |
20 |
* particular file as subject to the "Classpath" exception as provided |
21 |
* by Oracle in the GPL Version 2 section of the License file that |
22 |
* accompanied this code. If applicable, add the following below the |
23 |
* License Header, with the fields enclosed by brackets [] replaced by |
24 |
* your own identifying information: |
25 |
* "Portions Copyrighted [year] [name of copyright owner]" |
26 |
* |
27 |
* If you wish your version of this file to be governed by only the CDDL |
28 |
* or only the GPL Version 2, indicate your decision by adding |
29 |
* "[Contributor] elects to include this software in this distribution |
30 |
* under the [CDDL or GPL Version 2] license." If you do not indicate a |
31 |
* single choice of license, a recipient has the option to distribute |
32 |
* your version of this file under either the CDDL, the GPL Version 2 or |
33 |
* to extend the choice of license to its licensees as provided above. |
34 |
* However, if you add GPL Version 2 code and therefore, elected the GPL |
35 |
* Version 2 license, then the option applies only if the new code is |
36 |
* made subject to such option by the copyright holder. |
37 |
* |
38 |
* Contributor(s): |
39 |
* |
40 |
* Portions Copyrighted 2012 Sun Microsystems, Inc. |
41 |
*/ |
42 |
package org.netbeans.modules.options; |
43 |
|
44 |
import java.awt.Component; |
45 |
import java.awt.event.KeyEvent; |
46 |
import java.util.ArrayList; |
47 |
import java.util.Arrays; |
48 |
import javax.swing.JLabel; |
49 |
import junit.framework.Test; |
50 |
import org.netbeans.jellytools.JellyTestCase; |
51 |
import org.netbeans.jellytools.OptionsOperator; |
52 |
import org.netbeans.jemmy.ComponentChooser; |
53 |
import org.netbeans.jemmy.EventTool; |
54 |
import org.netbeans.jemmy.operators.JLabelOperator; |
55 |
import org.netbeans.jemmy.operators.JTabbedPaneOperator; |
56 |
import org.netbeans.jemmy.operators.JTextFieldOperator; |
57 |
import org.netbeans.jemmy.operators.Operator; |
58 |
import org.netbeans.jemmy.operators.Operator.StringComparator; |
59 |
import org.netbeans.junit.NbModuleSuite; |
60 |
|
61 |
/** |
62 |
* |
63 |
* @author theofanis |
64 |
*/ |
65 |
public class SearchInOptionsTest extends JellyTestCase { |
66 |
|
67 |
private StringComparator stringComparator; |
68 |
private OptionsOperator optionsOperator; |
69 |
private JTextFieldOperator jTextFieldOperator; |
70 |
private JTabbedPaneOperator jTabbedPaneOperator; |
71 |
private String[] categoryIDs; |
72 |
|
73 |
/** |
74 |
* Constructor required by JUnit |
75 |
*/ |
76 |
public SearchInOptionsTest(String testName) { |
77 |
super(testName); |
78 |
} |
79 |
|
80 |
/** |
81 |
* Creates suite from particular test cases. |
82 |
*/ |
83 |
public static Test suite() { |
84 |
return NbModuleSuite.createConfiguration(SearchInOptionsTest.class).addTest( |
85 |
"testSearchInOptionsWindow").clusters(".*").enableModules(".*").gui(true).suite(); |
86 |
} |
87 |
|
88 |
public void testSearchInOptionsWindow() { |
89 |
OptionsOperator.invoke(); |
90 |
new EventTool().waitNoEvent(1000); |
91 |
log("Option dialog was opened"); |
92 |
|
93 |
optionsOperator = new OptionsOperator(); |
94 |
new EventTool().waitNoEvent(1000); |
95 |
|
96 |
jTextFieldOperator = new JTextFieldOperator(optionsOperator); |
97 |
stringComparator = Operator.getDefaultStringComparator(); |
98 |
categoryIDs = CategoryModel.getInstance().getCategoryIDs(); |
99 |
|
100 |
int[] tabIndexes = {0}; |
101 |
String[] selectedCategories = {"Editor"}; |
102 |
ArrayList<String> enabledCategories = new ArrayList<String>(); |
103 |
enabledCategories.add("Editor"); |
104 |
searchFor("general editor", tabIndexes, selectedCategories, enabledCategories); |
105 |
|
106 |
tabIndexes[0] = 6; |
107 |
searchFor("macros", tabIndexes, selectedCategories, enabledCategories); |
108 |
|
109 |
tabIndexes[0] = 2; |
110 |
searchFor("completion", tabIndexes, selectedCategories, enabledCategories); |
111 |
|
112 |
tabIndexes[0] = 3; |
113 |
searchFor("templates", tabIndexes, selectedCategories, enabledCategories); |
114 |
|
115 |
tabIndexes[0] = 8; |
116 |
searchFor("dictionary", tabIndexes, selectedCategories, enabledCategories); |
117 |
|
118 |
tabIndexes[0] = 7; |
119 |
searchFor("on save", tabIndexes, selectedCategories, enabledCategories); |
120 |
|
121 |
enabledCategories.clear(); |
122 |
enabledCategories.add("General"); |
123 |
tabIndexes[0] = -1; |
124 |
selectedCategories[0] = "General"; |
125 |
searchFor("proxy", tabIndexes, selectedCategories, enabledCategories); |
126 |
|
127 |
enabledCategories.clear(); |
128 |
enabledCategories.add("Fonts & Colors"); |
129 |
tabIndexes[0] = 0; |
130 |
selectedCategories[0] = "FontsAndColors"; |
131 |
searchFor("syntax", tabIndexes, selectedCategories, enabledCategories); |
132 |
|
133 |
tabIndexes[0] = 1; |
134 |
searchFor("highlighting", tabIndexes, selectedCategories, enabledCategories); |
135 |
|
136 |
tabIndexes[0] = 4; |
137 |
searchFor("versioning", tabIndexes, selectedCategories, enabledCategories); |
138 |
|
139 |
enabledCategories.clear(); |
140 |
enabledCategories.add("Keymap"); |
141 |
tabIndexes[0] = -1; |
142 |
selectedCategories[0] = "Keymaps"; |
143 |
searchFor("keymap", tabIndexes, selectedCategories, enabledCategories); |
144 |
|
145 |
enabledCategories.clear(); |
146 |
enabledCategories.add("Java"); |
147 |
tabIndexes[0] = 5; |
148 |
selectedCategories[0] = "Java"; |
149 |
searchFor("maven", tabIndexes, selectedCategories, enabledCategories); |
150 |
|
151 |
tabIndexes[0] = 0; |
152 |
selectedCategories[0] = "Java"; |
153 |
searchFor("ant", tabIndexes, selectedCategories, enabledCategories); |
154 |
|
155 |
enabledCategories.add("Miscellaneous"); |
156 |
tabIndexes = new int[2]; |
157 |
selectedCategories = new String[2]; |
158 |
tabIndexes[0] = 4; |
159 |
tabIndexes[1] = 2; |
160 |
selectedCategories[0] = "Java"; |
161 |
selectedCategories[1] = "Miscellaneous"; |
162 |
searchFor("me", tabIndexes, selectedCategories, enabledCategories); |
163 |
|
164 |
enabledCategories.clear(); |
165 |
enabledCategories.add("Java"); |
166 |
tabIndexes = new int[1]; |
167 |
selectedCategories = new String[1]; |
168 |
tabIndexes[0] = 7; |
169 |
selectedCategories[0] = "Java"; |
170 |
searchFor("fx", tabIndexes, selectedCategories, enabledCategories); |
171 |
|
172 |
enabledCategories.clear(); |
173 |
enabledCategories.add("Miscellaneous"); |
174 |
tabIndexes[0] = 3; |
175 |
selectedCategories[0] = "Miscellaneous"; |
176 |
searchFor("groovy", tabIndexes, selectedCategories, enabledCategories); |
177 |
|
178 |
tabIndexes[0] = 5; |
179 |
selectedCategories[0] = "Miscellaneous"; |
180 |
searchFor("javascript", tabIndexes, selectedCategories, enabledCategories); |
181 |
|
182 |
tabIndexes[0] = 7; |
183 |
selectedCategories[0] = "Miscellaneous"; |
184 |
searchFor("svg", tabIndexes, selectedCategories, enabledCategories); |
185 |
|
186 |
tabIndexes[0] = 8; |
187 |
selectedCategories[0] = "Miscellaneous"; |
188 |
searchFor("terminal", tabIndexes, selectedCategories, enabledCategories); |
189 |
|
190 |
enabledCategories.add("Fonts & Colors"); |
191 |
tabIndexes = new int[2]; |
192 |
selectedCategories = new String[2]; |
193 |
tabIndexes[0] = 3; |
194 |
tabIndexes[1] = 1; |
195 |
selectedCategories[0] = "FontsAndColors"; |
196 |
selectedCategories[1] = "Miscellaneous"; |
197 |
searchFor("diff", tabIndexes, selectedCategories, enabledCategories); |
198 |
|
199 |
enabledCategories.clear(); |
200 |
enabledCategories.addAll(Arrays.asList("General", "Editor", "Fonts & Colors", "Keymap", "Java", "PHP", "C/C++", "Miscellaneous")); |
201 |
tabIndexes = new int[1]; |
202 |
selectedCategories = new String[1]; |
203 |
tabIndexes[0] = 1; |
204 |
selectedCategories[0] = "Miscellaneous"; |
205 |
searchFor("", tabIndexes, selectedCategories, enabledCategories); |
206 |
} |
207 |
|
208 |
private void searchFor(String searchTxt, int[] selectedTabIndexes, String[] selectedCategories, ArrayList<String> enabledCategories) { |
209 |
jTextFieldOperator.setText(searchTxt); |
210 |
new EventTool().waitNoEvent(500); |
211 |
jTextFieldOperator.pushKey(KeyEvent.VK_ENTER); |
212 |
new EventTool().waitNoEvent(1000); |
213 |
for (int i = 0; i < selectedCategories.length; i++) { |
214 |
String selectedCategory = selectedCategories[i]; |
215 |
if (selectedCategory.equals("General")) { |
216 |
optionsOperator.selectGeneral(); |
217 |
} else if (selectedCategory.equals("Editor")) { |
218 |
optionsOperator.selectEditor(); |
219 |
} else if (selectedCategory.equals("FontsAndColors")) { |
220 |
optionsOperator.selectFontAndColors(); |
221 |
} else if (selectedCategory.equals("Keymaps")) { |
222 |
optionsOperator.selectKeymap(); |
223 |
} else if (selectedCategory.equals("Java")) { |
224 |
optionsOperator.selectJava(); |
225 |
} else if (selectedCategory.equals("Miscellaneous")) { |
226 |
optionsOperator.selectMiscellaneous(); |
227 |
} |
228 |
new EventTool().waitNoEvent(1000); |
229 |
int selectedTabIndex = selectedTabIndexes[i]; |
230 |
if (selectedTabIndex != -1) { |
231 |
jTabbedPaneOperator = new JTabbedPaneOperator(optionsOperator); |
232 |
assertEquals(selectedTabIndex, jTabbedPaneOperator.getSelectedIndex()); |
233 |
} |
234 |
} |
235 |
for(String category : categoryIDs) { |
236 |
if(enabledCategories.contains(category)) { |
237 |
assertTrue(getJLabelOperator(category).isEnabled()); |
238 |
} |
239 |
} |
240 |
} |
241 |
|
242 |
private JLabelOperator getJLabelOperator(final String category) { |
243 |
return new JLabelOperator(optionsOperator, new ComponentChooser() { |
244 |
@Override |
245 |
public boolean checkComponent(Component comp) { |
246 |
if (comp.getClass().getName().equals("org.netbeans.modules.options.OptionsPanel$CategoryButton") ||// NOI18N |
247 |
comp.getClass().getName().equals("org.netbeans.modules.options.OptionsPanel$NimbusCategoryButton")) { // NOI18N |
248 |
if (((JLabel) comp).getText() != null) { |
249 |
return stringComparator.equals(((JLabel) comp).getText(), category); |
250 |
} |
251 |
} |
252 |
return false; |
253 |
} |
254 |
|
255 |
@Override |
256 |
public String getDescription() { |
257 |
return "OptionsPanel$CategoryButton with text " + category; // NOI18N |
258 |
} |
259 |
}); |
260 |
} |
261 |
} |