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