KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > jbi > component > lifecycle > ServiceAssemblyLifeCycleTest


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: ServiceAssemblyLifeCycleTest.java 12:11:14 ddesjardins $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.jbi.component.lifecycle;
23
24 import java.io.File JavaDoc;
25
26 import javax.jbi.JBIException;
27 import javax.management.ObjectName JavaDoc;
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 /**
46  * Test of the ServiceAssemblyLifeCycle
47  *
48  * @author ddesjardins - eBMWebsourcing
49  */

50 public class ServiceAssemblyLifeCycleTest extends TestCase {
51
52     private ServiceAssemblyLifeCycle serviceAssemblyLifeCycle;
53
54     private ServiceUnitLifeCycle serviceUnitLifeCycle;
55
56     public void setUp() throws Exception JavaDoc {
57         String JavaDoc 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 JavaDoc(
67             "test@test:name=test"), new LoggingUtil(logger),
68             serviceAssemblyMock, new RepositoryImpl(), new SystemStateImpl(),
69             new File JavaDoc(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 JavaDoc("test@test:name=test"), null, new LoggingUtil(logger));
82
83         lifeCycleManagerImpl.getBindingCompoLifeCycles().put(
84             new ObjectName JavaDoc("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 JavaDoc 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