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.RaveWindowOperator;
052: import org.netbeans.modules.visualweb.gravy.RaveTestCase;
053: import org.netbeans.modules.visualweb.gravy.TestUtils;
054: import org.netbeans.modules.visualweb.gravy.Util;
055: import org.netbeans.modules.visualweb.gravy.model.IDE;
056: import org.netbeans.modules.visualweb.gravy.model.components.DropDownListComponent;
057: import org.netbeans.modules.visualweb.gravy.model.components.TableComponent;
058: import org.netbeans.modules.visualweb.gravy.model.components.WebComponent;
059: import org.netbeans.modules.visualweb.gravy.model.deployment.ApplicationServer;
060: import org.netbeans.modules.visualweb.gravy.model.deployment.DeploymentTarget;
061: import org.netbeans.modules.visualweb.gravy.model.deployment.DeploymentTargetDescriptor;
062: import org.netbeans.modules.visualweb.gravy.model.project.Project;
063: import org.netbeans.modules.visualweb.gravy.model.project.ProjectDescriptor;
064: import org.netbeans.modules.visualweb.gravy.model.project.WebPage;
065: import org.netbeans.modules.visualweb.gravy.model.project.WebPageFolder;
066: import org.netbeans.modules.visualweb.gravy.model.project.components.VisualComponent;
067: import org.netbeans.modules.visualweb.gravy.model.project.components.VisualEventHandlingComponent;
068:
069: import com.meterware.httpunit.*;
070: import java.awt.*;
071:
072: /**
073: *
074: * @author Roman Mostyka
075: */
076:
077: public class OtherDeploymentTest extends RaveTestCase {
078:
079: private static String dlg_addNewDataProvider = "Add New Data Provider";
080: private static int projectNumber = 1;
081: private ServerNavigatorOperator server;
082: private JTreeOperator sntree;
083: private DesignerPaneOperator designer;
084: private DeploymentAcceptanceTest dat;
085: private static DeploymentTargetDescriptor dtd;
086: private static DeploymentTarget dt;
087: private static ApplicationServer as;
088: public static String serverType = null;
089: static String AS_PREF;
090:
091: /** constructor required by JUnit
092: * @param testName method name to be used as testcase
093: */
094: public OtherDeploymentTest(String testName) {
095: super (testName);
096: }
097:
098: public static Test suite() {
099: NbTestSuite suite = new NbTestSuite("Other Deployment Tests");
100: suite.addTest(new OtherDeploymentTest(
101: "testRestartIDEandDeploy_2"));
102: suite.addTest(new OtherDeploymentTest(
103: "testStopStartASandDeploy"));
104: suite.addTest(new OtherDeploymentTest(
105: "testStopStartDBandDeploy"));
106: suite.addTest(new OtherDeploymentTest("testStopASandDeploy"));
107: suite.addTest(new OtherDeploymentTest("testStopDBandDeploy"));
108: suite.addTest(new OtherDeploymentTest("testChangeDSandDeploy"));
109: return suite;
110: }
111:
112: /** method called before each testcase
113: */
114: protected void setUp() {
115: }
116:
117: public void testRestartIDEandDeploy_2() {
118: PluginsOperator.getInstance().installAvailablePlugins(
119: dat.pluginName);
120: dtd = new DeploymentTargetDescriptor();
121: dtd.load();
122: if (serverType != null)
123: dtd.setProperty(dtd.SERVER_TYPE_KEY, serverType);
124: dt = IDE.getIDE().addDeploymentTarget(dtd);
125: as = (ApplicationServer) dt;
126: AS_PREF = as.getName().replace(' ', '_').replace('.', '_');
127: dat.startDB();
128: TestUtils.wait(1000);
129: dat.connectToDB(dat.testDBName);
130: TestUtils.wait(1000);
131: as.start();
132: TestUtils.wait(1000);
133: dat.path_to_applications = server.STR_SERVERS_PATH
134: + as.web_applications_path;
135: if (as.getName().indexOf("WebLogic") == -1) {
136: Project prj = null;
137: try {
138: prj = IDE.getIDE().openProject(
139: dat._projectPath + AS_PREF + "_"
140: + dat._testProjectName + projectNumber);
141: } catch (Exception e) {
142: new JButtonOperator(
143: new JDialogOperator("Open Project"), "Cancel")
144: .push();
145: fail("There is no specified project!");
146: }
147: TestUtils.wait(5000);
148: System.out.println("Project " + AS_PREF + "_"
149: + dat._testProjectName + projectNumber
150: + " is opened.");
151: prj.run();
152: try {
153: WebConversation conversation = new WebConversation();
154: WebResponse response = null;
155: System.out.println("requestPrefix=" + as.requestPrefix);
156: response = conversation.getResponse(as.requestPrefix
157: + AS_PREF + "_" + dat._testProjectName
158: + projectNumber);
159: if (response.getText().indexOf("JumboCom") == -1) {
160: server.pushPopup(dat.path_to_applications + "|"
161: + as.app_pref + AS_PREF + "_"
162: + dat._testProjectName + projectNumber,
163: as.APPLICATION_UNDEPLOY);
164: TestUtils.wait(1000);
165: prj.close();
166: fail("Application doesn't contain right data!");
167: }
168: } catch (Exception e) {
169: System.out.println("Exception occured: ");
170: e.printStackTrace();
171: fail("Excetion in HTTP check : " + e);
172: } finally {
173: dat.finishProject(prj, true, true);
174: }
175: WebPageFolder wpf = prj.getRoot().getWebPageRootFolder();
176: WebPage wp = wpf.getWebPage("Page1");
177: wp.open();
178: VisualEventHandlingComponent vehcmp = (VisualEventHandlingComponent) wp
179: .add(
180: (WebComponent) IDE
181: .getIDE()
182: .getDefaultComponentSet()
183: .getComponent(
184: DropDownListComponent.DROP_DOWN_LIST_ID),
185: new Point(48, 96));
186: server = ServerNavigatorOperator.showNavigatorOperator();
187: TestUtils.wait(4000);
188: sntree = server.getTree();
189: sntree.selectPath(sntree.findPath(dat.dbPath
190: + dat.testDBName + "|Tables|CUSTOMER"));
191: TestUtils.wait(1000);
192: designer = new DesignerPaneOperator(RaveWindowOperator
193: .getDefaultRave());
194:
195: //workaround
196: // --- start ---
197: new Thread(new Runnable() {
198: public void run() {
199: designer.clickMouse(50, 100, 1);
200: }
201: }).start();
202: // --- stop ---
203:
204: TestUtils.wait(3000);
205: new JButtonOperator(new JDialogOperator(
206: dlg_addNewDataProvider), dat.btn_OK).pushNoBlock();
207: TestUtils.wait(1000);
208: designer.requestFocus();
209: designer.clickForPopup(50, 100);
210: JPopupMenuOperator popup = new JPopupMenuOperator();
211: popup.pushMenuNoBlock(dat.bindDBPopup);
212: JDialogOperator dataBind = new JDialogOperator(
213: dat.dlg_bindDB);
214: new JTabbedPaneOperator(dataBind).selectPage(dat.bindToDP);
215: TestUtils.wait(1000);
216: JListOperator valueList = new JListOperator(dataBind, 0);
217: TestUtils.wait(1000);
218: valueList.selectItem("CUSTOMER.CUSTOMER_ID");
219: TestUtils.wait(1000);
220: JListOperator displayList = new JListOperator(dataBind, 1);
221: TestUtils.wait(1000);
222: displayList.selectItem("CUSTOMER.CITY");
223: TestUtils.wait(1000);
224: new JButtonOperator(dataBind, dat.btn_OK).pushNoBlock();
225: TestUtils.wait(1000);
226: prj.run();
227: try {
228: WebConversation conversation = new WebConversation();
229: WebResponse response = null;
230: System.out.println("requestPrefix=" + as.requestPrefix);
231: response = conversation.getResponse(as.requestPrefix
232: + AS_PREF + "_" + dat._testProjectName
233: + projectNumber);
234: if (response.getText().indexOf("JumboCom") == -1
235: || response.getText()
236: .indexOf("Fort Lauderdale") == -1)
237: fail("Application doesn't contain right data!");
238: } catch (Exception e) {
239: System.out.println("Exception occured: ");
240: e.printStackTrace();
241: fail("Excetion in HTTP check : " + e);
242: } finally {
243: dat.finishProject(prj, true, true);
244: }
245: }
246: }
247:
248: public void testStopStartASandDeploy() {
249: projectNumber++;
250: ProjectDescriptor pd = new ProjectDescriptor(AS_PREF + "_"
251: + dat._testProjectName + projectNumber,
252: dat._projectPath, ProjectDescriptor.J2EE14, as
253: .getName());
254: Project prj = IDE.getIDE().createProject(pd);
255: TestUtils.disableBrowser(AS_PREF + "_" + dat._testProjectName
256: + projectNumber, true);
257: TestUtils.wait(1000);
258: as.stop();
259: TestUtils.wait(5000);
260: as.start();
261: TestUtils.wait(5000);
262: prj.run();
263: try {
264: verifyHTTPSimple();
265: } catch (Exception e) {
266: System.out.println("Exception occured: ");
267: e.printStackTrace();
268: fail("Excetion in HTTP check : " + e);
269: } finally {
270: dat.finishProject(prj, true, true);
271: }
272: }
273:
274: public void testStopStartDBandDeploy() {
275: projectNumber++;
276: ProjectDescriptor pd = new ProjectDescriptor(AS_PREF + "_"
277: + dat._testProjectName + projectNumber,
278: dat._projectPath, ProjectDescriptor.J2EE14, as
279: .getName());
280: Project prj = IDE.getIDE().createProject(pd);
281: TestUtils.disableBrowser(AS_PREF + "_" + dat._testProjectName
282: + projectNumber, true);
283: TestUtils.wait(1000);
284: WebPageFolder wpf = prj.getRoot().getWebPageRootFolder();
285: WebPage wp = wpf.getWebPage("Page1");
286: VisualComponent vcmp = (VisualComponent) wp.add(
287: (WebComponent) IDE.getIDE().getDefaultComponentSet()
288: .getComponent(TableComponent.TABLE_ID),
289: new Point(48, 48));
290: designer = new DesignerPaneOperator(RaveWindowOperator
291: .getDefaultRave());
292: TestUtils.wait(1000);
293: server = ServerNavigatorOperator.showNavigatorOperator();
294: TestUtils.wait(4000);
295: sntree = server.getTree();
296: sntree.selectPath(sntree.findPath(dat.dbPath + dat.testDBName
297: + "|Tables|CUSTOMER"));
298: designer.requestFocus();
299: designer.clickMouse(50, 50, 1);
300: TestUtils.wait(2000);
301: dat.stopDB();
302: TestUtils.wait(5000);
303: dat.startDB();
304: TestUtils.wait(5000);
305: prj.run();
306: try {
307: verifyHTTPDB("JumboCom");
308: } catch (Exception e) {
309: System.out.println("Exception occured: ");
310: e.printStackTrace();
311: fail("Excetion in HTTP check : " + e);
312: } finally {
313: dat.finishProject(prj, true, true);
314: }
315: }
316:
317: public void testStopASandDeploy() {
318: projectNumber++;
319: ProjectDescriptor pd = new ProjectDescriptor(AS_PREF + "_"
320: + dat._testProjectName + projectNumber,
321: dat._projectPath, ProjectDescriptor.J2EE14, as
322: .getName());
323: Project prj = IDE.getIDE().createProject(pd);
324: TestUtils.disableBrowser(AS_PREF + "_" + dat._testProjectName
325: + projectNumber, true);
326: TestUtils.wait(1000);
327: server = ServerNavigatorOperator.showNavigatorOperator();
328: TestUtils.wait(4000);
329: as.stop();
330: TestUtils.wait(5000);
331: prj.run();
332: try {
333: verifyHTTPSimple();
334: } catch (Exception e) {
335: System.out.println("Exception occured: ");
336: e.printStackTrace();
337: fail("Excetion in HTTP check : " + e);
338: } finally {
339: dat.finishProject(prj, true, true);
340: }
341: }
342:
343: public void testStopDBandDeploy() {
344: projectNumber++;
345: ProjectDescriptor pd = new ProjectDescriptor(AS_PREF + "_"
346: + dat._testProjectName + projectNumber,
347: dat._projectPath, ProjectDescriptor.J2EE14, as
348: .getName());
349: Project prj = IDE.getIDE().createProject(pd);
350: TestUtils.disableBrowser(AS_PREF + "_" + dat._testProjectName
351: + projectNumber, true);
352: TestUtils.wait(1000);
353: WebPageFolder wpf = prj.getRoot().getWebPageRootFolder();
354: WebPage wp = wpf.getWebPage("Page1");
355: VisualComponent vcmp = (VisualComponent) wp.add(
356: (WebComponent) IDE.getIDE().getDefaultComponentSet()
357: .getComponent(TableComponent.TABLE_ID),
358: new Point(48, 48));
359: designer = new DesignerPaneOperator(RaveWindowOperator
360: .getDefaultRave());
361: TestUtils.wait(1000);
362: server = ServerNavigatorOperator.showNavigatorOperator();
363: TestUtils.wait(4000);
364: sntree = server.getTree();
365: sntree.selectPath(sntree.findPath(dat.dbPath + dat.testDBName
366: + "|Tables|CUSTOMER"));
367: designer.requestFocus();
368: designer.clickMouse(50, 50, 1);
369: TestUtils.wait(2000);
370: dat.stopDB();
371: TestUtils.wait(5000);
372: prj.run();
373: try {
374: WebConversation conversation = new WebConversation();
375: WebResponse response = null;
376: System.out.println("requestPrefix=" + as.requestPrefix);
377: response = conversation.getResponse(as.requestPrefix
378: + AS_PREF + "_" + dat._testProjectName
379: + projectNumber);
380: } catch (Exception e) {
381: if (e
382: .getClass()
383: .getName()
384: .equals(
385: "com.meterware.httpunit.HttpInternalErrorException")) {
386: if (e.toString().indexOf(
387: "Error on HTTP request: 500 Internal Error") == -1)
388: fail("Wrong response!");
389: } else {
390: System.out.println("Exception occured: ");
391: e.printStackTrace();
392: fail("Excetion in HTTP check : " + e);
393: }
394: } finally {
395: dat.finishProject(prj, true, true);
396: }
397: }
398:
399: public void testChangeDSandDeploy() {
400: projectNumber++;
401: ProjectDescriptor pd = new ProjectDescriptor(AS_PREF + "_"
402: + dat._testProjectName + projectNumber,
403: dat._projectPath, ProjectDescriptor.J2EE14, as
404: .getName());
405: Project prj = IDE.getIDE().createProject(pd);
406: TestUtils.disableBrowser(AS_PREF + "_" + dat._testProjectName
407: + projectNumber, true);
408: TestUtils.wait(1000);
409: dat.startDB();
410: TestUtils.wait(5000);
411: WebPageFolder wpf = prj.getRoot().getWebPageRootFolder();
412: WebPage wp = wpf.getWebPage("Page1");
413: VisualEventHandlingComponent vehcmp = (VisualEventHandlingComponent) wp
414: .add(
415: (WebComponent) IDE
416: .getIDE()
417: .getDefaultComponentSet()
418: .getComponent(
419: DropDownListComponent.DROP_DOWN_LIST_ID),
420: new Point(48, 48));
421: designer = new DesignerPaneOperator(RaveWindowOperator
422: .getDefaultRave());
423: server = ServerNavigatorOperator.showNavigatorOperator();
424: TestUtils.wait(4000);
425: sntree = server.getTree();
426: sntree.selectPath(sntree.findPath(dat.dbPath + dat.testDBName
427: + "|Tables|CUSTOMER"));
428: TestUtils.wait(1000);
429: designer.requestFocus();
430: designer.clickMouse(50, 50, 1);
431: TestUtils.wait(1000);
432: designer.requestFocus();
433: designer.clickForPopup(50, 50);
434: JPopupMenuOperator popup = new JPopupMenuOperator();
435: popup.pushMenuNoBlock(dat.bindDBPopup);
436: JDialogOperator dataBind = new JDialogOperator(dat.dlg_bindDB);
437: new JTabbedPaneOperator(dataBind).selectPage(dat.bindToDP);
438: TestUtils.wait(1000);
439: JListOperator valueList = new JListOperator(dataBind, 0);
440: TestUtils.wait(1000);
441: valueList.selectItem("CUSTOMER.CUSTOMER_ID");
442: TestUtils.wait(1000);
443: JListOperator displayList = new JListOperator(dataBind, 1);
444: TestUtils.wait(1000);
445: displayList.selectItem("CUSTOMER.NAME");
446: TestUtils.wait(1000);
447: new JButtonOperator(dataBind, dat.btn_OK).pushNoBlock();
448: TestUtils.wait(1000);
449: prj.run();
450: try {
451: verifyHTTPDB("JumboCom");
452: } catch (Exception e) {
453: System.out.println("Exception occured: ");
454: e.printStackTrace();
455: fail("Excetion in HTTP check : " + e);
456: } finally {
457: dat.finishProject(prj, true, true);
458: dat.disconnectFromDB(dat.testDBName);
459: TestUtils.wait(1000);
460: dat.stopDB();
461: TestUtils.wait(1000);
462: as.stop();
463: TestUtils.wait(1000);
464: }
465: designer.requestFocus();
466: designer.clickForPopup(50, 50);
467: popup = new JPopupMenuOperator();
468: popup.pushMenuNoBlock(dat.bindDBPopup);
469: dataBind = new JDialogOperator(dat.dlg_bindDB);
470: new JTabbedPaneOperator(dataBind).selectPage(dat.bindToDP);
471: TestUtils.wait(1000);
472: valueList = new JListOperator(dataBind, 0);
473: TestUtils.wait(1000);
474: valueList.selectItem("CUSTOMER.CUSTOMER_ID");
475: TestUtils.wait(1000);
476: displayList = new JListOperator(dataBind, 1);
477: TestUtils.wait(1000);
478: displayList.selectItem("CUSTOMER.CITY");
479: TestUtils.wait(1000);
480: new JButtonOperator(dataBind, dat.btn_OK).pushNoBlock();
481: TestUtils.wait(1000);
482: prj.run();
483: try {
484: verifyHTTPDB("Fort Lauderdale");
485: } catch (Exception e) {
486: System.out.println("Exception occured: ");
487: e.printStackTrace();
488: fail("Excetion in HTTP check : " + e);
489: } finally {
490: dat.finishProject(prj, true, true);
491: dat.disconnectFromDB(dat.testDBName);
492: TestUtils.wait(1000);
493: dat.stopDB();
494: TestUtils.wait(1000);
495: as.stop();
496: TestUtils.wait(1000);
497: }
498: }
499:
500: public void verifyHTTPSimple() throws Exception {
501: WebConversation conversation = new WebConversation();
502: WebResponse response = null;
503: System.out.println("requestPrefix=" + as.requestPrefix);
504: response = conversation.getResponse(as.requestPrefix + AS_PREF
505: + "_" + dat._testProjectName + projectNumber);
506: }
507:
508: public void verifyHTTPDB(String toCompare) throws Exception {
509: WebConversation conversation = new WebConversation();
510: WebResponse response = null;
511: System.out.println("requestPrefix=" + as.requestPrefix);
512: response = conversation.getResponse(as.requestPrefix + AS_PREF
513: + "_" + dat._testProjectName + projectNumber);
514: if (response.getText().indexOf(toCompare) == -1)
515: fail("String \"" + toCompare
516: + "\" is not found in response!");
517: }
518: }
|