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.validators.longrange;
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.validators.longrange.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 _outlinePage1 = Bundle.getStringTrimmed(
093: _sharedBundle, "outlinePage1");
094:
095: //Palette variables
096: public String _basicPalette = Bundle.getStringTrimmed(
097: _sharedBundle, "basicPalette");
098: public String _basicButton = Bundle.getStringTrimmed(_sharedBundle,
099: "basicButton");
100: public String _basicTextField = Bundle.getStringTrimmed(
101: _sharedBundle, "basicTextField");
102: public String _validatorPalette = Bundle.getStringTrimmed(
103: _sharedBundle, "validatorPalette");
104: public String _validatorLongRange = Bundle.getStringTrimmed(
105: _sharedBundle, "validatorLongRange");
106:
107: //drop points
108: public int _x = Integer.parseInt(Bundle.getStringTrimmed(
109: _privateBundle, "x"));
110: public int _longrange1y = Integer.parseInt(Bundle.getStringTrimmed(
111: _privateBundle, "longrange1y"));
112: public int _button1y = Integer.parseInt(Bundle.getStringTrimmed(
113: _privateBundle, "button1y"));
114: public String _longRangeValidator1 = Bundle.getStringTrimmed(
115: _privateBundle, "longRangeValidator1");
116: public int _textfield1y = Integer.parseInt(Bundle.getStringTrimmed(
117: _privateBundle, "textfield1y"));
118:
119: //properties
120: public String _propertyMaximum = Bundle.getStringTrimmed(
121: _sharedBundle, "propertyMaximum");
122: public String _propertyMinimum = Bundle.getStringTrimmed(
123: _sharedBundle, "propertyMinimum");
124: public String _maxValue = Bundle.getStringTrimmed(_privateBundle,
125: "maxValue");
126: public String _minValue = Bundle.getStringTrimmed(_privateBundle,
127: "minValue");
128:
129: //undeployment
130: public String _undeploy = Bundle.getStringTrimmed(_sharedBundle,
131: "undeploy");
132: public String _refresh = Bundle.getStringTrimmed(_sharedBundle,
133: "refresh");
134: public String _serverPath = Bundle.getStringTrimmed(_sharedBundle,
135: "serverPath");
136: public String _deploymentPath = Bundle.getStringTrimmed(
137: _sharedBundle, "deploymentPathGlassfish");
138: public String _separator = Bundle.getStringTrimmed(_sharedBundle,
139: "separator");
140:
141: Point clickPoint, dropPoint;
142: public static DesignerPaneOperator designer;
143: public static PaletteContainerOperator palette;
144: public static DocumentOutlineOperator outline;
145: public static SheetTableOperator sheet;
146: public static DeploymentDialogOperator deploy;
147: public static ServerNavigatorOperator explorer;
148: public int row;
149:
150: public AcceptanceTest(String testName) {
151: super (testName);
152: }
153:
154: public static Test suite() {
155: TestSuite suite = new NbTestSuite();
156: suite.addTest(new AcceptanceTest("testCreateWebProject"));
157: suite.addTest(new AcceptanceTest("testAddTextField1"));
158: suite.addTest(new AcceptanceTest("testAddLongRangeValidator"));
159: suite.addTest(new AcceptanceTest(
160: "testConfigureLongRangeValidator"));
161: suite.addTest(new AcceptanceTest("testAddButton"));
162: suite.addTest(new AcceptanceTest("testDeploy"));
163: suite.addTest(new AcceptanceTest("testCloseWebProject"));
164: suite.addTest(new AcceptanceTest("testUndeploy"));
165: suite.addTest(new AcceptanceTest("testCheckIDELog"));
166:
167: return suite;
168: }
169:
170: /** method called before each testcase
171: */
172: protected void setUp() {
173: System.out.println("######## " + getName() + " #######");
174: }
175:
176: /** method called after each testcase
177: */
178: protected void tearDown() {
179: System.out.println("######## " + getName()
180: + " Finished #######");
181: }
182:
183: /*
184: * Create Web Project
185: *
186: */
187: public void testCreateWebProject() {
188: startTest();
189: log("**Creating Project");
190: //Create Project
191: try {
192: ComponentUtils.createNewProject(_projectName);
193: } catch (Exception e) {
194: log(">> Project Creation Failed");
195: e.printStackTrace();
196: log(e.toString());
197: fail();
198: }
199: log("**Done");
200:
201: endTest();
202: }
203:
204: /*
205: * Add textField1
206: */
207: public void testAddTextField1() {
208: startTest();
209:
210: log("**Initialize");
211: designer = new DesignerPaneOperator(RaveWindowOperator
212: .getDefaultRave());
213: palette = new PaletteContainerOperator(_basicPalette);
214: try {
215: Thread.sleep(5000);
216: } catch (Exception e) {
217: }
218:
219: log("**Add textField1 to designer");
220: clickPoint = palette.getClickPoint(_basicTextField);
221: dropPoint = new Point(_x, _textfield1y);
222: palette.dndPaletteComponent(_basicTextField, designer,
223: dropPoint);
224: // palette.addComponent(_basicTextField, designer, dropPoint);
225: try {
226: Thread.sleep(2000);
227: } catch (Exception e) {
228: }
229:
230: log("**Done.");
231: endTest();
232:
233: }
234:
235: /*
236: * Add a long Range Validator to designer
237: */
238: public void testAddLongRangeValidator() {
239: startTest();
240: log("**Initialize");
241: designer = new DesignerPaneOperator(RaveWindowOperator
242: .getDefaultRave());
243: palette = new PaletteContainerOperator(_validatorPalette);
244: try {
245: Thread.sleep(5000);
246: } catch (Exception e) {
247: }
248:
249: log("**Add long range validator to designer");
250: clickPoint = palette.getClickPoint(_validatorLongRange);
251: dropPoint = new Point(_x + 15, _longrange1y + 15);
252: palette.addComponent(_validatorLongRange, designer, dropPoint);
253: try {
254: Thread.sleep(2000);
255: } catch (Exception e) {
256: }
257:
258: log("**Done.");
259: endTest();
260:
261: }
262:
263: /*
264: * Configure long Range in outline window
265: */
266: public void testConfigureLongRangeValidator() {
267: startTest();
268: log("**Initialize");
269: DocumentOutlineOperator doo = new DocumentOutlineOperator(Util
270: .getMainWindow());
271: Util.wait(2000);
272:
273: log("**Select doubleRangeValidator1 from Outline window");
274: String path = _outlinePage1 + _longRangeValidator1;
275: doo.verify();
276: // doo.clickOnPath(path);
277: doo.selectPath(path);
278: Util.wait(5000);
279:
280: log("**Set Max property value"); //1000
281: sheet = new SheetTableOperator();
282: int row = sheet.findCellRow(_propertyMaximum);
283: sheet.clickForEdit(row, 1);
284: sheet.clickForEdit(row, 1);
285: new JTextComponentOperator(sheet).enterText(_maxValue);
286:
287: log("**Set Min property value"); //-273.15
288: row = sheet.findCellRow(_propertyMinimum);
289: sheet.clickForEdit(row, 1);
290: sheet.clickForEdit(row, 1);
291: new JTextComponentOperator(sheet).enterText(_minValue);
292:
293: log("**Done.");
294: endTest();
295: }
296:
297: /*
298: * Verify length validator in outline window
299: */
300: public void testVerifyLongRangeValidator() {
301: startTest();
302: log("**Initialize");
303: DocumentOutlineOperator doo = new DocumentOutlineOperator(Util
304: .getMainWindow());
305: Util.wait(2000);
306:
307: log("**Select longRangeValidator1 from Outline window");
308: String path = _outlinePage1 + _longRangeValidator1;
309: doo.verify();
310: // doo.clickOnPath(path);
311: doo.selectPath(path);
312: Util.wait(5000);
313:
314: log("**Done.");
315: endTest();
316: }
317:
318: /*
319: * Add a button to designer
320: */
321: public void testAddButton() {
322: startTest();
323: log("**Initialize");
324: designer = new DesignerPaneOperator(RaveWindowOperator
325: .getDefaultRave());
326: palette = new PaletteContainerOperator(_basicPalette);
327: try {
328: Thread.sleep(5000);
329: } catch (Exception e) {
330: }
331:
332: log("**Add Button to designer");
333: clickPoint = palette.getClickPoint(_basicButton);
334: dropPoint = new Point(_x, _button1y);
335: palette.dndPaletteComponent(_basicButton, designer, dropPoint);
336: try {
337: Thread.sleep(2000);
338: } catch (Exception e) {
339: }
340:
341: log("**Done.");
342: endTest();
343: }
344:
345: /*
346: * Deploy application
347: */
348: public void testDeploy() {
349: startTest();
350: //need to wait responce
351: Waiter deploymentWaiter = new Waiter(new Waitable() {
352: public Object actionProduced(Object output) {
353: String text = ((OutputOperator) output).getText();
354: if (text.indexOf(_buildSuccess) != -1)
355: return _true;
356: return null;
357:
358: }
359:
360: public String getDescription() {
361: return ("Waiting Project Deployed");
362: }
363: });
364: log("Deploy from menu");
365: ProjectNavigatorOperator.pressPopupItemOnNode(_projectName,
366: _run);
367: TestUtils.wait(2000);
368: OutputOperator outputWindow = new OutputOperator();
369: deploymentWaiter.getTimeouts().setTimeout("Waiter.WaitingTime",
370: 240000);
371: log("wait until " + _buildSuccess);
372: try {
373: deploymentWaiter.waitAction(outputWindow);
374: } catch (InterruptedException e) {
375: log(outputWindow.getText());
376: e.printStackTrace();
377: fail("Deployment error: " + e);
378: }
379: log("Deployment complete");
380: endTest();
381: }
382:
383: /*
384: * Close Project
385: *
386: */
387: public void testCloseWebProject() {
388: startTest();
389: Util.saveAllAPICall();
390: new ProjectNavigatorOperator().pressPopupItemOnNode(
391: _projectName, _close);
392: //TestUtils.closeCurrentProject();
393: TestUtils.wait(5000);
394: endTest();
395: }
396:
397: /* Need to undeploy project to finish tests correctly */
398: public void testUndeploy() {
399: startTest();
400: log("Initialize");
401: explorer = ServerNavigatorOperator.showNavigatorOperator();
402: String serverPath = _serverPath + _projectServer; //Current deployment server
403: String deploymentPath = serverPath + _deploymentPath; //glassfish specific
404: String applicationPath = deploymentPath + _separator
405: + _projectName; //project name
406:
407: // Select the Server Navigator and set the JTreeOperator
408: log("get explorer");
409: new QueueTool().waitEmpty(100); //??
410: explorer.requestFocus();
411: JTreeOperator tree = explorer.getTree();
412: try {
413: Thread.sleep(4000);
414: } catch (Exception e) {
415: } // Sleep 4 secs to make sure Server Navigator is in focus
416:
417: // Need to refresh J2EE AppServer node
418: log("refresh");
419: explorer.pushPopup(tree, serverPath, _refresh);
420: TestUtils.wait(1000);
421:
422: log("refresh deployment path: " + deploymentPath);
423: TestUtils.wait(1000);
424: explorer.selectPath(deploymentPath);
425: explorer.getTree().expandPath(
426: explorer.getTree().findPath(deploymentPath));
427: explorer.pushPopup(tree, deploymentPath, _refresh);
428: TestUtils.wait(1000);
429:
430: log("undeploy Path: " + applicationPath);
431: explorer.selectPath(applicationPath);
432: TestUtils.wait(1000);
433:
434: log("Push Menu Undeploy...");
435: explorer.pushPopup(explorer.getTree(), applicationPath,
436: _undeploy);
437: TestUtils.wait(5000);
438: endTest();
439: }
440:
441: public void testCheckIDELog() {
442: startTest();
443: try {
444: String err = ComponentUtils.hasUnexpectedException();
445: String str = "";
446: if (!(err.equals(""))) {
447: assertTrue(
448: "Unexpected exceptions found in message.log: "
449: + err, str.equals(""));
450: }
451: } catch (IOException ioe) {
452: ioe.printStackTrace();
453: fail("Failed to open message.log : " + ioe);
454: }
455: endTest();
456: }
457:
458: }
|