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