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;
019
020 import java.util.Iterator;
021
022 import javax.management.MBeanServer;
023 import javax.management.ObjectName;
024
025 import junit.framework.Test;
026 import junit.framework.TestSuite;
027
028 import jade.jademx.agent.AgentSuiteTest;
029 import jade.jademx.config.ConfigSuiteTest;
030 import jade.jademx.mbean.MBeanSuiteTest;
031 import jade.jademx.server.JadeMXServerFactory;
032 import jade.jademx.server.ServerSuiteTest;
033 import jade.jademx.unit.UnitSuiteTest;
034 import jade.jademx.util.UtilSuiteTest;
035 import jade.util.Logger;
036
037 /**
038 * test suite for jademx
039 * @author David Bernstein
040 */
041 public class JadeMXSuiteTest extends TestSuite {
042
043 /**
044 * make a JadeMXSuiteTest
045 */
046 public JadeMXSuiteTest() {
047 super("jademx JUnit test suite, " +
048 JadeMXServerFactory.SERVER_TYPE_PROPERTY + "=" +
049 JadeMXServerFactory.serverClassName() );
050 }
051
052
053 /**
054 * factory for creating suite of tests
055 * @return test suite
056 */
057 public static Test suite() {
058 TestSuite suite =
059 new TestSuite(
060 nameWithClass( JadeMXSuiteTest.class,
061 "jade.jademx.server package" ) );
062 suite.addTest( UtilSuiteTest.suite() );
063 suite.addTest( ConfigSuiteTest.suite() );
064 suite.addTest( ServerSuiteTest.suite() );
065 suite.addTest( MBeanSuiteTest.suite() );
066 suite.addTest( AgentSuiteTest.suite() );
067 suite.addTest( UnitSuiteTest.suite() );
068 return suite;
069 }
070
071
072 // helper methods
073
074 /**
075 * convenience method to append classname to a name
076 * @param theClass class to make expanded name for
077 * @param simpleName simple name for test suite
078 * @return simpleName-param (theClass-param.getName)
079 */
080 public static String nameWithClass( Class theClass, String simpleName ) {
081 StringBuffer sb = new StringBuffer();
082 sb.append( simpleName );
083 sb.append( " (" );
084 sb.append( theClass.getName() );
085 sb.append( ")" );
086 return sb.toString();
087 }
088
089
090 /** my logger */
091 private static final Logger logger =
092 Logger.getMyLogger(JadeMXSuiteTest.class.getName());
093 /** list out current mbeans */
094 public static void listMBeans( MBeanServer mBeanServer, String msg) {
095 StringBuffer sb = new StringBuffer();
096 sb.append( "<<<\n" );
097 sb.append( msg + "\n");
098 if ( null == mBeanServer ) {
099 sb.append( "null MBeanServer\n" );
100 }
101 else {
102 Iterator mBeanNameIter = mBeanServer.queryNames( null, null ).iterator();
103 int mBeanNameCount = 0;
104 while ( mBeanNameIter.hasNext() ) {
105 ObjectName mBeanName = (ObjectName)mBeanNameIter.next();
106 String name = mBeanName.getCanonicalName();
107 if ( !name.startsWith("java.")) {
108 mBeanNameCount++;
109 sb.append( mBeanNameCount+". "+name+"\n");
110 }
111 }
112 }
113 sb.append( ">>>" );
114 logger.log( Logger.INFO, sb.toString() );
115 }
116
117 }