Source Code Cross Referenced for StandardMBeanTest.java in  » JMX » mx4j » test » javax » management » 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 » JMX » mx4j » test.javax.management 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) The MX4J Contributors.
003:         * All rights reserved.
004:         *
005:         * This software is distributed under the terms of the MX4J License version 1.0.
006:         * See the terms of the MX4J License in the documentation provided with this software.
007:         */
008:
009:        package test.javax.management;
010:
011:        import javax.management.MBeanInfo;
012:        import javax.management.MBeanServer;
013:        import javax.management.NotCompliantMBeanException;
014:        import javax.management.ObjectName;
015:        import javax.management.ReflectionException;
016:        import javax.management.StandardMBean;
017:
018:        import test.MX4JTestCase;
019:        import test.javax.management.support.StandardMBeanSupport;
020:
021:        /**
022:         * @version $Revision: 1.7 $
023:         */
024:        public class StandardMBeanTest extends MX4JTestCase {
025:            public StandardMBeanTest(String s) {
026:                super (s);
027:            }
028:
029:            public void testInvalidStandardMBean() throws Exception {
030:                try {
031:                    new StandardMBean(null, null);
032:                    fail("Implementation cannot be null");
033:                } catch (IllegalArgumentException x) {
034:                }
035:
036:                try {
037:                    Object impl = new Object();
038:                    new StandardMBean(impl, null);
039:                    fail(impl.getClass().getName()
040:                            + " is not a compliant MBean");
041:                } catch (NotCompliantMBeanException x) {
042:                }
043:
044:                try {
045:                    Object impl = new Object();
046:                    Class mgmt = Cloneable.class;
047:                    new StandardMBean(impl, mgmt);
048:                    fail(impl.getClass().getName() + " does not implement "
049:                            + mgmt.getName());
050:                } catch (NotCompliantMBeanException x) {
051:                }
052:
053:                try {
054:                    Object impl = new Object();
055:                    Class mgmt = Object.class;
056:                    new StandardMBean(impl, mgmt);
057:                    fail("Class " + mgmt.getName() + " is not an interface");
058:                } catch (NotCompliantMBeanException x) {
059:                }
060:
061:                try {
062:                    new StandardMBeanSupport.SubclassNotCompliant();
063:                    fail("StandardMBean is not compliant");
064:                } catch (NotCompliantMBeanException x) {
065:                }
066:            }
067:
068:            public void testSubclassWithNoManagement() throws Exception {
069:                StandardMBean mbean = new StandardMBeanSupport.SubclassWithNoManagement();
070:                testNoManagement(mbean);
071:            }
072:
073:            public void testSubclassWithManagement() throws Exception {
074:                StandardMBean mbean = new StandardMBeanSupport.SubclassWithManagement();
075:                testManagement(mbean);
076:            }
077:
078:            public void testImplementationWithNoManagement() throws Exception {
079:                StandardMBean mbean = new StandardMBean(
080:                        new StandardMBeanSupport.ImplementationWithNoManagement(),
081:                        null);
082:                testNoManagement(mbean);
083:            }
084:
085:            public void testImplementationWithManagement() throws Exception {
086:                StandardMBean mbean = new StandardMBean(
087:                        new StandardMBeanSupport.ImplementationWithManagement(),
088:                        StandardMBeanSupport.Management.class);
089:                testManagement(mbean);
090:            }
091:
092:            private void testNoManagement(Object mbean) throws Exception {
093:                MBeanServer server = newMBeanServer();
094:                ObjectName name = ObjectName
095:                        .getInstance(":type=subclass,management=no");
096:                server.registerMBean(mbean, name);
097:                Object result = server.invoke(name, "test", null, null);
098:                assertNotNull(result);
099:            }
100:
101:            private void testManagement(Object mbean) throws Exception {
102:                MBeanServer server = newMBeanServer();
103:                ObjectName name = ObjectName
104:                        .getInstance(":type=subclass,management=yes");
105:                server.registerMBean(mbean, name);
106:                Object result = server.invoke(name, "test", null, null);
107:                assertNotNull(result);
108:                try {
109:                    server.invoke(name, "cannotCall", null, null);
110:                    fail("Cannot invoke a method not in the management interface");
111:                } catch (ReflectionException x) {
112:                }
113:            }
114:
115:            public void testMBeanInfoCaching() throws Exception {
116:                StandardMBean mbean = new StandardMBeanSupport.SubclassWithNoManagement();
117:                MBeanInfo original = mbean.getMBeanInfo();
118:
119:                // Make a second call and be sure it's cached
120:                MBeanInfo info = mbean.getMBeanInfo();
121:                if (info != original)
122:                    fail("MBeanInfo is not cached");
123:            }
124:
125:            public void testCallbacks() throws Exception {
126:                StandardMBeanSupport.CallbackCounter mbean = new StandardMBeanSupport.CallbackCounter(
127:                        0);
128:                // Trigger the callbacks
129:                mbean.getMBeanInfo();
130:                // There are 10 callbacks: the management interface has 1 attribute and 1 operation, so:
131:                // 1 -> class name of MBeanInfo
132:                // 2 -> description of MBeanInfo
133:                // 3 -> description of attribute
134:                // 6 -> description of constructor + parameter name + parameter description
135:                // 10 -> description of operation + parameter name + parameter description + operation impact
136:                assertEquals(mbean.getCount(), 10);
137:            }
138:
139:            public void testSetImplementation() throws Exception {
140:                StandardMBean mbean = new StandardMBeanSupport.SubclassWithManagement();
141:                mbean
142:                        .setImplementation(new StandardMBeanSupport.ImplementationWithManagement());
143:
144:                try {
145:                    mbean.setImplementation(new Object());
146:                    fail("New implementation does not implement the management interface "
147:                            + mbean.getMBeanInterface().getName());
148:                } catch (NotCompliantMBeanException x) {
149:                }
150:            }
151:
152:            public void testPublicManagementInterfaceWithPrivateImplementation()
153:                    throws Exception {
154:                // Tests whether a MBean is acceptable as long as the public interface is public
155:                // Checks compliance with p34 of JMX 1.2 specification
156:                StandardMBeanSupport.PublicInterfaceMBean mbean = StandardMBeanSupport
157:                        .createPublicInterfaceMBean();
158:                MBeanServer server = newMBeanServer();
159:                ObjectName name = ObjectName
160:                        .getInstance(":type=privateimplementation");
161:                server.registerMBean(mbean, name);
162:                Object result = server.invoke(name, "test", null, null);
163:                assertNotNull(result);
164:
165:                try {
166:                    name = ObjectName
167:                            .getInstance(":type=privateimplementation2");
168:                    server
169:                            .createMBean(
170:                                    "test.javax.management.support.StandardMBeanSupport$PublicInterface",
171:                                    name);
172:                    fail("Must not be able to create an MBean whose class is private");
173:                } catch (ReflectionException x) {
174:                    Exception xx = x.getTargetException();
175:                    assertTrue(xx instanceof  IllegalAccessException);
176:                }
177:            }
178:
179:            public void testIsInstanceOf() throws Exception {
180:                MBeanServer mbs = newMBeanServer();
181:
182:                StandardMBean smbone = new StandardMBean(
183:                        new StandardMBeanSupport.ImplementationWithManagement(),
184:                        StandardMBeanSupport.Management.class);
185:                ObjectName smbonename = new ObjectName(":type=implwmgmt");
186:                mbs.registerMBean(smbone, smbonename);
187:
188:                StandardMBean smbtwo = new StandardMBean(
189:                        new StandardMBeanSupport.CallbackCounter(42),
190:                        StandardMBeanSupport.FullManagement.class);
191:                ObjectName smbtwoname = new ObjectName(":type=cbcounter");
192:                mbs.registerMBean(smbtwo, smbtwoname);
193:
194:                assertTrue(mbs
195:                        .isInstanceOf(smbonename,
196:                                "test.javax.management.support.StandardMBeanSupport$Management"));
197:                assertTrue(mbs
198:                        .isInstanceOf(smbtwoname,
199:                                "test.javax.management.support.StandardMBeanSupport$FullManagement"));
200:            }
201:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.