1 7 8 package test.compliance.server; 9 10 import javax.management.MBeanServer; 11 import javax.management.MBeanServerFactory; 12 import javax.management.Notification; 13 import javax.management.NotificationListener; 14 import javax.management.ObjectName; 15 16 import junit.framework.TestCase; 17 import test.compliance.server.support.Test; 18 19 26 public class MBeanDelegateTEST extends TestCase 27 { 28 29 public MBeanDelegateTEST(String s) 30 { 31 super(s); 32 } 33 34 class MyNotificationListener implements NotificationListener { 35 36 int notificationCount = 0; 37 38 public void handleNotification(Notification notification, Object handback) 39 { 40 try 41 { 42 notificationCount++; 43 } 44 catch (Exception e) 45 { 46 fail("Unexpected error: " + e.toString()); 47 } 48 } 49 } 50 51 public synchronized void testRegistrationAndUnregistrationNotification() throws Exception 52 { 53 MBeanServer server = MBeanServerFactory.createMBeanServer(); 54 MyNotificationListener listener = new MyNotificationListener(); 55 56 server.addNotificationListener( 57 new ObjectName("JMImplementation:type=MBeanServerDelegate"), 58 listener, null, null 59 ); 60 61 server.registerMBean(new Test(), new ObjectName("test:foo=bar")); 63 64 server.unregisterMBean(new ObjectName("test:foo=bar")); 66 67 for (int i = 0; i < 10; ++i) 69 { 70 wait(500); 71 72 if (listener.notificationCount > 1) 73 break; 74 } 75 76 assertTrue(listener.notificationCount == 2); 77 } 78 79 } 80 | Popular Tags |