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