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.input.calendar;
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.gravy.DocumentOutlineOperator;
058: import org.netbeans.modules.visualweb.gravy.EditorOperator;
059: import org.netbeans.modules.visualweb.gravy.ProjectNavigatorOperator;
060: import org.netbeans.modules.visualweb.test.components.util.ComponentUtils;
061: import org.netbeans.modules.visualweb.gravy.dataconnectivity.ServerNavigatorOperator;
062:
063: import org.netbeans.jemmy.operators.*;
064: import org.netbeans.jemmy.drivers.text.SwingTextKeyboardDriver;
065:
066: import java.io.File;
067: import java.io.IOException;
068:
069: import java.awt.Point;
070:
071: /**
072: * @author Lark Fitzgerald (lark.fitzgerald@sun.com)
073: */
074: public class AcceptanceTest extends RaveTestCase {
075:
076: //Project variables
077: public String _sharedBundle = "org.netbeans.modules.visualweb.test.components.Component";
078: public String _privateBundle = "org.netbeans.modules.visualweb.test.components.input.calendar.Acceptance";
079: public String _projectName = Bundle.getStringTrimmed(
080: _privateBundle, "projectName");
081: public String _projectServer = Bundle.getStringTrimmed(
082: _sharedBundle, "projectServer");
083: public String _logFileLocation = Bundle.getStringTrimmed(
084: _sharedBundle, "logFile");
085: public String _logFile = System.getProperty("xtest.workdir")
086: + File.separator + _logFileLocation;
087: public String _exception = Bundle.getStringTrimmed(_sharedBundle,
088: "Exception");
089: public String _close = Bundle.getStringTrimmed(_sharedBundle,
090: "close");
091: public String _run = Bundle.getStringTrimmed(_sharedBundle, "Run");
092: public String _buildSuccess = Bundle.getStringTrimmed(
093: _sharedBundle, "buildSuccess");
094: public String _true = Bundle
095: .getStringTrimmed(_sharedBundle, "true");
096:
097: //Bundle variables
098: public String _basicPalette = Bundle.getStringTrimmed(
099: _sharedBundle, "basicPalette");
100: public String _basicButton = Bundle.getStringTrimmed(_sharedBundle,
101: "basicButton");
102: public String _basicLabel = Bundle.getStringTrimmed(_sharedBundle,
103: "basicLabel");
104: public String _basicMessage = Bundle.getStringTrimmed(
105: _sharedBundle, "basicMessage");
106: public String _basicCalendar = Bundle.getStringTrimmed(
107: _sharedBundle, "basicCalendar");
108:
109: //drop points
110: public int _x = Integer.parseInt(Bundle.getStringTrimmed(
111: _privateBundle, "x"));
112: public int _button1y = Integer.parseInt(Bundle.getStringTrimmed(
113: _privateBundle, "button1y"));
114: public int _message1y = Integer.parseInt(Bundle.getStringTrimmed(
115: _privateBundle, "message1y"));
116: public int _label1y = Integer.parseInt(Bundle.getStringTrimmed(
117: _privateBundle, "label1y"));
118: public int _calendar1y = Integer.parseInt(Bundle.getStringTrimmed(
119: _privateBundle, "calendar1y"));
120:
121: //values
122: public String _buttonValue1 = Bundle.getStringTrimmed(
123: _privateBundle, "buttonValue1");
124: public String _labelValue1 = Bundle.getStringTrimmed(
125: _privateBundle, "labelValue1");
126: public String _beanPropertyType1 = Bundle.getStringTrimmed(
127: _privateBundle, "beanPropertyType1");
128: public String _beanPropertyName1 = Bundle.getStringTrimmed(
129: _privateBundle, "beanPropertyName1");
130: public String _beanPropertyName2 = Bundle.getStringTrimmed(
131: _privateBundle, "beanPropertyName2");
132: public String _beanPropertyName3 = Bundle.getStringTrimmed(
133: _privateBundle, "beanPropertyName3");
134: public String _calendar1 = Bundle.getStringTrimmed(_privateBundle,
135: "calendar1");
136:
137: //property items
138: public String _propertyFor = Bundle.getStringTrimmed(_sharedBundle,
139: "propertyFor");
140: public String _propertyText = Bundle.getStringTrimmed(
141: _sharedBundle, "propertyText");
142: public String _propertyRequired = Bundle.getStringTrimmed(
143: _sharedBundle, "propertyRequired");
144: public String _propertyDateFormatPattern = Bundle.getStringTrimmed(
145: _sharedBundle, "propertyDateFormatPattern");
146: public String _propertyMaxDate = Bundle.getStringTrimmed(
147: _sharedBundle, "propertyMaxDate");
148: public String _propertyMinDate = Bundle.getStringTrimmed(
149: _sharedBundle, "propertyMinDate");
150: public String _propertySelectedDate = Bundle.getStringTrimmed(
151: _sharedBundle, "propertySelectedDate");
152:
153: //Outline variables
154: public String _outlineForm1 = Bundle.getStringTrimmed(
155: _sharedBundle, "outlineForm1");
156: public String _sessionBean1 = Bundle.getStringTrimmed(
157: _sharedBundle, "sessionBean1");
158:
159: public String _beanPatternPath = Bundle.getStringTrimmed(
160: _sharedBundle, "beanPatternPath");
161: public String _addPropertyPath = Bundle.getStringTrimmed(
162: _sharedBundle, "addPropertyPath");
163:
164: //undeployment
165: public String _undeploy = Bundle.getStringTrimmed(_sharedBundle,
166: "undeploy");
167: public String _refresh = Bundle.getStringTrimmed(_sharedBundle,
168: "refresh");
169: public String _serverPath = Bundle.getStringTrimmed(_sharedBundle,
170: "serverPath");
171: public String _deploymentPath = Bundle.getStringTrimmed(
172: _sharedBundle, "deploymentPathGlassfish");
173: public String _separator = Bundle.getStringTrimmed(_sharedBundle,
174: "separator");
175:
176: Point clickPoint, dropPoint;
177: public static DesignerPaneOperator designer;
178: public static PaletteContainerOperator palette;
179: public static DocumentOutlineOperator outline;
180: public static SheetTableOperator sheet;
181: public static DeploymentDialogOperator deploy;
182: public static ServerNavigatorOperator explorer;
183: public int row;
184: public String _page1 = Bundle.getStringTrimmed(_sharedBundle,
185: "webPage1");
186:
187: public AcceptanceTest(String testName) {
188: super (testName);
189: }
190:
191: public static Test suite() {
192: TestSuite suite = new NbTestSuite();
193: // suite.addTest(new AcceptanceTest("configureServer"));
194: suite.addTest(new AcceptanceTest("createWebProject"));
195: // suite.addTest(new AcceptanceTest("testAddLabel"));
196: suite.addTest(new AcceptanceTest("testAddMessage"));
197: suite.addTest(new AcceptanceTest("testAddButton"));
198: suite.addTest(new AcceptanceTest("testAddCalendar"));
199: suite.addTest(new AcceptanceTest("testAddLinks"));
200: // suite.addTest(new AcceptanceTest("testSetCalendarProperties"));
201: // suite.addTest(new AcceptanceTest("testAddPageSource"));
202: suite.addTest(new AcceptanceTest("testDeploy"));
203: suite.addTest(new AcceptanceTest("testCloseWebProject"));
204: suite.addTest(new AcceptanceTest("testUndeploy"));
205: suite.addTest(new AcceptanceTest("testCheckIDELog"));
206:
207: return suite;
208: }
209:
210: /** method called before each testcase
211: */
212: protected void setUp() {
213: System.out.println("######## " + getName() + " #######");
214: }
215:
216: /** method called after each testcase
217: */
218: protected void tearDown() {
219: System.out.println("######## " + getName()
220: + " Finished #######");
221: }
222:
223: /*
224: * Create Web Project
225: *
226: */
227: public void createWebProject() {
228: startTest();
229: log("**Creating Project");
230: //Create Project
231: try {
232: ComponentUtils.createNewProject(_projectName);
233: } catch (Exception e) {
234: log(">> Project Creation Failed");
235: e.printStackTrace();
236: log(e.toString());
237: fail();
238: }
239: log("**Done");
240: endTest();
241: }
242:
243: /*
244: * Drag a Basic > button and label it Submit
245: */
246: public void testAddButton() {
247: startTest();
248: log("**Initialize");
249: designer = new DesignerPaneOperator(RaveWindowOperator
250: .getDefaultRave());
251: palette = new PaletteContainerOperator(_basicPalette);
252: try {
253: Thread.sleep(5000);
254: } catch (Exception e) {
255: }
256:
257: log("**Add Button to designer");
258: clickPoint = palette.getClickPoint(_basicButton);
259: dropPoint = new Point(_x, _button1y);
260: palette.dndPaletteComponent(_basicButton, designer, dropPoint);
261: try {
262: Thread.sleep(2000);
263: } catch (Exception e) {
264: }
265:
266: log("**Set Button text inline");
267: JTextFieldOperator field = new JTextFieldOperator(designer);
268: SwingTextKeyboardDriver keyboard = new SwingTextKeyboardDriver();
269: keyboard.enterText(field, _buttonValue1);
270:
271: log("**Done.");
272: endTest();
273: }
274:
275: /*
276: * Drag a basic > message onto designer
277: */
278: public void testAddMessage() {
279: startTest();
280: log("**Initialize");
281: designer = new DesignerPaneOperator(RaveWindowOperator
282: .getDefaultRave());
283: palette = new PaletteContainerOperator(_basicPalette);
284: try {
285: Thread.sleep(5000);
286: } catch (Exception e) {
287: }
288:
289: log("**Drag Message onto designer");
290: clickPoint = palette.getClickPoint(_basicMessage);
291: dropPoint = new Point(_x, _message1y);
292: palette.dndPaletteComponent(_basicMessage, designer, dropPoint);
293: try {
294: Thread.sleep(2000);
295: } catch (Exception e) {
296: }
297:
298: log("**Done.");
299: endTest();
300: }
301:
302: /*
303: * Drag a basic > label onto designer and label it: Please select your birthdate.
304: */
305: public void testAddLabel() {
306: startTest();
307: log("**Initialize");
308: designer = new DesignerPaneOperator(RaveWindowOperator
309: .getDefaultRave());
310: palette = new PaletteContainerOperator(_basicPalette);
311: try {
312: Thread.sleep(5000);
313: } catch (Exception e) {
314: }
315:
316: log("**Add label to designer");
317: clickPoint = palette.getClickPoint(_basicLabel);
318: dropPoint = new Point(_x, _label1y);
319: palette.dndPaletteComponent(_basicLabel, designer, dropPoint);
320: try {
321: Thread.sleep(2000);
322: } catch (Exception e) {
323: }
324:
325: //For some reason, the property sheet doesn't rise to top
326: log("make sure property sheet is visible");
327: Util.getMainMenu().pushMenu("Window|Properties", "|");
328: try {
329: Thread.sleep(2000);
330: } catch (Exception e) {
331: }
332:
333: log("**Set label value via property sheet");
334: sheet = new SheetTableOperator();
335: sheet.clickCell(_propertyText);
336: // row = sheet.findCellRow(_propertyLabel);
337: // sheet.clickForEdit(row, 1);
338: // sheet.clickForEdit(row, 1);
339: new JTextComponentOperator(sheet).enterText(_labelValue1);
340:
341: log("**Done.");
342: endTest();
343: }
344:
345: /*
346: * Drag a basic > calendar onto designer.
347: */
348: public void testAddCalendar() {
349: startTest();
350: log("**Initialize");
351: designer = new DesignerPaneOperator(RaveWindowOperator
352: .getDefaultRave());
353: palette = new PaletteContainerOperator(_basicPalette);
354: try {
355: Thread.sleep(5000);
356: } catch (Exception e) {
357: }
358:
359: log("**Add Calendar to designer");
360: clickPoint = palette.getClickPoint(_basicCalendar);
361: dropPoint = new Point(_x, _label1y);
362: //drops in wrong position
363: // palette.dndPaletteComponent(_basicCalendar, designer, dropPoint);
364: palette.addComponent(_basicCalendar, designer, dropPoint);
365: try {
366: Thread.sleep(2000);
367: } catch (Exception e) {
368: }
369:
370: log("**Done.");
371: endTest();
372: }
373:
374: /*
375: * Link the message component to the calendar
376: * It should update to say: Message summary for calendar 1
377: *
378: * Link the label component to the calendar
379: */
380: public void testAddLinks() {
381: startTest();
382: /* log("Select the label component");
383: designer.clickMouse(_x, _label1y, 1);
384:
385: //For some reason, the property sheet doesn't rise to top
386: log("make sure property sheet is visible");
387: Util.getMainMenu().pushMenu("Window|Properties","|");
388:
389: log("**Set Label for property to calendar1");
390: row = sheet.findCellRow(_propertyFor);
391: sheet.clickForEdit(row, 1);
392: sheet.setComboBoxValue(_propertyFor, _calendar1);
393: try { Thread.sleep(1000); } catch(Exception e) {}
394: */
395: log("Select the message component");
396: // designer.clickMouse(_x, _message1y, 1);
397: //For some reason I can't select the component on the designer.
398: //probably the actual drop point is different than what I selected.
399: //So I'm using the outline window instead.
400: outline = new DocumentOutlineOperator(Util.getMainWindow());
401: Util.wait(2000);
402: outline.verify();
403: String msg = _outlineForm1 + "message1";
404: // outline.clickOnPath(msg);
405: outline.selectPath(msg);
406: Util.wait(5000);
407:
408: log("make sure property sheet is visible");
409: Util.getMainMenu().pushMenu("Window|Properties", "|");
410: try {
411: Thread.sleep(2000);
412: } catch (Exception e) {
413: }
414:
415: log("**Set message for property via property sheet");
416: sheet = new SheetTableOperator();
417: row = sheet.findCellRow(_propertyFor);
418: // sheet.clickCell(_propertyFor);
419: sheet.clickForEdit(row, 1);
420: sheet.setComboBoxValue(_propertyFor, _calendar1);
421:
422: log("**Done.");
423: endTest();
424: }
425:
426: // suite.addTest(new AcceptanceTest("testSetCalendarProperties"));
427: // suite.addTest(new AcceptanceTest("testAddPageSource"));
428:
429: /*
430: Select Calendar on the designer and go to its properties.
431:
432: Go to dateFormatPattern property and press the ...
433:
434: Check-on the MM.dd.yyy format and press OK.
435:
436: Go to the maxDate property and press the ...
437: Select the #{SessionBean1.maxDate} and press OK.
438:
439: Go to the minDate property and press the ...
440: Select the #{SessionBean1.minDate} and press OK.
441:
442: Go to the Required property and set it to true
443: The label should show the * indicator
444:
445: Go to the selectedDate property and press the ...
446: Select the #{SessionBean1.selectedDate} and press OK.
447:
448: Select the Java tab of the designer and add the following import statement:
449: import java.util.Date;
450:
451: Scroll down to the init() method and add the following code:
452: getSessionBean1().setMaxDate(new Date());
453: getSessionBean1().setMinDate(new Date(01, 0, 1));
454: getSessionBean1().setSelectedDate(new Date(69, 7, 13));
455:
456: Ctrl-S to save
457:
458: Go back to designer
459: */
460:
461: /*
462: * Deploy application
463: */
464: public void testDeploy() {
465: startTest();
466: Util.saveAllAPICall();
467: TestUtils.wait(2000);
468: //need to wait responce
469: Waiter deploymentWaiter = new Waiter(new Waitable() {
470: public Object actionProduced(Object output) {
471: String text = ((OutputOperator) output).getText();
472: if (text.indexOf(_buildSuccess) != -1)
473: return _true;
474: return null;
475:
476: }
477:
478: public String getDescription() {
479: return ("Waiting Project Deployed");
480: }
481: });
482: log("Deploy from menu");
483: ProjectNavigatorOperator.pressPopupItemOnNode(_projectName,
484: _run);
485: TestUtils.wait(2000);
486: OutputOperator outputWindow = new OutputOperator();
487: deploymentWaiter.getTimeouts().setTimeout("Waiter.WaitingTime",
488: 240000);
489: log("wait until " + _buildSuccess);
490: try {
491: deploymentWaiter.waitAction(outputWindow);
492: } catch (InterruptedException e) {
493: log(outputWindow.getText());
494: e.printStackTrace();
495: fail("Deployment error: " + e);
496: }
497: log("Deployment complete");
498: endTest();
499: }
500:
501: /*
502: * Close Project
503: *
504: */
505: public void testCloseWebProject() {
506: startTest();
507: Util.saveAllAPICall();
508: new ProjectNavigatorOperator().pressPopupItemOnNode(
509: _projectName, _close);
510: //TestUtils.closeCurrentProject();
511: TestUtils.wait(5000);
512: endTest();
513: }
514:
515: /* Need to undeploy project to finish tests correctly */
516: public void testUndeploy() {
517: startTest();
518: log("Initialize");
519: explorer = ServerNavigatorOperator.showNavigatorOperator();
520: String serverPath = _serverPath + _projectServer; //Current deployment server
521: String deploymentPath = serverPath + _deploymentPath; //glassfish specific
522: String applicationPath = deploymentPath + _separator
523: + _projectName; //project name
524:
525: // Select the Server Navigator and set the JTreeOperator
526: log("get explorer");
527: new QueueTool().waitEmpty(100); //??
528: explorer.requestFocus();
529: JTreeOperator tree = explorer.getTree();
530: try {
531: Thread.sleep(4000);
532: } catch (Exception e) {
533: } // Sleep 4 secs to make sure Server Navigator is in focus
534:
535: // Need to refresh J2EE AppServer node
536: log("refresh");
537: explorer.pushPopup(tree, serverPath, _refresh);
538: TestUtils.wait(1000);
539:
540: log("refresh deployment path: " + deploymentPath);
541: TestUtils.wait(1000);
542: explorer.selectPath(deploymentPath);
543: explorer.getTree().expandPath(
544: explorer.getTree().findPath(deploymentPath));
545: explorer.pushPopup(tree, deploymentPath, _refresh);
546: TestUtils.wait(1000);
547:
548: log("undeploy Path: " + applicationPath);
549: explorer.selectPath(applicationPath);
550: TestUtils.wait(1000);
551:
552: log("Push Menu Undeploy...");
553: explorer.pushPopup(explorer.getTree(), applicationPath,
554: _undeploy);
555: TestUtils.wait(5000);
556: endTest();
557: }
558:
559: public void testCheckIDELog() {
560: startTest();
561: try {
562: String err = ComponentUtils.hasUnexpectedException();
563: String str = "";
564: if (!(err.equals(""))) {
565: assertTrue(
566: "Unexpected exceptions found in message.log: "
567: + err, str.equals(""));
568: }
569: } catch (IOException ioe) {
570: ioe.printStackTrace();
571: fail("Failed to open message.log : " + ioe);
572: }
573: endTest();
574: }
575: }
|