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