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