Source Code Cross Referenced for MBeanNameAndLocationWizard.java in  » IDE-Netbeans » jmx » org » netbeans » modules » jmx » test » mbeanwizard » 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 » jmx » org.netbeans.modules.jmx.test.mbeanwizard 
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 2004-2005 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.jmx.test.mbeanwizard;
043:
044:        import javax.swing.JLabel;
045:        import org.netbeans.jellytools.NewFileNameLocationStepOperator;
046:        import org.netbeans.jellytools.NewFileWizardOperator;
047:        import org.netbeans.junit.NbTestSuite;
048:        import org.netbeans.modules.jmx.test.helpers.MBean;
049:        import static org.netbeans.modules.jmx.test.helpers.JellyConstants.*;
050:
051:        /**
052:         * Create JMX MBean files.
053:         * Check :
054:         * - wizards default values
055:         * - wizards behavior
056:         * - wizards robustness
057:         */
058:        public class MBeanNameAndLocationWizard extends MBeanWizardTestCase {
059:
060:            private static final String STANDARD_MBEAN_NEW_FILE_DESCRIPTION = "\nCreates a new JMX Standard MBean.";
061:            private static final String MXBEAN_NEW_FILE_DESCRIPTION = "\nCreates a new JMX MXBean.";
062:            private static final String MBEAN_FROM_EXISTING_JAVA_CLASS_NEW_FILE_DESCRIPTION = "\nCreates a new JMX MBean from an existing Java Class.";
063:            private static final String STANDARD_MBEAN_WITH_METADATA_NEW_FILE_DESCRIPTION = "\nCreates a new JMX MBean that extends javax.management.StandardMBean class.";
064:
065:            /** Need to be defined because of JUnit */
066:            public MBeanNameAndLocationWizard(String name) {
067:                super (name);
068:            }
069:
070:            /** Use for execution inside IDE */
071:            public static void main(java.lang.String[] args) {
072:                // run whole suite
073:                junit.textui.TestRunner.run(suite());
074:            }
075:
076:            public static NbTestSuite suite() {
077:                NbTestSuite suite = new NbTestSuite();
078:                suite.addTest(new MBeanNameAndLocationWizard("createMBean1"));
079:                suite.addTest(new MBeanNameAndLocationWizard("createMBean2"));
080:                suite.addTest(new MBeanNameAndLocationWizard("createMBean3"));
081:                suite.addTest(new MBeanNameAndLocationWizard("createMBean4"));
082:                return suite;
083:            }
084:
085:            public void setUp() {
086:                // Select project node
087:                selectNode(PROJECT_NAME_MBEAN_FUNCTIONAL);
088:                // Initialize the wrapper java class
089:                initWrapperJavaClass(PROJECT_NAME_MBEAN_FUNCTIONAL,
090:                        PACKAGE_COM_FOO_BAR, EMPTY_JAVA_CLASS_NAME);
091:            }
092:
093:            //========================= JMX CLASS =================================//
094:
095:            /**
096:             * StandardMBean
097:             */
098:            public void createMBean1() {
099:
100:                System.out.println("==========  createMBean1  ==========");
101:
102:                testNameAndLocationWizard(FILE_TYPE_STANDARD_MBEAN,
103:                        STANDARD_MBEAN_DEFAULT_NAME);
104:            }
105:
106:            /**
107:             * MXBean
108:             */
109:            public void createMBean2() {
110:
111:                System.out.println("==========  createMBean2  ==========");
112:
113:                testNameAndLocationWizard(FILE_TYPE_MXBEAN, MXBEAN_DEFAULT_NAME);
114:            }
115:
116:            /**
117:             * MBean from existing java class
118:             */
119:            public void createMBean3() {
120:
121:                System.out.println("==========  createMBean3  ==========");
122:
123:                testNameAndLocationWizard(
124:                        FILE_TYPE_MBEAN_FROM_EXISTING_JAVA_CLASS,
125:                        MBEAN_FROM_EXISTING_JAVA_CLASS_DEFAULT_NAME);
126:            }
127:
128:            /**
129:             * StandardMBean with metadata
130:             */
131:            public void createMBean4() {
132:
133:                System.out.println("==========  createMBean4  ==========");
134:
135:                testNameAndLocationWizard(
136:                        FILE_TYPE_STANDARD_MBEAN_WITH_METADATA,
137:                        STANDARD_MBEAN_WITH_METADATA_DEFAULT_NAME);
138:            }
139:
140:            //========================= Test Wizard ==================================//
141:
142:            /**
143:             * Test name and location wizard
144:             */
145:            private void testNameAndLocationWizard(String fileType,
146:                    String mbeanDefaultClassName) {
147:
148:                System.out.println("File type is " + fileType);
149:
150:                MBean mbean = null;
151:
152:                // New File wizard execution
153:                NewFileWizardOperator nfwo = newFileWizardFromMenu(
154:                        PROJECT_NAME_MBEAN_FUNCTIONAL, FILE_CATEGORY_JMX,
155:                        fileType);
156:                // Check new file wizard components
157:                checkNewFileWizardComponents(nfwo);
158:                // Check new file wizard values
159:                checkNewFileWizardValues(nfwo, fileType);
160:                nfwo.next();
161:
162:                NewFileNameLocationStepOperator nfnlso = nameAndLocationWizard(
163:                        null, null);
164:
165:                // Check name and location wizard components
166:                checkNameAndLocationWizardComponents(nfnlso, fileType, null);
167:                // Check name and location wizard default values
168:                mbean = new MBean(mbeanDefaultClassName, null, "",
169:                        mbeanDefaultClassName + " Description", "", false,
170:                        null, null, null);
171:                checkNameAndLocationWizardValues(nfnlso, fileType,
172:                        PROJECT_NAME_MBEAN_FUNCTIONAL, mbean);
173:
174:                // Update some values
175:                // Perform back/next actions
176:                // Check no data has been lost
177:                mbean = new MBean("MyNewClassName", null, PACKAGE_COM_FOO_BAR,
178:                        "My New Description", PACKAGE_COM_FOO_BAR + "."
179:                                + EMPTY_JAVA_CLASS_NAME, true, null, null, null);
180:                updateNameAndLocationWizardValues(nfnlso, fileType, mbean);
181:                nfnlso.back();
182:                nfnlso.next();
183:                // Check name and location wizard components
184:                checkNameAndLocationWizardComponents(nfnlso, fileType, mbean);
185:                // Check name and location wizard values
186:                checkNameAndLocationWizardValues(nfnlso, fileType,
187:                        PROJECT_NAME_MBEAN_FUNCTIONAL, mbean);
188:                if (fileType.equals(FILE_TYPE_MBEAN_FROM_EXISTING_JAVA_CLASS)
189:                        || fileType
190:                                .equals(FILE_TYPE_STANDARD_MBEAN_WITH_METADATA)) {
191:                    nfnlso.next();
192:                    nfnlso.back();
193:                    // Check name and location wizard components
194:                    checkNameAndLocationWizardComponents(nfnlso, fileType,
195:                            mbean);
196:                    // Check name and location wizard values
197:                    checkNameAndLocationWizardValues(nfnlso, fileType,
198:                            PROJECT_NAME_MBEAN_FUNCTIONAL, mbean);
199:                }
200:
201:                // Check warnings
202:                checkNameAndLocationWizardWarnings(nfnlso, fileType);
203:
204:                nfnlso.cancel();
205:            }
206:
207:            //========================= Check Wizard ==================================//
208:
209:            /**
210:             * Check new file wizard components are enabled/disabled
211:             */
212:            private void checkNewFileWizardComponents(NewFileWizardOperator nfwo) {
213:
214:                // Check text fields
215:                assertFalse(nfwo.txtDescription().isEditable());
216:
217:                // Checks buttons
218:                assertFalse(nfwo.btBack().isEnabled());
219:                assertTrue(nfwo.btNext().isEnabled());
220:                assertFalse(nfwo.btFinish().isEnabled());
221:                assertTrue(nfwo.btCancel().isEnabled());
222:                assertFalse(nfwo.btHelp().isEnabled());
223:            }
224:
225:            /**
226:             * Check new file wizard values
227:             */
228:            private void checkNewFileWizardValues(NewFileWizardOperator nfwo,
229:                    String fileType) {
230:
231:                String description = null;
232:
233:                // Check New File Wizard description
234:                if (fileType.equals(FILE_TYPE_STANDARD_MBEAN)) {
235:                    description = STANDARD_MBEAN_NEW_FILE_DESCRIPTION;
236:                } else if (fileType.equals(FILE_TYPE_MXBEAN)) {
237:                    description = MXBEAN_NEW_FILE_DESCRIPTION;
238:                } else if (fileType
239:                        .equals(FILE_TYPE_MBEAN_FROM_EXISTING_JAVA_CLASS)) {
240:                    description = MBEAN_FROM_EXISTING_JAVA_CLASS_NEW_FILE_DESCRIPTION;
241:                } else if (fileType
242:                        .equals(FILE_TYPE_STANDARD_MBEAN_WITH_METADATA)) {
243:                    description = STANDARD_MBEAN_WITH_METADATA_NEW_FILE_DESCRIPTION;
244:                }
245:                assertEquals(description, nfwo.txtDescription()
246:                        .getDisplayedText());
247:
248:            }
249:
250:            /**
251:             * Check name and location wizard components are enabled/disabled
252:             */
253:            private void checkNameAndLocationWizardComponents(
254:                    NewFileNameLocationStepOperator nfnlso, String fileType,
255:                    MBean mbean) {
256:
257:                // Check text fields
258:                assertTrue(nfnlso.txtObjectName().isEnabled());
259:                assertTrue(nfnlso.txtObjectName().isEditable());
260:                assertTrue(nfnlso.txtProject().isEnabled());
261:                assertFalse(nfnlso.txtProject().isEditable());
262:                assertTrue(nfnlso.txtCreatedFile().isEnabled());
263:                assertFalse(nfnlso.txtCreatedFile().isEditable());
264:                assertTrue(getTextFieldOperator(MBEAN_DESCRIPTION_TEXT_FIELD,
265:                        nfnlso).isEnabled());
266:                assertTrue(getTextFieldOperator(MBEAN_DESCRIPTION_TEXT_FIELD,
267:                        nfnlso).isEditable());
268:                if (fileType.equals(FILE_TYPE_MBEAN_FROM_EXISTING_JAVA_CLASS)) {
269:                    assertTrue(getTextFieldOperator(CLASS_TO_WRAP_TEXT_FIELD,
270:                            nfnlso).isEnabled());
271:                    assertTrue(getTextFieldOperator(CLASS_TO_WRAP_TEXT_FIELD,
272:                            nfnlso).isEditable());
273:                    assertTrue(getCheckBoxOperator(
274:                            OBJECT_WRAPPED_AS_MXBEAN_CHECK_BOX, nfnlso)
275:                            .isEnabled());
276:                }
277:
278:                // Check buttons
279:                assertTrue(nfnlso.btBack().isEnabled());
280:                // MBean from existing java class
281:                if (fileType.equals(FILE_TYPE_MBEAN_FROM_EXISTING_JAVA_CLASS)) {
282:                    if (mbean == null || mbean.getClassToWrap() == "") {
283:                        assertFalse(nfnlso.btNext().isEnabled());
284:                    } else {
285:                        assertTrue(nfnlso.btNext().isEnabled());
286:                    }
287:                    assertFalse(nfnlso.btFinish().isEnabled());
288:                    assertTrue(getButtonOperator(CLASS_TO_WRAP_BROWSE_BUTTON,
289:                            nfnlso).isEnabled());
290:                }
291:                // Standard MBean with metadata
292:                else if (fileType
293:                        .equals(FILE_TYPE_STANDARD_MBEAN_WITH_METADATA)) {
294:                    assertTrue(nfnlso.btNext().isEnabled());
295:                    assertFalse(nfnlso.btFinish().isEnabled());
296:                }
297:                // Standard MBean and MXBean
298:                else {
299:                    assertFalse(nfnlso.btNext().isEnabled());
300:                    assertTrue(nfnlso.btFinish().isEnabled());
301:                }
302:                assertTrue(nfnlso.btCancel().isEnabled());
303:                assertTrue(nfnlso.btHelp().isEnabled());
304:            }
305:
306:            /**
307:             * Check name and location wizard values
308:             */
309:            private void checkNameAndLocationWizardValues(
310:                    NewFileNameLocationStepOperator nfnlso, String fileType,
311:                    String projectName, MBean mbean) {
312:
313:                String createdFile = null;
314:                String interfaceFile = null;
315:
316:                // Initialize created file and interface file values
317:                createdFile = mbean.getName() + ".java";
318:                if (fileType.equals(FILE_TYPE_MXBEAN)) {
319:                    interfaceFile = mbean.getName() + "MXBean.java";
320:                } else {
321:                    interfaceFile = mbean.getName() + "MBean.java";
322:                }
323:
324:                // Check Name and Location Wizard title
325:                assertEquals("New " + fileType, nfnlso.getTitle());
326:                // Check Project value
327:                assertEquals(projectName, nfnlso.txtProject().getText());
328:                // Check Class Name value
329:                assertEquals(mbean.getName(), nfnlso.txtObjectName().getText());
330:                // Check Package value
331:                assertEquals(mbean.getPackage(), nfnlso.cboPackage()
332:                        .getSelectedItem());
333:                // Check Created File value
334:                assertTrue(nfnlso.txtCreatedFile().getText().endsWith(
335:                        createdFile));
336:                // Check Interface File value
337:                assertTrue(getTextFieldContent(CREATED_FILE_TEXT_FIELD, nfnlso)
338:                        .endsWith(interfaceFile));
339:                // Check Description value
340:                assertEquals(mbean.getDescription(), getTextFieldContent(
341:                        MBEAN_DESCRIPTION_TEXT_FIELD, nfnlso));
342:
343:                // Check Class to Wrap if needed
344:                if (fileType.equals(FILE_TYPE_MBEAN_FROM_EXISTING_JAVA_CLASS)) {
345:                    assertEquals(mbean.getClassToWrap(), getTextFieldContent(
346:                            CLASS_TO_WRAP_TEXT_FIELD, nfnlso));
347:                    if (mbean.isObjectWrappedAsMXBean()) {
348:                        assertTrue(getCheckBoxOperator(
349:                                OBJECT_WRAPPED_AS_MXBEAN_CHECK_BOX, nfnlso)
350:                                .isSelected());
351:                    } else {
352:                        assertFalse(getCheckBoxOperator(
353:                                OBJECT_WRAPPED_AS_MXBEAN_CHECK_BOX, nfnlso)
354:                                .isSelected());
355:                    }
356:                }
357:            }
358:
359:            /**
360:             * Check name and location wizard warnings :
361:             * - unknown class to wrap
362:             * - default package
363:             */
364:            private void checkNameAndLocationWizardWarnings(
365:                    NewFileNameLocationStepOperator nfnlso, String fileType) {
366:
367:                JLabel jl = null;
368:
369:                // Check class to wrap warning message
370:                // This message precedes the default package warning message
371:                if (fileType.equals(FILE_TYPE_MBEAN_FROM_EXISTING_JAVA_CLASS)) {
372:                    // Set the class to wrap to empty string
373:                    setTextFieldContent(CLASS_TO_WRAP_TEXT_FIELD, nfnlso, "");
374:                    // Check warning message is displayed
375:                    jl = getLabel(SPECIFY_CLASS_TO_WRAP_WARNING, nfnlso
376:                            .getContentPane());
377:                    assertNotNull(jl);
378:                    // Check next and finish buttons are disabled
379:                    assertFalse(nfnlso.btFinish().isEnabled());
380:                    assertFalse(nfnlso.btNext().isEnabled());
381:                    // Set the class to unknown java class
382:                    setTextFieldContent(CLASS_TO_WRAP_TEXT_FIELD, nfnlso,
383:                            PACKAGE_COM_FOO_BAR + ".UnknownJavaClass");
384:                    // Check warning message is displayed
385:                    jl = getLabel(CLASS_TO_WRAP_DOES_NOT_EXIST_WARNING, nfnlso
386:                            .getContentPane());
387:                    assertNotNull(jl);
388:                    // Check next and finish buttons are disabled
389:                    assertFalse(nfnlso.btFinish().isEnabled());
390:                    assertFalse(nfnlso.btNext().isEnabled());
391:                    // Set the class to empty java class
392:                    setTextFieldContent(CLASS_TO_WRAP_TEXT_FIELD, nfnlso,
393:                            PACKAGE_COM_FOO_BAR + "." + EMPTY_JAVA_CLASS_NAME);
394:                    // Check warning messages are not displayed anymore
395:                    jl = getLabel(SPECIFY_CLASS_TO_WRAP_WARNING, nfnlso
396:                            .getContentPane());
397:                    assertNull(jl);
398:                    jl = getLabel(CLASS_TO_WRAP_DOES_NOT_EXIST_WARNING, nfnlso
399:                            .getContentPane());
400:                    assertNull(jl);
401:                    // Check next button is not disabled anymore
402:                    assertTrue(nfnlso.btNext().isEnabled());
403:                }
404:
405:                // Check default package warning message
406:                // Set the package to empty string
407:                nfnlso.setPackage("");
408:                // Check warning message is displayed
409:                jl = getLabel(DEFAULT_PACKAGE_WARNING, nfnlso.getContentPane());
410:                assertNotNull(jl);
411:                // Set the package to com.foo.bar
412:                nfnlso.setPackage(PACKAGE_COM_FOO_BAR);
413:                // Check warning message is not displayed anymore
414:                jl = getLabel(DEFAULT_PACKAGE_WARNING, nfnlso.getContentPane());
415:                assertNull(jl);
416:            }
417:
418:            /**
419:             * Update name and location wizard values
420:             */
421:            private void updateNameAndLocationWizardValues(
422:                    NewFileNameLocationStepOperator nfnlso, String fileType,
423:                    MBean mbean) {
424:
425:                nfnlso.setObjectName(mbean.getName());
426:                nfnlso.setPackage(mbean.getPackage());
427:                setTextFieldContent(MBEAN_DESCRIPTION_TEXT_FIELD, nfnlso, mbean
428:                        .getDescription());
429:                if (fileType.equals(FILE_TYPE_MBEAN_FROM_EXISTING_JAVA_CLASS)) {
430:                    setTextFieldContent(CLASS_TO_WRAP_TEXT_FIELD, nfnlso, mbean
431:                            .getClassToWrap());
432:                    setCheckBoxSelection(OBJECT_WRAPPED_AS_MXBEAN_CHECK_BOX,
433:                            nfnlso, mbean.isObjectWrappedAsMXBean());
434:                }
435:            }
436:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.