001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package test.compliance.server;
023:
024: import java.util.List;
025:
026: import javax.management.MBeanServer;
027: import javax.management.MBeanServerFactory;
028: import javax.management.ObjectName;
029:
030: import junit.framework.AssertionFailedError;
031: import junit.framework.TestCase;
032:
033: public class MBeanServerFactoryTEST extends TestCase {
034: public MBeanServerFactoryTEST(String s) {
035: super (s);
036: }
037:
038: public void testFindNonCreated() {
039: MBeanServerFactory.newMBeanServer();
040: List mbsList = MBeanServerFactory.findMBeanServer(null);
041: assertEquals(0, mbsList.size());
042: }
043:
044: public void testCreateFindAndRelease() {
045: MBeanServer server = null;
046: List mbsList = null;
047:
048: try {
049: server = MBeanServerFactory.createMBeanServer();
050: mbsList = MBeanServerFactory.findMBeanServer(null);
051: assertEquals(1, mbsList.size());
052: } finally {
053: if (null != server) {
054: MBeanServerFactory.releaseMBeanServer(server);
055: }
056: }
057:
058: mbsList = MBeanServerFactory.findMBeanServer(null);
059: assertEquals(0, mbsList.size());
060: }
061:
062: public void testRemoveNonCreated() {
063: try {
064: MBeanServer server = MBeanServerFactory.newMBeanServer();
065: MBeanServerFactory.releaseMBeanServer(server);
066: fail("expected an IllegalArgumentException");
067: } catch (IllegalArgumentException e) {
068: } catch (Exception e) {
069: fail("expected an IllegalArgumentException but got: "
070: + e.getMessage());
071: }
072: }
073:
074: public void testDomainCreated() {
075: String domain = "dOmAiN";
076: MBeanServer server = null;
077: try {
078: server = MBeanServerFactory.createMBeanServer(domain);
079: assertEquals(domain, server.getDefaultDomain());
080: List mbsList = MBeanServerFactory.findMBeanServer(null);
081: assertEquals(server, mbsList.get(0));
082: assertTrue("expected server reference equality", mbsList
083: .get(0) == server);
084: } finally {
085: if (null != server) {
086: MBeanServerFactory.releaseMBeanServer(server);
087: }
088: }
089: }
090:
091: public void testDomainNonCreated() {
092: String domain = "dOmAiN";
093: MBeanServer server = MBeanServerFactory.newMBeanServer(domain);
094: assertEquals(domain, server.getDefaultDomain());
095: }
096:
097: public void testFindByAgentID() {
098: try {
099: MBeanServer server1 = MBeanServerFactory
100: .createMBeanServer();
101: MBeanServer server2 = MBeanServerFactory
102: .createMBeanServer();
103: MBeanServer server3 = MBeanServerFactory.newMBeanServer();
104: ObjectName delegateName = new ObjectName(
105: "JMImplementation:type=MBeanServerDelegate");
106:
107: String agentID1 = (String) server1.getAttribute(
108: delegateName, "MBeanServerId");
109: String agentID2 = (String) server2.getAttribute(
110: delegateName, "MBeanServerId");
111: String agentID3 = (String) server3.getAttribute(
112: delegateName, "MBeanServerId");
113:
114: assertTrue((MBeanServer) MBeanServerFactory
115: .findMBeanServer(agentID1).get(0) == server1);
116: assertTrue((MBeanServer) MBeanServerFactory
117: .findMBeanServer(agentID2).get(0) == server2);
118: assertTrue(MBeanServerFactory.findMBeanServer(agentID3)
119: .size() == 0);
120: } catch (AssertionFailedError e) {
121: throw e;
122: } catch (Throwable t) {
123: fail("Unexpected error: " + t.toString());
124: }
125: }
126:
127: }
|