1 22 package org.jboss.test.jmx.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 32 import org.jboss.test.jmx.compliance.server.support.Test; 33 34 41 public class MBeanDelegateTEST extends TestCase 42 { 43 44 public MBeanDelegateTEST(String s) 45 { 46 super(s); 47 } 48 49 class MyNotificationListener implements NotificationListener { 50 51 int notificationCount = 0; 52 53 public void handleNotification(Notification notification, Object handback) 54 { 55 try 56 { 57 notificationCount++; 58 } 59 catch (Exception e) 60 { 61 fail("Unexpected error: " + e.toString()); 62 } 63 } 64 } 65 66 public synchronized void testRegistrationAndUnregistrationNotification() throws Exception 67 { 68 MBeanServer server = MBeanServerFactory.createMBeanServer(); 69 MyNotificationListener listener = new MyNotificationListener(); 70 71 server.addNotificationListener( 72 new ObjectName ("JMImplementation:type=MBeanServerDelegate"), 73 listener, null, null 74 ); 75 76 server.registerMBean(new Test(), new ObjectName ("test:foo=bar")); 78 79 server.unregisterMBean(new ObjectName ("test:foo=bar")); 81 82 for (int i = 0; i < 10; ++i) 84 { 85 wait(500); 86 87 if (listener.notificationCount > 1) 88 break; 89 } 90 91 assertTrue(listener.notificationCount == 2); 92 } 93 94 } 95 | Popular Tags |