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.pagealert;
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 = "PageAlertTests";
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: //properties
092: public String _propertyType = Bundle.getStringTrimmed(
093: _sharedBundle, "propertyType");
094: public String _typeQuestion = Bundle.getStringTrimmed(
095: _sharedBundle, "typeQuestion");
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("addPageAlert"));
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: endTest();
157: }
158:
159: public void addPageAlert() {
160:
161: startTest();
162: designer = new DesignerPaneOperator(RaveWindowOperator
163: .getDefaultRave());
164: Util.wait(1000);
165: PaletteContainerOperator palette = new PaletteContainerOperator(
166: "Layout");
167: palette.addComponent("Page Alert", designer, new Point(50, 50));
168: try {
169: Thread.sleep(4000);
170: } catch (Exception e) {
171: }
172:
173: sheet = new SheetTableOperator();
174: sheet.setTextValue("id", "pgAlert1");
175: sheet.selectCombo("type", "information");
176: sheet.setTextValue("summary", "Summary goes here");
177: sheet.setTextValue("detail", "Detail info goes here ");
178: sheet
179: .setTextValue("style",
180: "height: 118px; left: 120px; top: 96px; position: absolute; width: 310px");
181: sheet.setTextValue("title", "Sun Microsystems");
182: sheet.setComboBoxValue(_propertyType, _typeQuestion);
183: Util.wait(500);
184: endTest();
185:
186: }
187:
188: /*
189: * Deploy application
190: */
191: public void testDeploy() {
192: startTest();
193: Util.saveAllAPICall();
194: TestUtils.wait(2000);
195: //need to wait responce
196: Waiter deploymentWaiter = new Waiter(new Waitable() {
197: public Object actionProduced(Object output) {
198: String text = ((OutputOperator) output).getText();
199: if (text.indexOf(_buildSuccess) != -1)
200: return _true;
201: return null;
202:
203: }
204:
205: public String getDescription() {
206: return ("Waiting Project Deployed");
207: }
208: });
209: log("Deploy from menu");
210: ProjectNavigatorOperator.pressPopupItemOnNode(_projectName,
211: _run);
212: TestUtils.wait(2000);
213: OutputOperator outputWindow = new OutputOperator();
214: deploymentWaiter.getTimeouts().setTimeout("Waiter.WaitingTime",
215: 240000);
216: log("wait until " + _buildSuccess);
217: try {
218: deploymentWaiter.waitAction(outputWindow);
219: } catch (InterruptedException e) {
220: log(outputWindow.getText());
221: e.printStackTrace();
222: fail("Deployment error: " + e);
223: }
224: log("Deployment complete");
225: endTest();
226: }
227:
228: public void closeProject() {
229: startTest();
230: Util.saveAllAPICall();
231: new ProjectNavigatorOperator().pressPopupItemOnNode(
232: _projectName, "close");
233: TestUtils.wait(5000);
234: endTest();
235: }
236:
237: /* Need to undeploy project to finish tests correctly */
238: public void testUndeploy() {
239: startTest();
240: log("Initialize");
241: explorer = ServerNavigatorOperator.showNavigatorOperator();
242: String serverPath = _serverPath + _projectServer; //Current deployment server
243: String deploymentPath = serverPath + _deploymentPath; //glassfish specific
244: String applicationPath = deploymentPath + _separator
245: + _projectName; //project name
246:
247: // Select the Server Navigator and set the JTreeOperator
248: log("get explorer");
249: new QueueTool().waitEmpty(100); //??
250: explorer.requestFocus();
251: JTreeOperator tree = explorer.getTree();
252: try {
253: Thread.sleep(4000);
254: } catch (Exception e) {
255: } // Sleep 4 secs to make sure Server Navigator is in focus
256:
257: // Need to refresh J2EE AppServer node
258: log("refresh");
259: explorer.pushPopup(tree, serverPath, _refresh);
260: TestUtils.wait(1000);
261:
262: log("refresh deployment path: " + deploymentPath);
263: TestUtils.wait(1000);
264: explorer.selectPath(deploymentPath);
265: explorer.getTree().expandPath(
266: explorer.getTree().findPath(deploymentPath));
267: explorer.pushPopup(tree, deploymentPath, _refresh);
268: TestUtils.wait(1000);
269:
270: log("undeploy Path: " + applicationPath);
271: explorer.selectPath(applicationPath);
272: TestUtils.wait(1000);
273:
274: log("Push Menu Undeploy...");
275: explorer.pushPopup(explorer.getTree(), applicationPath,
276: _undeploy);
277: TestUtils.wait(5000);
278: endTest();
279: }
280:
281: public void testCheckIDELog() {
282: startTest();
283: try {
284: String err = ComponentUtils.hasUnexpectedException();
285: String str = "";
286: if (!(err.equals(""))) {
287: assertTrue(
288: "Unexpected exceptions found in message.log: "
289: + err, str.equals(""));
290: }
291: } catch (IOException ioe) {
292: ioe.printStackTrace();
293: fail("Failed to open message.log : " + ioe);
294: }
295: endTest();
296: }
297:
298: }
|