KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > jbi > management > service > InstallationServiceTest


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: InstallationServiceTest.java 16:39:45 wjoseph $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.jbi.management.service;
23
24 import static org.easymock.EasyMock.expect;
25 import static org.easymock.EasyMock.isA;
26 import static org.easymock.classextension.EasyMock.createMock;
27 import static org.easymock.classextension.EasyMock.replay;
28 import static org.easymock.classextension.EasyMock.reset;
29 import static org.easymock.classextension.EasyMock.verify;
30
31 import java.io.File JavaDoc;
32 import java.lang.reflect.Method JavaDoc;
33 import java.net.URI JavaDoc;
34 import java.util.ArrayList JavaDoc;
35 import java.util.HashMap JavaDoc;
36 import java.util.List JavaDoc;
37 import java.util.Map JavaDoc;
38 import java.util.zip.ZipFile JavaDoc;
39
40 import javax.management.AttributeNotFoundException JavaDoc;
41 import javax.management.InstanceNotFoundException JavaDoc;
42 import javax.management.MBeanException JavaDoc;
43 import javax.management.MBeanServer JavaDoc;
44 import javax.management.ObjectName JavaDoc;
45 import javax.management.ReflectionException JavaDoc;
46
47 import junit.framework.TestCase;
48
49 import org.objectweb.petals.PetalsException;
50 import org.objectweb.petals.classloader.LoaderManager;
51 import org.objectweb.petals.classloader.LoaderManagerImpl;
52 import org.objectweb.petals.jbi.component.context.ComponentContextImpl;
53 import org.objectweb.petals.jbi.component.lifecycle.ComponentLifeCycle;
54 import org.objectweb.petals.jbi.component.lifecycle.Installer;
55 import org.objectweb.petals.jbi.component.lifecycle.LifeCycleMBean;
56 import org.objectweb.petals.jbi.management.systemstate.ComponentState;
57 import org.objectweb.petals.jbi.management.systemstate.SharedLibraryState;
58 import org.objectweb.petals.jbi.management.systemstate.SystemState;
59 import org.objectweb.petals.jbi.management.systemstate.SystemStateImpl;
60 import org.objectweb.petals.jbi.mock.MockLifeCycleManagerService;
61 import org.objectweb.petals.repository.RepositoryImpl;
62 import org.objectweb.petals.repository.RepositoryService;
63 import org.objectweb.petals.tools.jbicommon.descriptor.ComponentDescription;
64 import org.objectweb.petals.tools.jbicommon.descriptor.Identification;
65 import org.objectweb.petals.tools.jbicommon.descriptor.JBIDescriptor;
66 import org.objectweb.petals.tools.jbicommon.descriptor.SharedLibrary;
67 import org.objectweb.petals.tools.jbicommon.descriptor.SharedLibraryList;
68 import org.objectweb.petals.util.LoggingUtil;
69
70 /**
71  * Test of the InstallationServiceImpl
72  *
73  * @author wjoseph - eBMWebsourcing
74  */

75 public class InstallationServiceTest extends TestCase {
76
77     private File JavaDoc testDataDir = null;
78
79     public void testCheckClassPathElements() {
80         /*
81          * Test Case 1 An empty classpath element is found
82          */

83         /*
84          * Create Mocks
85          */

86         Method JavaDoc method1 = null;
87         try {
88             method1 = InstallationServiceImpl.class.getDeclaredMethod(
89                     "hasEntry", new Class JavaDoc[] {ZipFile JavaDoc.class, String JavaDoc.class});
90         } catch (Exception JavaDoc e) {
91             e.printStackTrace();
92             fail("Could not retrieve mocked methods");
93         }
94         Method JavaDoc[] mockedMethods = new Method JavaDoc[] {method1};
95         InstallationServiceImpl installationService = createMock(
96                 InstallationServiceImpl.class, mockedMethods);
97         /*
98          * Create Test parameters
99          */

100         List JavaDoc<String JavaDoc> classPathElements = new ArrayList JavaDoc<String JavaDoc>();
101         classPathElements.add("");
102         ZipFile JavaDoc archive = createMock(ZipFile JavaDoc.class);
103         /*
104          * Run Test Case 1
105          */

106         try {
107             installationService.checkClassPathElements(archive,
108                     classPathElements);
109             fail("No exception raised");
110         } catch (Exception JavaDoc e) {
111             // Do nothing
112
}
113
114         /*
115          * Test Case 2 An empty classpath element is found
116          */

117         /*
118          * Create Test parameters
119          */

120         classPathElements = new ArrayList JavaDoc<String JavaDoc>();
121         String JavaDoc element = "someElement";
122         classPathElements.add(element);
123         /*
124          * Initialize mocks
125          */

126         expect(installationService.hasEntry(archive, element)).andReturn(false);
127         replay(installationService);
128         /*
129          * Run Test Case 2
130          */

131         try {
132             installationService.checkClassPathElements(archive,
133                     classPathElements);
134             fail("No exception raised");
135         } catch (Exception JavaDoc e) {
136             verify(installationService);
137         }
138     }
139
140     // public void testCheckComponent() {
141
// /*
142
// * Test Case 1 descriptor.getComponent() returns null
143
// */
144
// /*
145
// * Create Mocks
146
// */
147
// Method method1 = null;
148
// Method method2 = null;
149
// Method method3 = null;
150
// try {
151
// method1 = InstallationServiceImpl.class.getDeclaredMethod("isLoaded",
152
// new Class[] {String.class});
153
// method2 = InstallationServiceImpl.class.getDeclaredMethod(
154
// "checkClassPathElements", new Class[] {ZipFile.class,
155
// List.class});
156
// method3 = InstallationServiceImpl.class.getDeclaredMethod(
157
// "openZipFile", new Class[] {URI.class});
158
// } catch (Exception e) {
159
// e.printStackTrace();
160
// fail("Could not retrieve mocked methods");
161
// }
162
// Method[] mockedMethods = new Method[] {method1, method2, method3};
163
// InstallationServiceImpl installationService = createMock(
164
// InstallationServiceImpl.class, mockedMethods);
165
// LoggingUtil log = createMock(LoggingUtil.class);
166
// installationService.log = log;
167
// /*
168
// * Create test parameters
169
// */
170
// JBIDescriptor descriptor = createMock(JBIDescriptor.class);
171
// URI archiveURI = new File(testDataDir, "fakearchive" + File.separator
172
// + "archive").toURI();
173
// boolean result = false;
174
// /*
175
// * Run Test Case 1
176
// */
177
// try {
178
// installationService.checkComponent(descriptor, archiveURI);
179
// fail("InstallationServiceImpl.checkComponent must throw "
180
// + "a PetalsException if component name is null");
181
// } catch (Exception e) {
182
// // Do nothing it's ok
183
//
184
// }
185
// assertFalse("Wrong invokation result", result);
186
// /*
187
// * Test Case 2 descriptor.getComponent() return the componentDescription
188
// * isLoaded returns true
189
// */
190
// reset(descriptor);
191
// /*
192
// * Create test parameters
193
// */
194
// ComponentDescription comp = createMock(ComponentDescription.class);
195
// Identification id = createMock(Identification.class);
196
// String componentName = "componentName";
197
//
198
// /*
199
// * Initialize Mocks
200
// */
201
// expect(descriptor.getComponent()).andReturn(comp);
202
// expect(comp.getIdentification()).andReturn(id);
203
// expect(id.getName()).andReturn(componentName);
204
// expect(installationService.isComponentLoaded(componentName)).andReturn(true);
205
// replay(descriptor);
206
// replay(comp);
207
// replay(id);
208
// replay(installationService);
209
// /*
210
// * Run Test Case 2
211
// */
212
// try {
213
// installationService.checkComponent(descriptor, archiveURI);
214
// fail("InstallationServiceImpl.checkComponent must throw "
215
// + "a PetalsException if component is already loaded");
216
// } catch (Exception e) {
217
// // Do nothing it's ok
218
//
219
// }
220
// verify(descriptor);
221
// verify(installationService);
222
// verify(comp);
223
// verify(id);
224
// assertFalse("Wrong invokation result", result);
225
//
226
// /*
227
// * Test Case 3 descriptor.getComponent() return the componentDescription
228
// * isLoaded returns true archive.close() throw an exception
229
// */
230
// reset(descriptor);
231
// reset(installationService);
232
// reset(comp);
233
// reset(id);
234
// /*
235
// * Create test parameters
236
// */
237
// ZipFile archive = createMock(MockZipFile.class, new Method[] {});
238
// /*
239
// * Initialize Mocks
240
// */
241
// try {
242
// expect(descriptor.getComponent()).andReturn(comp);
243
// expect(comp.getIdentification()).andReturn(id);
244
// expect(comp.getBootstrapClassPath()).andReturn(null);
245
// expect(comp.getComponentClassPath()).andReturn(null);
246
// expect(id.getName()).andReturn(componentName);
247
// expect(installationService.isComponentLoaded(componentName))
248
// .andReturn(false);
249
// expect(installationService.openZipFile(archiveURI)).andReturn(
250
// archive);
251
// installationService.checkClassPathElements(archive, null);
252
// installationService.checkClassPathElements(archive, null);
253
// } catch (Exception e) {
254
// e.printStackTrace();
255
// fail("Could not initialise Mocks");
256
// }
257
// replay(descriptor);
258
// replay(comp);
259
// replay(id);
260
// replay(installationService);
261
// /*
262
// * Run Test Case 3
263
// */
264
// try {
265
// installationService.checkComponent(descriptor, archiveURI);
266
// fail("No exception was raised");
267
// } catch (Exception e) {
268
// verify(descriptor);
269
// verify(installationService);
270
// verify(comp);
271
// verify(id);
272
// }
273
// }
274

275     public void testCheckComponentShutdownStateForSL() {
276         /*
277          * Test Case 1 One of the binding component unsing the shared library is
278          * not shutdown
279          */

280         InstallationServiceImpl installationService = new InstallationServiceImpl();
281         /*
282          * Create Test parameters
283          */

284         LifeCycleManagerService lcms = createMock(LifeCycleManagerImpl.class);
285         Map JavaDoc<ObjectName JavaDoc, ComponentLifeCycle> bindingComponentLifecycles = new HashMap JavaDoc<ObjectName JavaDoc, ComponentLifeCycle>();
286         Map JavaDoc<ObjectName JavaDoc, ComponentLifeCycle> engineLifecycles = new HashMap JavaDoc<ObjectName JavaDoc, ComponentLifeCycle>();
287         ObjectName JavaDoc componentName = null;
288         ObjectName JavaDoc engineName = null;
289         try {
290             componentName = new ObjectName JavaDoc("component", "component",
291                     "component");
292             engineName = new ObjectName JavaDoc("engine", "engine", "engine");
293         } catch (Exception JavaDoc e) {
294             e.printStackTrace();
295             fail("Could not create test parameters");
296         }
297         ComponentLifeCycle componentLifeCycle = createMock(ComponentLifeCycle.class);
298         LoggingUtil log = createMock(LoggingUtil.class);
299         bindingComponentLifecycles.put(componentName, componentLifeCycle);
300         engineLifecycles.put(engineName, componentLifeCycle);
301         ComponentDescription componentDescription = createMock(ComponentDescription.class);
302         Identification identification = createMock(Identification.class);
303         SharedLibraryList sharedLibrayList = createMock(SharedLibraryList.class);
304         List JavaDoc<SharedLibraryList> slList = new ArrayList JavaDoc<SharedLibraryList>();
305         slList.add(sharedLibrayList);
306         String JavaDoc slName = "sharedLibraryName";
307         String JavaDoc compName = "compName";
308         installationService.log = log;
309         /*
310          * Initialize Mocks
311          */

312         try {
313             expect(lcms.getBindingCompoLifeCycles()).andReturn(
314                     bindingComponentLifecycles);
315             expect(lcms.getEngineCompoLifeCycles()).andReturn(engineLifecycles);
316             expect(componentLifeCycle.getComponentDescription()).andReturn(
317                     componentDescription);
318             expect(componentLifeCycle.getCurrentState()).andReturn(
319                     LifeCycleMBean.STOPPED);
320             expect(componentDescription.getSharedLibraryList()).andReturn(
321                     slList);
322             expect(componentDescription.getIdentification()).andReturn(
323                     identification).anyTimes();
324             expect(identification.getName()).andReturn(compName);
325             expect(sharedLibrayList.getName()).andReturn(slName);
326         } catch (Exception JavaDoc e) {
327             e.printStackTrace();
328             fail("Could not initialize Mocks");
329         }
330         replay(sharedLibrayList);
331         replay(componentDescription);
332         replay(componentLifeCycle);
333         replay(lcms);
334         installationService.jmxAdmin = lcms;
335         boolean result = false;
336         /*
337          * Run Test Case 1
338          */

339         try {
340             result = installationService
341                     .checkComponentShutdownStateForSL(slName);
342         } catch (Exception JavaDoc e) {
343             e.printStackTrace();
344             fail("Error during invokation");
345         }
346         verify(sharedLibrayList);
347         verify(componentDescription);
348         verify(componentLifeCycle);
349         verify(lcms);
350         assertFalse("Wrong invokation result", result);
351
352         /*
353          * Test Case 2 One of the engine component unsing this shared library is
354          * not shutdown
355          */

356         reset(sharedLibrayList);
357         reset(componentDescription);
358         reset(componentLifeCycle);
359         reset(lcms);
360         reset(identification);
361         /*
362          * Create Test parameters
363          */

364         /*
365          * Initialize Mocks
366          */

367         try {
368             expect(lcms.getBindingCompoLifeCycles()).andReturn(
369                     bindingComponentLifecycles);
370             expect(lcms.getEngineCompoLifeCycles()).andReturn(engineLifecycles);
371             expect(componentLifeCycle.getComponentDescription()).andReturn(
372                     componentDescription).anyTimes();
373             expect(componentLifeCycle.getCurrentState()).andReturn(
374                     LifeCycleMBean.SHUTDOWN);
375             expect(componentLifeCycle.getCurrentState()).andReturn(
376                     LifeCycleMBean.STOPPED);
377             expect(componentDescription.getSharedLibraryList()).andReturn(
378                     slList).anyTimes();
379             expect(componentDescription.getIdentification()).andReturn(
380                     identification).anyTimes();
381             expect(identification.getName()).andReturn(compName);
382             expect(sharedLibrayList.getName()).andReturn(slName).anyTimes();
383         } catch (Exception JavaDoc e) {
384             e.printStackTrace();
385             fail("Could not initialize Mocks");
386         }
387         replay(sharedLibrayList);
388         replay(componentDescription);
389         replay(componentLifeCycle);
390         replay(lcms);
391         replay(identification);
392         installationService.jmxAdmin = lcms;
393         result = false;
394         /*
395          * Run Test Case 2
396          */

397         try {
398             result = installationService
399                     .checkComponentShutdownStateForSL(slName);
400         } catch (Exception JavaDoc e) {
401             e.printStackTrace();
402             fail("Error during invokation");
403         }
404         verify(sharedLibrayList);
405         verify(componentDescription);
406         verify(componentLifeCycle);
407         verify(lcms);
408         assertFalse("Wrong invokation result", result);
409     }
410
411     public void testGetComponentNameFromJBIDescriptor() {
412         /*
413          * Test Case 1
414          */

415         InstallationServiceImpl installationService = new InstallationServiceImpl();
416         /*
417          * Create test parameters
418          */

419         String JavaDoc componentName = "componentName";
420         JBIDescriptor descriptor = createMock(JBIDescriptor.class);
421         ComponentDescription component = createMock(ComponentDescription.class);
422         Identification id = createMock(Identification.class);
423         /*
424          * Initialize Mocks
425          */

426         expect(descriptor.getComponent()).andReturn(component);
427         expect(component.getIdentification()).andReturn(id);
428         expect(id.getName()).andReturn(componentName);
429         replay(descriptor);
430         replay(id);
431         replay(component);
432         /*
433          * Run Test Case 1
434          */

435         assertEquals("Wrong invokation result", componentName,
436                 installationService
437                         .getComponentNameFromJBIDescriptor(descriptor));
438         verify(descriptor);
439         verify(id);
440         verify(component);
441     }
442
443     public void testGetSharedLibraryName() {
444         /*
445          * Test Case 1
446          */

447         InstallationServiceImpl installationService = new InstallationServiceImpl();
448         /*
449          * Create test parameters
450          */

451         String JavaDoc sharedLibraryName = "sharedLibraryName";
452         JBIDescriptor descriptor = createMock(JBIDescriptor.class);
453         SharedLibrary sharedLibrary = createMock(SharedLibrary.class);
454         Identification id = createMock(Identification.class);
455         /*
456          * Initialize Mocks
457          */

458         expect(descriptor.getSharedLibrary()).andReturn(sharedLibrary);
459         expect(sharedLibrary.getIdentification()).andReturn(id);
460         expect(id.getName()).andReturn(sharedLibraryName);
461         replay(descriptor);
462         replay(id);
463         replay(sharedLibrary);
464         /*
465          * Run Test Case 1
466          */

467         assertEquals("Wrong invokation result", sharedLibraryName,
468                 installationService.getSharedLibraryName(descriptor));
469         verify(descriptor);
470         verify(id);
471         verify(sharedLibrary);
472     }
473
474     public void testStart() {
475         /*
476          * Test Case 1
477          */

478         InstallationServiceImpl installationService = new InstallationServiceImpl();
479         /*
480          * Create test parameters
481          */

482         /*
483          * Run Test Case 1
484          */

485         installationService.start();
486         assertNotNull("Initialization incorectly done",
487                 installationService.slLoadedCache);
488         assertNotNull("Initialization incorectly done",
489                 installationService.componentLoadedCache);
490         assertNotNull("Initialization incorectly done", installationService.log);
491         assertNotNull("Initialization incorectly done",
492                 installationService.packageHandler);
493     }
494
495     // public void testInstallSharedLibrary() {
496
// /*
497
// * Test Case 1 Parameter librayURL is null, an IllegalArgumentException
498
// * is raised
499
// */
500
// /*
501
// * Create Mocks
502
// */
503
// Method method1 = null;
504
// Method method2 = null;
505
// Method method3 = null;
506
// Method method4 = null;
507
// Method method5 = null;
508
// Method method6 = null;
509
// Method method7 = null;
510
// Method method8 = null;
511
// try {
512
// method1 = InstallationServiceImpl.class.getDeclaredMethod(
513
// "checkSharedLibrary", new Class[] {JBIDescriptor.class,
514
// URI.class});
515
// method2 = InstallationServiceImpl.class.getDeclaredMethod(
516
// "getSharedLibraryName", new Class[] {JBIDescriptor.class});
517
// method3 = InstallationServiceImpl.class.getDeclaredMethod(
518
// "installSharedLibrary", new Class[] {URI.class,
519
// JBIDescriptor.class});
520
// method4 = InstallationServiceImpl.class.getDeclaredMethod(
521
// "getInstalledArchive", new Class[] {File.class});
522
// method5 = InstallationServiceImpl.class.getDeclaredMethod(
523
// "createSuccessFile", new Class[] {File.class});
524
// method6 = InstallationServiceImpl.class.getDeclaredMethod(
525
// "createFileFromURI", new Class[] {URI.class});
526
// method7 = InstallationServiceImpl.class.getDeclaredMethod("copyFile",
527
// new Class[] {File.class, File.class});
528
// method8 = InstallationServiceImpl.class.getDeclaredMethod(
529
// "getSharedLibraryName", new Class[] {JBIDescriptor.class});
530
// } catch (Exception e) {
531
// e.printStackTrace();
532
// fail("Could not retrieve mocked methods");
533
// }
534
// Method[] mockedMethods = new Method[] {method1, method2, method3,
535
// method4, method5, method6, method7, method8};
536
// InstallationServiceImpl installationService = createMock(
537
// InstallationServiceImpl.class, mockedMethods);
538
// String librayURL = null;
539
// String result = null;
540
// LoggingUtil log = createMock(LoggingUtil.class);
541
// installationService.log = log;
542
// /*
543
// * Run Test Case 1
544
// */
545
// try {
546
// result = installationService.installSharedLibrary(librayURL);
547
// fail("No exception was raised");
548
// } catch (Exception e) {
549
// // Do nothing
550
// }
551
//
552
// /*
553
// * Test Case 2 Parameter librayURL is empty, an IllegalArgumentException
554
// * is raised
555
// */
556
// librayURL = "";
557
// /*
558
// * Run Test Case 2
559
// */
560
// try {
561
// result = installationService.installSharedLibrary(librayURL);
562
// fail("No exception was raised");
563
// } catch (Exception e) {
564
// // Do nothing
565
// }
566
//
567
// /*
568
// * Test Case 3 Parameter librayURL is not legal , an
569
// * IllegalArgumentException is raised
570
// */
571
// librayURL = "illegalURL";
572
// /*
573
// * Run Test Case 3
574
// */
575
// try {
576
// result = installationService.installSharedLibrary(librayURL);
577
// fail("No exception was raised");
578
// } catch (Exception e) {
579
// // Do nothing
580
// }
581
//
582
// /*
583
// * Test Case 4 Parameter librayURL is valid, checkSharedLibrary return
584
// * false
585
// */
586
// librayURL = "file://some/url";
587
// PackageHandler packageHandler = createMock(PackageHandler.class);
588
// URI archiveURI = null;
589
// /*
590
// * Initialize Mocks
591
// */
592
// try {
593
// expect(packageHandler.processAndGetPackageURI(librayURL, true))
594
// .andReturn(archiveURI);
595
// expect(packageHandler.loadDescriptor(null)).andReturn(null);
596
// installationService.checkSharedLibrary(null, null);
597
// expect(installationService.getSharedLibraryName(null)).andReturn(
598
// null);
599
// } catch (Exception e) {
600
// e.printStackTrace();
601
// fail("Could not initialize Mocks");
602
// }
603
// replay(packageHandler);
604
// replay(installationService);
605
// installationService.packageHandler = packageHandler;
606
// /*
607
// * Run Test Case 4
608
// */
609
// try {
610
// result = installationService.installSharedLibrary(librayURL);
611
// } catch (Exception e) {
612
// fail("Error during invokation");
613
// }
614
// assertTrue("Wrong invokation result", result
615
// .contains(InstallationServiceImpl.ERROR_INSTALL_SHARED_LIBRARY));
616
// verify(packageHandler);
617
// verify(installationService);
618
//
619
// /*
620
// * Test Case 5 Parameter librayURL is valid, checkSharedLibrary return
621
// * true
622
// */
623
// reset(packageHandler);
624
// reset(installationService);
625
// librayURL = "file://some/url";
626
// String libraryName = "libraryName";
627
// URI installationRoot = null;
628
// JBIDescriptor descriptor = new JBIDescriptor();
629
// try {
630
// installationRoot = new URI("file://installation/root");
631
// archiveURI = new URI("file://archive");
632
// } catch (Exception e) {
633
// e.printStackTrace();
634
// fail("Could not create Test parameters");
635
// }
636
// SystemState recoverySystem = createMock(SystemStateImpl.class);
637
// /*
638
// * Initialize Mocks
639
// */
640
// try {
641
// expect(packageHandler.processAndGetPackageURI(librayURL, true))
642
// .andReturn(archiveURI);
643
// expect(packageHandler.loadDescriptor(archiveURI)).andReturn(
644
// descriptor);
645
// expect(
646
// packageHandler.expandPackageIntoRepository(libraryName,
647
// archiveURI, EntityType.SL_TYPE)).andReturn(installationRoot);
648
// installationService.checkSharedLibrary(descriptor,
649
// archiveURI);
650
// expect(installationService.getSharedLibraryName(descriptor))
651
// .andReturn(libraryName);
652
// expect(
653
// installationService.installSharedLibrary(installationRoot,
654
// descriptor)).andReturn(libraryName);
655
// expect(installationService.createFileFromURI(archiveURI))
656
// .andReturn(null);
657
// expect(installationService.getInstalledArchive(null)).andReturn(
658
// testDataDir);
659
// installationService.copyFile(null, testDataDir);
660
// installationService.createSuccessFile(testDataDir);
661
// } catch (Exception e) {
662
// e.printStackTrace();
663
// fail("Could not initialize Mocks");
664
// }
665
// replay(packageHandler);
666
// replay(installationService);
667
// installationService.packageHandler = packageHandler;
668
// installationService.recoverySrv = recoverySystem;
669
// /*
670
// * Run Test Case 5
671
// */
672
// try {
673
// result = installationService.installSharedLibrary(librayURL);
674
// } catch (Exception e) {
675
// e.printStackTrace();
676
// fail("Error during invokation");
677
// }
678
// assertNotNull("Result of installSharedLibray must not be null", result);
679
// assertFalse("Result of installSharedLibray must not be empty", result
680
// .length() == 0);
681
// assertTrue("Wrong invokation result", result.equals(libraryName));
682
// verify(packageHandler);
683
// verify(installationService);
684
//
685
// }
686
//
687
// public void testInstallSharedLibrary2() {
688
// /*
689
// * Test Case 1 The parameter installationRoot is null, an exception will
690
// * be raised
691
// */
692
// Method method1 = null;
693
// try {
694
// method1 = InstallationServiceImpl.class.getDeclaredMethod(
695
// "isParentFirst", new Class[] {SharedLibrary.class});
696
// } catch (Exception e) {
697
// e.printStackTrace();
698
// fail("Could not retrieve mocked methods");
699
// }
700
// Method[] mockedMethods = new Method[] {method1};
701
// InstallationServiceImpl installationService = createMock(
702
// InstallationServiceImpl.class, mockedMethods);
703
// LoggingUtil log = createMock(LoggingUtil.class);
704
// installationService.log = log;
705
// /*
706
// * Create Test parameters
707
// */
708
// URI installationRoot = null;
709
// JBIDescriptor descriptor = null;
710
// /*
711
// * Run Test Case 1
712
// */
713
// try {
714
// installationService.installSharedLibrary(installationRoot,
715
// descriptor);
716
// fail("No exception raised");
717
// } catch (Exception e) {
718
// // Do nothing
719
// }
720
//
721
// /*
722
// * Test Case 2 The parameter installationRoot is null, an exception will
723
// * be raised
724
// */
725
// /*
726
// * Create Test parameters
727
// */
728
// try {
729
// installationRoot = new URI("file://installation/root");
730
// } catch (Exception e) {
731
// e.printStackTrace();
732
// fail("Could not create test parameters");
733
// }
734
// /*
735
// * Run Test Case 2
736
// */
737
// try {
738
// installationService.installSharedLibrary(installationRoot,
739
// descriptor);
740
// fail("No exception raised");
741
// } catch (Exception e) {
742
// // Do nothing
743
// }
744
//
745
// /*
746
// * Test Case 3
747
// *
748
// */
749
// /*
750
// * Create Test parameters
751
// */
752
// descriptor = createMock(JBIDescriptor.class);
753
// SharedLibrary sl = createMock(SharedLibrary.class);
754
// Identification id = createMock(Identification.class);
755
// String slName = "sharedLibraryName";
756
// LoaderManager loaderManager = createMock(LoaderManagerImpl.class);
757
// /*
758
// * Initialize Mocks
759
// */
760
// expect(descriptor.getSharedLibrary()).andReturn(sl);
761
// expect(installationService.isParentFirst(sl)).andReturn(true);
762
// expect(sl.getIdentification()).andReturn(id);
763
// expect(sl.getSharedLibraryClassPath()).andReturn(null);
764
// expect(id.getName()).andReturn(slName);
765
// replay(descriptor);
766
// replay(installationService);
767
// replay(id);
768
// replay(sl);
769
// installationService.loaderSrv = loaderManager;
770
// installationService.slLoadedCache = new ArrayList<String>();
771
// String result = null;
772
// /*
773
// * Run Test Case 3
774
// */
775
// try {
776
// result = installationService.installSharedLibrary(installationRoot,
777
// descriptor);
778
// } catch (Exception e) {
779
// e.printStackTrace();
780
// fail("No exception raised");
781
// }
782
// assertEquals("Wrong invokation result", result, slName);
783
// verify(descriptor);
784
// verify(installationService);
785
// verify(id);
786
// verify(sl);
787
//
788
// /*
789
// * Test Case 4 The installationRoot can not be parse to an url
790
// */
791
// reset(descriptor);
792
// reset(installationService);
793
// reset(id);
794
// reset(sl);
795
// /*
796
// * Create Test parameters
797
// */
798
// try {
799
// installationRoot = new URI("error://installation/root");
800
// } catch (Exception e) {
801
// e.printStackTrace();
802
// fail("Could not create test parameters");
803
// }
804
// /*
805
// * Initialize Mocks
806
// */
807
// expect(descriptor.getSharedLibrary()).andReturn(sl);
808
// expect(installationService.isParentFirst(sl)).andReturn(true);
809
// replay(descriptor);
810
// replay(installationService);
811
// installationService.loaderSrv = loaderManager;
812
// installationService.slLoadedCache = new ArrayList<String>();
813
// result = null;
814
// /*
815
// * Run Test Case 4
816
// */
817
// try {
818
// result = installationService.installSharedLibrary(installationRoot,
819
// descriptor);
820
// } catch (Exception e) {
821
// e.printStackTrace();
822
// fail("No exception raised");
823
// }
824
// assertNull("Wrong invokation result", result);
825
// verify(descriptor);
826
// verify(installationService);
827
//
828
// }
829

830     public void testInstallationService() {
831         /*
832          * Test Case 1
833          */

834         InstallationServiceImpl installationService = new InstallationServiceImpl();
835         assertNotNull(installationService);
836     }
837
838     public void testLoadInstaller() {
839         /*
840          * Test Case 1 The parameter componentName is null, an exception is
841          * raised
842          */

843         InstallationServiceImpl installationService = new InstallationServiceImpl();
844         String JavaDoc componentName = null;
845         LoggingUtil log = createMock(LoggingUtil.class);
846         installationService.log = log;
847         /*
848          * Run Test Case 1
849          */

850         try {
851             installationService.loadInstaller(componentName);
852             fail("No exception was thrown");
853         } catch (Exception JavaDoc e) {
854             // Do nothing
855
}
856
857         /*
858          * Test Case 2 The parameter componentName is empty, an exception is
859          * raised
860          */

861         componentName = "";
862         /*
863          * Run Test Case 2
864          */

865         try {
866             installationService.loadInstaller(componentName);
867             fail("No exception was thrown");
868         } catch (Exception JavaDoc e) {
869             // Do nothing
870
}
871
872         /*
873          * Test Case 3 There is no installer for this component name
874          */

875         componentName = "componentName";
876         LifeCycleManagerService lcms = createMock(LifeCycleManagerImpl.class);
877         installationService.jmxAdmin = lcms;
878         /*
879          * Run Test Case 3
880          */

881         ObjectName JavaDoc result = installationService.loadInstaller(componentName);
882         assertNull("Wrong invokation result", result);
883     }
884
885     public void testLoadNewInstaller() {
886         /*
887          * Test Case 1 The parameter installZipUrl is null, an exception is
888          * raised
889          */

890         /*
891          * Create Mocks
892          */

893         Method JavaDoc method1 = null;
894         Method JavaDoc method2 = null;
895         Method JavaDoc method3 = null;
896         Method JavaDoc method4 = null;
897         Method JavaDoc method5 = null;
898         Method JavaDoc method6 = null;
899         Method JavaDoc method7 = null;
900         Method JavaDoc method8 = null;
901         Method JavaDoc method9 = null;
902         try {
903             method1 = InstallationServiceImpl.class.getDeclaredMethod(
904                     "checkComponent", new Class JavaDoc[] {JBIDescriptor.class,
905                         URI JavaDoc.class});
906             method2 = InstallationServiceImpl.class.getDeclaredMethod(
907                     "checkInstalledSLForComp",
908                     new Class JavaDoc[] {JBIDescriptor.class});
909             method3 = InstallationServiceImpl.class.getDeclaredMethod(
910                     "getComponentNameFromJBIDescriptor",
911                     new Class JavaDoc[] {JBIDescriptor.class});
912             method4 = InstallationServiceImpl.class.getDeclaredMethod(
913                     "loadNewInstaller", new Class JavaDoc[] {URI JavaDoc.class,
914                         JBIDescriptor.class});
915             method5 = InstallationServiceImpl.class.getDeclaredMethod(
916                     "createFileFromURI", new Class JavaDoc[] {URI JavaDoc.class});
917             method6 = InstallationServiceImpl.class.getDeclaredMethod(
918                     "getInstalledArchive", new Class JavaDoc[] {File JavaDoc.class});
919             method7 = InstallationServiceImpl.class.getDeclaredMethod(
920                     "copyFile", new Class JavaDoc[] {File JavaDoc.class, File JavaDoc.class});
921             method8 = InstallationServiceImpl.class.getDeclaredMethod(
922                     "createSuccessFile", new Class JavaDoc[] {File JavaDoc.class});
923             method9 = InstallationServiceImpl.class.getDeclaredMethod(
924                     "explodeComponent", new Class JavaDoc[] {String JavaDoc.class, URI JavaDoc.class});
925         } catch (Exception JavaDoc e) {
926             e.printStackTrace();
927             fail("Could not retrieve mockedMethods");
928         }
929         Method JavaDoc[] mockedMethods = new Method JavaDoc[] {method1, method2, method3,
930             method4, method5, method6, method7, method8, method9};
931         InstallationServiceImpl installationService = createMock(
932                 InstallationServiceImpl.class, mockedMethods);
933         String JavaDoc installZipUrl = null;
934         LoggingUtil log = createMock(LoggingUtil.class);
935         installationService.log = log;
936         /*
937          * Run Test Case 1
938          */

939         try {
940             installationService.loadNewInstaller(installZipUrl);
941             fail("No exception was thrown");
942         } catch (Exception JavaDoc e) {
943             // Do nothing
944
}
945
946         /*
947          * Test Case 2 The parameter installZipUrl is empty, an exception is
948          * raised
949          */

950         installZipUrl = "";
951         /*
952          * Run Test Case 2
953          */

954         try {
955             installationService.loadNewInstaller(installZipUrl);
956             fail("No exception was thrown");
957         } catch (Exception JavaDoc e) {
958             // Do nothing
959
}
960
961         /*
962          * Test Case 3 The parameter installZipUrl is not a legal URL, an
963          * exception is raised
964          */

965         installZipUrl = "illegalURL";
966         /*
967          * Run Test Case 3
968          */

969         try {
970             installationService.loadNewInstaller(installZipUrl);
971             fail("No exception was thrown");
972         } catch (Exception JavaDoc e) {
973             // Do nothing
974
}
975
976         /*
977          * Test Case 4 The parameter installZipUrl is a valid URL
978          */

979         installZipUrl = "file://zip/URL";
980         PackageHandler packageHandler = createMock(PackageHandler.class);
981         JBIDescriptor descriptor = createMock(JBIDescriptor.class);
982         URI JavaDoc archiveURI = null;
983         try {
984             archiveURI = new URI JavaDoc("file://archive/uri");
985         } catch (Exception JavaDoc e) {
986             e.printStackTrace();
987             fail("Could not create test parameters");
988         }
989
990         reset(installationService);
991         reset(packageHandler);
992         /*
993          * Create test parameters
994          */

995         String JavaDoc componentName = "componentName";
996         URI JavaDoc installRootURI = null;
997         try {
998             installRootURI = new URI JavaDoc("file://install/root");
999         } catch (Exception JavaDoc e) {
1000            e.printStackTrace();
1001            fail("Could not create test parameters");
1002        }
1003        File JavaDoc file = new File JavaDoc("");
1004        File JavaDoc installedArchive = new File JavaDoc(testDataDir, "installedArchive");
1005        SystemState recoverySrv = createMock(SystemStateImpl.class);
1006        ObjectName JavaDoc invokationResult = createMock(ObjectName JavaDoc.class);
1007        /*
1008         * Initialize Mocks
1009         */

1010        try {
1011            expect(packageHandler.processAndGetPackageURI(installZipUrl, true))
1012                    .andReturn(archiveURI);
1013            expect(packageHandler.loadDescriptor(archiveURI)).andReturn(
1014                    descriptor);
1015            installationService.checkComponent(descriptor, archiveURI);
1016            expect(
1017                    installationService.loadNewInstaller(installRootURI,
1018                            descriptor)).andReturn(invokationResult);
1019            expect(
1020                    installationService
1021                            .getComponentNameFromJBIDescriptor(descriptor))
1022                    .andReturn(componentName);
1023            expect(
1024                    installationService.explodeComponent(componentName,
1025                            archiveURI)).andReturn(installRootURI);
1026            expect(installationService.createFileFromURI(archiveURI))
1027                    .andReturn(file);
1028            expect(installationService.getInstalledArchive(file)).andReturn(
1029                    installedArchive);
1030            installationService.createSuccessFile(installedArchive);
1031            installationService.copyFile(file, installedArchive);
1032        } catch (Exception JavaDoc e) {
1033            e.printStackTrace();
1034            fail("Could not initialize Mocks");
1035        }
1036        replay(installationService);
1037        replay(packageHandler);
1038        installationService.packageHandler = packageHandler;
1039        installationService.recoverySrv = recoverySrv;
1040        /*
1041         * Run Test Case 6
1042         */

1043        ObjectName JavaDoc result = null;
1044        try {
1045            result = installationService.loadNewInstaller(installZipUrl);
1046        } catch (Exception JavaDoc e) {
1047            fail("Error during invokation");
1048        }
1049        assertNotNull("Result of loadNewInstaller must not be null", result);
1050        assertEquals("Wrong invokation result ", result, invokationResult);
1051        verify(installationService);
1052        verify(packageHandler);
1053    }
1054
1055    public void testCheckInstalledSLForComp() {
1056        /*
1057         * Test Case 1
1058         */

1059        InstallationServiceImpl installationService = new InstallationServiceImpl();
1060        /*
1061         * Create Test parameters
1062         */

1063        JBIDescriptor descriptor = createMock(JBIDescriptor.class);
1064        ComponentDescription componentDescription = createMock(ComponentDescription.class);
1065        SharedLibraryList sharedLibrayList = createMock(SharedLibraryList.class);
1066        LoggingUtil log = createMock(LoggingUtil.class);
1067        List JavaDoc<SharedLibraryList> slList = new ArrayList JavaDoc<SharedLibraryList>();
1068        slList.add(sharedLibrayList);
1069        installationService.log = log;
1070        /*
1071         * Initialise Mocks
1072         */

1073        expect(descriptor.getComponent()).andReturn(componentDescription);
1074        expect(componentDescription.getSharedLibraryList()).andReturn(slList);
1075        expect(sharedLibrayList.getName()).andReturn("a SL name").anyTimes();
1076        replay(descriptor);
1077        replay(sharedLibrayList);
1078        replay(componentDescription);
1079        installationService.slLoadedCache = new ArrayList JavaDoc<String JavaDoc>();
1080        /*
1081         * Run Test Case 1
1082         */

1083        try {
1084            installationService.checkInstalledSLForComp(descriptor);
1085            fail("Must throw an exception if SL is missing");
1086        } catch (PetalsException e) {
1087            // Do nothing it's ok
1088
}
1089        verify(descriptor);
1090        verify(componentDescription);
1091    }
1092
1093    // public void testCheckSharedLibrary() {
1094
// /*
1095
// * Test Case 1 descriptor.getSharedLibrary() return null
1096
// */
1097
// /*
1098
// * Create Mocks
1099
// */
1100
// Method method1 = null;
1101
// Method method2 = null;
1102
// Method method3 = null;
1103
// try {
1104
// method1 = InstallationServiceImpl.class.getDeclaredMethod("isLoaded",
1105
// new Class[] {String.class});
1106
// method2 = InstallationServiceImpl.class.getDeclaredMethod(
1107
// "openZipFile", new Class[] {URI.class});
1108
// method3 = InstallationServiceImpl.class.getDeclaredMethod(
1109
// "checkClassPathElements", new Class[] {ZipFile.class,
1110
// List.class});
1111
// } catch (Exception e) {
1112
// e.printStackTrace();
1113
// fail("Could not retrieve mocked methods");
1114
// }
1115
// Method[] mockedMethods = new Method[] {method1, method2, method3};
1116
// InstallationServiceImpl installationService = createMock(
1117
// InstallationServiceImpl.class, mockedMethods);
1118
// LoggingUtil log = createMock(LoggingUtil.class);
1119
// installationService.log = log;
1120
// /*
1121
// * Create Test parameters
1122
// */
1123
// JBIDescriptor descriptor = createMock(JBIDescriptor.class);
1124
// URI archiveURI = new File(testDataDir, "fakearchive" + File.separator
1125
// + "archive").toURI();
1126
// SharedLibrary sharedLibray = createMock(SharedLibrary.class);
1127
// boolean result = false;
1128
// /*
1129
// * Run Test Case 1
1130
// */
1131
// try {
1132
// installationService.checkSharedLibrary(descriptor, archiveURI);
1133
// } catch (Exception e) {
1134
// e.printStackTrace();
1135
// fail("Error during invokation");
1136
// }
1137
// assertFalse("Wrong invokation result", result);
1138
//
1139
// /*
1140
// * Test Case 2 descriptor.getSharedLibrary() return an instance of
1141
// * sharedLibrary isLoaded returns true, there is already a component
1142
// * with this name on the platform
1143
// */
1144
// reset(descriptor);
1145
// /*
1146
// * Create Test parameters
1147
// */
1148
// Identification id = createMock(Identification.class);
1149
// String slName = "sharedLibraryName";
1150
// result = false;
1151
// /*
1152
// * Initialize Mocks
1153
// */
1154
// expect(descriptor.getSharedLibrary()).andReturn(sharedLibray);
1155
// expect(sharedLibray.getIdentification()).andReturn(id);
1156
// expect(id.getName()).andReturn(slName);
1157
// expect(installationService.isSLLoaded(slName)).andReturn(true);
1158
// replay(descriptor);
1159
// replay(sharedLibray);
1160
// replay(id);
1161
// replay(installationService);
1162
// /*
1163
// * Run Test Case 2
1164
// */
1165
// try {
1166
// installationService.checkSharedLibrary(descriptor, archiveURI);
1167
// } catch (Exception e) {
1168
// e.printStackTrace();
1169
// fail("Error during invokation");
1170
// }
1171
// assertFalse("Wrong invokation result", result);
1172
// verify(descriptor);
1173
// verify(sharedLibray);
1174
// verify(id);
1175
// verify(installationService);
1176
//
1177
// /*
1178
// * Test Case 3 descriptor.getSharedLibrary() return an instance of
1179
// * sharedLibrary isLoaded returns false, there is no other component
1180
// * with this name on the platform
1181
// */
1182
// reset(descriptor);
1183
// reset(sharedLibray);
1184
// reset(id);
1185
// reset(installationService);
1186
// /*
1187
// * Create Test parameters
1188
// */
1189
// result = false;
1190
// ZipFile zipFile = createMock(MockZipFile.class, new Method[] {});
1191
// /*
1192
// * Initialize Mocks
1193
// */
1194
// try {
1195
// expect(descriptor.getSharedLibrary()).andReturn(sharedLibray);
1196
// expect(sharedLibray.getIdentification()).andReturn(id);
1197
// expect(sharedLibray.getSharedLibraryClassPath()).andReturn(null);
1198
// expect(id.getName()).andReturn(slName);
1199
// expect(installationService.isSLLoaded(slName)).andReturn(false);
1200
// expect(installationService.openZipFile(archiveURI)).andReturn(
1201
// zipFile);
1202
// installationService.checkClassPathElements(zipFile, null);
1203
// } catch (Exception e) {
1204
// e.printStackTrace();
1205
// fail("Could not initialize Mocks");
1206
// }
1207
// replay(descriptor);
1208
// replay(sharedLibray);
1209
// replay(id);
1210
// replay(installationService);
1211
// /*
1212
// * Run Test Case 3
1213
// */
1214
// try {
1215
// installationService.checkSharedLibrary(descriptor, archiveURI);
1216
// fail("No exception was raised");
1217
// } catch (Exception e) {
1218
// verify(descriptor);
1219
// verify(sharedLibray);
1220
// verify(id);
1221
// verify(installationService);
1222
// }
1223
// }
1224

1225    public void testCreateAndRegisterInstallerMBean() {
1226        /*
1227         * Test Case 1
1228         */

1229        InstallationServiceImpl installationService = new InstallationServiceImpl();
1230        /*
1231         * Create Test parameters
1232         */

1233        LoggingUtil log = createMock(LoggingUtil.class);
1234        installationService.log = log;
1235        ComponentContextImpl componentCtx = createMock(ComponentContextImpl.class);
1236// InstallationContextImpl installationCtx = createMock(InstallationContextImpl.class);
1237
JBIDescriptor descriptor = createMock(JBIDescriptor.class);
1238        URI JavaDoc installationRoot = new File JavaDoc(testDataDir, "fakearchive"
1239                + File.separator + "archive").toURI();
1240        ComponentDescription componentDescription = createMock(ComponentDescription.class);
1241        ObjectName JavaDoc result = null;
1242        LifeCycleManagerService lcms = createMock(LifeCycleManagerImpl.class);
1243        MBeanNamesImpl beanNames = createMock(MBeanNamesImpl.class);
1244        Identification id = createMock(Identification.class);
1245        String JavaDoc componentName = "componentName";
1246        ObjectName JavaDoc objectName = createMock(ObjectName JavaDoc.class);
1247        /*
1248         * Initialize Mocks
1249         */

1250        try {
1251            expect(descriptor.getComponent()).andReturn(componentDescription);
1252            expect(lcms.getMBeanNames()).andReturn(beanNames);
1253            expect(lcms.registerInstaller(isA(Installer.class)))
1254                    .andReturn(null);
1255            expect(componentDescription.getIdentification()).andReturn(id);
1256            expect(id.getName()).andReturn(componentName);
1257            expect(beanNames.createInstallerMBeanName(componentName))
1258                    .andReturn(objectName);
1259        } catch (Exception JavaDoc e) {
1260            e.printStackTrace();
1261            fail("Could not initialize Mocks");
1262        }
1263        replay(lcms);
1264        replay(descriptor);
1265        replay(id);
1266        replay(beanNames);
1267        replay(componentDescription);
1268        installationService.jmxAdmin = lcms;
1269        /*
1270         * Run Test Case 1
1271         */

1272        try {
1273            result = installationService
1274                    .createAndRegisterInstallerMBean(componentCtx,
1275                            descriptor, installationRoot);
1276        } catch (PetalsException e) {
1277            e.printStackTrace();
1278        }
1279        verify(lcms);
1280        verify(descriptor);
1281        verify(id);
1282        verify(beanNames);
1283        verify(componentDescription);
1284        assertEquals("Wrong invokation result", result, objectName);
1285    }
1286
1287    public void testCreateFileFromURI() {
1288        /*
1289         * Test Case 1
1290         */

1291        InstallationServiceImpl installationService = new InstallationServiceImpl();
1292        /*
1293         * Create Test parameters
1294         */

1295        URI JavaDoc fileURI = new File JavaDoc(testDataDir, "fakearchive" + File.separator
1296                + "archive").toURI();
1297        File JavaDoc result = null;
1298        /*
1299         * Run Test Case 1
1300         */

1301        result = installationService.createFileFromURI(fileURI);
1302        assertEquals("Wrong invokation result", result.toURI(), fileURI);
1303    }
1304
1305    public void testLoadNewInstaller2() {
1306        /*
1307         * Test Case 1 The parameter installationURI is null, an exception is
1308         * raised
1309         */

1310        /*
1311         * Create Mocks
1312         */

1313        Method JavaDoc createComponentContextMethod = null;
1314// Method method2 = null;
1315
Method JavaDoc createAndRegisterInstallerMBeanMethod = null;
1316        Method JavaDoc getComponentNameFromJBIDescriptormethod = null;
1317        Method JavaDoc checkInstalledSLForCompMethod = null;
1318        try {
1319            createComponentContextMethod = InstallationServiceImpl.class.getDeclaredMethod(
1320                    "createComponentContext", new Class JavaDoc[] {JBIDescriptor.class,
1321                        URI JavaDoc.class});
1322// method2 = InstallationServiceImpl.class.getDeclaredMethod(
1323
// "createInstallationContext", new Class[] {
1324
// ComponentContextImpl.class, JBIDescriptor.class});
1325
createAndRegisterInstallerMBeanMethod = InstallationServiceImpl.class
1326                .getDeclaredMethod("createAndRegisterInstallerMBean",
1327                    new Class JavaDoc[] {ComponentContextImpl.class,
1328                        JBIDescriptor.class, URI JavaDoc.class});
1329            getComponentNameFromJBIDescriptormethod = InstallationServiceImpl.class.getDeclaredMethod(
1330                    "getComponentNameFromJBIDescriptor",
1331                    new Class JavaDoc[] {JBIDescriptor.class});
1332            checkInstalledSLForCompMethod = InstallationServiceImpl.class.getDeclaredMethod(
1333                    "checkInstalledSLForComp",
1334                    new Class JavaDoc[] {JBIDescriptor.class});
1335        } catch (Exception JavaDoc e) {
1336            e.printStackTrace();
1337            fail("Could not retrieve mockedMethods");
1338        }
1339// Method[] mockedMethods = new Method[] {method1, method2, method3,
1340
// method4, method5};
1341
Method JavaDoc[] mockedMethods = new Method JavaDoc[] {createComponentContextMethod, createAndRegisterInstallerMBeanMethod,
1342            getComponentNameFromJBIDescriptormethod, checkInstalledSLForCompMethod};
1343        
1344        InstallationServiceImpl installationService = createMock(
1345                InstallationServiceImpl.class, mockedMethods);
1346        LoggingUtil log = createMock(LoggingUtil.class);
1347        installationService.log = log;
1348        /*
1349         * Create Test parameters
1350         */

1351        URI JavaDoc installationRoot = null;
1352        JBIDescriptor descriptor = null;
1353        /*
1354         * Run Test Case 1
1355         */

1356        try {
1357            installationService.loadNewInstaller(installationRoot, descriptor);
1358            fail("No exception was raised");
1359        } catch (Exception JavaDoc e) {
1360            // Do nothing
1361
}
1362
1363        /*
1364         * Test Case 2 The parameter descriptor is null, an exception is raised
1365         */

1366        /*
1367         * Create Test parameters
1368         */

1369        try {
1370            installationRoot = new URI JavaDoc("file://installation/root");
1371        } catch (Exception JavaDoc e) {
1372            e.printStackTrace();
1373            fail("Could not create test parameters");
1374        }
1375        /*
1376         * Run Test Case 2
1377         */

1378        try {
1379            installationService.loadNewInstaller(installationRoot, descriptor);
1380            fail("No exception was raised");
1381        } catch (Exception JavaDoc e) {
1382            // Do nothing
1383
}
1384
1385        /*
1386         * Test Case 3
1387         *
1388         */

1389        /*
1390         * Create Test parameters
1391         */

1392        descriptor = createMock(JBIDescriptor.class);
1393        ComponentContextImpl componentCtx = createMock(ComponentContextImpl.class);
1394// InstallationContextImpl installationCtx = createMock(InstallationContextImpl.class);
1395
ObjectName JavaDoc objectName = createMock(ObjectName JavaDoc.class);
1396        String JavaDoc componentName = "componentName";
1397        /*
1398         * Initialize Mocks
1399         */

1400        try {
1401            expect(
1402                    installationService.createComponentContext(descriptor,
1403                            installationRoot)).andReturn(componentCtx);
1404        } catch (PetalsException e2) {
1405            e2.printStackTrace();
1406        }
1407// expect(
1408
// installationService.createInstallationContext(componentCtx,
1409
// descriptor)).andReturn(installationCtx);
1410
try {
1411            expect(
1412                    installationService.createAndRegisterInstallerMBean(
1413                            componentCtx, descriptor,
1414                            installationRoot)).andReturn(objectName);
1415        } catch (PetalsException e1) {
1416            e1.printStackTrace();
1417        }
1418        try {
1419            installationService.checkInstalledSLForComp(descriptor);
1420        } catch (PetalsException e1) {
1421            e1.printStackTrace();
1422        }
1423        expect(
1424                installationService
1425                        .getComponentNameFromJBIDescriptor(descriptor))
1426                .andReturn(componentName);
1427        replay(installationService);
1428        installationService.componentLoadedCache = new ArrayList JavaDoc<String JavaDoc>();
1429        ObjectName JavaDoc result = null;
1430        /*
1431         * Run Test Case 3
1432         */

1433        try {
1434            result = installationService.loadNewInstaller(installationRoot,
1435                    descriptor);
1436        } catch (Exception JavaDoc e) {
1437            e.printStackTrace();
1438            fail("Error during invokation");
1439        }
1440        verify(installationService);
1441        assertNotNull("Result of loadNewInstaller", result);
1442        assertEquals("Wrong invokation result", objectName, result);
1443    }
1444
1445    public void testStop() {
1446        /*
1447         * Test Case 1 The requested interface does not belong to adminService
1448         */

1449        InstallationServiceImpl installationService = new InstallationServiceImpl();
1450        /*
1451         * Create test parameters
1452         */

1453        installationService.start();
1454        /*
1455         * Run Test Case 1
1456         */

1457        installationService.stop();
1458        assertNull("Shutdown process incomplete", installationService.logger);
1459        assertNull("Shutdown process incomplete",
1460                installationService.slLoadedCache);
1461        assertNull("Shutdown process incomplete",
1462                installationService.componentLoadedCache);
1463    }
1464
1465    public void testUninstallSharedLibrary() {
1466        /*
1467         * Test Case 1 The parameter slName is null, an exception is raised
1468         */

1469        /*
1470         * Create Mocks
1471         */

1472        Method JavaDoc method1 = null;
1473        Method JavaDoc method2 = null;
1474        Method JavaDoc method3 = null;
1475        Method JavaDoc method4 = null;
1476        try {
1477            method1 = InstallationServiceImpl.class.getDeclaredMethod(
1478                    "checkComponentShutdownStateForSL",
1479                    new Class JavaDoc[] {String JavaDoc.class});
1480            method2 = InstallationServiceImpl.class.getDeclaredMethod(
1481                    "createFileFromURI", new Class JavaDoc[] {URI JavaDoc.class});
1482            method3 = InstallationServiceImpl.class.getDeclaredMethod(
1483                    "getUninstalledArchive", new Class JavaDoc[] {File JavaDoc.class});
1484            /*
1485             * method4 =
1486             * InstallationServiceImpl.class.getDeclaredMethod("getComponentNameFromJBIDescriptor",new
1487             * Class[]{JBIDescriptor.class});
1488             */

1489        } catch (Exception JavaDoc e) {
1490            e.printStackTrace();
1491            fail("Could not retrieve mockedMethods");
1492        }
1493        Method JavaDoc[] mockedMethods = new Method JavaDoc[] {method1, method2, method3,
1494            method4};
1495        InstallationServiceImpl installationService = createMock(
1496                InstallationServiceImpl.class, mockedMethods);
1497        LoggingUtil log = createMock(LoggingUtil.class);
1498        installationService.log = log;
1499        LoaderManager loaderSrv = createMock(LoaderManagerImpl.class);
1500        installationService.loaderSrv = loaderSrv;
1501        installationService.slLoadedCache = new ArrayList JavaDoc<String JavaDoc>();
1502        SystemState recoverySrv = createMock(SystemStateImpl.class);
1503        installationService.recoverySrv = recoverySrv;
1504        RepositoryService repositorySrv = createMock(RepositoryImpl.class);
1505        /*
1506         * Create Test parameters
1507         */

1508        String JavaDoc slName = null;
1509        /*
1510         * Run Test Case 1
1511         */

1512        try {
1513            installationService.uninstallSharedLibrary(slName);
1514            fail("No exception was raised");
1515        } catch (Exception JavaDoc e) {
1516            // Do nothing
1517
}
1518
1519        /*
1520         * Test Case 2 The parameter slName is empty, an exception is raised
1521         */

1522        /*
1523         * Create Test parameters
1524         */

1525        slName = "";
1526        /*
1527         * Run Test Case 2
1528         */

1529        try {
1530            installationService.uninstallSharedLibrary(slName);
1531            fail("No exception was raised");
1532        } catch (Exception JavaDoc e) {
1533            // Do nothing
1534
}
1535
1536        /*
1537         * Test Case 3
1538         */

1539        /*
1540         * Create Test parameters
1541         */

1542        slName = "sharedLibraryName";
1543        PackageHandler packageHandler = createMock(PackageHandler.class);
1544        SharedLibraryState slState = createMock(SharedLibraryState.class);
1545        String JavaDoc archiveZipURL = "file://achive.zip.url";
1546        URI JavaDoc archiveURI = null;
1547        try {
1548            archiveURI = new URI JavaDoc(archiveZipURL);
1549        } catch (Exception JavaDoc e) {
1550            e.printStackTrace();
1551            fail("Could not create test parameters");
1552        }
1553        File JavaDoc installedArchive = new File JavaDoc(testDataDir, "fakearchive"
1554                + File.separator + "archive");
1555        File JavaDoc uninstalledArchive = installedArchive;
1556        /*
1557         * Initialize Mocks
1558         */

1559        try {
1560            expect(installationService.checkComponentShutdownStateForSL(slName))
1561                    .andReturn(true);
1562            expect(installationService.createFileFromURI(archiveURI))
1563                    .andReturn(installedArchive);
1564            expect(installationService.getUninstalledArchive(installedArchive))
1565                    .andReturn(uninstalledArchive);
1566            expect(repositorySrv.removeSharedLibPackage(slName))
1567                    .andReturn(true);
1568            expect(recoverySrv.deleteSharedLibraryStateHolder(slName))
1569                    .andReturn(slState);
1570            expect(slState.getArchiveURL()).andReturn(archiveZipURL);
1571            expect(packageHandler.processAndGetPackageURI(archiveZipURL, false))
1572                    .andReturn(archiveURI);
1573        } catch (Exception JavaDoc e) {
1574            e.printStackTrace();
1575            fail("Could not initialize Mocks");
1576        }
1577        replay(installationService);
1578        replay(repositorySrv);
1579        replay(slState);
1580        replay(packageHandler);
1581        replay(recoverySrv);
1582        installationService.repositorySrv = repositorySrv;
1583        installationService.packageHandler = packageHandler;
1584        installationService.recoverySrv = recoverySrv;
1585        boolean result = false;
1586        /*
1587         * Run Test Case 3
1588         */

1589        try {
1590            result = installationService.uninstallSharedLibrary(slName);
1591        } catch (Exception JavaDoc e) {
1592            fail("Error during invokation");
1593        }
1594        verify(installationService);
1595        verify(repositorySrv);
1596        verify(slState);
1597        verify(packageHandler);
1598        verify(recoverySrv);
1599        assertTrue("Wrong invokation result", result);
1600
1601        /*
1602         * Test Case 5 deleteSharedLibraryStateHolder throws an exception
1603         */

1604        /*
1605         * Create Test parameters
1606         */

1607        reset(installationService);
1608        reset(repositorySrv);
1609        reset(slState);
1610        reset(packageHandler);
1611        reset(recoverySrv);
1612        /*
1613         * Initialize Mocks
1614         */

1615        try {
1616            expect(installationService.checkComponentShutdownStateForSL(slName))
1617                    .andReturn(true);
1618            // expect(repositorySrv.removePackage(slName)).andReturn(true);
1619
expect(recoverySrv.deleteSharedLibraryStateHolder(slName))
1620                    .andThrow(
1621                            new Exception JavaDoc(
1622                                    "deleteSharedLibraryStateHolder testing exception"));
1623            // expect(slState.getArchiveURL()).andReturn(archiveZipURL);
1624
// expect(packageHandler.processAndGetPackageURI(archiveZipURL,
1625
// false)).andThrow(new PetalsException("processAndGetPackageURI
1626
// testing exception"));
1627
} catch (Exception JavaDoc e) {
1628            e.printStackTrace();
1629            fail("Could not initialize Mocks");
1630        }
1631        replay(installationService);
1632        // replay(repositorySrv);
1633
// replay(slState);
1634
// replay(packageHandler);
1635
replay(recoverySrv);
1636        installationService.repositorySrv = repositorySrv;
1637        installationService.packageHandler = packageHandler;
1638        installationService.recoverySrv = recoverySrv;
1639        result = false;
1640        /*
1641         * Run Test Case 5
1642         */

1643        try {
1644            result = installationService.uninstallSharedLibrary(slName);
1645        } catch (Exception JavaDoc e) {
1646            fail("Error during invokation");
1647        }
1648        verify(installationService);
1649        verify(recoverySrv);
1650        // verify(repositorySrv);
1651
// verify(slState);
1652
// verify(packageHandler);
1653
assertFalse("Wrong invokation result", result);
1654    }
1655
1656    public void testUnloadInstaller() {
1657        /*
1658         * Test Case 1 The parameter componentName is null, an exception is
1659         * raised
1660         */

1661        /*
1662         * Create Mocks
1663         */

1664        Method JavaDoc method1 = null;
1665        Method JavaDoc method2 = null;
1666        Method JavaDoc method3 = null;
1667        Method JavaDoc method4 = null;
1668        Method JavaDoc method5 = null;
1669        try {
1670            method1 = MockLifeCycleManagerService.class.getDeclaredMethod(
1671                    "getInstallerByName", new Class JavaDoc[] {String JavaDoc.class});
1672            method2 = MockLifeCycleManagerService.class.getDeclaredMethod(
1673                    "getMBeanServer", new Class JavaDoc[] {});
1674            method3 = MockLifeCycleManagerService.class.getDeclaredMethod(
1675                    "unregisterInstaller", new Class JavaDoc[] {ObjectName JavaDoc.class});
1676            method4 = InstallationServiceImpl.class.getDeclaredMethod(
1677                    "createFileFromURI", new Class JavaDoc[] {URI JavaDoc.class});
1678            method5 = InstallationServiceImpl.class.getDeclaredMethod(
1679                    "getUninstalledArchive", new Class JavaDoc[] {File JavaDoc.class});
1680        } catch (Exception JavaDoc e) {
1681            e.printStackTrace();
1682            fail("Could not retrieve mockedMethods");
1683        }
1684        Method JavaDoc[] mockedMethods = new Method JavaDoc[] {method4, method5};
1685        InstallationServiceImpl installationService = createMock(
1686                InstallationServiceImpl.class, mockedMethods);
1687        mockedMethods = new Method JavaDoc[] {method1, method2};
1688        LoggingUtil log = createMock(LoggingUtil.class);
1689        installationService.log = log;
1690        /*
1691         * LoaderManager loaderSrv = createMock(LoaderManagerImpl.class);
1692         * installationService.loaderSrv = loaderSrv;
1693         * installationService.packagesLoadedCache = new ArrayList<String>();
1694         * SystemState recoverySrv = createMock(SystemStateImpl.class);
1695         * installationService.recoverySrv = recoverySrv; RepositoryService
1696         * repositorySrv = createMock(RepositoryImpl.class);
1697         */

1698        /*
1699         * Create Test parameters
1700         */

1701        String JavaDoc componentName = null;
1702        /*
1703         * Run Test Case 1
1704         */

1705        try {
1706            installationService.unloadInstaller(componentName, true);
1707            fail("No exception was raised");
1708        } catch (Exception JavaDoc e) {
1709            // Do nothing
1710
}
1711
1712        /*
1713         * Test Case 2 The parameter componentName is empty, an exception is
1714         * raised
1715         */

1716        /*
1717         * Create Test parameters
1718         */

1719        componentName = "";
1720        /*
1721         * Run Test Case 2
1722         */

1723        try {
1724            installationService.unloadInstaller(componentName, true);
1725            fail("No exception was raised");
1726        } catch (Exception JavaDoc e) {
1727            // Do nothing
1728
}
1729
1730        /*
1731         * Test Case 3 mbeanSrv.getAttribute throw an InstanceNotFoundException
1732         */

1733        /*
1734         * Create Test parameters
1735         */

1736        componentName = "ComponentName";
1737        LifeCycleManagerService managerSrv = createMock(
1738                MockLifeCycleManagerService.class, mockedMethods);
1739        ObjectName JavaDoc objectName = createMock(ObjectName JavaDoc.class);
1740        MBeanServer JavaDoc beanServer = createMock(MBeanServer JavaDoc.class);
1741        /*
1742         * Initialize Mocks
1743         */

1744        try {
1745            expect(managerSrv.getInstallerByName(componentName)).andReturn(
1746                    objectName);
1747            expect(managerSrv.getMBeanServer()).andReturn(beanServer);
1748            expect(beanServer.getAttribute(objectName, "Installed")).andThrow(
1749                    new InstanceNotFoundException JavaDoc(
1750                            "getAttribute testing exception"));
1751        } catch (Exception JavaDoc e) {
1752            e.printStackTrace();
1753            fail("Could not initialize Mocks");
1754        }
1755        replay(managerSrv);
1756        replay(beanServer);
1757        installationService.jmxAdmin = managerSrv;
1758        boolean result = false;
1759        /*
1760         * Run Test Case 3
1761         */

1762        try {
1763            result = installationService.unloadInstaller(componentName, true);
1764        } catch (Exception JavaDoc e) {
1765            fail("Error during invokation");
1766        }
1767        verify(managerSrv);
1768        verify(beanServer);
1769        assertFalse("Wrong invokation result", result);
1770
1771        /*
1772         * Test Case 4 mbeanSrv.getAttribute throw an MBeanException
1773         */

1774        reset(managerSrv);
1775        reset(beanServer);
1776        /*
1777         * Create Test parameters
1778         */

1779        /*
1780         * Initialize Mocks
1781         */

1782        try {
1783            expect(managerSrv.getInstallerByName(componentName)).andReturn(
1784                    objectName);
1785            expect(managerSrv.getMBeanServer()).andReturn(beanServer);
1786            expect(beanServer.getAttribute(objectName, "Installed")).andThrow(
1787                    new MBeanException JavaDoc(new Exception JavaDoc(
1788                            "getAttribute testing exception")));
1789        } catch (Exception JavaDoc e) {
1790            e.printStackTrace();
1791            fail("Could not initialize Mocks");
1792        }
1793        replay(managerSrv);
1794        replay(beanServer);
1795        installationService.jmxAdmin = managerSrv;
1796        result = false;
1797        /*
1798         * Run Test Case 4
1799         */

1800        try {
1801            result = installationService.unloadInstaller(componentName, true);
1802        } catch (Exception JavaDoc e) {
1803            fail("Error during invokation");
1804        }
1805        verify(managerSrv);
1806        verify(beanServer);
1807        assertFalse("Wrong invokation result", result);
1808
1809        /*
1810         * Test Case 5 mbeanSrv.getAttribute throw an ReflectionException
1811         */

1812        reset(managerSrv);
1813        reset(beanServer);
1814        /*
1815         * Create Test parameters
1816         */

1817        /*
1818         * Initialize Mocks
1819         */

1820        try {
1821            expect(managerSrv.getInstallerByName(componentName)).andReturn(
1822                    objectName);
1823            expect(managerSrv.getMBeanServer()).andReturn(beanServer);
1824            expect(beanServer.getAttribute(objectName, "Installed")).andThrow(
1825                    new ReflectionException JavaDoc(new Exception JavaDoc(
1826                            "getAttribute testing exception")));
1827        } catch (Exception JavaDoc e) {
1828            e.printStackTrace();
1829            fail("Could not initialize Mocks");
1830        }
1831        replay(managerSrv);
1832        replay(beanServer);
1833        installationService.jmxAdmin = managerSrv;
1834        result = false;
1835        /*
1836         * Run Test Case 5
1837         */

1838        try {
1839            result = installationService.unloadInstaller(componentName, true);
1840        } catch (Exception JavaDoc e) {
1841            fail("Error during invokation");
1842        }
1843        verify(managerSrv);
1844        verify(beanServer);
1845        assertFalse("Wrong invokation result", result);
1846
1847        /*
1848         * Test Case 6 mbeanSrv.getAttribute throw an AttributeNotFoundException
1849         */

1850        reset(managerSrv);
1851        reset(beanServer);
1852        /*
1853         * Create Test parameters
1854         */

1855        /*
1856         * Initialize Mocks
1857         */

1858        try {
1859            expect(managerSrv.getInstallerByName(componentName)).andReturn(
1860                    objectName);
1861            expect(managerSrv.getMBeanServer()).andReturn(beanServer);
1862            expect(beanServer.getAttribute(objectName, "Installed")).andThrow(
1863                    new AttributeNotFoundException JavaDoc(
1864                            "getAttribute testing exception"));
1865        } catch (Exception JavaDoc e) {
1866            e.printStackTrace();
1867            fail("Could not initialize Mocks");
1868        }
1869        replay(managerSrv);
1870        replay(beanServer);
1871        installationService.jmxAdmin = managerSrv;
1872        result = false;
1873        /*
1874         * Run Test Case 6
1875         */

1876        try {
1877            result = installationService.unloadInstaller(componentName, true);
1878        } catch (Exception JavaDoc e) {
1879            fail("Error during invokation");
1880        }
1881        verify(managerSrv);
1882        verify(beanServer);
1883        assertFalse("Wrong invokation result", result);
1884
1885        /*
1886         * Test Case 7 mbeanSrv.getAttribute return true
1887         * jmxAdmin.unregisterInstaller raise an exception
1888         */

1889        reset(managerSrv);
1890        reset(beanServer);
1891        /*
1892         * Create Test parameters
1893         */

1894        Boolean JavaDoc getAttribute = new Boolean JavaDoc(true);
1895        /*
1896         * Initialize Mocks
1897         */

1898        try {
1899            expect(managerSrv.getInstallerByName(componentName)).andReturn(
1900                    objectName);
1901            expect(managerSrv.getMBeanServer()).andReturn(beanServer);
1902            expect(beanServer.getAttribute(objectName, "Installed")).andReturn(
1903                    getAttribute);
1904            expect(
1905                    beanServer.invoke(isA(ObjectName JavaDoc.class), isA(String JavaDoc.class),
1906                            isA(Object JavaDoc[].class), isA(String JavaDoc[].class)))
1907                    .andReturn(null);
1908        } catch (Exception JavaDoc e) {
1909            e.printStackTrace();
1910            fail("Could not initialize Mocks");
1911        }
1912        replay(managerSrv);
1913        replay(beanServer);
1914        installationService.jmxAdmin = managerSrv;
1915        result = false;
1916        /*
1917         * Run Test Case 7
1918         */

1919        try {
1920            result = installationService.unloadInstaller(componentName, true);
1921        } catch (Exception JavaDoc e) {
1922            fail("Error during invokation");
1923        }
1924        verify(managerSrv);
1925        verify(beanServer);
1926        assertFalse("Wrong invokation result", result);
1927
1928        /*
1929         * Test Case 8 mbeanSrv.getAttribute return true
1930         * recoverySrv.deleteComponentStateHolder raise an exception
1931         */

1932        reset(managerSrv);
1933        reset(beanServer);
1934        /*
1935         * Create Test parameters
1936         */

1937        mockedMethods = new Method JavaDoc[] {method1, method2, method3};
1938        managerSrv = createMock(MockLifeCycleManagerService.class,
1939                mockedMethods);
1940        SystemState sysState = createMock(SystemStateImpl.class);
1941        ComponentState componentState = createMock(ComponentState.class);
1942        RepositoryService repositorySrv = createMock(RepositoryImpl.class);
1943        /*
1944         * Initialize Mocks
1945         */

1946        try {
1947            expect(managerSrv.getInstallerByName(componentName)).andReturn(
1948                    objectName);
1949            expect(managerSrv.getMBeanServer()).andReturn(beanServer);
1950            managerSrv.unregisterInstaller(objectName);
1951            expect(beanServer.getAttribute(objectName, "Installed")).andReturn(
1952                    getAttribute);
1953            expect(
1954                    beanServer.invoke(isA(ObjectName JavaDoc.class), isA(String JavaDoc.class),
1955                            isA(Object JavaDoc[].class), isA(String JavaDoc[].class)))
1956                    .andReturn(null);
1957            expect(sysState.deleteComponentStateHolder(componentName))
1958                    .andThrow(
1959                            new Exception JavaDoc(
1960                                    "deleteComponentStateHolder testing exception"));
1961        } catch (Exception JavaDoc e) {
1962            e.printStackTrace();
1963            fail("Could not initialize Mocks");
1964        }
1965        replay(managerSrv);
1966        replay(beanServer);
1967        replay(sysState);
1968        replay(repositorySrv);
1969        installationService.jmxAdmin = managerSrv;
1970        installationService.componentLoadedCache = new ArrayList JavaDoc<String JavaDoc>();
1971        installationService.recoverySrv = sysState;
1972        installationService.repositorySrv = repositorySrv;
1973        result = false;
1974        /*
1975         * Run Test Case 8
1976         */

1977        try {
1978            result = installationService.unloadInstaller(componentName, true);
1979        } catch (Exception JavaDoc e) {
1980            fail("Error during invokation");
1981        }
1982        verify(managerSrv);
1983        verify(beanServer);
1984        verify(sysState);
1985        verify(repositorySrv);
1986        assertFalse("Wrong invokation result", result);
1987
1988        /*
1989         * Test Case 9 mbeanSrv.getAttribute return true
1990         * recoverySrv.deleteComponentStateHolder raise an exception
1991         */

1992        reset(managerSrv);
1993        reset(beanServer);
1994        reset(repositorySrv);
1995        reset(sysState);
1996        /*
1997         * Create Test parameters
1998         */

1999        String JavaDoc archiveUrl = "archive/url";
2000        URI JavaDoc archiveURI = null;
2001        try {
2002            archiveURI = new URI JavaDoc("file://arvhice.uri");
2003        } catch (Exception JavaDoc e) {
2004            e.printStackTrace();
2005            fail("Could not create Test parameters");
2006        }
2007        File JavaDoc installedArchive = new File JavaDoc(testDataDir, "fakearchive"
2008                + File.separator + "archive");
2009        File JavaDoc uninstalledArchive = installedArchive;
2010        PackageHandler packageHandler = createMock(PackageHandler.class);
2011        /*
2012         * Initialize Mocks
2013         */

2014        try {
2015            expect(managerSrv.getInstallerByName(componentName)).andReturn(
2016                    objectName);
2017            expect(managerSrv.getMBeanServer()).andReturn(beanServer);
2018            managerSrv.unregisterInstaller(objectName);
2019            expect(beanServer.getAttribute(objectName, "Installed")).andReturn(
2020                    getAttribute);
2021            expect(
2022                    beanServer.invoke(isA(ObjectName JavaDoc.class), isA(String JavaDoc.class),
2023                            isA(Object JavaDoc[].class), isA(String JavaDoc[].class)))
2024                    .andReturn(null);
2025            expect(sysState.deleteComponentStateHolder(componentName))
2026                    .andReturn(componentState);
2027            expect(repositorySrv.removeComponentPackage(componentName))
2028                    .andReturn(true);
2029            expect(componentState.getArchiveURL()).andReturn(archiveUrl);
2030            expect(installationService.createFileFromURI(archiveURI))
2031                    .andReturn(installedArchive);
2032            expect(installationService.getUninstalledArchive(installedArchive))
2033                    .andReturn(uninstalledArchive);
2034            expect(packageHandler.processAndGetPackageURI(archiveUrl, false))
2035                    .andReturn(archiveURI);
2036        } catch (Exception JavaDoc e) {
2037            e.printStackTrace();
2038            fail("Could not initialize Mocks");
2039        }
2040        replay(managerSrv);
2041        replay(beanServer);
2042        replay(sysState);
2043        replay(repositorySrv);
2044        replay(componentState);
2045        replay(installationService);
2046        replay(packageHandler);
2047        installationService.jmxAdmin = managerSrv;
2048        installationService.componentLoadedCache = new ArrayList JavaDoc<String JavaDoc>();
2049        installationService.recoverySrv = sysState;
2050        installationService.repositorySrv = repositorySrv;
2051        installationService.packageHandler = packageHandler;
2052        result = false;
2053        /*
2054         * Run Test Case 9
2055         */

2056        try {
2057            result = installationService.unloadInstaller(componentName, true);
2058        } catch (Exception JavaDoc e) {
2059            e.printStackTrace();
2060            fail("Error during invokation");
2061        }
2062        verify(managerSrv);
2063        verify(beanServer);
2064        verify(sysState);
2065        verify(componentState);
2066        verify(repositorySrv);
2067        verify(installationService);
2068        verify(packageHandler);
2069        assertTrue("Wrong invokation result", result);
2070
2071    }
2072
2073    @Override JavaDoc
2074    protected void setUp() {
2075        String JavaDoc baseDir = this.getClass().getResource(".").toString();
2076        baseDir = baseDir.substring(0, baseDir.indexOf("target"));
2077        baseDir = baseDir.substring(baseDir.indexOf(":") + 1);
2078
2079        testDataDir = new File JavaDoc(baseDir + "src" + File.separator + "test-data");
2080    }
2081}
2082
Popular Tags