KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > gui > web > extbrowser > settings > BrowserRegistry


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 org.netbeans.test.gui.web.extbrowser.settings;
21
22 import org.netbeans.jellytools.JellyTestCase;
23 import org.netbeans.jellytools.Bundle;
24 import org.netbeans.jellytools.ExplorerOperator;
25 import org.netbeans.jellytools.OptionsOperator;
26 import org.netbeans.jellytools.NbDialogOperator;
27
28 import org.netbeans.jellytools.properties.TextFieldProperty;
29 import org.netbeans.jellytools.properties.PropertySheetTabOperator;
30 import org.netbeans.jellytools.properties.PropertySheetOperator;
31 import org.netbeans.jellytools.properties.editors.FileCustomEditorOperator;
32
33
34
35
36 import org.netbeans.test.gui.web.util.BrowserUtils;
37
38 import org.netbeans.jemmy.operators.JButtonOperator;
39 import org.netbeans.jemmy.operators.JTextFieldOperator;
40 import org.netbeans.jemmy.operators.JTextComponentOperator;
41 import org.netbeans.junit.NbTestSuite;
42 import java.io.File JavaDoc;
43
44 public class BrowserRegistry extends JellyTestCase {
45     private static String JavaDoc workDir = null;
46     private static String JavaDoc webModule = null;
47     private static String JavaDoc wmName = "wm1";
48     private static String JavaDoc fSep = System.getProperty("file.separator");
49     private static String JavaDoc iSep = "|";
50     private static String JavaDoc classes = "Classes";
51     private static boolean wa = false;
52     private static String JavaDoc ideConfiguration = Bundle.getString("org.netbeans.core.Bundle", "UI/Services/IDEConfiguration");
53     private static String JavaDoc sets = Bundle.getString("org.netbeans.core.Bundle", "UI/Services/IDEConfiguration/ServerAndExternalToolSettings");
54     private static String JavaDoc browsers = Bundle.getString("org.netbeans.core.Bundle", "Services/Browsers");
55     private static String JavaDoc cl = Bundle.getString("org.netbeans.modules.extbrowser.Bundle","CTL_SimpleExtBrowser");
56     private static String JavaDoc ub = Bundle.getString("org.netbeans.modules.extbrowser.Bundle","CTL_UnixBrowserName");
57     private static String JavaDoc pnameBrowserExecutable = Bundle.getString("org.netbeans.modules.extbrowser.Bundle" ,"PROP_browserExecutable");
58     private static String JavaDoc pnameBrowserDescr = Bundle.getString("org.netbeans.modules.extbrowser.Bundle" ,"PROP_Description");
59     public BrowserRegistry(java.lang.String JavaDoc testName) {
60         super(testName);
61     }
62
63     public static void main(java.lang.String JavaDoc[] args) {
64         junit.textui.TestRunner.run(suite());
65     }
66          
67     //method required by JUnit
68
public static junit.framework.Test suite() {
69     workDir = System.getProperty("extbrowser.workdir").replace('/', fSep.charAt(0));
70     webModule = workDir + fSep + wmName;
71
72     //WorkAround for 27177
73
OptionsOperator oo = OptionsOperator.invoke();
74      try {
75          oo.selectOption(ideConfiguration + iSep + sets + iSep + browsers + iSep + cl);
76      }catch(Exception JavaDoc e) {
77          try {
78          sets = "ServerAndExternalToolSettings";
79          oo.selectOption(ideConfiguration + iSep + sets + iSep + browsers + iSep + cl);
80          wa = true;
81          }catch(Exception JavaDoc e1) {
82          System.err.println("BrowserRegistry:suite():Looks like something is wrong with options");
83          }
84      }
85      oo.close();
86      return new NbTestSuite(BrowserRegistry.class);
87     }
88
89     /**
90        External Browser (Command Line) : Change Browser Description
91      **/

92     public void testChangeBrowserDescrEBCL() {
93     String JavaDoc newDescr = "CL Browser";
94     OptionsOperator oo = OptionsOperator.invoke();
95     TextFieldProperty pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + cl, pnameBrowserDescr);
96     pr.setValue(newDescr);
97     if (!pr.getValue().equals(newDescr)) {
98         fail("Browser Description field not editable");
99     }
100     pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + cl, pnameBrowserDescr);
101     oo.close(); //Closing options
102
oo = OptionsOperator.invoke();
103     pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + cl, pnameBrowserDescr);
104     if (!pr.getValue().equals(newDescr)) {
105         fail("Browser Description field not saved");
106     }
107     }
108    
109     /**
110        External Browser (Command Line) : Set Process to Browser in Path
111      **/

112     
113     public void testSetProcessToBrowserInPathEBCL() {
114     String JavaDoc newExec = "netscape {URL}";
115     OptionsOperator oo = OptionsOperator.invoke();
116     TextFieldProperty pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + cl, pnameBrowserExecutable);
117     pr.setValue(newExec);
118     if (!pr.getValue().equals(newExec)) {
119         fail("Browser Executable field not editable");
120     }
121     oo.close();
122     oo = OptionsOperator.invoke();
123     pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + cl, pnameBrowserExecutable);
124     if (!pr.getValue().equals(newExec)) {
125         fail("Browser Executable field not saved");
126     }
127     }
128     /**
129        External Browser (Command Line) : Set Process with Full Path to Browser
130                            &
131        External Browser (Command Line) : Use String '{URL}' in Process
132      **/

133
134     public void testSetProcessWithFullPathToBrowserEBCL() {
135     String JavaDoc newExec = fullPathCommand();
136     OptionsOperator oo = OptionsOperator.invoke();
137     TextFieldProperty pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + cl, pnameBrowserExecutable);
138     pr.openEditor();
139     NbDialogOperator nbo = new NbDialogOperator(pnameBrowserExecutable);
140     if(!(new JTextComponentOperator(nbo, 1)).getText().equals("{URL}")) {
141         fail("Wrong default arguments field: " + (new JTextFieldOperator(nbo, 1)).getText());
142     }
143     String JavaDoc custom = "..."; //Correct bundle Not found currently
144
new JButtonOperator(nbo, custom).pushNoBlock();
145     NbDialogOperator nbo1 = new NbDialogOperator("Open");
146     new JTextFieldOperator(nbo1, 0).setText(newExec);
147     String JavaDoc openTitle = Bundle.getString("org.openide.explorer.propertysheet.editors.Bundle", "CTL_OpenButtonName");
148     new JButtonOperator(nbo1, openTitle).push();
149     nbo.ok();
150     pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + cl, pnameBrowserExecutable);
151     if (!pr.getValue().equals(newExec + " {URL}")) {
152         fail("Browser Executable not set via editor. \"" + pr.getValue() + "\" instead of \"" + newExec + " {URL}\"");
153     }
154     oo.close();
155     oo = OptionsOperator.invoke();
156     pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + cl, pnameBrowserExecutable);
157     if (!pr.getValue().equals(newExec + " {URL}")) {
158         fail("Browser Executable field not saved, if set via editor. "+ pr.getValue() + " instead of \"" + newExec + " {URL}\"");
159     }
160     }
161     /**
162        External Browser (Command Line) : Change process -- "Cancel"
163     **/

164     
165     public void testChangeProcessCancelEBCL() {
166     String JavaDoc newExec = "UnReal";
167     OptionsOperator oo = OptionsOperator.invoke();
168     TextFieldProperty pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + cl, pnameBrowserExecutable);
169     String JavaDoc origExec = pr.getValue();
170     pr.openEditor();
171     NbDialogOperator nbo = new NbDialogOperator(pnameBrowserExecutable);
172     new JTextFieldOperator(nbo, 0).setText(newExec);
173     nbo.cancel();
174     pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + cl, pnameBrowserExecutable);
175     if (!pr.getValue().equals(origExec)) {
176         fail("\"" + pr.getValue() + "\" instead of \"" + origExec + "\"");
177     }
178     }
179
180     /**
181        External Browser (Command Line) : Change arguments -- "Cancel"
182     **/

183     
184     public void testChangeArgumentsCancelEBCL() {
185     String JavaDoc newArg = "UnRealArgs";
186     OptionsOperator oo = OptionsOperator.invoke();
187     TextFieldProperty pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + cl, pnameBrowserExecutable);
188     String JavaDoc origExec = pr.getValue();
189     pr.openEditor();
190     NbDialogOperator nbo = new NbDialogOperator(pnameBrowserExecutable);
191     new JTextComponentOperator(nbo, 1).setText(newArg);
192     nbo.cancel();
193     pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + cl, pnameBrowserExecutable);
194     if (!pr.getValue().equals(origExec)) {
195         fail("\"" + pr.getValue() + "\" instead of \"" + origExec + "\"");
196     }
197     }
198
199     /********************************************
200        External Browser (Unix) section
201     *********************************************/

202     /**
203        External Browser (Unix) : Change Browser Description
204      **/

205     public void testChangeBrowserDescrEBU() {
206     String JavaDoc newDescr = "CL Browser";
207     OptionsOperator oo = OptionsOperator.invoke();
208     TextFieldProperty pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + ub, pnameBrowserDescr);
209     if (pr.isEditable()) {
210         fail("Browser Description field is editable");
211     }
212     oo.close();
213     
214     }
215    
216     /**
217        External Browser (Unix) : Set Process to Browser in Path
218      **/

219     
220     public void testSetProcessToBrowserInPathEBU() {
221     String JavaDoc newExec = "netscape {params}";
222     OptionsOperator oo = OptionsOperator.invoke();
223     TextFieldProperty pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + ub, pnameBrowserExecutable);
224     pr.setValue(newExec);
225     if (!pr.getValue().equals(newExec)) {
226         fail("Browser Executable field not editable");
227     }
228     oo.close();
229     oo = OptionsOperator.invoke();
230     pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + ub, pnameBrowserExecutable);
231     if (!pr.getValue().equals(newExec)) {
232         fail("Browser Executable field not saved");
233     }
234     }
235     /**
236        External Browser (Unix) : Set Process with Full Path to Browser
237                            &
238        External Browser (Unix) : Use String '{params}' in Process
239      **/

240
241     public void testSetProcessWithFullPathToBrowserEBU() {
242     String JavaDoc newExec = fullPathCommand();
243     OptionsOperator oo = OptionsOperator.invoke();
244     TextFieldProperty pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + ub, pnameBrowserExecutable);
245     pr.openEditor();
246     NbDialogOperator nbo = new NbDialogOperator(pnameBrowserExecutable);
247     if(!(new JTextComponentOperator(nbo, 1)).getText().equals("{params}")) {
248         fail("Wrong default arguments field: " + (new JTextFieldOperator(nbo, 1)).getText());
249     }
250     String JavaDoc custom = "..."; //Correct bundle Not found currently
251
new JButtonOperator(nbo, custom).pushNoBlock();
252     System.out.println("Before wait for open");
253     NbDialogOperator nbo1 = new NbDialogOperator("Open");
254     System.out.println("After wait for open");
255     new JTextFieldOperator(nbo1, 0).setText(newExec);
256     String JavaDoc openTitle = Bundle.getString("org.openide.explorer.propertysheet.editors.Bundle", "CTL_OpenButtonName");
257     new JButtonOperator(nbo1, openTitle).push();
258     nbo.ok();
259     pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + ub, pnameBrowserExecutable);
260     if (!pr.getValue().equals(newExec + " {params}")) {
261         fail("Browser Executable not set via editor. \"" + pr.getValue() + "\" instead of \"" + newExec + " {params}\"");
262     }
263     oo.close();
264     oo = OptionsOperator.invoke();
265     pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + ub, pnameBrowserExecutable);
266     if (!pr.getValue().equals(newExec + " {params}")) {
267         fail("Browser Executable field not saved, if set via editor. "+ pr.getValue() + " instead of \"" + newExec + " {params}\"");
268     }
269     }
270     /**
271        External Browser (Unix) : Change process -- "Cancel"
272     **/

273     
274     public void testChangeProcessCancelEBU() {
275     String JavaDoc newExec = "UnReal";
276     OptionsOperator oo = OptionsOperator.invoke();
277     TextFieldProperty pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + ub, pnameBrowserExecutable);
278     String JavaDoc origExec = pr.getValue();
279     pr.openEditor();
280     NbDialogOperator nbo = new NbDialogOperator(pnameBrowserExecutable);
281     new JTextFieldOperator(nbo, 0).setText(newExec);
282     nbo.cancel();
283     pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + ub, pnameBrowserExecutable);
284     if (!pr.getValue().equals(origExec)) {
285         fail("\"" + pr.getValue() + "\" instead of \"" + origExec + "\"");
286     }
287     }
288
289     /**
290        External Browser (Unix) : Change arguments -- "Cancel"
291     **/

292     
293     public void testChangeArgumentsCancelEBU() {
294     String JavaDoc newArg = "UnRealArgs";
295     OptionsOperator oo = OptionsOperator.invoke();
296     TextFieldProperty pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + ub, pnameBrowserExecutable);
297     String JavaDoc origExec = pr.getValue();
298     pr.openEditor();
299     NbDialogOperator nbo = new NbDialogOperator(pnameBrowserExecutable);
300     new JTextComponentOperator(nbo, 1).setText(newArg);
301     nbo.cancel();
302     pr = getTFProperty(ideConfiguration + iSep + sets + iSep + browsers + iSep + ub, pnameBrowserExecutable);
303     if (!pr.getValue().equals(origExec)) {
304         fail("\"" + pr.getValue() + "\" instead of \"" + origExec + "\"");
305     }
306     }
307
308     /**
309        Please use this method to request properties.
310        It allow workaround focus problems.
311      */

312
313     private TextFieldProperty getTFProperty(String JavaDoc path, String JavaDoc pname) {
314     OptionsOperator oo = OptionsOperator.invoke();
315     oo.selectOption(path);
316     PropertySheetOperator pso = PropertySheetOperator.invoke();
317         PropertySheetTabOperator psto = new PropertySheetTabOperator(pso);
318     return new TextFieldProperty(psto, pname);
319     }
320
321
322
323
324
325     private static String JavaDoc fullPathCommand() {
326     String JavaDoc[] paths = null;
327     String JavaDoc command = null;
328     if(System.getProperty("os.name").indexOf("Windows")!=-1) {
329             fail("This test must be extended for Windows platform");
330         }else {
331         paths = new String JavaDoc[] {"/usr/bin/netscape","/usr/local/bin/netscape","/bin/netscape"};
332     }
333     for(int i=0;i<paths.length;i++) {
334         if((new File JavaDoc(paths[i])).exists()) {
335         command = paths[i];
336         i = paths.length;
337         }
338     }
339     if(command == null) {
340         StringBuffer JavaDoc reason = new StringBuffer JavaDoc("Nothing of following commands found on your system : ");
341         for(int i=0;i<paths.length;i++) {
342         reason.append(paths[i] + ";");
343         }
344         fail(reason.toString());
345     }
346     return command;
347     }
348 }
349
350
351
352
353
354
355
356
Popular Tags