Source Code Cross Referenced for ModelMBeanAssemblerTest.java in  » Web-Services-apache-cxf-2.0.1 » management » org » apache » cxf » 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 » Web Services apache cxf 2.0.1 » management » org.apache.cxf.management.jmx.export 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements. See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership. The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License. You may obtain a copy of the License at
009:         *
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied. See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.
018:         */package org.apache.cxf.management.jmx.export;
019:
020:        import javax.management.Attribute;
021:        import javax.management.MBeanAttributeInfo;
022:        import javax.management.MBeanNotificationInfo;
023:        import javax.management.MBeanOperationInfo;
024:        import javax.management.MBeanServer;
025:        import javax.management.MBeanServerFactory;
026:        import javax.management.MalformedObjectNameException;
027:        import javax.management.ObjectName;
028:        import javax.management.modelmbean.ModelMBeanInfo;
029:        import javax.management.modelmbean.ModelMBeanOperationInfo;
030:        import javax.management.modelmbean.RequiredModelMBean;
031:
032:        import org.apache.cxf.management.jmx.export.runtime.ModelMBeanAssembler;
033:        import org.junit.After;
034:        import org.junit.Assert;
035:        import org.junit.Before;
036:        import org.junit.Test;
037:
038:        public class ModelMBeanAssemblerTest extends Assert {
039:
040:            protected static final String AGE_ATTRIBUTE = "Age";
041:
042:            protected static final String NAME_ATTRIBUTE = "Name";
043:
044:            protected static AnnotationTestInstrumentation ati = new AnnotationTestInstrumentation();
045:
046:            protected MBeanServer server;
047:
048:            protected ObjectName ton;
049:
050:            @Before
051:            public final void setUp() throws Exception {
052:                this .server = MBeanServerFactory.createMBeanServer();
053:                try {
054:                    onSetUp();
055:                } catch (Exception e) {
056:                    releaseServer();
057:                    throw e;
058:                }
059:            }
060:
061:            @After
062:            public void tearDown() throws Exception {
063:                releaseServer();
064:                onTearDown();
065:            }
066:
067:            private void releaseServer() {
068:                MBeanServerFactory.releaseMBeanServer(this .getServer());
069:            }
070:
071:            protected void onTearDown() throws Exception {
072:                // unregister the mbean client
073:                server.unregisterMBean(ton);
074:            }
075:
076:            protected void onSetUp() throws Exception {
077:
078:                try {
079:                    ton = new ObjectName(
080:                            "org.apache.cxf:Type=testInstrumentation");
081:                } catch (MalformedObjectNameException e) {
082:                    e.printStackTrace();
083:                } catch (NullPointerException e) {
084:                    e.printStackTrace();
085:                }
086:
087:                //create the mbean and register it
088:                ModelMBeanInfo mbi = getMBeanInfoFromAssembler();
089:
090:                RequiredModelMBean rtMBean;
091:
092:                rtMBean = (RequiredModelMBean) server
093:                        .instantiate("javax.management.modelmbean.RequiredModelMBean");
094:
095:                rtMBean.setModelMBeanInfo(mbi);
096:
097:                rtMBean.setManagedResource(ati, "ObjectReference");
098:
099:                server.registerMBean(rtMBean, ton);
100:            }
101:
102:            public MBeanServer getServer() {
103:                return server;
104:            }
105:
106:            //the client get and set the ModelObject and setup the ManagerBean
107:            @Test
108:            public void testRegisterOperations() throws Exception {
109:                ModelMBeanInfo info = getMBeanInfoFromAssembler();
110:                assertEquals("Incorrect number of operations registered", 10,
111:                        info.getOperations().length);
112:            }
113:
114:            @Test
115:            public void testGetMBeanInfo() throws Exception {
116:                ModelMBeanInfo info = getMBeanInfoFromAssembler();
117:                assertNotNull("MBeanInfo should not be null", info);
118:            }
119:
120:            @Test
121:            public void testGetMBeanAttributeInfo() throws Exception {
122:                ModelMBeanInfo info = getMBeanInfoFromAssembler();
123:                MBeanAttributeInfo[] inf = info.getAttributes();
124:                assertEquals("Invalid number of Attributes returned", 4,
125:                        inf.length);
126:
127:                for (int x = 0; x < inf.length; x++) {
128:                    assertNotNull("MBeanAttributeInfo should not be null",
129:                            inf[x]);
130:                    assertNotNull(
131:                            "Description for MBeanAttributeInfo should not be null",
132:                            inf[x].getDescription());
133:                }
134:            }
135:
136:            @Test
137:            public void testGetMBeanOperationInfo() throws Exception {
138:                ModelMBeanInfo info = getMBeanInfoFromAssembler();
139:                MBeanOperationInfo[] inf = info.getOperations();
140:                assertEquals("Invalid number of Operations returned", 10,
141:                        inf.length);
142:
143:                for (int x = 0; x < inf.length; x++) {
144:                    assertNotNull("MBeanOperationInfo should not be null",
145:                            inf[x]);
146:                    assertNotNull(
147:                            "Description for MBeanOperationInfo should not be null",
148:                            inf[x].getDescription());
149:                }
150:            }
151:
152:            @Test
153:            public void testDescriptionNotNull() throws Exception {
154:                ModelMBeanInfo info = getMBeanInfoFromAssembler();
155:                assertNotNull("The MBean description should not be null", info
156:                        .getDescription());
157:            }
158:
159:            @Test
160:            public void testSetAttribute() throws Exception {
161:                getServer().setAttribute(ton, new Attribute(AGE_ATTRIBUTE, 12));
162:                assertEquals("The Age should be ", 12, ati.getAge());
163:                getServer().setAttribute(ton,
164:                        new Attribute(NAME_ATTRIBUTE, "Rob Harrop"));
165:                assertEquals("The name should be ", "Rob Harrop", ati.getName());
166:            }
167:
168:            @Test
169:            public void testGetAttribute() throws Exception {
170:                ati.setName("John Smith");
171:                Object val = getServer().getAttribute(ton, NAME_ATTRIBUTE);
172:                assertEquals("Incorrect result", "John Smith", val);
173:            }
174:
175:            @Test
176:            public void testOperationInvocation() throws Exception {
177:                Object result = getServer().invoke(ton, "add",
178:                        new Object[] { new Integer(20), new Integer(30) },
179:                        new String[] { "int", "int" });
180:                assertEquals("Incorrect result", new Integer(50), result);
181:            }
182:
183:            @Test
184:            public void testAttributeHasCorrespondingOperations()
185:                    throws Exception {
186:                ModelMBeanInfo info = getMBeanInfoFromAssembler();
187:
188:                ModelMBeanOperationInfo myOperation = info
189:                        .getOperation("myOperation");
190:                assertNotNull("get operation should not be null", myOperation);
191:                assertEquals("Incorrect myOperation return type", "long",
192:                        myOperation.getReturnType());
193:
194:                ModelMBeanOperationInfo add = info.getOperation("add");
195:                assertNotNull("set operation should not be null", add);
196:                assertEquals("Incorrect add method description",
197:                        "Add Two Numbers Together", add.getDescription());
198:
199:            }
200:
201:            @Test
202:            public void testNotificationMetadata() throws Exception {
203:                ModelMBeanInfo info = getMBeanInfoFromAssembler();
204:                MBeanNotificationInfo[] notifications = info.getNotifications();
205:                assertEquals("Incorrect number of notifications", 1,
206:                        notifications.length);
207:                assertEquals("Incorrect notification name", "My Notification",
208:                        notifications[0].getName());
209:
210:                String[] notifTypes = notifications[0].getNotifTypes();
211:
212:                assertEquals("Incorrect number of notification types", 2,
213:                        notifTypes.length);
214:                assertEquals("Notification type.foo not found", "type.foo",
215:                        notifTypes[0]);
216:                assertEquals("Notification type.bar not found", "type.bar",
217:                        notifTypes[1]);
218:            }
219:
220:            protected ModelMBeanInfo getMBeanInfoFromAssembler() {
221:                ModelMBeanAssembler assembler = new ModelMBeanAssembler();
222:                return assembler
223:                        .getModelMbeanInfo(AnnotationTestInstrumentation.class);
224:            }
225:
226:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.