1 22 package org.objectweb.petals.kernel.jmx; 23 24 import java.io.IOException ; 25 26 import javax.management.remote.JMXConnectorServer ; 27 import javax.management.remote.JMXServiceURL ; 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 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 { 51 JMXConnectorServer connectorServer = EasyMock 52 .createMock(JMXConnectorServer .class); 53 LoggingUtil loggingUtil = EasyMock.createMock(LoggingUtil.class); 54 JMXServiceURL jmxUrl = EasyMock.createMock(JMXServiceURL .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 { 87 SystemUtil.setHost("127.0.0.1"); 88 89 JMXConnectorServer connectorServer = EasyMock 90 .createMock(JMXConnectorServer .class); 91 LoggingUtil loggingUtil = EasyMock.createMock(LoggingUtil.class); 92 JMXServiceURL jmxUrl = EasyMock.createMock(JMXServiceURL .class); 93 AdminAttributes adminAttributes = EasyMock 94 .createMock(AdminAttributes.class); 95 RuntimeException runtimeException = new RuntimeException (); 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 |