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.breadcrumbs;
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:
051: import org.netbeans.modules.visualweb.gravy.*;
052: import org.netbeans.modules.visualweb.gravy.ProjectNavigatorOperator;
053: import org.netbeans.modules.visualweb.gravy.dataconnectivity.ServerNavigatorOperator;
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.modules.visualweb.gravy.dataconnectivity.ServerNavigatorOperator;
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 _projectServer = Bundle.getStringTrimmed(_bundle,
072: "projectServer");
073: public String _logFileLocation = Bundle.getStringTrimmed(_bundle,
074: "logFile");
075: public String _logFile = System.getProperty("xtest.workdir")
076: + File.separator + _logFileLocation;
077: public String _exception = Bundle.getStringTrimmed(_bundle,
078: "Exception");
079: public String _close = Bundle.getStringTrimmed(_bundle, "close");
080: public String _run = Bundle.getStringTrimmed(_bundle, "Run");
081: public String _buildSuccess = Bundle.getStringTrimmed(_bundle,
082: "buildSuccess");
083: public String _true = Bundle.getStringTrimmed(_bundle, "true");
084:
085: public String _projectName = "BreadcrumbsAcceptanceTest";
086:
087: public String _page1 = "Page1";
088: public String _page2 = "Page2";
089:
090: //Menu variables
091: public String _separator = Bundle.getStringTrimmed(_bundle,
092: "separator");
093: public String _propertySheet = Bundle.getStringTrimmed(_bundle,
094: "propertySheet");
095:
096: //undeployment
097: public String _undeploy = Bundle.getStringTrimmed(_bundle,
098: "undeploy");
099: public String _refresh = Bundle
100: .getStringTrimmed(_bundle, "refresh");
101: public String _serverPath = Bundle.getStringTrimmed(_bundle,
102: "serverPath");
103: public String _deploymentPath = Bundle.getStringTrimmed(_bundle,
104: "deploymentPathGlassfish");
105:
106: public static int xLabel = 50;
107: public static int yLabel = 50;
108: public static int xBreadcrumbs = 50;
109: public static int yBreadcrumbs = 150;
110:
111: public static DesignerPaneOperator designer;
112: public static SheetTableOperator sheet;
113: public static ProjectNavigatorOperator prjNav = ProjectNavigatorOperator
114: .showProjectNavigator();
115: public static ServerNavigatorOperator explorer;
116:
117: public AcceptanceTest(String testName) {
118: super (testName);
119: }
120:
121: public static Test suite() {
122: TestSuite suite = new TestSuite();
123: suite.addTest(new AcceptanceTest("testCreateProject"));
124: suite.addTest(new AcceptanceTest("testAddPage2"));
125: suite.addTest(new AcceptanceTest("testAddBreadcrumbsOnPage1"));
126: suite.addTest(new AcceptanceTest("testAddBreadcrumbsOnPage2"));
127: suite.addTest(new AcceptanceTest("testDeploy"));
128: suite.addTest(new AcceptanceTest("testCloseProject"));
129: suite.addTest(new AcceptanceTest("testUndeploy"));
130: suite.addTest(new AcceptanceTest("testCheckIDELog"));
131: return suite;
132: }
133:
134: /** method called before each testcase
135: */
136: protected void setUp() {
137: System.out.println("######## " + getName() + " #######");
138: }
139:
140: /** method called after each testcase
141: */
142: protected void tearDown() {
143: System.out.println("######## " + getName()
144: + " Finished #######");
145: }
146:
147: /*
148: * Start PE. Delete PointBase travel resource
149: */
150: private void testStartup() {
151: //Start PE is it is not started yet
152: ServerNavigatorOperator se = new ServerNavigatorOperator();
153: // Skip next 2 steps if running on Mac as Jemmy's call popup issue
154: if (!System.getProperty("os.name").equals("Mac OS X")) {
155: //Start PE is it is not started yet
156: try {
157: se.startServer("J2EE");
158: } catch (Exception e) {
159: }
160: // Delete pb travel resource if it exists
161: se.deleteResource("jdbc/Travel");
162: }
163: }
164:
165: /*
166: * Create new project
167: * And add property val to SessionBean1.java
168: */
169: public void testCreateProject() {
170: startTest();
171: log("**Creating Project");
172: //Create Project
173: try {
174: ComponentUtils.createNewProject(_projectName);
175: } catch (Exception e) {
176: log(">> Project Creation Failed");
177: e.printStackTrace();
178: log(e.toString());
179: fail();
180: }
181: log("**Done");
182: endTest();
183: }
184:
185: /*
186: * Create Second Page page2.jsp
187: */
188:
189: public void testAddPage2() {
190: startTest();
191: log("Add second page");
192: prjNav.addWebPage(_projectName, _page2);
193: Util.saveAllAPICall();
194: Util.wait(2000);
195: endTest();
196: }
197:
198: /*
199: * Add label and breadcrumbs on Page1. Verify breadcrumb on outline
200: */
201: public void testAddBreadcrumbsOnPage1() {
202: startTest();
203: log("Open Page1.jsp");
204: prjNav.openWebPage(_projectName, _page1);
205: Util.wait(2000);
206: log("Add a label component");
207: designer = new DesignerPaneOperator(RaveWindowOperator
208: .getDefaultRave());
209: PaletteContainerOperator palette = new PaletteContainerOperator(
210: Bundle.getStringTrimmed(_bundle, "basicPalette"));
211: palette.addComponent(Bundle.getStringTrimmed(_bundle,
212: "basicLabel"), designer, new Point(xLabel, yLabel));
213:
214: log("Set the label's text property");
215: Util.wait(1000);
216: sheet = new SheetTableOperator();
217: ComponentUtils.setProperty(sheet, Bundle.getStringTrimmed(
218: _bundle, "propertyText"), "Page 1");
219: Util.wait(2000);
220:
221: log("Add breadcrumbs");
222: palette = new PaletteContainerOperator(Bundle.getStringTrimmed(
223: _bundle, "compositePalette"));
224: palette.addComponent(Bundle.getStringTrimmed(_bundle,
225: "compositeBreadcrumbs"), designer, new Point(
226: xBreadcrumbs, yBreadcrumbs));
227: Util.wait(2000);
228:
229: log("Verify breadcrumbs in outlin window");
230: DocumentOutlineOperator doo = new DocumentOutlineOperator(Util
231: .getMainWindow());
232: Util.wait(2000);
233:
234: log("**Select breadcrumbs from Outline window");
235: String path = "Page1|page1|html1|body1|form1|breadcrumbs1";
236:
237: doo.verify();
238: // doo.clickOnPath(path);
239: doo.selectPath(path);
240: Util.wait(5000);
241:
242: Util.saveAllAPICall();
243: Util.wait(5000);
244: endTest();
245: }
246:
247: /*
248: * Add static text and breadcrumbs on second page
249: */
250:
251: public void testAddBreadcrumbsOnPage2() {
252: startTest();
253: log("Open Page2.jsp");
254: prjNav.openWebPage(_projectName, _page2);
255: Util.wait(2000);
256: log("Add a label");
257: //designer = new DesignerPaneOperator(RaveWindowOperator.getDefaultRave());
258: designer = new DesignerPaneOperator(Util.getMainWindow(), 1);
259:
260: Util.wait(2000);
261: PaletteContainerOperator palette = new PaletteContainerOperator(
262: Bundle.getStringTrimmed(_bundle, "basicPalette"));
263: Util.wait(2000);
264: palette.addComponent(Bundle.getStringTrimmed(_bundle,
265: "basicLabel"), designer, new Point(xLabel, yLabel));
266:
267: Util.wait(2000);
268: log("Set the statictext's text property");
269: sheet = new SheetTableOperator();
270: ComponentUtils.setProperty(sheet, Bundle.getStringTrimmed(
271: _bundle, "propertyText"), "Page 2");
272: Util.wait(2000);
273:
274: log("Add breadcrumbs");
275: palette = new PaletteContainerOperator(Bundle.getStringTrimmed(
276: _bundle, "compositePalette"));
277: palette.addComponent(Bundle.getStringTrimmed(_bundle,
278: "compositeBreadcrumbs"), designer, new Point(
279: xBreadcrumbs, yBreadcrumbs));
280: Util.wait(2000);
281:
282: log("Verify breadcrumbs in outlin window");
283: DocumentOutlineOperator doo = new DocumentOutlineOperator(Util
284: .getMainWindow());
285: Util.wait(2000);
286:
287: log("**Select breadcrumbs from Outline window");
288: String path = "Page2|page1|html1|body1|form1|breadcrumbs1";
289:
290: doo.verify();
291: // doo.clickOnPath(path);
292: doo.selectPath(path);
293: Util.wait(5000);
294:
295: Util.saveAllAPICall();
296: Util.wait(5000);
297: endTest();
298: }
299:
300: /*
301: * Deploy application
302: */
303: public void testDeploy() {
304: startTest();
305: //need to wait responce
306: Waiter deploymentWaiter = new Waiter(new Waitable() {
307: public Object actionProduced(Object output) {
308: String text = ((OutputOperator) output).getText();
309: if (text.indexOf(_buildSuccess) != -1)
310: return _true;
311: return null;
312:
313: }
314:
315: public String getDescription() {
316: return ("Waiting Project Deployed");
317: }
318: });
319: log("Deploy from menu");
320: ProjectNavigatorOperator.pressPopupItemOnNode(_projectName,
321: _run);
322: TestUtils.wait(2000);
323: OutputOperator outputWindow = new OutputOperator();
324: deploymentWaiter.getTimeouts().setTimeout("Waiter.WaitingTime",
325: 240000);
326: log("wait until " + _buildSuccess);
327: try {
328: deploymentWaiter.waitAction(outputWindow);
329: } catch (InterruptedException e) {
330: log(outputWindow.getText());
331: e.printStackTrace();
332: fail("Deployment error: " + e);
333: }
334: log("Deployment complete");
335: endTest();
336: }
337:
338: public void testCloseProject() {
339: startTest();
340: Util.saveAllAPICall();
341: new ProjectNavigatorOperator().pressPopupItemOnNode(
342: _projectName, Bundle.getStringTrimmed(_bundle,
343: "CloseProjectPopupItem"));
344: //TestUtils.closeCurrentProject();
345: TestUtils.wait(5000);
346: endTest();
347: }
348:
349: /* Need to undeploy project to finish tests correctly */
350: public void testUndeploy() {
351: startTest();
352: log("Initialize");
353: explorer = ServerNavigatorOperator.showNavigatorOperator();
354: String serverPath = _serverPath + _projectServer; //Current deployment server
355: String deploymentPath = serverPath + _deploymentPath; //glassfish specific
356: String applicationPath = deploymentPath + _separator
357: + _projectName; //project name
358:
359: // Select the Server Navigator and set the JTreeOperator
360: log("get explorer");
361: new QueueTool().waitEmpty(100); //??
362: explorer.requestFocus();
363: JTreeOperator tree = explorer.getTree();
364: try {
365: Thread.sleep(4000);
366: } catch (Exception e) {
367: } // Sleep 4 secs to make sure Server Navigator is in focus
368:
369: // Need to refresh J2EE AppServer node
370: log("refresh");
371: explorer.pushPopup(tree, serverPath, _refresh);
372: TestUtils.wait(1000);
373:
374: log("refresh deployment path: " + deploymentPath);
375: TestUtils.wait(1000);
376: explorer.selectPath(deploymentPath);
377: explorer.getTree().expandPath(
378: explorer.getTree().findPath(deploymentPath));
379: explorer.pushPopup(tree, deploymentPath, _refresh);
380: TestUtils.wait(1000);
381:
382: log("undeploy Path: " + applicationPath);
383: explorer.selectPath(applicationPath);
384: TestUtils.wait(1000);
385:
386: log("Push Menu Undeploy...");
387: explorer.pushPopup(explorer.getTree(), applicationPath,
388: _undeploy);
389: TestUtils.wait(5000);
390: endTest();
391: }
392:
393: public void testCheckIDELog() {
394: startTest();
395: try {
396: String err = ComponentUtils.hasUnexpectedException();
397: String str = "";
398: if (!(err.equals(""))) {
399: assertTrue(
400: "Unexpected exceptions found in message.log: "
401: + err, str.equals(""));
402: }
403: } catch (IOException ioe) {
404: ioe.printStackTrace();
405: fail("Failed to open message.log : " + ioe);
406: }
407: endTest();
408: }
409:
410: }
|