KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > jbi > component > thread > ComponentLifeCycleThreadTest


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$
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.jbi.component.thread;
23
24 import javax.jbi.JBIException;
25 import javax.jbi.component.Component;
26 import javax.jbi.component.ComponentContext;
27 import javax.jbi.component.ComponentLifeCycle;
28
29 import junit.framework.TestCase;
30 import static org.easymock.EasyMock.expect;
31 import static org.easymock.classextension.EasyMock.createMock;
32 import static org.easymock.classextension.EasyMock.replay;
33 import static org.easymock.classextension.EasyMock.reset;
34 import static org.easymock.classextension.EasyMock.verify;
35
36 /**
37  * Component life cycle thread unit test
38  *
39  * @author Christophe Hamerling - EBM WebSourcing
40  */

41 public class ComponentLifeCycleThreadTest extends TestCase {
42
43     /**
44      * The component life cycle thread to test
45      */

46     private ComponentLifeCycleThread lifeCycleThread;
47     
48     /**
49      * The mock life cycle
50      */

51     private ComponentLifeCycle lifeCycleMock;
52
53     /**
54      * The mock component
55      */

56     private Component componentMock;
57
58     /**
59      * The mock component context
60      */

61     private ComponentContext contextMock;
62
63     /**
64      *
65      *
66      */

67     public void testDoInit() throws Exception JavaDoc {
68         lifeCycleThread.start();
69         reset(componentMock);
70         expect(componentMock.getLifeCycle()).andReturn(lifeCycleMock);
71         replay(componentMock);
72
73         lifeCycleThread.doInit(contextMock);
74         verify(componentMock);
75         
76         JBIException jbie = lifeCycleThread.getJbiException();
77         assertNull(jbie);
78     }
79
80     /**
81      *
82      *
83      */

84     public void testDoStart() throws Exception JavaDoc {
85         lifeCycleThread.start();
86         reset(componentMock);
87         expect(componentMock.getLifeCycle()).andReturn(lifeCycleMock);
88         replay(componentMock);
89
90         lifeCycleThread.doStart();
91         verify(componentMock);
92         
93         JBIException jbie = lifeCycleThread.getJbiException();
94         assertNull(jbie);
95     }
96
97     /**
98      *
99      */

100     public void testDoStop() throws Exception JavaDoc {
101         lifeCycleThread.start();
102
103         reset(componentMock);
104         expect(componentMock.getLifeCycle()).andReturn(lifeCycleMock);
105         replay(componentMock);
106
107         lifeCycleThread.doStop();
108         verify(componentMock);
109         
110         JBIException jbie = lifeCycleThread.getJbiException();
111         assertNull(jbie);
112     }
113
114     /**
115      *
116      *
117      */

118     public void testDoShutdown() throws Exception JavaDoc {
119         lifeCycleThread.start();
120
121         reset(componentMock);
122         expect(componentMock.getLifeCycle()).andReturn(lifeCycleMock);
123         replay(componentMock);
124
125         lifeCycleThread.doShutdown();
126         verify(componentMock);
127
128         JBIException jbie = lifeCycleThread.getJbiException();
129         assertNull(jbie);
130     }
131
132     /**
133      * Test multiple calls
134      *
135      */

136     public void testMultipleCalls() {
137         lifeCycleThread.start();
138
139         // stop component
140
reset(componentMock);
141         expect(componentMock.getLifeCycle()).andReturn(lifeCycleMock);
142         replay(componentMock);
143         try {
144             lifeCycleThread.doStop();
145         } catch (JBIException e) {
146             fail(e.getMessage());
147         }
148         verify(componentMock);
149
150         // shutdown component
151
reset(componentMock);
152         expect(componentMock.getLifeCycle()).andReturn(lifeCycleMock);
153         replay(componentMock);
154         try {
155             lifeCycleThread.doShutdown();
156         } catch (JBIException e) {
157             fail(e.getMessage());
158         }
159         verify(componentMock);
160         
161     }
162     
163     /*
164      * (non-Javadoc)
165      *
166      * @see junit.framework.TestCase#setUp()
167      */

168     protected void setUp() throws Exception JavaDoc {
169         super.setUp();
170
171         componentMock = createMock(Component.class);
172         contextMock = createMock(ComponentContext.class);
173         lifeCycleMock = createMock(ComponentLifeCycle.class);
174
175         lifeCycleThread = new ComponentLifeCycleThread(componentMock);
176     }
177
178 }
179
Popular Tags