Source Code Cross Referenced for StandardMBeanTEST.java in  » EJB-Server-JBoss-4.2.1 » jmx » test » compliance » standard » 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 » EJB Server JBoss 4.2.1 » jmx » test.compliance.standard 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JBoss, Home of Professional Open Source.
003:         * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004:         * as indicated by the @author tags. See the copyright.txt file in the
005:         * distribution for a full listing of individual contributors.
006:         *
007:         * This is free software; you can redistribute it and/or modify it
008:         * under the terms of the GNU Lesser General Public License as
009:         * published by the Free Software Foundation; either version 2.1 of
010:         * the License, or (at your option) any later version.
011:         *
012:         * This software is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this software; if not, write to the Free
019:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021:         */
022:        package test.compliance.standard;
023:
024:        import javax.management.MBeanInfo;
025:        import javax.management.MBeanAttributeInfo;
026:        import javax.management.MBeanConstructorInfo;
027:        import javax.management.MBeanOperationInfo;
028:        import javax.management.MBeanParameterInfo;
029:        import javax.management.MBeanServer;
030:        import javax.management.MBeanServerFactory;
031:        import javax.management.NotCompliantMBeanException;
032:        import javax.management.ObjectName;
033:        import javax.management.StandardMBean;
034:
035:        import junit.framework.TestCase;
036:
037:        import test.compliance.standard.support.ArbitraryInterface;
038:        import test.compliance.standard.support.MBeanRunnable;
039:        import test.compliance.standard.support.MyRunnable;
040:        import test.compliance.standard.support.MyStandardMBean;
041:        import test.compliance.standard.support.NoConstructorsStandardMBean;
042:        import test.compliance.standard.support.Trivial;
043:        import test.compliance.standard.support.TrivialMBean;
044:
045:        /**
046:         * @author  <a href="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>.
047:         */
048:
049:        public class StandardMBeanTEST extends TestCase {
050:            public StandardMBeanTEST(String s) {
051:                super (s);
052:            }
053:
054:            public void testOverrideManagementInterface() throws Exception {
055:                MBeanServer server = MBeanServerFactory.newMBeanServer();
056:                ObjectName name = new ObjectName("test:test=test");
057:                server.registerMBean(new MBeanRunnable(), name);
058:                server.invoke(name, "run", new Object[0], new String[0]);
059:            }
060:
061:            public void testSpecifyManagementInterface() throws Exception {
062:                MBeanServer server = MBeanServerFactory.newMBeanServer();
063:                ObjectName name = new ObjectName("test:test=test");
064:                server.registerMBean(new StandardMBean(new MyRunnable(),
065:                        Runnable.class), name);
066:                server.invoke(name, "run", new Object[0], new String[0]);
067:            }
068:
069:            public void testDontSpecifyManagementInterface() throws Exception {
070:                MBeanServer server = MBeanServerFactory.newMBeanServer();
071:                ObjectName name = new ObjectName("test:test=test");
072:                server.registerMBean(new StandardMBean(new Trivial(), null),
073:                        name);
074:                server.invoke(name, "doOperation", new Object[] { "arg" },
075:                        new String[] { String.class.getName() });
076:            }
077:
078:            public void testGetImplementationImplied() throws Exception {
079:                StandardMBean std = new MBeanRunnable();
080:                assertTrue("MBeanRunnable is its own implementation",
081:                        std == std.getImplementation());
082:                assertTrue("MBeanRunnable is its own implementation class", std
083:                        .getClass() == std.getImplementationClass());
084:            }
085:
086:            public void testGetImplementationSpecified() throws Exception {
087:                Object obj = new MyRunnable();
088:                StandardMBean std = new StandardMBean(obj, Runnable.class);
089:                assertTrue("MyRunnable is the implementation", obj == std
090:                        .getImplementation());
091:                assertTrue("MyRunnable is the implementation class", obj
092:                        .getClass() == std.getImplementationClass());
093:            }
094:
095:            public void testMBeanInterfaceImplied() throws Exception {
096:                StandardMBean std = new MBeanRunnable();
097:                assertTrue(
098:                        "MBeanRunnable has Runnable as a management interface",
099:                        Runnable.class == std.getMBeanInterface());
100:            }
101:
102:            public void testMBeanInterfaceSpecified() throws Exception {
103:                Object obj = new MyRunnable();
104:                StandardMBean std = new StandardMBean(obj, Runnable.class);
105:                assertTrue("MyRunnable has Runnable as a management interface",
106:                        Runnable.class == std.getMBeanInterface());
107:            }
108:
109:            public void testMBeanInterfaceOldStyle() throws Exception {
110:                Object obj = new Trivial();
111:                StandardMBean std = new StandardMBean(obj, null);
112:                assertTrue(
113:                        "Trivial has TrivialMBean as a management interface",
114:                        TrivialMBean.class == std.getMBeanInterface());
115:            }
116:
117:            public void testMetaData() throws Exception {
118:                StandardMBean std = new MyStandardMBean();
119:                MBeanInfo info = std.getMBeanInfo();
120:                assertEquals(MyStandardMBean.MBEAN_CLASSNAME, info
121:                        .getClassName());
122:                assertEquals(MyStandardMBean.MBEAN_DESCRIPTION, info
123:                        .getDescription());
124:
125:                MBeanAttributeInfo[] attributes = info.getAttributes();
126:                assertEquals(attributes.length, 1);
127:                assertEquals(MyStandardMBean.MBEAN_ATTRIBUTE_DESCRIPTION
128:                        + "AnAttribute", attributes[0].getDescription());
129:
130:                MBeanConstructorInfo[] constructors = info.getConstructors();
131:                assertEquals(constructors.length, 2);
132:                for (int i = 0; i < 2; i++) {
133:                    if (constructors[i].getSignature().length == 0)
134:                        assertEquals(
135:                                MyStandardMBean.MBEAN_CONSTRUCTOR_DESCRIPTION
136:                                        + "0", constructors[i].getDescription());
137:                    else {
138:                        assertEquals(
139:                                MyStandardMBean.MBEAN_CONSTRUCTOR_DESCRIPTION
140:                                        + "2", constructors[i].getDescription());
141:                        MBeanParameterInfo[] params = constructors[i]
142:                                .getSignature();
143:                        assertEquals(params.length, 2);
144:                        assertEquals(MyStandardMBean.MBEAN_PARAMETER + "0",
145:                                params[0].getName());
146:                        assertEquals(MyStandardMBean.MBEAN_PARAMETER + "1",
147:                                params[1].getName());
148:                        assertEquals(
149:                                MyStandardMBean.MBEAN_PARAMETER_DESCRIPTION
150:                                        + "0", params[0].getDescription());
151:                        assertEquals(
152:                                MyStandardMBean.MBEAN_PARAMETER_DESCRIPTION
153:                                        + "1", params[1].getDescription());
154:                    }
155:                }
156:
157:                MBeanOperationInfo[] operations = info.getOperations();
158:                assertEquals(operations.length, 1);
159:                assertEquals(MyStandardMBean.MBEAN_OPERATION_DESCRIPTION
160:                        + "anOperation", operations[0].getDescription());
161:                MBeanParameterInfo[] params = operations[0].getSignature();
162:                assertEquals(params.length, 2);
163:                assertEquals(MyStandardMBean.MBEAN_PARAMETER + "anOperation0",
164:                        params[0].getName());
165:                assertEquals(MyStandardMBean.MBEAN_PARAMETER + "anOperation1",
166:                        params[1].getName());
167:                assertEquals(MyStandardMBean.MBEAN_PARAMETER_DESCRIPTION
168:                        + "anOperation0", params[0].getDescription());
169:                assertEquals(MyStandardMBean.MBEAN_PARAMETER_DESCRIPTION
170:                        + "anOperation1", params[1].getDescription());
171:                assertEquals(MBeanOperationInfo.ACTION, operations[0]
172:                        .getImpact());
173:            }
174:
175:            public void testNoConstructorsMetaData() throws Exception {
176:                StandardMBean std = new NoConstructorsStandardMBean();
177:                MBeanInfo info = std.getMBeanInfo();
178:
179:                MBeanConstructorInfo[] constructors = info.getConstructors();
180:                assertEquals(constructors.length, 0);
181:            }
182:
183:            public void testCaching() throws Exception {
184:                StandardMBean std = new MyStandardMBean();
185:                MBeanInfo info = std.getMBeanInfo();
186:                assertTrue("MBeanInfo should be cached", info == std
187:                        .getMBeanInfo());
188:            }
189:
190:            public void testErrors() throws Exception {
191:                boolean caught = false;
192:                try {
193:                    new StandardMBean(null, Runnable.class);
194:                } catch (IllegalArgumentException e) {
195:                    caught = true;
196:                }
197:                assertTrue(
198:                        "Expected IllegalArgumentException for null implementation",
199:                        caught);
200:
201:                caught = false;
202:                try {
203:                    new StandardMBean(new MyRunnable(),
204:                            ArbitraryInterface.class);
205:                } catch (NotCompliantMBeanException e) {
206:                    caught = true;
207:                }
208:                assertTrue(
209:                        "Expected NotCompliantMBeanException for the wrong management interface",
210:                        caught);
211:
212:                caught = false;
213:                try {
214:                    new StandardMBean(new MyRunnable(), null);
215:                } catch (NotCompliantMBeanException e) {
216:                    caught = true;
217:                }
218:                assertTrue(
219:                        "Expected NotCompliantMBeanException for null management interface",
220:                        caught);
221:
222:                caught = false;
223:                try {
224:                    MBeanServer server = MBeanServerFactory.newMBeanServer();
225:                    ObjectName name = new ObjectName("test:test=test");
226:                    server.registerMBean(new MBeanRunnable(true), name);
227:                } catch (NotCompliantMBeanException e) {
228:                    caught = true;
229:                }
230:                assertTrue(
231:                        "Expected NotCompliantMBeanException for wrong management interface",
232:                        caught);
233:
234:                caught = false;
235:                try {
236:                    MBeanServer server = MBeanServerFactory.newMBeanServer();
237:                    ObjectName name = new ObjectName("test:test=test");
238:                    server.registerMBean(new MBeanRunnable(0), name);
239:                } catch (NotCompliantMBeanException e) {
240:                    caught = true;
241:                }
242:                assertTrue(
243:                        "Expected NotCompliantMBeanException for null management interface",
244:                        caught);
245:            }
246:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.