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.commontasks;
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.QueueTool;
051: import org.netbeans.jemmy.operators.JTreeOperator;
052:
053: import org.netbeans.modules.visualweb.gravy.*;
054: import org.netbeans.modules.visualweb.gravy.designer.DesignerPaneOperator;
055: import org.netbeans.modules.visualweb.gravy.properties.SheetTableOperator;
056: import org.netbeans.modules.visualweb.gravy.toolbox.PaletteContainerOperator;
057: import org.netbeans.modules.visualweb.test.components.util.ComponentUtils;
058: import org.netbeans.modules.visualweb.gravy.dataconnectivity.ServerNavigatorOperator;
059:
060: import java.io.File;
061: import java.awt.Point;
062: import java.io.IOException;
063:
064: /**
065: * @author Lark Fitzgerald (lark.fitzgerald@sun.com)
066: */
067: public class AcceptanceTest extends RaveTestCase {
068:
069: //Project variables
070: public String _sharedBundle = "org.netbeans.modules.visualweb.test.components.Component";
071: public String _privateBundle = "org.netbeans.modules.visualweb.test.components.layout.commontasks.Acceptance";
072: public String _projectName = Bundle.getStringTrimmed(
073: _privateBundle, "projectName");
074: public String _projectServer = Bundle.getStringTrimmed(
075: _sharedBundle, "projectServer");
076: public String _logFileLocation = Bundle.getStringTrimmed(
077: _sharedBundle, "logFile");
078: public String _logFile = System.getProperty("xtest.workdir")
079: + File.separator + _logFileLocation;
080: public String _exception = Bundle.getStringTrimmed(_sharedBundle,
081: "Exception");
082: public String _close = Bundle.getStringTrimmed(_sharedBundle,
083: "close");
084: public String _run = Bundle.getStringTrimmed(_sharedBundle, "Run");
085: public String _buildSuccess = Bundle.getStringTrimmed(
086: _sharedBundle, "buildSuccess");
087: public String _true = Bundle
088: .getStringTrimmed(_sharedBundle, "true");
089:
090: //Palette variables
091: public String _basicPalette = Bundle.getStringTrimmed(
092: _sharedBundle, "basicPalette");
093: public String _basicButton = Bundle.getStringTrimmed(_sharedBundle,
094: "basicButton");
095: public String _compositePalette = Bundle.getStringTrimmed(
096: _sharedBundle, "compositePalette");
097: public String _compositeCommonTasksSection = Bundle
098: .getStringTrimmed(_sharedBundle,
099: "compositeCommonTasksSection");
100: public String _compositeCommonTasksGroup = Bundle.getStringTrimmed(
101: _sharedBundle, "compositeCommonTasksGroup");
102: public String _compositeCommonTask = Bundle.getStringTrimmed(
103: _sharedBundle, "compositeCommonTask");
104:
105: //drop points
106: public int _x = Integer.parseInt(Bundle.getStringTrimmed(
107: _privateBundle, "x"));
108: public int _commontaskssection1y = Integer.parseInt(Bundle
109: .getStringTrimmed(_privateBundle, "commontaskssection1y"));
110: public int _commontasksgroup1y = Integer.parseInt(Bundle
111: .getStringTrimmed(_privateBundle, "commontasksgroup1y"));
112: public int _commontask1y = Integer.parseInt(Bundle
113: .getStringTrimmed(_privateBundle, "commontask1y"));
114: public int _button1y = Integer.parseInt(Bundle.getStringTrimmed(
115: _privateBundle, "button1y"));
116:
117: //Outline names
118: public String _outlineForm1 = Bundle.getStringTrimmed(
119: _sharedBundle, "outlineForm1");
120: public String _commonTasksSection1 = Bundle.getStringTrimmed(
121: _privateBundle, "commontaskssection1");
122: public String _commonTasksGroup1 = Bundle.getStringTrimmed(
123: _privateBundle, "commontasksgroup1");
124: public String _commonTask1 = Bundle.getStringTrimmed(
125: _privateBundle, "commontask1");
126:
127: //undeployment
128: public String _undeploy = Bundle.getStringTrimmed(_sharedBundle,
129: "undeploy");
130: public String _refresh = Bundle.getStringTrimmed(_sharedBundle,
131: "refresh");
132: public String _serverPath = Bundle.getStringTrimmed(_sharedBundle,
133: "serverPath");
134: public String _deploymentPath = Bundle.getStringTrimmed(
135: _sharedBundle, "deploymentPathGlassfish");
136: public String _separator = Bundle.getStringTrimmed(_sharedBundle,
137: "separator");
138:
139: Point clickPoint, dropPoint;
140: public static DesignerPaneOperator designer;
141: public static PaletteContainerOperator palette;
142: public static DocumentOutlineOperator outline;
143: public static SheetTableOperator sheet;
144: public static DeploymentDialogOperator deploy;
145: public static ServerNavigatorOperator explorer;
146: public int row;
147:
148: public AcceptanceTest(String testName) {
149: super (testName);
150: }
151:
152: public static Test suite() {
153: TestSuite suite = new NbTestSuite();
154: suite.addTest(new AcceptanceTest("testCreateWebProject"));
155: suite.addTest(new AcceptanceTest("testAddCommonTasksSection"));
156: suite
157: .addTest(new AcceptanceTest(
158: "testVerifyCommonTasksSection"));
159: suite.addTest(new AcceptanceTest("testAddCommonTasksGroup"));
160: suite.addTest(new AcceptanceTest("testVerifyCommonTasksGroup"));
161: suite.addTest(new AcceptanceTest("testAddCommonTask"));
162: suite.addTest(new AcceptanceTest("testVerifyCommonTask"));
163: suite.addTest(new AcceptanceTest("testDeploy"));
164: suite.addTest(new AcceptanceTest("testCloseWebProject"));
165: suite.addTest(new AcceptanceTest("testUndeploy"));
166: suite.addTest(new AcceptanceTest("testCheckIDELog"));
167:
168: return suite;
169: }
170:
171: /** method called before each testcase
172: */
173: protected void setUp() {
174: System.out.println("######## " + getName() + " #######");
175: }
176:
177: /** method called after each testcase
178: */
179: protected void tearDown() {
180: System.out.println("######## " + getName()
181: + " Finished #######");
182: }
183:
184: /*
185: * Create Web Project
186: *
187: */
188: public void testCreateWebProject() {
189: startTest();
190: log("**Creating Project");
191: //Create Project
192: try {
193: ComponentUtils.createNewProject(_projectName);
194: } catch (Exception e) {
195: log(">> Project Creation Failed");
196: e.printStackTrace();
197: log(e.toString());
198: fail();
199: }
200: log("**Done");
201: endTest();
202: }
203:
204: /*
205: * Add a password to designer
206: */
207: public void testAddCommonTasksSection() {
208: startTest();
209: log("**Initialize");
210: designer = new DesignerPaneOperator(RaveWindowOperator
211: .getDefaultRave());
212: palette = new PaletteContainerOperator(_compositePalette);
213: try {
214: Thread.sleep(5000);
215: } catch (Exception e) {
216: }
217:
218: log("**Add grid panel to designer");
219: clickPoint = palette
220: .getClickPoint(_compositeCommonTasksSection);
221: dropPoint = new Point(_x, _commontaskssection1y);
222: palette.addComponent(_compositeCommonTasksSection, designer,
223: dropPoint);
224: try {
225: Thread.sleep(2000);
226: } catch (Exception e) {
227: }
228:
229: log("**Done.");
230: endTest();
231:
232: }
233:
234: /*
235: * Verify Common Tasks Section in the outline
236: */
237: public void testVerifyCommonTasksSection() {
238: startTest();
239: log("**Initialize");
240: DocumentOutlineOperator doo = new DocumentOutlineOperator(Util
241: .getMainWindow());
242: Util.wait(2000);
243:
244: log("**Select common tasks section from Outline window");
245: String path = _outlineForm1 + _commonTasksSection1;
246: doo.verify();
247: // doo.clickOnPath(path);
248: doo.selectPath(path);
249: Util.wait(5000);
250: endTest();
251: }
252:
253: /*
254: * Add a common tasks group to designer
255: */
256: public void testAddCommonTasksGroup() {
257: startTest();
258: log("**Initialize");
259: designer = new DesignerPaneOperator(RaveWindowOperator
260: .getDefaultRave());
261: palette = new PaletteContainerOperator(_compositePalette);
262: try {
263: Thread.sleep(5000);
264: } catch (Exception e) {
265: }
266:
267: log("**Add common task group to designer");
268: clickPoint = palette.getClickPoint(_compositeCommonTasksGroup);
269: dropPoint = new Point(_x + 25, _commontasksgroup1y + 25);
270: palette.addComponent(_compositeCommonTasksGroup, designer,
271: dropPoint);
272: try {
273: Thread.sleep(2000);
274: } catch (Exception e) {
275: }
276:
277: log("**Done.");
278: endTest();
279: }
280:
281: /*
282: * Verify Common Tasks Group in the outline
283: */
284: public void testVerifyCommonTasksGroup() {
285: startTest();
286: log("**Initialize");
287: DocumentOutlineOperator doo = new DocumentOutlineOperator(Util
288: .getMainWindow());
289: Util.wait(2000);
290:
291: log("**Select common tasks group from Outline window");
292: String path = _outlineForm1 + _commonTasksSection1 + _separator
293: + _commonTasksGroup1;
294: doo.verify();
295: // doo.clickOnPath(path);
296: doo.selectPath(path);
297: Util.wait(5000);
298: endTest();
299: }
300:
301: /*
302: * Add a common task to designer
303: */
304: public void testAddCommonTask() {
305: startTest();
306: log("**Initialize");
307: designer = new DesignerPaneOperator(RaveWindowOperator
308: .getDefaultRave());
309: palette = new PaletteContainerOperator(_compositePalette);
310: try {
311: Thread.sleep(5000);
312: } catch (Exception e) {
313: }
314:
315: log("**Add common task to designer");
316: clickPoint = palette.getClickPoint(_compositeCommonTask);
317: dropPoint = new Point(_x + 50, _commontask1y + 50);
318: palette.addComponent(_compositeCommonTask, designer, dropPoint);
319: try {
320: Thread.sleep(2000);
321: } catch (Exception e) {
322: }
323:
324: log("**Done.");
325: endTest();
326: }
327:
328: /*
329: * Verify Common Task in the outline
330: */
331: public void testVerifyCommonTask() {
332: startTest();
333: log("**Initialize");
334: DocumentOutlineOperator doo = new DocumentOutlineOperator(Util
335: .getMainWindow());
336: Util.wait(2000);
337:
338: log("**Select common task 2 from Outline window");
339: String path = _outlineForm1 + _commonTasksSection1 + _separator
340: + _commonTasksGroup1 + _separator + _commonTask1;
341: doo.verify();
342: // doo.clickOnPath(path);
343: doo.selectPath(path);
344: Util.wait(5000);
345: endTest();
346: }
347:
348: /*
349: * Deploy application
350: */
351: public void testDeploy() {
352: startTest();
353: //need to wait responce
354: Waiter deploymentWaiter = new Waiter(new Waitable() {
355: public Object actionProduced(Object output) {
356: String text = ((OutputOperator) output).getText();
357: if (text.indexOf(_buildSuccess) != -1)
358: return _true;
359: return null;
360:
361: }
362:
363: public String getDescription() {
364: return ("Waiting Project Deployed");
365: }
366: });
367: log("Deploy from menu");
368: ProjectNavigatorOperator.pressPopupItemOnNode(_projectName,
369: _run);
370: TestUtils.wait(2000);
371: OutputOperator outputWindow = new OutputOperator();
372: deploymentWaiter.getTimeouts().setTimeout("Waiter.WaitingTime",
373: 240000);
374: log("wait until " + _buildSuccess);
375: try {
376: deploymentWaiter.waitAction(outputWindow);
377: } catch (InterruptedException e) {
378: log(outputWindow.getText());
379: e.printStackTrace();
380: fail("Deployment error: " + e);
381: }
382: log("Deployment complete");
383: endTest();
384: }
385:
386: /*
387: * Close Project
388: *
389: */
390: public void testCloseWebProject() {
391: startTest();
392: Util.saveAllAPICall();
393: new ProjectNavigatorOperator().pressPopupItemOnNode(
394: _projectName, _close);
395: //TestUtils.closeCurrentProject();
396: TestUtils.wait(5000);
397: endTest();
398: }
399:
400: /* Need to undeploy project to finish tests correctly */
401: public void testUndeploy() {
402: startTest();
403: log("Initialize");
404: explorer = ServerNavigatorOperator.showNavigatorOperator();
405: String serverPath = _serverPath + _projectServer; //Current deployment server
406: String deploymentPath = serverPath + _deploymentPath; //glassfish specific
407: String applicationPath = deploymentPath + _separator
408: + _projectName; //project name
409:
410: // Select the Server Navigator and set the JTreeOperator
411: log("get explorer");
412: new QueueTool().waitEmpty(100); //??
413: explorer.requestFocus();
414: JTreeOperator tree = explorer.getTree();
415: try {
416: Thread.sleep(4000);
417: } catch (Exception e) {
418: } // Sleep 4 secs to make sure Server Navigator is in focus
419:
420: // Need to refresh J2EE AppServer node
421: log("refresh");
422: explorer.pushPopup(tree, serverPath, _refresh);
423: TestUtils.wait(1000);
424:
425: log("refresh deployment path: " + deploymentPath);
426: TestUtils.wait(1000);
427: explorer.selectPath(deploymentPath);
428: explorer.getTree().expandPath(
429: explorer.getTree().findPath(deploymentPath));
430: explorer.pushPopup(tree, deploymentPath, _refresh);
431: TestUtils.wait(1000);
432:
433: log("undeploy Path: " + applicationPath);
434: explorer.selectPath(applicationPath);
435: TestUtils.wait(1000);
436:
437: log("Push Menu Undeploy...");
438: explorer.pushPopup(explorer.getTree(), applicationPath,
439: _undeploy);
440: TestUtils.wait(5000);
441: endTest();
442: }
443:
444: public void testCheckIDELog() {
445: startTest();
446: try {
447: String err = ComponentUtils.hasUnexpectedException();
448: String str = "";
449: if (!(err.equals(""))) {
450: assertTrue(
451: "Unexpected exceptions found in message.log: "
452: + err, str.equals(""));
453: }
454: } catch (IOException ioe) {
455: ioe.printStackTrace();
456: fail("Failed to open message.log : " + ioe);
457: }
458: endTest();
459: }
460: }
|