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.listbox;
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.gravy.dataconnectivity.ServerNavigatorOperator;
059: import org.netbeans.jemmy.operators.*;
060: import org.netbeans.modules.visualweb.test.components.util.ComponentUtils;
061: import org.netbeans.jellytools.OutputOperator;
062: import org.netbeans.jemmy.Waitable;
063: import org.netbeans.jemmy.Waiter;
064: import org.netbeans.jemmy.QueueTool;
065: import org.netbeans.jemmy.operators.JTreeOperator;
066:
067: /**
068: * @author Sherry Zhou (sherry.zhou@sun.com)
069: */
070: public class AcceptanceTest extends RaveTestCase {
071:
072: public String _bundle = ComponentUtils.getBundle();
073: public String _projectName = "ListboxAcceptanceTest";
074: public String _projectServer = Bundle.getStringTrimmed(_bundle,
075: "projectServer");
076: public String _logFileLocation = Bundle.getStringTrimmed(_bundle,
077: "logFile");
078: public String _logFile = System.getProperty("xtest.sketchpad")
079: + File.separator + _logFileLocation;
080: public String _exception = Bundle.getStringTrimmed(_bundle,
081: "Exception");
082: public String _close = Bundle.getStringTrimmed(_bundle, "close");
083: public String _run = Bundle.getStringTrimmed(_bundle, "Run");
084: public String _buildSuccess = Bundle.getStringTrimmed(_bundle,
085: "buildSuccess");
086: public String _true = Bundle.getStringTrimmed(_bundle, "true");
087:
088: //undeployment
089: public String _undeploy = Bundle.getStringTrimmed(_bundle,
090: "undeploy");
091: public String _refresh = Bundle
092: .getStringTrimmed(_bundle, "refresh");
093: public String _serverPath = Bundle.getStringTrimmed(_bundle,
094: "serverPath");
095: public String _deploymentPath = Bundle.getStringTrimmed(_bundle,
096: "deploymentPathGlassfish");
097: public String _separator = Bundle.getStringTrimmed(_bundle,
098: "separator");
099:
100: public static int xListbox1 = 50;
101: public static int yListbox1 = 50;
102: public static int xListbox2 = 50;
103: public static int yListbox2 = 250;
104: public static int xTextArea = 150;
105: public static int yTextArea = 100;
106: public static int xButton1 = 150;
107: public static int yButton1 = 50;
108: public static int xButton2 = 150;
109: public static int yButton2 = 250;
110: public static DesignerPaneOperator designer;
111: public static SheetTableOperator sheet;
112: public static ServerNavigatorOperator explorer;
113:
114: public AcceptanceTest(String testName) {
115: super (testName);
116: }
117:
118: public static Test suite() {
119: TestSuite suite = new TestSuite();
120: suite.addTest(new AcceptanceTest("testCreateProject"));
121: suite.addTest(new AcceptanceTest("testAddListbox1"));
122: suite.addTest(new AcceptanceTest("testListbox1DataBinding"));
123: // suite.addTest(new AcceptanceTest("testAddSessionBeanProperties"));
124: // suite.addTest(new AcceptanceTest("testBindSelectedProperty"));
125: // suite.addTest(new AcceptanceTest("testAddButton1ActionEvent"));
126: // suite.addTest(new AcceptanceTest("testAddListbox2"));
127: // suite.addTest(new AcceptanceTest("testListbox2DataBinding"));
128: // suite.addTest(new AcceptanceTest("testAddButton2ActionEvent"));
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 first listbox components. Set properties
191: */
192:
193: public void testAddListbox1() {
194: startTest();
195: designer = new DesignerPaneOperator(RaveWindowOperator
196: .getDefaultRave());
197:
198: log("Add first listbox component");
199: PaletteContainerOperator palette = new PaletteContainerOperator(
200: Bundle.getStringTrimmed(_bundle, "basicPalette"));
201: Util.wait(2000);
202: //palette.dndPaletteComponent(Bundle.getStringTrimmed(_bundle, "basicListbox"), designer, new Point(xListbox1, yListbox1));
203: palette.addComponent(Bundle.getStringTrimmed(_bundle,
204: "basicListbox"), designer, new Point(xListbox1,
205: yListbox1));
206: Util.wait(2000);
207:
208: DocumentOutlineOperator doo = new DocumentOutlineOperator(Util
209: .getMainWindow());
210: Util.wait(2000);
211:
212: log("**Select listbox1 from Outline window");
213: String path = "Page1|page1|html1|body1|form1|listbox1";
214: doo.verify();
215: doo.clickOnPath(path);
216: //doo.selectPath(path);
217: Util.wait(5000);
218:
219: log("set its label, labelOnTop properties");
220: sheet = new SheetTableOperator();
221: Util.wait(2000);
222: // sheet.setButtonValue() can't location lable property if labelOnTop is in property sheet
223: // So use ComponentUtils.setProperty()
224: ComponentUtils.setProperty(sheet, Bundle.getStringTrimmed(
225: _bundle, "propertyLabel"), "Select a Person");
226: Util.wait(500);
227: sheet.setCheckBoxValue(Bundle.getStringTrimmed(_bundle,
228: "propertyLabelOnTop"), "true");
229: Util.wait(500);
230: //sheet.setButtonValue(Bundle.getStringTrimmed(_bundle, "propertyRows"), "5");
231: ComponentUtils.setProperty(sheet, Bundle.getStringTrimmed(
232: _bundle, "propertyRows"), "5");
233: Util.wait(500);
234: sheet.setCheckBoxValue(Bundle.getStringTrimmed(_bundle,
235: "propertyMultiple"), "true");
236: Util.wait(500);
237: Util.saveAllAPICall();
238: Util.wait(2000);
239: endTest();
240: }
241:
242: public void testListbox1DataBinding() {
243: startTest();
244: String _dataProvider = "customerDataProvider";
245: String _dbName = Bundle.getStringTrimmed(_bundle,
246: "Databses_SampleDBNode");
247: String _passwd = "app";
248: String _tableName = Bundle.getStringTrimmed(_bundle,
249: "Databases_CustomerTableNode");
250: log("Connect sample database");
251: ComponentUtils.connectDB(_dbName, _passwd);
252: ComponentUtils.bindToDataProvider(xListbox1 + 5, yListbox1 + 5,
253: _tableName, _dataProvider, "NAME", "NAME");
254: endTest();
255: }
256:
257: public void testAddButton1ActionEvent() {
258: startTest();
259: designer = new DesignerPaneOperator(RaveWindowOperator
260: .getDefaultRave());
261: designer.makeComponentVisible();
262:
263: log("Add button and text area component");
264: PaletteContainerOperator palette = new PaletteContainerOperator(
265: Bundle.getStringTrimmed(_bundle, "basicPalette"));
266: Util.wait(2000);
267: palette
268: .addComponent(Bundle.getStringTrimmed(_bundle,
269: "basicButton"), designer, new Point(xButton1,
270: yButton1));
271: Util.wait(500);
272: palette.addComponent(Bundle.getStringTrimmed(_bundle,
273: "basicTextArea"), designer, new Point(xTextArea,
274: yTextArea));
275: Util.wait(500);
276: // Double click at button to open Jave Editor
277: designer.clickMouse(xButton1 + 1, yButton1 + 1, 2);
278: TestUtils.wait(1000);
279: JEditorPaneOperator editor = new JEditorPaneOperator(
280: RaveWindowOperator.getDefaultRave(), "public class "
281: + "Page1");
282:
283: editor.setVerification(false);
284: TestUtils.wait(2000);
285: editor.requestFocus();
286: TestUtils.wait(2000);
287: editor.pushKey(KeyEvent.VK_ENTER);
288: editor
289: .setText("String[] mySelections = getSessionBean1().getChoices();\n");
290: editor.setText("String showSelections = \"\"; \n");
291: editor.setText("if (mySelections != null) { \n");
292: editor
293: .setText("// Create a list of the values of the selected items \n");
294: editor
295: .setText("for (int i = 0; i < mySelections.length; i++) \n");
296: editor
297: .setText("showSelections = showSelections + mySelections[i] +\"\n\"; \n");
298: // editor.setText("} \n");
299: editor.setText("if (showSelections.equals(\"\")) \n");
300: editor.setText("showSelections = \"nothing selected\"; \n");
301: editor.setText("else \n");
302: editor
303: .setText("showSelections = \"Values chosen:\n\" + showSelections; \n");
304: editor
305: .setText("// Display the list in the textArea1 text area \n");
306: editor.setText("getTextArea1().setValue(showSelections); \n");
307: TestUtils.wait(200);
308:
309: log("Reformat code");
310: editor.clickForPopup();
311: new JPopupMenuOperator().pushMenu("Reformat Code");
312: TestUtils.wait(200);
313:
314: // Switch to design panel
315: designer.makeComponentVisible();
316: TestUtils.wait(10000);
317: Util.saveAllAPICall();
318: Util.wait(2000);
319: endTest();
320: }
321:
322: /*
323: * Add second listbox. Set its property. Bind it to sessionbean property
324: */
325: public void testAddListbox2() {
326: startTest();
327: designer = new DesignerPaneOperator(RaveWindowOperator
328: .getDefaultRave());
329:
330: log("Add first listbox component");
331: PaletteContainerOperator palette = new PaletteContainerOperator(
332: Bundle.getStringTrimmed(_bundle, "basicPalette"));
333: Util.wait(2000);
334: palette.addComponent(Bundle.getStringTrimmed(_bundle,
335: "basicListbox"), designer, new Point(xListbox2,
336: yListbox2));
337:
338: log("set its label, labelOnTop properties");
339: sheet = new SheetTableOperator();
340: // sheet.setButtonValue(Bundle.getStringTrimmed(_bundle, "propertyLabel"), "Choices");
341: Util.wait(500);
342: // sheet.setCheckBoxValue(Bundle.getStringTrimmed(_bundle, "propertyRequired"), "true");
343: Util.wait(500);
344: Util.saveAllAPICall();
345: Util.wait(2000);
346: endTest();
347: }
348:
349: public void testAddSessionBeanProperties() {
350: startTest();
351: log("Add SessionBean property - choices");
352: String path = _projectName + "|"
353: + Bundle.getStringTrimmed(_bundle, "SessionBean_Path");
354: ComponentUtils.addObjectProperty(path, "choices", "String[]",
355: Bundle.getStringTrimmed(_bundle,
356: "BeanPattern_Mode_ReadWrite"));
357: Util.wait(500);
358:
359: log("Add SessionBean property - listOptions");
360: path = _projectName + "|"
361: + Bundle.getStringTrimmed(_bundle, "SessionBean_Path");
362: String type = Bundle.getStringTrimmed(_bundle, "optionType")
363: + "[]";
364: ComponentUtils.addObjectProperty(path, "listOptions", type,
365: Bundle.getStringTrimmed(_bundle,
366: "BeanPattern_Mode_ReadWrite"));
367: Util.wait(500);
368:
369: log("Add SessionBean property - choice2");
370: path = _projectName + "|"
371: + Bundle.getStringTrimmed(_bundle, "SessionBean_Path");
372: ComponentUtils.addObjectProperty(path, "choice2", "String",
373: Bundle.getStringTrimmed(_bundle,
374: "BeanPattern_Mode_ReadWrite"));
375: Util.wait(500);
376:
377: Util.saveAllAPICall();
378: Util.wait(2000);
379: endTest();
380: }
381:
382: public void testBindSelectedProperty() {
383: startTest();
384: designer = new DesignerPaneOperator(RaveWindowOperator
385: .getDefaultRave());
386: ComponentUtils.setPropertyBinding(designer, xListbox1,
387: yListbox1, "selected", "#{SessionBean1.choices}");
388: endTest();
389: }
390:
391: public void testListbox2DataBinding() {
392: startTest();
393: ComponentUtils.bindToObject(xListbox2, yListbox2,
394: "ApplicationBean1");
395: // ComponentUtils.bindToObject(xListbox2, yListbox2, new String[] {"Page1", "Page1"});
396: endTest();
397: }
398:
399: public void testAddButton2ActionEvent() {
400: startTest();
401: designer = new DesignerPaneOperator(RaveWindowOperator
402: .getDefaultRave());
403: designer.makeComponentVisible();
404:
405: log("Add button and text area component");
406: PaletteContainerOperator palette = new PaletteContainerOperator(
407: Bundle.getStringTrimmed(_bundle, "basicPalette"));
408: Util.wait(2000);
409: palette
410: .addComponent(Bundle.getStringTrimmed(_bundle,
411: "basicButton"), designer, new Point(xButton2,
412: yButton2));
413: Util.wait(500);
414:
415: // Double click at button to open Jave Editor
416: designer.clickMouse(xButton2 + 1, yButton2 + 1, 2);
417: TestUtils.wait(1000);
418: JEditorPaneOperator editor = new JEditorPaneOperator(
419: RaveWindowOperator.getDefaultRave(), "public class "
420: + "Page1");
421:
422: editor.setVerification(false);
423: TestUtils.wait(2000);
424: editor.requestFocus();
425: TestUtils.wait(2000);
426: editor.pushKey(KeyEvent.VK_ENTER);
427: editor
428: .setText("getTextArea1().setText(getSessionBean1().getChoices2()); \n");
429: // Switch to design panel
430: designer.makeComponentVisible();
431: TestUtils.wait(10000);
432: Util.saveAllAPICall();
433: Util.wait(2000);
434: endTest();
435: }
436:
437: /*
438: * Deploy application
439: */
440: public void testDeploy() {
441: startTest();
442: //need to wait responce
443: Waiter deploymentWaiter = new Waiter(new Waitable() {
444: public Object actionProduced(Object output) {
445: String text = ((OutputOperator) output).getText();
446: if (text.indexOf(_buildSuccess) != -1)
447: return _true;
448: return null;
449:
450: }
451:
452: public String getDescription() {
453: return ("Waiting Project Deployed");
454: }
455: });
456: log("Deploy from menu");
457: ProjectNavigatorOperator.pressPopupItemOnNode(_projectName,
458: _run);
459: TestUtils.wait(2000);
460: OutputOperator outputWindow = new OutputOperator();
461: deploymentWaiter.getTimeouts().setTimeout("Waiter.WaitingTime",
462: 240000);
463: log("wait until " + _buildSuccess);
464: try {
465: deploymentWaiter.waitAction(outputWindow);
466: } catch (InterruptedException e) {
467: log(outputWindow.getText());
468: e.printStackTrace();
469: fail("Deployment error: " + e);
470: }
471: log("Deployment complete");
472: endTest();
473: }
474:
475: public void testCloseProject() {
476: startTest();
477: Util.saveAllAPICall();
478: new ProjectNavigatorOperator().pressPopupItemOnNode(
479: _projectName, Bundle.getStringTrimmed(_bundle,
480: "CloseProjectPopupItem"));
481: //TestUtils.closeCurrentProject();
482: TestUtils.wait(5000);
483: endTest();
484: }
485:
486: /* Need to undeploy project to finish tests correctly */
487: public void testUndeploy() {
488: startTest();
489: log("Initialize");
490: explorer = ServerNavigatorOperator.showNavigatorOperator();
491: String serverPath = _serverPath + _projectServer; //Current deployment server
492: String deploymentPath = serverPath + _deploymentPath; //glassfish specific
493: String applicationPath = deploymentPath + _separator
494: + _projectName; //project name
495:
496: // Select the Server Navigator and set the JTreeOperator
497: log("get explorer");
498: new QueueTool().waitEmpty(100); //??
499: explorer.requestFocus();
500: JTreeOperator tree = explorer.getTree();
501: try {
502: Thread.sleep(4000);
503: } catch (Exception e) {
504: } // Sleep 4 secs to make sure Server Navigator is in focus
505:
506: // Need to refresh J2EE AppServer node
507: log("refresh");
508: explorer.pushPopup(tree, serverPath, _refresh);
509: TestUtils.wait(1000);
510:
511: log("refresh deployment path: " + deploymentPath);
512: TestUtils.wait(1000);
513: explorer.selectPath(deploymentPath);
514: explorer.getTree().expandPath(
515: explorer.getTree().findPath(deploymentPath));
516: explorer.pushPopup(tree, deploymentPath, _refresh);
517: TestUtils.wait(1000);
518:
519: log("undeploy Path: " + applicationPath);
520: explorer.selectPath(applicationPath);
521: TestUtils.wait(1000);
522:
523: log("Push Menu Undeploy...");
524: explorer.pushPopup(explorer.getTree(), applicationPath,
525: _undeploy);
526: TestUtils.wait(5000);
527: endTest();
528: }
529:
530: public void testCheckIDELog() {
531: startTest();
532: try {
533: String err = ComponentUtils.hasUnexpectedException();
534: String str = "";
535: if (!(err.equals(""))) {
536: assertTrue(
537: "Unexpected exceptions found in message.log: "
538: + err, str.equals(""));
539: }
540: } catch (IOException ioe) {
541: ioe.printStackTrace();
542: fail("Failed to open message.log : " + ioe);
543: }
544: endTest();
545: }
546: }
|