1 7 8 package test.compliance.server; 9 10 import java.util.List; 11 12 import javax.management.MBeanServer; 13 import javax.management.MBeanServerFactory; 14 import javax.management.ObjectName; 15 16 import junit.framework.AssertionFailedError; 17 import junit.framework.TestCase; 18 19 20 public class MBeanServerFactoryTEST extends TestCase 21 { 22 public MBeanServerFactoryTEST(String s) 23 { 24 super(s); 25 } 26 27 public void testFindNonCreated() 28 { 29 MBeanServerFactory.newMBeanServer(); 30 List mbsList = MBeanServerFactory.findMBeanServer(null); 31 assertEquals(0, mbsList.size()); 32 } 33 34 public void testCreateFindAndRelease() 35 { 36 MBeanServer server = null; 37 List mbsList = null; 38 39 try 40 { 41 server = MBeanServerFactory.createMBeanServer(); 42 mbsList = MBeanServerFactory.findMBeanServer(null); 43 assertEquals(1, mbsList.size()); 44 } 45 finally 46 { 47 if (null != server) 48 { 49 MBeanServerFactory.releaseMBeanServer(server); 50 } 51 } 52 53 mbsList = MBeanServerFactory.findMBeanServer(null); 54 assertEquals(0, mbsList.size()); 55 } 56 57 public void testRemoveNonCreated() 58 { 59 try 60 { 61 MBeanServer server = MBeanServerFactory.newMBeanServer(); 62 MBeanServerFactory.releaseMBeanServer(server); 63 fail("expected an IllegalArgumentException"); 64 } 65 catch (IllegalArgumentException e) 66 { 67 } 68 catch (Exception e) 69 { 70 fail("expected an IllegalArgumentException but got: " + e.getMessage()); 71 } 72 } 73 74 public void testDomainCreated() 75 { 76 String domain = "dOmAiN"; 77 MBeanServer server = null; 78 try 79 { 80 server = MBeanServerFactory.createMBeanServer(domain); 81 assertEquals(domain, server.getDefaultDomain()); 82 List mbsList = MBeanServerFactory.findMBeanServer(null); 83 assertEquals(server, mbsList.get(0)); 84 assertTrue("expected server reference equality", mbsList.get(0) == server); 85 } 86 finally 87 { 88 if (null != server) 89 { 90 MBeanServerFactory.releaseMBeanServer(server); 91 } 92 } 93 } 94 95 public void testDomainNonCreated() 96 { 97 String domain = "dOmAiN"; 98 MBeanServer server = MBeanServerFactory.newMBeanServer(domain); 99 assertEquals(domain, server.getDefaultDomain()); 100 } 101 102 public void testFindByAgentID() 103 { 104 try 105 { 106 MBeanServer server1 = MBeanServerFactory.createMBeanServer(); 107 MBeanServer server2 = MBeanServerFactory.createMBeanServer(); 108 MBeanServer server3 = MBeanServerFactory.newMBeanServer(); 109 ObjectName delegateName = new ObjectName("JMImplementation:type=MBeanServerDelegate"); 110 111 String agentID1 = (String)server1.getAttribute(delegateName, "MBeanServerId"); 112 String agentID2 = (String)server2.getAttribute(delegateName, "MBeanServerId"); 113 String agentID3 = (String)server3.getAttribute(delegateName, "MBeanServerId"); 114 115 assertTrue((MBeanServer)MBeanServerFactory.findMBeanServer(agentID1).get(0) == server1); 116 assertTrue((MBeanServer)MBeanServerFactory.findMBeanServer(agentID2).get(0) == server2); 117 assertTrue(MBeanServerFactory.findMBeanServer(agentID3).size() == 0); 118 } 119 catch (AssertionFailedError e) 120 { 121 throw e; 122 } 123 catch (Throwable t) 124 { 125 fail("Unexpected error: " + t.toString()); 126 } 127 } 128 129 } 130 | Popular Tags |