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