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