KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > kernel > admin > DistributedJMXServerTest


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: DistributedJMXServerTest.java 9:31:38 AM ddesjardins $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.kernel.admin;
23
24 import java.io.IOException JavaDoc;
25 import java.util.Hashtable JavaDoc;
26 import java.util.Set JavaDoc;
27 import java.util.TreeSet 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 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 /**
45  * Test of the DistributedJMXServer
46  *
47  * @author ddesjardins - eBMWebsourcing
48  */

49 public class DistributedJMXServerTest extends TestCase {
50
51     public void testGetAdminServiceMBeanName() throws IOException JavaDoc,
52         MalformedObjectNameException JavaDoc, NullPointerException JavaDoc {
53         JMXConnector JavaDoc connector = EasyMock.createMock(JMXConnector JavaDoc.class);
54
55         MBeanServerConnection JavaDoc connection = EasyMock
56                 .createMock(MBeanServerConnection JavaDoc.class);
57
58         Set JavaDoc<ObjectName JavaDoc> names = new TreeSet JavaDoc<ObjectName JavaDoc>();
59         ObjectName JavaDoc adName = new ObjectName JavaDoc("Petals:type=service");
60         names.add(adName);
61
62         Hashtable JavaDoc<String JavaDoc, String JavaDoc> attrs = new Hashtable JavaDoc<String JavaDoc, String JavaDoc>();
63         attrs.put("name", "Admin");
64         attrs.put("type", "service");
65         ObjectName JavaDoc objName = new ObjectName JavaDoc("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 JavaDoc adminName = distributedJMXServer.getAdminServiceMBeanName();
79         assertEquals(adName, adminName);
80     }
81
82     public void testInvoke() throws IOException JavaDoc, MalformedObjectNameException JavaDoc,
83         NullPointerException JavaDoc, InstanceNotFoundException JavaDoc, MBeanException JavaDoc,
84         ReflectionException JavaDoc {
85         MBeanServerConnection JavaDoc connection = EasyMock
86                 .createMock(MBeanServerConnection JavaDoc.class);
87         JMXConnector JavaDoc connector = EasyMock.createMock(JMXConnector JavaDoc.class);
88
89         ObjectName JavaDoc adminName = new ObjectName JavaDoc(
90                 "FC/Petals/jbi/admin-impl@1111:itf=service");
91
92         Object JavaDoc[] objs = new Object JavaDoc[0];
93         String JavaDoc[] args = new String JavaDoc[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 JavaDoc) distributedJMXServer.invoke(adminName, "test",
106                 objs, args)).booleanValue());
107     }
108
109 }
110
Popular Tags