1 22 package org.objectweb.petals.jbi.component.lifecycle; 23 24 import javax.jbi.JBIException; 25 import javax.management.ObjectName ; 26 27 import junit.framework.TestCase; 28 29 import org.easymock.classextension.EasyMock; 30 import org.objectweb.petals.jbi.component.context.ComponentContextImpl; 31 import org.objectweb.petals.jbi.component.lifecycle.mock.MockComponentDescriptionBuilder; 32 import org.objectweb.petals.jbi.component.lifecycle.mock.MockServiceUnitBuilder; 33 import org.objectweb.petals.jbi.component.lifecycle.mock.ServiceUnitManagerMock; 34 import org.objectweb.petals.jbi.management.service.LifeCycleManagerImpl; 35 import org.objectweb.petals.jbi.management.systemstate.SystemStateImpl; 36 import org.objectweb.petals.jbi.routing.mock.ComponentMock; 37 import org.objectweb.petals.util.LoggingUtil; 38 39 44 public class ServiceUnitLifeCycleTest extends TestCase { 45 46 private ServiceUnitLifeCycle serviceUnitLifeCycle; 47 48 private ServiceUnitManagerMock serviceUnitManagerMock; 49 50 private String baseDir; 51 52 public void setUp() throws Exception { 53 LifeCycleManagerImpl lifeCycleManagerImpl = new LifeCycleManagerImpl(); 54 55 ComponentMock componentMock = new ComponentMock(); 56 serviceUnitManagerMock = new ServiceUnitManagerMock(); 57 componentMock.setServiceUnitManager(serviceUnitManagerMock); 58 59 serviceUnitManagerMock.deploy("testServiceUnit", "none"); 60 61 ComponentLifeCycle componentLifeCycle = new ComponentLifeCycle( 62 MockComponentDescriptionBuilder.buildComponentDescription(), 63 componentMock, new ComponentContextImpl(), new SystemStateImpl(), 64 new ObjectName ("test@test:name=test"), null, EasyMock 65 .createMock(LoggingUtil.class)); 66 67 lifeCycleManagerImpl.getBindingCompoLifeCycles().put( 68 new ObjectName ("test@test:name=test"), componentLifeCycle); 69 lifeCycleManagerImpl.start(); 70 71 baseDir = this.getClass().getResource(".").toString(); 72 baseDir = baseDir.substring(0, baseDir.indexOf("target")); 73 baseDir = baseDir.substring(baseDir.indexOf(":") + 1); 74 serviceUnitLifeCycle = new ServiceUnitLifeCycle(MockServiceUnitBuilder 75 .buildServiceUnit(), lifeCycleManagerImpl, baseDir + "target", 76 EasyMock.createMock(LoggingUtil.class)); 77 } 78 79 public void testGetServiceUnitManager() { 80 assertEquals(serviceUnitLifeCycle.getServiceUnitManager(), 81 serviceUnitManagerMock); 82 } 83 84 public void testDoStart() throws JBIException { 85 serviceUnitLifeCycle.doStart(); 86 assertEquals(serviceUnitManagerMock.getUnits().get("testServiceUnit") 87 .getState(), "Started"); 88 } 89 90 public void testDoShutdown() throws JBIException { 91 serviceUnitLifeCycle.doShutdown(); 92 assertEquals(serviceUnitManagerMock.getUnits().get("testServiceUnit") 93 .getState(), "Shutdown"); 94 } 95 96 public void testDoStop() throws JBIException { 97 serviceUnitLifeCycle.doStop(); 98 assertEquals(serviceUnitManagerMock.getUnits().get("testServiceUnit") 99 .getState(), "Stopped"); 100 } 101 102 public void testGetSuName() { 103 assertEquals(serviceUnitLifeCycle.getSuName(), "testServiceUnit"); 104 } 105 106 public void testGetServiceUnitRootPath() { 107 assertEquals(serviceUnitLifeCycle.getServiceUnitRootPath(), baseDir 108 + "target"); 109 } 110 111 } 112 | Popular Tags |