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.agent; 019 020 import javax.management.Attribute; 021 import javax.management.AttributeList; 022 023 import jade.jademx.JadeMXSuiteTest; 024 import jade.jademx.mbean.JadeAgent; 025 import jade.jademx.mbean.JadeFactory; 026 import jade.jademx.mbean.JadePlatform; 027 import jade.jademx.mbean.JadeRuntime; 028 import jade.jademx.mbean.JademxException; 029 import jade.jademx.server.JadeMXServer; 030 import jade.jademx.server.JadeMXServerFactory; 031 import junit.framework.Test; 032 import junit.framework.TestCase; 033 import junit.framework.TestSuite; 034 035 /** 036 * JadeAgent MBean test 037 * @author David Bernstein, <a href="http://www.caboodlenetworks.com" 038 * >Caboodle Networks, Inc.</a> 039 */ 040 public class JademxAgentTest extends TestCase { 041 042 ///** test(suite) name */ 043 //private static String name = 044 // JadeMXSuiteTest.nameWithClass( 045 // JademxAgentTest.class, 046 // "testing JadeAgent: JADE agent MBean class"); 047 048 049 /** jadeMXServer we're using */ 050 private JadeMXServer jadeMXServer = null; 051 052 /** runtime for test use */ 053 private JadeRuntime jadeRuntime = null; 054 055 /** mbean for platform under test */ 056 JadePlatform platformMBean = null; 057 058 /** resource name for configuration of one nop agent */ 059 private static final String ONE_BASE_CONFIG_RESOURCE = 060 "jade/jademx/config/one-base-agent.xml"; 061 062 /** name for dummy agent */ 063 private static final String AGENT_LOCAL_NAME_DUMMY = "dummy"; 064 065 066 // tests 067 068 069 /* (non-Javadoc) 070 * @see junit.framework.TestCase#setUp() 071 */ 072 protected void setUp() throws Exception { 073 // first get JadeMXServer 074 jadeMXServer = JadeMXServerFactory.jadeMXServerBySysProp(); 075 // now get a factory to use 076 JadeFactory jadeFactory = 077 new JadeFactory( jadeMXServer ); 078 jadeRuntime = (JadeRuntime)jadeFactory.runtimeInstance(); 079 //JadeMXSuiteTest.listMBeans(mBeanServer, "at end of setUp()"); 080 JadePlatform platformMBeans[] = 081 jadeRuntime.platformsFromConfigResource( 082 ONE_BASE_CONFIG_RESOURCE ); 083 platformMBean = platformMBeans[0]; 084 } 085 086 087 088 /* (non-Javadoc) 089 * @see junit.framework.TestCase#tearDown() 090 */ 091 protected void tearDown() throws Exception { 092 //JadeMXSuiteTest.listMBeans(mBeanServer, 093 //"at start of JadePlatformTest.tearDown()"); 094 if ( null != jadeRuntime ) { 095 jadeRuntime.shutdown(); 096 } 097 //JadeMXSuiteTest.listMBeans(mBeanServer, 098 //"at end of JadePlatformTest.tearDown()"); 099 } 100 101 /** 102 * run the NOP agent, which exercises base class code during setup 103 * @throws JademxException 104 */ 105 public void testJademxAgentBase() throws JademxException { 106 JadeAgent jadeAgent = platformMBean.getAgent( AGENT_LOCAL_NAME_DUMMY ); 107 boolean bound = jadeAgent.waitForJademxAgentBinding(59*1000/*59sec*/,0); 108 assertTrue(bound); 109 AttributeList aList = jadeAgent.getAttributes( new String[0]); 110 assertEquals("expected empty attribute list but is size "+aList.size(), 111 0,aList.size()); 112 jadeAgent.setAttributes( aList ); 113 try { 114 aList = new AttributeList( 1 ); 115 aList.add( new Attribute("foo","bar")); 116 jadeAgent.setAttributes( aList ); 117 fail("didn't get exception trying to set non-existent attribute"); 118 } 119 catch ( RuntimeException re ) { 120 assertTrue(true); 121 } 122 123 } 124 125 // suite 126 127 /** 128 * return the implicit suite of tests 129 * @return the implicit suite of tests 130 */ 131 public static Test suite() { 132 return new TestSuite( 133 JademxAgentTest.class, 134 JadeMXSuiteTest.nameWithClass( JademxAgentTest.class, 135 "testing JademxAgent: jademx agent superclass") ); 136 } 137 138 139 140 }