Source Code Cross Referenced for ModelMBeanAssemblerTest.java in  » ESB » celtix-1.0 » org » objectweb » celtix » bus » management » jmx » export » 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 » ESB » celtix 1.0 » org.objectweb.celtix.bus.management.jmx.export 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.objectweb.celtix.bus.management.jmx.export;
002:
003:        import javax.management.Attribute;
004:        import javax.management.MBeanAttributeInfo;
005:        import javax.management.MBeanNotificationInfo;
006:        import javax.management.MBeanOperationInfo;
007:        import javax.management.MBeanServer;
008:        import javax.management.MBeanServerFactory;
009:        import javax.management.MalformedObjectNameException;
010:        import javax.management.ObjectName;
011:        import javax.management.modelmbean.ModelMBeanInfo;
012:        import javax.management.modelmbean.ModelMBeanOperationInfo;
013:        import javax.management.modelmbean.RequiredModelMBean;
014:
015:        import junit.framework.TestCase;
016:
017:        import org.objectweb.celtix.bus.management.jmx.export.runtime.ModelMBeanAssembler;
018:
019:        public class ModelMBeanAssemblerTest extends TestCase {
020:
021:            protected static final String AGE_ATTRIBUTE = "Age";
022:
023:            protected static final String NAME_ATTRIBUTE = "Name";
024:
025:            protected static AnnotationTestInstrumentation ati = new AnnotationTestInstrumentation();
026:
027:            protected MBeanServer server;
028:
029:            protected ObjectName ton;
030:
031:            public final void setUp() throws Exception {
032:                this .server = MBeanServerFactory.createMBeanServer();
033:                try {
034:                    onSetUp();
035:                } catch (Exception e) {
036:                    releaseServer();
037:                    throw e;
038:                }
039:            }
040:
041:            protected void tearDown() throws Exception {
042:                releaseServer();
043:                onTearDown();
044:            }
045:
046:            private void releaseServer() {
047:                MBeanServerFactory.releaseMBeanServer(this .getServer());
048:            }
049:
050:            protected void onTearDown() throws Exception {
051:                // unregister the mbean client
052:                server.unregisterMBean(ton);
053:            }
054:
055:            protected void onSetUp() throws Exception {
056:
057:                try {
058:                    ton = new ObjectName(
059:                            "org.objectweb.celtix:Type=testInstrumentation");
060:                } catch (MalformedObjectNameException e) {
061:                    e.printStackTrace();
062:                } catch (NullPointerException e) {
063:                    e.printStackTrace();
064:                }
065:
066:                //create the mbean and register it
067:                ModelMBeanInfo mbi = getMBeanInfoFromAssembler();
068:
069:                RequiredModelMBean rtMBean;
070:
071:                rtMBean = (RequiredModelMBean) server
072:                        .instantiate("javax.management.modelmbean.RequiredModelMBean");
073:
074:                rtMBean.setModelMBeanInfo(mbi);
075:
076:                rtMBean.setManagedResource(ati, "ObjectReference");
077:
078:                server.registerMBean(rtMBean, ton);
079:            }
080:
081:            public MBeanServer getServer() {
082:                return server;
083:            }
084:
085:            //the client get and set the ModelObject and setup the ManagerBean
086:
087:            public void testRegisterOperations() throws Exception {
088:                ModelMBeanInfo info = getMBeanInfoFromAssembler();
089:                assertEquals("Incorrect number of operations registered", 10,
090:                        info.getOperations().length);
091:            }
092:
093:            public void testGetMBeanInfo() throws Exception {
094:                ModelMBeanInfo info = getMBeanInfoFromAssembler();
095:                assertNotNull("MBeanInfo should not be null", info);
096:            }
097:
098:            public void testGetMBeanAttributeInfo() throws Exception {
099:                ModelMBeanInfo info = getMBeanInfoFromAssembler();
100:                MBeanAttributeInfo[] inf = info.getAttributes();
101:                assertEquals("Invalid number of Attributes returned", 4,
102:                        inf.length);
103:
104:                for (int x = 0; x < inf.length; x++) {
105:                    assertNotNull("MBeanAttributeInfo should not be null",
106:                            inf[x]);
107:                    assertNotNull(
108:                            "Description for MBeanAttributeInfo should not be null",
109:                            inf[x].getDescription());
110:                }
111:            }
112:
113:            public void testGetMBeanOperationInfo() throws Exception {
114:                ModelMBeanInfo info = getMBeanInfoFromAssembler();
115:                MBeanOperationInfo[] inf = info.getOperations();
116:                assertEquals("Invalid number of Operations returned", 10,
117:                        inf.length);
118:
119:                for (int x = 0; x < inf.length; x++) {
120:                    assertNotNull("MBeanOperationInfo should not be null",
121:                            inf[x]);
122:                    assertNotNull(
123:                            "Description for MBeanOperationInfo should not be null",
124:                            inf[x].getDescription());
125:                }
126:            }
127:
128:            public void testDescriptionNotNull() throws Exception {
129:                ModelMBeanInfo info = getMBeanInfoFromAssembler();
130:                assertNotNull("The MBean description should not be null", info
131:                        .getDescription());
132:            }
133:
134:            public void testSetAttribute() throws Exception {
135:                getServer().setAttribute(ton, new Attribute(AGE_ATTRIBUTE, 12));
136:                assertEquals("The Age should be ", 12, ati.getAge());
137:                getServer().setAttribute(ton,
138:                        new Attribute(NAME_ATTRIBUTE, "Rob Harrop"));
139:                assertEquals("The name should be ", "Rob Harrop", ati.getName());
140:            }
141:
142:            public void testGetAttribute() throws Exception {
143:                ati.setName("John Smith");
144:                Object val = getServer().getAttribute(ton, NAME_ATTRIBUTE);
145:                assertEquals("Incorrect result", "John Smith", val);
146:            }
147:
148:            public void testOperationInvocation() throws Exception {
149:                Object result = getServer().invoke(ton, "add",
150:                        new Object[] { new Integer(20), new Integer(30) },
151:                        new String[] { "int", "int" });
152:                assertEquals("Incorrect result", new Integer(50), result);
153:            }
154:
155:            public void testAttributeHasCorrespondingOperations()
156:                    throws Exception {
157:                ModelMBeanInfo info = getMBeanInfoFromAssembler();
158:
159:                ModelMBeanOperationInfo myOperation = info
160:                        .getOperation("myOperation");
161:                assertNotNull("get operation should not be null", myOperation);
162:                assertEquals("Incorrect myOperation return type", "long",
163:                        myOperation.getReturnType());
164:
165:                ModelMBeanOperationInfo add = info.getOperation("add");
166:                assertNotNull("set operation should not be null", add);
167:                assertEquals("Incorrect add method description",
168:                        "Add Two Numbers Together", add.getDescription());
169:
170:            }
171:
172:            public void testNotificationMetadata() throws Exception {
173:                ModelMBeanInfo info = getMBeanInfoFromAssembler();
174:                MBeanNotificationInfo[] notifications = info.getNotifications();
175:                assertEquals("Incorrect number of notifications", 1,
176:                        notifications.length);
177:                assertEquals("Incorrect notification name", "My Notification",
178:                        notifications[0].getName());
179:
180:                String[] notifTypes = notifications[0].getNotifTypes();
181:
182:                assertEquals("Incorrect number of notification types", 2,
183:                        notifTypes.length);
184:                assertEquals("Notification type.foo not found", "type.foo",
185:                        notifTypes[0]);
186:                assertEquals("Notification type.bar not found", "type.bar",
187:                        notifTypes[1]);
188:            }
189:
190:            protected ModelMBeanInfo getMBeanInfoFromAssembler() {
191:                ModelMBeanAssembler assembler = new ModelMBeanAssembler();
192:                return assembler
193:                        .getModelMbeanInfo(AnnotationTestInstrumentation.class);
194:            }
195:
196:        }
w__w__w__._j___av_a_2__s___.c_om___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.