1 22 package org.jboss.test.jmx.compliance.registration; 23 24 import javax.management.InstanceAlreadyExistsException ; 25 import javax.management.MBeanRegistrationException ; 26 import javax.management.MBeanServer ; 27 import javax.management.MBeanServerFactory ; 28 import javax.management.MalformedObjectNameException ; 29 import javax.management.ObjectName ; 30 31 import org.jboss.test.jmx.compliance.registration.support.RegistrationAware; 32 33 import junit.framework.TestCase; 34 35 public class RegistrationTEST extends TestCase 36 { 37 public RegistrationTEST(String s) 38 { 39 super(s); 40 } 41 42 public void testSimpleRegistration() 43 { 44 try 45 { 46 MBeanServer server = MBeanServerFactory.newMBeanServer(); 47 RegistrationAware ra = new RegistrationAware(); 48 ObjectName name = new ObjectName ("test:key=value"); 49 50 server.registerMBean(ra, name); 51 52 assertTrue("preRegister", ra.isPreRegisterCalled()); 53 assertTrue("postRegister", ra.isPostRegisterCalled()); 54 assertTrue("postRegisterRegistrationDone", ra.isPostRegisterRegistrationDone()); 55 assertEquals(name, ra.getRegisteredObjectName()); 56 57 server.unregisterMBean(name); 58 59 assertTrue("preDeRegister", ra.isPreDeRegisterCalled()); 60 assertTrue("postDeRegister", ra.isPostDeRegisterCalled()); 61 } 62 catch (MalformedObjectNameException e) 63 { 64 fail("spurious MalformedObjectNameException"); 65 } 66 catch (MBeanRegistrationException e) 67 { 68 fail("strange MBeanRegistrationException linked to: " + e.getTargetException().getMessage()); 69 } 70 catch (Exception e) 71 { 72 fail("something else went wrong: " + e.getMessage()); 73 } 74 } 75 76 public void testDuplicateRegistration() 77 { 78 79 try 80 { 81 MBeanServer server = MBeanServerFactory.newMBeanServer(); 82 ObjectName name = new ObjectName ("test:key=value"); 83 84 RegistrationAware original = new RegistrationAware(); 85 RegistrationAware ra = new RegistrationAware(); 86 87 server.registerMBean(original, name); 88 89 try 90 { 91 server.registerMBean(ra, name); 92 fail("expected a InstanceAlreadyExistsException"); 93 } 94 catch (InstanceAlreadyExistsException e) 95 { 96 } 97 98 assertTrue("preRegister", ra.isPreRegisterCalled()); 99 assertTrue("postRegister", ra.isPostRegisterCalled()); 100 assertTrue("postRegisterRegistrationDone", !ra.isPostRegisterRegistrationDone()); 101 assertTrue("preDeRegister", !ra.isPreDeRegisterCalled()); 102 assertTrue("postDeRegister", !ra.isPostDeRegisterCalled()); 103 assertEquals(name, ra.getRegisteredObjectName()); 104 105 server.unregisterMBean(name); 106 } 107 catch (Exception e) 108 { 109 fail("got an unexpected exception: " + e.getMessage()); 110 } 111 } 112 113 } 114 | Popular Tags |