01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package test.compliance.server;
23:
24: import javax.management.MBeanServer;
25: import javax.management.MBeanServerFactory;
26: import javax.management.Notification;
27: import javax.management.NotificationListener;
28: import javax.management.ObjectName;
29:
30: import junit.framework.TestCase;
31: import test.compliance.server.support.Test;
32:
33: /**
34: * Tests for the MBean server delegate.
35: *
36: * @author <a href="mailto:juha@jboss.org">Juha Lindfors</a>.
37: *
38: * @version $Revision: 57200 $
39: */
40: public class MBeanDelegateTEST extends TestCase {
41:
42: public MBeanDelegateTEST(String s) {
43: super (s);
44: }
45:
46: class MyNotificationListener implements NotificationListener {
47:
48: int notificationCount = 0;
49:
50: public void handleNotification(Notification notification,
51: Object handback) {
52: try {
53: notificationCount++;
54: } catch (Exception e) {
55: fail("Unexpected error: " + e.toString());
56: }
57: }
58: }
59:
60: public synchronized void testRegistrationAndUnregistrationNotification()
61: throws Exception {
62: MBeanServer server = MBeanServerFactory.createMBeanServer();
63: MyNotificationListener listener = new MyNotificationListener();
64:
65: server.addNotificationListener(new ObjectName(
66: "JMImplementation:type=MBeanServerDelegate"), listener,
67: null, null);
68:
69: // force registration notification
70: server
71: .registerMBean(new Test(), new ObjectName(
72: "test:foo=bar"));
73:
74: // force unregistration notification
75: server.unregisterMBean(new ObjectName("test:foo=bar"));
76:
77: // wait for notif to arrive max 5 secs
78: for (int i = 0; i < 10; ++i) {
79: wait(500);
80:
81: if (listener.notificationCount > 1)
82: break;
83: }
84:
85: assertTrue(listener.notificationCount == 2);
86: }
87:
88: }
|