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.stdbutton;
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.modules.visualweb.test.components.util.ComponentUtils;
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.gravy.dataconnectivity.ServerNavigatorOperator;
059: import org.netbeans.jellytools.OutputOperator;
060: import org.netbeans.jemmy.Waitable;
061: import org.netbeans.jemmy.Waiter;
062: import org.netbeans.jemmy.operators.*;
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 _projectServer = Bundle.getStringTrimmed(_bundle,
073: "projectServer");
074: public String _logFileLocation = Bundle.getStringTrimmed(_bundle,
075: "logFile");
076: public String _logFile = System.getProperty("xtest.workdir")
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: public String _projectName = "StandardButtonAcceptanceTest";
086: public String _projectPath = ComponentUtils
087: .getProjectPath(_projectName);
088: public String prjType = "Web";
089: public String prjCategory = System
090: .getProperty("xtest.project.category");
091: public String imageDir = ComponentUtils.getDataDir() + "action"
092: + File.separator;
093: public String image1 = imageDir + "orchid1.JPG";
094: public String image2 = imageDir + "orchid2.JPG";
095: public static int xButton = 50;
096: public static int yButton = 50;
097: //undeployment
098: public String _undeploy = Bundle.getStringTrimmed(_bundle,
099: "undeploy");
100: public String _refresh = Bundle
101: .getStringTrimmed(_bundle, "refresh");
102: public String _serverPath = Bundle.getStringTrimmed(_bundle,
103: "serverPath");
104: public String _deploymentPath = Bundle.getStringTrimmed(_bundle,
105: "deploymentPathGlassfish");
106: public String _separator = Bundle.getStringTrimmed(_bundle,
107: "separator");
108: public String _reformatCode = Bundle.getStringTrimmed(_bundle,
109: "reformatCode");
110: //Palette variables
111: public String _standardPalette = Bundle.getStringTrimmed(_bundle,
112: "standardPalette");
113: public String _standardButton = Bundle.getStringTrimmed(_bundle,
114: "standardButton");
115: public static DesignerPaneOperator designer;
116: public static SheetTableOperator sheet;
117: public static ServerNavigatorOperator explorer;
118:
119: public AcceptanceTest(String testName) {
120: super (testName);
121: }
122:
123: public static Test suite() {
124: TestSuite suite = new TestSuite();
125: suite.addTest(new AcceptanceTest("testCreateProject"));
126: suite.addTest(new AcceptanceTest("testAddButton"));
127: suite.addTest(new AcceptanceTest("testAddActionEvent"));
128: suite.addTest(new AcceptanceTest("testVerifyJSPEditor"));
129: // can't locate property in property sheet window
130: // suite.addTest(new AcceptanceTest("testChangeTextInPropertySheet"));
131: // suite.addTest(new AcceptanceTest("testChangeTextInJSPEditor"));
132: suite.addTest(new AcceptanceTest("testDeploy"));
133: suite.addTest(new AcceptanceTest("testCloseProject"));
134: suite.addTest(new AcceptanceTest("testUndeploy"));
135: suite.addTest(new AcceptanceTest("testCheckIDELog"));
136: return suite;
137: }
138:
139: /** method called before each testcase
140: */
141: protected void setUp() {
142: System.out.println("######## " + getName() + " #######");
143: }
144:
145: /** method called after each testcase
146: */
147: protected void tearDown() {
148: System.out.println("######## " + getName()
149: + " Finished #######");
150: }
151:
152: /*
153: * Start PE. Delete PointBase travel resource
154: */
155: private void testStartup() {
156: //Start PE is it is not started yet
157: ServerNavigatorOperator se = new ServerNavigatorOperator();
158: // Skip next 2 steps if running on Mac as Jemmy's call popup issue
159: if (!System.getProperty("os.name").equals("Mac OS X")) {
160: //Start PE is it is not started yet
161: try {
162: se.startServer("J2EE");
163: } catch (Exception e) {
164: }
165: // Delete pb travel resource if it exists
166: se.deleteResource("jdbc/Travel");
167: }
168: }
169:
170: /*
171: * Create new project
172: * And add property val to SessionBean1.java
173: */
174: public void testCreateProject() {
175: startTest();
176: log("**Creating Project");
177: //Create Project
178: try {
179: ComponentUtils.createNewProject(_projectName);
180: } catch (Exception e) {
181: log(">> Project Creation Failed");
182: e.printStackTrace();
183: log(e.toString());
184: fail();
185: }
186: log("**Done");
187: endTest();
188: }
189:
190: /*
191: * Add 2 Buttons. Set their action event handler.
192: */
193: public void testAddButton() {
194: startTest();
195: designer = new DesignerPaneOperator(RaveWindowOperator
196: .getDefaultRave());
197: log("Add a button component");
198: PaletteContainerOperator palette = new PaletteContainerOperator(
199: Bundle.getStringTrimmed(_bundle, "standardPalette"));
200: Util.wait(2000);
201: palette.addComponent(Bundle.getStringTrimmed(_bundle,
202: "standardButton"), designer,
203: new Point(xButton, yButton));
204:
205: TestUtils.wait(2000);
206: Util.saveAllAPICall();
207: Util.wait(500);
208: endTest();
209: }
210:
211: /*
212: * Verify button_action() code is generated
213: */
214: public void testAddActionEvent() {
215: startTest();
216: log("Open java code editor view by clicking designer and then double clicking on the button ");
217: designer.clickMouse(20, 20, 1);
218: TestUtils.wait(1000);
219: designer.clickMouse(xButton + 5, yButton + 5, 2);
220: TestUtils.wait(1000);
221: String expectedStr = "button1_action()";
222: designer = new DesignerPaneOperator(RaveWindowOperator
223: .getDefaultRave());
224:
225: JEditorPaneOperator editor = new JEditorPaneOperator(
226: RaveWindowOperator.getDefaultRave(), "public class "
227: + "Page1");
228:
229: editor.setVerification(false);
230: TestUtils.wait(2000);
231: assertFalse("There is no \"" + expectedStr
232: + "\" string in jsp editor",
233: new org.netbeans.jellytools.EditorOperator("Page1")
234: .getText().indexOf(expectedStr) == -1);
235:
236: editor.setText("log(\"StdButton action performed\");\n");
237: log("Reformat code");
238: TestUtils.wait(200);
239: editor.clickForPopup();
240: new JPopupMenuOperator().pushMenu(_reformatCode);
241: TestUtils.wait(200);
242: log("Editor Dump:");
243: log(editor.getText());
244: log("Switch back to Designer");
245: designer.makeComponentVisible();
246: TestUtils.wait(10000);
247: Util.saveAllAPICall();
248: Util.wait(2000);
249: endTest();
250: }
251:
252: /*
253: * Verfiy JPS code. Check for action="#{Page1.button1_action} "
254: */
255: public void testVerifyJSPEditor() {
256: startTest();
257: designer = new DesignerPaneOperator(RaveWindowOperator
258: .getDefaultRave());
259: designer.switchToJSPSource();
260: TestUtils.wait(2000);
261: log("Verify action tag should present in JSP editor");
262: String expectedStr = "action=\"#{Page1.button1_action}\"";
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(
285: _bundle, "propertyValue"), "Stoplight");
286: // sheet.setButtonValue(Bundle.getStringTrimmed(_bundle, "propertyValue"), "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 = "value=\"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.selectText("Submit");
322: editor.pushKey(KeyEvent.VK_DELETE);
323: editor.typeText("Trafficlight");
324: TestUtils.wait(200);
325:
326: log("Switch to designer. Verify that propertry sheet has been updated");
327: designer.makeComponentVisible();
328: TestUtils.wait(2000);
329:
330: sheet = new SheetTableOperator();
331: TestUtils.wait(2000);
332:
333: String expectedStr = "Trafficlight";
334: log(sheet.getValue(Bundle.getStringTrimmed(_bundle,
335: "propertyValue")));
336: assertFalse("There is no \"" + expectedStr
337: + "\" string property sheet", sheet.getValue(
338: Bundle.getStringTrimmed(_bundle, "propertyValue"))
339: .equals(expectedStr));
340:
341: TestUtils.wait(500);
342: Util.saveAllAPICall();
343: TestUtils.wait(1000);
344: endTest();
345: }
346:
347: /*
348: * Deploy application
349: */
350: public void testDeploy() {
351: startTest();
352: //need to wait responce
353: Waiter deploymentWaiter = new Waiter(new
354:
355: Waitable() {
356:
357: public Object actionProduced(Object output) {
358: String text = ((OutputOperator) output).getText();
359: if (text.indexOf(_buildSuccess) != -1) {
360: return _true;
361: }
362: return null;
363:
364: }
365:
366: public String getDescription() {
367: return ("Waiting Project Deployed");
368: }
369: });
370: log("Deploy from menu");
371: ProjectNavigatorOperator.pressPopupItemOnNode(_projectName,
372: _run);
373: TestUtils.wait(2000);
374: OutputOperator outputWindow = new OutputOperator();
375: deploymentWaiter.getTimeouts().setTimeout("Waiter.WaitingTime",
376: 240000);
377: log("wait until " + _buildSuccess);
378: try {
379: deploymentWaiter.waitAction(outputWindow);
380: } catch (InterruptedException e) {
381: log(outputWindow.getText());
382: e.printStackTrace();
383: fail("Deployment error: " + e);
384: }
385: log("Deployment complete");
386: endTest();
387: }
388:
389: public void testCloseProject() {
390: startTest();
391: Util.saveAllAPICall();
392: new ProjectNavigatorOperator().pressPopupItemOnNode(
393: _projectName, Bundle.getStringTrimmed(_bundle,
394: "CloseProjectPopupItem"));
395: //TestUtils.closeCurrentProject();
396: TestUtils.wait(5000);
397: endTest();
398: }
399:
400: /* Need to undeploy project to finish tests correctly */
401: public void testUndeploy() {
402: startTest();
403: log("Initialize");
404: explorer = ServerNavigatorOperator.showNavigatorOperator();
405: String serverPath = _serverPath + _projectServer; //Current deployment server
406: String deploymentPath = serverPath + _deploymentPath; //glassfish specific
407: String applicationPath = deploymentPath + _separator
408: + _projectName; //project name
409:
410: // Select the Server Navigator and set the JTreeOperator
411: log("get explorer");
412: new QueueTool().waitEmpty(100); //??
413: explorer.requestFocus();
414: JTreeOperator tree = explorer.getTree();
415: try {
416: Thread.sleep(4000);
417: } catch (Exception e) {
418: } // Sleep 4 secs to make sure Server Navigator is in focus
419:
420: // Need to refresh J2EE AppServer node
421: log("refresh");
422: explorer.pushPopup(tree, serverPath, _refresh);
423: TestUtils.wait(1000);
424:
425: log("refresh deployment path: " + deploymentPath);
426: TestUtils.wait(1000);
427: explorer.selectPath(deploymentPath);
428: explorer.getTree().expandPath(
429: explorer.getTree().findPath(deploymentPath));
430: explorer.pushPopup(tree, deploymentPath, _refresh);
431: TestUtils.wait(1000);
432:
433: log("undeploy Path: " + applicationPath);
434: explorer.selectPath(applicationPath);
435: TestUtils.wait(1000);
436:
437: log("Push Menu Undeploy...");
438: explorer.pushPopup(explorer.getTree(), applicationPath,
439: _undeploy);
440: TestUtils.wait(5000);
441: endTest();
442: }
443:
444: public void testCheckIDELog() {
445: startTest();
446: try {
447: String err = ComponentUtils.hasUnexpectedException();
448: String str = "";
449: if (!(err.equals(""))) {
450: assertTrue(
451: "Unexpected exceptions found in message.log: "
452: + err, str.equals(""));
453: }
454: } catch (IOException ioe) {
455: ioe.printStackTrace();
456: fail("Failed to open message.log : " + ioe);
457: }
458: endTest();
459: }
460: }
|