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.selection.dropdown;
043:
044: import junit.framework.Test;
045: import junit.framework.TestSuite;
046:
047: import java.io.File;
048: import java.awt.*;
049: import java.io.IOException;
050:
051: import org.netbeans.modules.visualweb.gravy.*;
052: import org.netbeans.modules.visualweb.gravy.ProjectNavigatorOperator;
053: import org.netbeans.modules.visualweb.gravy.dataconnectivity.ServerNavigatorOperator;
054: import org.netbeans.modules.visualweb.gravy.toolbox.PaletteContainerOperator;
055: import org.netbeans.modules.visualweb.gravy.designer.DesignerPaneOperator;
056: import org.netbeans.modules.visualweb.gravy.properties.SheetTableOperator;
057: import org.netbeans.modules.visualweb.gravy.dataconnectivity.ServerNavigatorOperator;
058: import org.netbeans.jemmy.operators.*;
059: import org.netbeans.modules.visualweb.test.components.util.ComponentUtils;
060: import org.netbeans.jellytools.OutputOperator;
061: import org.netbeans.jemmy.Waitable;
062: import org.netbeans.jemmy.Waiter;
063: import org.netbeans.jemmy.QueueTool;
064: import org.netbeans.jemmy.operators.JTreeOperator;
065:
066: /**
067: * @author Sherry Zhou (sherry.zhou@sun.com)
068: */
069: public class AcceptanceTest extends RaveTestCase {
070:
071: public String _bundle = "org.netbeans.modules.visualweb.test.components.Component";
072: public String _projectName = "DropdownAcceptanceTest";
073: public String _projectServer = Bundle.getStringTrimmed(_bundle,
074: "projectServer");
075: public String _logFileLocation = Bundle.getStringTrimmed(_bundle,
076: "logFile");
077: public String _logFile = System.getProperty("xtest.sketchpad")
078: + File.separator + _logFileLocation;
079: public String _exception = Bundle.getStringTrimmed(_bundle,
080: "Exception");
081: public String _close = Bundle.getStringTrimmed(_bundle, "close");
082: public String _run = Bundle.getStringTrimmed(_bundle, "Run");
083: public String _buildSuccess = Bundle.getStringTrimmed(_bundle,
084: "buildSuccess");
085: public String _true = Bundle.getStringTrimmed(_bundle, "true");
086:
087: //undeployment
088: public String _undeploy = Bundle.getStringTrimmed(_bundle,
089: "undeploy");
090: public String _refresh = Bundle
091: .getStringTrimmed(_bundle, "refresh");
092: public String _serverPath = Bundle.getStringTrimmed(_bundle,
093: "serverPath");
094: public String _deploymentPath = Bundle.getStringTrimmed(_bundle,
095: "deploymentPathGlassfish");
096: public String _separator = Bundle.getStringTrimmed(_bundle,
097: "separator");
098:
099: public static int xDropdown = 50;
100: public static int yDropdown = 50;
101: public static int xTable = 50;
102: public static int yTable = 150;
103:
104: public static DesignerPaneOperator designer;
105: public static SheetTableOperator sheet;
106: public static ServerNavigatorOperator explorer;
107:
108: public AcceptanceTest(String testName) {
109: super (testName);
110: }
111:
112: public static Test suite() {
113: TestSuite suite = new TestSuite();
114: suite.addTest(new AcceptanceTest("testCreateProject"));
115: suite.addTest(new AcceptanceTest("testAddDropdown"));
116: suite.addTest(new AcceptanceTest("testDropdownDataBind"));
117: // suite.addTest(new AcceptanceTest("testAddTable"));
118: // suite.addTest(new AcceptanceTest("testAddSessionBeanProperty"));
119: // suite.addTest(new AcceptanceTest("testEditQueryStatement"));
120: suite.addTest(new AcceptanceTest("testDeploy"));
121: suite.addTest(new AcceptanceTest("testCloseProject"));
122: suite.addTest(new AcceptanceTest("testUndeploy"));
123: suite.addTest(new AcceptanceTest("testCheckIDELog"));
124: return suite;
125: }
126:
127: /** method called before each testcase
128: */
129: protected void setUp() {
130: System.out.println("######## " + getName() + " #######");
131: }
132:
133: /** method called after each testcase
134: */
135: protected void tearDown() {
136: System.out.println("######## " + getName()
137: + " Finished #######");
138: }
139:
140: /*
141: * Start PE. Delete PointBase travel resource
142: */
143: private void testStartup() {
144: //Start PE is it is not started yet
145: ServerNavigatorOperator se = new ServerNavigatorOperator();
146: // Skip next 2 steps if running on Mac as Jemmy's call popup issue
147: if (!System.getProperty("os.name").equals("Mac OS X")) {
148: //Start PE is it is not started yet
149: try {
150: se.startServer("J2EE");
151: } catch (Exception e) {
152: }
153: // Delete pb travel resource if it exists
154: se.deleteResource("jdbc/Travel");
155: }
156: }
157:
158: /*
159: * Create new project
160: * And add property val to SessionBean1.java
161: */
162: public void testCreateProject() {
163: startTest();
164: log("**Creating Project");
165: //Create Project
166: try {
167: ComponentUtils.createNewProject(_projectName);
168: Util.wait(10000);
169: } catch (Exception e) {
170: log(">> Project Creation Failed");
171: e.printStackTrace();
172: log(e.toString());
173: fail();
174: }
175: log("**Done");
176: endTest();
177: }
178:
179: /*
180: * Add a dropdown component.
181: * Set auto-submit on change
182: */
183:
184: public void testAddDropdown() {
185: startTest();
186: designer = new DesignerPaneOperator(RaveWindowOperator
187: .getDefaultRave());
188:
189: log("Add a dropdown component");
190: PaletteContainerOperator palette = new PaletteContainerOperator(
191: Bundle.getStringTrimmed(_bundle, "basicPalette"));
192: Util.wait(2000);
193: palette.addComponent(Bundle.getStringTrimmed(_bundle,
194: "basicDropdown"), designer, new Point(xDropdown,
195: yDropdown));
196:
197: log("Set Auto-submit on cChange to true");
198: designer.clickForPopup(xDropdown, yDropdown);
199: new JPopupMenuOperator().pushMenuNoBlock(Bundle
200: .getStringTrimmed(_bundle, "Designer_Menu_AutoSubmit"));
201:
202: log("Set its label property");
203: sheet = new SheetTableOperator();
204: ComponentUtils.setProperty(sheet, Bundle.getStringTrimmed(
205: _bundle, "propertyLabel"), "Person");
206:
207: Util.saveAllAPICall();
208: Util.wait(2000);
209: endTest();
210: }
211:
212: /*
213: * Bind travel>person database table to dropdown.
214: */
215: public void testDropdownDataBind() {
216: startTest();
217: String _dataProvider = "customerDataProvider";
218: String _dbName = Bundle.getStringTrimmed(_bundle,
219: "Databses_SampleDBNode");
220: String _passwd = "app";
221: String _tableName = Bundle.getStringTrimmed(_bundle,
222: "Databases_CustomerTableNode");
223: log("Connect sample database");
224: ComponentUtils.connectDB(_dbName, _passwd);
225: designer = new DesignerPaneOperator(RaveWindowOperator
226: .getDefaultRave());
227: log("Bind Sample DB table Customer to dropdown");
228: ComponentUtils.bindToDataProvider(xDropdown, yDropdown,
229: _tableName, _dataProvider, "NAME", "NAME");
230: Util.wait(2000);
231:
232: Util.saveAllAPICall();
233: Util.wait(2000);
234: endTest();
235: }
236:
237: /*
238: * Add table and bind travel>trip
239: */
240: public void testAddTable() {
241: startTest();
242: designer = new DesignerPaneOperator(RaveWindowOperator
243: .getDefaultRave());
244: PaletteContainerOperator palette = new PaletteContainerOperator(
245: Bundle.getStringTrimmed(_bundle, "basicPalette"));
246: Util.wait(2000);
247:
248: // Add dropdown component
249: palette.addComponent(Bundle.getStringTrimmed(_bundle,
250: "basicTable"), designer, new Point(xTable, yTable));
251: Util.wait(1000);
252: ComponentUtils.bindToDataProvider(xTable, yTable, Bundle
253: .getStringTrimmed(_bundle, "DataSource_TripNode"),
254: "tripDataProvider", "", "");
255: Util.saveAllAPICall();
256: Util.wait(2000);
257: endTest();
258: }
259:
260: public void testAddSessionBeanPropertyForVisitors() {
261: startTest();
262: String path = _projectName + "|"
263: + Bundle.getStringTrimmed(_bundle, "SessionBean_Path");
264: ComponentUtils.addObjectProperty(path, "personId", "Integer",
265: Bundle.getStringTrimmed(_bundle,
266: "BeanPattern_Mode_ReadWrite"));
267: Util.wait(500);
268: endTest();
269:
270: }
271:
272: public void testEditQueryEditor() {
273: startTest();
274: //TBD
275: endTest();
276: }
277:
278: /*
279: * Deploy application
280: */
281: public void testDeploy() {
282: startTest();
283: //need to wait responce
284: Waiter deploymentWaiter = new Waiter(new Waitable() {
285: public Object actionProduced(Object output) {
286: String text = ((OutputOperator) output).getText();
287: if (text.indexOf(_buildSuccess) != -1)
288: return _true;
289: return null;
290:
291: }
292:
293: public String getDescription() {
294: return ("Waiting Project Deployed");
295: }
296: });
297: log("Deploy from menu");
298: ProjectNavigatorOperator.pressPopupItemOnNode(_projectName,
299: _run);
300: TestUtils.wait(2000);
301: OutputOperator outputWindow = new OutputOperator();
302: deploymentWaiter.getTimeouts().setTimeout("Waiter.WaitingTime",
303: 240000);
304: log("wait until " + _buildSuccess);
305: try {
306: deploymentWaiter.waitAction(outputWindow);
307: } catch (InterruptedException e) {
308: log(outputWindow.getText());
309: e.printStackTrace();
310: fail("Deployment error: " + e);
311: }
312: log("Deployment complete");
313: endTest();
314: }
315:
316: public void testCloseProject() {
317: startTest();
318: Util.saveAllAPICall();
319: new ProjectNavigatorOperator().pressPopupItemOnNode(
320: _projectName, Bundle.getStringTrimmed(_bundle,
321: "CloseProjectPopupItem"));
322: //TestUtils.closeCurrentProject();
323: TestUtils.wait(5000);
324: endTest();
325: }
326:
327: /* Need to undeploy project to finish tests correctly */
328: public void testUndeploy() {
329: startTest();
330: log("Initialize");
331: explorer = ServerNavigatorOperator.showNavigatorOperator();
332: String serverPath = _serverPath + _projectServer; //Current deployment server
333: String deploymentPath = serverPath + _deploymentPath; //glassfish specific
334: String applicationPath = deploymentPath + _separator
335: + _projectName; //project name
336:
337: // Select the Server Navigator and set the JTreeOperator
338: log("get explorer");
339: new QueueTool().waitEmpty(100); //??
340: explorer.requestFocus();
341: JTreeOperator tree = explorer.getTree();
342: try {
343: Thread.sleep(4000);
344: } catch (Exception e) {
345: } // Sleep 4 secs to make sure Server Navigator is in focus
346:
347: // Need to refresh J2EE AppServer node
348: log("refresh");
349: explorer.pushPopup(tree, serverPath, _refresh);
350: TestUtils.wait(1000);
351:
352: log("refresh deployment path: " + deploymentPath);
353: TestUtils.wait(1000);
354: explorer.selectPath(deploymentPath);
355: explorer.getTree().expandPath(
356: explorer.getTree().findPath(deploymentPath));
357: explorer.pushPopup(tree, deploymentPath, _refresh);
358: TestUtils.wait(1000);
359:
360: log("undeploy Path: " + applicationPath);
361: explorer.selectPath(applicationPath);
362: TestUtils.wait(1000);
363:
364: log("Push Menu Undeploy...");
365: explorer.pushPopup(explorer.getTree(), applicationPath,
366: _undeploy);
367: TestUtils.wait(5000);
368: endTest();
369: }
370:
371: public void testCheckIDELog() {
372: startTest();
373: try {
374: String err = ComponentUtils.hasUnexpectedException();
375: String str = "";
376: if (!(err.equals(""))) {
377: assertTrue(
378: "Unexpected exceptions found in message.log: "
379: + err, str.equals(""));
380: }
381: } catch (IOException ioe) {
382: ioe.printStackTrace();
383: fail("Failed to open message.log : " + ioe);
384: }
385: endTest();
386: }
387: }
|