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.pagefragment;
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.JTextComponentOperator;
051: import org.netbeans.jemmy.operators.JDialogOperator;
052: import org.netbeans.jemmy.operators.JButtonOperator;
053: import org.netbeans.jemmy.operators.JTextFieldOperator;
054: import org.netbeans.jemmy.QueueTool;
055: import org.netbeans.jemmy.operators.JTreeOperator;
056:
057: import org.netbeans.modules.visualweb.gravy.*;
058: import org.netbeans.modules.visualweb.gravy.designer.DesignerPaneOperator;
059: import org.netbeans.modules.visualweb.gravy.properties.SheetTableOperator;
060: import org.netbeans.modules.visualweb.gravy.toolbox.PaletteContainerOperator;
061: import org.netbeans.modules.visualweb.test.components.util.ComponentUtils;
062: import org.netbeans.modules.visualweb.gravy.dataconnectivity.ServerNavigatorOperator;
063:
064: import java.io.File;
065: import java.awt.Point;
066: import java.io.IOException;
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.pagefragment.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 _layoutPalette = Bundle.getStringTrimmed(
100: _sharedBundle, "layoutPalette");
101: public String _layoutPageFragment = Bundle.getStringTrimmed(
102: _sharedBundle, "layoutPageFragment");
103: public String _basicTextField = Bundle.getStringTrimmed(
104: _sharedBundle, "basicTextField");
105: public String _basicLabel = Bundle.getStringTrimmed(_sharedBundle,
106: "basicLabel");
107: public String _basicMessage = Bundle.getStringTrimmed(
108: _sharedBundle, "basicMessage");
109:
110: //Component names & values
111: public String _labelValue1 = Bundle.getStringTrimmed(
112: _privateBundle, "labelValue1");
113: public String _textField1 = Bundle.getStringTrimmed(_sharedBundle,
114: "textField1");
115: public String _selectPageFragment = Bundle.getStringTrimmed(
116: _sharedBundle, "selectPageFragment");
117: public String _createNewPageFragment = Bundle.getStringTrimmed(
118: _sharedBundle, "createNewPageFragment");
119: public String _createPageFragment = Bundle.getStringTrimmed(
120: _sharedBundle, "createPageFragment");
121: public String _fragmentName1 = Bundle.getStringTrimmed(
122: _privateBundle, "fragmentName1");
123:
124: //Property, menu & button variables
125: public String _propertyText = Bundle.getStringTrimmed(
126: _sharedBundle, "propertyText");
127: public String _propertyFor = Bundle.getStringTrimmed(_sharedBundle,
128: "propertyFor");
129: public String _propertyRequired = Bundle.getStringTrimmed(
130: _sharedBundle, "propertyRequired");
131: public String _properties = Bundle.getStringTrimmed(_sharedBundle,
132: "properties");
133: public String _ok = Bundle.getStringTrimmed(_sharedBundle,
134: "Button_OK");
135:
136: //drop points
137: public int _x = Integer.parseInt(Bundle.getStringTrimmed(
138: _privateBundle, "x"));
139: public int _pagefragment1y = Integer.parseInt(Bundle
140: .getStringTrimmed(_privateBundle, "pagefragment1y"));
141: public int _button1y = Integer.parseInt(Bundle.getStringTrimmed(
142: _privateBundle, "button1y"));
143: public int _textfield1y = Integer.parseInt(Bundle.getStringTrimmed(
144: _privateBundle, "textfield1y"));
145: public int _message1y = Integer.parseInt(Bundle.getStringTrimmed(
146: _privateBundle, "message1y"));
147: public int _label1y = Integer.parseInt(Bundle.getStringTrimmed(
148: _privateBundle, "label1y"));
149:
150: //undeployment
151: public String _undeploy = Bundle.getStringTrimmed(_sharedBundle,
152: "undeploy");
153: public String _refresh = Bundle.getStringTrimmed(_sharedBundle,
154: "refresh");
155: public String _serverPath = Bundle.getStringTrimmed(_sharedBundle,
156: "serverPath");
157: public String _deploymentPath = Bundle.getStringTrimmed(
158: _sharedBundle, "deploymentPathGlassfish");
159: public String _separator = Bundle.getStringTrimmed(_sharedBundle,
160: "separator");
161:
162: Point clickPoint, dropPoint;
163: public static DesignerPaneOperator designer;
164: public static PaletteContainerOperator palette;
165: public static DocumentOutlineOperator outline;
166: public static SheetTableOperator sheet;
167: public static DeploymentDialogOperator deploy;
168: public static ServerNavigatorOperator explorer;
169: public int row;
170:
171: public AcceptanceTest(String testName) {
172: super (testName);
173: }
174:
175: public static Test suite() {
176: TestSuite suite = new NbTestSuite();
177: suite.addTest(new AcceptanceTest("testCreateWebProject"));
178: suite.addTest(new AcceptanceTest("testAddPageFragment"));
179: suite.addTest(new AcceptanceTest("testOpenPageFragment"));
180: suite.addTest(new AcceptanceTest("testBuildFragmentPage"));
181: // suite.addTest(new AcceptanceTest("testDeploy"));
182: // suite.addTest(new AcceptanceTest("testCloseWebProject"));
183: // suite.addTest(new AcceptanceTest("testUndeploy"));
184: // suite.addTest(new AcceptanceTest("testCheckIDELog"));
185:
186: return suite;
187: }
188:
189: /** method called before each testcase
190: */
191: protected void setUp() {
192: System.out.println("######## " + getName() + " #######");
193: }
194:
195: /** method called after each testcase
196: */
197: protected void tearDown() {
198: System.out.println("######## " + getName()
199: + " Finished #######");
200: }
201:
202: /*
203: * Create Web Project
204: *
205: */
206: public void testCreateWebProject() {
207: startTest();
208: log("**Creating Project");
209: //Create Project
210: try {
211: ComponentUtils.createNewProject(_projectName);
212: } catch (Exception e) {
213: log(">> Project Creation Failed");
214: e.printStackTrace();
215: log(e.toString());
216: fail();
217: }
218: log("**Done");
219:
220: endTest();
221: }
222:
223: /*
224: * Add a page fragment to designer
225: */
226: public void testAddPageFragment() {
227: startTest();
228: log("**Initialize");
229: designer = new DesignerPaneOperator(RaveWindowOperator
230: .getDefaultRave());
231: palette = new PaletteContainerOperator(_layoutPalette);
232: try {
233: Thread.sleep(5000);
234: } catch (Exception e) {
235: }
236:
237: log("**Add page fragment to designer");
238: clickPoint = palette.getClickPoint(_layoutPageFragment);
239: dropPoint = new Point(_x, _pagefragment1y);
240: palette.dndPaletteComponent(_layoutPageFragment, designer,
241: dropPoint);
242: try {
243: Thread.sleep(2000);
244: } catch (Exception e) {
245: }
246:
247: log("Select Page Fragment Dialog");
248: JDialogOperator pageFragmentDialog = new JDialogOperator(
249: _selectPageFragment);
250: new JButtonOperator(pageFragmentDialog, _createNewPageFragment)
251: .pushNoBlock();
252: TestUtils.wait(1000);
253:
254: log("Create Page Fragment Dialog");
255: JDialogOperator createPageFragment = new JDialogOperator(
256: _createPageFragment);
257: new JTextFieldOperator(createPageFragment, 0)
258: .setText(_fragmentName1);
259: TestUtils.wait(1000);
260:
261: log("Close dialogs");
262: new JButtonOperator(createPageFragment, _ok).pushNoBlock();
263: TestUtils.wait(3000);
264: new JButtonOperator(pageFragmentDialog, _close).pushNoBlock();
265: TestUtils.wait(3000);
266:
267: log("**Done.");
268: endTest();
269:
270: }
271:
272: /*
273: * Open Page Fragment
274: */
275: public void testOpenPageFragment() {
276: startTest();
277: log("**Initialize");
278: designer = new DesignerPaneOperator(RaveWindowOperator
279: .getDefaultRave());
280:
281: log("**Double click on fragment to open");
282: designer.clickMouse(_x + 15, _pagefragment1y + 15, 2);
283: // designer.clickMouse(_fragmentName1, 2);
284: log("**Done.");
285: endTest();
286: }
287:
288: /*
289: * add textField
290: * add a label for textfield and give it a name.
291: * mark textField required.
292: * add a message component linked to textField3
293: */
294: public void testBuildFragmentPage() {
295: startTest();
296:
297: log("**Initialize");
298: designer = new DesignerPaneOperator(RaveWindowOperator
299: .getDefaultRave());
300: designer.clickMouse();
301: palette = new PaletteContainerOperator(_basicPalette); //previously set to Layout
302: palette.clickMouse();
303: // palette = new PaletteContainerOperator(_basicPalette); //previously set to Layout
304: try {
305: Thread.sleep(5000);
306: } catch (Exception e) {
307: }
308:
309: log("**Add Textfield to designer");
310: Point clickPoint = palette.getClickPoint(_basicTextField);
311: Point dropPoint = new Point(_x, _textfield1y); //leave room for label
312: // palette.
313: palette.addComponent(_basicTextField, designer, dropPoint);
314: try {
315: Thread.sleep(2000);
316: } catch (Exception e) {
317: }
318:
319: log("**Add label to designer");
320: clickPoint = palette.getClickPoint(_basicLabel);
321: dropPoint = new Point(_x, _label1y);
322: palette = new PaletteContainerOperator(null); //workaround
323: palette.dndPaletteComponent(_basicLabel, designer, dropPoint);
324: try {
325: Thread.sleep(2000);
326: } catch (Exception e) {
327: }
328:
329: log("**Set Label text property");
330: sheet = new SheetTableOperator();
331: int row = sheet.findCellRow(_propertyText);
332: sheet.clickForEdit(row, 1);
333: sheet.clickForEdit(row, 1);
334: new JTextComponentOperator(sheet).enterText(_labelValue1);
335:
336: log("**Set Label for property to textField");
337: row = sheet.findCellRow(_propertyFor);
338: sheet.clickForEdit(row, 1);
339: sheet.setComboBoxValue(_propertyFor, _textField1);
340: try {
341: Thread.sleep(1000);
342: } catch (Exception e) {
343: }
344:
345: log("**Select textfield");
346: designer.clickMouse(_x, _textfield1y, 1);
347: try {
348: Thread.sleep(3000);
349: } catch (Exception e) {
350: }
351:
352: log("**Set required option to true");
353: row = sheet.findCellRow(_propertyRequired);
354: sheet.clickForEdit(row, 1);
355: sheet.setCheckBoxValue(_propertyRequired, _true);
356: try {
357: Thread.sleep(2000);
358: } catch (Exception e) {
359: }
360:
361: log("**Drag Message onto designer");
362: clickPoint = palette.getClickPoint(_basicMessage);
363: dropPoint = new Point(_x, _message1y);
364: palette = new PaletteContainerOperator(_basicPalette); //workaround
365: palette.dndPaletteComponent(_basicMessage, designer, dropPoint);
366: try {
367: Thread.sleep(2000);
368: } catch (Exception e) {
369: }
370:
371: // log("**Set message via shift-drag and drop onto textField");
372:
373: log("**Set message for property via property sheet");
374: row = sheet.findCellRow(_propertyFor);
375: sheet.clickForEdit(row, 1);
376: sheet.setComboBoxValue(_propertyFor, _textField1);
377:
378: log("**Add Button to designer");
379: clickPoint = palette.getClickPoint(_basicButton);
380: dropPoint = new Point(_x, _button1y);
381: palette = new PaletteContainerOperator(null); //workaround
382: palette.dndPaletteComponent(_basicButton, designer, dropPoint);
383: try {
384: Thread.sleep(2000);
385: } catch (Exception e) {
386: }
387:
388: log("**Done.");
389: endTest();
390:
391: }
392:
393: /*
394: * Deploy application
395: */
396: public void testDeploy() {
397: startTest();
398: //need to wait responce
399: Waiter deploymentWaiter = new Waiter(new Waitable() {
400: public Object actionProduced(Object output) {
401: String text = ((OutputOperator) output).getText();
402: if (text.indexOf(_buildSuccess) != -1)
403: return _true;
404: return null;
405:
406: }
407:
408: public String getDescription() {
409: return ("Waiting Project Deployed");
410: }
411: });
412: log("Deploy from menu");
413: ProjectNavigatorOperator.pressPopupItemOnNode(_projectName,
414: _run);
415: TestUtils.wait(2000);
416: OutputOperator outputWindow = new OutputOperator();
417: deploymentWaiter.getTimeouts().setTimeout("Waiter.WaitingTime",
418: 240000);
419: log("wait until " + _buildSuccess);
420: try {
421: deploymentWaiter.waitAction(outputWindow);
422: } catch (InterruptedException e) {
423: log(outputWindow.getText());
424: e.printStackTrace();
425: fail("Deployment error: " + e);
426: }
427: log("Deployment complete");
428: endTest();
429: }
430:
431: /*
432: * Close Project
433: *
434: */
435: public void testCloseWebProject() {
436: startTest();
437: Util.saveAllAPICall();
438: new ProjectNavigatorOperator().pressPopupItemOnNode(
439: _projectName, _close);
440: //TestUtils.closeCurrentProject();
441: TestUtils.wait(5000);
442: endTest();
443: }
444:
445: /* Need to undeploy project to finish tests correctly */
446: public void testUndeploy() {
447: startTest();
448: log("Initialize");
449: explorer = ServerNavigatorOperator.showNavigatorOperator();
450: String serverPath = _serverPath + _projectServer; //Current deployment server
451: String deploymentPath = serverPath + _deploymentPath; //glassfish specific
452: String applicationPath = deploymentPath + _separator
453: + _projectName; //project name
454:
455: // Select the Server Navigator and set the JTreeOperator
456: log("get explorer");
457: new QueueTool().waitEmpty(100); //??
458: explorer.requestFocus();
459: JTreeOperator tree = explorer.getTree();
460: try {
461: Thread.sleep(4000);
462: } catch (Exception e) {
463: } // Sleep 4 secs to make sure Server Navigator is in focus
464:
465: // Need to refresh J2EE AppServer node
466: log("refresh");
467: explorer.pushPopup(tree, serverPath, _refresh);
468: TestUtils.wait(1000);
469:
470: log("refresh deployment path: " + deploymentPath);
471: TestUtils.wait(1000);
472: explorer.selectPath(deploymentPath);
473: explorer.getTree().expandPath(
474: explorer.getTree().findPath(deploymentPath));
475: explorer.pushPopup(tree, deploymentPath, _refresh);
476: TestUtils.wait(1000);
477:
478: log("undeploy Path: " + applicationPath);
479: explorer.selectPath(applicationPath);
480: TestUtils.wait(1000);
481:
482: log("Push Menu Undeploy...");
483: explorer.pushPopup(explorer.getTree(), applicationPath,
484: _undeploy);
485: TestUtils.wait(5000);
486: endTest();
487: }
488:
489: public void testCheckIDELog() {
490: startTest();
491: try {
492: String err = ComponentUtils.hasUnexpectedException();
493: String str = "";
494: if (!(err.equals(""))) {
495: assertTrue(
496: "Unexpected exceptions found in message.log: "
497: + err, str.equals(""));
498: }
499: } catch (IOException ioe) {
500: ioe.printStackTrace();
501: fail("Failed to open message.log : " + ioe);
502: }
503: endTest();
504: }
505: }
|