001 // jademx - JADE management using JMX
002 // Copyright 2005 Caboodle Networks, Inc.
003 //
004 // This library is free software; you can redistribute it and/or
005 // modify it under the terms of the GNU Lesser General Public
006 // License as published by the Free Software Foundation; either
007 // version 2.1 of the License, or (at your option) any later version.
008 //
009 // This library is distributed in the hope that it will be useful,
010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 // Lesser General Public License for more details.
013 //
014 // You should have received a copy of the GNU Lesser General Public
015 // License along with this library; if not, write to the Free Software
016 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
017
018 package jade.jademx.server;
019
020 import javax.management.MBeanServer;
021
022 import jade.jademx.JadeMXSuiteTest;
023 import junit.framework.Test;
024 import junit.framework.TestCase;
025 import junit.framework.TestSuite;
026
027 /**
028 * StaticMethod class test
029 * @author David Bernstein, <a href="http://www.caboodlenetworks.com"
030 * >Caboodle Networks, Inc.</a>
031 */
032 public class StaticMethodTest extends TestCase {
033
034 // tests
035
036 /** a class for testing StaticMethod */
037 private static class StaticMethodSubclass extends StaticMethod {
038 /** default constructor */
039 public StaticMethodSubclass() {
040 this("foo");
041 }
042 /**
043 * constructor where can set method name
044 * @param methodName method to use for getting mbean server
045 */
046 public StaticMethodSubclass( String methodName ) {
047 super(
048 StaticMethodSubclass.class.getName(),
049 methodName,
050 new Class[] { String.class, String.class },
051 new Object[] { "baz", "quux" }
052 );
053 }
054 /**
055 * default method to use for getting mbean server
056 * @param a dummy
057 * @param b dummy
058 * @return null mbean server
059 */
060 public static MBeanServer foo( String a, String b ) {
061 return null;
062 }
063 /**
064 * exception-raising method to use for getting mbean server
065 * @param a dummy
066 * @param b dummy
067 * @throws RuntimeException always
068 * @return by throwing exception
069 */
070 public static MBeanServer bar( String a, String b ) {
071 throw new RuntimeException("intentional runtime exception for testing");
072 }
073 }
074
075
076 /**
077 * test toString() for StaticMethod
078 */
079 public void testStaticMethodToString() {
080 StaticMethod sm = new StaticMethodSubclass();
081 assertEquals(
082 "jade.jademx.server.StaticMethodTest.StaticMethodSubclass"+
083 "[jade.jademx.server.StaticMethodTest$StaticMethodSubclass."+
084 "foo(java.lang.String baz, java.lang.String quux)]",
085 sm.toString());
086 }
087
088 /**
089 * test getting mbean server with no issues
090 */
091 public void testStaticMethodGetMBeanServer() {
092 StaticMethod sm = new StaticMethodSubclass();
093 assertNull( sm.getMBeanServer() );
094 }
095
096
097 /**
098 * test getting mbean server with exception raised
099 */
100 public void testStaticMethodGetMBeanServerException() {
101 try {
102 new StaticMethodSubclass("bar");
103 fail("expected exception not raised");
104 }
105 catch ( RuntimeException re ) {
106 assertTrue(true);
107 }
108 }
109
110
111 // suite
112
113 /**
114 * return the implicit suite of tests
115 * @return the implicit suite of tests
116 */
117 public static Test suite() {
118 return new TestSuite(
119 StaticMethodTest.class,
120 JadeMXSuiteTest.nameWithClass( StaticMethodTest.class,
121 "testing StaticMethod: finding MBeanServer via static method") );
122 }
123
124
125
126 }