Source Code Cross Referenced for PropertyEditorsTest.java in  » IDE-Netbeans » library » gui » propertyeditors » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » library » gui.propertyeditors 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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-2006 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 gui.propertyeditors;
043:
044:        import java.io.PrintStream;
045:        import java.io.PrintWriter;
046:
047:        import org.netbeans.jellytools.JellyTestCase;
048:        import org.netbeans.jellytools.NbDialogOperator;
049:
050:        import org.netbeans.jellytools.properties.Property;
051:        import org.netbeans.jellytools.properties.PropertySheetOperator;
052:
053:        import org.netbeans.jemmy.JemmyProperties;
054:        import org.netbeans.jemmy.TestOut;
055:        import org.netbeans.jemmy.operators.JTableOperator;
056:        import org.netbeans.jemmy.operators.Operator;
057:
058:        /**
059:         * JellyTestCase test case with implemented Property Editors Test support stuff
060:         *
061:         * @author  mmirilovic@netbeans.org
062:         */
063:        public abstract class PropertyEditorsTest extends JellyTestCase {
064:
065:            protected static PrintStream err;
066:            protected static PrintStream log;
067:
068:            public String propertyInitialValue;
069:            public String propertyValue;
070:
071:            protected static JTableOperator tableOperator;
072:
073:            protected static NbDialogOperator propertyCustomizer;
074:
075:            protected static NbDialogOperator propertiesWindow = null;
076:
077:            private static final String CAPTION = "\n===========================";
078:
079:            /** Creates a new instance of PropertyEditorsTest */
080:            public PropertyEditorsTest(String testName) {
081:                super (testName);
082:            }
083:
084:            public void setUp() {
085:                //err = System.out;
086:                err = getLog();
087:                log = getRef();
088:
089:                try {
090:                    JemmyProperties.getProperties().setOutput(
091:                            new TestOut(null, new PrintWriter(err, true),
092:                                    new PrintWriter(err, true), null));
093:                    initializeWorkplace();
094:                } catch (Exception exc) {
095:                    failTest(exc,
096:                            "SetUp failed. It seems like initializeWorkplace cause exception:"
097:                                    + exc.getMessage());
098:                }
099:            }
100:
101:            /** Open Property Customizer for <b>propertyName</b>, set value by customizer and press Ok button, verify value with <b>expectance</b>.
102:             * @param propertyName name of property to be customized
103:             * @param expectance true- new value must be the same as expected value, false-value needn't be the same as expected
104:             */
105:            public void setByCustomizerOk(String propertyName,
106:                    boolean expectance) {
107:                try {
108:                    err.println(CAPTION
109:                            + " Trying to set value by customizer-ok {name="
110:                            + propertyName + " / value=" + propertyValue
111:                            + "} .");
112:                    propertyInitialValue = getValue(propertyName);
113:
114:                    openAndGetPropertyCustomizer(propertyName);
115:                    setCustomizerValue();
116:
117:                    if (propertyCustomizer.isShowing())
118:                        propertyCustomizer.ok();
119:
120:                    err.println(CAPTION
121:                            + " Trying to set value by customizer-ok {name="
122:                            + propertyName + " / value=" + propertyValue
123:                            + "} - finished.");
124:                    verifyPropertyValue(expectance);
125:
126:                } catch (Exception exc) {
127:                    failTest(exc, "EXCEPTION: setByCustomizer(" + propertyName
128:                            + ", " + expectance
129:                            + ") failed and cause exception:"
130:                            + exc.getMessage());
131:                }
132:            }
133:
134:            /** Open Property Customizer for <b>propertyName</b>, set value by customizer and press Cancel button, verify value with <b>expectance</b>.
135:             * @param propertyName name of property to be customized
136:             * @param expectance true- new value must be the same as expected value, false-value needn't be the same as expected
137:             */
138:            public void setByCustomizerCancel(String propertyName,
139:                    boolean expectance) {
140:                try {
141:                    err
142:                            .println(CAPTION
143:                                    + " Trying to set value by customizer-cancel {name="
144:                                    + propertyName + " / value="
145:                                    + propertyValue + "} .");
146:                    propertyInitialValue = getValue(propertyName);
147:                    openAndGetPropertyCustomizer(propertyName);
148:                    setCustomizerValue();
149:
150:                    if (propertyCustomizer.isShowing())
151:                        propertyCustomizer.cancel();
152:
153:                    err
154:                            .println(CAPTION
155:                                    + " Trying to set value by customizer-cancel {name="
156:                                    + propertyName + " / value="
157:                                    + propertyValue + "} - finished.");
158:                    verifyPropertyValue(expectance);
159:
160:                } catch (Exception exc) {
161:                    failTest(exc, "EXCEPTION: setByCustomizerCancel("
162:                            + propertyName + ", " + expectance
163:                            + ") failed and cause exception:"
164:                            + exc.getMessage());
165:                }
166:            }
167:
168:            /** Set value <b>propertyValue</b> of property <b>propertyName</b> by in-place, verify value with <b>expectance</b>.
169:             * @param propertyName name of property to be changed
170:             * @param propertyValue new value of property
171:             * @param expectance true- new value must be the same as expected value, false-value needn't be the same as expected
172:             */
173:            public void setByInPlace(String propertyName, String propertyValue,
174:                    boolean expectance) {
175:                try {
176:                    err.println(CAPTION
177:                            + " Trying to set value by in-place {name="
178:                            + propertyName + " / value=" + propertyValue
179:                            + "} .");
180:                    propertyInitialValue = getValue(propertyName);
181:
182:                    //            ((TextFieldProperty) findProperty(propertyName, "TextFieldProperty")).setValue(propertyValue);
183:                    new PropertySheetOperator(propertiesWindow)
184:                            .tblSheet()
185:                            .changeCellObject(
186:                                    findProperty(propertyName, propertiesWindow)
187:                                            .getRow(), 1, propertyValue);
188:
189:                    err.println(CAPTION
190:                            + " Trying to set value by in-place {name="
191:                            + propertyName + " / value=" + propertyValue
192:                            + "}  - finished.");
193:                    verifyPropertyValue(expectance);
194:
195:                } catch (Exception exc) {
196:                    failTest(exc, "EXCEPTION: setByInPlace(" + propertyName
197:                            + ", " + propertyValue + ", " + expectance
198:                            + ") failed and cause exception:"
199:                            + exc.getMessage());
200:                }
201:            }
202:
203:            /** Set value <b>propertyValue</b> of property <b>propertyName</b> by combobox, verify value with <b>expectance</b>.
204:             * @param propertyName name of property to be changed
205:             * @param propertyValue new value of property
206:             * @param expectance true- new value must be the same as expected value, false-value needn't be the same as expected
207:             */
208:            public void setByCombo(String propertyName, String propertyValue,
209:                    boolean expectance) {
210:                try {
211:                    err.println(CAPTION
212:                            + " Trying to set value by combo box {name="
213:                            + propertyName + " / value=" + propertyValue
214:                            + "} .");
215:                    propertyInitialValue = getValue(propertyName);
216:
217:                    findProperty(propertyName, propertiesWindow).setValue(
218:                            propertyValue);
219:
220:                    err.println(CAPTION
221:                            + " Trying to set value by combo box {name="
222:                            + propertyName + " / value=" + propertyValue
223:                            + "}  - finished.");
224:                    verifyPropertyValue(expectance);
225:
226:                } catch (Exception exc) {
227:                    failTest(exc, "EXCEPTION: setByCombo(" + propertyName
228:                            + ", " + propertyValue + ", " + expectance
229:                            + ") failed and cause exception:"
230:                            + exc.getMessage());
231:                }
232:            }
233:
234:            /** Set indexed value <b>propertyValueIndex</b> of property <b>propertyName</b> by combobox, verify value with <b>expectance</b>.
235:             * @param propertyName name of property to be changed
236:             * @param propertyValueIndex index of new value in combobox
237:             * @param expectance true- new value must be the same as expected value, false-value needn't be the same as expected
238:             */
239:            public void setByCombo(String propertyName, int propertyValueIndex,
240:                    boolean expectance) {
241:                try {
242:                    err.println(CAPTION
243:                            + " Trying to set value by combo box {name="
244:                            + propertyName + " / value=" + propertyValueIndex
245:                            + "} .");
246:                    propertyInitialValue = getValue(propertyName);
247:
248:                    findProperty(propertyName, propertiesWindow).setValue(
249:                            propertyValueIndex);
250:
251:                    err.println(CAPTION
252:                            + " Trying to set value by combo box {name="
253:                            + propertyName + " / value=" + propertyValueIndex
254:                            + "}  - finished.");
255:                    verifyPropertyValue(expectance);
256:
257:                } catch (Exception exc) {
258:                    failTest(exc, "EXCEPTION: setByCombo(" + propertyName
259:                            + ", " + propertyValueIndex + ", " + expectance
260:                            + ") failed and cause exception:"
261:                            + exc.getMessage());
262:                }
263:            }
264:
265:            /** Verify customizer layout for property <b>propertyName</b>.
266:             * @param propertyName name of property to be changed
267:             */
268:            public void verifyCustomizer(String propertyName) {
269:                try {
270:                    err.println(CAPTION + " Trying to verify customizer {name="
271:                            + propertyName + "} .");
272:                    openAndGetPropertyCustomizer(propertyName);
273:                    verifyCustomizerLayout();
274:
275:                    if (propertyCustomizer.isShowing())
276:                        propertyCustomizer.cancel();
277:
278:                    err.println(CAPTION + " Trying to verify customizer {name="
279:                            + propertyName + "}  - finished.");
280:
281:                } catch (Exception exc) {
282:                    failTest(exc,
283:                            "EXCEPTION: Verification of Property Customizer Layout for property("
284:                                    + propertyName
285:                                    + ") failed and cause exception:"
286:                                    + exc.getMessage());
287:                }
288:            }
289:
290:            /** Open property customizer for property <b>propertyName</b>.
291:             * @param propertyName name of property to be changed
292:             * @return Property Customizer
293:             */
294:            public static NbDialogOperator openAndGetPropertyCustomizer(
295:                    String propertyName) {
296:                // hack for troubles with request focus on already focused property
297:                new PropertySheetOperator(propertiesWindow).tblSheet()
298:                        .selectCell(0, 0);
299:
300:                findProperty(propertyName, propertiesWindow).openEditor();
301:                propertyCustomizer = findPropertyCustomizer(propertyName);
302:                return propertyCustomizer;
303:            }
304:
305:            /** Return Property Customizer.
306:             * @return Property Customizer.
307:             */
308:            public NbDialogOperator getPropertyCustomizer() {
309:                return propertyCustomizer;
310:            }
311:
312:            /** Return Informational dialog
313:             * @return Informational dialog
314:             */
315:            public NbDialogOperator getInformationDialog() {
316:                String title = org.netbeans.jellytools.Bundle.getString(
317:                        "org.openide.Bundle", "NTF_InformationTitle");
318:
319:                err.println(CAPTION + " Waiting dialog {" + title + "} .");
320:                NbDialogOperator dialog = new NbDialogOperator(title);
321:                err.println(CAPTION + " Waiting dialog {" + title
322:                        + "} - finished.");
323:                return dialog;
324:            }
325:
326:            /** Get value of property <b>propertyName</b>
327:             * @param propertyName name of property asked for value
328:             * @return value of property
329:             */
330:            public String getValue(String propertyName) {
331:                String returnValue = findProperty(propertyName,
332:                        propertiesWindow).getValue();
333:                err.println("GET VALUE = [" + returnValue + "].");
334:                return returnValue;
335:            }
336:
337:            /** Find Property Cusotmizer by name of property <b>propertyName</b>
338:             * @param propertyName name of property
339:             * @return founded Property Customizer
340:             */
341:            private static NbDialogOperator findPropertyCustomizer(
342:                    String propertyName) {
343:                return new NbDialogOperator(propertyName);
344:            }
345:
346:            /** Verify exceptation value.
347:             * @param propertyName name of property
348:             * @param expectation true - expected value must be the same as new value, false - expected value should not be the same
349:             * @param propertyValueExpectation expected value
350:             * @param propertyValue new value
351:             * @param waitDialog true - after changing value Informational dialog about impissibility to set invalid value arise
352:             */
353:            public void verifyExpectationValue(String propertyName,
354:                    boolean expectation, String propertyValueExpectation,
355:                    String propertyValue, boolean waitDialog) {
356:
357:                // Dialog isn't used for informing user about Invalid new value: Class,
358:                if (waitDialog) {
359:                    getInformationDialog().ok();
360:                    err.println(CAPTION + " Dialog closed by [Ok].");
361:
362:                    if (propertyCustomizer != null
363:                            && propertyCustomizer.isShowing()) {
364:                        err.println(CAPTION
365:                                + " Property Customizer is still showing.");
366:                        propertyCustomizer.cancel();
367:                        err.println(CAPTION
368:                                + " Property Customizer closed by [Cancel].");
369:                    }
370:
371:                }
372:
373:                String newValue = getValue(propertyName);
374:                String log = "Actual value is {" + newValue
375:                        + "} and initial is{" + propertyInitialValue
376:                        + "} - set value is {" + propertyValue
377:                        + "} / expectation value is {"
378:                        + propertyValueExpectation + "}";
379:
380:                err.println(CAPTION + " Trying to verify value [" + log + "].");
381:
382:                if (expectation) {
383:                    if (newValue.equals(propertyValueExpectation)) {
384:                        log(log + " --> PASS");
385:                    } else {
386:                        fail(log + " --> FAIL");
387:                    }
388:                } else {
389:                    if (newValue.equals(propertyInitialValue)) {
390:                        log(log + " --> PASS");
391:                    } else {
392:                        fail(log + " --> FAIL");
393:                    }
394:
395:                }
396:            }
397:
398:            /** Reinitialize Workplace. */
399:            public static NbDialogOperator reInitializeWorkplace() {
400:                propertiesWindow = null;
401:                return openPropertySheet();
402:            }
403:
404:            /** Initialize Workplace. */
405:            public static NbDialogOperator initializeWorkplace() {
406:                return openPropertySheet();
407:            }
408:
409:            /** Open property sheet (bean customizer). */
410:            private static NbDialogOperator openPropertySheet() {
411:                String waitDialogTimeout = "DialogWaiter.WaitDialogTimeout";
412:                long findTimeout = JemmyProperties
413:                        .getCurrentTimeout(waitDialogTimeout);
414:                JemmyProperties.setCurrentTimeout(waitDialogTimeout, 3000);
415:
416:                try {
417:                    propertiesWindow = new NbDialogOperator(
418:                            org.netbeans.jellytools.Bundle.getString(
419:                                    "org.netbeans.core.Bundle",
420:                                    "CTL_FMT_LocalProperties", new Object[] {
421:                                            new Integer(1), "TestNode" }));
422:                } catch (org.netbeans.jemmy.TimeoutExpiredException exception) {
423:                    new PropertiesTest();
424:                    propertiesWindow = new NbDialogOperator(
425:                            org.netbeans.jellytools.Bundle.getString(
426:                                    "org.netbeans.core.Bundle",
427:                                    "CTL_FMT_LocalProperties", new Object[] {
428:                                            new Integer(1), "TestNode" }));
429:                }
430:
431:                JemmyProperties.setCurrentTimeout(waitDialogTimeout,
432:                        findTimeout);
433:
434:                return propertiesWindow;
435:            }
436:
437:            /** Find Property in Property Sheet and return them.
438:             * This is first hack for new Jelly2, because it isn't possible to set String Comparator only for one operator.
439:             * @param propertyName name of property
440:             * @param type  TextFieldProperty - textfield property, ComboBoxProperty - combobox property
441:             * @return property by <b>propertyName</b> and <b>type</b>.
442:             */
443:            protected static Property findProperty(String propertyName,
444:                    NbDialogOperator propertiesWindow) {
445:                PropertySheetOperator propertySheet = new PropertySheetOperator(
446:                        propertiesWindow);
447:                Property property = new Property(propertySheet, propertyName);
448:
449:                // property.openEditor(); - doesn't work - custom editor is opened without Users Event
450:                // hack for invoking Custom Editor by pushing shortcut CTRL+SPACE
451:                tableOperator = propertySheet.tblSheet();
452:                // Need to request focus before selection because invokeCustomEditor action works
453:                // only when table is focused
454:                tableOperator.makeComponentVisible();
455:                tableOperator.requestFocus();
456:                tableOperator.waitHasFocus();
457:                // need to select property first
458:                ((javax.swing.JTable) tableOperator.getSource())
459:                        .changeSelection(property.getRow(), 0, false, false);
460:                //        return new Property(new PropertySheetOperator(propertiesWindow), propertyName);
461:                return property;
462:            }
463:
464:            public void tearDown() {
465:                closeAllModal();
466:            }
467:
468:            /** Print full stack trace to log files, get message and log to test results if test fails.
469:             * @param exc Exception logged to description
470:             * @param message written to test results
471:             */
472:            protected static void failTest(Exception exc, String message) {
473:                err.println("################################");
474:                exc.printStackTrace(err);
475:                err.println("################################");
476:                fail(message);
477:            }
478:
479:            /** Make IDE screenshot of whole IDE
480:             * @param testCase it is needed for locate destination directory of saving screenshot file
481:             */
482:            public static void makeIDEScreenshot(JellyTestCase testCase) {
483:                try {
484:                    testCase.getWorkDir();
485:                    org.netbeans.jemmy.util.PNGEncoder.captureScreen(testCase
486:                            .getWorkDirPath()
487:                            + System.getProperty("file.separator")
488:                            + "IDEscreenshot.png");
489:                } catch (Exception ioexc) {
490:                    testCase.log("Impossible make IDE screenshot!!! \n"
491:                            + ioexc.toString());
492:                }
493:            }
494:
495:            public abstract void setCustomizerValue();
496:
497:            public abstract void verifyCustomizerLayout();
498:
499:            public abstract void verifyPropertyValue(boolean expectation);
500:
501:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.