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