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