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.basic;
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 Chary Kanaparthi (Chary.Kanaparthi@sun.com)
066: */
067: public class AcceptanceTest extends RaveTestCase {
068:
069: public static String BUNDLE = "org.netbeans.modules.visualweb.test.components.output.Bundle";
070: public String _projectName = "BasicTableAcceptance";
071:
072: //Project variables
073: public String _sharedBundle = "org.netbeans.modules.visualweb.test.components.Component";
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.sketchpad")
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: //undeployment
091: public String _undeploy = Bundle.getStringTrimmed(_sharedBundle,
092: "undeploy");
093: public String _refresh = Bundle.getStringTrimmed(_sharedBundle,
094: "refresh");
095: public String _serverPath = Bundle.getStringTrimmed(_sharedBundle,
096: "serverPath");
097: public String _deploymentPath = Bundle.getStringTrimmed(
098: _sharedBundle, "deploymentPathGlassfish");
099: public String _separator = Bundle.getStringTrimmed(_sharedBundle,
100: "separator");
101:
102: public static DesignerPaneOperator designer;
103: public static SheetTableOperator sheet;
104: public static ServerNavigatorOperator explorer;
105:
106: //Point at which table is dropped
107: public static int xTable = 25;
108: public static int yTable = 50;
109:
110: public AcceptanceTest(String testName) {
111: super (testName);
112: }
113:
114: public static Test suite() {
115: TestSuite suite = new NbTestSuite();
116: suite.addTest(new AcceptanceTest("createProject"));
117: suite.addTest(new AcceptanceTest("addTable"));
118: suite.addTest(new AcceptanceTest("testTableDataBind"));
119: //suite.addTest(new AcceptanceTest("testTableAddColumn"));
120: //suite.addTest(new AcceptanceTest("testTableAddRowGroup"));
121: suite.addTest(new AcceptanceTest("testDeploy"));
122: suite.addTest(new AcceptanceTest("closeProject"));
123: suite.addTest(new AcceptanceTest("testUndeploy"));
124: suite.addTest(new AcceptanceTest("testCheckIDELog"));
125:
126: return suite;
127: }
128:
129: /** method called before each testcase
130: */
131: protected void setUp() {
132: System.out.println("Running Test " + getName()
133: + " ..................");
134: }
135:
136: /** method called after each testcase
137: */
138: protected void tearDown() {
139: System.out.println(" Finished Running Test " + getName()
140: + "..................");
141: }
142:
143: public void createProject() {
144: startTest();
145: log("**Creating Project");
146: //Create Project
147: try {
148: ComponentUtils.createNewProject(_projectName);
149: } catch (Exception e) {
150: log(">> Project Creation Failed");
151: e.printStackTrace();
152: log(e.toString());
153: fail();
154: }
155: log("**Done");
156: endTest();
157: }
158:
159: public void addTable() {
160:
161: startTest();
162: designer = new DesignerPaneOperator(RaveWindowOperator
163: .getDefaultRave());
164: PaletteContainerOperator palette = new PaletteContainerOperator(
165: "Basic");
166: palette.dndPaletteComponent("Table", designer, new Point(
167: xTable, yTable));
168: try {
169: Thread.sleep(2000);
170: } catch (Exception e) {
171: }
172:
173: // log("make sure property sheet is visible");
174: // Util.getMainMenu().pushMenu("Window|Properties","|");
175: // try { Thread.sleep(2000); } catch(Exception e) {}
176:
177: sheet = new SheetTableOperator();
178: sheet.setTextValue("id", "pTable");
179: //commented because it tries to set augmentTitle
180: // sheet.setTextValue("title", "Traveller Details");
181: // sheet.setTextValue("width", "100%");
182: Util.wait(2000);
183: endTest();
184:
185: }
186:
187: /* Test Databinding of table
188: */
189: public void testTableDataBind() {
190: startTest();
191: //String _dataProvider = "customerDataProvider";
192: String _dbName = Bundle.getStringTrimmed(_sharedBundle,
193: "Databses_SampleDBNode");
194: String _passwd = "app";
195: String _tableName = Bundle.getStringTrimmed(_sharedBundle,
196: "Databases_CustomerTableNode");
197: log("Connect sample database");
198: ComponentUtils.connectDB(_dbName, _passwd);
199: designer = new DesignerPaneOperator(RaveWindowOperator
200: .getDefaultRave());
201: log("Bind Sample DB table Customer to Table Component");
202: ComponentUtils.bindToDataProvider(xTable, yTable, _tableName);
203: Util.wait(2000);
204:
205: Util.saveAllAPICall();
206: Util.wait(2000);
207: endTest();
208: }
209:
210: /* Test Adding column to table
211: */
212: public void testTableAddColumn() {
213: startTest();
214: log("Adding new Column to table");
215: //Drop Table Column on table to add a new column to table
216: designer = new DesignerPaneOperator(RaveWindowOperator
217: .getDefaultRave());
218: PaletteContainerOperator palette = new PaletteContainerOperator(
219: "Basic");
220: //Column has to be dropped on the existing columns on the table
221: //therefore adjusting point coordinates
222: palette.dndPaletteComponent("Table Column", designer,
223: new Point(xTable + 25, yTable + 50));
224: try {
225: Thread.sleep(5000);
226: } catch (Exception e) {
227: }
228:
229: sheet = new SheetTableOperator();
230: log("Changing Id of new Column through property sheet");
231: sheet.setTextValue("id", "newColumn");
232: designer.select("ptable");
233: sheet = new SheetTableOperator();
234: log("Changing HeaderText of new Column through property Sheet");
235: sheet.setTextValue("headerText", "Test Column");
236: endTest();
237: }
238:
239: /* Test Adding new Row Group to table
240: *
241: */
242: public void testTableAddRowGroup() {
243: startTest();
244: //Drop Row Group on table to add a new row group
245: log("Adding new Row Group to table");
246: designer = new DesignerPaneOperator(RaveWindowOperator
247: .getDefaultRave());
248: PaletteContainerOperator palette = new PaletteContainerOperator(
249: "Basic");
250: palette.dndPaletteComponent("Table Row Group", designer,
251: new Point(xTable, yTable));
252: Util.wait(5000);
253: //try { Thread.sleep(5000); } catch(Exception e) {}
254: sheet = new SheetTableOperator();
255: log("Changing Id of new Row Group through property sheet");
256: sheet.setTextValue("id", "newRowGroup");
257: Util.wait(2000);
258: endTest();
259: }
260:
261: public void testTableLayout() {
262: startTest();
263: endTest();
264: }
265:
266: /*
267: * Deploy application
268: */
269: public void testDeploy() {
270: startTest();
271: //need to wait responce
272: Waiter deploymentWaiter = new Waiter(new Waitable() {
273: public Object actionProduced(Object output) {
274: String text = ((OutputOperator) output).getText();
275: if (text.indexOf(_buildSuccess) != -1)
276: return _true;
277: return null;
278:
279: }
280:
281: public String getDescription() {
282: return ("Waiting Project Deployed");
283: }
284: });
285: log("Deploy from menu");
286: ProjectNavigatorOperator.pressPopupItemOnNode(_projectName,
287: _run);
288: TestUtils.wait(2000);
289: OutputOperator outputWindow = new OutputOperator();
290: deploymentWaiter.getTimeouts().setTimeout("Waiter.WaitingTime",
291: 240000);
292: log("wait until " + _buildSuccess);
293: try {
294: deploymentWaiter.waitAction(outputWindow);
295: } catch (InterruptedException e) {
296: log(outputWindow.getText());
297: e.printStackTrace();
298: fail("Deployment error: " + e);
299: }
300: log("Deployment complete");
301: endTest();
302: }
303:
304: public void closeProject() {
305: startTest();
306: Util.saveAllAPICall();
307: new ProjectNavigatorOperator().pressPopupItemOnNode(
308: _projectName, "close");
309: TestUtils.wait(5000);
310: endTest();
311: }
312:
313: /* Need to undeploy project to finish tests correctly */
314: public void testUndeploy() {
315: startTest();
316: log("Initialize");
317: explorer = ServerNavigatorOperator.showNavigatorOperator();
318: String serverPath = _serverPath + _projectServer; //Current deployment server
319: String deploymentPath = serverPath + _deploymentPath; //glassfish specific
320: String applicationPath = deploymentPath + _separator
321: + _projectName; //project name
322:
323: // Select the Server Navigator and set the JTreeOperator
324: log("get explorer");
325: new QueueTool().waitEmpty(100); //??
326: explorer.requestFocus();
327: JTreeOperator tree = explorer.getTree();
328: try {
329: Thread.sleep(4000);
330: } catch (Exception e) {
331: } // Sleep 4 secs to make sure Server Navigator is in focus
332:
333: // Need to refresh J2EE AppServer node
334: log("refresh");
335: explorer.pushPopup(tree, serverPath, _refresh);
336: TestUtils.wait(1000);
337:
338: log("refresh deployment path: " + deploymentPath);
339: TestUtils.wait(1000);
340: explorer.selectPath(deploymentPath);
341: explorer.getTree().expandPath(
342: explorer.getTree().findPath(deploymentPath));
343: explorer.pushPopup(tree, deploymentPath, _refresh);
344: TestUtils.wait(1000);
345:
346: log("undeploy Path: " + applicationPath);
347: explorer.selectPath(applicationPath);
348: TestUtils.wait(1000);
349:
350: log("Push Menu Undeploy...");
351: explorer.pushPopup(explorer.getTree(), applicationPath,
352: _undeploy);
353: TestUtils.wait(5000);
354: endTest();
355: }
356:
357: public void testCheckIDELog() {
358: startTest();
359: try {
360: String err = ComponentUtils.hasUnexpectedException();
361: String str = "";
362: if (!(err.equals(""))) {
363: assertTrue(
364: "Unexpected exceptions found in message.log: "
365: + err, str.equals(""));
366: }
367: } catch (IOException ioe) {
368: ioe.printStackTrace();
369: fail("Failed to open message.log : " + ioe);
370: }
371: endTest();
372: }
373:
374: }
|