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.modules.visualweb.test.components.layout.virtualform;
043:
044: import junit.framework.Test;
045: import junit.framework.TestSuite;
046: import org.netbeans.junit.NbTestSuite;
047: import org.netbeans.jellytools.OutputOperator;
048: import org.netbeans.jemmy.Waiter;
049: import org.netbeans.jemmy.Waitable;
050: import org.netbeans.jemmy.operators.JPopupMenuOperator;
051: import org.netbeans.jemmy.operators.JButtonOperator;
052: import org.netbeans.jemmy.operators.JTableOperator;
053: import org.netbeans.jemmy.QueueTool;
054: import org.netbeans.jemmy.operators.JTreeOperator;
055:
056: import org.netbeans.modules.visualweb.gravy.*;
057: import org.netbeans.modules.visualweb.gravy.designer.DesignerPaneOperator;
058: import org.netbeans.modules.visualweb.gravy.properties.SheetTableOperator;
059: import org.netbeans.modules.visualweb.gravy.toolbox.PaletteContainerOperator;
060: import org.netbeans.modules.visualweb.test.components.util.ComponentUtils;
061: import org.netbeans.modules.visualweb.gravy.dataconnectivity.ServerNavigatorOperator;
062:
063: import java.io.File;
064: import java.awt.Point;
065: import java.io.IOException;
066: import org.netbeans.jemmy.operators.JComboBoxOperator;
067:
068: /**
069: * @author Lark Fitzgerald (lark.fitzgerald@sun.com)
070: */
071: public class AcceptanceTest extends RaveTestCase {
072:
073: //Project variables
074: public String _sharedBundle = "org.netbeans.modules.visualweb.test.components.Component";
075: public String _privateBundle = "org.netbeans.modules.visualweb.test.components.layout.virtualform.Acceptance";
076: public String _projectName = Bundle.getStringTrimmed(
077: _privateBundle, "projectName");
078: public String _projectServer = Bundle.getStringTrimmed(
079: _sharedBundle, "projectServer");
080: public String _logFileLocation = Bundle.getStringTrimmed(
081: _sharedBundle, "logFile");
082: public String _logFile = System.getProperty("xtest.workdir")
083: + File.separator + _logFileLocation;
084: public String _exception = Bundle.getStringTrimmed(_sharedBundle,
085: "Exception");
086: public String _close = Bundle.getStringTrimmed(_sharedBundle,
087: "close");
088: public String _run = Bundle.getStringTrimmed(_sharedBundle, "Run");
089: public String _buildSuccess = Bundle.getStringTrimmed(
090: _sharedBundle, "buildSuccess");
091: public String _true = Bundle
092: .getStringTrimmed(_sharedBundle, "true");
093:
094: //Palette variables
095: public String _basicPalette = Bundle.getStringTrimmed(
096: _sharedBundle, "basicPalette");
097: public String _basicButton = Bundle.getStringTrimmed(_sharedBundle,
098: "basicButton");
099: public String _basicTextField = Bundle.getStringTrimmed(
100: _sharedBundle, "basicTextField");
101: public String _basicMessageGroup = Bundle.getStringTrimmed(
102: _sharedBundle, "basicMessageGroup");
103:
104: //drop points
105: public int _x = Integer.parseInt(Bundle.getStringTrimmed(
106: _privateBundle, "x"));
107: public int _textfield1y = Integer.parseInt(Bundle.getStringTrimmed(
108: _privateBundle, "textfield1y"));
109: public int _button1y = Integer.parseInt(Bundle.getStringTrimmed(
110: _privateBundle, "button1y"));
111: public int _textfield2y = Integer.parseInt(Bundle.getStringTrimmed(
112: _privateBundle, "textfield2y"));
113: public int _button2y = Integer.parseInt(Bundle.getStringTrimmed(
114: _privateBundle, "button2y"));
115: public int _messagegroup1y = Integer.parseInt(Bundle
116: .getStringTrimmed(_privateBundle, "messagegroup1y"));
117:
118: //Property, Menu & Dialog variables
119: public String _propertyRequired = Bundle.getStringTrimmed(
120: _sharedBundle, "propertyRequired");
121: public String _separator = Bundle.getStringTrimmed(_sharedBundle,
122: "separator");
123: public String _menuVirtualForm = Bundle.getStringTrimmed(
124: _sharedBundle, "menuVirtualForm");
125: public String _virtualFormDialog = Bundle.getStringTrimmed(
126: _sharedBundle, "virtualFormDialog");
127: public String _new = Bundle.getStringTrimmed(_sharedBundle, "new");
128: public String _yes = Bundle.getStringTrimmed(_sharedBundle, "yes");
129: public String _ok = Bundle.getStringTrimmed(_sharedBundle,
130: "Button_OK");
131:
132: //undeployment
133: public String _undeploy = Bundle.getStringTrimmed(_sharedBundle,
134: "undeploy");
135: public String _refresh = Bundle.getStringTrimmed(_sharedBundle,
136: "refresh");
137: public String _serverPath = Bundle.getStringTrimmed(_sharedBundle,
138: "serverPath");
139: public String _deploymentPath = Bundle.getStringTrimmed(
140: _sharedBundle, "deploymentPathGlassfish");
141:
142: Point clickPoint, dropPoint;
143: public static DesignerPaneOperator designer;
144: public static PaletteContainerOperator palette;
145: public static DocumentOutlineOperator outline;
146: public static SheetTableOperator sheet;
147: public static DeploymentDialogOperator deploy;
148: public static ServerNavigatorOperator explorer;
149: public int row;
150:
151: public AcceptanceTest(String testName) {
152: super (testName);
153: }
154:
155: public static Test suite() {
156: TestSuite suite = new NbTestSuite();
157: suite.addTest(new AcceptanceTest("testCreateWebProject"));
158: suite.addTest(new AcceptanceTest("testCreateForm"));
159: suite.addTest(new AcceptanceTest("testAddVirtualForm1"));
160: suite.addTest(new AcceptanceTest("testAddVirtualForm2"));
161: suite.addTest(new AcceptanceTest("testDeploy"));
162: suite.addTest(new AcceptanceTest("testCloseWebProject"));
163: suite.addTest(new AcceptanceTest("testUndeploy"));
164: suite.addTest(new AcceptanceTest("testCheckIDELog"));
165:
166: return suite;
167: }
168:
169: /** method called before each testcase
170: */
171: protected void setUp() {
172: System.out.println("######## " + getName() + " #######");
173: }
174:
175: /** method called after each testcase
176: */
177: protected void tearDown() {
178: System.out.println("######## " + getName()
179: + " Finished #######");
180: }
181:
182: /*
183: * Create Web Project
184: *
185: */
186: public void testCreateWebProject() {
187: startTest();
188: log("**Creating Project");
189: //Create Project
190: try {
191: ComponentUtils.createNewProject(_projectName);
192: } catch (Exception e) {
193: log(">> Project Creation Failed");
194: e.printStackTrace();
195: log(e.toString());
196: fail();
197: }
198: log("**Done");
199: endTest();
200: }
201:
202: /*
203: * Build Form
204: */
205: public void testCreateForm() {
206: startTest();
207: log("**Initialize");
208: designer = new DesignerPaneOperator(RaveWindowOperator
209: .getDefaultRave());
210: palette = new PaletteContainerOperator(_basicPalette);
211: try {
212: Thread.sleep(5000);
213: } catch (Exception e) {
214: }
215:
216: log("**Add textfield1 to designer");
217: clickPoint = palette.getClickPoint(_basicTextField);
218: dropPoint = new Point(_x, _textfield1y);
219: palette.dndPaletteComponent(_basicTextField, designer,
220: dropPoint);
221: try {
222: Thread.sleep(5000);
223: } catch (Exception e) {
224: }
225:
226: log("**Set required option to true");
227: sheet = new SheetTableOperator();
228: row = sheet.findCellRow(_propertyRequired);
229: sheet.clickForEdit(row, 1);
230: sheet.setCheckBoxValue(_propertyRequired, _true);
231: try {
232: Thread.sleep(2000);
233: } catch (Exception e) {
234: }
235:
236: log("**Add button1 to designer");
237: palette = new PaletteContainerOperator(_basicPalette);
238: clickPoint = palette.getClickPoint(_basicButton);
239: dropPoint = new Point(_x, _button1y);
240: palette.dndPaletteComponent(_basicButton, designer, dropPoint);
241: try {
242: Thread.sleep(2000);
243: } catch (Exception e) {
244: }
245:
246: log("**Add textfield2 to designer");
247: palette = new PaletteContainerOperator(_basicPalette);
248: clickPoint = palette.getClickPoint(_basicTextField);
249: dropPoint = new Point(_x, _textfield2y);
250: palette.dndPaletteComponent(_basicTextField, designer,
251: dropPoint);
252: try {
253: Thread.sleep(2000);
254: } catch (Exception e) {
255: }
256:
257: log("**Set required option to true");
258: sheet = new SheetTableOperator();
259: row = sheet.findCellRow(_propertyRequired);
260: sheet.clickForEdit(row, 1);
261: sheet.setCheckBoxValue(_propertyRequired, _true);
262: try {
263: Thread.sleep(2000);
264: } catch (Exception e) {
265: }
266:
267: log("**Add button2 to designer");
268: palette = new PaletteContainerOperator(_basicPalette);
269: clickPoint = palette.getClickPoint(_basicButton);
270: dropPoint = new Point(_x, _button2y);
271: palette.dndPaletteComponent(_basicButton, designer, dropPoint);
272: try {
273: Thread.sleep(2000);
274: } catch (Exception e) {
275: }
276:
277: log("**Add messagegroup1 to designer");
278: palette = new PaletteContainerOperator(_basicPalette);
279: clickPoint = palette.getClickPoint(_basicMessageGroup);
280: dropPoint = new Point(_x, _messagegroup1y);
281: palette.dndPaletteComponent(_basicMessageGroup, designer,
282: dropPoint);
283: try {
284: Thread.sleep(2000);
285: } catch (Exception e) {
286: }
287:
288: log("**Done.");
289: endTest();
290:
291: }
292:
293: /*
294: * Configure virtual form 1
295: */
296: public void testAddVirtualForm1() {
297: startTest();
298: // log("**De-select component (select designer)");
299: // designer.clickMouse(5, 5);
300: // try { Thread.sleep(1000); } catch(Exception e) {}
301:
302: log("**Right click textfield1");
303: designer.clickForPopup(_x + 10, _textfield1y + 10);
304: try {
305: Thread.sleep(1000);
306: } catch (Exception e) {
307: }
308:
309: log("**Select " + _menuVirtualForm + " menu item");
310: new JPopupMenuOperator().pushMenuNoBlock(_menuVirtualForm,
311: _separator);
312: try {
313: Thread.sleep(1000);
314: } catch (Exception e) {
315: }
316:
317: log("**locate Create Virtual Form dialog");
318: NbDialogOperator vf = new NbDialogOperator(_virtualFormDialog);
319:
320: log("**Add New Virtual Form");
321: JButtonOperator newButton = new JButtonOperator(vf, _new);
322: newButton.clickMouse();
323: try {
324: Thread.sleep(1000);
325: } catch (Exception e) {
326: }
327:
328: log("**set participate = Yes");
329: JTableOperator vfTable = new JTableOperator(vf);
330: vfTable.clickOnCell(0, 2, 2);
331: JComboBoxOperator yn = new JComboBoxOperator(vf);
332: yn.selectItem(_yes);
333:
334: log("**Close dialog");
335: JButtonOperator okButton = new JButtonOperator(vf, _ok);
336: okButton.clickMouse();
337:
338: log("**Right click button1");
339: designer.clickForPopup(_x + 10, _button1y + 10);
340: try {
341: Thread.sleep(3000);
342: } catch (Exception e) {
343: }
344:
345: log("**Select " + _menuVirtualForm + " menu item");
346: new JPopupMenuOperator().pushMenuNoBlock(_menuVirtualForm,
347: _separator);
348: try {
349: Thread.sleep(3000);
350: } catch (Exception e) {
351: }
352:
353: log("**locate Create Virtual Form dialog");
354: vf = new NbDialogOperator(_virtualFormDialog);
355:
356: log("**set submit = Yes");
357: vfTable = new JTableOperator(vf);
358: vfTable.clickOnCell(0, 3, 2);
359: yn = new JComboBoxOperator(vf);
360: yn.selectItem(_yes);
361:
362: log("**Close dialog");
363: okButton = new JButtonOperator(vf, _ok);
364: okButton.clickMouse();
365:
366: log("**Done.");
367: endTest();
368: }
369:
370: /*
371: * Configure virtual form 2
372: */
373: public void testAddVirtualForm2() {
374: startTest();
375: log("**Right click textfield1");
376: designer.clickForPopup(_x + 10, _textfield2y + 10);
377: try {
378: Thread.sleep(1000);
379: } catch (Exception e) {
380: }
381:
382: log("**Select " + _menuVirtualForm + " menu item");
383: new JPopupMenuOperator().pushMenuNoBlock(_menuVirtualForm,
384: _separator);
385: try {
386: Thread.sleep(1000);
387: } catch (Exception e) {
388: }
389:
390: log("**locate Create Virtual Form dialog");
391: NbDialogOperator vf = new NbDialogOperator(_virtualFormDialog);
392:
393: log("**Add New Virtual Form");
394: JButtonOperator newButton = new JButtonOperator(vf, _new);
395: newButton.clickMouse();
396: try {
397: Thread.sleep(1000);
398: } catch (Exception e) {
399: }
400:
401: log("**set participate = Yes");
402: JTableOperator vfTable = new JTableOperator(vf);
403: vfTable.clickOnCell(1, 2, 2);
404: JComboBoxOperator yn = new JComboBoxOperator(vf);
405: yn.selectItem(_yes);
406:
407: log("**Close dialog");
408: JButtonOperator okButton = new JButtonOperator(vf, _ok);
409: okButton.clickMouse();
410:
411: log("**Right click button1");
412: designer.clickForPopup(_x + 10, _button2y + 10);
413: try {
414: Thread.sleep(3000);
415: } catch (Exception e) {
416: }
417:
418: log("**Select " + _menuVirtualForm + " menu item");
419: new JPopupMenuOperator().pushMenuNoBlock(_menuVirtualForm,
420: _separator);
421: try {
422: Thread.sleep(3000);
423: } catch (Exception e) {
424: }
425:
426: log("**locate Create Virtual Form dialog");
427: vf = new NbDialogOperator(_virtualFormDialog);
428:
429: log("**set submit = Yes");
430: vfTable = new JTableOperator(vf);
431: vfTable.clickOnCell(1, 3, 2);
432: yn = new JComboBoxOperator(vf);
433: yn.selectItem(_yes);
434:
435: log("**Close dialog");
436: okButton = new JButtonOperator(vf, _ok);
437: okButton.clickMouse();
438:
439: log("**Done.");
440: endTest();
441: }
442:
443: /*
444: * Deploy application
445: */
446: public void testDeploy() {
447: startTest();
448: //need to wait responce
449: Waiter deploymentWaiter = new Waiter(new Waitable() {
450: public Object actionProduced(Object output) {
451: String text = ((OutputOperator) output).getText();
452: if (text.indexOf(_buildSuccess) != -1)
453: return _true;
454: return null;
455:
456: }
457:
458: public String getDescription() {
459: return ("Waiting Project Deployed");
460: }
461: });
462: log("Deploy from menu");
463: ProjectNavigatorOperator.pressPopupItemOnNode(_projectName,
464: _run);
465: TestUtils.wait(2000);
466: OutputOperator outputWindow = new OutputOperator();
467: deploymentWaiter.getTimeouts().setTimeout("Waiter.WaitingTime",
468: 480000);
469: log("wait until " + _buildSuccess);
470: try {
471: deploymentWaiter.waitAction(outputWindow);
472: } catch (InterruptedException e) {
473: log(outputWindow.getText());
474: e.printStackTrace();
475: fail("Deployment error: " + e);
476: }
477: log("Deployment complete");
478: endTest();
479: }
480:
481: /*
482: * Close Project
483: *
484: */
485: public void testCloseWebProject() {
486: startTest();
487: Util.saveAllAPICall();
488: new ProjectNavigatorOperator().pressPopupItemOnNode(
489: _projectName, _close);
490: //TestUtils.closeCurrentProject();
491: TestUtils.wait(5000);
492: endTest();
493: }
494:
495: /* Need to undeploy project to finish tests correctly */
496: public void testUndeploy() {
497: startTest();
498: log("Initialize");
499: explorer = ServerNavigatorOperator.showNavigatorOperator();
500: String serverPath = _serverPath + _projectServer; //Current deployment server
501: String deploymentPath = serverPath + _deploymentPath; //glassfish specific
502: String applicationPath = deploymentPath + _separator
503: + _projectName; //project name
504:
505: // Select the Server Navigator and set the JTreeOperator
506: log("get explorer");
507: new QueueTool().waitEmpty(100); //??
508: explorer.requestFocus();
509: JTreeOperator tree = explorer.getTree();
510: try {
511: Thread.sleep(4000);
512: } catch (Exception e) {
513: } // Sleep 4 secs to make sure Server Navigator is in focus
514:
515: // Need to refresh J2EE AppServer node
516: log("refresh");
517: explorer.pushPopup(tree, serverPath, _refresh);
518: TestUtils.wait(1000);
519:
520: log("refresh deployment path: " + deploymentPath);
521: TestUtils.wait(1000);
522: explorer.selectPath(deploymentPath);
523: explorer.getTree().expandPath(
524: explorer.getTree().findPath(deploymentPath));
525: explorer.pushPopup(tree, deploymentPath, _refresh);
526: TestUtils.wait(1000);
527:
528: log("undeploy Path: " + applicationPath);
529: explorer.selectPath(applicationPath);
530: TestUtils.wait(1000);
531:
532: log("Push Menu Undeploy...");
533: explorer.pushPopup(explorer.getTree(), applicationPath,
534: _undeploy);
535: TestUtils.wait(5000);
536: endTest();
537: }
538:
539: public void testCheckIDELog() {
540: startTest();
541: try {
542: String err = ComponentUtils.hasUnexpectedException();
543: String str = "";
544: if (!(err.equals(""))) {
545: assertTrue(
546: "Unexpected exceptions found in message.log: "
547: + err, str.equals(""));
548: }
549: } catch (IOException ioe) {
550: ioe.printStackTrace();
551: fail("Failed to open message.log : " + ioe);
552: }
553: endTest();
554: }
555: }
|