KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > jbi > management > service > mock > MockDistributedJMXServer


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2005 EBM Websourcing, http://www.ebmwebsourcing.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id: MockDistributedJMXServer.java 11:34:05 AM ddesjardins $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.jbi.management.service.mock;
23
24 import java.io.DataInputStream JavaDoc;
25 import java.io.File JavaDoc;
26 import java.io.FileInputStream JavaDoc;
27 import java.io.IOException JavaDoc;
28
29 import javax.management.InstanceNotFoundException JavaDoc;
30 import javax.management.MBeanException JavaDoc;
31 import javax.management.MBeanServerConnection JavaDoc;
32 import javax.management.MalformedObjectNameException JavaDoc;
33 import javax.management.ObjectName JavaDoc;
34 import javax.management.ReflectionException JavaDoc;
35 import javax.management.remote.JMXConnector JavaDoc;
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 /**
42  * Mock object of the DistributedJMXServer
43  *
44  * @author ddesjardins - eBMWebsourcing
45  */

46 public class MockDistributedJMXServer extends DistributedJMXServer {
47
48     private boolean getAdminServiceMBeanName;
49
50     private boolean invoke;
51
52     public MockDistributedJMXServer(MBeanServerConnection JavaDoc connection) {
53         super(EasyMock.createMock(JMXConnector JavaDoc.class));
54     }
55
56     public ObjectName JavaDoc getAdminServiceMBeanName() throws IOException JavaDoc,
57         MalformedObjectNameException JavaDoc, NullPointerException JavaDoc {
58         getAdminServiceMBeanName = true;
59         return null;
60     }
61
62     public Object JavaDoc invoke(ObjectName JavaDoc name, String JavaDoc operationName,
63         Object JavaDoc[] params, String JavaDoc[] signature) throws InstanceNotFoundException JavaDoc,
64         MBeanException JavaDoc, ReflectionException JavaDoc, IOException JavaDoc {
65         invoke = true;
66         if (operationName.equals(DistributedJMXServer.GET_SERVICE_DESCRITION)) {
67             String JavaDoc baseDir = this.getClass().getResource(".").toString();
68             baseDir = baseDir.substring(0, baseDir.indexOf("target"));
69             baseDir = baseDir.substring(baseDir.indexOf(":") + 1);
70             DataInputStream JavaDoc dis = new DataInputStream JavaDoc(new FileInputStream JavaDoc(
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 JavaDoc(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