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