KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gui > updatecenterwizard > UpdateCenterWizardTests


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.CatalogXMLFileParser;
24 import java.awt.Container JavaDoc;
25 import java.io.File JavaDoc;
26 import java.io.FileInputStream JavaDoc;
27 import javax.swing.JDialog JavaDoc;
28 import org.netbeans.jellytools.Bundle;
29 import org.netbeans.jellytools.JellyTestCase;
30 import org.netbeans.jellytools.WizardOperator;
31 import org.netbeans.jellytools.actions.Action;
32 import org.netbeans.jemmy.ComponentSearcher;
33 import org.netbeans.jemmy.JemmyException;
34 import org.netbeans.jemmy.operators.ContainerOperator;
35 import org.netbeans.jemmy.operators.JButtonOperator;
36 import org.netbeans.jemmy.operators.JDialogOperator;
37 import org.netbeans.jemmy.operators.JTableOperator;
38
39 /**
40  *
41  * @author Lukas.Hasik@Sun.Com, Jaromir.Uhrik@Sun.Com
42  */

43
44 public class UpdateCenterWizardTests extends JellyTestCase {
45     
46     public String JavaDoc WORKDIR_PROPERTY="work.dir";
47     public String JavaDoc WORKDIR_DEFAULT="C:\\TEMP";
48     
49     /** Creates a new instance of UpdateCenterWizardTests */
50     public UpdateCenterWizardTests(String JavaDoc name) {
51         super(name);
52         
53     }
54     
55     /* opens Update Center wizard from main menu Tools | Update Center
56      */

57     public WizardOperator openUpdateCenterWizard() throws JemmyException {
58         // "Tools"
59
String JavaDoc toolsItem = Bundle.getStringTrimmed("org.netbeans.core.Bundle", "Menu/Tools"); // NOI18N
60
WizardOperator updateCenterWizardOper = null;
61         String JavaDoc updateCenterItem = Bundle.getStringTrimmed("org.netbeans.modules.autoupdate.Bundle", "CTL_Update");
62         new Action(toolsItem+"|"+updateCenterItem, null).perform();
63         // "Update Center Wizard"
64
String JavaDoc updateCenterTitle = Bundle.getString("org.netbeans.modules.autoupdate.Bundle", "CTL_Wizard");
65         updateCenterWizardOper = new WizardOperator(updateCenterTitle);
66         
67         return updateCenterWizardOper;
68     }
69     
70     
71     public CatalogDataValues readDataValues(String JavaDoc file){
72         CatalogDataValues values = null;
73         try{
74             CatalogXMLFileParser xfp = new CatalogXMLFileParser();
75             javax.xml.parsers.SAXParserFactory JavaDoc saxParserFactory = javax.xml.parsers.SAXParserFactory.newInstance();
76             javax.xml.parsers.SAXParser JavaDoc saxParser = saxParserFactory.newSAXParser();
77             org.xml.sax.XMLReader JavaDoc parser = saxParser.getXMLReader();
78             parser.setContentHandler(xfp);
79             //String parsePath = "E:/ide001/autoupdatebuild\test\qa-functional\datasettings\local_settings.xml";
80
//parser.parse( new org.xml.sax.InputSource( new FileInputStream(getDataDir() + "settings" + File.separator + file) ));
81
parser.parse( new org.xml.sax.InputSource JavaDoc( new FileInputStream JavaDoc(getDataDir() + File.separator + "settings" + File.separator + file) ));
82             xfp.getData().printValues();
83             values = xfp.getData();
84         }catch(Exception JavaDoc e){
85             e.printStackTrace();
86         }
87         return values;
88     }
89     
90     public void setAUtypeSelected(String JavaDoc name, boolean selected){
91         WizardOperator ucWizard = openUpdateCenterWizard();
92         JTableOperator serversTable=new JTableOperator(ucWizard);
93         for(int row = 0; row<serversTable.getRowCount(); row++){
94             if(((String JavaDoc)(serversTable.getValueAt(row, 1))).equals(name)){
95                 serversTable.setValueAt(new Boolean JavaDoc(selected), row, 1);
96             }
97         }
98     }
99     public void setAllAUtypesSelected(boolean selected){
100         WizardOperator ucWizard = openUpdateCenterWizard();
101         JTableOperator serversTable=new JTableOperator(ucWizard);
102         for(int row = 0; row<serversTable.getRowCount(); row++){
103             serversTable.setValueAt(new Boolean JavaDoc(selected), row, 1);
104         }
105     }
106     public void setAUtypeSelected(int row, boolean selected){
107         WizardOperator ucWizard = openUpdateCenterWizard();
108         JTableOperator serversTable=new JTableOperator(ucWizard);
109         serversTable.setValueAt(new Boolean JavaDoc(selected), row, 1);
110     }
111     public String JavaDoc getAUtypeName(int row){
112         WizardOperator ucWizard = openUpdateCenterWizard();
113         JTableOperator serversTable=new JTableOperator(ucWizard);
114         String JavaDoc name = (String JavaDoc)(serversTable.getValueAt(row, 1));
115         return name;
116     }
117     /**The function for the test if the AUtype is selected
118      *@param row -the UC type index in the table (the first row has index 0)
119      */

120     public boolean isAUtypeSelected(int row){
121         WizardOperator ucWizard = openUpdateCenterWizard();
122         JTableOperator serversTable=new JTableOperator(ucWizard);
123         Boolean JavaDoc b = (Boolean JavaDoc)(serversTable.getValueAt(row, 0));
124         return b.booleanValue();
125     }
126     
127     public void selectAllAsSigned(){
128         
129         JTableOperator resultsTable = new JTableOperator(openUpdateCenterWizard());
130         for(int row=0; row < resultsTable.getRowCount(); row++){
131             /*doWait(1000);
132             resultsTable.changeSelection(row, col, false, false);*/

133             resultsTable.setValueAt(new Boolean JavaDoc(true), row, 0);
134             
135             /*
136             if(((Boolean)resultsTable.getValueAt(row, col)).booleanValue()== false){
137                 stopper stp = new stopper();
138                 stp.start();
139                 JamDialog cert_dialog = new JamDialog("Module Certificate");
140                 clickButton(cert_dialog, "Always Accept");
141             }*/

142         }
143     }
144     public int indexOfButton(String JavaDoc name, JDialogOperator dialog){
145         int current_index=0;
146         String JavaDoc button_string;
147         JButtonOperator button_operator=new JButtonOperator(dialog);
148         while(button_operator.findJButton(dialog.getContainer(ComponentSearcher.getTrueChooser("")),ComponentSearcher.getTrueChooser(""),current_index)!=null) {
149             button_string = new JButtonOperator(dialog, current_index).toString();
150             if(button_string.indexOf(name)!=-1){
151                 return current_index;
152             }
153             current_index++;
154         }
155         return -1;
156     }
157     public void scloseAllModal() {
158         JDialogOperator oper = null;
159         // find some JDialog
160
JDialog JavaDoc jDialog = JDialogOperator.findJDialog(ComponentSearcher.getTrueChooser(""));
161         // number of opened non-modal
162
int nonModal = 0;
163         // until any modal dialog is opened
164
while(jDialog!=null) {
165             oper = new JDialogOperator(jDialog);
166             if(oper.isModal()) {
167                 // close if modal
168
oper.close();
169             } else {
170                 // increment nonModal
171
nonModal++;
172             }
173             // use nonModal variable as index to skip opened non-modal dialogs
174
jDialog = JDialogOperator.findJDialog(ComponentSearcher.getTrueChooser(""), nonModal);
175         }
176     }
177     
178     public void confirmAllModal() {
179         JDialogOperator oper = null;
180         // find some JDialog
181
JDialog JavaDoc jDialog = JDialogOperator.findJDialog(ComponentSearcher.getTrueChooser(""));
182         // number of opened non-modal
183
int nonModal = 0;
184         // until any modal dialog is opened
185
while(jDialog!=null) {
186             oper = new JDialogOperator(jDialog);
187             if(oper.isModal()) {
188                 String JavaDoc unsignedModuleString = Bundle.getString("org.netbeans.modules.autoupdate.Bundle", "CTL_NotSignedConfirmation");
189                 String JavaDoc moduleCertificateString = Bundle.getString("org.netbeans.modules.autoupdate.Bundle", "CTL_Certificate_Title");
190                 
191                 //press Yes button on "Unsigned Module" dialog
192
if(oper.getTitle().indexOf(unsignedModuleString) != -1){
193                     new JButtonOperator(oper, "Yes").push();
194                 }else{
195                     //press Accept button on "Module Certificate" dialog
196
if (oper.getTitle().indexOf(moduleCertificateString) != -1){
197                         new JButtonOperator(oper, "Accept").push();
198                     }else{
199                         //other modal dialog just close
200
oper.close();
201                     }
202                 }
203                 
204                 
205             } else {
206                 // increment nonModal
207
nonModal++;
208             }
209             // use nonModal variable as index to skip opened non-modal dialogs
210
jDialog = JDialogOperator.findJDialog(ComponentSearcher.getTrueChooser(""), nonModal);
211         }
212     }
213     
214     public void sleep(int millis){
215         try{
216             new Thread JavaDoc().sleep(millis);
217         }catch(Exception JavaDoc e){
218             e.printStackTrace();
219         }
220     }
221 }
222
Popular Tags