websvc.kit/test/qa-functional/src/org/netbeans/modules/ws/qaf/EjbWsValidation.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;
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.NewJavaFileNameLocationStepOperator;
46 import org.netbeans.jellytools.modules.java.editor.GenerateCodeOperator;
47 import org.netbeans.jellytools.nodes.Node;
48 import org.netbeans.jemmy.EventTool;
49 import org.netbeans.jemmy.JemmyProperties;
50 import org.netbeans.jemmy.operators.JButtonOperator;
51 import org.netbeans.jemmy.operators.JRadioButtonOperator;
52 import org.netbeans.jemmy.operators.JTreeOperator;
53 import org.netbeans.junit.NbModuleSuite;
54 import org.netbeans.modules.ws.qaf.WebServicesTestBase.ProjectType;
57 * Basic validation suite for web services support in the IDE
59 * Duration of this test suite: aprox. 7min
61 * @author lukas.jungmann@sun.com
63 public class EjbWsValidation extends WsValidation {
65 /** Default constructor.
66 * @param testName name of particular test case
68 public EjbWsValidation(String name) {
73 protected ProjectType getProjectType() {
74 return ProjectType.EJB;
78 protected String getWsProjectName() {
79 return "WsInEjb"; //NOI18N
83 protected String getWsClientProjectName() {
84 return "WsClientInEjb"; //NOI18N
88 protected String getWsName() {
89 return "MyEjbWs"; //NOI18N
93 protected String getWsPackage() {
94 return "o.n.m.ws.qaf.ws.ejb"; //NOI18N
98 protected String getWsURL() {
99 String suffix = "?wsdl"; //NOI18N
100 if (REGISTERED_SERVER.equals(ServerType.GLASSFISH)) {
101 suffix = "?Tester"; //NOI18N
103 return "http://localhost:8080/" + getWsName() + "Service" + "/" + getWsName() + suffix; //NOI18N
107 protected String getWsClientPackage() {
108 return getWsPackage(); //NOI18N
111 public static Test suite() {
112 return NbModuleSuite.create(addServerTests(Server.GLASSFISH,
113 NbModuleSuite.createConfiguration(EjbWsValidation.class),
120 "testDeployWsProject",
122 "testCreateWsClient",
123 "testRefreshClientAndReplaceWSDL",
124 "testCallWsOperationInSessionEJB",
125 "testCallWsOperationInJavaClass",
126 "testWsFromEJBinClientProject",
127 "testWsClientHandlers",
128 "testDeployWsClientProject",
129 "testUndeployProjects",
130 "testStopServer").enableModules(".*").clusters(".*"));
133 public void testWsFromEJBinClientProject() {
134 String wsName = "WsFromEJB"; //NOI18N
136 String webServiceLabel = Bundle.getStringTrimmed("org.netbeans.modules.websvc.core.dev.wizard.Bundle", "Templates/WebServices/WebService.java");
137 createNewWSFile(getProject(), webServiceLabel);
138 NewJavaFileNameLocationStepOperator op = new NewJavaFileNameLocationStepOperator();
139 op.setObjectName(wsName);
140 op.setPackage(getWsPackage());
141 JRadioButtonOperator jrbo = new JRadioButtonOperator(op, 1);
142 jrbo.setSelected(true);
143 new JButtonOperator(op, 0).pushNoBlock();
144 //Browse Enterprise Bean
145 String browseEjbDlgTitle = Bundle.getStringTrimmed("org.netbeans.modules.websvc.core.dev.wizard.Bundle", "LBL_BrowseBean_Title");
146 NbDialogOperator ndo = new NbDialogOperator(browseEjbDlgTitle);
147 JTreeOperator jto = new JTreeOperator(ndo);
149 String ejbNodeLabel = Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbjar.project.ui.Bundle", "LBL_node");
150 Node ejbsNode = new Node(jto, getProjectName() + "|" + ejbNodeLabel);
152 new Node(ejbsNode, "NewSession").select();
155 JemmyProperties.setCurrentTimeout("JTreeOperator.WaitNextNodeTimeout", 60000); //NOI18N
156 Node wsRootNode = new Node(getProjectRootNode(), WEB_SERVICES_NODE_NAME);
158 Node wsNode = new Node(wsRootNode, wsName); //NOI18N
160 JemmyProperties.setCurrentTimeout("JTreeOperator.WaitNextNodeTimeout", 60000); //NOI18N
161 new Node(wsNode, "myBm"); //NOI18N
162 assertEquals("Only one operation should be there", 1, wsNode.getChildren().length);
163 EditorOperator eo = new EditorOperator(wsName);
164 assertTrue(eo.contains("@Stateless"));
165 assertTrue(eo.contains("@EJB"));
166 assertTrue(eo.contains("ejbRef"));
167 assertTrue(eo.contains("@WebMethod"));
168 assertTrue(eo.contains("myBm"));
172 * Tests Call Web Service Operation action in a servlet
174 public void testCallWsOperationInSessionEJB() {
175 assertServerRunning();
176 //create a session bean
177 String ejbName = "NewSession";
179 String enterpriseLabel = Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.resources.Bundle", "Templates/J2EE");
181 String sessionBeanLabel = Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ejb.wizard.session.Bundle", "Templates/J2EE/Session");
182 createNewFile(getWsClientProject(), enterpriseLabel, sessionBeanLabel);
183 NewJavaFileNameLocationStepOperator op = new NewJavaFileNameLocationStepOperator();
184 op.txtObjectName().clearText();
185 op.txtObjectName().typeText(ejbName);
186 op.cboPackage().clearText();
187 op.cboPackage().typeText("org.mycompany.ejbs"); //NOI18N
189 new EventTool().waitNoEvent(2000);
190 //Add business method
191 final EditorOperator eo = new EditorOperator(ejbName); //NOI18N
192 addBusinessMethod(eo, "myBm", "String"); //NOI18N
193 //edit code in the EJB
194 // add new line and select it
195 eo.setCaretPosition("myBm() {", false); //NOI18N
196 eo.insert("\n//xxx"); //NOI18N
197 eo.select("//xxx"); //NOI18N
198 callWsOperation(eo, "myIntMethod", eo.getLineNumber()); //NOI18N
199 assertTrue("@WebServiceRef has not been found", eo.contains("@WebServiceRef")); //NOI18N
200 assertFalse("Lookup present", eo.contains(getWsClientLookupCall()));
204 protected void addBusinessMethod(EditorOperator eo, String mName, String mRetVal) {
205 //Add Business Method...
206 String actionName = Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.action.Bundle", "LBL_AddBusinessMethodAction");
207 eo.setCaretPosition(16, 1);
208 GenerateCodeOperator.openDialog(actionName, eo);
209 addMethod(eo, actionName, mName, mRetVal);