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.label;
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 _sharedBundle = ComponentUtils.getBundle();
072:
073: public String _projectName = "LabelComponentTests";
074:
075: //Project variables
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("testCreateProject"));
115: suite.addTest(new AcceptanceTest("testAddLabel"));
116: suite.addTest(new AcceptanceTest("testDeploy"));
117: suite.addTest(new AcceptanceTest("testCloseProject"));
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 testCreateProject() {
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 testAddLabel() {
155:
156: startTest();
157: designer = new DesignerPaneOperator(RaveWindowOperator
158: .getDefaultRave());
159: Util.wait(1000);
160: PaletteContainerOperator palette = new PaletteContainerOperator(
161: Bundle.getStringTrimmed(BUNDLE, "PaletteGroup"));
162: palette.addComponent("Label", designer, new Point(50, 50));
163: sheet = new SheetTableOperator();
164: sheet.setTextValue("id", "company");
165: sheet.setTextValue("text", "Sun Microsystems");
166: sheet.setTextValue("toolTip", "My Work Place");
167: Util.wait(2000);
168: endTest();
169:
170: }
171:
172: /*
173: * Deploy application
174: */
175: public void testDeploy() {
176: startTest();
177: //need to wait responce
178: Waiter deploymentWaiter = new Waiter(new Waitable() {
179: public Object actionProduced(Object output) {
180: String text = ((OutputOperator) output).getText();
181: if (text.indexOf(_buildSuccess) != -1)
182: return _true;
183: return null;
184:
185: }
186:
187: public String getDescription() {
188: return ("Waiting Project Deployed");
189: }
190: });
191: log("Deploy from menu");
192: ProjectNavigatorOperator.pressPopupItemOnNode(_projectName,
193: _run);
194: TestUtils.wait(2000);
195: OutputOperator outputWindow = new OutputOperator();
196: deploymentWaiter.getTimeouts().setTimeout("Waiter.WaitingTime",
197: 240000);
198: log("wait until " + _buildSuccess);
199: try {
200: deploymentWaiter.waitAction(outputWindow);
201: } catch (InterruptedException e) {
202: log(outputWindow.getText());
203: e.printStackTrace();
204: fail("Deployment error: " + e);
205: }
206: log("Deployment complete");
207: endTest();
208: }
209:
210: public void testCloseProject() {
211: startTest();
212: Util.saveAllAPICall();
213: new ProjectNavigatorOperator().pressPopupItemOnNode(
214: _projectName, "close");
215: TestUtils.wait(5000);
216: endTest();
217: }
218:
219: /* Need to undeploy project to finish tests correctly */
220: public void testUndeploy() {
221: startTest();
222: log("Initialize");
223: explorer = ServerNavigatorOperator.showNavigatorOperator();
224: String serverPath = _serverPath + _projectServer; //Current deployment server
225: String deploymentPath = serverPath + _deploymentPath; //glassfish specific
226: String applicationPath = deploymentPath + _separator
227: + _projectName; //project name
228:
229: // Select the Server Navigator and set the JTreeOperator
230: log("get explorer");
231: new QueueTool().waitEmpty(100); //??
232: explorer.requestFocus();
233: JTreeOperator tree = explorer.getTree();
234: try {
235: Thread.sleep(4000);
236: } catch (Exception e) {
237: } // Sleep 4 secs to make sure Server Navigator is in focus
238:
239: // Need to refresh J2EE AppServer node
240: log("refresh");
241: explorer.pushPopup(tree, serverPath, _refresh);
242: TestUtils.wait(1000);
243:
244: log("refresh deployment path: " + deploymentPath);
245: TestUtils.wait(1000);
246: explorer.selectPath(deploymentPath);
247: explorer.getTree().expandPath(
248: explorer.getTree().findPath(deploymentPath));
249: explorer.pushPopup(tree, deploymentPath, _refresh);
250: TestUtils.wait(1000);
251:
252: log("undeploy Path: " + applicationPath);
253: explorer.selectPath(applicationPath);
254: TestUtils.wait(1000);
255:
256: log("Push Menu Undeploy...");
257: explorer.pushPopup(explorer.getTree(), applicationPath,
258: _undeploy);
259: TestUtils.wait(5000);
260: endTest();
261: }
262:
263: public void testCheckIDELog() {
264: startTest();
265: try {
266: String err = ComponentUtils.hasUnexpectedException();
267: String str = "";
268: if (!(err.equals(""))) {
269: assertTrue(
270: "Unexpected exceptions found in message.log: "
271: + err, str.equals(""));
272: }
273: } catch (IOException ioe) {
274: ioe.printStackTrace();
275: fail("Failed to open message.log : " + ioe);
276: }
277: endTest();
278: }
279: }
|