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.sqltime;
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.sqltime.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 _converterSqlTime = Bundle.getStringTrimmed(
102: _sharedBundle, "converterSQLTime");
103:
104: //drop points
105: public int _x = Integer.parseInt(Bundle.getStringTrimmed(
106: _privateBundle, "x"));
107: public int _sqltime1y = Integer.parseInt(Bundle.getStringTrimmed(
108: _privateBundle, "sqltime1y"));
109: public int _button1y = Integer.parseInt(Bundle.getStringTrimmed(
110: _privateBundle, "button1y"));
111:
112: public String _sqlTimeConverter1 = Bundle.getStringTrimmed(
113: _privateBundle, "sqlTimeConverter1");
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("testAddSqlTimeConverter"));
144: suite.addTest(new AcceptanceTest("testVerifySqlTimeConverter"));
145: suite.addTest(new AcceptanceTest("testAddButton"));
146: suite.addTest(new AcceptanceTest("testDeploy"));
147: suite.addTest(new AcceptanceTest("testCloseWebProject"));
148: suite.addTest(new AcceptanceTest("testUndeploy"));
149: suite.addTest(new AcceptanceTest("testCheckIDELog"));
150:
151: return suite;
152: }
153:
154: /** method called before each testcase
155: */
156: protected void setUp() {
157: System.out.println("######## " + getName() + " #######");
158: }
159:
160: /** method called after each testcase
161: */
162: protected void tearDown() {
163: System.out.println("######## " + getName()
164: + " Finished #######");
165: }
166:
167: /*
168: * Create Web Project
169: *
170: */
171: public void testCreateWebProject() {
172: startTest();
173: log("**Creating Project");
174: //Create Project
175: try {
176: ComponentUtils.createNewProject(_projectName);
177: } catch (Exception e) {
178: log(">> Project Creation Failed");
179: e.printStackTrace();
180: log(e.toString());
181: fail();
182: }
183: log("**Done");
184: endTest();
185: }
186:
187: /*
188: * Add a password to designer
189: */
190: public void testAddSqlTimeConverter() {
191: startTest();
192: log("**Initialize");
193: designer = new DesignerPaneOperator(RaveWindowOperator
194: .getDefaultRave());
195: palette = new PaletteContainerOperator(_converterPalette);
196: try {
197: Thread.sleep(5000);
198: } catch (Exception e) {
199: }
200:
201: log("**Add sql time converter to designer");
202: clickPoint = palette.getClickPoint(_converterSqlTime);
203: dropPoint = new Point(_x, _sqltime1y);
204: palette.addComponent(_converterSqlTime, designer, dropPoint);
205: try {
206: Thread.sleep(2000);
207: } catch (Exception e) {
208: }
209:
210: log("**Done.");
211: endTest();
212:
213: }
214:
215: /*
216: * Verify sql time converter in outline window
217: */
218: public void testVerifySqlTimeConverter() {
219: startTest();
220: log("**Initialize");
221: DocumentOutlineOperator doo = new DocumentOutlineOperator(Util
222: .getMainWindow());
223: Util.wait(2000);
224:
225: log("**Select sqlTimeConverter1 from Outline window");
226: String path = _outlinePage1 + _sqlTimeConverter1;
227: doo.verify();
228: // doo.clickOnPath(path);
229: doo.selectPath(path);
230: Util.wait(5000);
231:
232: log("**Done.");
233: endTest();
234: }
235:
236: /*
237: * Add a button to designer
238: */
239: public void testAddButton() {
240: startTest();
241: log("**Initialize");
242: designer = new DesignerPaneOperator(RaveWindowOperator
243: .getDefaultRave());
244: palette = new PaletteContainerOperator(_basicPalette);
245: try {
246: Thread.sleep(5000);
247: } catch (Exception e) {
248: }
249:
250: log("**Add Button to designer");
251: clickPoint = palette.getClickPoint(_basicButton);
252: dropPoint = new Point(_x, _button1y);
253: palette.dndPaletteComponent(_basicButton, designer, dropPoint);
254: try {
255: Thread.sleep(2000);
256: } catch (Exception e) {
257: }
258:
259: log("**Done.");
260: Util.saveAllAPICall();
261: endTest();
262: }
263:
264: /*
265: * Deploy application
266: */
267: public void testDeploy() {
268: startTest();
269: //need to wait responce
270: Waiter deploymentWaiter = new Waiter(new Waitable() {
271: public Object actionProduced(Object output) {
272: String text = ((OutputOperator) output).getText();
273: if (text.indexOf(_buildSuccess) != -1)
274: return _true;
275: return null;
276:
277: }
278:
279: public String getDescription() {
280: return ("Waiting Project Deployed");
281: }
282: });
283: log("Deploy from menu");
284: ProjectNavigatorOperator.pressPopupItemOnNode(_projectName,
285: _run);
286: TestUtils.wait(2000);
287: OutputOperator outputWindow = new OutputOperator();
288: deploymentWaiter.getTimeouts().setTimeout("Waiter.WaitingTime",
289: 240000);
290: log("wait until " + _buildSuccess);
291: try {
292: deploymentWaiter.waitAction(outputWindow);
293: } catch (InterruptedException e) {
294: log(outputWindow.getText());
295: e.printStackTrace();
296: fail("Deployment error: " + e);
297: }
298: log("Deployment complete");
299: endTest();
300: }
301:
302: /*
303: * Close Project
304: *
305: */
306: public void testCloseWebProject() {
307: startTest();
308: Util.saveAllAPICall();
309: new ProjectNavigatorOperator().pressPopupItemOnNode(
310: _projectName, _close);
311: //TestUtils.closeCurrentProject();
312: TestUtils.wait(5000);
313: endTest();
314: }
315:
316: /* Need to undeploy project to finish tests correctly */
317: public void testUndeploy() {
318: startTest();
319: log("Initialize");
320: explorer = ServerNavigatorOperator.showNavigatorOperator();
321: String serverPath = _serverPath + _projectServer; //Current deployment server
322: String deploymentPath = serverPath + _deploymentPath; //glassfish specific
323: String applicationPath = deploymentPath + _separator
324: + _projectName; //project name
325:
326: // Select the Server Navigator and set the JTreeOperator
327: log("get explorer");
328: new QueueTool().waitEmpty(100); //??
329: explorer.requestFocus();
330: JTreeOperator tree = explorer.getTree();
331: try {
332: Thread.sleep(4000);
333: } catch (Exception e) {
334: } // Sleep 4 secs to make sure Server Navigator is in focus
335:
336: // Need to refresh J2EE AppServer node
337: log("refresh");
338: explorer.pushPopup(tree, serverPath, _refresh);
339: TestUtils.wait(1000);
340:
341: log("refresh deployment path: " + deploymentPath);
342: TestUtils.wait(1000);
343: explorer.selectPath(deploymentPath);
344: explorer.getTree().expandPath(
345: explorer.getTree().findPath(deploymentPath));
346: explorer.pushPopup(tree, deploymentPath, _refresh);
347: TestUtils.wait(1000);
348:
349: log("undeploy Path: " + applicationPath);
350: explorer.selectPath(applicationPath);
351: TestUtils.wait(1000);
352:
353: log("Push Menu Undeploy...");
354: explorer.pushPopup(explorer.getTree(), applicationPath,
355: _undeploy);
356: TestUtils.wait(5000);
357: endTest();
358: }
359:
360: public void testCheckIDELog() {
361: startTest();
362: try {
363: String err = ComponentUtils.hasUnexpectedException();
364: String str = "";
365: if (!(err.equals(""))) {
366: assertTrue(
367: "Unexpected exceptions found in message.log: "
368: + err, str.equals(""));
369: }
370: } catch (IOException ioe) {
371: ioe.printStackTrace();
372: fail("Failed to open message.log : " + ioe);
373: }
374: endTest();
375: }
376: }
|