Source Code Cross Referenced for TestEventNotifier.java in  » ESB » open-esb » com » sun » jbi » management » facade » 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 » open esb » com.sun.jbi.management.facade 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * BEGIN_HEADER - DO NOT EDIT
003:         *
004:         * The contents of this file are subject to the terms
005:         * of the Common Development and Distribution License
006:         * (the "License").  You may not use this file except
007:         * in compliance with the License.
008:         *
009:         * You can obtain a copy of the license at
010:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011:         * See the License for the specific language governing
012:         * permissions and limitations under the License.
013:         *
014:         * When distributing Covered Code, include this CDDL
015:         * HEADER in each file and include the License file at
016:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017:         * If applicable add the following below this CDDL HEADER,
018:         * with the fields enclosed by brackets "[]" replaced with
019:         * your own identifying information: Portions Copyright
020:         * [year] [name of copyright owner]
021:         */
022:
023:        /*
024:         * @(#)TestEventNotifier.java
025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026:         *
027:         * END_HEADER - DO NOT EDIT
028:         */
029:
030:        package com.sun.jbi.management.facade;
031:
032:        import com.sun.jbi.EnvironmentContext;
033:        import com.sun.jbi.platform.PlatformContext;
034:        import com.sun.jbi.management.EventNotifierMBean;
035:        import com.sun.jbi.management.system.ScaffoldedEnvironmentContext;
036:        import com.sun.jbi.management.system.ScaffoldPlatformContext;
037:
038:        import javax.management.MBeanNotificationInfo;
039:        import javax.management.MBeanServer;
040:        import javax.management.Notification;
041:        import javax.management.ObjectName;
042:        import javax.management.StandardMBean;
043:
044:        /**
045:         * Tests for EventNotifier.
046:         *
047:         * @author Mark S White
048:         */
049:        public class TestEventNotifier extends junit.framework.TestCase {
050:            /**
051:             * Current test name.
052:             */
053:            private String mTestName;
054:
055:            /**
056:             * Local handle to the EnvironmentContext
057:             */
058:            private EnvironmentContext mContext;
059:
060:            /**
061:             * Local handle to the PlatformContext
062:             */
063:            private PlatformContext mPlatform;
064:
065:            /**
066:             * Instance of EventNotifier.
067:             */
068:            private EventNotifier mEventNotifier;
069:
070:            /**
071:             * MBean object name for EventNotifier
072:             */
073:            private ObjectName mMBeanName;
074:
075:            /**
076:             * The constructor for this testcase, forwards the test name to
077:             * the jUnit TestCase base class.
078:             * @param aTestName String with the name of this test.
079:             */
080:            public TestEventNotifier(String aTestName) {
081:                super (aTestName);
082:            }
083:
084:            /**
085:             * Setup for the test. This creates the EventNotifier instance
086:             * and other objects needed for the tests.
087:             * @throws Exception when set up fails for any reason.
088:             */
089:            public void setUp() throws Exception {
090:                super .setUp();
091:                System.err.println("***** START of test " + mTestName);
092:
093:                // Set up scaffolded Environment and Platform contexts
094:
095:                mContext = new ScaffoldedEnvironmentContext();
096:                mPlatform = mContext.getPlatformContext();
097:
098:                // Set up EventNotifier instance and register it as an MBean
099:
100:                mEventNotifier = new EventNotifier(mContext, "domain");
101:                StandardMBean mbean = null;
102:                try {
103:                    mbean = new StandardMBean(mEventNotifier,
104:                            EventNotifierMBean.class);
105:                } catch (javax.management.NotCompliantMBeanException ex) {
106:                    fail("Unable to create EventNotifier MBean: " + ex);
107:                }
108:                try {
109:                    mMBeanName = new ObjectName("com.sun.jbi:Type=Notification");
110:                } catch (javax.management.MalformedObjectNameException ex) {
111:                    fail("Unable to create ObjectName for EventNotifier MBean: "
112:                            + ex);
113:                }
114:                MBeanServer mbs = mContext.getMBeanServer();
115:                try {
116:                    mbs.registerMBean(mbean, mMBeanName);
117:                } catch (Throwable ex) {
118:                    fail("Unable to register EventNotifier MBean: " + ex);
119:                }
120:            }
121:
122:            /**
123:             * Cleanup for the test.
124:             * @throws Exception when tearDown fails for any reason.
125:             */
126:            public void tearDown() throws Exception {
127:                super .tearDown();
128:                MBeanServer mbs = mContext.getMBeanServer();
129:                try {
130:                    mbs.unregisterMBean(mMBeanName);
131:                } catch (javax.management.InstanceNotFoundException infEx) {
132:                    ; // Just ignore this error
133:                } catch (javax.management.MBeanRegistrationException mbrEx) {
134:                    fail("Unable to unregister EventNotifier MBean: " + mbrEx);
135:                }
136:                System.err.println("***** END of test " + mTestName);
137:            }
138:
139:            // =============================  test methods ================================
140:
141:            /**
142:             * Tests getNotificationInfo.
143:             * @throws Exception if an unexpected error occurs.
144:             */
145:            public void testGetNotificationInfo() {
146:                // Get the notification info for this MBean
147:
148:                MBeanNotificationInfo[] info = mEventNotifier
149:                        .getNotificationInfo();
150:                String[] types = info[0].getNotifTypes();
151:                String name = info[0].getName();
152:                String desc = info[0].getDescription();
153:
154:                // Verify that the notification info is correct
155:
156:                assertEquals(
157:                        "Got more than one MBeanNotificationInfo, expected one: ",
158:                        1, info.length);
159:                assertEquals("Got wrong number of notification types: ",
160:                        mEventNotifier.NOTIFICATION_TYPES.length, types.length);
161:                assertEquals("Got wrong class name: ",
162:                        mEventNotifier.NOTIFICATION_CLASS_NAME, name);
163:                assertEquals("Got wrong description: ",
164:                        mEventNotifier.NOTIFICATION_DESCRIPTION, desc);
165:            }
166:
167:            /**
168:             * Tests enableNotifications/disableNotifications.
169:             * @throws Exception if an unexpected error occurs.
170:             */
171:            public void testEnableDisableNotifications() {
172:                // Notifications default to enabled. Attempt to enable them again,
173:                // this should return a false result as nothing changed.
174:
175:                assertFalse("Error, notifications should already be enabled",
176:                        mEventNotifier.enableNotifications());
177:
178:                // Now disable notifications, this should return true.
179:
180:                assertTrue("Error, notifications should have been disabled",
181:                        mEventNotifier.disableNotifications());
182:
183:                // Now disable notifications again, this should return false.
184:
185:                assertFalse("Error, notifications should already be disabled",
186:                        mEventNotifier.disableNotifications());
187:
188:                // Now enable notifications again, this should return true.
189:
190:                assertTrue("Error, notifications should have been enabled",
191:                        mEventNotifier.enableNotifications());
192:            }
193:
194:            /**
195:             * Tests instanceStarted / instanceStopped.
196:             * @throws Exception if an unexpected error occurs.
197:             */
198:            public void testInstanceStartedStopped() {
199:                String instance = "server";
200:
201:                // Attempt instanceStopped with no instance active. This should
202:                // return false.
203:
204:                assertFalse("Error, instance should not be defined",
205:                        mEventNotifier.instanceStopped(instance, mMBeanName));
206:
207:                // Attempt instanceStarted with no instance active. This should
208:                // return true.
209:
210:                assertTrue("Error, instance should have been added",
211:                        mEventNotifier.instanceStarted(instance, mMBeanName));
212:
213:                // Attempt instanceStarted with the instance already active. This should
214:                // return false.
215:
216:                assertFalse("Error, instance should already be active",
217:                        mEventNotifier.instanceStarted(instance, mMBeanName));
218:
219:                // Attempt instanceStopped with the instance active. This should
220:                // return true.
221:
222:                assertTrue("Error, instance should have been removed",
223:                        mEventNotifier.instanceStopped(instance, mMBeanName));
224:            }
225:
226:            /**
227:             * Tests handleNotification.
228:             * @throws Exception if an unexpected error occurs.
229:             */
230:            public void testHandleNotification() {
231:                String type = "com.sun.jbi.event";
232:                long seq = 12345;
233:                String msg = "This is a notification";
234:                Notification notif = new Notification(type, mMBeanName, seq,
235:                        msg);
236:                String handBack = "server";
237:
238:                // Call the handler. There's really no way to check for a failure
239:                // other than the fact that no exception occurs.
240:                mEventNotifier.handleNotification(notif, handBack);
241:            }
242:
243:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.