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