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.deployment.generic;
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.designer.DesignerPaneOperator;
050: import org.netbeans.modules.visualweb.gravy.plugins.PluginsOperator;
051: import org.netbeans.modules.visualweb.gravy.DocumentOutlineOperator;
052: import org.netbeans.modules.visualweb.gravy.RaveWindowOperator;
053: import org.netbeans.modules.visualweb.gravy.RaveTestCase;
054: import org.netbeans.modules.visualweb.gravy.TestUtils;
055: import org.netbeans.modules.visualweb.gravy.Util;
056: import org.netbeans.modules.visualweb.gravy.model.project.components.*;
057: import org.netbeans.modules.visualweb.gravy.model.project.*;
058: import org.netbeans.modules.visualweb.gravy.model.components.*;
059: import org.netbeans.modules.visualweb.gravy.model.deployment.*;
060: import org.netbeans.modules.visualweb.gravy.model.*;
061:
062: import com.meterware.httpunit.*;
063: import java.util.Iterator;
064: import java.util.List;
065: import java.awt.Point;
066: import java.io.File;
067:
068: /**
069: *
070: * @author Roman Mostyka
071: */
072:
073: public class DeploymentAcceptanceTest extends RaveTestCase {
074:
075: public final static String btn_OK = "OK";
076: public final static String btn_Yes = "Yes";
077: public final static String btn_Add = "Add";
078: public final static String dlg_bindDB = "Bind to Data";
079: public final static String dbPath = "Databases|";
080: public final static String wsPath = "Web Services|";
081: public final static String dbConnect = "Connect";
082: public final static String dbDisconnect = "Disconnect";
083: public final static String testDBName = "jdbc:derby://localhost:1527/sample [app on APP]";
084: public final static String bindDBPopup = "Bind to Data...";
085: public final static String deleteResPopup = "Delete Resource";
086: public final static String deletePopup = "Delete";
087: public final static String reformatePopup = "Format";
088: public final static String dlg_ConfirmDeletion = "Confirm Object Deletion";
089: public final static String dlg_addWS = "Add Web Service";
090: public final static String popup_addWS = "Add Web Service...";
091: public final static String addToPagePopup = "Add to Page";
092: public final static String bindToDP = "Bind to Data Provider";
093: public static String _simpleProjectName = "SimpleProject";
094: public static String _simpleJavaEE5ProjectName = "SimpleJavaEE5Project";
095: public static String _dbProjectName = "DBProject";
096: public static String _wsProjectName = "WSProject";
097: public static String _firstProjectName = "FirstProject";
098: public static String _testProjectName = "TestProject";
099: public static String _projectPath = System
100: .getProperty("xtest.workdir")
101: + File.separator + "projects" + File.separator;
102: public static String serverFullPath = "";
103: public static String path_to_applications = "";
104: public static String wsURL = "http://www.webservicex.net/usweather.asmx?WSDL";
105: public static String wsName = "USWeather|USWeatherSoap";
106: public static String wsLabel = "Services tab web services compiling script";
107: public static String pluginName = "Visual Web JSF Backwards Compatibility Kit";
108: private ServerNavigatorOperator server;
109: private JTreeOperator sntree, aotree;
110: private DesignerPaneOperator designer;
111: private DocumentOutlineOperator outline;
112: private static ProjectDescriptor pd;
113: private static Project prj;
114: private static WebPageFolder wpf;
115: private static WebPage wp;
116: private static DeploymentTargetDescriptor dtd;
117: private static DeploymentTarget dt;
118: private static ApplicationServer as;
119: public static String serverType = null;
120: static String AS_PREF;
121:
122: /** constructor required by JUnit
123: * @param testName method name to be used as testcase
124: */
125: public DeploymentAcceptanceTest(String testName) {
126: super (testName);
127: }
128:
129: public static Test suite() {
130: NbTestSuite suite = new NbTestSuite(
131: "Deployment Acceptance Tests");
132: suite.addTest(new DeploymentAcceptanceTest(
133: "testOpenServerContextMenu"));
134: suite.addTest(new DeploymentAcceptanceTest(
135: "testDeploySimpleProject"));
136: suite.addTest(new DeploymentAcceptanceTest(
137: "testRedeploySimpleProject"));
138: suite.addTest(new DeploymentAcceptanceTest(
139: "testOpenApplicationContextMenu"));
140: suite.addTest(new DeploymentAcceptanceTest(
141: "testUndeployApplication"));
142: suite.addTest(new DeploymentAcceptanceTest(
143: "testDeploySimpleJavaEE5Project"));
144: suite.addTest(new DeploymentAcceptanceTest(
145: "testDeployDBProject"));
146: suite.addTest(new DeploymentAcceptanceTest(
147: "testRedeployDBProject"));
148: return suite;
149: }
150:
151: /** method called before each testcase
152: */
153: protected void setUp() {
154: }
155:
156: public void testOpenServerContextMenu() {
157: PluginsOperator.getInstance().installAvailablePlugins(
158: pluginName);
159: TestUtils.wait(1000);
160: dtd = new DeploymentTargetDescriptor();
161: dtd.load();
162: if (serverType != null)
163: dtd.setProperty(dtd.SERVER_TYPE_KEY, serverType);
164: dt = IDE.getIDE().addDeploymentTarget(dtd);
165: as = (ApplicationServer) dt;
166: AS_PREF = as.getName().replace(' ', '_').replace('.', '_');
167: String serverName = dt.getName();
168: String serverType = dt.getDescriptor().getProperty(
169: dt.getDescriptor().SERVER_TYPE_KEY);
170: as.start();
171: TestUtils.wait(1000);
172: path_to_applications = server.STR_SERVERS_PATH
173: + as.web_applications_path;
174: server = ServerNavigatorOperator.showNavigatorOperator();
175: TestUtils.wait(4000);
176: sntree = server.getTree();
177: serverFullPath = server.STR_SERVERS_PATH + serverName;
178: sntree.callPopupOnPath(sntree.findPath(serverFullPath));
179: TestUtils.wait(1000);
180: JPopupMenuOperator snpm = new JPopupMenuOperator();
181: TestUtils.wait(1000);
182: for (int i = 0; i < as.server_popup.length; i++) {
183: try {
184: new JMenuItemOperator(snpm, as.server_popup[i][0]);
185: } catch (Exception e) {
186: fail("\"" + as.server_popup[i][0] + "\" is not exist!");
187: }
188: }
189: server = ServerNavigatorOperator.showNavigatorOperator();
190: TestUtils.wait(1000);
191: sntree = server.getTree();
192: sntree.selectPath(sntree.findPath(serverFullPath));
193: TestUtils.wait(1000);
194: }
195:
196: public void testDeploySimpleProject() {
197: pd = new ProjectDescriptor(AS_PREF + "_" + _simpleProjectName,
198: _projectPath, ProjectDescriptor.J2EE14, dt.getName());
199: prj = IDE.getIDE().createProject(pd);
200: prj.run();
201: server = ServerNavigatorOperator.showNavigatorOperator();
202: TestUtils.wait(4000);
203: sntree = server.getTree();
204: if (as.getName().indexOf("WebLogic") == -1) {
205: sntree.selectPath(sntree.findPath(path_to_applications));
206: TestUtils.wait(1000);
207: server.pushPopup(sntree, path_to_applications,
208: ((ApplicationServer) dt).REFRESH);
209: TestUtils.wait(1000);
210: try {
211: sntree.selectPath(sntree.findPath(path_to_applications
212: + "|" + as.app_pref + AS_PREF + "_"
213: + _simpleProjectName));
214: } catch (Exception e) {
215: fail("There is no SimpleProject application in Deployed Components node!");
216: }
217: TestUtils.wait(1000);
218: }
219: try {
220: WebConversation conversation = new WebConversation();
221: WebResponse response = null;
222: System.out.println("requestPrefix=" + as.requestPrefix);
223: response = conversation.getResponse(as.requestPrefix
224: + AS_PREF + "_" + _simpleProjectName);
225: } catch (Exception e) {
226: System.out.println("Exception occured: ");
227: e.printStackTrace();
228: fail("Excetion in HTTP check : " + e);
229: }
230: TestUtils.wait(5000);
231: }
232:
233: public void testRedeploySimpleProject() {
234: prj.run();
235: server = ServerNavigatorOperator.showNavigatorOperator();
236: TestUtils.wait(4000);
237: sntree = server.getTree();
238: server.pushPopup(sntree, serverFullPath, as.REFRESH);
239: TestUtils.wait(1000);
240: if (as.getName().indexOf("WebLogic") == -1) {
241: try {
242: sntree.selectPath(sntree.findPath(path_to_applications
243: + "|" + as.app_pref + AS_PREF + "_"
244: + _simpleProjectName));
245: } catch (Exception e) {
246: fail("There is no SimpleProject application in Deployed Components node!");
247: }
248: TestUtils.wait(1000);
249: }
250: try {
251: WebConversation conversation = new WebConversation();
252: WebResponse response = null;
253: System.out.println("requestPrefix=" + as.requestPrefix);
254: response = conversation.getResponse(as.requestPrefix
255: + AS_PREF + "_" + _simpleProjectName);
256: } catch (Exception e) {
257: System.out.println("Exception occured: ");
258: e.printStackTrace();
259: fail("Excetion in HTTP check : " + e);
260: }
261: TestUtils.wait(5000);
262: }
263:
264: public void testOpenApplicationContextMenu() {
265: server = ServerNavigatorOperator.showNavigatorOperator();
266: TestUtils.wait(4000);
267: sntree = server.getTree();
268: sntree.callPopupOnPath(sntree.findPath(path_to_applications
269: + "|" + as.app_pref + AS_PREF + "_"
270: + _simpleProjectName));
271: TestUtils.wait(1000);
272: JPopupMenuOperator snpm = new JPopupMenuOperator();
273: TestUtils.wait(1000);
274: ApplicationServer as = (ApplicationServer) dt;
275: TestUtils.wait(1000);
276: for (int i = 0; i < as.application_popup.length; i++) {
277: try {
278: new JMenuItemOperator(snpm, as.application_popup[i]);
279: } catch (Exception e) {
280: fail("\"" + as.application_popup[i]
281: + "\" is not exist!");
282: }
283: }
284: server = ServerNavigatorOperator.showNavigatorOperator();
285: TestUtils.wait(1000);
286: sntree = server.getTree();
287: sntree.selectPath(sntree.findPath(serverFullPath));
288: }
289:
290: public void testUndeployApplication() {
291: server = ServerNavigatorOperator.showNavigatorOperator();
292: TestUtils.wait(4000);
293: sntree = server.getTree();
294: server.pushPopup(path_to_applications + "|" + as.app_pref
295: + AS_PREF + "_" + _simpleProjectName,
296: as.APPLICATION_UNDEPLOY);
297: TestUtils.wait(10000);
298: try {
299: sntree.selectPath(sntree.findPath(path_to_applications
300: + "|" + as.app_pref + AS_PREF + "_"
301: + _simpleProjectName));
302: fail("SimpleProject application is still in Deployed Components!");
303: } catch (Exception e) {
304: }
305: try {
306: WebConversation conversation = new WebConversation();
307: WebResponse response = null;
308: System.out.println("requestPrefix=" + as.requestPrefix);
309: response = conversation.getResponse(as.requestPrefix
310: + AS_PREF + "_" + _simpleProjectName);
311: if (response.getText().indexOf("HTTP Status 404") == -1)
312: fail("SimpleProject application is not undeployed!");
313: } catch (Exception e) {
314: } finally {
315: finishProject(prj, false, true);
316: }
317: }
318:
319: public void testDeploySimpleJavaEE5Project() {
320: pd = new ProjectDescriptor(AS_PREF + "_"
321: + _simpleJavaEE5ProjectName, _projectPath,
322: ProjectDescriptor.JavaEE5, dt.getName());
323: prj = IDE.getIDE().createProject(pd);
324: prj.run();
325: server = ServerNavigatorOperator.showNavigatorOperator();
326: TestUtils.wait(4000);
327: sntree = server.getTree();
328: sntree.selectPath(sntree.findPath(path_to_applications));
329: TestUtils.wait(1000);
330: server.pushPopup(sntree, path_to_applications,
331: ((ApplicationServer) dt).REFRESH);
332: TestUtils.wait(1000);
333: try {
334: server = ServerNavigatorOperator.showNavigatorOperator();
335: TestUtils.wait(1000);
336: sntree = server.getTree();
337: sntree.selectPath(sntree.findPath(path_to_applications
338: + "|" + as.app_pref + AS_PREF + "_"
339: + _simpleJavaEE5ProjectName));
340: } catch (Exception e) {
341: fail("There is no SimpleProject application in Deployed Components node!");
342: }
343: TestUtils.wait(1000);
344: try {
345: WebConversation conversation = new WebConversation();
346: WebResponse response = null;
347: System.out.println("requestPrefix=" + as.requestPrefix);
348: response = conversation.getResponse(as.requestPrefix
349: + AS_PREF + "_" + _simpleJavaEE5ProjectName);
350: } catch (Exception e) {
351: System.out.println("Exception occured: ");
352: e.printStackTrace();
353: fail("Excetion in HTTP check : " + e);
354: } finally {
355: finishProject(prj, true, true);
356: }
357: }
358:
359: public void testDeployDBProject() {
360: pd = new ProjectDescriptor(AS_PREF + "_" + _dbProjectName,
361: _projectPath, ProjectDescriptor.J2EE14, dt.getName());
362: prj = IDE.getIDE().createProject(pd);
363: TestUtils.disableBrowser(AS_PREF + "_" + _dbProjectName, true);
364: TestUtils.wait(1000);
365: WebPageFolder wpf = prj.getRoot().getWebPageRootFolder();
366: WebPage wp = wpf.getWebPage("Page1");
367: VisualComponent vcmp = (VisualComponent) wp.add(
368: (WebComponent) IDE.getIDE().getDefaultComponentSet()
369: .getComponent(TableComponent.TABLE_ID),
370: new Point(48, 48));
371: connectToDB(testDBName);
372: TestUtils.wait(500);
373: designer = new DesignerPaneOperator(RaveWindowOperator
374: .getDefaultRave());
375: TestUtils.wait(1000);
376: server = ServerNavigatorOperator.showNavigatorOperator();
377: TestUtils.wait(4000);
378: sntree = server.getTree();
379: sntree.selectPath(sntree.findPath(dbPath + testDBName
380: + "|Tables|CUSTOMER"));
381: designer.requestFocus();
382: designer.clickMouse(50, 50, 1);
383: TestUtils.wait(2000);
384: prj.run();
385: server = ServerNavigatorOperator.showNavigatorOperator();
386: TestUtils.wait(4000);
387: sntree = server.getTree();
388: server.pushPopup(sntree, serverFullPath, as.REFRESH);
389: TestUtils.wait(1000);
390: if (as.getName().indexOf("WebLogic") == -1) {
391: try {
392: sntree.selectPath(sntree.findPath(path_to_applications
393: + "|" + as.app_pref + AS_PREF + "_"
394: + _dbProjectName));
395: } catch (Exception e) {
396: fail("There is no DBProject application in Deployed Components node!");
397: }
398: TestUtils.wait(1000);
399: try {
400: WebConversation conversation = new WebConversation();
401: WebResponse response = null;
402: System.out.println("requestPrefix=" + as.requestPrefix);
403: response = conversation.getResponse(as.requestPrefix
404: + AS_PREF + "_" + _dbProjectName);
405: } catch (Exception e) {
406: System.out.println("Exception occured: ");
407: e.printStackTrace();
408: fail("Excetion in HTTP check : " + e);
409: }
410: TestUtils.wait(1000);
411: }
412: server.pushPopup(sntree, serverFullPath, as.REFRESH);
413: TestUtils.wait(1000);
414: }
415:
416: public void testRedeployDBProject() {
417: WebPageFolder wpf = prj.getRoot().getWebPageRootFolder();
418: WebPage wp = wpf.getWebPage("Page1");
419: deleteComponentFromPage(wp.getName(),
420: "page1|html1|body1|form1|table1");
421: deleteComponentFromPage(wp.getName(), "customerDataProvider");
422: deleteComponentFromPage("SessionBean1", "customerRowSet");
423: TestUtils.wait(1000);
424: prj.run();
425: server = ServerNavigatorOperator.showNavigatorOperator();
426: TestUtils.wait(4000);
427: sntree = server.getTree();
428: server.pushPopup(sntree, serverFullPath, as.REFRESH);
429: TestUtils.wait(1000);
430: if (as.getName().indexOf("WebLogic") == -1) {
431: try {
432: sntree.selectPath(sntree.findPath(path_to_applications
433: + "|" + as.app_pref + AS_PREF + "_"
434: + _dbProjectName));
435: } catch (Exception e) {
436: fail("There is no DBProject application in Deployed Components node!");
437: }
438: TestUtils.wait(1000);
439: }
440: try {
441: WebConversation conversation = new WebConversation();
442: WebResponse response = null;
443: System.out.println("requestPrefix=" + as.requestPrefix);
444: response = conversation.getResponse(as.requestPrefix
445: + AS_PREF + "_" + _dbProjectName);
446: } catch (Exception e) {
447: System.out.println("Exception occured: ");
448: e.printStackTrace();
449: fail("Excetion in HTTP check : " + e);
450: } finally {
451: finishProject(prj, true, true);
452: disconnectFromDB(testDBName);
453: TestUtils.wait(1000);
454: stopDB();
455: TestUtils.wait(1000);
456: as.stop();
457: }
458: }
459:
460: public static void startDB() {
461: try {
462: Util.getMainMenu().pushMenu(
463: "Tools|Java DB Database|Start Server");
464: } catch (Exception e) {
465: System.out
466: .println("Exception by attempt to call \"Tools|Java DB Database|Start Server\"");
467: }
468: TestUtils.wait(2000);
469: }
470:
471: public static void stopDB() {
472: try {
473: Util.getMainMenu().pushMenu(
474: "Tools|Java DB Database|Stop Server");
475: } catch (Exception e) {
476: System.out
477: .println("Exception by attempt to call \"Tools|Java DB Database|Stop Server\"");
478: }
479: TestUtils.wait(2000);
480: }
481:
482: public static void connectToDB(String dbName) {
483: ServerNavigatorOperator serverOperator = ServerNavigatorOperator
484: .showNavigatorOperator();
485: TestUtils.wait(4000);
486: JTreeOperator sotree = serverOperator.getTree();
487: serverOperator.pushPopup(sotree, dbPath + dbName, dbConnect);
488: TestUtils.wait(5000);
489: }
490:
491: public static void disconnectFromDB(String dbName) {
492: ServerNavigatorOperator serverOperator = ServerNavigatorOperator
493: .showNavigatorOperator();
494: TestUtils.wait(4000);
495: JTreeOperator sotree = serverOperator.getTree();
496: serverOperator.pushPopup(sotree, dbPath + dbName, dbDisconnect);
497: TestUtils.wait(2000);
498: }
499:
500: public static void finishProject(Project project, boolean undeploy,
501: boolean close) {
502: ApplicationServer as = null;
503: String asName = project.getDescriptor().getProperty(
504: ProjectDescriptor.SERVER_KEY);
505: List asList = IDE.getIDE().getDeploymentTargets();
506: Iterator asIterator = asList.iterator();
507: while (asIterator.hasNext()) {
508: as = (ApplicationServer) asIterator.next();
509: if (asName != null && as.getName().equals(asName))
510: break;
511: }
512: if (as != null && as.getName().indexOf("WebLogic") == -1
513: && undeploy) {
514: ServerNavigatorOperator serverOperator = ServerNavigatorOperator
515: .showNavigatorOperator();
516: TestUtils.wait(4000);
517: JTreeOperator sntree = serverOperator.getTree();
518: serverOperator.pushPopup(serverOperator.STR_SERVERS_PATH
519: + as.web_applications_path, as.REFRESH);
520: TestUtils.wait(1000);
521: serverOperator.pushPopup(serverOperator.STR_SERVERS_PATH
522: + as.web_applications_path + "|"
523: + project.getName(), as.APPLICATION_UNDEPLOY);
524: TestUtils.wait(3000);
525: }
526: Util.saveAllAPICall();
527: TestUtils.wait(1000);
528: if (close)
529: project.close();
530: TestUtils.wait(2000);
531: }
532:
533: public void deleteComponentFromPage(String page,
534: String full_component_path) {
535: outline = new DocumentOutlineOperator(RaveWindowOperator
536: .getDefaultRave());
537: TestUtils.wait(1000);
538: aotree = outline.getStructTreeOperator();
539: aotree.callPopupOnPath(aotree.findPath(page + "|"
540: + full_component_path));
541: TestUtils.wait(1000);
542: JPopupMenuOperator aopm = new JPopupMenuOperator();
543: TestUtils.wait(1000);
544: new JMenuItemOperator(aopm, deletePopup).pushNoBlock();
545: TestUtils.wait(1000);
546: new JButtonOperator(new JDialogOperator(dlg_ConfirmDeletion),
547: btn_Yes).push();
548: TestUtils.wait(1000);
549: }
550: }
|