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