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