websvc.kit/test/qa-functional/src/org/netbeans/modules/ws/qaf/designer/WebServiceDesignerTest.java
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
6 * The contents of this file are subject to the terms of either the GNU
7 * General Public License Version 2 only ("GPL") or the Common
8 * Development and Distribution License("CDDL") (collectively, the
9 * "License"). You may not use this file except in compliance with the
10 * License. You can obtain a copy of the License at
11 * http://www.netbeans.org/cddl-gplv2.html
12 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13 * specific language governing permissions and limitations under the
14 * License. When distributing the software, include this License Header
15 * Notice in each file and include the License file at
16 * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17 * particular file as subject to the "Classpath" exception as provided
18 * by Sun in the GPL Version 2 section of the License file that
19 * accompanied this code. If applicable, add the following below the
20 * License Header, with the fields enclosed by brackets [] replaced by
21 * your own identifying information:
22 * "Portions Copyrighted [year] [name of copyright owner]"
24 * If you wish your version of this file to be governed by only the CDDL
25 * or only the GPL Version 2, indicate your decision by adding
26 * "[Contributor] elects to include this software in this distribution
27 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28 * single choice of license, a recipient has the option to distribute
29 * your version of this file under either the CDDL, the GPL Version 2 or
30 * to extend the choice of license to its licensees as provided above.
31 * However, if you add GPL Version 2 code and therefore, elected the GPL
32 * Version 2 license, then the option applies only if the new code is
33 * made subject to such option by the copyright holder.
37 * Portions Copyrighted 2008 Sun Microsystems, Inc.
39 package org.netbeans.modules.ws.qaf.designer;
41 import junit.framework.Test;
42 import org.netbeans.jellytools.Bundle;
43 import org.netbeans.jellytools.EditorOperator;
44 import org.netbeans.jellytools.NbDialogOperator;
45 import org.netbeans.jellytools.actions.OpenAction;
46 import org.netbeans.jellytools.actions.SaveAllAction;
47 import org.netbeans.jellytools.nodes.Node;
48 import org.netbeans.jellytools.nodes.SourcePackagesNode;
49 import org.netbeans.jemmy.operators.JTextFieldOperator;
50 import org.netbeans.junit.NbModuleSuite;
51 import org.netbeans.modules.ws.qaf.WebServicesTestBase;
54 * Basic validation suite for web service designer
56 * Duration of this test suite: aprox. 3min
58 * @author lukas.jungmann@sun.com
60 public class WebServiceDesignerTest extends WebServicesTestBase {
62 public WebServiceDesignerTest(String name) {
67 protected String getProjectName() {
68 return getName().indexOf("Ejb") < 0 ? "60_webapp" : "65_ejbmodule"; //NOI18N
71 public void testAddOperation() {
72 addOperation("EmptyWs", 0, false); //NOI18N
75 public void testRemoveOperation() {
76 removeOperation("EmptyWs", 1, false); //NOI18N
79 public void testAddOperation2() {
80 addOperation("SampleWs", 2, false); //NOI18N
83 public void testRemoveOperation2() {
84 removeOperation("SampleWs", 3, false); //NOI18N
87 public void testAddOperationToIntf() {
88 addOperation("WsImpl", 1, true); //NOI18N
91 public void testRemoveOperationFromIntf() {
92 removeOperation("WsImpl", 2, true); //NOI18N
95 public void testEjbAddOperation() {
96 String wsName = "FromWSDL";
98 openFileInEditor(wsName);
99 assertEquals(opCount, WsDesignerUtilities.operationsCount(wsName));
100 WsDesignerUtilities.invokeAddOperation(wsName);
103 } catch (InterruptedException ex) {
107 String actionName = Bundle.getStringTrimmed("org.netbeans.modules.websvc.design.view.actions.Bundle", "TTL_AddWsOperation");
108 NbDialogOperator dialog = new NbDialogOperator(actionName);
109 JTextFieldOperator jtfo = new JTextFieldOperator(dialog, "operation");
111 jtfo.typeText("addedOp");
115 } catch (InterruptedException ex) {
118 // new JTextFieldOperator(dialog, 2).setText("test1"); //NOI18N
119 // new JTextFieldOperator(dialog, 1).setText("String"); //NOI18N
122 public void testEjbRemoveOperation() {
123 String wsName = "FromWSDL";
124 openFileInEditor(wsName);
125 WsDesignerUtilities.invokeRemoveOperation(wsName, "addedOp", false); //NOI18N
126 NbDialogOperator ndo = new NbDialogOperator("Question"); //NOI18N
130 } catch (InterruptedException ex) {
135 public void testGoToSource() {
136 String wsName = "EmptyWs"; //NOI18N
137 String opName = "test1"; //NOI18N
138 openFileInEditor(wsName);
139 WsDesignerUtilities.invokeGoToSource(wsName, opName);
142 } catch (InterruptedException ex) {
145 EditorOperator eo = new EditorOperator(wsName);
146 assertEquals(24, eo.getLineNumber());
147 // see: http://www.netbeans.org/issues/show_bug.cgi?id=150923
148 // wsName = "WsImpl"; //NOI18N
149 // openFileInEditor(wsName);
150 // WsDesignerUtilities.invokeGoToSource(wsName, opName);
152 // Thread.sleep(1000);
153 // } catch (InterruptedException ex) {
156 // eo = new EditorOperator(wsName);
157 // assertEquals(18, eo.getLineNumber());
158 wsName = "SampleWs"; //NOI18N
159 opName = "sayHi"; //NOI18N
160 openFileInEditor(wsName);
161 WsDesignerUtilities.invokeGoToSource(wsName, opName);
164 } catch (InterruptedException ex) {
167 eo = new EditorOperator(wsName);
168 assertEquals(33, eo.getLineNumber());
171 //only sanity test (see if there's no exception)
172 //some checks can be added later
173 public void testOperationButtons() {
174 String wsName = "SampleWs"; //NOI18N
175 WsDesignerUtilities.invokeAdvanced(wsName);
179 } catch (InterruptedException ex) {
182 NbDialogOperator o = new NbDialogOperator(wsName);
184 String opName = "voidOperation"; //NOI18N
185 WsDesignerUtilities.clickOnButton(wsName, opName, 0);
186 WsDesignerUtilities.clickOnButton(wsName, opName, 2);
187 WsDesignerUtilities.clickOnExpander(wsName, opName);
188 WsDesignerUtilities.clickOnExpander(wsName, opName);
189 WsDesignerUtilities.clickOnButton(wsName, opName, 1);
190 opName = "sayHi"; //NOI18N
191 WsDesignerUtilities.clickOnButton(wsName, opName, 1);
192 WsDesignerUtilities.clickOnButton(wsName, opName, 0);
193 WsDesignerUtilities.clickOnExpander(wsName, opName);
194 WsDesignerUtilities.clickOnExpander(wsName, opName);
195 WsDesignerUtilities.clickOnButton(wsName, opName, 0);
196 WsDesignerUtilities.clickOnButton(wsName, opName, 2);
197 WsDesignerUtilities.clickOnButton(wsName, opName, 0);
200 private void addOperation(String wsName, int opCount, boolean hasInterface) {
201 openFileInEditor(wsName);
202 assertEquals(opCount, WsDesignerUtilities.operationsCount(wsName));
203 WsDesignerUtilities.invokeAddOperation(wsName);
205 String actionName = Bundle.getStringTrimmed("org.netbeans.modules.websvc.core.jaxws.actions.Bundle", "LBL_OperationAction");
206 NbDialogOperator dialog = new NbDialogOperator(actionName);
207 new JTextFieldOperator(dialog, "operation").setText("test1"); //NOI18N
208 new JTextFieldOperator(dialog, "java.lang.String").setText("String"); //NOI18N
213 } catch (InterruptedException ex) {
216 new SaveAllAction().performAPI();
217 WsDesignerUtilities.source(wsName);
218 EditorOperator eo = new EditorOperator(wsName);
221 assertFalse(eo.contains("import javax.jws.WebMethod;")); //NOI18N
222 assertFalse(eo.contains("@WebMethod(operationName = \"test1\")")); //NOI18N
223 // see http://www.netbeans.org/issues/show_bug.cgi?id=150896
224 // assertEquals(opCount + 1, WsDesignerUtilities.operationsCount(wsName));
226 assertTrue(eo.contains("import javax.jws.WebMethod;")); //NOI18N
227 assertTrue(eo.contains("@WebMethod(operationName = \"test1\")")); //NOI18N
228 assertEquals(opCount + 1, WsDesignerUtilities.operationsCount(wsName));
230 assertTrue(eo.contains("public String test1() {")); //NOI18N
231 //check ws endpoint interface
233 //XXX-rather should find interface from the source
234 String iName = "EndpointI"; //NOI18N
235 openFileInEditor(iName);
236 EditorOperator eo2 = new EditorOperator(iName);
237 assertTrue(eo2.contains("public String test1();")); //NOI18N
242 private void removeOperation(String wsName, int opCount, boolean hasInterface) {
243 openFileInEditor(wsName);
244 WsDesignerUtilities.invokeRemoveOperation(wsName, "test1", opCount % 2 == 0); //NOI18N
245 NbDialogOperator ndo = new NbDialogOperator("Question"); //NOI18N
247 //see: http://www.netbeans.org/issues/show_bug.cgi?id=150896
249 assertEquals(opCount - 1, WsDesignerUtilities.operationsCount(wsName));
251 new SaveAllAction().performAPI();
252 WsDesignerUtilities.source(wsName);
253 EditorOperator eo = new EditorOperator(wsName);
255 assertFalse(eo.contains("@WebMethod(operationName = \"test1\")")); //NOI18N
257 assertTrue(eo.contains("public String test1() {")); //NOI18N
259 assertFalse(eo.contains("public String test1() {")); //NOI18N
261 //check ws endpoint interface
263 //XXX-rather should find interface from the source
264 String iName = "EndpointI"; //NOI18N
265 openFileInEditor(iName);
266 EditorOperator eo2 = new EditorOperator(iName);
268 assertFalse(eo2.contains("public String test1();")); //NOI18N
273 private void openFileInEditor(String fileName) {
275 //there's some weird bug:
276 //if project with webservices is checked out from VCS (cvs)
277 //and its class is opened in the editor then there's no
278 //web service designer or it is not initialized correctly :(
279 Node wsNode = new Node(getProjectRootNode(), "Web Services");
280 if (wsNode.isCollapsed()) {
284 SourcePackagesNode spn = new SourcePackagesNode(getProjectRootNode());
285 Node n = new Node(spn, "samples|" + fileName); //NOI18N
286 new OpenAction().perform(n);
289 public static Test suite() {
290 return NbModuleSuite.create(addServerTests(Server.GLASSFISH,
291 NbModuleSuite.createConfiguration(WebServiceDesignerTest.class),
292 "testAddOperation", //NOI18N
293 "testAddOperation2", //NOI18N
294 "testAddOperationToIntf", //NOI18N
295 "testOperationButtons", //NOI18N
296 "testGoToSource", //NOI18N
297 "testRemoveOperation", //NOI18N
298 "testRemoveOperation2", //NOI18N
299 "testRemoveOperationFromIntf" //NOI18N
300 // "testEjbAddOperation", //NOI18N
301 // "testEjbRemoveOperation" //NOI18N
302 ).enableModules(".*").clusters(".*")); //NOI18N