KickJava   Java API By Example, From Geeks To Geeks.

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


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: ServiceUnitLifeCycleTest.java 11:09:47 ddesjardins $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.jbi.component.lifecycle;
23
24 import javax.jbi.JBIException;
25 import javax.management.ObjectName JavaDoc;
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 /**
40  * Test of the ServiceUnitLifeCycle
41  *
42  * @author ddesjardins - eBMWebsourcing
43  */

44 public class ServiceUnitLifeCycleTest extends TestCase {
45
46     private ServiceUnitLifeCycle serviceUnitLifeCycle;
47
48     private ServiceUnitManagerMock serviceUnitManagerMock;
49
50     private String JavaDoc baseDir;
51
52     public void setUp() throws Exception JavaDoc {
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 JavaDoc("test@test:name=test"), null, EasyMock
65                 .createMock(LoggingUtil.class));
66
67         lifeCycleManagerImpl.getBindingCompoLifeCycles().put(
68             new ObjectName JavaDoc("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