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