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