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.output.message;
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.gravy.dataconnectivity.ServerNavigatorOperator;
058:
059: import org.netbeans.modules.visualweb.test.components.util.ComponentUtils;
060:
061: import java.awt.Point;
062: import java.io.File;
063: import java.io.IOException;
064: import org.netbeans.jemmy.operators.JTextComponentOperator;
065:
066: /**
067: * @author Chary Kanaparthi (Chary.Kanaparthi@sun.com)
068: */
069: public class AcceptanceTest extends RaveTestCase {
070:
071: public static String BUNDLE = "org.netbeans.modules.visualweb.test.components.output.Bundle";
072: public String _projectName = "MessageComponentTests";
073:
074: //Project variables
075: public String _sharedBundle = ComponentUtils.getBundle();
076: public String _projectServer = Bundle.getStringTrimmed(
077: _sharedBundle, "projectServer");
078: public String _logFileLocation = Bundle.getStringTrimmed(
079: _sharedBundle, "logFile");
080: public String _logFile = System.getProperty("xtest.workdir")
081: + File.separator + _logFileLocation;
082: public String _exception = Bundle.getStringTrimmed(_sharedBundle,
083: "Exception");
084: public String _close = Bundle.getStringTrimmed(_sharedBundle,
085: "close");
086: public String _run = Bundle.getStringTrimmed(_sharedBundle, "Run");
087: public String _buildSuccess = Bundle.getStringTrimmed(
088: _sharedBundle, "buildSuccess");
089: public String _true = Bundle
090: .getStringTrimmed(_sharedBundle, "true");
091:
092: //outline
093: public String _outlineForm1 = Bundle.getStringTrimmed(
094: _sharedBundle, "outlineForm1");
095:
096: //undeployment
097: public String _undeploy = Bundle.getStringTrimmed(_sharedBundle,
098: "undeploy");
099: public String _refresh = Bundle.getStringTrimmed(_sharedBundle,
100: "refresh");
101: public String _serverPath = Bundle.getStringTrimmed(_sharedBundle,
102: "serverPath");
103: public String _deploymentPath = Bundle.getStringTrimmed(
104: _sharedBundle, "deploymentPathGlassfish");
105: public String _separator = Bundle.getStringTrimmed(_sharedBundle,
106: "separator");
107:
108: public static DesignerPaneOperator designer;
109: public static SheetTableOperator sheet;
110: public static ServerNavigatorOperator explorer;
111:
112: public AcceptanceTest(String testName) {
113: super (testName);
114: }
115:
116: public static Test suite() {
117: TestSuite suite = new NbTestSuite();
118: suite.addTest(new AcceptanceTest("testCreateProject"));
119: suite.addTest(new AcceptanceTest("testAddMessage"));
120: suite.addTest(new AcceptanceTest("testDeploy"));
121: suite.addTest(new AcceptanceTest("testCloseProject"));
122: suite.addTest(new AcceptanceTest("testUndeploy"));
123: suite.addTest(new AcceptanceTest("testCheckIDELog"));
124:
125: return suite;
126: }
127:
128: /** method called before each testcase
129: */
130: protected void setUp() {
131: System.out.println("Running Test " + getName()
132: + " ..................");
133: }
134:
135: /** method called after each testcase
136: */
137: protected void tearDown() {
138: System.out.println(" Finished Running Test " + getName()
139: + "..................");
140: }
141:
142: public void testCreateProject() {
143: startTest();
144: log("**Creating Project");
145: //Create Project
146: try {
147: ComponentUtils.createNewProject(_projectName);
148: } catch (Exception e) {
149: log(">> Project Creation Failed");
150: e.printStackTrace();
151: log(e.toString());
152: fail();
153: }
154: log("**Done");
155: endTest();
156: }
157:
158: public void testAddMessage() {
159:
160: startTest();
161: log(">> Add textField");
162: designer = new DesignerPaneOperator(RaveWindowOperator
163: .getDefaultRave());
164: PaletteContainerOperator palette = new PaletteContainerOperator(
165: "Basic");
166: palette.addComponent("Text Field", designer, new Point(20, 40));
167: try {
168: Thread.sleep(2000);
169: } catch (Exception e) {
170: }
171:
172: log(">> Set text id");
173: DocumentOutlineOperator doo = new DocumentOutlineOperator(Util
174: .getMainWindow());
175: Util.wait(2000);
176: String path = _outlineForm1 + "textField1";
177: doo.verify();
178: doo.selectPath(path);
179: Util.wait(5000);
180: sheet = new SheetTableOperator();
181: sheet.setTextValue("id", "name");
182: /* int row = sheet.findCellRow("id");
183: sheet.clickForEdit(row, 1);
184: sheet.clickForEdit(row, 1);
185: new JTextComponentOperator(sheet).enterText("name");
186: try { Thread.sleep(2000); } catch(Exception e) {}
187: */
188:
189: log(">> Add message");
190: palette.addComponent("Message", designer, new Point(250, 40));
191: path = _outlineForm1 + "message1";
192: doo.verify();
193: doo.selectPath(path);
194:
195: log(">> set message for property");
196: sheet = new SheetTableOperator();
197: sheet.setTextValue("id", "msg1");
198: sheet.setComboBoxValue("for", "name");
199: Util.wait(2000);
200: endTest();
201:
202: }
203:
204: /*
205: * Deploy application
206: */
207: public void testDeploy() {
208: startTest();
209: //need to wait responce
210: Waiter deploymentWaiter = new Waiter(new Waitable() {
211: public Object actionProduced(Object output) {
212: String text = ((OutputOperator) output).getText();
213: if (text.indexOf(_buildSuccess) != -1)
214: return _true;
215: return null;
216:
217: }
218:
219: public String getDescription() {
220: return ("Waiting Project Deployed");
221: }
222: });
223: log("Deploy from menu");
224: ProjectNavigatorOperator.pressPopupItemOnNode(_projectName,
225: _run);
226: TestUtils.wait(2000);
227: OutputOperator outputWindow = new OutputOperator();
228: deploymentWaiter.getTimeouts().setTimeout("Waiter.WaitingTime",
229: 240000);
230: log("wait until " + _buildSuccess);
231: try {
232: deploymentWaiter.waitAction(outputWindow);
233: } catch (InterruptedException e) {
234: log(outputWindow.getText());
235: e.printStackTrace();
236: fail("Deployment error: " + e);
237: }
238: log("Deployment complete");
239: endTest();
240: }
241:
242: public void testCloseProject() {
243: startTest();
244: Util.saveAllAPICall();
245: new ProjectNavigatorOperator().pressPopupItemOnNode(
246: _projectName, "close");
247: TestUtils.wait(5000);
248: endTest();
249: }
250:
251: /* Need to undeploy project to finish tests correctly */
252: public void testUndeploy() {
253: startTest();
254: log("Initialize");
255: explorer = ServerNavigatorOperator.showNavigatorOperator();
256: String serverPath = _serverPath + _projectServer; //Current deployment server
257: String deploymentPath = serverPath + _deploymentPath; //glassfish specific
258: String applicationPath = deploymentPath + _separator
259: + _projectName; //project name
260:
261: // Select the Server Navigator and set the JTreeOperator
262: log("get explorer");
263: new QueueTool().waitEmpty(100); //??
264: explorer.requestFocus();
265: JTreeOperator tree = explorer.getTree();
266: try {
267: Thread.sleep(4000);
268: } catch (Exception e) {
269: } // Sleep 4 secs to make sure Server Navigator is in focus
270:
271: // Need to refresh J2EE AppServer node
272: log("refresh");
273: explorer.pushPopup(tree, serverPath, _refresh);
274: TestUtils.wait(1000);
275:
276: log("refresh deployment path: " + deploymentPath);
277: TestUtils.wait(1000);
278: explorer.selectPath(deploymentPath);
279: explorer.getTree().expandPath(
280: explorer.getTree().findPath(deploymentPath));
281: explorer.pushPopup(tree, deploymentPath, _refresh);
282: TestUtils.wait(1000);
283:
284: log("undeploy Path: " + applicationPath);
285: explorer.selectPath(applicationPath);
286: TestUtils.wait(1000);
287:
288: log("Push Menu Undeploy...");
289: explorer.pushPopup(explorer.getTree(), applicationPath,
290: _undeploy);
291: TestUtils.wait(5000);
292: endTest();
293: }
294:
295: public void testCheckIDELog() {
296: startTest();
297: try {
298: String err = ComponentUtils.hasUnexpectedException();
299: String str = "";
300: if (!(err.equals(""))) {
301: assertTrue(
302: "Unexpected exceptions found in message.log: "
303: + err, str.equals(""));
304: }
305: } catch (IOException ioe) {
306: ioe.printStackTrace();
307: fail("Failed to open message.log : " + ioe);
308: }
309: endTest();
310: }
311: }
|