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