Source Code Cross Referenced for WizardOperatorTest.java in  » IDE-Netbeans » jellytools » org » netbeans » jellytools » 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 » jellytools » org.netbeans.jellytools 
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:        package org.netbeans.jellytools;
042:
043:        import java.awt.Dialog;
044:        import java.beans.PropertyChangeEvent;
045:        import java.beans.PropertyChangeListener;
046:        import java.beans.PropertyChangeSupport;
047:        import javax.swing.JLabel;
048:        import javax.swing.event.ChangeListener;
049:        import org.netbeans.jemmy.JemmyException;
050:        import org.netbeans.jemmy.operators.JLabelOperator;
051:        import org.netbeans.junit.NbTestSuite;
052:        import org.openide.DialogDisplayer;
053:        import org.openide.WizardDescriptor;
054:        import org.openide.util.HelpCtx;
055:
056:        /**
057:         * Test of org.netbeans.jellytools.WizardOperator.
058:         */
059:        public class WizardOperatorTest extends JellyTestCase implements 
060:                PropertyChangeListener {
061:
062:            /** Title of test wizard. */
063:            private static final String TEST_WIZARD_TITLE = "Test Wizard";
064:            /** Caption of wizard panel. */
065:            private static final String TEST_WIZARD_PANEL0 = "First Panel";
066:            /** Caption of wizard panel. */
067:            private static final String TEST_WIZARD_PANEL1 = "Second Panel";
068:            /** Caption of wizard panel. */
069:            private static final String TEST_WIZARD_PANEL2 = "Third Panel";
070:            /** Text of JLabel in panels. */
071:            private static final String TEST_WIZARD_LABEL = "This is a test wizard panel ";
072:
073:            /** constructor required by JUnit
074:             * @param testName method name to be used as testcase
075:             */
076:            public WizardOperatorTest(java.lang.String testName) {
077:                super (testName);
078:            }
079:
080:            /** Use for internal test execution inside IDE
081:             * @param args command line arguments
082:             */
083:            public static void main(java.lang.String[] args) {
084:                junit.textui.TestRunner.run(suite());
085:            }
086:
087:            /** Method used for explicit testsuite definition
088:             * @return  created suite
089:             */
090:            public static NbTestSuite suite() {
091:                NbTestSuite suite = new NbTestSuite(WizardOperatorTest.class);
092:                return suite;
093:            }
094:
095:            /** Redirect output to log files, wait before each test case and
096:             * show dialog to test. */
097:            protected void setUp() {
098:                System.out.println("### " + getName() + " ###");
099:                showTestWizard();
100:            }
101:
102:            /** Dispose test dialog. */
103:            protected void tearDown() {
104:                dialog.dispose();
105:            }
106:
107:            /** Test Next button getter. Go to next panel and check if second panel
108:             * is shown. */
109:            public void testBtNext() {
110:                WizardOperator wo = new WizardOperator(TEST_WIZARD_TITLE);
111:                wo.btNext().push();
112:                String text = new JLabelOperator(wo, TEST_WIZARD_LABEL)
113:                        .getText();
114:                assertEquals("Next not detected correctly.", TEST_WIZARD_LABEL
115:                        + "1", text);
116:            }
117:
118:            /** Test of next method. Go to next panel and check if second panel
119:             * is shown. */
120:            public void testNext() {
121:                WizardOperator wo = new WizardOperator(TEST_WIZARD_TITLE);
122:                wo.next();
123:                String text = new JLabelOperator(wo, TEST_WIZARD_LABEL)
124:                        .getText();
125:                assertEquals("Next not detected correctly.", TEST_WIZARD_LABEL
126:                        + "1", text);
127:            }
128:
129:            /** Test Back button getter. Go to next panel, then back and check if
130:             * first panel is shown. */
131:            public void testBtBack() {
132:                WizardOperator wo = new WizardOperator(TEST_WIZARD_TITLE);
133:                wo.btNext().push();
134:                wo.btBack().push();
135:                String text = new JLabelOperator(wo, TEST_WIZARD_LABEL)
136:                        .getText();
137:                assertEquals("Back not detected correctly.", TEST_WIZARD_LABEL
138:                        + "0", text);
139:            }
140:
141:            /** Test of back method. Go to next panel, then back and check if
142:             * first panel is shown. */
143:            public void testBack() {
144:                WizardOperator wo = new WizardOperator(TEST_WIZARD_TITLE);
145:                wo.next();
146:                wo.back();
147:                String text = new JLabelOperator(wo, TEST_WIZARD_LABEL)
148:                        .getText();
149:                assertEquals("Back not detected correctly.", TEST_WIZARD_LABEL
150:                        + "0", text);
151:            }
152:
153:            /** Test Finish button getter. Go to the last panel and push Finish button.
154:             * Check if returned value correspond to FINISH_OPTION. */
155:            public void testBtFinish() {
156:                WizardOperator wo = new WizardOperator(TEST_WIZARD_TITLE);
157:                wo.btNext().push();
158:                wo.btNext().push();
159:                wo.btFinish().push();
160:                assertEquals("Finish not detected correctly.",
161:                        wd.FINISH_OPTION, wd.getValue());
162:            }
163:
164:            /** Test of finish method. Go to the last panel and push Finish button.
165:             * Check if returned value correspond to FINISH_OPTION. */
166:            public void testFinish() {
167:                WizardOperator wo = new WizardOperator(TEST_WIZARD_TITLE);
168:                wo.next();
169:                wo.next();
170:                wo.finish();
171:                assertEquals("Finish not detected correctly.",
172:                        wd.FINISH_OPTION, wd.getValue());
173:            }
174:
175:            /** Test of lstSteps method, of class org.netbeans.jellytools.WizardOperator. */
176:            public void testLstSteps() {
177:                WizardOperator wo = new WizardOperator(TEST_WIZARD_TITLE);
178:                wo.btNext().push();
179:                String value0 = wo.lstSteps().getModel().getElementAt(0)
180:                        .toString();
181:                assertEquals("List of steps not detected correctly",
182:                        TEST_WIZARD_PANEL0, value0);
183:            }
184:
185:            /** Test of stepsGetSelectedIndex method. On first panel it should be 0,
186:             * then go to next panel where it should be 1. */
187:            public void testStepsGetSelectedIndex() {
188:                WizardOperator wo = new WizardOperator(TEST_WIZARD_TITLE);
189:                int index = wo.stepsGetSelectedIndex();
190:                assertEquals("Selected index not detected correctly", 0, index);
191:                wo.next();
192:                index = wo.stepsGetSelectedIndex();
193:                assertEquals("Selected index not detected correctly", 1, index);
194:            }
195:
196:            /** Test of stepsGetSelectedValue method. On first panel it should be "First Panel",
197:             * then go to next panel where it should be "Second Panel". */
198:            public void testStepsGetSelectedValue() {
199:                WizardOperator wo = new WizardOperator(TEST_WIZARD_TITLE);
200:                String selectedValue = wo.stepsGetSelectedValue();
201:                assertEquals("Selected index not detected correctly",
202:                        TEST_WIZARD_PANEL0, selectedValue);
203:                wo.next();
204:                selectedValue = wo.stepsGetSelectedValue();
205:                assertEquals("Selected value not detected correctly",
206:                        TEST_WIZARD_PANEL1, selectedValue);
207:            }
208:
209:            /** Test of checkPanel method. Check first panel, then go to next panel
210:             * and check again. Then check negative case. */
211:            public void testCheckPanel() {
212:                WizardOperator wo = new WizardOperator(TEST_WIZARD_TITLE);
213:                try {
214:                    wo.checkPanel(TEST_WIZARD_PANEL0);
215:                } catch (JemmyException e) {
216:                    fail("checkPanel() method doesn't work properly.");
217:                }
218:                wo.next();
219:                try {
220:                    wo.checkPanel(TEST_WIZARD_PANEL1);
221:                } catch (JemmyException e) {
222:                    fail("checkPanel() method doesn't work properly.");
223:                }
224:                // negative case
225:                try {
226:                    wo.checkPanel(TEST_WIZARD_PANEL0);
227:                    fail("checkPanel() should throw exception if check fails.");
228:                } catch (JemmyException e) {
229:                    // right, it should fail
230:                }
231:            }
232:
233:            /** Constants to create a wizard. */
234:            private static final String PROP_AUTO_WIZARD_STYLE = "WizardPanel_autoWizardStyle"; // NOI18N
235:            private static final String PROP_CONTENT_DISPLAYED = "WizardPanel_contentDisplayed"; // NOI18N
236:            private static final String PROP_CONTENT_NUMBERED = "WizardPanel_contentNumbered"; // NOI18N
237:            private static final String PROP_CONTENT_SELECTED_INDEX = "WizardPanel_contentSelectedIndex"; // NOI18N
238:            private static final String PROP_CONTENT_DATA = "WizardPanel_contentData"; // NOI18N
239:
240:            /** Instance of WizardDescriptor used to test. */
241:            private WizardDescriptor wd;
242:            /** Instance of Dialog which hosts test wizard. */
243:            private Dialog dialog;
244:
245:            /** Opens test wizard with 3 steps. */
246:            private void showTestWizard() {
247:                TestPanel panel0 = new TestPanel(0);
248:                panel0.addPropertyChangeListener(this );
249:                TestPanel panel1 = new TestPanel(1);
250:                panel1.addPropertyChangeListener(this );
251:                TestPanel panel2 = new TestPanel(2);
252:                panel2.addPropertyChangeListener(this );
253:                WizardDescriptor.Panel[] panels = { panel0, panel1, panel2 };
254:                WizardDescriptor.ArrayIterator iterator = new WizardDescriptor.ArrayIterator(
255:                        panels);
256:                wd = new WizardDescriptor(iterator);
257:                wd.putProperty(PROP_AUTO_WIZARD_STYLE, Boolean.TRUE);
258:                wd.putProperty(PROP_CONTENT_DISPLAYED, Boolean.TRUE);
259:                wd.putProperty(PROP_CONTENT_NUMBERED, Boolean.TRUE);
260:                wd.putProperty(PROP_CONTENT_DATA, new String[] {
261:                        TEST_WIZARD_PANEL0, TEST_WIZARD_PANEL1,
262:                        TEST_WIZARD_PANEL2 });
263:                wd.setTitle(TEST_WIZARD_TITLE);
264:                wd.setModal(false);
265:                dialog = DialogDisplayer.getDefault().createDialog(wd);
266:                dialog.setVisible(true);
267:            }
268:
269:            /** Used to change selected item in list of steps. */
270:            public void propertyChange(PropertyChangeEvent evt) {
271:                if (PROP_CONTENT_SELECTED_INDEX.equals(evt.getPropertyName())) {
272:                    wd.putProperty(PROP_CONTENT_SELECTED_INDEX, evt
273:                            .getNewValue());
274:                }
275:            }
276:
277:            /** Test panel - one wizard step. */
278:            private class TestPanel implements  WizardDescriptor.Panel {
279:
280:                PropertyChangeSupport changeSupport;
281:                int index;
282:
283:                public TestPanel(int index) {
284:                    super ();
285:                    this .index = index;
286:                }
287:
288:                public java.awt.Component getComponent() {
289:                    if (changeSupport == null) {
290:                        changeSupport = new PropertyChangeSupport(this );
291:                    }
292:                    changeSupport.firePropertyChange(
293:                            PROP_CONTENT_SELECTED_INDEX, null, new Integer(
294:                                    index));
295:                    JLabel label = new JLabel(TEST_WIZARD_LABEL + index);
296:                    label
297:                            .setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
298:                    return label;
299:                }
300:
301:                public HelpCtx getHelp() {
302:                    return new HelpCtx("");
303:                }
304:
305:                /** Test whether the panel is finished and it is safe to proceed to the next one.
306:                 * If the panel is valid, the "Next" (or "Finish") button will be enabled.
307:                 */
308:                public boolean isValid() {
309:                    return true;
310:                }
311:
312:                public void storeSettings(Object settings) {
313:                }
314:
315:                public void readSettings(Object settings) {
316:                }
317:
318:                public void addChangeListener(ChangeListener listener) {
319:                }
320:
321:                public void removeChangeListener(ChangeListener listener) {
322:                }
323:
324:                public void addPropertyChangeListener(
325:                        PropertyChangeListener listener) {
326:                    if (changeSupport == null) {
327:                        changeSupport = new PropertyChangeSupport(this );
328:                    }
329:                    changeSupport.addPropertyChangeListener(listener);
330:                }
331:
332:                public void removePropertyChangeListener(
333:                        PropertyChangeListener listener) {
334:                    if (changeSupport != null) {
335:                        changeSupport.removePropertyChangeListener(listener);
336:                    }
337:                }
338:            }
339:
340:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.