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