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.stdcomponentlabel;
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.drivers.text.SwingTextKeyboardDriver;
051: import org.netbeans.jemmy.operators.JTextAreaOperator;
052: import org.netbeans.jemmy.QueueTool;
053: import org.netbeans.jemmy.operators.JTreeOperator;
054:
055: import org.netbeans.modules.visualweb.gravy.*;
056: import org.netbeans.modules.visualweb.gravy.designer.DesignerPaneOperator;
057: import org.netbeans.modules.visualweb.gravy.properties.SheetTableOperator;
058: import org.netbeans.modules.visualweb.gravy.toolbox.PaletteContainerOperator;
059: import org.netbeans.modules.visualweb.gravy.dataconnectivity.ServerNavigatorOperator;
060: import org.netbeans.modules.visualweb.test.components.util.ComponentUtils;
061:
062: import java.io.File;
063: import java.awt.Point;
064: import java.io.IOException;
065:
066: /**
067: * @author Lark Fitzgerald (lark.fitzgerald@sun.com)
068: */
069: public class AcceptanceTest extends RaveTestCase {
070:
071: //Project variables
072: public String _sharedBundle = ComponentUtils.getBundle();
073: public String _privateBundle = "org.netbeans.modules.visualweb.test.components.output.stdcomponentlabel.AcceptanceTest";
074: public String _projectName = Bundle.getStringTrimmed(
075: _privateBundle, "projectName");
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: //Palette variables
093: public String _standardPalette = Bundle.getStringTrimmed(
094: _sharedBundle, "standardPalette");
095: public String _standardButton = Bundle.getStringTrimmed(
096: _sharedBundle, "standardButton");
097: public String _standardComponentLabel = Bundle.getStringTrimmed(
098: _sharedBundle, "standardComponentLabel");
099: public String _standardTextField = Bundle.getStringTrimmed(
100: _sharedBundle, "standardTextField");
101:
102: //drop points
103: public int _x = Integer.parseInt(Bundle.getStringTrimmed(
104: _privateBundle, "x"));
105: public int _componentlabel1y = Integer.parseInt(Bundle
106: .getStringTrimmed(_privateBundle, "componentlabel1y"));
107: public int _button1y = Integer.parseInt(Bundle.getStringTrimmed(
108: _privateBundle, "button1y"));
109:
110: //Values
111: public String _componentLabel = Bundle.getStringTrimmed(
112: _privateBundle, "componentlabel");
113:
114: //undeployment
115: public String _undeploy = Bundle.getStringTrimmed(_sharedBundle,
116: "undeploy");
117: public String _refresh = Bundle.getStringTrimmed(_sharedBundle,
118: "refresh");
119: public String _serverPath = Bundle.getStringTrimmed(_sharedBundle,
120: "serverPath");
121: public String _deploymentPath = Bundle.getStringTrimmed(
122: _sharedBundle, "deploymentPathGlassfish");
123: public String _separator = Bundle.getStringTrimmed(_sharedBundle,
124: "separator");
125:
126: Point clickPoint, dropPoint;
127: public static DesignerPaneOperator designer;
128: public static PaletteContainerOperator palette;
129: public static DocumentOutlineOperator outline;
130: public static SheetTableOperator sheet;
131: public static DeploymentDialogOperator deploy;
132: public static ServerNavigatorOperator explorer;
133: public int row;
134:
135: public AcceptanceTest(String testName) {
136: super (testName);
137: }
138:
139: public static Test suite() {
140: TestSuite suite = new NbTestSuite();
141: suite.addTest(new AcceptanceTest("testCreateWebProject"));
142: suite.addTest(new AcceptanceTest("testAddComponentLabel"));
143: suite.addTest(new AcceptanceTest("testAddButton"));
144: suite.addTest(new AcceptanceTest("testDeploy"));
145: suite.addTest(new AcceptanceTest("testCloseWebProject"));
146: suite.addTest(new AcceptanceTest("testUndeploy"));
147: suite.addTest(new AcceptanceTest("testCheckIDELog"));
148: return suite;
149: }
150:
151: /** method called before each testcase
152: */
153: protected void setUp() {
154: System.out.println("######## " + getName() + " #######");
155: }
156:
157: /** method called after each testcase
158: */
159: protected void tearDown() {
160: System.out.println("######## " + getName()
161: + " Finished #######");
162: }
163:
164: /*
165: * Create Web Project
166: *
167: */
168: public void testCreateWebProject() {
169: startTest();
170: log("**Creating Project");
171: //Create Project
172: try {
173: ComponentUtils.createNewProject(_projectName);
174: } catch (Exception e) {
175: log(">> Project Creation Failed");
176: e.printStackTrace();
177: log(e.toString());
178: fail();
179: }
180: log("**Done");
181: endTest();
182: }
183:
184: /*
185: * Add a Component Label to designer
186: */
187: public void testAddComponentLabel() {
188: startTest();
189: log("**Initialize");
190: designer = new DesignerPaneOperator(RaveWindowOperator
191: .getDefaultRave());
192: palette = new PaletteContainerOperator(_standardPalette);
193: try {
194: Thread.sleep(5000);
195: } catch (Exception e) {
196: }
197:
198: log("**Add Standard Component Lable to designer");
199: clickPoint = palette.getClickPoint(_standardComponentLabel);
200: dropPoint = new Point(_x, _componentlabel1y);
201: palette.addComponent(_standardComponentLabel, designer,
202: dropPoint);
203: try {
204: Thread.sleep(2000);
205: } catch (Exception e) {
206: }
207:
208: /*
209: log("**Set label text inline");
210: //JTextFieldOperator field = new JTextFieldOperator(designer);
211: JTextAreaOperator field = new JTextAreaOperator(designer);
212: SwingTextKeyboardDriver keyboard = new SwingTextKeyboardDriver();
213: keyboard.enterText(field, _componentLabel);
214: */
215: log("**Done.");
216: endTest();
217:
218: }
219:
220: /*
221: * Add a button to designer
222: */
223: public void testAddButton() {
224: startTest();
225: log("**Initialize");
226: designer = new DesignerPaneOperator(RaveWindowOperator
227: .getDefaultRave());
228: palette = new PaletteContainerOperator(_standardPalette);
229: try {
230: Thread.sleep(5000);
231: } catch (Exception e) {
232: }
233:
234: log("**Add Button to designer");
235: clickPoint = palette.getClickPoint(_standardButton);
236: dropPoint = new Point(_x, _button1y);
237: palette.dndPaletteComponent(_standardButton, designer,
238: dropPoint);
239: try {
240: Thread.sleep(2000);
241: } catch (Exception e) {
242: }
243:
244: log("**Done.");
245: endTest();
246: }
247:
248: /*
249: * Deploy application
250: */
251: public void testDeploy() {
252: startTest();
253: //need to wait responce
254: Waiter deploymentWaiter = new Waiter(new Waitable() {
255: public Object actionProduced(Object output) {
256: String text = ((OutputOperator) output).getText();
257: if (text.indexOf(_buildSuccess) != -1)
258: return _true;
259: return null;
260:
261: }
262:
263: public String getDescription() {
264: return ("Waiting Project Deployed");
265: }
266: });
267: log("Deploy from menu");
268: ProjectNavigatorOperator.pressPopupItemOnNode(_projectName,
269: _run);
270: TestUtils.wait(2000);
271: OutputOperator outputWindow = new OutputOperator();
272: deploymentWaiter.getTimeouts().setTimeout("Waiter.WaitingTime",
273: 240000);
274: log("wait until " + _buildSuccess);
275: try {
276: deploymentWaiter.waitAction(outputWindow);
277: } catch (InterruptedException e) {
278: log(outputWindow.getText());
279: e.printStackTrace();
280: fail("Deployment error: " + e);
281: }
282: log("Deployment complete");
283: endTest();
284: }
285:
286: /*
287: * Close Project
288: *
289: */
290: public void testCloseWebProject() {
291: startTest();
292: Util.saveAllAPICall();
293: new ProjectNavigatorOperator().pressPopupItemOnNode(
294: _projectName, _close);
295: //TestUtils.closeCurrentProject();
296: TestUtils.wait(5000);
297: endTest();
298: }
299:
300: /* Need to undeploy project to finish tests correctly */
301: public void testUndeploy() {
302: startTest();
303: log("Initialize");
304: explorer = ServerNavigatorOperator.showNavigatorOperator();
305: String serverPath = _serverPath + _projectServer; //Current deployment server
306: String deploymentPath = serverPath + _deploymentPath; //glassfish specific
307: String applicationPath = deploymentPath + _separator
308: + _projectName; //project name
309:
310: // Select the Server Navigator and set the JTreeOperator
311: log("get explorer");
312: new QueueTool().waitEmpty(100); //??
313: explorer.requestFocus();
314: JTreeOperator tree = explorer.getTree();
315: try {
316: Thread.sleep(4000);
317: } catch (Exception e) {
318: } // Sleep 4 secs to make sure Server Navigator is in focus
319:
320: // Need to refresh J2EE AppServer node
321: log("refresh");
322: explorer.pushPopup(tree, serverPath, _refresh);
323: TestUtils.wait(1000);
324:
325: log("refresh deployment path: " + deploymentPath);
326: TestUtils.wait(1000);
327: explorer.selectPath(deploymentPath);
328: explorer.getTree().expandPath(
329: explorer.getTree().findPath(deploymentPath));
330: explorer.pushPopup(tree, deploymentPath, _refresh);
331: TestUtils.wait(1000);
332:
333: log("undeploy Path: " + applicationPath);
334: explorer.selectPath(applicationPath);
335: TestUtils.wait(1000);
336:
337: log("Push Menu Undeploy...");
338: explorer.pushPopup(explorer.getTree(), applicationPath,
339: _undeploy);
340: TestUtils.wait(5000);
341: endTest();
342: }
343:
344: public void testCheckIDELog() {
345: startTest();
346: try {
347: String err = ComponentUtils.hasUnexpectedException();
348: String str = "";
349: if (!(err.equals(""))) {
350: assertTrue(
351: "Unexpected exceptions found in message.log: "
352: + err, str.equals(""));
353: }
354: } catch (IOException ioe) {
355: ioe.printStackTrace();
356: fail("Failed to open message.log : " + ioe);
357: }
358: endTest();
359: }
360: }
|