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