KickJava   Java API By Example, From Geeks To Geeks.

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


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.MBeanServerConnection JavaDoc;
25 import javax.management.ObjectName JavaDoc;
26
27 import org.jboss.test.JBossTestCase;
28 import org.jboss.test.jmx.conf.SimpleBean;
29
30 /**
31  * MBean attribute configuration tests
32  *
33  * @author <a HREF="mailto:dimitris@jboss.org">Dimitris Andreadis</a>
34  * @version $Revision: 39246 $
35  */

36 public class MBeanAttributeConfigurationUnitTestCase extends JBossTestCase
37 {
38    public MBeanAttributeConfigurationUnitTestCase(String JavaDoc name)
39    {
40       super(name);
41    }
42
43    /**
44     * Test we can properly configure attributes in a normal deployment
45     */

46    public void testNormalAttributeConfiguration() throws Exception JavaDoc
47    {
48       getLog().info("+++ testNormalAttributeConfiguration");
49       
50       performTest("conftestnormal.sar");
51    }
52    
53    /**
54     * Test we can properly configure Class/Class[] attributes
55     * in a scoped deployment
56     *
57     * see [JBAS-1709]
58     */

59    public void testScopedAttributeConfiguration() throws Exception JavaDoc
60    {
61       getLog().info("+++ testScopedAttributeConfiguration");
62
63       performTest("conftestscoped.sar");
64    }
65       
66    /**
67     * The actual test, common for both normal and scoped deployments
68     */

69    private void performTest(String JavaDoc testService) throws Exception JavaDoc
70    {
71       try
72       {
73          deploy(testService);
74          
75          MBeanServerConnection JavaDoc server = super.getServer();
76          ObjectName JavaDoc target = new ObjectName JavaDoc("test:name=MBeanAttributeConfiguration");
77          
78          Class JavaDoc clazz = (Class JavaDoc)server.getAttribute(target, "ClassAttr");
79          assertTrue("ClassAttr of correct type", clazz.getName().equals("org.jboss.test.jmx.conf.SimpleClass1"));
80          
81          Class JavaDoc[] clazzes = (Class JavaDoc[])server.getAttribute(target, "ClassArrayAttr");
82          assertTrue("ClassArrayAttr array length == 2", clazzes.length == 2);
83          assertTrue("ClassArrayAttr[0] of correct type", clazzes[0].getName().equals("org.jboss.test.jmx.conf.SimpleClass1"));
84          assertTrue("ClassArrayAttr[1] of correct type", clazzes[1].getName().equals("org.jboss.test.jmx.conf.SimpleClass2"));
85          
86          SimpleBean bean = (SimpleBean)server.getAttribute(target, "BeanAttr");
87          assertTrue("bean.getAString() == 'string'", bean.getAString().equals("string"));
88          assertTrue("bean.getAStringArray().length == 2", bean.getAStringArray().length == 2);
89          assertTrue("ean.getAStringArray()[0] == 'string1'", bean.getAStringArray()[0].equals("string1"));
90          assertTrue("ean.getAStringArray()[0] == 'string1'", bean.getAStringArray()[1].equals("string2"));
91       }
92       catch (Exception JavaDoc e)
93       {
94          getLog().warn("Caught exception", e);
95          fail("Unexcepted Exception, see the Log file");
96       }
97       finally
98       {
99          undeploy(testService);
100       }
101    }
102 }
Popular Tags