visualweb.websvcmgr/test/qa-functional/src/org/netbeans/test/websvcmgr/WebServiceAcceptanceTest.java
Really making tests compilable.
2 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
6 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7 * Other names may be trademarks of their respective owners.
9 * The contents of this file are subject to the terms of either the GNU
10 * General Public License Version 2 only ("GPL") or the Common
11 * Development and Distribution License("CDDL") (collectively, the
12 * "License"). You may not use this file except in compliance with the
13 * License. You can obtain a copy of the License at
14 * http://www.netbeans.org/cddl-gplv2.html
15 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16 * specific language governing permissions and limitations under the
17 * License. When distributing the software, include this License Header
18 * Notice in each file and include the License file at
19 * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
20 * particular file as subject to the "Classpath" exception as provided
21 * by Oracle in the GPL Version 2 section of the License file that
22 * accompanied this code. If applicable, add the following below the
23 * License Header, with the fields enclosed by brackets [] replaced by
24 * your own identifying information:
25 * "Portions Copyrighted [year] [name of copyright owner]"
29 * The Original Software is NetBeans. The Initial Developer of the Original
30 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
31 * Microsystems, Inc. All Rights Reserved.
33 * If you wish your version of this file to be governed by only the CDDL
34 * or only the GPL Version 2, indicate your decision by adding
35 * "[Contributor] elects to include this software in this distribution
36 * under the [CDDL or GPL Version 2] license." If you do not indicate a
37 * single choice of license, a recipient has the option to distribute
38 * your version of this file under either the CDDL, the GPL Version 2 or
39 * to extend the choice of license to its licensees as provided above.
40 * However, if you add GPL Version 2 code and therefore, elected the GPL
41 * Version 2 license, then the option applies only if the new code is
42 * made subject to such option by the copyright holder.
45 package org.netbeans.test.websvcmgr;
47 import com.meterware.httpunit.WebConversation;
48 import com.meterware.httpunit.WebResponse;
49 import org.netbeans.jemmy.operators.*;
50 import org.netbeans.junit.NbTestSuite;
51 import junit.framework.Test;
53 import org.netbeans.modules.visualweb.gravy.dataconnectivity.ServerNavigatorOperator;
54 import org.netbeans.modules.visualweb.gravy.dataconnectivity.ServerExplorerOperator;
55 import org.netbeans.modules.visualweb.gravy.designer.DesignerPaneOperator;
56 import org.netbeans.modules.visualweb.gravy.plugins.PluginsOperator;
57 import org.netbeans.modules.visualweb.gravy.actions.FindAction;
58 import org.netbeans.modules.visualweb.gravy.websvc.*;
59 import org.netbeans.modules.visualweb.gravy.model.project.components.*;
60 import org.netbeans.modules.visualweb.gravy.model.project.*;
61 import org.netbeans.modules.visualweb.gravy.model.components.*;
62 import org.netbeans.modules.visualweb.gravy.model.deployment.*;
63 import org.netbeans.modules.visualweb.gravy.model.*;
64 import org.netbeans.modules.visualweb.gravy.*;
66 import java.util.Properties;
67 import java.awt.event.KeyEvent;
68 import java.awt.Point;
70 import java.io.FileInputStream;
74 * @author Roman Mostyka
77 public class WebServiceAcceptanceTest extends RaveTestCase {
79 private static String addBindingAttribute = Bundle.getStringTrimmed("org.netbeans.modules.visualweb.insync.action.Bundle","LBL_AddBindingAttributeActionName");
80 private static String sep = File.separator;
81 private static String wsPath = "Web Services|";
82 private static String deletePopup = "Delete";
83 private static String reformatPopup = "Format";
84 private static String addToPagePopup = "Add to Page";
85 private static String menuCopy = "Edit|Copy";
86 private static String menuPaste = "Edit|Paste";
87 private static String testMethod = "Test Method";
88 private static String dlgQuestion = "Question";
89 private static String dlgTestMethod = "Test Web Service Method";
90 private static String btnYes = "Yes";
91 private static String btnSubmit = "Submit";
92 private static String _wsProjectName = "AcceptanceWSProject";
93 private static String _projectPath = System.getProperty("xtest.workdir") + sep + "projects" + sep;
94 private static String wsURL = "URL";
95 private static String wsName = "PATH";
96 private static String wsMethod = "METHOD";
97 private static String wsMethodParameter = "PARAMETER";
98 private static String pluginName = "Visual Web JSF Backwards Compatibility Kit";
99 private static String javaCode = "CODE";
100 private static String wsResponse = "RESPONSE";
101 private static String serverType = "GlassFish V2";
103 private static Project prj, J2EE14prj, JavaEE5prj;
104 private static DeploymentTargetDescriptor dtd;
105 private static DeploymentTarget dt;
106 private static ApplicationServer as;
107 private static Properties properties;
109 private ServerNavigatorOperator server;
110 private JTreeOperator sntree;
112 /** constructor required by JUnit
113 * @param testName method name to be used as testcase
115 public WebServiceAcceptanceTest(String testName) {
119 public static Test suite() {
120 NbTestSuite suite = new NbTestSuite("Web Service Consumption Acceptance Tests");
121 suite.addTest(new WebServiceAcceptanceTest("testPreparation"));
122 suite.addTest(new WebServiceAcceptanceTest("testAddWebService"));
123 suite.addTest(new WebServiceAcceptanceTest("testTestMethodDialog"));
124 suite.addTest(new WebServiceAcceptanceTest("testAddWebServiceToJ2EE14Project"));
125 suite.addTest(new WebServiceAcceptanceTest("testDeployJ2EE14Project"));
126 suite.addTest(new WebServiceAcceptanceTest("testAddWebServiceToJavaEE5Project"));
127 suite.addTest(new WebServiceAcceptanceTest("testDeployJavaEE5Project"));
128 suite.addTest(new WebServiceAcceptanceTest("testRemoveWebService"));
132 /** method called before each testcase
134 protected void setUp() {
137 public void testPreparation() {
138 properties = new Properties();
140 properties.load(new FileInputStream(System.getProperty("xtest.ws-properties.file")));
141 } catch(Exception e) {
142 System.out.println("Properties can not be loaded!");
143 System.out.println("e=" + e.toString());
146 PluginsOperator.getInstance().installAvailablePlugins(pluginName);
147 dtd = new DeploymentTargetDescriptor();
149 if (serverType != null) dtd.setProperty(dtd.SERVER_TYPE_KEY, serverType);
150 dt = IDE.getIDE().addDeploymentTarget(dtd);
151 as = (ApplicationServer) dt;
153 TestUtils.wait(1000);
156 public void testAddWebService() {
157 server = ServerNavigatorOperator.showNavigatorOperator();
158 server.pushPopup("Web Services", "Add Web Service...");
159 AddWebServiceOperator wsOp = new AddWebServiceOperator();
160 wsOp.addWebService(properties.get(wsURL).toString());
161 TestUtils.wait(2000);
164 public void testTestMethodDialog(){
165 server = ServerNavigatorOperator.showNavigatorOperator();
166 TestUtils.wait(4000);
167 server.pushPopup(wsPath + properties.get(wsMethod).toString(), testMethod);
168 TestUtils.wait(1000);
169 JDialogOperator jdo = new JDialogOperator(dlgTestMethod);
170 TestUtils.wait(1000);
171 JTableOperator jto1 = new JTableOperator(jdo, 0);
172 TestUtils.wait(1000);
173 jto1.changeCellObject(0, 2, properties.get(wsMethodParameter).toString());
174 TestUtils.wait(1000);
175 new JButtonOperator(jdo, btnSubmit).push();
176 TestUtils.wait(10000);
177 JTableOperator jto2 = new JTableOperator(jdo, 1);
178 if (jto2.getValueAt(0, 1).toString().indexOf(properties.get(wsResponse).toString()) == -1) {
179 fail("There is no needed string in response!");
185 public void testAddWebServiceToJ2EE14Project() {
186 J2EE14prj = createProject(ProjectDescriptor.J2EE14);
187 addComponentToProject(J2EE14prj);
188 addWebServiceToProject();
189 editPrerenderMethod(properties.get(javaCode).toString());
192 public void testDeployJ2EE14Project() {
193 DeployAndCheckProject(J2EE14prj);
194 verifyHTTP(J2EE14prj, wsResponse);
195 projectUndeployAndClose(J2EE14prj);
198 public void testAddWebServiceToJavaEE5Project() {
199 JavaEE5prj = createProject(ProjectDescriptor.JavaEE5);
200 addComponentToProject(JavaEE5prj);
201 addWebServiceToProject();
202 editPrerenderMethod(properties.get(javaCode).toString());
205 public void testDeployJavaEE5Project() {
206 DeployAndCheckProject(JavaEE5prj);
207 verifyHTTP(JavaEE5prj, wsResponse);
208 projectUndeployAndClose(JavaEE5prj);
212 public void testRemoveWebService() {
213 server = ServerNavigatorOperator.showNavigatorOperator();
214 TestUtils.wait(4000);
215 String wsClientPath = properties.get(wsName).toString();
216 String realPath = wsPath +
217 wsClientPath.substring(0, wsClientPath.indexOf("|"));
218 server.pushPopup(realPath, deletePopup);
219 new JButtonOperator(new DialogOperator(dlgQuestion), btnYes).push();
220 TestUtils.wait(2000);
223 private Project createProject(String J2EEVersion) {
224 String J2EEVersion_PREF = J2EEVersion.replace(' ', '_').replace('.', '_');
225 ProjectDescriptor pd = new ProjectDescriptor(_wsProjectName + "_" + J2EEVersion_PREF, _projectPath, J2EEVersion, as.getName());
226 Project prj = IDE.getIDE().createProject(pd);
227 TestUtils.disableBrowser(prj.getName(), true);
228 TestUtils.wait(1000);
232 private void addComponentToProject(Project prj) {
233 WebPageFolder wpf = prj.getRoot().getWebPageRootFolder();
234 WebPage wp = wpf.getWebPage("Page1");
235 VisualComponent vcmp = (VisualComponent)
236 wp.add((WebComponent)
237 IDE.getIDE().getDefaultComponentSet().getComponent(StaticTextComponent.STATIC_TEXT_ID),
239 addBindingAttribute(wp.getName(), "page1|html1|body1|form1|" + vcmp.getName());
242 private void addWebServiceToProject() {
243 server = ServerNavigatorOperator.showNavigatorOperator();
244 TestUtils.wait(4000);
245 sntree = server.getTree();
246 server.selectPath(wsPath + properties.get(wsName).toString());
247 Util.getMainMenu().pushMenu(menuCopy);
248 WebPageFolder wpf = prj.getRoot().getWebPageRootFolder();
249 WebPage wp = wpf.getWebPage("Page1");
251 TestUtils.wait(1000);
252 Util.getMainMenu().pushMenu(menuPaste);
253 TestUtils.wait(30000);
256 private void editPrerenderMethod(String code) {
257 DesignerPaneOperator designer = new DesignerPaneOperator(RaveWindowOperator.getDefaultRave());
258 designer.switchToJavaSource();
259 TestUtils.wait(1000);
260 EditorOperator editor = new EditorOperator(RaveWindowOperator.getDefaultRave(), "Page1.java");
261 TestUtils.wait(2000);
262 new FindAction().performShortcut();
263 TestUtils.wait(2000);
264 JComboBoxOperator jcbo = new JComboBoxOperator(editor);
268 jcbo.enterText("prerender() {");
270 jcbo.pressKey(KeyEvent.VK_ESCAPE);
272 jcbo.pressKey(KeyEvent.VK_RIGHT);
274 editor.setCaretPositionToEndOfLine(editor.getLineNumber());
276 editor.pressKey(KeyEvent.VK_ENTER);
277 TestUtils.wait(2000);
278 editor.txtEditorPane().typeText(code);
279 editor.txtEditorPane().clickForPopup();
280 JPopupMenuOperator epm = new JPopupMenuOperator();
281 TestUtils.wait(1000);
282 new JMenuItemOperator(epm, reformatPopup).push();
283 TestUtils.wait(2000);
286 private void DeployAndCheckProject(Project prj) {
287 Util.getMainWindow().deploy();
288 TestUtils.wait(20000);
289 server = ServerNavigatorOperator.showNavigatorOperator();
290 TestUtils.wait(4000);
291 sntree = server.getTree();
292 server.pushPopup(ServerExplorerOperator.STR_SERVERS_PATH + as.web_applications_path, as.REFRESH);
293 TestUtils.wait(1000);
295 sntree.selectPath(sntree.findPath(ServerExplorerOperator.STR_SERVERS_PATH + as.web_applications_path + "|" + as.app_pref + prj.getName()));
297 catch (Exception e) {
298 fail("There is no " + prj.getName() + " application in Deployed Components node!");
300 TestUtils.wait(1000);
303 private void verifyHTTP(Project prj, String verificationString) {
305 WebConversation conversation = new WebConversation();
306 WebResponse response = null;
307 System.out.println("requestPrefix=" + as.requestPrefix);
308 response = conversation.getResponse(as.requestPrefix + prj.getName());
309 if (response.getText().indexOf(properties.get(wsResponse).toString()) == -1) fail("There is no needed string in response!");
310 } catch (Exception e) {
311 System.out.println("Exception occured: ");
313 fail("Excetion in HTTP check : " + e);
317 private void projectUndeployAndClose(Project prj) {
318 TestUtils.wait(1000);
319 Util.saveAllAPICall();
320 server.pushPopup(ServerExplorerOperator.STR_SERVERS_PATH + as.web_applications_path, as.REFRESH);
321 TestUtils.wait(1000);
322 server.pushPopup(ServerExplorerOperator.STR_SERVERS_PATH + as.web_applications_path + "|" + as.app_pref + prj.getName(), as.APPLICATION_UNDEPLOY);
323 TestUtils.wait(1000);
325 TestUtils.wait(1000);
328 public void addBindingAttribute(String page, String full_component_path) {
329 DocumentOutlineOperator outline = new DocumentOutlineOperator(RaveWindowOperator.getDefaultRave());
330 TestUtils.wait(1000);
331 JTreeOperator aotree = outline.getStructTreeOperator();
332 aotree.callPopupOnPath(aotree.findPath(page + "|" + full_component_path));
333 TestUtils.wait(1000);
334 JPopupMenuOperator aopm = new JPopupMenuOperator();
335 TestUtils.wait(1000);
336 new JMenuItemOperator(aopm, addBindingAttribute).pushNoBlock();
337 TestUtils.wait(1000);