001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.visualweb.gravy.websvc;
043:
044: import org.netbeans.jellytools.NbDialogOperator;
045: import org.netbeans.jemmy.operators.*;
046: import org.netbeans.modules.visualweb.gravy.TestUtils;
047: import org.netbeans.modules.visualweb.gravy.Util;
048:
049: /**
050: * AddWebServiceOperator class
051: * Implements test functionality for "Add Web Service" dialog
052: *
053: * @author <a href="mailto:alexey.butenko@sun.com">Alexey Butenko</a>
054: */
055: public class AddWebServiceOperator extends NbDialogOperator {
056:
057: private JRadioButtonOperator _rbtURL;
058: private JRadioButtonOperator _rbtLocal;
059: private JButtonOperator _btBrowse;
060: //private JButtonOperator _btGetWSInf;
061: private JButtonOperator _btSetProxy;
062: private JButtonOperator _btAdd;
063: private JButtonOperator _btCancel;
064: private JButtonOperator _btHelp;
065: private JTextFieldOperator _txtURL;
066: private JTextFieldOperator _txtLocal;
067: //private JTextFieldOperator _txtWSName;
068: private JTextFieldOperator _txtWSPackageName;
069: private boolean _isProxySet = false;
070: private String STR_BROWSE = "Browse...";
071: private String STR_PROXY = "Set Proxy...";
072: private String STR_ADD = "Add";
073: private String STR_CANCEL = "Cancel";
074: private String STR_HELP = "Help";
075: private String STR_OPEN = "Open";
076: private String STR_OK = "OK";
077: private String STR_OPTIONS = "Options";
078: private String STR_FILE = "Local File:";
079: private String STR_URL = "WSDL URL:";
080: private String STR_SYSTEM_PROXY = "Use System Proxy Settings";
081: private String STR_MANUAL_PROXY = "Manual Proxy Settings";
082: private String wsLabel = "Services tab web services compiling script";
083:
084: //private JTextComponentOperator _txtResults;
085:
086: public AddWebServiceOperator() {
087: super ("Add Web Service");
088: }
089:
090: public JRadioButtonOperator rbtURL() {
091: if (_rbtURL == null) {
092: _rbtURL = new JRadioButtonOperator(this , STR_URL);
093: }
094: return _rbtURL;
095: }
096:
097: public JRadioButtonOperator rbtLocal() {
098: if (_rbtLocal == null) {
099: _rbtLocal = new JRadioButtonOperator(this , STR_FILE);
100: }
101: return _rbtLocal;
102: }
103:
104: public JButtonOperator btBrowse() {
105: if (_btBrowse == null) {
106: _btBrowse = new JButtonOperator(this , STR_BROWSE);
107: }
108: return _btBrowse;
109: }
110:
111: /*public JButtonOperator btGetWSInf() {
112: if (_btGetWSInf == null) {
113: _btGetWSInf = new JButtonOperator(this, "Get Web Service Information");
114: }
115: return _btGetWSInf;
116: }*/
117:
118: public JButtonOperator btSetProxy() {
119: if (_btSetProxy == null) {
120: _btSetProxy = new JButtonOperator(this , STR_PROXY);
121:
122: }
123: return _btSetProxy;
124: }
125:
126: public JButtonOperator btAdd() {
127: if (_btAdd == null) {
128: _btAdd = new JButtonOperator(this , STR_ADD);
129: }
130: return _btAdd;
131: }
132:
133: public JButtonOperator btCancel() {
134: if (_btCancel == null) {
135: _btCancel = new JButtonOperator(this , STR_CANCEL);
136: }
137: return _btCancel;
138: }
139:
140: public JButtonOperator btHelp() {
141: if (_btHelp == null) {
142: _btHelp = new JButtonOperator(this , STR_HELP);
143: }
144: return _btHelp;
145: }
146:
147: public JTextFieldOperator txtURL() {
148: if (_txtURL == null) {
149: _txtURL = new JTextFieldOperator(this , 2);
150: }
151: return _txtURL;
152: }
153:
154: public JTextFieldOperator txtLocal() {
155: if (_txtLocal == null) {
156: _txtLocal = new JTextFieldOperator(this , 1);
157: }
158: return _txtLocal;
159: }
160:
161: /*public JTextFieldOperator txtWSName() {
162: if (_txtWSName == null) {
163: //System.out.println("TRACE: "+new JTextFieldOperator(this, 0).getText());
164: //System.out.println("TRACE: "+new JTextFieldOperator(this, 1).getText());
165: //System.out.println("TRACE: "+new JTextFieldOperator(this, 2).getText());
166: //System.out.println("TRACE: "+new JTextFieldOperator(this, 3).getText());
167: //System.out.println("TRACE: "+new JTextFieldOperator(this, 4).getText());
168: //_txtWSName = new JTextFieldOperator(this, 4);
169: try{
170: _txtWSName = new JTextFieldOperator(this, 6);
171: }catch(Exception e){
172: _txtWSName = null;
173: }
174: }
175: return _txtWSName;
176: }*/
177:
178: public JTextFieldOperator txtWSPackageName() {
179: if (_txtWSPackageName == null) {
180: _txtWSPackageName = new JTextFieldOperator(this , 0);
181: }
182: return _txtWSPackageName;
183: }
184:
185: /*public JTextComponentOperator txtResults() {
186: if (_txtResults == null) {
187: //_txtResults = new JTextComponentOperator(this,9);
188: _txtResults = new JTextComponentOperator(this,8);
189: }
190: return _txtResults;
191: }*/
192:
193: public boolean isProxySet() {
194: return _isProxySet;
195: }
196:
197: public void verify() {
198: btAdd();
199: btCancel();
200: btHelp();
201: //btGetWSInf();
202: btBrowse();
203: btSetProxy();
204: rbtLocal();
205: rbtURL();
206: txtLocal();
207: txtURL();
208: //txtWSName();
209: txtWSPackageName();
210: //txtResults();
211: }
212:
213: public String addLocalWebService(String name) {
214: JRadioButtonOperator wsType = rbtLocal();
215: wsType.requestFocus();
216: wsType.setSelected(true);
217: wsType.doClick();
218: TestUtils.wait(2000);
219: /*btBrowse().pushNoBlock();
220: TestUtils.wait(2000);
221: JDialogOperator open = new JDialogOperator(STR_OPEN);
222: JTextFieldOperator wsdlFileName = new JTextFieldOperator(open, 0);
223: wsdlFileName.typeText(name);
224: TestUtils.wait(1000);
225: new JButtonOperator(open, STR_OPEN).pushNoBlock();*/
226: JTextFieldOperator wsdlUrl = txtLocal();
227: wsdlUrl.clearText();
228: wsdlUrl.setText(name);
229: TestUtils.wait(1000);
230: //TODO hardcoded?
231: //if ((new JTextComponentOperator(this, 2)).getText().indexOf("error occurred")!= -1) return null;
232: //String wsName = "empty";
233: //JTextFieldOperator wsNameOper = txtWSName();
234: //if (wsNameOper!=null ) {wsName = wsNameOper.getText();}
235: // btAdd().pushNoBlock();
236: btAdd().pushNoBlock();
237: isWebServiceClientGenerated();
238: //return wsName;
239: return null;
240: }
241:
242: public String addWebService(String url) {
243: JRadioButtonOperator wsType = rbtURL();
244: wsType.requestFocus();
245: wsType.setSelected(true);
246: wsType.doClick();
247: TestUtils.wait(2000);
248: JTextFieldOperator wsdlUrl = txtURL();
249: wsdlUrl.clearText();
250: wsdlUrl.setText(url);
251: TestUtils.wait(1000);
252: //wsdlUrl.pushKey(KeyEvent.VK_ENTER);
253: //wsdlUrl.pushKey(KeyEvent.VK_ENTER);
254: //TestUtils.wait(6000);
255: //TODO hardcoded?
256: //if ((new JTextComponentOperator(this, 2)).getText().indexOf("error occurred")!= -1) return null;
257: //String wsName = "empty";
258: //JTextFieldOperator wsNameOper = txtWSName();
259: //if (wsNameOper!=null ) {wsName = wsNameOper.getText();}
260: // btAdd().pushNoBlock();
261: btAdd().pushNoBlock();
262: ;
263: isWebServiceClientGenerated();
264: //return wsName;
265: return null;
266: }
267:
268: public void setProxy(String proxyHost, String proxyPort) {
269: if (isProxySet())
270: clearProxy();
271: btSetProxy().pushNoBlock();
272: //JDialogOperator proxyConfig = new JDialogOperator("Proxy Configuration");
273: JDialogOperator proxyConfig = new JDialogOperator(STR_OPTIONS);
274: //JCheckBoxOperator proxyCb = new JCheckBoxOperator(proxyConfig);
275: TestUtils.wait(1000);
276: JRadioButtonOperator proxyRb = new JRadioButtonOperator(
277: proxyConfig, STR_MANUAL_PROXY);
278: proxyRb.requestFocus();
279: proxyRb.setSelected(true);
280: proxyRb.doClick();
281: //proxyCb.requestFocus();
282: //proxyCb.setSelected(true);
283: // proxyCb.doClick();
284: _isProxySet = true;
285: TestUtils.wait(2000);
286: new JTextFieldOperator(proxyConfig, 0).setText(proxyHost);
287: TestUtils.wait(1000);
288: new JTextFieldOperator(proxyConfig, 1).setText(proxyPort);
289: TestUtils.wait(1000);
290: new JButtonOperator(proxyConfig, STR_OK).pushNoBlock();
291: }
292:
293: public void clearProxy() {
294: if (isProxySet()) {
295: btSetProxy().pushNoBlock();
296: //JDialogOperator proxyConfig = new JDialogOperator("Proxy Configuration");
297: JDialogOperator proxyConfig = new JDialogOperator(
298: STR_OPTIONS);
299: //JCheckBoxOperator proxyCb = new JCheckBoxOperator(proxyConfig);
300: TestUtils.wait(1000);
301: JRadioButtonOperator proxyRb = new JRadioButtonOperator(
302: proxyConfig, STR_SYSTEM_PROXY);
303: //proxyCb.requestFocus();
304: //proxyCb.setSelected(false);
305: //proxyCb.doClick();
306: proxyRb.requestFocus();
307: proxyRb.setSelected(true);
308: proxyRb.doClick();
309: _isProxySet = false;
310: TestUtils.wait(1000);
311: new JButtonOperator(proxyConfig, STR_OK).pushNoBlock();
312: }
313: }
314:
315: private boolean isWebServiceClientGenerated() {
316: TestUtils.wait(500);
317: JLabelOperator jlo = new JLabelOperator(Util.getMainWindow(), 1);
318: while (jlo.getText() == null
319: || jlo.getText().indexOf(wsLabel) == -1) {
320: jlo = new JLabelOperator(Util.getMainWindow(), 1);
321: System.out.println("label in first cycle = "
322: + jlo.getText());
323: TestUtils.wait(1000);
324: }
325: while (jlo.getText() != null
326: && jlo.getText().indexOf(wsLabel) != -1) {
327: jlo = new JLabelOperator(Util.getMainWindow(), 1);
328: TestUtils.wait(1000);
329: }
330: TestUtils.wait(1000);
331: return true;
332: }
333: }
|