1 22 package org.objectweb.petals.kernel.admin; 23 24 import java.io.IOException ; 25 import java.util.Hashtable ; 26 import java.util.Set ; 27 import java.util.TreeSet ; 28 29 import javax.management.InstanceNotFoundException ; 30 import javax.management.MBeanException ; 31 import javax.management.MBeanServerConnection ; 32 import javax.management.MalformedObjectNameException ; 33 import javax.management.ObjectName ; 34 import javax.management.ReflectionException ; 35 import javax.management.remote.JMXConnector ; 36 37 import junit.framework.TestCase; 38 39 import org.easymock.classextension.EasyMock; 40 41 import static org.easymock.EasyMock.expect; 42 import static org.easymock.classextension.EasyMock.replay; 43 44 49 public class DistributedJMXServerTest extends TestCase { 50 51 public void testGetAdminServiceMBeanName() throws IOException , 52 MalformedObjectNameException , NullPointerException { 53 JMXConnector connector = EasyMock.createMock(JMXConnector .class); 54 55 MBeanServerConnection connection = EasyMock 56 .createMock(MBeanServerConnection .class); 57 58 Set <ObjectName > names = new TreeSet <ObjectName >(); 59 ObjectName adName = new ObjectName ("Petals:type=service"); 60 names.add(adName); 61 62 Hashtable <String , String > attrs = new Hashtable <String , String >(); 63 attrs.put("name", "Admin"); 64 attrs.put("type", "service"); 65 ObjectName objName = new ObjectName ("Petals", attrs); 66 67 expect(connection.queryNames(objName, null)).andReturn(names) 68 .anyTimes(); 69 connector.connect(); 70 expect(connector.getMBeanServerConnection()).andReturn(connection) 71 .anyTimes(); 72 73 replay(connection); 74 replay(connector); 75 76 DistributedJMXServer distributedJMXServer = new DistributedJMXServer( 77 connector); 78 ObjectName adminName = distributedJMXServer.getAdminServiceMBeanName(); 79 assertEquals(adName, adminName); 80 } 81 82 public void testInvoke() throws IOException , MalformedObjectNameException , 83 NullPointerException , InstanceNotFoundException , MBeanException , 84 ReflectionException { 85 MBeanServerConnection connection = EasyMock 86 .createMock(MBeanServerConnection .class); 87 JMXConnector connector = EasyMock.createMock(JMXConnector .class); 88 89 ObjectName adminName = new ObjectName ( 90 "FC/Petals/jbi/admin-impl@1111:itf=service"); 91 92 Object [] objs = new Object [0]; 93 String [] args = new String [0]; 94 expect(connection.invoke(adminName, "test", objs, args)).andReturn( 95 Boolean.TRUE).anyTimes(); 96 connector.connect(); 97 expect(connector.getMBeanServerConnection()).andReturn(connection) 98 .anyTimes(); 99 100 replay(connection); 101 replay(connector); 102 103 DistributedJMXServer distributedJMXServer = new DistributedJMXServer( 104 connector); 105 assertTrue(((Boolean ) distributedJMXServer.invoke(adminName, "test", 106 objs, args)).booleanValue()); 107 } 108 109 } 110 | Popular Tags |