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.table.std;
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.gravy.dataconnectivity.ServerNavigatorOperator;
058: import org.netbeans.modules.visualweb.test.components.util.ComponentUtils;
059:
060: import java.awt.Point;
061: import java.io.File;
062: import java.io.IOException;
063:
064: /**
065: * @author Lark Fitzgerald)
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.table.std.AcceptanceTest";
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: //Palette variables
091: public String _standardPalette = Bundle.getStringTrimmed(
092: _sharedBundle, "standardPalette");
093: public String _standardTable = Bundle.getStringTrimmed(
094: _sharedBundle, "standardTable");
095:
096: //drop points
097: public int _x = Integer.parseInt(Bundle.getStringTrimmed(
098: _privateBundle, "x"));
099: public int _table1y = Integer.parseInt(Bundle.getStringTrimmed(
100: _privateBundle, "table1y"));
101:
102: //undeployment
103: public String _undeploy = Bundle.getStringTrimmed(_sharedBundle,
104: "undeploy");
105: public String _refresh = Bundle.getStringTrimmed(_sharedBundle,
106: "refresh");
107: public String _serverPath = Bundle.getStringTrimmed(_sharedBundle,
108: "serverPath");
109: public String _deploymentPath = Bundle.getStringTrimmed(
110: _sharedBundle, "deploymentPathGlassfish");
111: public String _separator = Bundle.getStringTrimmed(_sharedBundle,
112: "separator");
113:
114: Point clickPoint, dropPoint;
115: public static DesignerPaneOperator designer;
116: public static SheetTableOperator sheet;
117: public static PaletteContainerOperator palette;
118: public static DocumentOutlineOperator outline;
119: public static DeploymentDialogOperator deploy;
120: public static ServerNavigatorOperator explorer;
121: public int row;
122:
123: public AcceptanceTest(String testName) {
124: super (testName);
125: }
126:
127: public static Test suite() {
128: TestSuite suite = new NbTestSuite();
129: suite.addTest(new AcceptanceTest("createProject"));
130: suite.addTest(new AcceptanceTest("addTable"));
131: suite.addTest(new AcceptanceTest("testTableDataBind"));
132: suite.addTest(new AcceptanceTest("testDeploy"));
133: suite.addTest(new AcceptanceTest("closeProject"));
134: suite.addTest(new AcceptanceTest("testUndeploy"));
135: suite.addTest(new AcceptanceTest("testCheckIDELog"));
136: return suite;
137: }
138:
139: /** method called before each testcase
140: */
141: protected void setUp() {
142: System.out.println("Running Test " + getName()
143: + " ..................");
144: }
145:
146: /** method called after each testcase
147: */
148: protected void tearDown() {
149: System.out.println(" Finished Running Test " + getName()
150: + "..................");
151: }
152:
153: public void createProject() {
154: startTest();
155: log("**Creating Project");
156: //Create Project
157: try {
158: ComponentUtils.createNewProject(_projectName);
159: } catch (Exception e) {
160: log(">> Project Creation Failed");
161: e.printStackTrace();
162: log(e.toString());
163: fail();
164: }
165: log("**Done");
166: endTest();
167: }
168:
169: public void addTable() {
170:
171: startTest();
172: log("Initialize");
173: designer = new DesignerPaneOperator(RaveWindowOperator
174: .getDefaultRave());
175: palette = new PaletteContainerOperator(_standardPalette);
176: try {
177: Thread.sleep(5000);
178: } catch (Exception e) {
179: }
180:
181: log("Add table to designer");
182: dropPoint = new Point(_x, _table1y); //25,25
183: palette.addComponent(_standardTable, designer, dropPoint);
184: try {
185: Thread.sleep(2000);
186: } catch (Exception e) {
187: }
188:
189: // log("make sure property sheet is visible");
190: // Util.getMainMenu().pushMenu("Window|Properties","|");
191: // try { Thread.sleep(2000); } catch(Exception e) {}
192:
193: // sheet = new SheetTableOperator();
194: // sheet.setTextValue("id", "pTable");
195: // sheet.setTextValue("title", "Traveller Details");
196: // sheet.setTextValue("width", "100%");
197: Util.wait(2000);
198: endTest();
199:
200: }
201:
202: /* Test Databinding of table
203: */
204: public void testTableDataBind() {
205: startTest();
206: //String _dataProvider = "customerDataProvider";
207: String _dbName = Bundle.getStringTrimmed(_sharedBundle,
208: "Databses_SampleDBNode");
209: String _passwd = "app";
210: String _tableName = Bundle.getStringTrimmed(_sharedBundle,
211: "Databases_CustomerTableNode");
212: log("Connect sample database");
213: ComponentUtils.connectDB(_dbName, _passwd);
214: designer = new DesignerPaneOperator(RaveWindowOperator
215: .getDefaultRave());
216: log("Bind Sample DB table Customer to Table Component");
217: ComponentUtils.bindToDataProvider(_x, _table1y, _tableName);
218: Util.wait(2000);
219:
220: Util.saveAllAPICall();
221: Util.wait(2000);
222: endTest();
223: }
224:
225: /*
226: * Deploy application
227: */
228: public void testDeploy() {
229: startTest();
230: //need to wait responce
231: Waiter deploymentWaiter = new Waiter(new Waitable() {
232: public Object actionProduced(Object output) {
233: String text = ((OutputOperator) output).getText();
234: if (text.indexOf(_buildSuccess) != -1)
235: return _true;
236: return null;
237:
238: }
239:
240: public String getDescription() {
241: return ("Waiting Project Deployed");
242: }
243: });
244: log("Deploy from menu");
245: ProjectNavigatorOperator.pressPopupItemOnNode(_projectName,
246: _run);
247: TestUtils.wait(2000);
248: OutputOperator outputWindow = new OutputOperator();
249: deploymentWaiter.getTimeouts().setTimeout("Waiter.WaitingTime",
250: 240000);
251: log("wait until " + _buildSuccess);
252: try {
253: deploymentWaiter.waitAction(outputWindow);
254: } catch (InterruptedException e) {
255: log(outputWindow.getText());
256: e.printStackTrace();
257: fail("Deployment error: " + e);
258: }
259: log("Deployment complete");
260: endTest();
261: }
262:
263: public void closeProject() {
264: startTest();
265: Util.saveAllAPICall();
266: new ProjectNavigatorOperator().pressPopupItemOnNode(
267: _projectName, "close");
268: TestUtils.wait(5000);
269: endTest();
270: }
271:
272: /* Need to undeploy project to finish tests correctly */
273: public void testUndeploy() {
274: startTest();
275: log("Initialize");
276: explorer = ServerNavigatorOperator.showNavigatorOperator();
277: String serverPath = _serverPath + _projectServer; //Current deployment server
278: String deploymentPath = serverPath + _deploymentPath; //glassfish specific
279: String applicationPath = deploymentPath + _separator
280: + _projectName; //project name
281:
282: // Select the Server Navigator and set the JTreeOperator
283: log("get explorer");
284: new QueueTool().waitEmpty(100); //??
285: explorer.requestFocus();
286: JTreeOperator tree = explorer.getTree();
287: try {
288: Thread.sleep(4000);
289: } catch (Exception e) {
290: } // Sleep 4 secs to make sure Server Navigator is in focus
291:
292: // Need to refresh J2EE AppServer node
293: log("refresh");
294: explorer.pushPopup(tree, serverPath, _refresh);
295: TestUtils.wait(1000);
296:
297: log("refresh deployment path: " + deploymentPath);
298: TestUtils.wait(1000);
299: explorer.selectPath(deploymentPath);
300: explorer.getTree().expandPath(
301: explorer.getTree().findPath(deploymentPath));
302: explorer.pushPopup(tree, deploymentPath, _refresh);
303: TestUtils.wait(1000);
304:
305: log("undeploy Path: " + applicationPath);
306: explorer.selectPath(applicationPath);
307: TestUtils.wait(1000);
308:
309: log("Push Menu Undeploy...");
310: explorer.pushPopup(explorer.getTree(), applicationPath,
311: _undeploy);
312: TestUtils.wait(5000);
313: endTest();
314: }
315:
316: public void testCheckIDELog() {
317: startTest();
318: try {
319: String err = ComponentUtils.hasUnexpectedException();
320: String str = "";
321: if (!(err.equals(""))) {
322: assertTrue(
323: "Unexpected exceptions found in message.log: "
324: + err, str.equals(""));
325: }
326: } catch (IOException ioe) {
327: ioe.printStackTrace();
328: fail("Failed to open message.log : " + ioe);
329: }
330: endTest();
331: }
332: }
|