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