KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jbossmx > compliance > standard > PackageProtectedTestCase


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.standard;
23
24 import javax.management.Attribute JavaDoc;
25 import javax.management.MBeanServer JavaDoc;
26 import javax.management.MBeanServerFactory JavaDoc;
27 import javax.management.ObjectName JavaDoc;
28
29 import org.jboss.test.jbossmx.compliance.TestCase;
30 import org.jboss.test.jbossmx.compliance.standard.support.PackageProtectedMBean;
31 import org.jboss.test.jbossmx.compliance.standard.support.PackageProtectedMBeanFactory;
32
33 /**
34  * Test a standard mbean with a package protected class implementation.
35  *
36  * @author <a HREF="mailto:dimitris@jboss.org">Dimitris Andreadis</a>
37  * @version $Revision: 43651 $
38  */

39 public class PackageProtectedTestCase extends TestCase
40 {
41    public PackageProtectedTestCase(String JavaDoc s)
42    {
43       super(s);
44    }
45
46    /**
47     * JBAS-1704
48     */

49    public void testRegisterPackageProtectedClassImpl()
50    {
51       try
52       {
53          MBeanServer JavaDoc server = MBeanServerFactory.newMBeanServer();
54          ObjectName JavaDoc objectName = new ObjectName JavaDoc("test:key=value");
55          PackageProtectedMBean mbean = PackageProtectedMBeanFactory.createMBean("TestMBean");
56          
57          server.registerMBean(mbean, objectName);
58          
59          String JavaDoc name = (String JavaDoc)server.getAttribute(objectName, "Name");
60          assertEquals("TestMBean", name);
61          
62          server.setAttribute(objectName, new Attribute JavaDoc("Name", "TestMBeanX"));
63          name = (String JavaDoc)server.getAttribute(objectName, "Name");
64          assertEquals("TestMBeanX", name);
65          
66          String JavaDoc message = "hello";
67          String JavaDoc reply = (String JavaDoc)server.invoke(
68                objectName,
69                "echo",
70                new Object JavaDoc[] { message },
71                new String JavaDoc[] { "java.lang.String" });
72          
73          assertEquals(message, reply);
74          
75          server.unregisterMBean(objectName);
76       }
77       catch (Exception JavaDoc e)
78       {
79          log.debug("Unexpected Exception", e);
80          fail("Caught unexpected exception");
81       }
82    }
83 }
84
Popular Tags