KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > jbi > management > deployment > DeploymentServiceTest


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

22 package org.objectweb.petals.jbi.management.deployment;
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.verify;
29
30 import java.lang.reflect.Method JavaDoc;
31 import java.net.URI JavaDoc;
32 import java.util.ArrayList JavaDoc;
33 import java.util.HashMap JavaDoc;
34 import java.util.List JavaDoc;
35 import java.util.Map JavaDoc;
36
37 import javax.jbi.component.Component;
38 import javax.jbi.component.ServiceUnitManager;
39 import javax.jbi.management.DeploymentException;
40
41 import junit.framework.TestCase;
42
43 import org.objectweb.petals.jbi.component.lifecycle.ComponentLifeCycle;
44 import org.objectweb.petals.jbi.component.lifecycle.LifeCycleAbstract;
45 import org.objectweb.petals.jbi.component.lifecycle.ServiceAssemblyLifeCycle;
46 import org.objectweb.petals.jbi.management.service.LifeCycleManagerImpl;
47 import org.objectweb.petals.jbi.management.service.LifeCycleManagerService;
48 import org.objectweb.petals.jbi.routing.mock.ComponentMock;
49 import org.objectweb.petals.tools.jbicommon.descriptor.Identification;
50 import org.objectweb.petals.tools.jbicommon.descriptor.ServiceAssembly;
51 import org.objectweb.petals.tools.jbicommon.descriptor.ServiceUnit;
52 import org.objectweb.petals.util.LoggingUtil;
53 import org.objectweb.util.monolog.api.Logger;
54 import org.objectweb.util.monolog.wrapper.printwriter.LoggerImpl;
55
56 /**
57  * Test of the DeploymentServiceImpl
58  *
59  * @author wjoseph - eBMWebsourcing
60  */

61 public class DeploymentServiceTest extends TestCase {
62
63     public void testCanDeployToComponent() {
64         /*
65          * Test Case 1 The parameter componentName is null, an exception will be
66          * raised
67          */

68         DeploymentServiceImpl deploymentService = new DeploymentServiceImpl();
69         /*
70          * Create Test parameters
71          */

72         String JavaDoc componentName = null;
73         LoggingUtil log = createMock(LoggingUtil.class);
74         deploymentService.log = log;
75         /*
76          * Run Test Case 1
77          */

78         try {
79             deploymentService.canDeployToComponent(componentName);
80             fail("No exception was raised");
81         } catch (Exception JavaDoc e) {
82             assertTrue("Wrong exception thrown", e.getMessage().contains(
83                     "must not be null"));
84         }
85
86         /*
87          * Test Case 2 The parameter componentName is empty, an exception will
88          * be raised
89          */

90         /*
91          * Create Test parameters
92          */

93         componentName = "";
94         /*
95          * Run Test Case 2
96          */

97         try {
98             deploymentService.canDeployToComponent(componentName);
99             fail("No exception was raised");
100         } catch (Exception JavaDoc e) {
101             assertTrue("Wrong exception thrown", e.getMessage().contains(
102                     "must not be empty"));
103         }
104
105         /*
106          * Test Case 3 One component is found with this name and accept
107          * deployment
108          */

109         /*
110          * Create Test parameters
111          */

112         componentName = "fooCompo";
113         LifeCycleManagerService lifeCycleManager = createMock(LifeCycleManagerImpl.class);
114         ComponentLifeCycle componentLifeCycle = createMock(ComponentLifeCycle.class);
115         Component component = new ComponentMock() {
116             public javax.jbi.component.ServiceUnitManager getServiceUnitManager() {
117                 return new ServiceUnitManager() {
118
119                     public String JavaDoc deploy(String JavaDoc serviceUnitName,
120                             String JavaDoc serviceUnitRootPath)
121                         throws DeploymentException {
122                         return null;
123                     }
124
125                     public void init(String JavaDoc serviceUnitName,
126                             String JavaDoc serviceUnitRootPath)
127                         throws DeploymentException {
128
129                     }
130
131                     public void shutDown(String JavaDoc serviceUnitName)
132                         throws DeploymentException {
133
134                     }
135
136                     public void start(String JavaDoc serviceUnitName)
137                         throws DeploymentException {
138
139                     }
140
141                     public void stop(String JavaDoc serviceUnitName)
142                         throws DeploymentException {
143
144                     }
145
146                     public String JavaDoc undeploy(String JavaDoc serviceUnitName,
147                             String JavaDoc serviceUnitRootPath)
148                         throws DeploymentException {
149                         return null;
150                     }
151
152                 };
153             }
154         };
155
156         /*
157          * Initialize Mocks
158          */

159         expect(lifeCycleManager.getComponentByName(componentName)).andReturn(
160                 componentLifeCycle);
161         expect(componentLifeCycle.getCurrentState()).andReturn(
162                 LifeCycleAbstract.STARTED);
163         expect(componentLifeCycle.getComponent()).andReturn(component);
164         replay(lifeCycleManager);
165         replay(componentLifeCycle);
166         deploymentService.managerService = lifeCycleManager;
167         boolean result = false;
168         /*
169          * Run Test Case 3
170          */

171         try {
172             result = deploymentService.canDeployToComponent(componentName);
173         } catch (Exception JavaDoc e) {
174             fail("Error during invokation");
175         }
176         assertTrue("Wrong invokation result", result);
177     }
178
179     public void testGetComponentsForDeployedServiceAssembly() {
180         /*
181          * Test Case 1 The parameter serviceAssemblyName is null, an exception
182          * will be raised
183          */

184         DeploymentServiceImpl deploymentService = new DeploymentServiceImpl();
185         /*
186          * Create Test parameters
187          */

188         String JavaDoc serviceAssemblyName = null;
189         LoggingUtil log = createMock(LoggingUtil.class);
190         deploymentService.log = log;
191         /*
192          * Run Test Case 1
193          */

194         try {
195             deploymentService
196                     .getComponentsForDeployedServiceAssembly(serviceAssemblyName);
197             fail("No exception was raised");
198         } catch (Exception JavaDoc e) {
199             assertTrue("Wrong exception thrown", e.getMessage().contains(
200                     "must not be null"));
201         }
202
203         /*
204          * Test Case 2 The parameter serviceAssemblyName is empty, an exception
205          * will be raised
206          */

207         /*
208          * Create Test parameters
209          */

210         serviceAssemblyName = "";
211         /*
212          * Run Test Case 2
213          */

214         try {
215             deploymentService
216                     .getComponentsForDeployedServiceAssembly(serviceAssemblyName);
217             fail("No exception was raised");
218         } catch (Exception JavaDoc e) {
219             assertTrue("Wrong exception thrown", e.getMessage().contains(
220                     "must not be empty"));
221         }
222         /*
223          * Test Case 3 No service assembly for the given name is found, an
224          * exception is raised
225          */

226         /*
227          * Create Test parameters
228          */

229         LifeCycleManagerService lifeCycleManager = createMock(LifeCycleManagerImpl.class);
230         deploymentService.managerService = lifeCycleManager;
231         serviceAssemblyName = "fooSA";
232         /*
233          * Run Test Case 3
234          */

235         try {
236             deploymentService
237                     .getComponentsForDeployedServiceAssembly(serviceAssemblyName);
238             fail("No exception was raised");
239         } catch (Exception JavaDoc e) {
240             assertTrue(
241                     "Wrong exception thrown",
242                     e
243                             .getMessage()
244                             .contains(
245                                     "Cannot retrieve service assembly with the specified name : "));
246         }
247
248         /*
249          * Test Case 4 The service assembly has one service unit
250          */

251         /*
252          * Create Test parameters
253          */

254         lifeCycleManager = createMock(LifeCycleManagerImpl.class);
255         serviceAssemblyName = "fooSA";
256         ServiceAssemblyLifeCycle saLifeCycle = createMock(ServiceAssemblyLifeCycle.class);
257         ServiceAssembly sa = createMock(ServiceAssembly.class);
258         List JavaDoc<ServiceUnit> sus = new ArrayList JavaDoc<ServiceUnit>();
259         ServiceUnit su = createMock(ServiceUnit.class);
260         sus.add(su);
261         String JavaDoc componentName = "componentName";
262         /*
263          * Initialize Mocks
264          */

265         expect(lifeCycleManager.getServiceAssemblyByName(serviceAssemblyName))
266                 .andReturn(saLifeCycle);
267         expect(saLifeCycle.getServiceAssembly()).andReturn(sa);
268         expect(sa.getServiceUnits()).andReturn(sus);
269         expect(su.getTargetComponentName()).andReturn(componentName);
270         replay(lifeCycleManager);
271         replay(sa);
272         replay(saLifeCycle);
273         replay(su);
274         deploymentService.managerService = lifeCycleManager;
275         String JavaDoc[] result = null;
276         /*
277          * Run Test Case 4
278          */

279         try {
280             result = deploymentService
281                     .getComponentsForDeployedServiceAssembly(serviceAssemblyName);
282         } catch (Exception JavaDoc e) {
283             e.printStackTrace();
284             fail("Error during invokation");
285         }
286         assertNotNull(
287                 "The result of getComponentsForDeployedServiceAssembly must not be null",
288                 result);
289         assertEquals("Wrong invokation result", result[0], componentName);
290         assertEquals("Wrong invokation result", result.length, 1);
291         verify(lifeCycleManager);
292         verify(sa);
293         verify(saLifeCycle);
294         verify(su);
295     }
296
297     public void testGetDeployedServiceAssemblies() {
298         /*
299          * Test Case 1
300          *
301          */

302         DeploymentServiceImpl deploymentService = new DeploymentServiceImpl();
303         /*
304          * Create Test parameters
305          */

306         LifeCycleManagerImpl lifeCycleManager = createMock(LifeCycleManagerImpl.class);
307         Map JavaDoc<String JavaDoc, ServiceAssemblyLifeCycle> serviceAssemblies = new HashMap JavaDoc<String JavaDoc, ServiceAssemblyLifeCycle>();
308         String JavaDoc saName = "service assembly";
309         ServiceAssemblyLifeCycle saLifeCycle = createMock(ServiceAssemblyLifeCycle.class);
310         serviceAssemblies.put(saName, saLifeCycle);
311         /*
312          * Initialize Mocks
313          */

314         expect(lifeCycleManager.getServiceAssemblyLifeCycles()).andReturn(
315                 serviceAssemblies);
316         replay(lifeCycleManager);
317         deploymentService.managerService = lifeCycleManager;
318         String JavaDoc[] result = null;
319         /*
320          * Run Test Case 1
321          */

322         try {
323             result = deploymentService.getDeployedServiceAssemblies();
324         } catch (Exception JavaDoc e) {
325             e.printStackTrace();
326             fail("Error during invokation");
327         }
328         assertNotNull(
329                 "Result of getDeployedServiceAssemblies must not be null",
330                 result);
331         assertEquals("Wrong invokation result", result[0], saName);
332         assertEquals("Wrong invokation result", result.length, 1);
333         verify(lifeCycleManager);
334     }
335
336     public void testGetDeployedServiceAssembliesForComponent() {
337         /*
338          * Test Case 1 The parameter componentName is null, an exception is
339          * raised
340          */

341         DeploymentServiceImpl deploymentService = new DeploymentServiceImpl();
342         /*
343          * Create Test parameters
344          */

345         String JavaDoc componentName = null;
346         LoggingUtil log = createMock(LoggingUtil.class);
347         deploymentService.log = log;
348         /*
349          * Run Test Case 1
350          */

351         try {
352             deploymentService
353                     .getDeployedServiceAssembliesForComponent(componentName);
354             fail("No exception raised");
355         } catch (Exception JavaDoc e) {
356             assertTrue("Wrong exception thrown", e.getMessage().contains(
357                     "must not be null"));
358         }
359         /*
360          * Test Case 2 The parameter componentName is empty, an exception is
361          * raised
362          */

363         /*
364          * Create Test parameters
365          */

366         componentName = "";
367         /*
368          * Run Test Case 2
369          */

370         try {
371             deploymentService
372                     .getDeployedServiceAssembliesForComponent(componentName);
373             fail("No exception raised");
374         } catch (Exception JavaDoc e) {
375             assertTrue("Wrong exception thrown", e.getMessage().contains(
376                     "must not be empty"));
377         }
378
379         /*
380          * Test Case 3
381          */

382         /*
383          * Create Test parameters
384          */

385         componentName = "fooComponent";
386         LifeCycleManagerImpl lifeCycleManager = createMock(LifeCycleManagerImpl.class);
387         Map JavaDoc<String JavaDoc, ServiceAssemblyLifeCycle> serviceAssemblies = new HashMap JavaDoc<String JavaDoc, ServiceAssemblyLifeCycle>();
388         String JavaDoc saName = "service assembly";
389         ServiceAssemblyLifeCycle saLifeCycle = createMock(ServiceAssemblyLifeCycle.class);
390         serviceAssemblies.put(saName, saLifeCycle);
391         ServiceAssembly sa = createMock(ServiceAssembly.class);
392         List JavaDoc<ServiceUnit> sus = new ArrayList JavaDoc<ServiceUnit>();
393         ServiceUnit su = createMock(ServiceUnit.class);
394         sus.add(su);
395         Identification identification = createMock(Identification.class);
396         /*
397          * Initialize Mocks
398          */

399         expect(lifeCycleManager.getServiceAssemblyLifeCycles()).andReturn(
400                 serviceAssemblies);
401         expect(saLifeCycle.getServiceAssembly()).andReturn(sa).times(2);
402         expect(sa.getServiceUnits()).andReturn(sus);
403         expect(sa.getIdentification()).andReturn(identification);
404         expect(identification.getName()).andReturn(saName);
405         expect(su.getTargetComponentName()).andReturn(componentName);
406         replay(sa);
407         replay(su);
408         replay(lifeCycleManager);
409         replay(saLifeCycle);
410         replay(identification);
411         deploymentService.managerService = lifeCycleManager;
412         String JavaDoc[] result = null;
413         /*
414          * Run Test Case 3
415          */

416         try {
417             result = deploymentService
418                     .getDeployedServiceAssembliesForComponent(componentName);
419         } catch (Exception JavaDoc e) {
420             fail("Error during invokation");
421         }
422         assertNotNull(
423                 "Result of getDeployedServiceAssembliesForComponent must not be null",
424                 result);
425         assertEquals("Wrong invokation result", result[0], saName);
426         verify(saLifeCycle);
427         verify(lifeCycleManager);
428         verify(sa);
429         verify(su);
430         verify(identification);
431     }
432
433     public void testGetDeployedServiceUnitList() {
434         /*
435          * Test Case 1 The parameter componentName is null, an exception is
436          * raised
437          */

438         DeploymentServiceImpl deploymentService = new DeploymentServiceImpl();
439         /*
440          * Create Test parameters
441          */

442         String JavaDoc componentName = null;
443         LoggingUtil log = createMock(LoggingUtil.class);
444         deploymentService.log = log;
445         /*
446          * Run Test Case 1
447          */

448         try {
449             deploymentService.getDeployedServiceUnitList(componentName);
450             fail("No exception raised");
451         } catch (Exception JavaDoc e) {
452             assertTrue("Wrong exception thrown", e.getMessage().contains(
453                     "must not be null"));
454         }
455         /*
456          * Test Case 2 The parameter componentName is empty, an exception is
457          * raised
458          */

459         /*
460          * Create Test parameters
461          */

462         componentName = "";
463         /*
464          * Run Test Case 2
465          */

466         try {
467             deploymentService.getDeployedServiceUnitList(componentName);
468             fail("No exception raised");
469         } catch (Exception JavaDoc e) {
470             assertTrue("Wrong exception thrown", e.getMessage().contains(
471                     "must not be empty"));
472         }
473
474         /*
475          * Test Case 3
476          */

477         /*
478          * Create Test parameters
479          */

480         componentName = "fooComponent";
481         LifeCycleManagerImpl lifeCycleManager = createMock(LifeCycleManagerImpl.class);
482         Map JavaDoc<String JavaDoc, ServiceAssemblyLifeCycle> serviceAssemblies = new HashMap JavaDoc<String JavaDoc, ServiceAssemblyLifeCycle>();
483         String JavaDoc suName = "service unit";
484         ServiceAssemblyLifeCycle saLifeCycle = createMock(ServiceAssemblyLifeCycle.class);
485         serviceAssemblies.put(suName, saLifeCycle);
486         ServiceAssembly sa = createMock(ServiceAssembly.class);
487         List JavaDoc<ServiceUnit> sus = new ArrayList JavaDoc<ServiceUnit>();
488         ServiceUnit su = createMock(ServiceUnit.class);
489         sus.add(su);
490         Identification identification = createMock(Identification.class);
491         /*
492          * Initialize Mocks
493          */

494         expect(lifeCycleManager.getServiceAssemblyLifeCycles()).andReturn(
495                 serviceAssemblies);
496         expect(saLifeCycle.getServiceAssembly()).andReturn(sa);
497         expect(sa.getServiceUnits()).andReturn(sus);
498         expect(identification.getName()).andReturn(suName);
499         expect(su.getTargetComponentName()).andReturn(componentName);
500         expect(su.getIdentification()).andReturn(identification);
501         replay(sa);
502         replay(su);
503         replay(lifeCycleManager);
504         replay(saLifeCycle);
505         replay(identification);
506         deploymentService.managerService = lifeCycleManager;
507         String JavaDoc[] result = null;
508         /*
509          * Run Test Case 3
510          */

511         try {
512             result = deploymentService
513                     .getDeployedServiceUnitList(componentName);
514         } catch (Exception JavaDoc e) {
515             fail("Error during invokation");
516         }
517         assertNotNull(
518                 "Result of getDeployedServiceAssembliesForComponent must not be null",
519                 result);
520         assertEquals("Wrong invokation result", result[0], suName);
521         verify(saLifeCycle);
522         verify(lifeCycleManager);
523         verify(sa);
524         verify(su);
525         verify(identification);
526     }
527
528     public void testGetServiceAssemblyDescriptor() {
529         /*
530          * Test Case 1 The parameter ServiceAssemblyName is null, an exception
531          * is raised
532          */

533         /*
534          * Create Mocks
535          */

536         Method JavaDoc method1 = null;
537         try {
538             method1 = DeploymentServiceImpl.class.getDeclaredMethod(
539                     "getJbiDescriptorAsString", new Class JavaDoc[] {URI JavaDoc.class});
540         } catch (Exception JavaDoc e) {
541             e.printStackTrace();
542             fail("Could not retrieve mocked methods");
543         }
544         Method JavaDoc[] mockedMethods = new Method JavaDoc[] {method1};
545         DeploymentServiceImpl deploymentService = createMock(
546                 DeploymentServiceImpl.class, mockedMethods);
547         /*
548          * Create Test parameters
549          */

550         String JavaDoc serviceAssemblyName = null;
551         LoggingUtil log = createMock(LoggingUtil.class);
552         deploymentService.log = log;
553         /*
554          * Run Test Case 1
555          */

556         try {
557             deploymentService.getServiceAssemblyDescriptor(serviceAssemblyName);
558             fail("No exception raised");
559         } catch (Exception JavaDoc e) {
560             assertTrue("Wrong exception thrown", e.getMessage().contains(
561                     " must not be null"));
562         }
563         /*
564          * Test Case 2 The parameter ServiceAssemblyName is empty, an exception
565          * is raised
566          */

567         /*
568          * Create Test parameters
569          */

570         serviceAssemblyName = "";
571         /*
572          * Run Test Case 2
573          */

574         try {
575             deploymentService.getServiceAssemblyDescriptor(serviceAssemblyName);
576             fail("No exception raised");
577         } catch (Exception JavaDoc e) {
578             assertTrue("Wrong exception thrown", e.getMessage().contains(
579                     "must not be empty"));
580         }
581
582         /*
583          * Test Case 3
584          */

585         /*
586          * Create Test parameters
587          */

588         LifeCycleManagerImpl lifeCycleManager = createMock(LifeCycleManagerImpl.class);
589         serviceAssemblyName = "service assembly";
590         ServiceAssemblyLifeCycle saLifeCycle = createMock(ServiceAssemblyLifeCycle.class);
591         URI JavaDoc installationURI = null;
592         try {
593             installationURI = new URI JavaDoc("file://installation");
594         } catch (Exception JavaDoc e) {
595             e.printStackTrace();
596             fail("Could not create test parameters");
597         }
598         org.objectweb.petals.util.monolog.wrapper.javalog.Logger logger = createMock(org.objectweb.petals.util.monolog.wrapper.javalog.Logger.class);
599         deploymentService.logger = logger;
600         String JavaDoc resultDescriptor = "result";
601         String JavaDoc result = null;
602         /*
603          * Initialize Mocks
604          */

605         expect(lifeCycleManager.getServiceAssemblyByName(serviceAssemblyName))
606                 .andReturn(saLifeCycle);
607         expect(saLifeCycle.getInstallationRoot()).andReturn(installationURI);
608         expect(deploymentService.getJbiDescriptorAsString(isA(URI JavaDoc.class)))
609                 .andReturn(resultDescriptor);
610         replay(lifeCycleManager);
611         replay(saLifeCycle);
612         replay(deploymentService);
613         deploymentService.managerService = lifeCycleManager;
614         /*
615          * Run Test Case 3
616          */

617         try {
618             result = deploymentService
619                     .getServiceAssemblyDescriptor(serviceAssemblyName);
620         } catch (Exception JavaDoc e) {
621             fail("Error during invokation");
622         }
623         verify(saLifeCycle);
624         verify(lifeCycleManager);
625         verify(deploymentService);
626         assertNotNull(
627                 "Result of getServiceAssemblyDescriptor must be non null",
628                 result);
629         assertEquals("Wrong invokation result", result, resultDescriptor);
630     }
631     
632     public void testIsDeployedServiceUnit() {
633         /*
634          * Test Case 1 The parameter serviceUnitName is null, an exception is
635          * raised
636          */

637         DeploymentServiceImpl deploymentService = new DeploymentServiceImpl();
638         /*
639          * Create Test parameters
640          *
641          */

642         LoggingUtil log = createMock(LoggingUtil.class);
643         deploymentService.log = log;
644         String JavaDoc serviceUnitName = null;
645         String JavaDoc componentName = null;
646         /*
647          * Run Test Case 1
648          */

649         try {
650             deploymentService.isDeployedServiceUnit(componentName,
651                     serviceUnitName);
652             fail("No exception raised");
653         } catch (Exception JavaDoc e) {
654             assertTrue("Wrong exception thrown", e.getMessage().contains(
655                     "must not be null"));
656         }
657
658         /*
659          * Test Case 2 The parameter serviceUnitName is empty, an exception is
660          * raised
661          */

662         /*
663          * Create Test parameters
664          */

665         serviceUnitName = "";
666         /*
667          * Run Test Case 2
668          */

669         try {
670             deploymentService.isDeployedServiceUnit(componentName,
671                     serviceUnitName);
672             fail("No exception raised");
673         } catch (Exception JavaDoc e) {
674             assertTrue("Wrong exception thrown", e.getMessage().contains(
675                     "must not be empty"));
676         }
677
678         /*
679          * Test Case 3 The parameter componentName is null, an exception is
680          * raised
681          */

682         /*
683          * Create Test parameters
684          */

685         serviceUnitName = "service unit name";
686         /*
687          * Run Test Case 3
688          */

689         try {
690             deploymentService.isDeployedServiceUnit(componentName,
691                     serviceUnitName);
692             fail("No exception raised");
693         } catch (Exception JavaDoc e) {
694             assertTrue("Wrong exception thrown", e.getMessage().contains(
695                     "must not be null"));
696         }
697
698         /*
699          * Test Case 4 The parameter componentName is empty, an exception is
700          * raised
701          */

702         /*
703          * Create Test parameters
704          */

705         componentName = "";
706         /*
707          * Run Test Case 4
708          */

709         try {
710             deploymentService.isDeployedServiceUnit(componentName,
711                     serviceUnitName);
712             fail("No exception raised");
713         } catch (Exception JavaDoc e) {
714             assertTrue("Wrong exception thrown", e.getMessage().contains(
715                     "must not be empty"));
716         }
717
718         /*
719          * Test Case 5 There is a service unit with the given name deployed for
720          * this component
721          */

722         /*
723          * Create Test parameters
724          */

725         componentName = "fooComponent";
726         String JavaDoc saName = "service assembly name";
727         LifeCycleManagerImpl lifeCycleManager = createMock(LifeCycleManagerImpl.class);
728         Map JavaDoc<String JavaDoc, ServiceAssemblyLifeCycle> serviceAssemblies = new HashMap JavaDoc<String JavaDoc, ServiceAssemblyLifeCycle>();
729         ServiceAssemblyLifeCycle saLifeCycle = createMock(ServiceAssemblyLifeCycle.class);
730         serviceAssemblies.put(saName, saLifeCycle);
731         ServiceAssembly sa = createMock(ServiceAssembly.class);
732         List JavaDoc<ServiceUnit> sus = new ArrayList JavaDoc<ServiceUnit>();
733         ServiceUnit su = createMock(ServiceUnit.class);
734         sus.add(su);
735         Identification identification = createMock(Identification.class);
736         /*
737          * Initialize Mocks
738          */

739         expect(lifeCycleManager.getServiceAssemblyLifeCycles()).andReturn(
740                 serviceAssemblies);
741         expect(saLifeCycle.getServiceAssembly()).andReturn(sa);
742         expect(sa.getServiceUnits()).andReturn(sus);
743         expect(identification.getName()).andReturn(serviceUnitName);
744         expect(su.getTargetComponentName()).andReturn(componentName);
745         expect(su.getIdentification()).andReturn(identification);
746         replay(sa);
747         replay(su);
748         replay(lifeCycleManager);
749         replay(saLifeCycle);
750         replay(identification);
751         deploymentService.managerService = lifeCycleManager;
752         boolean result = false;
753         /*
754          * Run Test Case 5
755          */

756         try {
757             result = deploymentService.isDeployedServiceUnit(componentName,
758                     serviceUnitName);
759         } catch (Exception JavaDoc e) {
760             e.printStackTrace();
761             fail("Error during invokation");
762         }
763         assertTrue("Wrong invokation result", result);
764         verify(sa);
765         verify(su);
766         verify(lifeCycleManager);
767         verify(saLifeCycle);
768         verify(identification);
769     }
770     
771     public void testShutdown() {
772         /*
773          * Test Case 1 serviceAssemblyName parameter is null, an exception is
774          * raised
775          */

776         DeploymentServiceImpl deploymentService = new DeploymentServiceImpl();
777         /*
778          * Create Test parameters
779          */

780         LoggingUtil log = createMock(LoggingUtil.class);
781         deploymentService.log = log;
782         String JavaDoc serviceAssemblyName = null;
783         /*
784          * Run Test Case 1
785          */

786         try {
787             deploymentService.shutDown(serviceAssemblyName);
788             fail("No exception was raised");
789         } catch (Exception JavaDoc e) {
790             assertTrue("Wrong exception thrown", e.getMessage().contains(
791                     "must not be null"));
792         }
793         /*
794          * Test Case 2 serviceAssemblyName parameter is empty, an exception is
795          * raised
796          */

797         /*
798          * Create Test parameters
799          */

800         serviceAssemblyName = "";
801         /*
802          * Run Test Case 2
803          */

804         try {
805             deploymentService.shutDown(serviceAssemblyName);
806             fail("No exception was raised");
807         } catch (Exception JavaDoc e) {
808             assertTrue("Wrong exception thrown", e.getMessage().contains(
809                     "must not be empty"));
810         }
811     }
812     
813     public void testStop() {
814         /*
815          * Test Case 1
816          */

817         DeploymentServiceImpl deploymentService = new DeploymentServiceImpl();
818         /*
819          * Create Test parameters
820          */

821         LoggingUtil log = createMock(LoggingUtil.class);
822         deploymentService.log = log;
823
824         Logger logger = createMock(LoggerImpl.class);
825         deploymentService.logger = logger;
826         /*
827          * Run Test Case 1
828          */

829         deploymentService.stop();
830         assertNull("ShutDown action was not properly realized",deploymentService.logger);
831     }
832
833     public void testStart() {
834         /*
835          * Test Case 1 serviceAssemblyName parameter is null, an exception is
836          * raised
837          */

838         DeploymentServiceImpl deploymentService = new DeploymentServiceImpl();
839         /*
840          * Create Test parameters
841          */

842         LoggingUtil log = createMock(LoggingUtil.class);
843         deploymentService.log = log;
844         String JavaDoc serviceAssemblyName = null;
845         /*
846          * Run Test Case 1
847          */

848         try {
849             deploymentService.start(serviceAssemblyName);
850             fail("No exception was raised");
851         } catch (Exception JavaDoc e) {
852             assertTrue("Wrong exception thrown", e.getMessage().contains(
853                     "must not be null"));
854         }
855         /*
856          * Test Case 2 serviceAssemblyName parameter is empty, an exception is
857          * raised
858          */

859         /*
860          * Create Test parameters
861          */

862         serviceAssemblyName = "";
863         /*
864          * Run Test Case 2
865          */

866         try {
867             deploymentService.start(serviceAssemblyName);
868             fail("No exception was raised");
869         } catch (Exception JavaDoc e) {
870             assertTrue("Wrong exception thrown", e.getMessage().contains(
871                     "must not be empty"));
872         }
873     }
874
875     public void testStopSA() {
876         /*
877          * Test Case 1 serviceAssemblyName parameter is null, an exception is
878          * raised
879          */

880         DeploymentServiceImpl deploymentService = new DeploymentServiceImpl();
881         /*
882          * Create Test parameters
883          */

884         LoggingUtil log = createMock(LoggingUtil.class);
885         deploymentService.log = log;
886         String JavaDoc serviceAssemblyName = null;
887         /*
888          * Run Test Case 1
889          */

890         try {
891             deploymentService.stop(serviceAssemblyName);
892             fail("No exception was raised");
893         } catch (Exception JavaDoc e) {
894             assertTrue("Wrong exception thrown", e.getMessage().contains(
895                     "must not be null"));
896         }
897         /*
898          * Test Case 2 serviceAssemblyName parameter is empty, an exception is
899          * raised
900          */

901         /*
902          * Create Test parameters
903          */

904         serviceAssemblyName = "";
905         /*
906          * Run Test Case 2
907          */

908         try {
909             deploymentService.stop(serviceAssemblyName);
910             fail("No exception was raised");
911         } catch (Exception JavaDoc e) {
912             assertTrue("Wrong exception thrown", e.getMessage().contains(
913                     "must not be empty"));
914         }
915     }
916
917     public void testUndeploy() {
918
919     }
920
921     @Override JavaDoc
922     protected void setUp() {
923
924     }
925 }
926
Popular Tags