KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > kernel > mx4j > MX4JHtmlAdaptorTest


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_HtmlAdaptorTest.java 15:05:03 ddesjardins $
20  * -------------------------------------------------------------------------
21  */

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 /**
34  * Test the MX4JHtmlAdaptor
35  *
36  * @author ddesjardins - eBMWebsourcing
37  */

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 JavaDoc runtimeException = new RuntimeException JavaDoc("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 JavaDoc runtimeException = new RuntimeException JavaDoc(
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