KickJava   Java API By Example, From Geeks To Geeks.

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


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: DistributedJMXServerManagerImplTest.java 14:10:53 ddesjardins $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.kernel.admin;
23
24 import javax.naming.Context JavaDoc;
25 import javax.naming.InitialContext JavaDoc;
26 import javax.naming.NameClassPair JavaDoc;
27 import javax.naming.NamingException JavaDoc;
28
29 import junit.framework.TestCase;
30
31 import org.easymock.classextension.EasyMock;
32 import org.objectweb.petals.jbi.registry.mock.MockContext;
33 import org.objectweb.petals.kernel.admin.ContainerInformation.ContainerState;
34 import org.objectweb.petals.kernel.admin.util.ServerUtil;
35 import org.objectweb.petals.kernel.registry.jndi.NamingEnumerationImpl;
36 import org.objectweb.petals.util.LoggingUtil;
37 import org.objectweb.util.monolog.Monolog;
38
39 /**
40  * Test of the DistributedJMXServerManagerImpl
41  *
42  * @author ddesjardins - eBMWebsourcing
43  */

44 public class DistributedJMXServerManagerImplTest extends TestCase {
45
46     private DistributedJMXServerFactoryImpl distributedJMXServerManagerImpl = new DistributedJMXServerFactoryImpl();
47
48     public void setUp() throws Exception JavaDoc {
49         distributedJMXServerManagerImpl.log = new LoggingUtil(Monolog
50             .initialize().getLogger("test"));
51     }
52
53     public void testCreateDistributedJMXServer() throws Exception JavaDoc {
54         ServerUtil.start(9999);
55         MockContext containers = new MockContext();
56         ContainerInformation containerInformation = new ContainerInformation();
57         containerInformation.setHost("localhost");
58         containerInformation.setJmxLogin("");
59         containerInformation.setJmxPassword("");
60         containerInformation.setName("0");
61         containerInformation.setJmxPort("9999");
62         containers.bind("0", containerInformation);
63         distributedJMXServerManagerImpl.containersContext = containers;
64
65         assertNotNull(distributedJMXServerManagerImpl
66             .createDistributedJMXServer("0"));
67         ServerUtil.stop();
68     }
69
70     
71
72     public void testIsContainerStarted() throws NamingException JavaDoc {
73         DistributedJMXServerFactoryImpl distributedJMXServerFactoryImpl = new DistributedJMXServerFactoryImpl();
74         LoggingUtil loggingUtil = EasyMock.createMock(LoggingUtil.class);
75         InitialContext JavaDoc initialContext = EasyMock
76             .createMock(InitialContext JavaDoc.class);
77         Context JavaDoc contContext = EasyMock.createMock(Context JavaDoc.class);
78         ContainerInformation containerInformation = new ContainerInformation();
79         containerInformation.setState(ContainerState.STARTED);
80
81         loggingUtil.start();
82         EasyMock.expect(initialContext.list("containers")).andReturn(
83             new NamingEnumerationImpl<NameClassPair JavaDoc>(
84                 new NameClassPair JavaDoc[] {new NameClassPair JavaDoc("test", "foo")}));
85         EasyMock.expect(contContext.lookup("test")).andReturn(
86             containerInformation);
87         loggingUtil.end();
88
89         EasyMock.replay(loggingUtil);
90         EasyMock.replay(contContext);
91         EasyMock.replay(initialContext);
92
93         distributedJMXServerFactoryImpl.containersContext = contContext;
94         distributedJMXServerFactoryImpl.log = loggingUtil;
95         distributedJMXServerFactoryImpl.rootContext = initialContext;
96
97         assertTrue(distributedJMXServerFactoryImpl.isContainerStarted("test"));
98     }
99 }
100
Popular Tags