1 22 package org.objectweb.petals.jbi.component.lifecycle; 23 24 import java.io.File ; 25 26 import javax.jbi.JBIException; 27 import javax.management.ObjectName ; 28 29 import junit.framework.TestCase; 30 31 import org.objectweb.petals.jbi.component.context.ComponentContextImpl; 32 import org.objectweb.petals.jbi.component.lifecycle.mock.IdentificationMock; 33 import org.objectweb.petals.jbi.component.lifecycle.mock.MockComponentDescriptionBuilder; 34 import org.objectweb.petals.jbi.component.lifecycle.mock.MockServiceUnitBuilder; 35 import org.objectweb.petals.jbi.component.lifecycle.mock.ServiceAssemblyMock; 36 import org.objectweb.petals.jbi.component.lifecycle.mock.ServiceUnitManagerMock; 37 import org.objectweb.petals.jbi.management.service.LifeCycleManagerImpl; 38 import org.objectweb.petals.jbi.management.systemstate.SystemStateImpl; 39 import org.objectweb.petals.jbi.messaging.mock.MockLogger; 40 import org.objectweb.petals.jbi.routing.mock.ComponentMock; 41 import org.objectweb.petals.repository.RepositoryImpl; 42 import org.objectweb.petals.util.LoggingUtil; 43 import org.objectweb.util.monolog.api.Logger; 44 45 50 public class ServiceAssemblyLifeCycleTest extends TestCase { 51 52 private ServiceAssemblyLifeCycle serviceAssemblyLifeCycle; 53 54 private ServiceUnitLifeCycle serviceUnitLifeCycle; 55 56 public void setUp() throws Exception { 57 String baseDir = this.getClass().getResource(".").toString(); 58 baseDir = baseDir.substring(0, baseDir.indexOf("target")); 59 baseDir = baseDir.substring(baseDir.indexOf(":") + 1); 60 61 Logger logger = new MockLogger(); 62 ServiceAssemblyMock serviceAssemblyMock = new ServiceAssemblyMock(); 63 IdentificationMock identification = new IdentificationMock(); 64 identification.setName("testSA"); 65 serviceAssemblyMock.setIdentification(identification); 66 serviceAssemblyLifeCycle = new ServiceAssemblyLifeCycle(new ObjectName ( 67 "test@test:name=test"), new LoggingUtil(logger), 68 serviceAssemblyMock, new RepositoryImpl(), new SystemStateImpl(), 69 new File (baseDir + "target").toURI()); 70 71 LifeCycleManagerImpl lifeCycleManagerImpl = new LifeCycleManagerImpl(); 72 73 ComponentMock componentMock = new ComponentMock(); 74 ServiceUnitManagerMock serviceUnitManagerMock = new ServiceUnitManagerMock(); 75 serviceUnitManagerMock.deploy("testServiceUnit", "none"); 76 componentMock.setServiceUnitManager(serviceUnitManagerMock); 77 78 ComponentLifeCycle componentLifeCycle = new ComponentLifeCycle( 79 MockComponentDescriptionBuilder.buildComponentDescription(), 80 componentMock, new ComponentContextImpl(), new SystemStateImpl(), 81 new ObjectName ("test@test:name=test"), null, new LoggingUtil(logger)); 82 83 lifeCycleManagerImpl.getBindingCompoLifeCycles().put( 84 new ObjectName ("test@test:name=test"), componentLifeCycle); 85 lifeCycleManagerImpl.start(); 86 87 serviceUnitLifeCycle = new ServiceUnitLifeCycle(MockServiceUnitBuilder 88 .buildServiceUnit(), lifeCycleManagerImpl, baseDir + File.separator 89 + "target", new LoggingUtil(logger)); 90 } 91 92 public void testRegisterSUIntoSA() throws JBIException { 93 serviceAssemblyLifeCycle.registerSUIntoSA("testSU", 94 serviceUnitLifeCycle); 95 assertEquals(serviceAssemblyLifeCycle.getServiceUnitsLifeCycles().get( 96 "testSU"), serviceUnitLifeCycle); 97 } 98 99 public void testDoInit() throws JBIException { 100 serviceAssemblyLifeCycle.doInit(); 101 } 102 103 public void testDoShutdownFailed() throws JBIException { 104 testRegisterSUIntoSA(); 105 try { 106 serviceAssemblyLifeCycle.doShutdown(); 107 fail(); 108 } catch (Exception e) { 109 110 } 111 } 112 113 public void testDoShutdown() throws JBIException { 114 testRegisterSUIntoSA(); 115 serviceUnitLifeCycle.state = "Stopped"; 116 serviceAssemblyLifeCycle.doShutdown(); 117 assertEquals(serviceAssemblyLifeCycle.getServiceUnitsLifeCycles().get( 118 "testSU").getCurrentState(), "Shutdown"); 119 } 120 121 public void testDoStop() throws JBIException { 122 testRegisterSUIntoSA(); 123 serviceUnitLifeCycle.state = "Started"; 124 serviceAssemblyLifeCycle.doStop(); 125 assertEquals(serviceAssemblyLifeCycle.getServiceUnitsLifeCycles().get( 126 "testSU").getCurrentState(), "Stopped"); 127 } 128 129 public void testDoStart() throws JBIException { 130 testRegisterSUIntoSA(); 131 serviceUnitLifeCycle.state = "Stopped"; 132 serviceAssemblyLifeCycle.doStart(); 133 assertEquals(serviceAssemblyLifeCycle.getServiceUnitsLifeCycles().get( 134 "testSU").getCurrentState(), "Started"); 135 } 136 137 } 138 | Popular Tags |