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