KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jmx > compliance > notcompliant > NCMBeanTEST


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.jmx.compliance.notcompliant;
23
24 import javax.management.MBeanInfo JavaDoc;
25 import javax.management.MBeanServer JavaDoc;
26 import javax.management.MBeanServerFactory JavaDoc;
27 import javax.management.NotCompliantMBeanException JavaDoc;
28 import javax.management.ObjectName JavaDoc;
29
30 import org.jboss.test.jmx.compliance.notcompliant.support.DynamicAndStandard;
31 import org.jboss.test.jmx.compliance.notcompliant.support.InterfaceProblems;
32 import org.jboss.test.jmx.compliance.notcompliant.support.NullDynamic;
33 import org.jboss.test.jmx.compliance.notcompliant.support.OverloadedAttribute1;
34 import org.jboss.test.jmx.compliance.notcompliant.support.OverloadedAttribute2;
35 import org.jboss.test.jmx.compliance.notcompliant.support.OverloadedAttribute3;
36 import org.jboss.test.jmx.compliance.notcompliant.support.OverloadedAttribute4;
37 import org.jboss.test.jmx.compliance.notcompliant.support.OverloadedAttribute5;
38
39 import junit.framework.TestCase;
40
41 public class NCMBeanTEST extends TestCase
42 {
43    public NCMBeanTEST(String JavaDoc s)
44    {
45       super(s);
46    }
47
48    public void testOverloadedAttribute1()
49    {
50       registerAndTest(new OverloadedAttribute1());
51    }
52
53    public void testOverloadedAttribute2()
54    {
55       registerAndTest(new OverloadedAttribute2());
56    }
57
58    public void testOverloadedAttribute3()
59    {
60       registerAndTest(new OverloadedAttribute3());
61    }
62
63    public void testOverloadedAttribute4()
64    {
65       registerAndTest(new OverloadedAttribute4());
66    }
67
68    public void testOverloadedAttribute5()
69    {
70       registerAndTest(new OverloadedAttribute5());
71    }
72
73    public void testMixedDynamicStandard()
74    {
75       MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
76       try
77       {
78          server.registerMBean(new DynamicAndStandard(), new ObjectName JavaDoc("test:foo=bar"));
79          MBeanInfo JavaDoc info = server.getMBeanInfo(new ObjectName JavaDoc("test:foo=bar"));
80          assertTrue("A mixed dynamic and standard mbean should be dynamic",
81                     info.getDescription().equals(DynamicAndStandard.DESCRIPTION));
82       }
83       catch (NotCompliantMBeanException JavaDoc e)
84       {
85          fail("A mixed dynamic and standardmbean is allowed from jmx 1.1");
86       }
87       catch (Exception JavaDoc e)
88       {
89          fail("unexpected exception when registering " + DynamicAndStandard.class.getName() + ": " + e.getMessage());
90       }
91       finally
92       {
93          MBeanServerFactory.releaseMBeanServer(server);
94       }
95    }
96
97    public void testNoConstructor()
98    {
99       try
100       {
101          registerAndDontTest(NoConstructor.getInstance());
102       }
103       catch (NotCompliantMBeanException JavaDoc e)
104       {
105          fail("An MBean without a public constructor is allowed from jmx 1.1");
106       }
107    }
108
109    public void testInterfaceProblems()
110    {
111       try
112       {
113          registerAndDontTest(new InterfaceProblems());
114       }
115       catch (NotCompliantMBeanException JavaDoc e)
116       {
117          fail("FAILS IN RI: Cannot cope with overriden get/is in interfaces");
118       }
119    }
120
121    public void testNullDynamic()
122       throws Exception JavaDoc
123    {
124       MBeanServer JavaDoc server = MBeanServerFactory.newMBeanServer();
125       ObjectName JavaDoc name = new ObjectName JavaDoc("test:test=test");
126       boolean caught = false;
127       try
128       {
129          server.registerMBean(new NullDynamic(), name);
130       }
131       catch (NotCompliantMBeanException JavaDoc e)
132       {
133          caught = true;
134       }
135       assertTrue("Expected NCME for null MBeanInfo", caught);
136    }
137
138    private void registerAndTest(Object JavaDoc mbean)
139    {
140       MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
141       try
142       {
143          server.registerMBean(mbean, new ObjectName JavaDoc("test:foo=bar"));
144          fail("expected a NotCompliantMBeanException for " + mbean.getClass().getName());
145       }
146       catch (NotCompliantMBeanException JavaDoc e)
147       {
148          // this is what we want
149
}
150       catch (Exception JavaDoc e)
151       {
152          fail("unexpected exception when registering " + mbean.getClass().getName() + ": " + e);
153       }
154       finally
155       {
156          MBeanServerFactory.releaseMBeanServer(server);
157       }
158    }
159
160    private void registerAndDontTest(Object JavaDoc mbean)
161       throws NotCompliantMBeanException JavaDoc
162    {
163       MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
164       try
165       {
166          server.registerMBean(mbean, new ObjectName JavaDoc("test:foo=bar"));
167       }
168       catch (NotCompliantMBeanException JavaDoc e)
169       {
170          throw e;
171       }
172       catch (Exception JavaDoc e)
173       {
174          fail("unexpected exception when registering " + mbean.getClass().getName() + ": " + e.getMessage());
175       }
176       finally
177       {
178          MBeanServerFactory.releaseMBeanServer(server);
179       }
180    }
181 }
182
Popular Tags