KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jbossmx > compliance > server > MBeanServerFactoryTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.jbossmx.compliance.server;
23
24 import org.jboss.test.jbossmx.compliance.TestCase;
25
26 import javax.management.MBeanServer JavaDoc;
27 import javax.management.MBeanServerFactory JavaDoc;
28 import java.util.List JavaDoc;
29
30 public class MBeanServerFactoryTestCase
31    extends TestCase
32 {
33    public MBeanServerFactoryTestCase(String JavaDoc s)
34    {
35       super(s);
36    }
37
38    public void testFindNonCreated()
39    {
40       MBeanServer JavaDoc server = MBeanServerFactory.newMBeanServer();
41       List JavaDoc mbsList = MBeanServerFactory.findMBeanServer(null);
42       assertEquals(0, mbsList.size());
43    }
44
45    public void testCreateFindAndRelease()
46    {
47       MBeanServer JavaDoc server = null;
48       List JavaDoc mbsList = null;
49
50       try
51       {
52          server = MBeanServerFactory.createMBeanServer();
53          mbsList = MBeanServerFactory.findMBeanServer(null);
54          assertEquals(1, mbsList.size());
55       }
56       finally
57       {
58          if (null != server)
59          {
60             MBeanServerFactory.releaseMBeanServer(server);
61          }
62       }
63
64       mbsList = MBeanServerFactory.findMBeanServer(null);
65       assertEquals(0, mbsList.size());
66    }
67
68    public void testRemoveNonCreated()
69    {
70       try
71       {
72          MBeanServer JavaDoc server = MBeanServerFactory.newMBeanServer();
73          MBeanServerFactory.releaseMBeanServer(server);
74          fail("expected an IllegalArgumentException");
75       }
76       catch (IllegalArgumentException JavaDoc e)
77       {
78       }
79       catch (Exception JavaDoc e)
80       {
81          fail("expected an IllegalArgumentException but got: " + e.getMessage());
82       }
83    }
84
85    public void testDomainCreated()
86    {
87       String JavaDoc domain = "dOmAiN";
88       MBeanServer JavaDoc server = null;
89       try
90       {
91          server = MBeanServerFactory.createMBeanServer(domain);
92          assertEquals(domain, server.getDefaultDomain());
93          List JavaDoc mbsList = MBeanServerFactory.findMBeanServer(null);
94          assertEquals(server, mbsList.get(0));
95          assertTrue("expected server reference equality", mbsList.get(0) == server);
96       }
97       finally
98       {
99          if (null != server)
100          {
101             MBeanServerFactory.releaseMBeanServer(server);
102          }
103       }
104    }
105
106    public void testDomainNonCreated()
107    {
108       String JavaDoc domain = "dOmAiN";
109       MBeanServer JavaDoc server = MBeanServerFactory.newMBeanServer(domain);
110       assertEquals(domain, server.getDefaultDomain());
111    }
112
113    public void testFindByAgentID()
114    {
115       // FIXME THS - flesh this out
116
}
117
118 }
119
Popular Tags