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.action.image;
043:
044: import junit.framework.Test;
045: import junit.framework.TestSuite;
046:
047: import java.io.File;
048: import java.awt.*;
049: import java.io.IOException;
050:
051: import org.netbeans.modules.visualweb.gravy.*;
052: import org.netbeans.modules.visualweb.gravy.ProjectNavigatorOperator;
053: import org.netbeans.modules.visualweb.gravy.dataconnectivity.ServerNavigatorOperator;
054: import org.netbeans.modules.visualweb.gravy.toolbox.PaletteContainerOperator;
055: import org.netbeans.modules.visualweb.gravy.designer.DesignerPaneOperator;
056: import org.netbeans.modules.visualweb.gravy.properties.SheetTableOperator;
057: import org.netbeans.modules.visualweb.gravy.dataconnectivity.ServerNavigatorOperator;
058: import org.netbeans.modules.visualweb.test.components.util.ComponentUtils;
059: import org.netbeans.jellytools.OutputOperator;
060: import org.netbeans.jemmy.Waitable;
061: import org.netbeans.jemmy.Waiter;
062: import org.netbeans.jemmy.QueueTool;
063: import org.netbeans.jemmy.operators.JTreeOperator;
064:
065: /**
066: * @author Sherry Zhou (sherry.zhou@sun.com)
067: */
068: public class AcceptanceTest extends RaveTestCase {
069:
070: public String _bundle = "org.netbeans.modules.visualweb.test.components.Component";
071: public String _projectServer = Bundle.getStringTrimmed(_bundle,
072: "projectServer");
073: public String _logFileLocation = Bundle.getStringTrimmed(_bundle,
074: "logFile");
075: public String _logFile = System.getProperty("xtest.workdir")
076: + File.separator + _logFileLocation;
077: public String _exception = Bundle.getStringTrimmed(_bundle,
078: "Exception");
079: public String _close = Bundle.getStringTrimmed(_bundle, "close");
080:
081: public String _projectName = "ImageAcceptanceTest";
082:
083: public String _run = Bundle.getStringTrimmed(_bundle, "Run");
084: public String _buildSuccess = Bundle.getStringTrimmed(_bundle,
085: "buildSuccess");
086: public String _true = Bundle.getStringTrimmed(_bundle, "true");
087:
088: public String imageDir = ComponentUtils.getDataDir() + "action"
089: + File.separator;
090: public String image1 = imageDir + "orchid1.JPG";
091: public String image2 = imageDir + "orchid2.JPG";
092: public static int xImage = 50;
093: public static int yImage1 = 50;
094: public static int yImage2 = 200;
095: public static int yImage3 = 400;
096:
097: //undeployment
098: public String _undeploy = Bundle.getStringTrimmed(_bundle,
099: "undeploy");
100: public String _refresh = Bundle
101: .getStringTrimmed(_bundle, "refresh");
102: public String _serverPath = Bundle.getStringTrimmed(_bundle,
103: "serverPath");
104: public String _deploymentPath = Bundle.getStringTrimmed(_bundle,
105: "deploymentPathGlassfish");
106: public String _separator = Bundle.getStringTrimmed(_bundle,
107: "separator");
108:
109: public static DesignerPaneOperator designer;
110: public static SheetTableOperator sheet;
111: public static ServerNavigatorOperator explorer;
112:
113: public AcceptanceTest(String testName) {
114: super (testName);
115: }
116:
117: public static Test suite() {
118: TestSuite suite = new TestSuite();
119: suite.addTest(new AcceptanceTest("testCreateProject"));
120: suite.addTest(new AcceptanceTest("testAddImage1"));
121: // Always have trouble to drop second iamge. Comment it for now
122: // suite.addTest(new AcceptanceTest("testAddImage2"));
123: suite.addTest(new AcceptanceTest("testDeploy"));
124: suite.addTest(new AcceptanceTest("testCloseProject"));
125: suite.addTest(new AcceptanceTest("testUndeploy"));
126: suite.addTest(new AcceptanceTest("testCheckIDELog"));
127: return suite;
128: }
129:
130: /** method called before each testcase
131: */
132: protected void setUp() {
133: System.out.println("######## " + getName() + " #######");
134: }
135:
136: /** method called after each testcase
137: */
138: protected void tearDown() {
139: System.out.println("######## " + getName()
140: + " Finished #######");
141: }
142:
143: /*
144: * Start PE. Delete PointBase travel resource
145: */
146: private void testStartup() {
147: //Start PE is it is not started yet
148: ServerNavigatorOperator se = new ServerNavigatorOperator();
149: // Skip next 2 steps if running on Mac as Jemmy's call popup issue
150: if (!System.getProperty("os.name").equals("Mac OS X")) {
151: //Start PE is it is not started yet
152: try {
153: se.startServer("J2EE");
154: } catch (Exception e) {
155: }
156: // Delete pb travel resource if it exists
157: se.deleteResource("jdbc/Travel");
158: }
159: }
160:
161: /*
162: * Create new project
163: * And add property val to SessionBean1.java
164: */
165: public void testCreateProject() {
166: startTest();
167: log("**Creating Project");
168: //Create Project
169: try {
170: ComponentUtils.createNewProject(_projectName);
171: } catch (Exception e) {
172: log(">> Project Creation Failed");
173: e.printStackTrace();
174: log(e.toString());
175: fail();
176: }
177: log("**Done");
178: endTest();
179: }
180:
181: /*
182: * Add 1st image component.
183: * Set its image from designer
184: * Set its tooltip, width, heigth properties
185: */
186:
187: public void testAddImage1() {
188: startTest();
189: designer = new DesignerPaneOperator(RaveWindowOperator
190: .getDefaultRave());
191: PaletteContainerOperator palette = new PaletteContainerOperator(
192: Bundle.getStringTrimmed(_bundle, "basicPalette"));
193: Util.wait(5000);
194:
195: log("**Add Image to designer");
196: String name = Bundle.getStringTrimmed(_bundle, "basicImage");
197: Point dropPoint = new Point(xImage, yImage1);
198: int index = 1; //Image = 1, Image Hyperlink = 0
199: palette.addComponent(name, index, designer, dropPoint);
200: Util.wait(2000);
201:
202: log("Set property values");
203: sheet = new SheetTableOperator();
204: ComponentUtils.setProperty(sheet, Bundle.getStringTrimmed(
205: _bundle, "propertyToolTip"), "Orchid");
206: ComponentUtils.setProperty(sheet, Bundle.getStringTrimmed(
207: _bundle, "propertyWidth"), "50");
208: ComponentUtils.setProperty(sheet, Bundle.getStringTrimmed(
209: _bundle, "propertyHeight"), "50");
210: ComponentUtils.setProperty(sheet, Bundle.getStringTrimmed(
211: _bundle, "propertyBorder"), "2");
212: log("id= " + sheet.getSelectedComponentID());
213: //designer.setImage(sheet.getSelectedComponentID(), image1);
214: designer.setImage(xImage, yImage1, image1);
215: Util.wait(1000);
216:
217: Util.saveAllAPICall();
218: Util.wait(2000);
219: endTest();
220: }
221:
222: /*
223: * Add 2nd image component.
224: * Set image via url property
225: */
226: public void testAddImage2() {
227: startTest();
228: designer = new DesignerPaneOperator(RaveWindowOperator
229: .getDefaultRave());
230: PaletteContainerOperator palette = new PaletteContainerOperator(
231: Bundle.getStringTrimmed(_bundle, "basicPalette"));
232: Util.wait(5000);
233:
234: log("**Add Image to designer");
235: String name = Bundle.getStringTrimmed(_bundle, "basicImage");
236: Point dropPoint = new Point(xImage, yImage2);
237: int index = 1; //Image = 1, Image Hyperlink = 0
238: palette.addComponent(name, index, designer, dropPoint);
239: Util.wait(2000);
240:
241: // String image2ID="image2";
242: // designer.clickMouse(image2ID, 1);
243: // Util.wait(500);
244: log("Set properties");
245: sheet = new SheetTableOperator();
246: Util.wait(1500);
247: ComponentUtils.setProperty(sheet, Bundle.getStringTrimmed(
248: _bundle, "propertyWidth"), "80");
249: ComponentUtils.setProperty(sheet, Bundle.getStringTrimmed(
250: _bundle, "propertyHeight"), "70");
251: sheet.setImage("image1", Bundle.getStringTrimmed(_bundle,
252: "propertyUrl"), image2);
253: Util.wait(2000);
254:
255: Util.saveAllAPICall();
256: Util.wait(2000);
257: endTest();
258: }
259:
260: /*
261: * Deploy application
262: */
263: public void testDeploy() {
264: startTest();
265: //need to wait responce
266: Waiter deploymentWaiter = new Waiter(new Waitable() {
267: public Object actionProduced(Object output) {
268: String text = ((OutputOperator) output).getText();
269: if (text.indexOf(_buildSuccess) != -1)
270: return _true;
271: return null;
272:
273: }
274:
275: public String getDescription() {
276: return ("Waiting Project Deployed");
277: }
278: });
279: log("Deploy from menu");
280: ProjectNavigatorOperator.pressPopupItemOnNode(_projectName,
281: _run);
282: TestUtils.wait(2000);
283: OutputOperator outputWindow = new OutputOperator();
284: deploymentWaiter.getTimeouts().setTimeout("Waiter.WaitingTime",
285: 240000);
286: log("wait until " + _buildSuccess);
287: try {
288: deploymentWaiter.waitAction(outputWindow);
289: } catch (InterruptedException e) {
290: log(outputWindow.getText());
291: e.printStackTrace();
292: fail("Deployment error: " + e);
293: }
294: log("Deployment complete");
295: endTest();
296: }
297:
298: public void testCloseProject() {
299: startTest();
300: Util.saveAllAPICall();
301: new ProjectNavigatorOperator().pressPopupItemOnNode(
302: _projectName, Bundle.getStringTrimmed(_bundle,
303: "CloseProjectPopupItem"));
304: //TestUtils.closeCurrentProject();
305: TestUtils.wait(5000);
306: endTest();
307: }
308:
309: /* Need to undeploy project to finish tests correctly */
310: public void testUndeploy() {
311: startTest();
312: log("Initialize");
313: explorer = ServerNavigatorOperator.showNavigatorOperator();
314: String serverPath = _serverPath + _projectServer; //Current deployment server
315: String deploymentPath = serverPath + _deploymentPath; //glassfish specific
316: String applicationPath = deploymentPath + _separator
317: + _projectName; //project name
318:
319: // Select the Server Navigator and set the JTreeOperator
320: log("get explorer");
321: new QueueTool().waitEmpty(100); //??
322: explorer.requestFocus();
323: JTreeOperator tree = explorer.getTree();
324: try {
325: Thread.sleep(4000);
326: } catch (Exception e) {
327: } // Sleep 4 secs to make sure Server Navigator is in focus
328:
329: // Need to refresh J2EE AppServer node
330: log("refresh");
331: explorer.pushPopup(tree, serverPath, _refresh);
332: TestUtils.wait(1000);
333:
334: log("refresh deployment path: " + deploymentPath);
335: TestUtils.wait(1000);
336: explorer.selectPath(deploymentPath);
337: explorer.getTree().expandPath(
338: explorer.getTree().findPath(deploymentPath));
339: explorer.pushPopup(tree, deploymentPath, _refresh);
340: TestUtils.wait(1000);
341:
342: log("undeploy Path: " + applicationPath);
343: explorer.selectPath(applicationPath);
344: TestUtils.wait(1000);
345:
346: log("Push Menu Undeploy...");
347: explorer.pushPopup(explorer.getTree(), applicationPath,
348: _undeploy);
349: TestUtils.wait(5000);
350: endTest();
351: }
352:
353: public void testCheckIDELog() {
354: startTest();
355: try {
356: String err = ComponentUtils.hasUnexpectedException();
357: String str = "";
358: if (!(err.equals(""))) {
359: assertTrue(
360: "Unexpected exceptions found in message.log: "
361: + err, str.equals(""));
362: }
363: } catch (IOException ioe) {
364: ioe.printStackTrace();
365: fail("Failed to open message.log : " + ioe);
366: }
367: endTest();
368: }
369: }
|