Source Code Cross Referenced for TestEventNotifier.java in  » ESB » open-esb » com » sun » jbi » framework » 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.framework 
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.framework;
031:
032:        import javax.management.MBeanNotificationInfo;
033:        import javax.management.Notification;
034:        import javax.management.openmbean.CompositeData;
035:
036:        /**
037:         * Tests for EventNotifier.
038:         *
039:         * @author Mark S White
040:         */
041:        public class TestEventNotifier extends junit.framework.TestCase {
042:            /**
043:             * Current test name.
044:             */
045:            private String mTestName;
046:
047:            /**
048:             * Local handle to the EnvironmentContext
049:             */
050:            private EnvironmentContext mContext;
051:
052:            /**
053:             * The EnvironmentSetup helper class
054:             */
055:            private EnvironmentSetup mSetup;
056:
057:            /**
058:             * Instance of EventNotifier.
059:             */
060:            private EventNotifier mEventNotifier;
061:
062:            /**
063:             * The constructor for this testcase, forwards the test name to
064:             * the jUnit TestCase base class.
065:             * @param aTestName String with the name of this test.
066:             */
067:            public TestEventNotifier(String aTestName) {
068:                super (aTestName);
069:            }
070:
071:            /**
072:             * Setup for the test. This creates the EventNotifier instance
073:             * and other objects needed for the tests.
074:             * @throws Exception when set up fails for any reason.
075:             */
076:            public void setUp() throws Exception {
077:                super .setUp();
078:                System.err.println("***** START of test " + mTestName);
079:
080:                // Create EnvironmentContext
081:
082:                mSetup = new EnvironmentSetup();
083:                mContext = mSetup.getEnvironmentContext();
084:                mEventNotifier = (EventNotifier) mContext.getNotifier();
085:            }
086:
087:            /**
088:             * Cleanup for the test.
089:             * @throws Exception when tearDown fails for any reason.
090:             */
091:            public void tearDown() throws Exception {
092:                super .tearDown();
093:                System.err.println("***** END of test " + mTestName);
094:            }
095:
096:            // =============================  test methods ================================
097:
098:            /**
099:             * Tests getNotificationInfo.
100:             * @throws Exception if an unexpected error occurs.
101:             */
102:            public void testGetNotificationInfo() {
103:                // Get the notification info for this MBean
104:
105:                MBeanNotificationInfo[] info = mEventNotifier
106:                        .getNotificationInfo();
107:                String[] types = info[0].getNotifTypes();
108:                String name = info[0].getName();
109:                String desc = info[0].getDescription();
110:
111:                // Verify that the notification info is correct
112:
113:                assertEquals(
114:                        "Got more than one MBeanNotificationInfo, expected one: ",
115:                        1, info.length);
116:                assertEquals("Got wrong number of notification types: ",
117:                        mEventNotifier.NOTIFICATION_TYPES.length, types.length);
118:                assertEquals("Got wrong class name: ",
119:                        mEventNotifier.NOTIFICATION_CLASS_NAME, name);
120:                assertEquals("Got wrong description: ",
121:                        mEventNotifier.NOTIFICATION_DESCRIPTION, desc);
122:            }
123:
124:            /**
125:             * Tests emitRuntimeNotification for startup/shutdown of the JBI framework.
126:             * @throws Exception if an unexpected error occurs.
127:             */
128:            public void testEmitRuntimeNotification() {
129:                // Emit a notification for startup of the JBI Framework
130:
131:                String msg = "JBI Framework has been started";
132:                Notification not = mEventNotifier.emitRuntimeNotification(
133:                        EventNotifier.EventType.Started, msg);
134:
135:                // Verify that the notification content is correct
136:
137:                assertEquals("Notification type is incorrect: ", not.getType(),
138:                        "com.sun.jbi." + EventNotifier.EventType.Started + "."
139:                                + EventNotifier.SourceType.JBIRuntime);
140:
141:                assertEquals("Message in notification is incorrect: ", not
142:                        .getMessage(), msg);
143:
144:                CompositeData cd = (CompositeData) not.getUserData();
145:
146:                assertEquals("UserData in notification has wrong event type: ",
147:                        cd.get(EventNotifier.EVENT_TYPE_KEY),
148:                        EventNotifier.EventType.Started.toString());
149:                assertEquals(
150:                        "UserData in notification has wrong source type: ", cd
151:                                .get(EventNotifier.SOURCE_TYPE_KEY),
152:                        EventNotifier.SourceType.JBIRuntime.toString());
153:                assertEquals(
154:                        "UserData in notification has wrong source name: ", cd
155:                                .get(EventNotifier.SOURCE_NAME_KEY),
156:                        mEventNotifier.JBI_FRAMEWORK);
157:
158:                // Now emit another notification
159:
160:                msg = "JBI Framework has been stopped";
161:                Notification not2 = mEventNotifier.emitRuntimeNotification(
162:                        EventNotifier.EventType.Stopped, msg);
163:
164:                // Verify that the notification sequence number is correct. It should
165:                // be the sequence number from the first notification plus one.
166:
167:                assertEquals("Notification sequence number incorrect: ", not2
168:                        .getSequenceNumber(), not.getSequenceNumber() + 1);
169:            }
170:
171:            /**
172:             * Tests emitComponentNotification for a component install/uninstall.
173:             * @throws Exception if an unexpected error occurs.
174:             */
175:            public void testEmitComponentNotification() {
176:                // Emit a notification for installation of a component
177:
178:                String compName = "TestBinding";
179:                String compMsg = "TestBinding has been installed";
180:                Notification not = mEventNotifier.emitComponentNotification(
181:                        EventNotifier.EventType.Installed,
182:                        EventNotifier.SourceType.BindingComponent, compName,
183:                        compMsg);
184:
185:                // Verify that the notification content is correct
186:
187:                assertEquals("Notification type is incorrect: ", not.getType(),
188:                        "com.sun.jbi." + EventNotifier.EventType.Installed
189:                                + "."
190:                                + EventNotifier.SourceType.BindingComponent);
191:
192:                assertEquals("Message in notification is incorrect: ", not
193:                        .getMessage(), compMsg);
194:
195:                CompositeData cd = (CompositeData) not.getUserData();
196:
197:                assertEquals("UserData in notification has wrong event type: ",
198:                        cd.get(EventNotifier.EVENT_TYPE_KEY),
199:                        EventNotifier.EventType.Installed.toString());
200:                assertEquals(
201:                        "UserData in notification has wrong source type: ", cd
202:                                .get(EventNotifier.SOURCE_TYPE_KEY),
203:                        EventNotifier.SourceType.BindingComponent.toString());
204:                assertEquals(
205:                        "UserData in notification has wrong source name: ", cd
206:                                .get(EventNotifier.SOURCE_NAME_KEY), compName);
207:
208:                // Now emit another notification for uninstallation
209:
210:                Notification not2 = mEventNotifier.emitComponentNotification(
211:                        EventNotifier.EventType.Uninstalled,
212:                        EventNotifier.SourceType.BindingComponent, compName,
213:                        compMsg);
214:
215:                // Verify that the notification sequence number is correct. It should
216:                // be the sequence number from the first notification plus one.
217:
218:                assertEquals("Notification sequence number incorrect: ", not2
219:                        .getSequenceNumber(), not.getSequenceNumber() + 1);
220:            }
221:
222:            /**
223:             * Tests emitSharedLibraryNotification for a shared library install/
224:             * uninstall.
225:             * @throws Exception if an unexpected error occurs.
226:             */
227:            public void testEmitSharedLibraryNotification() {
228:                String slName = "TestSharedLibrary";
229:                String slMsg = "TestSharedLibrary has been installed";
230:                Notification not = mEventNotifier
231:                        .emitSharedLibraryNotification(
232:                                EventNotifier.EventType.Installed, slName,
233:                                slMsg);
234:
235:                // Verification
236:
237:                assertEquals("Notification type is incorrect: ", not.getType(),
238:                        "com.sun.jbi." + EventNotifier.EventType.Installed
239:                                + "." + EventNotifier.SourceType.SharedLibrary);
240:
241:                assertEquals("Message in notification is incorrect: ", not
242:                        .getMessage(), slMsg);
243:
244:                CompositeData cd = (CompositeData) not.getUserData();
245:
246:                assertEquals("UserData in notification has wrong event type: ",
247:                        cd.get(EventNotifier.EVENT_TYPE_KEY),
248:                        EventNotifier.EventType.Installed.toString());
249:                assertEquals(
250:                        "UserData in notification has wrong source type: ", cd
251:                                .get(EventNotifier.SOURCE_TYPE_KEY),
252:                        EventNotifier.SourceType.SharedLibrary.toString());
253:                assertEquals(
254:                        "UserData in notification has wrong source name: ", cd
255:                                .get(EventNotifier.SOURCE_NAME_KEY), slName);
256:
257:                // Now emit another notification for uninstallation
258:
259:                slMsg = "TestSharedLibrary has been uninstalled";
260:                Notification not2 = mEventNotifier
261:                        .emitSharedLibraryNotification(
262:                                EventNotifier.EventType.Uninstalled, slName,
263:                                slMsg);
264:
265:                // Verify that the notification sequence number is correct. It should
266:                // be the sequence number from the first notification plus one.
267:
268:                assertEquals("Notification sequence number incorrect: ", not2
269:                        .getSequenceNumber(), not.getSequenceNumber() + 1);
270:            }
271:
272:            /**
273:             * Tests emitServiceAssemblyNotification for a service assembly deploy/
274:             * undeploy.
275:             * @throws Exception if an unexpected error occurs.
276:             */
277:            public void testEmitServiceAssemblyNotification() {
278:                String saName = "TestServiceAssembly";
279:                String saMsg = "TestServiceAssembly has been deployed";
280:                Notification not = mEventNotifier
281:                        .emitServiceAssemblyNotification(
282:                                EventNotifier.EventType.Deployed, saName, saMsg);
283:
284:                // Verification
285:
286:                assertEquals("Notification type is incorrect: ", not.getType(),
287:                        "com.sun.jbi." + EventNotifier.EventType.Deployed + "."
288:                                + EventNotifier.SourceType.ServiceAssembly);
289:
290:                assertEquals("Message in notification is incorrect: ", not
291:                        .getMessage(), saMsg);
292:
293:                CompositeData cd = (CompositeData) not.getUserData();
294:
295:                assertEquals("UserData in notification has wrong event type: ",
296:                        cd.get(EventNotifier.EVENT_TYPE_KEY),
297:                        EventNotifier.EventType.Deployed.toString());
298:                assertEquals(
299:                        "UserData in notification has wrong source type: ", cd
300:                                .get(EventNotifier.SOURCE_TYPE_KEY),
301:                        EventNotifier.SourceType.ServiceAssembly.toString());
302:                assertEquals(
303:                        "UserData in notification has wrong source name: ", cd
304:                                .get(EventNotifier.SOURCE_NAME_KEY), saName);
305:
306:                // Now emit another notification for undeployment
307:
308:                saMsg = "TestServiceAssembly has been undeployed";
309:                Notification not2 = mEventNotifier
310:                        .emitServiceAssemblyNotification(
311:                                EventNotifier.EventType.Undeployed, saName,
312:                                saMsg);
313:
314:                // Verify that the notification sequence number is correct. It should
315:                // be the sequence number from the first notification plus one.
316:
317:                assertEquals("Notification sequence number incorrect: ", not2
318:                        .getSequenceNumber(), not.getSequenceNumber() + 1);
319:            }
320:
321:            /**
322:             * Tests emitServiceUnitNotification for a service unit start/shutdown.
323:             * @throws Exception if an unexpected error occurs.
324:             */
325:            public void testEmitServiceUnitNotification() {
326:                String suName = "TestServiceUnit";
327:                String suMsg = "TestServiceUnit has been started";
328:                String saName = "TestServiceAssembly";
329:                String compName = "TestEngine";
330:                Notification not = mEventNotifier.emitServiceUnitNotification(
331:                        EventNotifier.EventType.Started, suName, saName,
332:                        compName, suMsg);
333:
334:                // Verification
335:
336:                assertEquals("Notification type is incorrect: ", not.getType(),
337:                        "com.sun.jbi." + EventNotifier.EventType.Started + "."
338:                                + EventNotifier.SourceType.ServiceUnit);
339:
340:                assertEquals("Message in notification is incorrect: ", not
341:                        .getMessage(), suMsg);
342:
343:                CompositeData cd = (CompositeData) not.getUserData();
344:
345:                assertEquals("UserData in notification has wrong event type: ",
346:                        cd.get(EventNotifier.EVENT_TYPE_KEY),
347:                        EventNotifier.EventType.Started.toString());
348:                assertEquals(
349:                        "UserData in notification has wrong source type: ", cd
350:                                .get(EventNotifier.SOURCE_TYPE_KEY),
351:                        EventNotifier.SourceType.ServiceUnit.toString());
352:                assertEquals(
353:                        "UserData in notification has wrong source name: ", cd
354:                                .get(EventNotifier.SOURCE_NAME_KEY), suName);
355:                assertEquals(
356:                        "UserData in notification has wrong service assembly name: ",
357:                        cd.get(EventNotifier.SERVICE_ASSEMBLY_NAME_KEY), saName);
358:                assertEquals(
359:                        "UserData in notification has wrong component name: ",
360:                        cd.get(EventNotifier.COMPONENT_NAME_KEY), compName);
361:
362:                // Now emit another notification for shutdown
363:
364:                suMsg = "TestServiceUnit has been shut down";
365:                Notification not2 = mEventNotifier.emitServiceUnitNotification(
366:                        EventNotifier.EventType.ShutDown, suName, saName,
367:                        compName, suMsg);
368:
369:                // Verify that the notification sequence number is correct. It should
370:                // be the sequence number from the first notification plus one.
371:
372:                assertEquals("Notification sequence number incorrect: ", not2
373:                        .getSequenceNumber(), not.getSequenceNumber() + 1);
374:            }
375:
376:            /**
377:             * Tests enableNotifications/disableNotifications.
378:             * @throws Exception if an unexpected error occurs.
379:             */
380:            public void testEnableDisableNotifications() {
381:                // First emit a runtime notification
382:
383:                String msg = "JBI Framework has been started";
384:                Notification not = mEventNotifier.emitRuntimeNotification(
385:                        EventNotifier.EventType.Started, msg);
386:
387:                // Verify that the notification was created
388:
389:                assertNotNull("Notification not created: ", not);
390:                assertEquals("Notification not correct: ", msg, not
391:                        .getMessage());
392:
393:                // Now disable notifications
394:
395:                mEventNotifier.disableNotifications();
396:
397:                // Attempt to emit a runtime notification
398:
399:                not = mEventNotifier.emitRuntimeNotification(
400:                        EventNotifier.EventType.Started, msg);
401:
402:                // Verify that the notification was not created
403:
404:                assertNull("Notification should not have been created: ", not);
405:
406:                // Now enable notifications
407:
408:                mEventNotifier.enableNotifications();
409:
410:                // Emit a runtime notification
411:
412:                not = mEventNotifier.emitRuntimeNotification(
413:                        EventNotifier.EventType.Started, msg);
414:
415:                // Verify that the notification was created
416:
417:                assertNotNull("Notification not created: ", not);
418:                assertEquals("Notification not correct: ", msg, not
419:                        .getMessage());
420:            }
421:
422:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.