1 22 package org.objectweb.petals.kernel.mx4j; 23 24 import junit.framework.TestCase; 25 import mx4j.tools.adaptor.http.HttpAdaptorMBean; 26 27 import org.easymock.classextension.EasyMock; 28 import org.objectweb.fractal.jmx.agent.AdminAttributes; 29 import org.objectweb.petals.kernel.mx4j.mock.MockMBeanServer; 30 import org.objectweb.petals.util.LoggingUtil; 31 import org.objectweb.petals.util.SystemUtil; 32 33 38 public class MX4JHtmlAdaptorTest extends TestCase { 39 40 protected MX4JHtmlAdaptor adaptor; 41 42 public void setUp() { 43 adaptor = new MX4JHtmlAdaptor(); 44 } 45 46 public void testStartStop() { 47 AdminAttributes adminAttributes = EasyMock 48 .createMock(AdminAttributes.class); 49 MockMBeanServer mockMBeanServer = new MockMBeanServer(); 50 EasyMock.expect(adminAttributes.getRawMBeanServer()).andReturn( 51 mockMBeanServer).anyTimes(); 52 EasyMock.replay(adminAttributes); 53 adaptor.adminAttributes = adminAttributes; 54 adaptor.log = EasyMock.createMock(LoggingUtil.class); 55 adaptor.start(); 56 assertTrue(mockMBeanServer.isRegisterMBean()); 57 adaptor.stop(); 58 assertTrue(mockMBeanServer.isUnregisterMBean()); 59 } 60 61 public void testStartFcAlreadyStarted() { 62 SystemUtil.setHtmlPort("8082"); 63 64 HttpAdaptorMBean httpAdaptorMBean = EasyMock 65 .createMock(HttpAdaptorMBean.class); 66 67 EasyMock.expect(httpAdaptorMBean.isActive()).andReturn(Boolean.TRUE); 68 EasyMock.expect(httpAdaptorMBean.getPort()).andReturn(8082); 69 70 EasyMock.replay(httpAdaptorMBean); 71 72 adaptor.adaptor = httpAdaptorMBean; 73 adaptor.log = EasyMock.createMock(LoggingUtil.class); 74 75 adaptor.start(); 76 } 77 78 public void testStartStopAdaptor() { 79 HttpAdaptorMBean httpAdaptorMBean = EasyMock 80 .createMock(HttpAdaptorMBean.class); 81 LoggingUtil log = EasyMock.createMock(LoggingUtil.class); 82 AdminAttributes adminAttributes = EasyMock 83 .createMock(AdminAttributes.class); 84 RuntimeException runtimeException = new RuntimeException ("test error"); 85 86 EasyMock.expect(httpAdaptorMBean.isActive()).andReturn(Boolean.FALSE); 87 httpAdaptorMBean.stop(); 88 log.start(); 89 EasyMock.expect(adminAttributes.getRawMBeanServer()).andThrow( 90 runtimeException); 91 log.error("Fail to start HTML adaptor", runtimeException); 92 log.end(); 93 94 EasyMock.replay(log); 95 EasyMock.replay(httpAdaptorMBean); 96 EasyMock.replay(adminAttributes); 97 98 adaptor.adaptor = httpAdaptorMBean; 99 adaptor.log = log; 100 adaptor.adminAttributes = adminAttributes; 101 102 adaptor.start(); 103 } 104 105 public void testStopException() { 106 AdminAttributes adminAttributes = EasyMock 107 .createMock(AdminAttributes.class); 108 LoggingUtil log = EasyMock.createMock(LoggingUtil.class); 109 RuntimeException runtimeException = new RuntimeException ( 110 "test exception"); 111 112 log.start(); 113 EasyMock.expect(adminAttributes.getRawMBeanServer()).andThrow( 114 runtimeException); 115 log.warning("Error during MBean unregistering: test exception", 116 runtimeException); 117 log.end(); 118 119 EasyMock.replay(adminAttributes); 120 EasyMock.replay(log); 121 122 adaptor.adaptor = EasyMock.createMock(HttpAdaptorMBean.class); 123 adaptor.log = log; 124 adaptor.adminAttributes = adminAttributes; 125 126 adaptor.stop(); 127 } 128 129 } 130 | Popular Tags |