1 22 package org.objectweb.petals.jbi.management.service.mock; 23 24 import java.io.DataInputStream ; 25 import java.io.File ; 26 import java.io.FileInputStream ; 27 import java.io.IOException ; 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 org.easymock.classextension.EasyMock; 38 import org.objectweb.petals.kernel.admin.DistributedJMXServer; 39 import org.objectweb.petals.tools.jbicommon.util.XMLUtil; 40 41 46 public class MockDistributedJMXServer extends DistributedJMXServer { 47 48 private boolean getAdminServiceMBeanName; 49 50 private boolean invoke; 51 52 public MockDistributedJMXServer(MBeanServerConnection connection) { 53 super(EasyMock.createMock(JMXConnector .class)); 54 } 55 56 public ObjectName getAdminServiceMBeanName() throws IOException , 57 MalformedObjectNameException , NullPointerException { 58 getAdminServiceMBeanName = true; 59 return null; 60 } 61 62 public Object invoke(ObjectName name, String operationName, 63 Object [] params, String [] signature) throws InstanceNotFoundException , 64 MBeanException , ReflectionException , IOException { 65 invoke = true; 66 if (operationName.equals(DistributedJMXServer.GET_SERVICE_DESCRITION)) { 67 String baseDir = this.getClass().getResource(".").toString(); 68 baseDir = baseDir.substring(0, baseDir.indexOf("target")); 69 baseDir = baseDir.substring(baseDir.indexOf(":") + 1); 70 DataInputStream dis = new DataInputStream (new FileInputStream ( 71 baseDir + "src" + File.separator + "test-data" + File.separator 72 + "wsdl" + File.separator + "HelloworldService.wsdl")); 73 byte[] bytes = new byte[dis.available()]; 74 dis.readFully(bytes); 75 dis.close(); 76 return XMLUtil.createDocumentFromString(new String (bytes)); 77 } else if (operationName.equals(DistributedJMXServer.IS_OK_WITH_CONS)) { 78 return Boolean.TRUE; 79 } else if (operationName.equals(DistributedJMXServer.IS_OK_WITH_PROV)) { 80 return Boolean.TRUE; 81 } 82 return null; 83 } 84 85 public boolean isGetAdminServiceMBeanName() { 86 return getAdminServiceMBeanName; 87 } 88 89 public boolean isInvoke() { 90 return invoke; 91 } 92 93 public void setGetAdminServiceMBeanName(boolean getAdminServiceMBeanName) { 94 this.getAdminServiceMBeanName = getAdminServiceMBeanName; 95 } 96 97 public void setInvoke(boolean invoke) { 98 this.invoke = invoke; 99 } 100 101 } 102 | Popular Tags |