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.selection.checkboxgroup;
043:
044: import junit.framework.Test;
045: import junit.framework.TestSuite;
046:
047: import java.io.File;
048: import java.awt.*;
049: import java.awt.event.KeyEvent;
050: import java.io.IOException;
051:
052: import org.netbeans.modules.visualweb.gravy.*;
053: import org.netbeans.modules.visualweb.gravy.ProjectNavigatorOperator;
054: import org.netbeans.modules.visualweb.gravy.dataconnectivity.ServerNavigatorOperator;
055: import org.netbeans.modules.visualweb.gravy.toolbox.PaletteContainerOperator;
056: import org.netbeans.modules.visualweb.gravy.designer.DesignerPaneOperator;
057: import org.netbeans.modules.visualweb.gravy.properties.SheetTableOperator;
058: import org.netbeans.jemmy.operators.*;
059: import org.netbeans.modules.visualweb.test.components.util.ComponentUtils;
060: import org.netbeans.jellytools.OutputOperator;
061: import org.netbeans.jemmy.Waitable;
062: import org.netbeans.jemmy.Waiter;
063: import org.netbeans.jemmy.QueueTool;
064: import org.netbeans.jemmy.operators.JTreeOperator;
065:
066: /**
067: * @author Sherry Zhou (sherry.zhou@sun.com)
068: */
069: public class AcceptanceTest extends RaveTestCase {
070:
071: public String _bundle = "org.netbeans.modules.visualweb.test.components.Component";
072: public String _projectName = "CheckboxGroupAcceptanceTest";
073: public String _projectServer = Bundle.getStringTrimmed(_bundle,
074: "projectServer");
075: public String _logFileLocation = Bundle.getStringTrimmed(_bundle,
076: "logFile");
077: public String _logFile = System.getProperty("xtest.sketchpad")
078: + File.separator + _logFileLocation;
079: public String _exception = Bundle.getStringTrimmed(_bundle,
080: "Exception");
081: public String _close = Bundle.getStringTrimmed(_bundle, "close");
082: public String _run = Bundle.getStringTrimmed(_bundle, "Run");
083: public String _buildSuccess = Bundle.getStringTrimmed(_bundle,
084: "buildSuccess");
085: public String _true = Bundle.getStringTrimmed(_bundle, "true");
086:
087: public static int xCheckboxGroup = 50;
088: public static int yCheckboxGroup = 50;
089: public static int xMessageGroup = 50;
090: public static int yMessageGroup = 100;
091: public static int xButton = 100;
092: public static int yButton = 200;
093:
094: //undeployment
095: public String _undeploy = Bundle.getStringTrimmed(_bundle,
096: "undeploy");
097: public String _refresh = Bundle
098: .getStringTrimmed(_bundle, "refresh");
099: public String _serverPath = Bundle.getStringTrimmed(_bundle,
100: "serverPath");
101: public String _deploymentPath = Bundle.getStringTrimmed(_bundle,
102: "deploymentPathGlassfish");
103: public String _separator = Bundle.getStringTrimmed(_bundle,
104: "separator");
105:
106: public static DesignerPaneOperator designer;
107: public static SheetTableOperator sheet;
108: public static ServerNavigatorOperator explorer;
109:
110: public AcceptanceTest(String testName) {
111: super (testName);
112: }
113:
114: public static Test suite() {
115: TestSuite suite = new TestSuite();
116: suite.addTest(new AcceptanceTest("testCreateProject"));
117: suite.addTest(new AcceptanceTest("testAddCheckboxGroup"));
118: // suite.addTest(new AcceptanceTest("testCheckboxGroupDBBinding"));
119: // suite.addTest(new AcceptanceTest("testAddSessionBeanProperties"));
120: // suite.addTest(new AcceptanceTest("testBindSelectedProperty"));
121: // suite.addTest(new AcceptanceTest("testAddButtonActionEvent"));
122: suite.addTest(new AcceptanceTest("testDeploy"));
123: suite.addTest(new AcceptanceTest("testCloseProject"));
124: suite.addTest(new AcceptanceTest("testUndeploy"));
125: suite.addTest(new AcceptanceTest("testCheckIDELog"));
126:
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: *
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 first CheckboxGroup components. Set properties
183: */
184:
185: public void testAddCheckboxGroup() {
186: startTest();
187: designer = new DesignerPaneOperator(RaveWindowOperator
188: .getDefaultRave());
189:
190: log("Add first CheckboxGroup component");
191: PaletteContainerOperator palette = new PaletteContainerOperator(
192: Bundle.getStringTrimmed(_bundle, "basicPalette"));
193: Util.wait(10000);
194: palette.addComponent(Bundle.getStringTrimmed(_bundle,
195: "basicCheckboxGroup"), designer, new Point(
196: xCheckboxGroup, yCheckboxGroup));
197:
198: log("set its label, required, cloumns properties");
199: sheet = new SheetTableOperator();
200: Util.wait(2000);
201: // sheet.setButtonValue() can't location lable property if labelOnTop is in property sheet
202: // So use ComponentUtils.setProperty()
203: ComponentUtils.setProperty(sheet, Bundle.getStringTrimmed(
204: _bundle, "propertyLabel"), "Select a Person(s)");
205: Util.wait(500);
206: sheet.setCheckBoxValue(Bundle.getStringTrimmed(_bundle,
207: "propertyRequired"), "true");
208: Util.wait(500);
209: // sheet.setButtonValue(Bundle.getStringTrimmed(_bundle, "propertyColumns"), "5");
210: ComponentUtils.setProperty(sheet, Bundle.getStringTrimmed(
211: _bundle, "propertyColumns"), "6");
212: Util.wait(500);
213:
214: Util.saveAllAPICall();
215: Util.wait(2000);
216: endTest();
217: }
218:
219: public void testCheckboxGroupDBBinding() {
220: startTest();
221: String _dataProvider = "customerDataProvider";
222: String _dbName = Bundle.getStringTrimmed(_bundle,
223: "Databses_SampleDBNode");
224: String _passwd = "app";
225: String _tableName = Bundle.getStringTrimmed(_bundle,
226: "Databases_CustomerTableNode");
227: log(_tableName);
228: ComponentUtils.connectDB(_dbName, _passwd);
229: ComponentUtils.bindToDataProvider(xCheckboxGroup + 1,
230: yCheckboxGroup + 1, _tableName, _dataProvider, "NAME",
231: "NAME");
232: endTest();
233: }
234:
235: public void testAddSessionBeanProperties() {
236: startTest();
237: log("Add SessionBean propert - choices");
238: String path = _projectName + "|"
239: + Bundle.getStringTrimmed(_bundle, "SessionBean_Path");
240: // Put long sleep to wait for scanning project classpath finish, otherwisethe node won't expand
241: Util.wait(10000);
242:
243: ComponentUtils.addObjectProperty(path, "choices", "String[]",
244: Bundle.getStringTrimmed(_bundle,
245: "BeanPattern_Mode_ReadWrite"));
246: Util.wait(500);
247:
248: Util.saveAllAPICall();
249: Util.wait(2000);
250: endTest();
251: }
252:
253: public void testBindSelectedProperty() {
254: startTest();
255: designer = new DesignerPaneOperator(RaveWindowOperator
256: .getDefaultRave());
257: ComponentUtils.setPropertyBinding(designer, xCheckboxGroup,
258: yCheckboxGroup, "selected", "#{SessionBean1.choices}");
259: endTest();
260: }
261:
262: public void testAddButtonActionEvent() {
263: startTest();
264: designer = new DesignerPaneOperator(RaveWindowOperator
265: .getDefaultRave());
266: designer.makeComponentVisible();
267:
268: log("Add button and message group component");
269: PaletteContainerOperator palette = new PaletteContainerOperator(
270: Bundle.getStringTrimmed(_bundle, "basicPalette"));
271: Util.wait(2000);
272: palette.addComponent(Bundle.getStringTrimmed(_bundle,
273: "basicButton"), designer, new Point(xButton, yButton));
274: Util.wait(500);
275: palette.addComponent(Bundle.getStringTrimmed(_bundle,
276: "basicMessageGroup"), designer, new Point(
277: xMessageGroup, yMessageGroup));
278: Util.wait(500);
279: // Double click at button to open Jave Editor
280: designer.clickMouse(xButton + 1, yButton + 1, 2);
281: TestUtils.wait(1000);
282: JEditorPaneOperator editor = new JEditorPaneOperator(
283: RaveWindowOperator.getDefaultRave(), "public class "
284: + "Page1");
285:
286: editor.setVerification(false);
287: TestUtils.wait(2000);
288: editor.requestFocus();
289: TestUtils.wait(2000);
290: editor.pushKey(KeyEvent.VK_ENTER);
291: editor.setText("String showSelections=\"You selected \"; \n");
292: editor
293: .setText("String[] mySelections = getSessionBean1().getChoices();\n");
294: editor
295: .setText("for (int i = 0; i < mySelections.length; i++) \n");
296: editor.setText("showSelections+=mySelections[i] +\" \"; \n");
297: // editor.setText(("} \n");
298: editor.setText("if (showSelections.equals(\"\")) \n");
299: editor.setText("showSelections = \"nothing selected\"; \n");
300: editor.setText("else \n");
301: editor
302: .setText("showSelections = \"Values chosen:\n\" + showSelections; \n");
303: editor.setText("// Display the list in the message group \n");
304: editor.setText("info(showSelections); \n");
305: TestUtils.wait(200);
306:
307: log("Reformat code");
308: editor.clickForPopup();
309: new JPopupMenuOperator().pushMenu("Reformat Code");
310: TestUtils.wait(200);
311:
312: // Switch to design panel
313: designer.makeComponentVisible();
314: TestUtils.wait(10000);
315: Util.saveAllAPICall();
316: Util.wait(2000);
317: endTest();
318: }
319:
320: /*
321: * Deploy application
322: */
323: public void testDeploy() {
324: startTest();
325: //need to wait responce
326: Waiter deploymentWaiter = new Waiter(new Waitable() {
327: public Object actionProduced(Object output) {
328: String text = ((OutputOperator) output).getText();
329: if (text.indexOf(_buildSuccess) != -1)
330: return _true;
331: return null;
332:
333: }
334:
335: public String getDescription() {
336: return ("Waiting Project Deployed");
337: }
338: });
339: log("Deploy from menu");
340: ProjectNavigatorOperator.pressPopupItemOnNode(_projectName,
341: _run);
342: TestUtils.wait(2000);
343: OutputOperator outputWindow = new OutputOperator();
344: deploymentWaiter.getTimeouts().setTimeout("Waiter.WaitingTime",
345: 240000);
346: log("wait until " + _buildSuccess);
347: try {
348: deploymentWaiter.waitAction(outputWindow);
349: } catch (InterruptedException e) {
350: log(outputWindow.getText());
351: e.printStackTrace();
352: fail("Deployment error: " + e);
353: }
354: log("Deployment complete");
355: endTest();
356: }
357:
358: public void testCloseProject() {
359: startTest();
360: Util.saveAllAPICall();
361: new ProjectNavigatorOperator().pressPopupItemOnNode(
362: _projectName, Bundle.getStringTrimmed(_bundle,
363: "CloseProjectPopupItem"));
364: //TestUtils.closeCurrentProject();
365: TestUtils.wait(5000);
366: endTest();
367: }
368:
369: /* Need to undeploy project to finish tests correctly */
370: public void testUndeploy() {
371: startTest();
372: log("Initialize");
373: explorer = ServerNavigatorOperator.showNavigatorOperator();
374: String serverPath = _serverPath + _projectServer; //Current deployment server
375: String deploymentPath = serverPath + _deploymentPath; //glassfish specific
376: String applicationPath = deploymentPath + _separator
377: + _projectName; //project name
378:
379: // Select the Server Navigator and set the JTreeOperator
380: log("get explorer");
381: new QueueTool().waitEmpty(100); //??
382: explorer.requestFocus();
383: JTreeOperator tree = explorer.getTree();
384: try {
385: Thread.sleep(4000);
386: } catch (Exception e) {
387: } // Sleep 4 secs to make sure Server Navigator is in focus
388:
389: // Need to refresh J2EE AppServer node
390: log("refresh");
391: explorer.pushPopup(tree, serverPath, _refresh);
392: TestUtils.wait(1000);
393:
394: log("refresh deployment path: " + deploymentPath);
395: TestUtils.wait(1000);
396: explorer.selectPath(deploymentPath);
397: explorer.getTree().expandPath(
398: explorer.getTree().findPath(deploymentPath));
399: explorer.pushPopup(tree, deploymentPath, _refresh);
400: TestUtils.wait(1000);
401:
402: log("undeploy Path: " + applicationPath);
403: explorer.selectPath(applicationPath);
404: TestUtils.wait(1000);
405:
406: log("Push Menu Undeploy...");
407: explorer.pushPopup(explorer.getTree(), applicationPath,
408: _undeploy);
409: TestUtils.wait(5000);
410: endTest();
411: }
412:
413: public void testCheckIDELog() {
414: startTest();
415: try {
416: String err = ComponentUtils.hasUnexpectedException();
417: String str = "";
418: if (!(err.equals(""))) {
419: assertTrue(
420: "Unexpected exceptions found in message.log: "
421: + err, str.equals(""));
422: }
423: } catch (IOException ioe) {
424: ioe.printStackTrace();
425: fail("Failed to open message.log : " + ioe);
426: }
427: endTest();
428: }
429: }
|