KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jmx > test > MBeanInfoUnitTestCase


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.test;
23
24 import javax.management.MBeanAttributeInfo JavaDoc;
25 import javax.management.MBeanInfo JavaDoc;
26 import javax.management.MBeanOperationInfo JavaDoc;
27 import javax.management.ObjectName JavaDoc;
28
29 import junit.framework.Test;
30
31 import org.jboss.test.JBossTestCase;
32
33 /**
34  * Tests for that metadata exposes for an mbean is the same,
35  * when the mbean is deployed as a standard mbean or an
36  * xmbean.
37  *
38  * @author Dimitris.Andreadis@jboss.org
39  * @version $Revision: 40362 $
40  */

41 public class MBeanInfoUnitTestCase extends JBossTestCase
42 {
43    public MBeanInfoUnitTestCase(String JavaDoc name)
44    {
45       super(name);
46    }
47
48    public static Test suite()
49       throws Exception JavaDoc
50    {
51       return getDeploySetup(MBeanInfoUnitTestCase.class, "mbeaninfo-xmbean.sar");
52    }
53
54    public void testMBeanInfoStandardMBean() throws Exception JavaDoc
55    {
56       getLog().info("+++ testMBeanInfoStandardMBean");
57       ObjectName JavaDoc target = new ObjectName JavaDoc("jboss.test:name=mbeaninfo,type=standard");
58       MBeanInfo JavaDoc info = getServer().getMBeanInfo(target);
59       checkMBeanInfo(info);
60    }
61    
62    public void testMBeanInfoXMBean() throws Exception JavaDoc
63    {
64       getLog().info("+++ testMBeanInfoXMBean");
65       ObjectName JavaDoc target = new ObjectName JavaDoc("jboss.test:name=mbeaninfo,type=xmbean");
66       MBeanInfo JavaDoc info = getServer().getMBeanInfo(target);
67       checkMBeanInfo(info);
68    }
69    
70    private void checkMBeanInfo(MBeanInfo JavaDoc info)
71    {
72       // Verify the 1 attribute we expect
73
MBeanAttributeInfo JavaDoc[] attrs = info.getAttributes();
74       assertTrue("mbean has 1 attribute", attrs.length == 1);
75       assertTrue("attribute[0] name is 'StringAttr'", attrs[0].getName().equals("StringAttr"));
76       assertTrue("attribute[0] type is 'java.lang.String'", attrs[0].getType().equals("java.lang.String"));
77       
78       // Verify the 1 operation we expect
79
MBeanOperationInfo JavaDoc[] ops = info.getOperations();
80       assertTrue("mbean has 1 operation", ops.length == 1);
81       assertTrue("operation[0] is 'echo'", ops[0].getName().equals("echo"));
82       assertTrue("operation[0] accepts one parameter", ops[0].getSignature().length == 1);
83       assertTrue("operation[0] returns 'java.lang.String'", ops[0].getReturnType().equals("java.lang.String"));
84    }
85
86 }
87
Popular Tags