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.test.websvcmgr;
043:
044: import org.netbeans.jemmy.operators.*;
045: import org.netbeans.junit.NbTestSuite;
046: import junit.framework.Test;
047:
048: import org.netbeans.modules.visualweb.gravy.dataconnectivity.ServerNavigatorOperator;
049: import org.netbeans.modules.visualweb.gravy.dataconnectivity.ServerExplorerOperator;
050: import org.netbeans.modules.visualweb.gravy.designer.DesignerPaneOperator;
051: import org.netbeans.modules.visualweb.gravy.DocumentOutlineOperator;
052: import org.netbeans.modules.visualweb.gravy.plugins.PluginsOperator;
053: import org.netbeans.modules.visualweb.gravy.actions.FindAction;
054: import org.netbeans.modules.visualweb.gravy.websvc.*;
055: import org.netbeans.modules.visualweb.gravy.RaveWindowOperator;
056: import org.netbeans.modules.visualweb.gravy.TestUtils;
057: import org.netbeans.modules.visualweb.gravy.Util;
058: import org.netbeans.modules.visualweb.gravy.model.project.components.*;
059: import org.netbeans.modules.visualweb.gravy.model.project.*;
060: import org.netbeans.modules.visualweb.gravy.model.components.*;
061: import org.netbeans.modules.visualweb.gravy.model.deployment.*;
062: import org.netbeans.modules.visualweb.gravy.model.*;
063: import org.netbeans.modules.visualweb.gravy.*;
064:
065: import com.meterware.httpunit.*;
066: import java.util.Properties;
067: import java.awt.event.KeyEvent;
068: import java.awt.Point;
069: import java.io.File;
070: import java.io.FileInputStream;
071:
072: /**
073: *
074: * @author Roman Mostyka
075: */
076:
077: public class WebServiceAcceptanceTest extends RaveTestCase {
078:
079: private static String addBindingAttribute = Bundle
080: .getStringTrimmed(
081: "org.netbeans.modules.visualweb.insync.action.Bundle",
082: "LBL_AddBindingAttributeActionName");
083: private static String sep = File.separator;
084: private static String wsPath = "Web Services|";
085: private static String deletePopup = "Delete";
086: private static String reformatPopup = "Format";
087: private static String addToPagePopup = "Add to Page";
088: private static String testMethod = "Test Method";
089: private static String dlgQuestion = "Question";
090: private static String dlgTestMethod = "Test Web Service Method";
091: private static String btnYes = "Yes";
092: private static String btnSubmit = "Submit";
093: private static String _wsProjectName = "AcceptanceWSProject";
094: private static String _projectPath = System
095: .getProperty("xtest.workdir")
096: + sep + "projects" + sep;
097: private static String wsURL = "URL";
098: private static String wsName = "PATH";
099: private static String wsMethod = "METHOD";
100: private static String wsMethodParameter = "PARAMETER";
101: private static String pluginName = "Visual Web JSF Backwards Compatibility Kit";
102: private static String javaCode = "CODE";
103: private static String wsResponse = "RESPONSE";
104: private static String serverType = "GlassFish V2";
105:
106: private static Project prj, J2EE14prj, JavaEE5prj;
107: private static DeploymentTargetDescriptor dtd;
108: private static DeploymentTarget dt;
109: private static ApplicationServer as;
110: private static Properties properties;
111:
112: private ServerNavigatorOperator server;
113: private JTreeOperator sntree;
114:
115: /** constructor required by JUnit
116: * @param testName method name to be used as testcase
117: */
118: public WebServiceAcceptanceTest(String testName) {
119: super (testName);
120: }
121:
122: public static Test suite() {
123: NbTestSuite suite = new NbTestSuite(
124: "Web Service Consumption Acceptance Tests");
125: suite.addTest(new WebServiceAcceptanceTest("testPreparation"));
126: suite
127: .addTest(new WebServiceAcceptanceTest(
128: "testAddWebService"));
129: suite.addTest(new WebServiceAcceptanceTest(
130: "testTestMethodDialog"));
131: suite.addTest(new WebServiceAcceptanceTest(
132: "testAddWebServiceToJ2EE14Project"));
133: suite.addTest(new WebServiceAcceptanceTest(
134: "testDeployJ2EE14Project"));
135: suite.addTest(new WebServiceAcceptanceTest(
136: "testAddWebServiceToJavaEE5Project"));
137: suite.addTest(new WebServiceAcceptanceTest(
138: "testDeployJavaEE5Project"));
139: suite.addTest(new WebServiceAcceptanceTest(
140: "testRemoveWebService"));
141: return suite;
142: }
143:
144: /** method called before each testcase
145: */
146: protected void setUp() {
147: }
148:
149: public void testPreparation() {
150: properties = new Properties();
151: try {
152: properties.load(new FileInputStream(System
153: .getProperty("xtest.ws-properties.file")));
154: } catch (Exception e) {
155: System.out.println("Properties can not be loaded!");
156: System.out.println("e=" + e.toString());
157: return;
158: }
159: PluginsOperator.getInstance().installAvailablePlugins(
160: pluginName);
161: dtd = new DeploymentTargetDescriptor();
162: dtd.load();
163: if (serverType != null)
164: dtd.setProperty(dtd.SERVER_TYPE_KEY, serverType);
165: dt = IDE.getIDE().addDeploymentTarget(dtd);
166: as = (ApplicationServer) dt;
167: as.start();
168: TestUtils.wait(1000);
169: }
170:
171: public void testAddWebService() {
172: server = ServerNavigatorOperator.showNavigatorOperator();
173: server.pushPopup("Web Services", "Add Web Service...");
174: AddWebServiceOperator wsOp = new AddWebServiceOperator();
175: wsOp.addWebService(properties.get(wsURL).toString());
176: TestUtils.wait(2000);
177: }
178:
179: public void testTestMethodDialog() {
180: server = ServerNavigatorOperator.showNavigatorOperator();
181: TestUtils.wait(4000);
182: server.pushPopup(wsPath + properties.get(wsMethod).toString(),
183: testMethod);
184: TestUtils.wait(1000);
185: JDialogOperator jdo = new JDialogOperator(dlgTestMethod);
186: TestUtils.wait(1000);
187: JTableOperator jto1 = new JTableOperator(jdo, 0);
188: TestUtils.wait(1000);
189: jto1.changeCellObject(0, 2, properties.get(wsMethodParameter)
190: .toString());
191: TestUtils.wait(1000);
192: new JButtonOperator(jdo, btnSubmit).push();
193: TestUtils.wait(5000);
194: JTableOperator jto2 = new JTableOperator(jdo, 1);
195: if (jto2.getValueAt(0, 1).toString().indexOf(
196: properties.get(wsResponse).toString()) == -1) {
197: fail("There is no needed string in response!");
198: jdo.close();
199: }
200: jdo.close();
201: }
202:
203: public void testAddWebServiceToJ2EE14Project() {
204: J2EE14prj = createProject(ProjectDescriptor.J2EE14);
205: addComponentToProject(J2EE14prj);
206: addWebServiceToProject();
207: editPrerenderMethod(properties.get(javaCode).toString());
208: }
209:
210: public void testDeployJ2EE14Project() {
211: DeployAndCheckProject(J2EE14prj);
212: verifyHTTP(J2EE14prj, wsResponse);
213: projectUndeployAndClose(J2EE14prj);
214: }
215:
216: public void testAddWebServiceToJavaEE5Project() {
217: JavaEE5prj = createProject(ProjectDescriptor.JavaEE5);
218: addComponentToProject(JavaEE5prj);
219: addWebServiceToProject();
220: editPrerenderMethod(properties.get(javaCode).toString());
221: }
222:
223: public void testDeployJavaEE5Project() {
224: DeployAndCheckProject(JavaEE5prj);
225: verifyHTTP(JavaEE5prj, wsResponse);
226: projectUndeployAndClose(JavaEE5prj);
227: as.stop();
228: }
229:
230: public void testRemoveWebService() {
231: server = ServerNavigatorOperator.showNavigatorOperator();
232: TestUtils.wait(4000);
233: String wsClientPath = properties.get(wsName).toString();
234: String realPath = wsPath
235: + wsClientPath.substring(0, wsClientPath.indexOf("|"));
236: server.pushPopup(realPath, deletePopup);
237: new JButtonOperator(new DialogOperator(dlgQuestion), btnYes)
238: .push();
239: TestUtils.wait(2000);
240: }
241:
242: private Project createProject(String J2EEVersion) {
243: String J2EEVersion_PREF = J2EEVersion.replace(' ', '_')
244: .replace('.', '_');
245: ProjectDescriptor pd = new ProjectDescriptor(_wsProjectName
246: + "_" + J2EEVersion_PREF, _projectPath, J2EEVersion, as
247: .getName());
248: Project prj = IDE.getIDE().createProject(pd);
249: TestUtils.disableBrowser(prj.getName(), true);
250: TestUtils.wait(1000);
251: return prj;
252: }
253:
254: private void addComponentToProject(Project prj) {
255: WebPageFolder wpf = prj.getRoot().getWebPageRootFolder();
256: WebPage wp = wpf.getWebPage("Page1");
257: VisualComponent vcmp = (VisualComponent) wp.add(
258: (WebComponent) IDE.getIDE().getDefaultComponentSet()
259: .getComponent(
260: StaticTextComponent.STATIC_TEXT_ID),
261: new Point(48, 48));
262: addBindingAttribute(wp.getName(), "page1|html1|body1|form1|"
263: + vcmp.getName());
264: }
265:
266: private void addWebServiceToProject() {
267: server = ServerNavigatorOperator.showNavigatorOperator();
268: TestUtils.wait(4000);
269: sntree = server.getTree();
270: server.pushPopup(wsPath + properties.get(wsName).toString(),
271: addToPagePopup);
272: TestUtils.wait(30000);
273: }
274:
275: private void editPrerenderMethod(String code) {
276: DesignerPaneOperator designer = new DesignerPaneOperator(
277: RaveWindowOperator.getDefaultRave());
278: designer.switchToJavaSource();
279: TestUtils.wait(1000);
280: EditorOperator editor = new EditorOperator(RaveWindowOperator
281: .getDefaultRave(), "Page1.java");
282: TestUtils.wait(2000);
283: new FindAction().performShortcut();
284: TestUtils.wait(2000);
285: JComboBoxOperator jcbo = new JComboBoxOperator(editor);
286: TestUtils.wait(500);
287: jcbo.clearText();
288: TestUtils.wait(500);
289: jcbo.enterText("prerender() {");
290: TestUtils.wait(500);
291: jcbo.pressKey(KeyEvent.VK_ESCAPE);
292: TestUtils.wait(500);
293: jcbo.pressKey(KeyEvent.VK_RIGHT);
294: TestUtils.wait(500);
295: editor.setCaretPositionToEndOfLine(editor.getLineNumber());
296: TestUtils.wait(500);
297: editor.pressKey(KeyEvent.VK_ENTER);
298: TestUtils.wait(2000);
299: editor.txtEditorPane().typeText(code);
300: editor.txtEditorPane().clickForPopup();
301: JPopupMenuOperator epm = new JPopupMenuOperator();
302: TestUtils.wait(1000);
303: new JMenuItemOperator(epm, reformatPopup).push();
304: TestUtils.wait(2000);
305: }
306:
307: private void DeployAndCheckProject(Project prj) {
308: Util.getMainWindow().deploy();
309: TestUtils.wait(20000);
310: server = ServerNavigatorOperator.showNavigatorOperator();
311: TestUtils.wait(4000);
312: sntree = server.getTree();
313: server.pushPopup(ServerExplorerOperator.STR_SERVERS_PATH
314: + as.web_applications_path, as.REFRESH);
315: TestUtils.wait(1000);
316: try {
317: sntree.selectPath(sntree
318: .findPath(ServerExplorerOperator.STR_SERVERS_PATH
319: + as.web_applications_path + "|"
320: + as.app_pref + prj.getName()));
321: } catch (Exception e) {
322: fail("There is no " + prj.getName()
323: + " application in Deployed Components node!");
324: }
325: TestUtils.wait(1000);
326: }
327:
328: private void verifyHTTP(Project prj, String verificationString) {
329: try {
330: WebConversation conversation = new WebConversation();
331: WebResponse response = null;
332: System.out.println("requestPrefix=" + as.requestPrefix);
333: response = conversation.getResponse(as.requestPrefix
334: + prj.getName());
335: if (response.getText().indexOf(
336: properties.get(wsResponse).toString()) == -1)
337: fail("There is no needed string in response!");
338: } catch (Exception e) {
339: System.out.println("Exception occured: ");
340: e.printStackTrace();
341: fail("Excetion in HTTP check : " + e);
342: }
343: }
344:
345: private void projectUndeployAndClose(Project prj) {
346: TestUtils.wait(1000);
347: Util.saveAllAPICall();
348: server.pushPopup(ServerExplorerOperator.STR_SERVERS_PATH
349: + as.web_applications_path, as.REFRESH);
350: TestUtils.wait(1000);
351: server.pushPopup(ServerExplorerOperator.STR_SERVERS_PATH
352: + as.web_applications_path + "|" + as.app_pref
353: + prj.getName(), as.APPLICATION_UNDEPLOY);
354: TestUtils.wait(1000);
355: prj.close();
356: TestUtils.wait(1000);
357: }
358:
359: public void addBindingAttribute(String page,
360: String full_component_path) {
361: DocumentOutlineOperator outline = new DocumentOutlineOperator(
362: RaveWindowOperator.getDefaultRave());
363: TestUtils.wait(1000);
364: JTreeOperator aotree = outline.getStructTreeOperator();
365: aotree.callPopupOnPath(aotree.findPath(page + "|"
366: + full_component_path));
367: TestUtils.wait(1000);
368: JPopupMenuOperator aopm = new JPopupMenuOperator();
369: TestUtils.wait(1000);
370: new JMenuItemOperator(aopm, addBindingAttribute).pushNoBlock();
371: TestUtils.wait(1000);
372: }
373: }
|