KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > jbi > management > systemstate > SystemStateImplTest


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: SystemStateImplTest.java 5:04:24 PM ddesjardins $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.jbi.management.systemstate;
23
24 import java.lang.reflect.Method JavaDoc;
25 import java.util.ArrayList JavaDoc;
26 import java.util.List JavaDoc;
27
28 import junit.framework.TestCase;
29
30 import org.easymock.classextension.EasyMock;
31 import org.objectweb.petals.jbi.management.service.ManagementException;
32 import org.objectweb.petals.util.LoggingUtil;
33 import org.objectweb.util.monolog.api.Logger;
34
35 /**
36  * Tests of the SystemStateImpl
37  *
38  * @author ddesjardins - eBMWebsourcing
39  */

40 public class SystemStateImplTest extends TestCase {
41
42     public void testCreateComponentStateHolder() throws Exception JavaDoc {
43         SystemStateImpl systemStateImpl = new SystemStateImpl();
44         StateStorage stateStorage = EasyMock.createMock(StateStorage.class);
45         ComponentState componentState = EasyMock
46                 .createMock(ComponentState.class);
47
48         EasyMock.expect(
49                 stateStorage.createComponentStateHolder("compo", "installURL",
50                         "zipURL", "installState", "lifecycleState")).andReturn(
51                 componentState);
52
53         EasyMock.replay(stateStorage);
54
55         systemStateImpl.stateStorage = stateStorage;
56
57         assertEquals(componentState, systemStateImpl
58                 .createComponentStateHolder("compo", "installURL", "zipURL",
59                         "installState", "lifecycleState"));
60     }
61
62     public void testDeleteComponentStateHolder() throws Exception JavaDoc {
63         SystemStateImpl systemStateImpl = new SystemStateImpl();
64         StateStorage stateStorage = EasyMock.createMock(StateStorage.class);
65         ComponentState componentState = EasyMock
66                 .createMock(ComponentState.class);
67
68         EasyMock.expect(
69                 stateStorage.deleteComponentStateHolder("componentName"))
70                 .andReturn(componentState);
71
72         EasyMock.replay(stateStorage);
73
74         systemStateImpl.stateStorage = stateStorage;
75
76         assertEquals(componentState, systemStateImpl
77                 .deleteComponentStateHolder("componentName"));
78     }
79
80     public void testCreateServiceAssemblyStateHolder() throws Exception JavaDoc {
81         SystemStateImpl systemStateImpl = new SystemStateImpl();
82         StateStorage stateStorage = EasyMock.createMock(StateStorage.class);
83         ServiceAssemblyState serviceAssemblyState = EasyMock
84                 .createMock(ServiceAssemblyState.class);
85
86         EasyMock.expect(
87                 stateStorage.createServiceAssemblyStateHolder("saName",
88                         "installURL", "zipURL", "lifecycleState")).andReturn(
89                 serviceAssemblyState);
90
91         EasyMock.replay(stateStorage);
92
93         systemStateImpl.stateStorage = stateStorage;
94
95         assertEquals(serviceAssemblyState, systemStateImpl
96                 .createServiceAssemblyStateHolder("saName", "installURL",
97                         "zipURL", "lifecycleState"));
98     }
99
100     public void testDeleteServiceAssemblyStateHolder() throws Exception JavaDoc {
101         SystemStateImpl systemStateImpl = new SystemStateImpl();
102         StateStorage stateStorage = EasyMock.createMock(StateStorage.class);
103         ServiceAssemblyState serviceAssemblyState = EasyMock
104                 .createMock(ServiceAssemblyState.class);
105
106         EasyMock
107                 .expect(stateStorage.deleteServiceAssemblyStateHolder("saName"))
108                 .andReturn(serviceAssemblyState);
109
110         EasyMock.replay(stateStorage);
111
112         systemStateImpl.stateStorage = stateStorage;
113
114         assertEquals(serviceAssemblyState, systemStateImpl
115                 .deleteServiceAssemblyStateHolder("saName"));
116     }
117
118     public void testCreateSharedLibraryStateHolder() throws Exception JavaDoc {
119         SystemStateImpl systemStateImpl = new SystemStateImpl();
120         StateStorage stateStorage = EasyMock.createMock(StateStorage.class);
121         SharedLibraryState sharedLibraryState = EasyMock
122                 .createMock(SharedLibraryState.class);
123
124         EasyMock.expect(
125                 stateStorage.createSharedLibraryStateHolder("slName",
126                         "installURL", "zipURL")).andReturn(sharedLibraryState);
127
128         EasyMock.replay(stateStorage);
129
130         systemStateImpl.stateStorage = stateStorage;
131
132         assertEquals(sharedLibraryState, systemStateImpl
133                 .createSharedLibraryStateHolder("slName", "installURL",
134                         "zipURL"));
135     }
136
137     public void testDeleteSharedLibraryStateHolder() throws Exception JavaDoc {
138         SystemStateImpl systemStateImpl = new SystemStateImpl();
139         StateStorage stateStorage = EasyMock.createMock(StateStorage.class);
140         SharedLibraryState sharedLibraryState = EasyMock
141                 .createMock(SharedLibraryState.class);
142
143         EasyMock.expect(stateStorage.deleteSharedLibraryStateHolder("slName"))
144                 .andReturn(sharedLibraryState);
145
146         EasyMock.replay(stateStorage);
147
148         systemStateImpl.stateStorage = stateStorage;
149
150         assertEquals(sharedLibraryState, systemStateImpl
151                 .deleteSharedLibraryStateHolder("slName"));
152     }
153
154     public void testRecoverAllComponent() throws ManagementException {
155         SystemStateImpl systemStateImpl = new SystemStateImpl();
156         SystemRecovery systemRecovery = EasyMock
157                 .createMock(SystemRecovery.class);
158
159         EasyMock.expect(systemRecovery.recoverAllComponent()).andReturn(true);
160
161         EasyMock.replay(systemRecovery);
162
163         systemStateImpl.systemRecovery = systemRecovery;
164
165         systemRecovery.recoverAllComponent();
166     }
167
168     public void testRecoverAllServiceAssembly() throws ManagementException {
169         SystemStateImpl systemStateImpl = new SystemStateImpl();
170         SystemRecovery systemRecovery = EasyMock
171                 .createMock(SystemRecovery.class);
172
173         EasyMock.expect(systemRecovery.recoverAllServiceAssembly()).andReturn(
174                 true);
175
176         EasyMock.replay(systemRecovery);
177
178         systemStateImpl.systemRecovery = systemRecovery;
179
180         systemRecovery.recoverAllServiceAssembly();
181     }
182
183     public void testRecoverAllSharedLibrary() throws ManagementException {
184         SystemStateImpl systemStateImpl = new SystemStateImpl();
185         SystemRecovery systemRecovery = EasyMock
186                 .createMock(SystemRecovery.class);
187
188         EasyMock.expect(systemRecovery.recoverAllSharedLibrary()).andReturn(
189                 true);
190
191         EasyMock.replay(systemRecovery);
192
193         systemStateImpl.systemRecovery = systemRecovery;
194
195         systemRecovery.recoverAllSharedLibrary();
196     }
197
198     public void testRecoverAllEntities() throws SecurityException JavaDoc,
199         NoSuchMethodException JavaDoc, ManagementException {
200         SystemStateImpl systemStateImpl = EasyMock.createMock(
201                 SystemStateImpl.class, new Method JavaDoc[] {
202                     SystemStateImpl.class.getDeclaredMethod(
203                             "recoverAllSharedLibrary", new Class JavaDoc[] {}),
204                     SystemStateImpl.class.getDeclaredMethod(
205                             "recoverAllComponent", new Class JavaDoc[] {}),
206                     SystemStateImpl.class.getDeclaredMethod(
207                             "recoverAllServiceAssembly", new Class JavaDoc[] {})});
208         LoggingUtil loggingUtil = EasyMock.createMock(LoggingUtil.class);
209
210         loggingUtil.start();
211         EasyMock.expect(systemStateImpl.recoverAllComponent()).andReturn(true);
212         EasyMock.expect(systemStateImpl.recoverAllServiceAssembly()).andReturn(
213                 true);
214         EasyMock.expect(systemStateImpl.recoverAllSharedLibrary()).andReturn(
215                 true);
216         loggingUtil.end();
217
218         EasyMock.replay(systemStateImpl);
219         EasyMock.replay(loggingUtil);
220
221         systemStateImpl.log = loggingUtil;
222
223         systemStateImpl.recoverAllEntities();
224     }
225
226     public void testRecoverAllEntitiesException() throws SecurityException JavaDoc,
227         NoSuchMethodException JavaDoc, ManagementException {
228         SystemStateImpl systemStateImpl = EasyMock.createMock(
229                 SystemStateImpl.class, new Method JavaDoc[] {
230                     SystemStateImpl.class.getDeclaredMethod(
231                             "recoverAllSharedLibrary", new Class JavaDoc[] {}),
232                     SystemStateImpl.class.getDeclaredMethod(
233                             "recoverAllComponent", new Class JavaDoc[] {}),
234                     SystemStateImpl.class.getDeclaredMethod(
235                             "recoverAllServiceAssembly", new Class JavaDoc[] {})});
236         LoggingUtil loggingUtil = EasyMock.createMock(LoggingUtil.class);
237         ManagementException managementException = new ManagementException(
238                 "test error");
239
240         loggingUtil.start();
241         EasyMock.expect(systemStateImpl.recoverAllSharedLibrary()).andThrow(
242                 managementException);
243         loggingUtil.error("Entities can't be correctly recovered !",
244                 managementException);
245         loggingUtil.end();
246
247         EasyMock.replay(systemStateImpl);
248         EasyMock.replay(loggingUtil);
249
250         systemStateImpl.log = loggingUtil;
251
252         try {
253             systemStateImpl.recoverAllEntities();
254             fail("recoverAllEntities must throw an exception if SystemStateImpl.recoverAllSharedLibrary throws an exception");
255         } catch (ManagementException e) {
256             // DO nothing it's ok
257
}
258     }
259
260     public void testRetrieveAllComponentStates() throws ManagementException {
261         SystemStateImpl systemStateImpl = new SystemStateImpl();
262         StateStorage stateStorage = EasyMock.createMock(StateStorage.class);
263         List JavaDoc<ComponentState> compos = new ArrayList JavaDoc<ComponentState>();
264
265         EasyMock.expect(stateStorage.retrieveAllComponentStates()).andReturn(
266                 compos);
267
268         EasyMock.replay(stateStorage);
269
270         systemStateImpl.stateStorage = stateStorage;
271
272         assertEquals(systemStateImpl.retrieveAllComponentStates(), compos);
273     }
274
275     public void testRetrieveAllServiceAssemblyStates()
276         throws ManagementException {
277         SystemStateImpl systemStateImpl = new SystemStateImpl();
278         StateStorage stateStorage = EasyMock.createMock(StateStorage.class);
279         List JavaDoc<ServiceAssemblyState> serv = new ArrayList JavaDoc<ServiceAssemblyState>();
280
281         EasyMock.expect(stateStorage.retrieveAllServiceAssemblyStates())
282                 .andReturn(serv);
283
284         EasyMock.replay(stateStorage);
285
286         systemStateImpl.stateStorage = stateStorage;
287
288         assertEquals(systemStateImpl.retrieveAllServiceAssemblyStates(), serv);
289     }
290
291     public void testRetrieveAllSharedLibraryStates() throws ManagementException {
292         SystemStateImpl systemStateImpl = new SystemStateImpl();
293         StateStorage stateStorage = EasyMock.createMock(StateStorage.class);
294         List JavaDoc<SharedLibraryState> shList = new ArrayList JavaDoc<SharedLibraryState>();
295
296         EasyMock.expect(stateStorage.retrieveAllSharedLibraryStates())
297                 .andReturn(shList);
298
299         EasyMock.replay(stateStorage);
300
301         systemStateImpl.stateStorage = stateStorage;
302
303         assertEquals(systemStateImpl.retrieveAllSharedLibraryStates(), shList);
304     }
305
306
307     public void testUpdateComponentInstallationState() throws Exception JavaDoc {
308         SystemStateImpl systemStateImpl = new SystemStateImpl();
309         StateStorage stateStorage = EasyMock.createMock(StateStorage.class);
310
311         stateStorage.updateComponentInstallationState("compo", "installState");
312
313         EasyMock.replay(stateStorage);
314
315         systemStateImpl.stateStorage = stateStorage;
316
317         systemStateImpl.updateComponentInstallationState("compo",
318                 "installState");
319     }
320
321     public void testUpdateComponentLifeCycleState() throws Exception JavaDoc {
322         SystemStateImpl systemStateImpl = new SystemStateImpl();
323         StateStorage stateStorage = EasyMock.createMock(StateStorage.class);
324
325         stateStorage.updateComponentLifeCycleState("compo", "lifecycleState");
326
327         EasyMock.replay(stateStorage);
328
329         systemStateImpl.stateStorage = stateStorage;
330
331         systemStateImpl
332                 .updateComponentLifeCycleState("compo", "lifecycleState");
333     }
334
335     public void testUpdateServiceAssemblyState() throws Exception JavaDoc {
336         SystemStateImpl systemStateImpl = new SystemStateImpl();
337         StateStorage stateStorage = EasyMock.createMock(StateStorage.class);
338
339         stateStorage.updateServiceAssemblyState("saName", "lifecycleState");
340
341         EasyMock.replay(stateStorage);
342
343         systemStateImpl.stateStorage = stateStorage;
344
345         systemStateImpl.updateServiceAssemblyState("saName", "lifecycleState");
346     }
347
348     public void testShutdown() {
349         SystemStateImpl systemStateImpl = new SystemStateImpl();
350         LoggingUtil loggingUtil = EasyMock.createMock(LoggingUtil.class);
351
352         loggingUtil.start();
353         loggingUtil.end();
354
355         EasyMock.replay(loggingUtil);
356         systemStateImpl.log = loggingUtil;
357         systemStateImpl.logger = EasyMock.createMock(Logger.class);
358
359         systemStateImpl.stop();
360         assertNull(systemStateImpl.logger);
361     }
362 }
363
Popular Tags