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.addremove;
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 = ComponentUtils.getBundle();
071: public String _projectName = "AddRemoveAcceptanceTest";
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 _projectJ2EEVersion = Bundle.getStringTrimmed(
086: _bundle, "projectJ2EEVersion");
087:
088: public static int xAddRemove = 50;
089: public static int yAddRemove = 150;
090: public static int xMessage = 150;
091: public static int yMessage = 50;
092: public static int xButton = 50;
093: public static int yButton = 50;
094: String addRemoveID = "addRemoveList1";
095: String addRemoveLabel = "Lab Systems to be Upgraded:";
096: String addRemoveToolTip = "Please select the lab systems to be upgraded.";
097: String importStatement = "import "
098: + Bundle.getStringTrimmed(_bundle, "optionType") + ";";
099: //String[] javaCode1 = {"import com.sun.rave.web.ui.model.Option;"};
100: String[] javaCode1 = { importStatement };
101: String[] javaCode2 = { " Option[] ilmHosts = new Option[] { " };
102: String[] javaCode3 = { "new Option(\"bsqe-falcon.sfbay\"),",
103: "new Option(\"rave-shark.sfbay\"),",
104: "new Option(\"rave-express.sfbay\"),",
105: "new Option(\"clue.sfbay\"),",
106: "new Option(\"rave-sol.eng\"),",
107: "new Option(\"sheezy.sfbay\"),",
108: "new Option(\"caliban.sfbay\"),",
109: "new Option(\"rave-eagle.sfbay\"),",
110: "new Option(\"raveqe-fire.sfbay\")" };
111: String[] javaCode4 = { "getSessionBean1().setLabMachines(ilmHosts);" };
112:
113: //undeployment
114: public String _undeploy = Bundle.getStringTrimmed(_bundle,
115: "undeploy");
116: public String _refresh = Bundle
117: .getStringTrimmed(_bundle, "refresh");
118: public String _serverPath = Bundle.getStringTrimmed(_bundle,
119: "serverPath");
120: public String _deploymentPath = Bundle.getStringTrimmed(_bundle,
121: "deploymentPathGlassfish");
122: public String _separator = Bundle.getStringTrimmed(_bundle,
123: "separator");
124:
125: //Outline variables
126: public String _outlineForm1 = Bundle.getStringTrimmed(_bundle,
127: "outlineForm1");
128:
129: public static DesignerPaneOperator designer;
130: public static SheetTableOperator sheet;
131: public static ServerNavigatorOperator explorer;
132: public static DocumentOutlineOperator outline;
133:
134: public AcceptanceTest(String testName) {
135: super (testName);
136: }
137:
138: public static Test suite() {
139: TestSuite suite = new TestSuite();
140: suite.addTest(new AcceptanceTest("testCreateProject"));
141: suite.addTest(new AcceptanceTest("testAddComponents"));
142: suite.addTest(new AcceptanceTest("testConfigureAddRemove"));
143: // suite.addTest(new AcceptanceTest("testAddSessionBeanProperty"));
144: // suite.addTest(new AcceptanceTest("testEditJavaSource"));
145: // suite.addTest(new AcceptanceTest("testAddRemoveDataBinding"));
146: suite.addTest(new AcceptanceTest("testDeploy"));
147: suite.addTest(new AcceptanceTest("testCloseProject"));
148: suite.addTest(new AcceptanceTest("testUndeploy"));
149: suite.addTest(new AcceptanceTest("testCheckIDELog"));
150:
151: return suite;
152: }
153:
154: /** method called before each testcase
155: */
156: protected void setUp() {
157: System.out.println("######## " + getName() + " #######");
158: }
159:
160: /** method called after each testcase
161: */
162: protected void tearDown() {
163: System.out.println("######## " + getName()
164: + " Finished #######");
165: }
166:
167: /*
168: * Start PE. Delete PointBase travel resource
169: */
170: private void testStartup() {
171: //Start PE is it is not started yet
172: ServerNavigatorOperator se = new ServerNavigatorOperator();
173: // Skip next 2 steps if running on Mac as Jemmy's call popup issue
174: if (!System.getProperty("os.name").equals("Mac OS X")) {
175: //Start PE is it is not started yet
176: try {
177: se.startServer("J2EE");
178: } catch (Exception e) {
179: }
180: // Delete pb travel resource if it exists
181: se.deleteResource("jdbc/Travel");
182: }
183: }
184:
185: /*
186: * Create new project
187: * And add property val to SessionBean1.java
188: */
189: public void testCreateProject() {
190: startTest();
191: log("**Creating Project");
192: log(_projectJ2EEVersion);
193: //Create Project
194: try {
195: ComponentUtils.createNewProject(_projectName);
196: } catch (Exception e) {
197: log(">> Project Creation Failed");
198: e.printStackTrace();
199: log(e.toString());
200: fail();
201: }
202: log("**Done");
203: endTest();
204: }
205:
206: /*
207: * Add an addremove, button and message components.
208: */
209:
210: public void testAddComponents() {
211: startTest();
212: designer = new DesignerPaneOperator(RaveWindowOperator
213: .getDefaultRave());
214:
215: log("Add a button component.");
216: PaletteContainerOperator palette = new PaletteContainerOperator(
217: Bundle.getStringTrimmed(_bundle, "basicPalette"));
218: Util.wait(2000);
219: palette.addComponent(Bundle.getStringTrimmed(_bundle,
220: "basicButton"), designer, new Point(xButton, yButton));
221: // sheet = new SheetTableOperator();
222: // sheet.setButtonValue(Bundle.getStringTrimmed(_bundle, "propertyText"), "Get Machines");
223: //ComponentUtils.setProperty(sheet, Bundle.getStringTrimmed(_bundle, "propertyText"), "Get Machines");
224: Util.wait(500);
225:
226: log("Add an AddRemove component");
227: palette = new PaletteContainerOperator(Bundle.getStringTrimmed(
228: _bundle, "compositePalette"));
229: palette.addComponent(Bundle.getStringTrimmed(_bundle,
230: "compositeAddRemove"), designer, new Point(xAddRemove,
231: yAddRemove));
232: Util.wait(2500);
233:
234: // log("Add a message component");
235: // palette = new PaletteContainerOperator(Bundle.getStringTrimmed(_bundle, "basicPalette"));
236: // Util.wait(2000);
237: // palette.addComponent(Bundle.getStringTrimmed(_bundle, "basicMessage"), designer, new Point(xMessage, yMessage));
238: // Util.wait(500);
239: // sheet = new SheetTableOperator();
240: // Util.wait(1500);
241: // sheet.setComboBoxValue(Bundle.getStringTrimmed(_bundle, "propertyFor"), "addRemoveList1");
242: // Util.wait(500);
243:
244: Util.saveAllAPICall();
245: Util.wait(2000);
246: endTest();
247: }
248:
249: public void testConfigureAddRemove() {
250: startTest();
251: // causes ee4 to lock up
252: // log("Select AddRemove Component");
253: // designer.clickMouse(addRemoveID, 1);
254: DocumentOutlineOperator doo = new DocumentOutlineOperator(Util
255: .getMainWindow());
256: Util.wait(2000);
257:
258: log("**Select addRemove1 from Outline window");
259: String path = _outlineForm1 + "addRemoveList1";
260: doo.verify();
261: // doo.clickOnPath(path);
262: doo.selectPath(path);
263: Util.wait(5000);
264:
265: if (_projectJ2EEVersion.equals("J2EE 1.4")) {
266: // sheet calls hang in EE4 project.
267: // sheet = new SheetTableOperator();
268: // sheet.setButtonValue(Bundle.getStringTrimmed(_bundle, "propertyLabel"), addRemoveLabel);
269: // Util.wait(500);
270: } else {
271: // Util.wait(500);
272: log("Set following properties to True: LabelOnTop,moveButtons, selectetAll, requried, sort");
273: sheet = new SheetTableOperator();
274: sheet.setButtonValue(Bundle.getStringTrimmed(_bundle,
275: "propertyLabel"), addRemoveLabel);
276: Util.wait(500);
277: sheet.setCheckBoxValue(Bundle.getStringTrimmed(_bundle,
278: "propertyLabelOnTop"), "true");
279: Util.wait(500);
280: sheet.setCheckBoxValue(Bundle.getStringTrimmed(_bundle,
281: "propertyMoveButtons"), "true");
282: Util.wait(500);
283: sheet.setCheckBoxValue(Bundle.getStringTrimmed(_bundle,
284: "propertySelectAll"), "true");
285: Util.wait(500);
286: sheet.setCheckBoxValue(Bundle.getStringTrimmed(_bundle,
287: "propertyRequired"), "true");
288: Util.wait(500);
289: sheet.setCheckBoxValue(Bundle.getStringTrimmed(_bundle,
290: "propertySorted"), "true");
291: Util.wait(500);
292: ComponentUtils.setProperty(sheet, Bundle.getStringTrimmed(
293: _bundle, "propertyToolTip"), addRemoveToolTip);
294: Util.wait(500);
295: }
296:
297: Util.saveAllAPICall();
298: Util.wait(2000);
299: endTest();
300: }
301:
302: public void testAddSessionBeanProperty() {
303: startTest();
304: String path = _projectName + "|"
305: + Bundle.getStringTrimmed(_bundle, "SessionBean_Path");
306: String dataType = Bundle
307: .getStringTrimmed(_bundle, "optionType")
308: + "[]";
309: log("Datatype=" + dataType);
310: ComponentUtils.addObjectProperty(path, "labMachines", dataType,
311: Bundle.getStringTrimmed(_bundle,
312: "BeanPattern_Mode_ReadWrite"));
313: endTest();
314: }
315:
316: public void testEditJavaSource() {
317: startTest();
318: log("Double click at designer to open Jave Editor");
319: designer = new DesignerPaneOperator(RaveWindowOperator
320: .getDefaultRave());
321: designer.clickMouse(20, 20, 2);
322: TestUtils.wait(1000);
323:
324: log("Enter import statement");
325: EditorOperator editor = new EditorOperator(
326: Util.getMainWindow(), "Page1.java");
327: editor.setCaretPosition("public class " + "Page1", true);
328: editor.pushKey(KeyEvent.VK_ENTER);
329: TestUtils.wait(1000);
330: log(importStatement);
331: ComponentUtils.insertJavaCode(editor, javaCode1);
332: editor.pushKey(KeyEvent.VK_ENTER);
333: editor.pushKey(KeyEvent.VK_ENTER);
334: TestUtils.wait(1000);
335:
336: log("Enter init sessionbean property code");
337: editor.setCaretPosition("public void init() {", false);
338: TestUtils.wait(1000);
339: editor.pushKey(KeyEvent.VK_ENTER);
340: ComponentUtils.insertJavaCode(editor, javaCode2);
341: editor.pushKey(KeyEvent.VK_ENTER);
342: editor.pushKey(KeyEvent.VK_DOWN);
343: editor.insert(";");
344: editor.pushKey(KeyEvent.VK_UP);
345: ComponentUtils.insertJavaCode(editor, javaCode3);
346: editor.pushKey(KeyEvent.VK_DOWN);
347: editor.pushKey(KeyEvent.VK_ENTER);
348: ComponentUtils.insertJavaCode(editor, javaCode4);
349: TestUtils.wait(1000);
350:
351: log("Switch to design panel");
352: designer.makeComponentVisible();
353:
354: TestUtils.wait(5000);
355: Util.saveAllAPICall();
356: TestUtils.wait(2000);
357: endTest();
358: }
359:
360: public void testAddRemoveDataBinding() {
361:
362: startTest();
363: designer = new DesignerPaneOperator(RaveWindowOperator
364: .getDefaultRave());
365: ComponentUtils
366: .setPropertyBinding(designer, xAddRemove + 5,
367: yAddRemove + 5, Bundle.getStringTrimmed(
368: _bundle, "propertyItems"),
369: "#{SessionBean1.labMachines}");
370:
371: Util.saveAllAPICall();
372: Util.wait(2000);
373: endTest();
374: }
375:
376: /*
377: * Deploy application
378: */
379: public void testDeploy() {
380: startTest();
381: //need to wait responce
382: Waiter deploymentWaiter = new Waiter(new Waitable() {
383: public Object actionProduced(Object output) {
384: String text = ((OutputOperator) output).getText();
385: if (text.indexOf(_buildSuccess) != -1)
386: return _true;
387: return null;
388:
389: }
390:
391: public String getDescription() {
392: return ("Waiting Project Deployed");
393: }
394: });
395: log("Deploy from menu");
396: ProjectNavigatorOperator.pressPopupItemOnNode(_projectName,
397: _run);
398: TestUtils.wait(2000);
399: OutputOperator outputWindow = new OutputOperator();
400: deploymentWaiter.getTimeouts().setTimeout("Waiter.WaitingTime",
401: 240000);
402: log("wait until " + _buildSuccess);
403: try {
404: deploymentWaiter.waitAction(outputWindow);
405: } catch (InterruptedException e) {
406: log(outputWindow.getText());
407: e.printStackTrace();
408: fail("Deployment error: " + e);
409: }
410: log("Deployment complete");
411: endTest();
412: }
413:
414: public void testCloseProject() {
415: startTest();
416: Util.saveAllAPICall();
417: new ProjectNavigatorOperator().pressPopupItemOnNode(
418: _projectName, Bundle.getStringTrimmed(_bundle,
419: "CloseProjectPopupItem"));
420: //TestUtils.closeCurrentProject();
421: TestUtils.wait(5000);
422: endTest();
423: }
424:
425: /* Need to undeploy project to finish tests correctly */
426: public void testUndeploy() {
427: startTest();
428: log("Initialize");
429: explorer = ServerNavigatorOperator.showNavigatorOperator();
430: String serverPath = _serverPath + _projectServer; //Current deployment server
431: String deploymentPath = serverPath + _deploymentPath; //glassfish specific
432: String applicationPath = deploymentPath + _separator
433: + _projectName; //project name
434:
435: // Select the Server Navigator and set the JTreeOperator
436: log("get explorer");
437: new QueueTool().waitEmpty(100); //??
438: explorer.requestFocus();
439: JTreeOperator tree = explorer.getTree();
440: try {
441: Thread.sleep(4000);
442: } catch (Exception e) {
443: } // Sleep 4 secs to make sure Server Navigator is in focus
444:
445: // Need to refresh J2EE AppServer node
446: log("refresh");
447: explorer.pushPopup(tree, serverPath, _refresh);
448: TestUtils.wait(1000);
449:
450: log("refresh deployment path: " + deploymentPath);
451: TestUtils.wait(1000);
452: explorer.selectPath(deploymentPath);
453: explorer.getTree().expandPath(
454: explorer.getTree().findPath(deploymentPath));
455: explorer.pushPopup(tree, deploymentPath, _refresh);
456: TestUtils.wait(1000);
457:
458: log("undeploy Path: " + applicationPath);
459: explorer.selectPath(applicationPath);
460: TestUtils.wait(1000);
461:
462: log("Push Menu Undeploy...");
463: explorer.pushPopup(explorer.getTree(), applicationPath,
464: _undeploy);
465: TestUtils.wait(5000);
466: endTest();
467: }
468:
469: public void testCheckIDELog() {
470: startTest();
471: try {
472: String err = ComponentUtils.hasUnexpectedException();
473: String str = "";
474: if (!(err.equals(""))) {
475: assertTrue(
476: "Unexpected exceptions found in message.log: "
477: + err, str.equals(""));
478: }
479: } catch (IOException ioe) {
480: ioe.printStackTrace();
481: fail("Failed to open message.log : " + ioe);
482: }
483: endTest();
484: }
485: }
|