1 22 package org.objectweb.petals.kernel.admin; 23 24 import javax.naming.Context ; 25 import javax.naming.InitialContext ; 26 import javax.naming.NameClassPair ; 27 import javax.naming.NamingException ; 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 44 public class DistributedJMXServerManagerImplTest extends TestCase { 45 46 private DistributedJMXServerFactoryImpl distributedJMXServerManagerImpl = new DistributedJMXServerFactoryImpl(); 47 48 public void setUp() throws Exception { 49 distributedJMXServerManagerImpl.log = new LoggingUtil(Monolog 50 .initialize().getLogger("test")); 51 } 52 53 public void testCreateDistributedJMXServer() throws Exception { 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 { 73 DistributedJMXServerFactoryImpl distributedJMXServerFactoryImpl = new DistributedJMXServerFactoryImpl(); 74 LoggingUtil loggingUtil = EasyMock.createMock(LoggingUtil.class); 75 InitialContext initialContext = EasyMock 76 .createMock(InitialContext .class); 77 Context contContext = EasyMock.createMock(Context .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 >( 84 new NameClassPair [] {new NameClassPair ("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 |