KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > kernel > jmx > RMIConnectorTest


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: MX4J_RMIAdaptorTest.java 14:59:06 ddesjardins $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.kernel.jmx;
23
24 import java.io.IOException JavaDoc;
25
26 import javax.management.remote.JMXConnectorServer JavaDoc;
27 import javax.management.remote.JMXServiceURL JavaDoc;
28
29 import junit.framework.TestCase;
30
31 import org.easymock.classextension.EasyMock;
32 import org.objectweb.fractal.jmx.agent.AdminAttributes;
33 import org.objectweb.petals.kernel.mx4j.mock.MockMBeanServer;
34 import org.objectweb.petals.util.LoggingUtil;
35 import org.objectweb.petals.util.SystemUtil;
36
37 /**
38  * Test the MX4JRMIAdaptor
39  *
40  * @author ddesjardins - eBMWebsourcing
41  */

42 public class RMIConnectorTest extends TestCase {
43
44     protected RMIConnector adaptor;
45
46     public void setUp() {
47         adaptor = new RMIConnector();
48     }
49
50     public void testStartReturn() throws IOException JavaDoc {
51         JMXConnectorServer JavaDoc connectorServer = EasyMock
52             .createMock(JMXConnectorServer JavaDoc.class);
53         LoggingUtil loggingUtil = EasyMock.createMock(LoggingUtil.class);
54         JMXServiceURL JavaDoc jmxUrl = EasyMock.createMock(JMXServiceURL JavaDoc.class);
55
56         loggingUtil.start();
57         EasyMock.expect(connectorServer.isActive()).andReturn(Boolean.TRUE);
58         EasyMock.expect(connectorServer.getAddress()).andReturn(jmxUrl);
59         connectorServer.stop();
60         EasyMock.expect(jmxUrl.getPort()).andReturn(8081);
61
62         EasyMock.replay(connectorServer);
63         EasyMock.replay(loggingUtil);
64         EasyMock.replay(jmxUrl);
65
66         adaptor.log = loggingUtil;
67         SystemUtil.setJmxPort("8081");
68         adaptor.cs = connectorServer;
69
70         adaptor.start();
71     }
72
73     public void testStartStop() {
74         adaptor.log = EasyMock.createMock(LoggingUtil.class);
75         AdminAttributes adminAttributes = EasyMock
76             .createMock(AdminAttributes.class);
77         MockMBeanServer mockMBeanServer = new MockMBeanServer();
78         EasyMock.expect(adminAttributes.getRawMBeanServer()).andReturn(
79             mockMBeanServer).anyTimes();
80         EasyMock.replay(adminAttributes);
81         adaptor.adminAttributes = adminAttributes;
82         adaptor.start();
83         adaptor.stop();
84     }
85
86     public void testStartStopStart() throws IOException JavaDoc {
87         SystemUtil.setHost("127.0.0.1");
88
89         JMXConnectorServer JavaDoc connectorServer = EasyMock
90             .createMock(JMXConnectorServer JavaDoc.class);
91         LoggingUtil loggingUtil = EasyMock.createMock(LoggingUtil.class);
92         JMXServiceURL JavaDoc jmxUrl = EasyMock.createMock(JMXServiceURL JavaDoc.class);
93         AdminAttributes adminAttributes = EasyMock
94             .createMock(AdminAttributes.class);
95         RuntimeException JavaDoc runtimeException = new RuntimeException JavaDoc();
96
97         loggingUtil.start();
98         EasyMock.expect(connectorServer.isActive()).andReturn(Boolean.TRUE);
99         EasyMock.expect(connectorServer.getAddress()).andReturn(jmxUrl);
100         connectorServer.stop();
101         EasyMock.expect(jmxUrl.getPort()).andReturn(8080);
102         EasyMock.expect(adminAttributes.getRawMBeanServer()).andThrow(
103             runtimeException);
104         loggingUtil.error(
105             "Error during the instanciation of the MX4J RMI adaptor:",
106             runtimeException);
107         loggingUtil.end();
108
109         EasyMock.replay(connectorServer);
110         EasyMock.replay(loggingUtil);
111         EasyMock.replay(jmxUrl);
112         EasyMock.replay(adminAttributes);
113
114         adaptor.log = loggingUtil;
115         adaptor.adminAttributes = adminAttributes;
116         SystemUtil.setJmxPort("8081");
117         adaptor.cs = connectorServer;
118
119         adaptor.start();
120     }
121 }
122
Popular Tags