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.calendar;
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:
064: /**
065: * @author Lark Fitzgerald (lark.fitzgerald@sun.com)
066: */
067: public class AcceptanceTest extends RaveTestCase {
068:
069: //Project variables
070: public String _sharedBundle = "org.netbeans.modules.visualweb.test.components.Component";
071: public String _privateBundle = "org.netbeans.modules.visualweb.test.components.converters.calendar.Acceptance";
072: public String _projectName = Bundle.getStringTrimmed(
073: _privateBundle, "projectName");
074: public String _projectServer = Bundle.getStringTrimmed(
075: _sharedBundle, "projectServer");
076: public String _logFileLocation = Bundle.getStringTrimmed(
077: _sharedBundle, "logFile");
078: public String _logFile = System.getProperty("xtest.workdir")
079: + File.separator + _logFileLocation;
080: public String _exception = Bundle.getStringTrimmed(_sharedBundle,
081: "Exception");
082: public String _close = Bundle.getStringTrimmed(_sharedBundle,
083: "close");
084: public String _run = Bundle.getStringTrimmed(_sharedBundle, "Run");
085: public String _buildSuccess = Bundle.getStringTrimmed(
086: _sharedBundle, "buildSuccess");
087: public String _true = Bundle
088: .getStringTrimmed(_sharedBundle, "true");
089:
090: //Outline variables
091: public String _outlinePage1 = Bundle.getStringTrimmed(
092: _sharedBundle, "outlinePage1");
093:
094: //Palette variables
095: public String _basicPalette = Bundle.getStringTrimmed(
096: _sharedBundle, "basicPalette");
097: public String _basicButton = Bundle.getStringTrimmed(_sharedBundle,
098: "basicButton");
099: public String _converterPalette = Bundle.getStringTrimmed(
100: _sharedBundle, "converterPalette");
101: public String _converterCalendar = Bundle.getStringTrimmed(
102: _sharedBundle, "converterCalendar");
103:
104: //drop points
105: public int _x = Integer.parseInt(Bundle.getStringTrimmed(
106: _privateBundle, "x"));
107: public int _calendar1y = Integer.parseInt(Bundle.getStringTrimmed(
108: _privateBundle, "calendar1y"));
109: public int _button1y = Integer.parseInt(Bundle.getStringTrimmed(
110: _privateBundle, "button1y"));
111:
112: public String _calendarConverter1 = Bundle.getStringTrimmed(
113: _privateBundle, "calendarConverter1");
114:
115: //undeployment
116: public String _undeploy = Bundle.getStringTrimmed(_sharedBundle,
117: "undeploy");
118: public String _refresh = Bundle.getStringTrimmed(_sharedBundle,
119: "refresh");
120: public String _serverPath = Bundle.getStringTrimmed(_sharedBundle,
121: "serverPath");
122: public String _deploymentPath = Bundle.getStringTrimmed(
123: _sharedBundle, "deploymentPathGlassfish");
124: public String _separator = Bundle.getStringTrimmed(_sharedBundle,
125: "separator");
126:
127: Point clickPoint, dropPoint;
128: public static DesignerPaneOperator designer;
129: public static PaletteContainerOperator palette;
130: public static DocumentOutlineOperator outline;
131: public static SheetTableOperator sheet;
132: public static DeploymentDialogOperator deploy;
133: public static ServerNavigatorOperator explorer;
134: public int row;
135:
136: public AcceptanceTest(String testName) {
137: super (testName);
138: }
139:
140: public static Test suite() {
141: TestSuite suite = new NbTestSuite();
142: suite.addTest(new AcceptanceTest("testCreateWebProject"));
143: suite.addTest(new AcceptanceTest("testAddCalendarConverter"));
144: suite
145: .addTest(new AcceptanceTest(
146: "testVerifyCalendarConverter"));
147: suite.addTest(new AcceptanceTest("testAddButton"));
148: suite.addTest(new AcceptanceTest("testDeploy"));
149: suite.addTest(new AcceptanceTest("testCloseWebProject"));
150: suite.addTest(new AcceptanceTest("testUndeploy"));
151: suite.addTest(new AcceptanceTest("testCheckIDELog"));
152:
153: return suite;
154: }
155:
156: /** method called before each testcase
157: */
158: protected void setUp() {
159: System.out.println("######## " + getName() + " #######");
160: }
161:
162: /** method called after each testcase
163: */
164: protected void tearDown() {
165: System.out.println("######## " + getName()
166: + " Finished #######");
167: }
168:
169: /*
170: * Create Web Project
171: *
172: */
173: public void testCreateWebProject() {
174: startTest();
175: log("**Creating Project");
176: //Create Project
177: try {
178: ComponentUtils.createNewProject(_projectName);
179: } catch (Exception e) {
180: log(">> Project Creation Failed");
181: e.printStackTrace();
182: log(e.toString());
183: fail();
184: }
185: log("**Done");
186: endTest();
187: }
188:
189: /*
190: * Add a password to designer
191: */
192: public void testAddCalendarConverter() {
193: startTest();
194: log("**Initialize");
195: designer = new DesignerPaneOperator(RaveWindowOperator
196: .getDefaultRave());
197: palette = new PaletteContainerOperator(_converterPalette);
198: try {
199: Thread.sleep(5000);
200: } catch (Exception e) {
201: }
202:
203: log("**Add calendar converter to designer");
204: clickPoint = palette.getClickPoint(_converterCalendar);
205: dropPoint = new Point(_x, _calendar1y);
206: palette.addComponent(_converterCalendar, designer, dropPoint);
207: try {
208: Thread.sleep(2000);
209: } catch (Exception e) {
210: }
211:
212: log("**Done.");
213: endTest();
214:
215: }
216:
217: /*
218: * Add a button to designer
219: */
220: public void testAddButton() {
221: startTest();
222: log("**Initialize");
223: designer = new DesignerPaneOperator(RaveWindowOperator
224: .getDefaultRave());
225: palette = new PaletteContainerOperator(_basicPalette);
226: try {
227: Thread.sleep(5000);
228: } catch (Exception e) {
229: }
230:
231: log("**Add Button to designer");
232: clickPoint = palette.getClickPoint(_basicButton);
233: dropPoint = new Point(_x, _button1y);
234: palette.dndPaletteComponent(_basicButton, designer, dropPoint);
235: try {
236: Thread.sleep(2000);
237: } catch (Exception e) {
238: }
239:
240: log("**Done.");
241: endTest();
242: }
243:
244: /*
245: * Verify Calendar converter in outline window
246: */
247: public void testVerifyCalendarConverter() {
248: startTest();
249: log("**Initialize");
250: DocumentOutlineOperator doo = new DocumentOutlineOperator(Util
251: .getMainWindow());
252: Util.wait(2000);
253:
254: log("**Select calendarConverter1 from Outline window");
255: String path = _outlinePage1 + _calendarConverter1;
256: doo.verify();
257: // doo.clickOnPath(path);
258: doo.selectPath(path);
259: Util.wait(5000);
260:
261: log("**Done.");
262: endTest();
263: }
264:
265: /*
266: * Deploy application
267: */
268: public void testDeploy() {
269: startTest();
270: //need to wait responce
271: Waiter deploymentWaiter = new Waiter(new Waitable() {
272: public Object actionProduced(Object output) {
273: String text = ((OutputOperator) output).getText();
274: if (text.indexOf(_buildSuccess) != -1)
275: return _true;
276: return null;
277:
278: }
279:
280: public String getDescription() {
281: return ("Waiting Project Deployed");
282: }
283: });
284: log("Deploy from menu");
285: ProjectNavigatorOperator.pressPopupItemOnNode(_projectName,
286: _run);
287: TestUtils.wait(2000);
288: OutputOperator outputWindow = new OutputOperator();
289: deploymentWaiter.getTimeouts().setTimeout("Waiter.WaitingTime",
290: 240000);
291: log("wait until " + _buildSuccess);
292: try {
293: deploymentWaiter.waitAction(outputWindow);
294: } catch (InterruptedException e) {
295: log(outputWindow.getText());
296: e.printStackTrace();
297: fail("Deployment error: " + e);
298: }
299: log("Deployment complete");
300: endTest();
301: }
302:
303: /*
304: * Close Project
305: *
306: */
307: public void testCloseWebProject() {
308: startTest();
309: Util.saveAllAPICall();
310: new ProjectNavigatorOperator().pressPopupItemOnNode(
311: _projectName, _close);
312: //TestUtils.closeCurrentProject();
313: TestUtils.wait(5000);
314: endTest();
315: }
316:
317: /* Need to undeploy project to finish tests correctly */
318: public void testUndeploy() {
319: startTest();
320: log("Initialize");
321: explorer = ServerNavigatorOperator.showNavigatorOperator();
322: String serverPath = _serverPath + _projectServer; //Current deployment server
323: String deploymentPath = serverPath + _deploymentPath; //glassfish specific
324: String applicationPath = deploymentPath + _separator
325: + _projectName; //project name
326:
327: // Select the Server Navigator and set the JTreeOperator
328: log("get explorer");
329: new QueueTool().waitEmpty(100); //??
330: explorer.requestFocus();
331: JTreeOperator tree = explorer.getTree();
332: try {
333: Thread.sleep(4000);
334: } catch (Exception e) {
335: } // Sleep 4 secs to make sure Server Navigator is in focus
336:
337: // Need to refresh J2EE AppServer node
338: log("refresh");
339: explorer.pushPopup(tree, serverPath, _refresh);
340: TestUtils.wait(4000);
341:
342: log("refresh deployment path: " + deploymentPath);
343: TestUtils.wait(4000);
344: explorer.selectPath(deploymentPath);
345: explorer.getTree().expandPath(
346: explorer.getTree().findPath(deploymentPath));
347: explorer.pushPopup(tree, deploymentPath, _refresh);
348: TestUtils.wait(4000);
349:
350: log("undeploy Path: " + applicationPath);
351: explorer.selectPath(applicationPath);
352: TestUtils.wait(1000);
353:
354: log("Push Menu Undeploy...");
355: explorer.pushPopup(explorer.getTree(), applicationPath,
356: _undeploy);
357: TestUtils.wait(5000);
358: endTest();
359: }
360:
361: public void testCheckIDELog() {
362: startTest();
363: try {
364: String err = ComponentUtils.hasUnexpectedException();
365: String str = "";
366: if (!(err.equals(""))) {
367: assertTrue(
368: "Unexpected exceptions found in message.log: "
369: + err, str.equals(""));
370: }
371: } catch (IOException ioe) {
372: ioe.printStackTrace();
373: fail("Failed to open message.log : " + ioe);
374: }
375: endTest();
376: }
377: }
|