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: package org.netbeans.modules.visualweb.test.components.action.button;
042:
043: import junit.framework.Test;
044: import junit.framework.TestSuite;
045:
046: import java.io.File;
047: import java.awt.*;
048: import java.awt.event.KeyEvent;
049: import java.io.IOException;
050:
051: import org.netbeans.jellytools.EditorOperator;
052: import org.netbeans.modules.visualweb.test.components.util.ComponentUtils;
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.jellytools.OutputOperator;
058: import org.netbeans.jellytools.actions.SaveAllAction;
059: import org.netbeans.jemmy.Waitable;
060: import org.netbeans.jemmy.Waiter;
061: import org.netbeans.jemmy.QueueTool;
062: import org.netbeans.jemmy.operators.JEditorPaneOperator;
063: import org.netbeans.jemmy.operators.JPopupMenuOperator;
064: import org.netbeans.jemmy.operators.JTreeOperator;
065: import org.netbeans.modules.visualweb.gravy.Bundle;
066: import org.netbeans.modules.visualweb.gravy.RaveTestCase;
067: import org.netbeans.modules.visualweb.gravy.RaveWindowOperator;
068: import org.netbeans.modules.visualweb.gravy.TestUtils;
069: import org.netbeans.modules.visualweb.gravy.Util;
070: import org.netbeans.modules.visualweb.gravy.dataconnectivity.ServerNavigatorOperator;
071:
072: /**
073: * @author Sherry Zhou (sherry.zhou@sun.com)
074: */
075: public class AcceptanceTest extends RaveTestCase {
076:
077: public String _bundle = ComponentUtils.getBundle();
078: public String _projectServer = Bundle.getStringTrimmed(_bundle,
079: "projectServer");
080: public String _logFileLocation = Bundle.getStringTrimmed(_bundle,
081: "logFile");
082: public String _logFile = System.getProperty("xtest.workdir")
083: + File.separator + _logFileLocation;
084: public String _exception = Bundle.getStringTrimmed(_bundle,
085: "Exception");
086: public String _close = Bundle.getStringTrimmed(_bundle, "close");
087: public String _run = Bundle.getStringTrimmed(_bundle, "Run");
088: public String _buildSuccess = Bundle.getStringTrimmed(_bundle,
089: "buildSuccess");
090: public String _true = Bundle.getStringTrimmed(_bundle, "true");
091: public String _projectName = "ButtonAcceptanceTest";
092: public String imageDir = ComponentUtils.getDataDir() + "action"
093: + File.separator;
094: public String image1 = imageDir + "orchid1.JPG";
095: public String image2 = imageDir + "orchid2.JPG";
096: public static int xButton = 50;
097: public static int yButton = 50;
098: //undeployment
099: public String _undeploy = Bundle.getStringTrimmed(_bundle,
100: "undeploy");
101: public String _refresh = Bundle
102: .getStringTrimmed(_bundle, "refresh");
103: public String _serverPath = Bundle.getStringTrimmed(_bundle,
104: "serverPath");
105: public String _deploymentPath = Bundle.getStringTrimmed(_bundle,
106: "deploymentPathGlassfish");
107: public String _separator = Bundle.getStringTrimmed(_bundle,
108: "separator");
109: public String _reformatCode = Bundle.getStringTrimmed(_bundle,
110: "reformatCode");
111: public static DesignerPaneOperator designer;
112: public static SheetTableOperator sheet;
113: public static ServerNavigatorOperator explorer;
114:
115: public AcceptanceTest(String testName) {
116: super (testName);
117: }
118:
119: public static Test suite() {
120: TestSuite suite = new TestSuite();
121: suite.addTest(new AcceptanceTest("testCreateProject"));
122: suite.addTest(new AcceptanceTest("testAddButton"));
123: suite.addTest(new AcceptanceTest("testAddActionEvent"));
124: suite.addTest(new AcceptanceTest("testVerifyJSPEditor"));
125: suite.addTest(new AcceptanceTest(
126: "testChangeTextInPropertySheet"));
127: suite.addTest(new AcceptanceTest("testChangeTextInJSPEditor"));
128: suite.addTest(new AcceptanceTest("testDeploy"));
129: suite.addTest(new AcceptanceTest("testCloseProject"));
130: suite.addTest(new AcceptanceTest("testUndeploy"));
131: suite.addTest(new AcceptanceTest("testCheckIDELog"));
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: log(System.getProperty("j2eeVersion"));
174: //Create Project
175: try {
176: ComponentUtils.createNewProject(_projectName);
177: } catch (Exception e) {
178: log(">> Project Creation Failed");
179: e.printStackTrace();
180: log(e.toString());
181: fail(e);
182: }
183: log("**Done");
184: endTest();
185: }
186:
187: /*
188: * Add 2 Buttons. Set their action event handler.
189: */
190: public void testAddButton() {
191: startTest();
192: designer = new DesignerPaneOperator(RaveWindowOperator
193: .getDefaultRave());
194: log("Add a button component");
195: PaletteContainerOperator palette = new PaletteContainerOperator(
196: Bundle.getStringTrimmed(_bundle, "basicPalette"));
197: Util.wait(2000);
198: palette.dndPaletteComponent(Bundle.getStringTrimmed(_bundle,
199: "basicButton"), designer, new Point(xButton, yButton));
200:
201: TestUtils.wait(2000);
202: Util.saveAllAPICall();
203: Util.wait(500);
204: endTest();
205: }
206:
207: /*
208: * Verify button_action() code is generated
209: */
210: public void testAddActionEvent() {
211: startTest();
212: log("Open java code editor view by clicking designer and then double clicking on the button ");
213: designer.clickMouse(20, 20, 1);
214: TestUtils.wait(1000);
215: designer.clickMouse(xButton + 5, yButton + 5, 2);
216: TestUtils.wait(1000);
217: designer = new DesignerPaneOperator(RaveWindowOperator
218: .getDefaultRave());
219: JEditorPaneOperator editor = new JEditorPaneOperator(
220: RaveWindowOperator.getDefaultRave(), "public class "
221: + "Page1");
222: editor.setVerification(false);
223: TestUtils.wait(2000);
224: editor.requestFocus();
225: new SaveAllAction().perform();
226: log("Editor Dump:");
227: log(editor.getText());
228: String expectedStr = "button1_action()";
229: assertTrue("There is no \"" + expectedStr
230: + "\" string in jsp editor", editor.getText().contains(
231: expectedStr));
232: editor.requestFocus();
233: editor.setText("log(\"Action Performed\");\n");
234: log("Reformat code");
235: TestUtils.wait(200);
236: editor.clickForPopup();
237: new JPopupMenuOperator().pushMenu(_reformatCode);
238: TestUtils.wait(200);
239: log("Editor Dump:");
240: log(editor.getText());
241: log("Switch back to Designer");
242: designer.makeComponentVisible();
243: // TestUtils.wait(10000);
244: // Util.saveAllAPICall();
245: Util.wait(2000);
246: endTest();
247: }
248:
249: /*
250: * Verfiy JPS code. Check for action="#{Page1.button1_action} "
251: */
252: public void testVerifyJSPEditor() {
253: startTest();
254: designer = new DesignerPaneOperator(RaveWindowOperator
255: .getDefaultRave());
256: designer.switchToJSPSource();
257: TestUtils.wait(2000);
258: log("Verify action tag should present in JSP editor");
259: String expectedStr = Bundle.getStringTrimmed(_bundle,
260: "actionTag")
261: + "=\"#{Page1.button1_action}\"";
262: log(expectedStr);
263: JEditorPaneOperator editor = new JEditorPaneOperator(
264: RaveWindowOperator.getDefaultRave());
265: assertFalse("There is no \"" + expectedStr
266: + "\" string in jsp editor", editor.getText().indexOf(
267: expectedStr) == -1);
268: log("Switch back to Designer");
269: designer.makeComponentVisible();
270: TestUtils.wait(2000);
271: endTest();
272: }
273:
274: /*
275: * Change text property via property sheet. verify JSP code
276: */
277: public void testChangeTextInPropertySheet() {
278: startTest();
279: log("Set button's text property via property sheet");
280: designer.clickMouse(xButton, yButton, 1);
281: TestUtils.wait(1000);
282: sheet = new SheetTableOperator();
283:
284: //ComponentUtils.setProperty(sheet, Bundle.getStringTrimmed(_bundle, "propertyText"), "Stoplight");
285: sheet.setButtonValue(Bundle.getStringTrimmed(_bundle,
286: "propertyText"), "Stoplight");
287: TestUtils.wait(5000);
288:
289: log("Switch to JSP page. Verify that the jsp source has been updated");
290: // designer = new DesignerPaneOperator(RaveWindowOperator.getDefaultRave());
291: designer.switchToJSPSource();
292: TestUtils.wait(2000);
293: String expectedStr = "text=\"Stoplight";
294: JEditorPaneOperator editor = new JEditorPaneOperator(
295: RaveWindowOperator.getDefaultRave());
296: assertFalse("There is no \"" + expectedStr
297: + "\" string in jsp editor", editor.getText().indexOf(
298: expectedStr) == -1);
299:
300: log("Switch back to Designer");
301: designer.makeComponentVisible();
302: TestUtils.wait(2000);
303: endTest();
304: }
305:
306: /*
307: * Change text property in JSP code. verify it from property sheet
308: */
309: public void testChangeTextInJSPEditor() {
310: startTest();
311:
312: log("Set button's text in JSP Edtor");
313: designer = new DesignerPaneOperator(RaveWindowOperator
314: .getDefaultRave());
315: designer.switchToJSPSource();
316: TestUtils.wait(1000);
317:
318: JEditorPaneOperator editor = new JEditorPaneOperator(
319: RaveWindowOperator.getDefaultRave());
320: editor.selectText("Stoplight");
321: editor.pushKey(KeyEvent.VK_DELETE);
322: editor.typeText("Trafficlight");
323: TestUtils.wait(200);
324:
325: log("Switch to designer. Verify that propertry sheet has been updated");
326: designer.makeComponentVisible();
327: TestUtils.wait(2000);
328:
329: sheet = new SheetTableOperator();
330: TestUtils.wait(2000);
331:
332: String expectedStr = "Trafficlight";
333: log(sheet.getValue(Bundle.getStringTrimmed(_bundle,
334: "propertyText")));
335: assertFalse("There is no \"" + expectedStr
336: + "\" string property sheet", sheet.getValue(
337: Bundle.getStringTrimmed(_bundle, "propertyText"))
338: .equals(expectedStr));
339:
340: TestUtils.wait(500);
341: Util.saveAllAPICall();
342: TestUtils.wait(1000);
343: endTest();
344: }
345:
346: /*
347: * Deploy application
348: */
349: public void testDeploy() {
350: startTest();
351: //need to wait responce
352: Waiter deploymentWaiter = new Waiter(new Waitable() {
353:
354: public Object actionProduced(Object output) {
355: String text = ((OutputOperator) output).getText();
356: if (text.indexOf(_buildSuccess) != -1) {
357: return _true;
358: }
359: return null;
360: }
361:
362: public String getDescription() {
363: return ("Waiting Project Deployed");
364: }
365: });
366: log("Deploy from menu");
367: ProjectNavigatorOperator.pressPopupItemOnNode(_projectName,
368: _run);
369: TestUtils.wait(2000);
370: OutputOperator outputWindow = new OutputOperator();
371: deploymentWaiter.getTimeouts().setTimeout("Waiter.WaitingTime",
372: 240000);
373: log("wait until " + _buildSuccess);
374: try {
375: deploymentWaiter.waitAction(outputWindow);
376: } catch (InterruptedException e) {
377: log(outputWindow.getText());
378: e.printStackTrace();
379: fail("Deployment error: " + e);
380: }
381: log("Deployment complete");
382: endTest();
383: }
384:
385: public void testCloseProject() {
386: startTest();
387: Util.saveAllAPICall();
388: new ProjectNavigatorOperator().pressPopupItemOnNode(
389: _projectName, Bundle.getStringTrimmed(_bundle,
390: "CloseProjectPopupItem"));
391: //TestUtils.closeCurrentProject();
392: TestUtils.wait(5000);
393: endTest();
394: }
395:
396: /* Need to undeploy project to finish tests correctly */
397: public void testUndeploy() {
398: startTest();
399: log("Initialize");
400: explorer = ServerNavigatorOperator.showNavigatorOperator();
401: String serverPath = _serverPath + _projectServer; //Current deployment server
402: String deploymentPath = serverPath + _deploymentPath; //glassfish specific
403: String applicationPath = deploymentPath + _separator
404: + _projectName; //project name
405:
406: // Select the Server Navigator and set the JTreeOperator
407: log("get explorer");
408: new QueueTool().waitEmpty(100); //??
409: explorer.requestFocus();
410: JTreeOperator tree = explorer.getTree();
411: try {
412: Thread.sleep(4000);
413: } catch (Exception e) {
414: } // Sleep 4 secs to make sure Server Navigator is in focus
415:
416: // Need to refresh J2EE AppServer node
417: log("refresh");
418: explorer.pushPopup(tree, serverPath, _refresh);
419: TestUtils.wait(1000);
420:
421: log("refresh deployment path: " + deploymentPath);
422: TestUtils.wait(1000);
423: explorer.selectPath(deploymentPath);
424: explorer.getTree().expandPath(
425: explorer.getTree().findPath(deploymentPath));
426: explorer.pushPopup(tree, deploymentPath, _refresh);
427: TestUtils.wait(1000);
428:
429: log("undeploy Path: " + applicationPath);
430: explorer.selectPath(applicationPath);
431: TestUtils.wait(1000);
432:
433: log("Push Menu Undeploy...");
434: explorer.pushPopup(explorer.getTree(), applicationPath,
435: _undeploy);
436: TestUtils.wait(5000);
437: endTest();
438: }
439:
440: public void testCheckIDELog() {
441: startTest();
442: try {
443: String err = ComponentUtils.hasUnexpectedException();
444: String str = "";
445: if (!(err.equals(""))) {
446: assertTrue(
447: "Unexpected exceptions found in message.log: "
448: + err, str.equals(""));
449: }
450: } catch (IOException ioe) {
451: ioe.printStackTrace();
452: fail("Failed to open message.log : " + ioe);
453: }
454: endTest();
455: }
456: }
|