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