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.statictext;
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:
065: /**
066: * @author Chary Kanaparthi (Chary.Kanaparthi@sun.com)
067: */
068: public class AcceptanceTest extends RaveTestCase {
069:
070: public static String BUNDLE = "org.netbeans.modules.visualweb.test.components.output.Bundle";
071: public String _projectName = "StaticTextComponentTests";
072:
073: //Project variables
074: public String _sharedBundle = ComponentUtils.getBundle();
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: public String _buildSuccess = Bundle.getStringTrimmed(
087: _sharedBundle, "buildSuccess");
088: public String _true = Bundle
089: .getStringTrimmed(_sharedBundle, "true");
090:
091: //undeployment
092: public String _undeploy = Bundle.getStringTrimmed(_sharedBundle,
093: "undeploy");
094: public String _refresh = Bundle.getStringTrimmed(_sharedBundle,
095: "refresh");
096: public String _serverPath = Bundle.getStringTrimmed(_sharedBundle,
097: "serverPath");
098: public String _deploymentPath = Bundle.getStringTrimmed(
099: _sharedBundle, "deploymentPathGlassfish");
100: public String _separator = Bundle.getStringTrimmed(_sharedBundle,
101: "separator");
102:
103: public static DesignerPaneOperator designer;
104: public static SheetTableOperator sheet;
105: public static ServerNavigatorOperator explorer;
106:
107: public AcceptanceTest(String testName) {
108: super (testName);
109: }
110:
111: public static Test suite() {
112: TestSuite suite = new NbTestSuite();
113: suite.addTest(new AcceptanceTest("createProject"));
114: suite.addTest(new AcceptanceTest("addStaticText"));
115: suite.addTest(new AcceptanceTest("testDeploy"));
116: suite.addTest(new AcceptanceTest("closeProject"));
117: suite.addTest(new AcceptanceTest("testUndeploy"));
118: suite.addTest(new AcceptanceTest("testCheckIDELog"));
119:
120: return suite;
121: }
122:
123: /** method called before each testcase
124: */
125: protected void setUp() {
126: System.out.println("Running Test " + getName()
127: + " ..................");
128: }
129:
130: /** method called after each testcase
131: */
132: protected void tearDown() {
133: System.out.println(" Finished Running Test " + getName()
134: + "..................");
135: }
136:
137: public void createProject() {
138: startTest();
139: log("**Creating Project");
140: //Create Project
141: try {
142: ComponentUtils.createNewProject(_projectName);
143: } catch (Exception e) {
144: log(">> Project Creation Failed");
145: e.printStackTrace();
146: log(e.toString());
147: fail();
148: }
149: log("**Done");
150: endTest();
151: }
152:
153: public void addStaticText() {
154:
155: startTest();
156: designer = new DesignerPaneOperator(RaveWindowOperator
157: .getDefaultRave());
158: Util.wait(1000);
159: PaletteContainerOperator palette = new PaletteContainerOperator(
160: "Basic");
161: palette
162: .addComponent("Static Text", designer,
163: new Point(50, 50));
164: sheet = new SheetTableOperator();
165: sheet.setTextValue("id", "company");
166: sheet.setTextValue("text", "Sun Microsystems");
167: sheet.setTextValue("toolTip", "My Work Place");
168: Util.wait(2000);
169: endTest();
170:
171: }
172:
173: /*
174: * Deploy application
175: */
176: public void testDeploy() {
177: startTest();
178: //need to wait responce
179: Waiter deploymentWaiter = new Waiter(new Waitable() {
180: public Object actionProduced(Object output) {
181: String text = ((OutputOperator) output).getText();
182: if (text.indexOf(_buildSuccess) != -1)
183: return _true;
184: return null;
185:
186: }
187:
188: public String getDescription() {
189: return ("Waiting Project Deployed");
190: }
191: });
192: log("Deploy from menu");
193: ProjectNavigatorOperator.pressPopupItemOnNode(_projectName,
194: _run);
195: TestUtils.wait(2000);
196: OutputOperator outputWindow = new OutputOperator();
197: deploymentWaiter.getTimeouts().setTimeout("Waiter.WaitingTime",
198: 240000);
199: log("wait until " + _buildSuccess);
200: try {
201: deploymentWaiter.waitAction(outputWindow);
202: } catch (InterruptedException e) {
203: log(outputWindow.getText());
204: e.printStackTrace();
205: fail("Deployment error: " + e);
206: }
207: log("Deployment complete");
208: endTest();
209: }
210:
211: public void closeProject() {
212: startTest();
213: Util.saveAllAPICall();
214: new ProjectNavigatorOperator().pressPopupItemOnNode(
215: _projectName, "close");
216: TestUtils.wait(5000);
217: endTest();
218: }
219:
220: /* Need to undeploy project to finish tests correctly */
221: public void testUndeploy() {
222: startTest();
223: log("Initialize");
224: explorer = ServerNavigatorOperator.showNavigatorOperator();
225: String serverPath = _serverPath + _projectServer; //Current deployment server
226: String deploymentPath = serverPath + _deploymentPath; //glassfish specific
227: String applicationPath = deploymentPath + _separator
228: + _projectName; //project name
229:
230: // Select the Server Navigator and set the JTreeOperator
231: log("get explorer");
232: new QueueTool().waitEmpty(100); //??
233: explorer.requestFocus();
234: JTreeOperator tree = explorer.getTree();
235: try {
236: Thread.sleep(4000);
237: } catch (Exception e) {
238: } // Sleep 4 secs to make sure Server Navigator is in focus
239:
240: // Need to refresh J2EE AppServer node
241: log("refresh");
242: explorer.pushPopup(tree, serverPath, _refresh);
243: TestUtils.wait(1000);
244:
245: log("refresh deployment path: " + deploymentPath);
246: TestUtils.wait(1000);
247: explorer.selectPath(deploymentPath);
248: explorer.getTree().expandPath(
249: explorer.getTree().findPath(deploymentPath));
250: explorer.pushPopup(tree, deploymentPath, _refresh);
251: TestUtils.wait(1000);
252:
253: log("undeploy Path: " + applicationPath);
254: explorer.selectPath(applicationPath);
255: TestUtils.wait(1000);
256:
257: log("Push Menu Undeploy...");
258: explorer.pushPopup(explorer.getTree(), applicationPath,
259: _undeploy);
260: TestUtils.wait(5000);
261: endTest();
262: }
263:
264: public void testCheckIDELog() {
265: startTest();
266: try {
267: String err = ComponentUtils.hasUnexpectedException();
268: String str = "";
269: if (!(err.equals(""))) {
270: assertTrue(
271: "Unexpected exceptions found in message.log: "
272: + err, str.equals(""));
273: }
274: } catch (IOException ioe) {
275: ioe.printStackTrace();
276: fail("Failed to open message.log : " + ioe);
277: }
278: endTest();
279: }
280: }
|