1 22 package org.objectweb.petals.jbi.transport; 23 24 import java.io.File ; 25 import java.io.IOException ; 26 import java.lang.reflect.Method ; 27 import java.util.ArrayList ; 28 import java.util.List ; 29 30 import junit.framework.TestCase; 31 32 import org.easymock.classextension.EasyMock; 33 import org.objectweb.fractal.api.control.IllegalLifeCycleException; 34 35 import org.objectweb.petals.PetalsException; 36 import org.objectweb.petals.kernel.admin.ContainerInformation; 37 import org.objectweb.petals.util.LoggingUtil; 38 import org.objectweb.petals.util.SystemUtil; 39 40 45 public class JoramAgentTest extends TestCase { 46 47 protected JoramAgent agentImpl; 48 49 protected String baseDir; 50 51 public void setUp() { 52 agentImpl = new JoramAgent(new LoggingUtil(null)); 53 baseDir = this.getClass().getResource(".").toString(); 54 baseDir = baseDir.substring(0, baseDir.indexOf("target")); 55 baseDir = baseDir.substring(baseDir.indexOf(":") + 1); 56 new File (baseDir + "target" + File.separator + "lib").mkdir(); 57 new File (baseDir + "target" + File.separator + "lib" + File.separator 58 + "petals-1.0-SNAPSHOT.jar").mkdir(); 59 System.setProperty("petals.home", baseDir + "target"); 60 } 61 62 public void testInitConfiguration() throws IOException { 63 agentImpl.initConfiguration(); 64 assertNotNull(agentImpl.factory); 65 } 66 67 80 public void testStop() throws IllegalLifeCycleException, SecurityException , 81 NoSuchMethodException { 82 JoramAgent agentImpl = EasyMock.createMock(JoramAgent.class, 83 new Method [] { 84 JoramAgent.class.getDeclaredMethod("initJoramAgentServer", 85 new Class [] {}), 86 JoramAgent.class.getDeclaredMethod("startJoramAgentServer", 87 new Class [] {})}); 88 agentImpl.log = EasyMock.createMock(LoggingUtil.class); 89 agentImpl.stopServer(); 90 } 91 92 121 public void testStartServerException() throws SecurityException , 122 NoSuchMethodException , IOException { 123 SystemUtil.setJoramId("0"); 124 SystemUtil.setHost("127.0.0.1"); 125 SystemUtil.setJoramTCPPort("16200"); 126 SystemUtil.setJoramDomainPort("16300"); 127 128 agentImpl = EasyMock.createMock(JoramAgent.class, new Method [] { 129 JoramAgent.class.getDeclaredMethod( 130 "retrieveDistributedConfiguration", new Class [0]), 131 JoramAgent.class.getDeclaredMethod( 132 "retrieveAllContainersInformation", new Class [0])}); 133 LoggingUtil log = EasyMock.createNiceMock(LoggingUtil.class); 134 135 RuntimeException runtimeException = new RuntimeException (); 136 137 EasyMock.expect(agentImpl.retrieveDistributedConfiguration()).andThrow( 138 runtimeException).anyTimes(); 139 log.error("Problem while starting the Joram server", runtimeException); 140 List <ContainerInformation> conts = new ArrayList <ContainerInformation>(); 141 conts.add(null); 142 conts.add(null); 143 EasyMock.expect(agentImpl.retrieveAllContainersInformation()) 144 .andReturn(conts); 145 146 EasyMock.replay(log); 147 EasyMock.replay(agentImpl); 148 149 agentImpl.log = log; 150 151 agentImpl.startServer(); 152 } 153 154 public void testRetrieveContainerInformation() throws PetalsException { 155 SystemUtil.setJmxPort("8081"); 156 ContainerInformation containerInformation = agentImpl 157 .createContainerInformation(); 158 assertEquals(containerInformation.getJmxPort(), "8081"); 159 } 160 161 } 162 | Popular Tags |