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.advanced.facesactionlistener;
043:
044: import junit.framework.Test;
045: import junit.framework.TestSuite;
046: import org.netbeans.junit.NbTestSuite;
047: import org.netbeans.jellytools.OutputOperator;
048: import org.netbeans.jemmy.Waiter;
049: import org.netbeans.jemmy.Waitable;
050: import org.netbeans.jemmy.QueueTool;
051: import org.netbeans.jemmy.operators.JTreeOperator;
052:
053: import org.netbeans.modules.visualweb.gravy.*;
054: import org.netbeans.modules.visualweb.gravy.designer.DesignerPaneOperator;
055: import org.netbeans.modules.visualweb.gravy.properties.SheetTableOperator;
056: import org.netbeans.modules.visualweb.gravy.toolbox.PaletteContainerOperator;
057: import org.netbeans.modules.visualweb.test.components.util.ComponentUtils;
058: import org.netbeans.modules.visualweb.gravy.dataconnectivity.ServerExplorerOperator;
059: import org.netbeans.modules.visualweb.gravy.dataconnectivity.ServerNavigatorOperator;
060:
061: import java.io.File;
062: import java.awt.Point;
063: import java.io.IOException;
064:
065: /**
066: * @author Lark Fitzgerald (lark.fitzgerald@sun.com)
067: */
068: public class AcceptanceTest extends RaveTestCase {
069:
070: //Project variables
071: public String _sharedBundle = "org.netbeans.modules.visualweb.test.components.Component";
072: public String _privateBundle = "org.netbeans.modules.visualweb.test.components.advanced.facesactionlistener.Acceptance";
073: public String _projectName = Bundle.getStringTrimmed(
074: _privateBundle, "projectName");
075: public String _projectServer = Bundle.getStringTrimmed(
076: _sharedBundle, "projectServer");
077: public String _logFileLocation = Bundle.getStringTrimmed(
078: _sharedBundle, "logFile");
079: public String _logFile = System.getProperty("xtest.workdir")
080: + File.separator + _logFileLocation;
081: public String _exception = Bundle.getStringTrimmed(_sharedBundle,
082: "Exception");
083: public String _close = Bundle.getStringTrimmed(_sharedBundle,
084: "close");
085: public String _run = Bundle.getStringTrimmed(_sharedBundle, "Run");
086:
087: //Outline variables
088: public String _outlineForm1 = Bundle.getStringTrimmed(
089: _sharedBundle, "outlineForm1");
090:
091: //Palette variables
092: public String _basicPalette = Bundle.getStringTrimmed(
093: _sharedBundle, "basicPalette");
094: public String _basicButton = Bundle.getStringTrimmed(_sharedBundle,
095: "basicButton");
096: public String _advancedPalette = Bundle.getStringTrimmed(
097: _sharedBundle, "advancedPalette");
098: public String _advancedFacesActionListener = Bundle
099: .getStringTrimmed(_sharedBundle,
100: "advancedFacesActionListener");
101:
102: //drop points
103: public int _x = Integer.parseInt(Bundle.getStringTrimmed(
104: _privateBundle, "x"));
105: public int _facesactionlistener1y = Integer.parseInt(Bundle
106: .getStringTrimmed(_privateBundle, "facesactionlistener1y"));
107: public int _button1y = Integer.parseInt(Bundle.getStringTrimmed(
108: _privateBundle, "button1y"));
109:
110: public String _facesactionlistener = Bundle.getStringTrimmed(
111: _privateBundle, "facesactionlistener");
112:
113: //undeployment
114: public String _undeploy = Bundle.getStringTrimmed(_sharedBundle,
115: "undeploy");
116: public String _refresh = Bundle.getStringTrimmed(_sharedBundle,
117: "refresh");
118: public String _serverPath = Bundle.getStringTrimmed(_sharedBundle,
119: "serverPath");
120: public String _deploymentPath = Bundle.getStringTrimmed(
121: _sharedBundle, "deploymentPathGlassfish");
122: public String _separator = Bundle.getStringTrimmed(_sharedBundle,
123: "separator");
124:
125: Point clickPoint, dropPoint;
126: public static DesignerPaneOperator designer;
127: public static PaletteContainerOperator palette;
128: public static DocumentOutlineOperator outline;
129: public static SheetTableOperator sheet;
130: public static DeploymentDialogOperator deploy;
131: public static ServerNavigatorOperator explorer;
132: public int row;
133:
134: public AcceptanceTest(String testName) {
135: super (testName);
136: }
137:
138: public static Test suite() {
139: TestSuite suite = new NbTestSuite();
140: suite.addTest(new AcceptanceTest("testCreateWebProject"));
141:
142: suite.addTest(new AcceptanceTest(
143: "testAddAdvancedFacesActionListener"));
144: suite.addTest(new AcceptanceTest(
145: "testVerifyFacesActionListener"));
146: // suite.addTest(new AcceptanceTest("testAddTextField"));
147: // suite.addTest(new AcceptanceTest("testAddButton"));
148:
149: suite.addTest(new AcceptanceTest("testDeploy"));
150: suite.addTest(new AcceptanceTest("testCloseWebProject"));
151: suite.addTest(new AcceptanceTest("testUndeploy"));
152: suite.addTest(new AcceptanceTest("testCheckIDELog"));
153:
154: return suite;
155: }
156:
157: /** method called before each testcase
158: */
159: protected void setUp() {
160: log("setup()");
161: System.out.println("######## " + getName() + " #######");
162: }
163:
164: /** method called after each testcase
165: */
166: protected void tearDown() {
167: log("teardown()");
168: System.out.println("######## " + getName()
169: + " Finished #######");
170: }
171:
172: /*
173: * Create Web Project
174: *
175: */
176: public void testCreateWebProject() {
177: startTest();
178: log("**Creating Project");
179: //Create Project
180: try {
181: ComponentUtils.createNewProject(_projectName);
182: } catch (Exception e) {
183: log(">> Project Creation Failed");
184: e.printStackTrace();
185: log(e.toString());
186: fail();
187: }
188: log("**Done");
189: endTest();
190: }
191:
192: /*
193: * Add a faces action listener to designer
194: */
195: public void testAddAdvancedFacesActionListener() {
196: startTest();
197: log("**Initialize");
198: designer = new DesignerPaneOperator(RaveWindowOperator
199: .getDefaultRave());
200: palette = new PaletteContainerOperator(_advancedPalette);
201: try {
202: Thread.sleep(5000);
203: } catch (Exception e) {
204: }
205:
206: log("**Add faces action listner to designer");
207: clickPoint = palette
208: .getClickPoint(_advancedFacesActionListener);
209: dropPoint = new Point(_x, _facesactionlistener1y);
210: palette.addComponent(_advancedFacesActionListener, designer,
211: dropPoint);
212: try {
213: Thread.sleep(2000);
214: } catch (Exception e) {
215: }
216:
217: log("**Done.");
218: endTest();
219:
220: }
221:
222: /*
223: * Verify faces action listner in outline window
224: */
225: public void testVerifyFacesActionListener() {
226: startTest();
227: log("**Initialize");
228: DocumentOutlineOperator doo = new DocumentOutlineOperator(Util
229: .getMainWindow());
230: Util.wait(2000);
231:
232: log("**Select " + _facesactionlistener + " from Outline window");
233: String path = _outlineForm1 + _facesactionlistener;
234: doo.verify();
235: // doo.clickOnPath(path);
236: doo.selectPath(path);
237: Util.wait(5000);
238:
239: log("**Done.");
240: endTest();
241: }
242:
243: /*
244: * Change var name
245: */
246:
247: /*
248: * Add a button to designer
249: */
250: public void testAddButton() {
251: startTest();
252: log("**Initialize");
253: designer = new DesignerPaneOperator(RaveWindowOperator
254: .getDefaultRave());
255: palette = new PaletteContainerOperator(_basicPalette);
256: try {
257: Thread.sleep(5000);
258: } catch (Exception e) {
259: }
260:
261: log("**Add Button to designer");
262: clickPoint = palette.getClickPoint(_basicButton);
263: dropPoint = new Point(_x, _button1y);
264: palette.dndPaletteComponent(_basicButton, designer, dropPoint);
265: try {
266: Thread.sleep(2000);
267: } catch (Exception e) {
268: }
269:
270: log("**Done.");
271: endTest();
272: }
273:
274: /*
275: * Set button to get text value from bundle
276: */
277:
278: /*
279: * Deploy application
280: */
281: public void testDeploy() {
282: startTest();
283: //need to wait responce
284: Waiter deploymentWaiter = new Waiter(new Waitable() {
285: public Object actionProduced(Object output) {
286: String text = ((OutputOperator) output).getText();
287: if (text.indexOf("BUILD SUCCESSFUL") != -1)
288: return "true";
289: return null;
290:
291: }
292:
293: public String getDescription() {
294: return ("Waiting Project Deployed");
295: }
296: });
297: log("Deploy from menu");
298: ProjectNavigatorOperator.pressPopupItemOnNode(_projectName,
299: _run);
300: TestUtils.wait(2000);
301: OutputOperator outputWindow = new OutputOperator();
302: deploymentWaiter.getTimeouts().setTimeout("Waiter.WaitingTime",
303: 240000);
304: log("wait until BUILD SUCCESSFUL");
305: try {
306: deploymentWaiter.waitAction(outputWindow);
307: } catch (InterruptedException e) {
308: log(outputWindow.getText());
309: e.printStackTrace();
310: fail("Deployment error: " + e);
311: }
312: log("Deployment complete");
313: endTest();
314: }
315:
316: /*
317: * Close Project
318: *
319: */
320: public void testCloseWebProject() {
321: startTest();
322: Util.saveAllAPICall();
323: new ProjectNavigatorOperator().pressPopupItemOnNode(
324: _projectName, _close);
325: //TestUtils.closeCurrentProject();
326: TestUtils.wait(5000);
327: endTest();
328: }
329:
330: /* Need to undeploy project to finish tests correctly */
331: public void testUndeploy() {
332: startTest();
333: log("Initialize");
334: explorer = ServerNavigatorOperator.showNavigatorOperator();
335: String serverPath = _serverPath + _projectServer; //Current deployment server
336: String deploymentPath = serverPath + _deploymentPath; //glassfish specific
337: String applicationPath = deploymentPath + _separator
338: + _projectName; //project name
339:
340: // Select the Server Navigator and set the JTreeOperator
341: log("get explorer");
342: new QueueTool().waitEmpty(100); //??
343: explorer.requestFocus();
344: JTreeOperator tree = explorer.getTree();
345: try {
346: Thread.sleep(4000);
347: } catch (Exception e) {
348: } // Sleep 4 secs to make sure Server Navigator is in focus
349:
350: // Need to refresh J2EE AppServer node
351: log("refresh");
352: explorer.pushPopup(tree, serverPath, _refresh);
353: TestUtils.wait(1000);
354:
355: log("refresh deployment path: " + deploymentPath);
356: TestUtils.wait(1000);
357: explorer.selectPath(deploymentPath);
358: explorer.getTree().expandPath(
359: explorer.getTree().findPath(deploymentPath));
360: explorer.pushPopup(tree, deploymentPath, _refresh);
361: TestUtils.wait(1000);
362:
363: log("undeploy Path: " + applicationPath);
364: explorer.selectPath(applicationPath);
365: TestUtils.wait(1000);
366:
367: log("Push Menu Undeploy...");
368: explorer.pushPopup(explorer.getTree(), applicationPath,
369: _undeploy);
370: TestUtils.wait(5000);
371: endTest();
372: }
373:
374: public void testCheckIDELog() {
375: startTest();
376: try {
377: String err = ComponentUtils.hasUnexpectedException();
378: String str = "";
379: if (!(err.equals(""))) {
380: assertTrue(
381: "Unexpected exceptions found in message.log: "
382: + err, str.equals(""));
383: }
384: } catch (IOException ioe) {
385: ioe.printStackTrace();
386: fail("Failed to open message.log : " + ioe);
387: }
388: endTest();
389: }
390: }
|