KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gui > updatecenterwizard > N_LocalServerUpdateCenterWizardTests


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 gui.updatecenterwizard;
21
22 import gui.updatecenterwizard.settings.CatalogDataValues;
23 import gui.updatecenterwizard.settings.TestbagsProperties;
24 import java.awt.Component JavaDoc;
25 import java.io.File JavaDoc;
26 import java.lang.Thread JavaDoc;
27 import java.util.Properties JavaDoc;
28 import javax.swing.JComponent JavaDoc;
29 import javax.swing.JDialog JavaDoc;
30 import org.netbeans.jellytools.Bundle;
31 import org.netbeans.jellytools.JellyTestCase;
32 import org.netbeans.jellytools.NbDialogOperator;
33 import org.netbeans.jellytools.OptionsOperator;
34 import org.netbeans.jellytools.WizardOperator;
35 import org.netbeans.jellytools.actions.Action;
36 import org.netbeans.jellytools.actions.ActionNoBlock;
37 import org.netbeans.jellytools.nodes.Node;
38 import org.netbeans.jellytools.properties.Property;
39 import org.netbeans.jellytools.properties.PropertySheetOperator;
40 import org.netbeans.jellytools.properties.StringProperty;
41 import org.netbeans.jemmy.ComponentChooser;
42 import org.netbeans.jemmy.ComponentSearcher;
43 import org.netbeans.jemmy.EventTool;
44 import org.netbeans.jemmy.JemmyException;
45 import org.netbeans.jemmy.JemmyProperties;
46 import org.netbeans.jemmy.operators.JButtonOperator;
47 import org.netbeans.jemmy.operators.JCheckBoxOperator;
48 import org.netbeans.jemmy.operators.JDialogOperator;
49 import org.netbeans.jemmy.operators.JLabelOperator;
50 import org.netbeans.jemmy.operators.JTableOperator;
51 import org.netbeans.jemmy.operators.JTextFieldOperator;
52 import org.netbeans.jemmy.operators.JTreeOperator;
53 import org.netbeans.jemmy.operators.Operator;
54 import org.netbeans.junit.NbTestSuite;
55
56 /**
57  *
58  * @author Jaromir.Uhrik@Sun.Com
59  */

60
61 public class N_LocalServerUpdateCenterWizardTests extends UpdateCenterWizardTests {
62     
63     CatalogDataValues dataValues = null;
64     TestbagsProperties tbp = new TestbagsProperties();
65     
66     /** Creates a new instance of LocalServerUpdateCenterWizardTests */
67     public N_LocalServerUpdateCenterWizardTests(String JavaDoc name) {
68         super(name);
69     }
70     public void setUp() {
71         System.out.println("######## "+getName()+" #######");
72         dataValues = readDataValues("N_local_settings.xml");
73     }
74     
75     
76     public static NbTestSuite suite() {
77         NbTestSuite suite = new NbTestSuite();
78         
79         suite.addTest(new N_LocalServerUpdateCenterWizardTests("testCreateUpdateCenterType"));
80         suite.addTest(new N_LocalServerUpdateCenterWizardTests("testSuccessfulConnection"));
81         suite.addTest(new N_LocalServerUpdateCenterWizardTests("testUpdateCenter"));
82         suite.addTest(new N_LocalServerUpdateCenterWizardTests("testRestart"));
83         return suite;
84     }
85     
86     
87     /** Use for execution inside IDE */
88     public static void main(java.lang.String JavaDoc[] args) {
89         // run whole suite
90
//TestRunner.run(suite());
91
junit.textui.TestRunner.run(suite());
92     }
93     
94     /** tests creation of new UC type
95      * first parses the xml (upon the content sets the UC type attributes)
96      * then sets the following:
97      * -name
98      * -server URL
99      */

100     public void testCreateUpdateCenterType(){
101         //If the updater restarted IDE then do nothing
102
if(tbp.readProperty(TestbagsProperties.LOCAL_SERVER_TESTBAG_RESTARTED_PROPERTY_NAME) == true){
103             return;
104         }
105         OptionsOperator optionsOper = OptionsOperator.invoke();
106         // set exact comparator because in Japanese there is conflict with Filesystem settings
107
optionsOper.treeTable().tree().setComparator(new Operator.DefaultStringComparator(true, true));
108         // "IDE Configuration|System|Autoupdate Types"
109
String JavaDoc systemSettings = Bundle.getString("org.netbeans.core.Bundle", "UI/Services/IDEConfiguration") + "|" +
110                 Bundle.getString("org.netbeans.core.Bundle", "UI/Services/IDEConfiguration/System") + "|" +
111                 Bundle.getString("org.netbeans.modules.updatecenters.resources.Bundle", "Services/AutoupdateType");
112         
113         Node n = new Node(optionsOper.treeTable().tree(), systemSettings);
114         n.select();
115         
116         new ActionNoBlock(null, /*Bundle.getString("org.openide.loaders.Bundle", "NewTemplate") -doesn't work*/"New" + "|" +
117                 Bundle.getString("org.netbeans.modules.autoupdate.resources.Bundle", "Templates/Services/AutoupdateType/autoupdate_xml_type.settings")
118                 ).perform(n);
119         
120         
121         //New Wizard - General Update Center;
122
String JavaDoc endTitle = Bundle.getString("org.netbeans.modules.autoupdate.resources.Bundle", "Templates/Services/AutoupdateType/autoupdate_xml_type.settings");
123         String JavaDoc startTitle = Bundle.getString("org.openide.loaders.Bundle", "CTL_TemplateTitle2");
124         startTitle = startTitle.substring(0, startTitle.length()-3);
125         String JavaDoc newWizardTitle = startTitle + endTitle;
126         WizardOperator newWizardOperator = null;
127         newWizardOperator = new WizardOperator(newWizardTitle);
128         
129         JTextFieldOperator tfo = new JTextFieldOperator(newWizardOperator, 0);
130         tfo.setText(dataValues.getUcName());
131         
132         newWizardOperator.btFinish().push();
133         
134         
135         String JavaDoc localUCType = systemSettings + "|" + dataValues.getUcName();
136         n = new Node(optionsOper.treeTable().tree(), localUCType);
137         n.select();
138         
139         PropertySheetOperator pso = new PropertySheetOperator(optionsOper);
140         Property serverURLProperty = new Property(pso, Bundle.getString("org.netbeans.modules.autoupdate.Bundle", "PROP_Url"));
141         serverURLProperty.setValue("file:/" + getDataDir() + File.separator + "catalog" + File.separator + dataValues.getUcFile());
142         optionsOper.close();
143     }
144     
145     
146     
147     /** opens Update Center wizard
148      * set proxy to webcache:8080 !!! please change it correctly to your local settings, or comment the line marked with '// !!! proxy !!!'
149      * connects to default update center
150      */

151     public void testSuccessfulConnection() {
152         //If the updater restarted IDE then do nothing
153
if(tbp.readProperty(TestbagsProperties.LOCAL_SERVER_TESTBAG_RESTARTED_PROPERTY_NAME) == true){
154             return;
155         }
156         
157         WizardOperator ucwizard = null;
158         try {
159             ucwizard = openUpdateCenterWizard();
160             
161             //only remote UC created by tests will be selected
162
setAllAUtypesSelected(false);
163             String JavaDoc myUC = dataValues.getUcName();
164             setAUtypeSelected(myUC, true);
165             
166             // set proxy
167
// Proxy Configuration...
168
String JavaDoc buttonProxyConfLabel = Bundle.getString("org.netbeans.modules.autoupdate.Bundle", "BNT_Proxy"); // !!! proxy !!! // NOI18N
169
new JButtonOperator(ucwizard, buttonProxyConfLabel).pushNoBlock(); // !!! proxy !!!
170
// Proxy Configuration
171
String JavaDoc proxyConfDialogTitle = Bundle.getString("org.netbeans.modules.autoupdate.Bundle", "CTL_ProxyDialog_Title"); // !!! proxy !!! // NOI18N
172
NbDialogOperator proxyDialog = new NbDialogOperator(proxyConfDialogTitle);// !!! proxy !!!
173
// Use Proxy check box
174
new JCheckBoxOperator(proxyDialog).setSelected(true);// !!! proxy !!!
175
// Proxy Host: text field
176
new JTextFieldOperator(proxyDialog, 0).setText(dataValues.getProxyHost());// !!! proxy !!! // NOI18N
177
// Proxy Port: text field
178
new JTextFieldOperator(proxyDialog, 1).setText(dataValues.getProxyPort());// !!! proxy !!! // NOI18N
179
proxyDialog.ok();// !!! proxy !!!
180
// "Next >"
181
ucwizard.btNext().pushNoBlock();
182             // wait connecting dialog appears
183
// "Connecting"
184
String JavaDoc connectingTitle = Bundle.getString("org.netbeans.modules.autoupdate.Bundle", "CTL_Connecting_Title");
185             // wait at most 60 second until connecting dialog dismiss
186
JemmyProperties.setCurrentTimeout("ComponentOperator.WaitStateTimeout", 60000);
187             new NbDialogOperator(connectingTitle).waitClosed();
188             //check that you are on second pane/step
189
String JavaDoc secondStep = Bundle.getString("org.netbeans.modules.autoupdate.Bundle", "LAB_221"); //label 'Available Updates and New Modules:' is only on second pane
190
new JLabelOperator(ucwizard, secondStep);
191             //can close
192
ucwizard.close();
193             
194         } catch (JemmyException e) {
195             // close Update center dialog
196
if(ucwizard != null) {
197                 ucwizard.close();
198             }
199             throw e;
200         }
201         
202     }
203     
204     /** Test Update Center
205      * - open Update Center Wizard from main menu Tools|Update Center
206      * - set proxy and go next
207      * - wait until connection dialog dismiss
208      * - in modules tree select "Development Update Center|Web|Applet" node
209      * - click right arrow button and go next
210      * - accept license dialog
211      * - wait until download is finished and finish the wizard
212      */

213     public void testUpdateCenter() {
214         //If the updater restarted IDE then do nothing
215
if(tbp.readProperty(TestbagsProperties.LOCAL_SERVER_TESTBAG_RESTARTED_PROPERTY_NAME) == true){
216             return;
217         }
218         
219         // "Tools"
220
String JavaDoc toolsItem = Bundle.getStringTrimmed("org.netbeans.core.Bundle", "Menu/Tools"); // NOI18N
221
WizardOperator updateCenterWizardOper = null;
222         long oldWaitStateTime = JemmyProperties.getCurrentTimeout("ComponentOperator.WaitStateTimeout");
223         try {
224             // "Update Center"
225
String JavaDoc updateCenterItem = Bundle.getStringTrimmed("org.netbeans.modules.autoupdate.Bundle", "CTL_Update");
226             new Action(toolsItem+"|"+updateCenterItem, null).perform();
227             // "Update Center Wizard"
228
String JavaDoc updateCenterTitle = Bundle.getString("org.netbeans.modules.autoupdate.Bundle", "CTL_Wizard");
229             updateCenterWizardOper = new WizardOperator(updateCenterTitle);
230             // disable Forte for Java Update Center if any
231
JTableOperator oper = new JTableOperator(updateCenterWizardOper);
232             // check each row
233
for(int i=0;i<oper.getRowCount();i++) {
234                 // if Update Center matches "Forte" and it is enabled/checked then click to uncheck
235
if(oper.getValueAt(i, 1).toString().indexOf("Forte")>-1 && ((Boolean JavaDoc)oper.getValueAt(i, 0)).booleanValue()) { // NOI18N
236
oper.clickOnCell(i, 0);
237                 }
238                 // if Update Center matches "Sun ONE Studio" and it is enabled/checked then click to uncheck
239
if(oper.getValueAt(i, 1).toString().indexOf("Sun")>-1 && ((Boolean JavaDoc)oper.getValueAt(i, 0)).booleanValue()) { // NOI18N
240
oper.clickOnCell(i, 0);
241                 }
242             }
243             
244             // set proxy
245
// Proxy Configuration...
246
String JavaDoc buttonProxyConfLabel = Bundle.getString("org.netbeans.modules.autoupdate.Bundle", "BNT_Proxy"); // NOI18N
247
new JButtonOperator(updateCenterWizardOper, buttonProxyConfLabel).pushNoBlock();
248             // Proxy Configuration
249
String JavaDoc proxyConfDialogTitle = Bundle.getString("org.netbeans.modules.autoupdate.Bundle", "CTL_ProxyDialog_Title"); // NOI18N
250
NbDialogOperator proxyDialog = new NbDialogOperator(proxyConfDialogTitle);
251             // Use Proxy check box
252
new JCheckBoxOperator(proxyDialog).setSelected(true);
253             // Proxy Host: text field
254
new JTextFieldOperator(proxyDialog, 0).setText("webcache"); // NOI18N
255
// Proxy Port: text field
256
new JTextFieldOperator(proxyDialog, 1).setText("8080"); // NOI18N
257
proxyDialog.ok();
258             
259             // "Next >"
260
updateCenterWizardOper.btNext().pushNoBlock();
261             // wait connecting dialog appears
262
// "Connecting"
263
String JavaDoc connectingTitle = Bundle.getString("org.netbeans.modules.autoupdate.Bundle", "CTL_Connecting_Title");
264             // wait at most 60 second until connecting dialog dismiss
265
JemmyProperties.setCurrentTimeout("ComponentOperator.WaitStateTimeout", 60000);
266             new NbDialogOperator(connectingTitle).waitClosed();
267             // wait JTree generated on next page
268
new EventTool().waitNoEvent(500);
269             JTreeOperator tree = new JTreeOperator(updateCenterWizardOper);
270             // "Development Update Center
271
String JavaDoc devUCLabel = Bundle.getString("org.netbeans.modules.updatecenters.resources.Bundle", "Services/AutoupdateType/autoupdate_xml_type.settings");
272             
273             //add to the right list only modules that are specified in xml file
274
for(int i = 0; i<dataValues.getModules().size(); i++){
275                 new Node(tree, dataValues.getUcName() + "|" + dataValues.getModules().elementAt(i).toString()).select(); // NOI18N
276
// add to right panel (push button with tooltip "Add")
277
new JButtonOperator(updateCenterWizardOper, new ComponentChooser() {
278             /*HINT_Add=Add
279              *HINT_AddAll=Add All
280              *HINT_Remove=Remove
281              *HINT_RemoveAll=Remove All
282              */

283                     final String JavaDoc addLabel = Bundle.getString("org.netbeans.modules.autoupdate.Bundle", "HINT_Add"); // NOI18N
284
public boolean checkComponent(Component JavaDoc comp) {
285                         String JavaDoc tooltip = ((JComponent JavaDoc)comp).getToolTipText();
286                         if(tooltip != null) {
287                             return tooltip.equals(addLabel);
288                         } else {
289                             return false;
290                         }
291                     }
292                     
293                     public String JavaDoc getDescription() {
294                         return "JButton with tooltip equals "+addLabel;
295                     }
296                 }).push();
297             }
298             // push "Next" button
299
updateCenterWizardOper.btNext().pushNoBlock();
300             // accept license agreement
301
// "License Agreement"
302
String JavaDoc licenceTitle = Bundle.getString("org.netbeans.modules.autoupdate.Bundle", "CTL_Licence_Title");
303             // "Accept"
304
String JavaDoc acceptLabel = Bundle.getString("org.netbeans.modules.autoupdate.Bundle", "CTL_Licence_Accept");
305             new JButtonOperator(new NbDialogOperator(licenceTitle), acceptLabel).push();
306             // wait 30 s until download is done
307
JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 30000); // NOI18N
308
// "Done."
309
String JavaDoc doneLabel = Bundle.getString("org.netbeans.modules.autoupdate.Bundle", "DownloadProgressPanel.jLabel1.doneText");
310             new JLabelOperator(updateCenterWizardOper, doneLabel);
311             updateCenterWizardOper.next();
312             // accept certificate if requested
313
JTableOperator resultsTable = new JTableOperator(updateCenterWizardOper);
314             //select all checkboxes
315
for(int row=0; row < resultsTable.getRowCount(); row++){
316                 //select it only if checkbox is false
317
System.out.println(((Boolean JavaDoc)(resultsTable.getValueAt(row, 0))).booleanValue());
318                 if(((Boolean JavaDoc)(resultsTable.getValueAt(row, 0))).booleanValue()==false){
319                     new Thread JavaDoc(){
320                         public void run(){
321                             try{
322                                 sleep(1000);
323                                 confirmAllModal();
324                             }catch(Exception JavaDoc e){
325                                 e.printStackTrace();
326                             }
327                         }
328                     }.start();
329                     
330                     resultsTable.clickOnCell(row, 0);
331                 }
332             }
333         } catch (JemmyException e) {
334             // close possible error dialog
335
// "Error"
336
String JavaDoc errorTitle = Bundle.getString("org.netbeans.modules.autoupdate.Bundle", "CTL_Error");
337             if(JDialogOperator.findJDialog(errorTitle, true, true) != null) {
338                 new NbDialogOperator(errorTitle).close();
339             }
340             // close Update center dialog
341
if(updateCenterWizardOper != null) {
342                 updateCenterWizardOper.close();
343             }
344             throw e;
345         } finally {
346             // restore default timeout
347
JemmyProperties.setCurrentTimeout("ComponentOperator.WaitStateTimeout", oldWaitStateTime);
348         }
349     }
350     
351     
352     public void testRestart(){
353         //If the updater restarted IDE then do nothing
354
if(tbp.readProperty(TestbagsProperties.LOCAL_SERVER_TESTBAG_RESTARTED_PROPERTY_NAME) == true){
355             //if(isRestarted()){
356
//This is the last executed line of this suite
357
return;
358         }
359         //Otherwise set atribut that going restarting and restart IDE then
360
tbp.writeProperty(TestbagsProperties.LOCAL_SERVER_TESTBAG_RESTARTED_PROPERTY_NAME, true);
361         //setRestarted(true);
362
WizardOperator updateCenterWizardOper = null;
363         updateCenterWizardOper = openUpdateCenterWizard();
364         //updateCenterWizardOper.btCancel().push();
365
System.out.println("pushing finish...");
366         updateCenterWizardOper.btFinish().push();
367         // System.out.println("finish pushed...");
368
}
369     
370     
371     public boolean isRestarted(){
372         return (tbp.readProperty(TestbagsProperties.LOCAL_SERVER_TESTBAG_RESTARTED_PROPERTY_NAME) == true);
373     }
374     public void setRestarted(boolean value){
375         tbp.writeProperty(TestbagsProperties.LOCAL_SERVER_TESTBAG_RESTARTED_PROPERTY_NAME, value);
376     }
377     
378     
379  /* public void testProxyDialogPossibilities() {
380   
381     }
382   
383     public void testAddNewAUType() {
384   
385     }
386   
387     public void testBadAUUrl() {
388   
389     }
390   
391     public void testChangePropagation() {
392   
393     }
394   
395     public void testSecondPanelButtons() {
396   
397     }
398   
399     public void testAcceptLicence() {
400   
401     }
402   
403     public void testSkipDownloadStep() {
404   
405     }
406   
407     public void testIncludeCheckBox() {
408   
409     }
410   
411     public void testSaveCopy() {
412   
413     }
414   
415     public void testSaveCopyWithWrongName() {
416   
417     }
418   
419     public void testUninstallAndInstallAUModule() {
420   
421     }
422   */

423     
424 }
425
Popular Tags