KickJava   Java API By Example, From Geeks To Geeks.

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


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.Bootstrap;
26 import javax.jbi.component.InstallationContext;
27 import javax.management.ObjectName JavaDoc;
28
29 import junit.framework.TestCase;
30
31 import org.objectweb.petals.jbi.component.context.InstallationContextImpl;
32 import org.objectweb.petals.jbi.component.lifecycle.Installer;
33
34 import static org.easymock.EasyMock.expect;
35 import static org.easymock.EasyMock.expectLastCall;
36 import static org.easymock.classextension.EasyMock.createMock;
37 import static org.easymock.classextension.EasyMock.replay;
38 import static org.easymock.classextension.EasyMock.reset;
39 import static org.easymock.classextension.EasyMock.verify;
40
41 /**
42  * Installer thread unit test
43  *
44  * @author Christophe Hamerling - EBM WebSourcing
45  */

46 public class InstallerThreadTest extends TestCase {
47
48     private BootstrapThread installerThread;
49
50     private Installer installerMock;
51
52     private InstallationContext installContextMock;
53
54     private Bootstrap bootstrapMock;
55
56     /**
57      * Test cleanUp
58      *
59      */

60     public void testCleanUp() throws JBIException {
61         installerThread.start();
62
63         reset(bootstrapMock);
64         bootstrapMock.cleanUp();
65         expectLastCall();
66         replay(bootstrapMock);
67
68         try {
69             installerThread.cleanUp();
70         } catch (JBIException e) {
71             fail(e.getMessage());
72         }
73         verify(bootstrapMock);
74     }
75
76     /**
77      * Test init
78      *
79      */

80     public void testInit() throws JBIException {
81         installerThread.start();
82         
83         installContextMock = createMock(InstallationContextImpl.class);
84
85         reset(bootstrapMock);
86         
87         bootstrapMock.init(installContextMock);
88         expectLastCall();
89         replay(bootstrapMock);
90
91         try {
92             installerThread.init(installContextMock);
93         } catch (JBIException e) {
94             fail(e.getMessage());
95         }
96         verify(bootstrapMock);
97     }
98
99     /**
100      * Test onInstall
101      *
102      */

103     public void testOnInstall() throws JBIException {
104         installerThread.start();
105
106         reset(bootstrapMock);
107         bootstrapMock.onInstall();
108         expectLastCall();
109         replay(bootstrapMock);
110
111         try {
112             installerThread.onInstall();
113         } catch (JBIException e) {
114             fail(e.getMessage());
115         }
116         verify(bootstrapMock);
117     }
118
119     /**
120      * Test onUninstall
121      *
122      */

123     public void testOnUninstall() throws JBIException {
124         installerThread.start();
125
126         reset(bootstrapMock);
127         bootstrapMock.onUninstall();
128         expectLastCall();
129         replay(bootstrapMock);
130
131         try {
132             installerThread.onUninstall();
133         } catch (JBIException e) {
134             fail(e.getMessage());
135         }
136         verify(bootstrapMock);
137     }
138
139     /**
140      * Test getExtensionMBeanName
141      *
142      */

143     public void testGetExtensionMBeanName() {
144         installerThread.start();
145         
146         reset(bootstrapMock);
147         ObjectName JavaDoc objectName = createMock(ObjectName JavaDoc.class);
148         expect(bootstrapMock.getExtensionMBeanName()).andReturn(objectName);
149         replay(bootstrapMock);
150
151         ObjectName JavaDoc oName = installerThread.getExtensionMBeanName();
152         assertEquals(oName, objectName);
153         verify(bootstrapMock);
154     }
155     
156     public void testMultipleCalls(){
157         installerThread.start();
158         
159         try {
160             installerThread.onInstall();
161             installerThread.onUninstall();
162             installerThread.onInstall();
163             installerThread.onUninstall();
164             installerThread.onInstall();
165             installerThread.onUninstall();
166         } catch (JBIException e) {
167             // TODO Auto-generated catch block
168
e.printStackTrace();
169         }
170     }
171     
172     /*
173      * (non-Javadoc)
174      *
175      * @see junit.framework.TestCase#setUp()
176      */

177     protected void setUp() throws Exception JavaDoc {
178         super.setUp();
179
180         installerMock = createMock(Installer.class);
181         bootstrapMock = createMock(Bootstrap.class);
182         expect(installerMock.getComponentName()).andReturn(null);
183         replay(installerMock);
184
185         installerThread = new BootstrapThread(installerMock, bootstrapMock);
186     }
187
188 }
189
Popular Tags