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