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.action.tree;
043:
044: import junit.framework.Test;
045: import junit.framework.TestSuite;
046:
047: import java.io.File;
048: import java.awt.*;
049: import java.io.IOException;
050: import org.netbeans.jemmy.operators.*;
051: import org.netbeans.jellytools.TopComponentOperator;
052: import org.netbeans.jemmy.QueueTool;
053: import org.netbeans.jemmy.operators.JTreeOperator;
054:
055: import org.netbeans.modules.visualweb.gravy.*;
056: import org.netbeans.modules.visualweb.gravy.ProjectNavigatorOperator;
057: import org.netbeans.modules.visualweb.gravy.dataconnectivity.ServerNavigatorOperator;
058: import org.netbeans.modules.visualweb.gravy.toolbox.PaletteContainerOperator;
059: import org.netbeans.modules.visualweb.gravy.designer.DesignerPaneOperator;
060: import org.netbeans.modules.visualweb.gravy.properties.SheetTableOperator;
061: import org.netbeans.modules.visualweb.gravy.dataconnectivity.ServerNavigatorOperator;
062:
063: import org.netbeans.modules.visualweb.test.components.util.ComponentUtils;
064: import org.netbeans.jellytools.OutputOperator;
065: import org.netbeans.jemmy.Waitable;
066: import org.netbeans.jemmy.Waiter;
067:
068: /**
069: * @author Sherry Zhou (sherry.zhou@sun.com)
070: */
071: public class AcceptanceTest extends RaveTestCase {
072:
073: public String _bundle = "org.netbeans.modules.visualweb.test.components.Component";
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.workdir")
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: public String _projectName = "TreeAcceptanceTest";
088: public String dataDir = ComponentUtils.getDataDir() + "action"
089: + File.separator;
090: String pdfFile = dataDir + "catalog.pdf";
091: String imageFile = dataDir + "orchid1.JPG";
092: public String _requestPrefix = "";
093: public static int xTree = 50;
094: public static int yTree = 50;
095: public static int xTreeNode = 70;
096: public static int yTreeNode = 70;
097: public static int xLabel = 100;
098: public static int yLabel = 50;
099:
100: public String _page1 = "Page1";
101: public String _page2 = "Page2";
102:
103: //undeployment
104: public String _undeploy = Bundle.getStringTrimmed(_bundle,
105: "undeploy");
106: public String _refresh = Bundle
107: .getStringTrimmed(_bundle, "refresh");
108: public String _serverPath = Bundle.getStringTrimmed(_bundle,
109: "serverPath");
110: public String _deploymentPath = Bundle.getStringTrimmed(_bundle,
111: "deploymentPathGlassfish");
112: public String _separator = Bundle.getStringTrimmed(_bundle,
113: "separator");
114:
115: public static DesignerPaneOperator designer;
116: public static SheetTableOperator sheet;
117: public static ProjectNavigatorOperator prjNav;
118: public static PaletteContainerOperator palette;
119: public static ServerNavigatorOperator explorer;
120:
121: public AcceptanceTest(String testName) {
122: super (testName);
123: }
124:
125: public static Test suite() {
126: TestSuite suite = new TestSuite();
127: suite.addTest(new AcceptanceTest("testCreateProject"));
128: suite.addTest(new AcceptanceTest("testAddTree"));
129: suite.addTest(new AcceptanceTest("testConfigureTreeNodes"));
130: suite.addTest(new AcceptanceTest("testAddSecondPage"));
131: suite.addTest(new AcceptanceTest("testCreatePageNavigation"));
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(e);
185: }
186: log("**Done");
187: endTest();
188: }
189:
190: /*
191: * Add tree component. Set its text via property sheet
192: */
193:
194: public void testAddTree() {
195: startTest();
196: designer = new DesignerPaneOperator(RaveWindowOperator
197: .getDefaultRave());
198:
199: log("Add Tree component");
200: palette = new PaletteContainerOperator(Bundle.getStringTrimmed(
201: _bundle, "basicPalette"));
202: Util.wait(5000);
203: palette.addComponent(Bundle.getStringTrimmed(_bundle,
204: "basicTree"), designer, new Point(xTree, yTree));
205:
206: log("Set tree's text property via property sheet ");
207: sheet = new SheetTableOperator();
208: Util.wait(2000);
209: ComponentUtils.setProperty(sheet, Bundle.getStringTrimmed(
210: _bundle, "propertyText"), "Documents");
211: //sheet.setButtonValue(Bundle.getStringTrimmed(_bundle, "propertyText"), "Documents");
212:
213: log("Set Tree Node 1's text property");
214: Util.wait(1000);
215:
216: log("**Select Tree Node 1 from Outline window");
217: selectOutlineNode("tree1:Documents|treeNode1:Tree Node 1");
218:
219: sheet = new SheetTableOperator();
220: Util.wait(5000);
221: ComponentUtils.setProperty(sheet, Bundle.getStringTrimmed(
222: _bundle, "propertyText"), "Creator Tutorial");
223: Util.wait(1000);
224: ComponentUtils.setProperty(sheet, Bundle.getStringTrimmed(
225: _bundle, "propertyUrl"),
226: "http://java.sun.com/docs/books/tutorial");
227: Util.wait(1000);
228: Util.saveAllAPICall();
229: Util.wait(2000);
230: endTest();
231: }
232:
233: /*
234: * Add 3 tree node components.
235: * Configure their properties
236: */
237: public void testConfigureTreeNodes() {
238: startTest();
239: log("Setup");
240: //Lines Fail!! See Lark's Temp fix
241: // palette = new PaletteContainerOperator(Bundle.getStringTrimmed(_bundle, "basicPalette"));
242: // PaletteContainerOperator palette = new PaletteContainerOperator(Bundle.getStringTrimmed(_bundle,"basicPalette"));
243: designer = new DesignerPaneOperator(RaveWindowOperator
244: .getDefaultRave());
245: sheet = new SheetTableOperator();
246: Util.wait(1000);
247: //Larks temp fix
248: /* log("larks temp workaround");
249: palette = new PaletteContainerOperator(null); //Seems to work, every other?
250: log("drop Tree Node2");
251: // palette.dndPaletteComponent(Bundle.getStringTrimmed(_bundle, "basicTreeNode"), designer, new Point(xTreeNode, yTreeNode));
252: palette.addComponent("Tree Node", designer, new Point(70, 70));
253: Util.wait(1000);
254: log("set properties");
255: sheet = new SheetTableOperator();
256: Util.wait(1000);
257: ComponentUtils.setProperty(sheet, Bundle.getStringTrimmed(_bundle, "propertyText"), "JSP Page" );
258: Util.wait(1000);
259: ComponentUtils.setProperty(sheet, Bundle.getStringTrimmed(_bundle, "propertyToolTip"), "Open Page2" );
260: Util.wait(1000);
261: sheet.setComboBoxValue(Bundle.getStringTrimmed(_bundle, "propertyTarget"), "New window (_blank)" );
262: Util.wait(1000);
263: log("Node2 added");
264:
265: log("drop Tree Node3");
266: designer.clickMouse("treeNode1", 1); //This is REALLY SLOW
267: palette = new PaletteContainerOperator(Bundle.getStringTrimmed(_bundle, "basicPalette"));
268: // palette.dndPaletteComponent(Bundle.getStringTrimmed(_bundle, "basicTreeNode"), designer, new Point(xTreeNode, yTreeNode));
269: palette.dndPaletteComponent("Tree Node", designer, new Point(70, 70));
270: Util.wait(1000);
271: log("set properties");
272: sheet = new SheetTableOperator();
273: Util.wait(1000);
274: ComponentUtils.setProperty(sheet, Bundle.getStringTrimmed(_bundle, "propertyText"), "Image File" );
275: Util.wait(1000);
276: ComponentUtils.setProperty(sheet, Bundle.getStringTrimmed(_bundle, "propertyToolTip"), "Show an image" );
277: Util.wait(1000);
278: sheet.setComboBoxValue(Bundle.getStringTrimmed(_bundle, "propertyTarget"), "New window (_blank)" );
279: Util.wait(1000);
280: log("Node3 added");
281:
282: log("drop Tree Node4");
283: designer.clickMouse("treeNode1", 1); //This is REALLY SLOW
284: palette = new PaletteContainerOperator(Bundle.getStringTrimmed(_bundle, "basicPalette"));
285: // palette.dndPaletteComponent(Bundle.getStringTrimmed(_bundle, "basicTreeNode"), designer, new Point(xTreeNode, yTreeNode));
286: palette.dndPaletteComponent("Tree Node", designer, new Point(70, 70));
287: Util.wait(1000);
288: log("set properties");
289: sheet = new SheetTableOperator();
290: Util.wait(1000);
291: ComponentUtils.setProperty(sheet, Bundle.getStringTrimmed(_bundle, "propertyText"), "PDF File" );
292: Util.wait(1000);
293: ComponentUtils.setProperty(sheet, Bundle.getStringTrimmed(_bundle, "propertyToolTip"), "Open a PDF File" );
294: Util.wait(1000);
295: sheet.setComboBoxValue(Bundle.getStringTrimmed(_bundle, "propertyTarget"), "New window (_blank)" );
296: Util.wait(1000);
297: log("Node4 added");
298:
299: log("end larks stuff");
300: //End Larks temp fix
301: */
302:
303: String[] treeNodeName = { "JSP Page", "Image File", "PDF File" };
304: String[] treeNodeToolTip = { "Open Page2", "Show an image",
305: "Open a PDF File" };
306: String[] treeNodeTarget = {
307: Bundle.getStringTrimmed(_bundle,
308: "propertyTargetNewWindow"),
309: "",
310: Bundle.getStringTrimmed(_bundle,
311: "propertyTargetNewWindow") };
312:
313: int index = 1;
314:
315: String path;
316: int tmpnode;
317:
318: log("Add 3 more tree nodes to Documents. Set the text, tooltip, target properties via property sheet ");
319: for (int i = 0; i < 3; i++) {
320:
321: log("Click Tree root node in outline");
322: selectOutlineNode("tree1:Documents");
323:
324: log("drop Tree Node" + i);
325: designer = new DesignerPaneOperator(RaveWindowOperator
326: .getDefaultRave());
327: palette = new PaletteContainerOperator(Bundle
328: .getStringTrimmed(_bundle, "basicPalette"));
329: palette.addComponent(Bundle.getStringTrimmed(_bundle,
330: "basicTreeNode"), designer, new Point(
331: xTreeNode + 5, yTreeNode + 5));
332: Util.wait(1000);
333:
334: log("select new node in outline");
335: tmpnode = i + 2;
336: selectOutlineNode("tree1:Documents|treeNode" + tmpnode
337: + ":Tree Node " + tmpnode);
338: Util.wait(1000);
339:
340: log("set properties");
341: sheet = new SheetTableOperator();
342: Util.wait(1000);
343: ComponentUtils.setProperty(sheet, Bundle.getStringTrimmed(
344: _bundle, "propertyText"), treeNodeName[i]);
345: Util.wait(1000);
346: ComponentUtils.setProperty(sheet, Bundle.getStringTrimmed(
347: _bundle, "propertyToolTip"), treeNodeToolTip[i]);
348: Util.wait(1000);
349: if (treeNodeTarget[i] != null)
350: sheet.setComboBoxValue(Bundle.getStringTrimmed(_bundle,
351: "propertyTarget"), treeNodeTarget[i]);
352: Util.wait(1000);
353: log("Node added");
354: }
355:
356: log("Set Image File Node's url property");
357: selectOutlineNode("tree1:Documents|treeNode3:Image File");
358: sheet = new SheetTableOperator();
359: sheet.setImage("treeNode3", Bundle.getStringTrimmed(_bundle,
360: "propertyUrl"), imageFile);
361: Util.wait(1000);
362:
363: log("Set FPD File Node's url property");
364: selectOutlineNode("tree1:Documents|treeNode4:PDF File");
365: sheet = new SheetTableOperator();
366: sheet.setImage("treeNode4", Bundle.getStringTrimmed(_bundle,
367: "propertyUrl"), pdfFile);
368: Util.wait(1000);
369:
370: Util.saveAllAPICall();
371: Util.wait(2000);
372: endTest();
373: }
374:
375: /*
376: * Create second page
377: */
378: public void testAddSecondPage() {
379: startTest();
380: log("Create Page2");
381: prjNav = ProjectNavigatorOperator.showProjectNavigator();
382: prjNav.addWebPage(_projectName, _page2);
383: Util.wait(1000);
384: log("Add a label component. Set its text property");
385: designer = new DesignerPaneOperator(Util.getMainWindow(), 1);
386: //designer = new DesignerPaneOperator(RaveWindowOperator.getDefaultRave());
387: log(designer.toString());
388: Util.wait(1000);
389: PaletteContainerOperator palette = new PaletteContainerOperator(
390: Bundle.getStringTrimmed(_bundle, "basicPalette"));
391: Util.wait(2000);
392: palette.addComponent(Bundle.getStringTrimmed(_bundle,
393: "basicLabel"), designer, new Point(xLabel, yLabel));
394: Util.wait(5000);
395: sheet = new SheetTableOperator();
396: Util.wait(1000);
397: ComponentUtils.setProperty(sheet, Bundle.getStringTrimmed(
398: _bundle, "propertyText"), _page2);
399:
400: Util.saveAllAPICall();
401: Util.wait(2000);
402: endTest();
403: }
404:
405: /*
406: * Create page navigation from JSP Page tree node to Page2
407: */
408: public void testCreatePageNavigation() {
409: startTest();
410: log("Go to Page1");
411: new TopComponentOperator(_page1).getFocus();
412: // designer = new DesignerPaneOperator(Util.getMainWindow());
413:
414: // log("Select treeNode2 and add action event");
415: // Util.wait(2000);
416: // selectOutlineNode("tree1:Documents|treeNode2:JSP Page"); // Always call Tree root context menu
417: // designer = new DesignerPaneOperator(RaveWindowOperator.getDefaultRave());
418: // Util.wait(2000);
419: // designer.clickMouse("treeNode2", 2);
420: // log("Set outcome to page2 in Java editor");
421: // JEditorPaneOperator editor = new JEditorPaneOperator(
422: // RaveWindowOperator.getDefaultRave(), "public class " + "Page1");
423: //
424: // editor.setVerification(false);
425: // TestUtils.wait(2000);
426: // editor.requestFocus();
427: // TestUtils.wait(2000);
428: // editor.selectText("return null;");
429: // editor.pushKey(KeyEvent.VK_DELETE);
430: // editor.setText("return \"page2\";\n");
431: // TestUtils.wait(200);
432: // editor.clickForPopup();
433: // new JPopupMenuOperator().pushMenu("Reformat Code");
434: // TestUtils.wait(200);
435: //
436: // log("Switch to designer");
437: // designer.makeComponentVisible();
438: // TestUtils.wait(10000);
439: // TODO fix the ComponentUtils.linkWebPages(), then uncommet next lines
440: //log("Create link between page1 to page2, named 'page1'");
441: //ComponentUtils.linkWebPages(designer, _page1, _page2, "page2");
442:
443: Util.saveAllAPICall();
444: Util.wait(2000);
445: endTest();
446: }
447:
448: /*
449: * Deploy application
450: */
451: public void testDeploy() {
452: startTest();
453: //need to wait responce
454: Waiter deploymentWaiter = new Waiter(new Waitable() {
455: public Object actionProduced(Object output) {
456: String text = ((OutputOperator) output).getText();
457: if (text.indexOf(_buildSuccess) != -1)
458: return _true;
459: return null;
460:
461: }
462:
463: public String getDescription() {
464: return ("Waiting Project Deployed");
465: }
466: });
467: log("Deploy from menu");
468: ProjectNavigatorOperator.pressPopupItemOnNode(_projectName,
469: _run);
470: TestUtils.wait(2000);
471: OutputOperator outputWindow = new OutputOperator();
472: deploymentWaiter.getTimeouts().setTimeout("Waiter.WaitingTime",
473: 240000);
474: log("wait until " + _buildSuccess);
475: try {
476: deploymentWaiter.waitAction(outputWindow);
477: } catch (InterruptedException e) {
478: log(outputWindow.getText());
479: e.printStackTrace();
480: fail("Deployment error: " + e);
481: }
482: log("Deployment complete");
483: endTest();
484: }
485:
486: public void testCloseProject() {
487: startTest();
488: Util.saveAllAPICall();
489: new ProjectNavigatorOperator().pressPopupItemOnNode(
490: _projectName, Bundle.getStringTrimmed(_bundle,
491: "CloseProjectPopupItem"));
492: //TestUtils.closeCurrentProject();
493: TestUtils.wait(5000);
494: endTest();
495: }
496:
497: private void selectOutlineNode(String path) {
498: DocumentOutlineOperator doo;
499: String fullPath;
500:
501: doo = new DocumentOutlineOperator(Util.getMainWindow());
502: Util.wait(2000);
503: fullPath = "Page1|page1|html1|body1|form1|" + path;
504: doo.verify();
505: doo.expandPath(fullPath);
506: doo.selectPath(fullPath);
507: Util.wait(5000);
508: }
509:
510: private void callForActionHandlerPopup(String node) {
511: DocumentOutlineOperator doo;
512: String fullPath;
513:
514: doo = new DocumentOutlineOperator(Util.getMainWindow());
515: Util.wait(2000);
516: fullPath = "Page1|page1|html1|body1|form1|" + node;
517: doo.verify();
518: doo.clickOnPath(fullPath);
519: doo.selectPath(fullPath);
520: Util.wait(5000);
521: doo.clickForPopup();
522: new JPopupMenuOperator()
523: .pushMenuNoBlock("Edit action Event Handler");
524: TestUtils.wait(2000);
525:
526: }
527:
528: /* Need to undeploy project to finish tests correctly */
529: public void testUndeploy() {
530: startTest();
531: log("Initialize");
532: explorer = ServerNavigatorOperator.showNavigatorOperator();
533: String serverPath = _serverPath + _projectServer; //Current deployment server
534: String deploymentPath = serverPath + _deploymentPath; //glassfish specific
535: String applicationPath = deploymentPath + _separator
536: + _projectName; //project name
537:
538: // Select the Server Navigator and set the JTreeOperator
539: log("get explorer");
540: new QueueTool().waitEmpty(100); //??
541: explorer.requestFocus();
542: JTreeOperator tree = explorer.getTree();
543: try {
544: Thread.sleep(4000);
545: } catch (Exception e) {
546: } // Sleep 4 secs to make sure Server Navigator is in focus
547:
548: // Need to refresh J2EE AppServer node
549: log("refresh");
550: explorer.pushPopup(tree, serverPath, _refresh);
551: TestUtils.wait(1000);
552:
553: log("refresh deployment path: " + deploymentPath);
554: TestUtils.wait(1000);
555: explorer.selectPath(deploymentPath);
556: explorer.getTree().expandPath(
557: explorer.getTree().findPath(deploymentPath));
558: explorer.pushPopup(tree, deploymentPath, _refresh);
559: TestUtils.wait(1000);
560:
561: log("undeploy Path: " + applicationPath);
562: explorer.selectPath(applicationPath);
563: TestUtils.wait(1000);
564:
565: log("Push Menu Undeploy...");
566: explorer.pushPopup(explorer.getTree(), applicationPath,
567: _undeploy);
568: TestUtils.wait(5000);
569: endTest();
570: }
571:
572: public void testCheckIDELog() {
573: startTest();
574: try {
575: String err = ComponentUtils.hasUnexpectedException();
576: String str = "";
577: if (!(err.equals(""))) {
578: assertTrue(
579: "Unexpected exceptions found in message.log: "
580: + err, str.equals(""));
581: }
582: } catch (IOException ioe) {
583: ioe.printStackTrace();
584: fail("Failed to open message.log : " + ioe);
585: }
586: endTest();
587: }
588: }
|