KickJava   Java API By Example, From Geeks To Geeks.

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


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

22 package org.objectweb.petals.jbi.management.service;
23
24 import static org.easymock.EasyMock.expect;
25 import static org.easymock.classextension.EasyMock.createMock;
26 import static org.easymock.classextension.EasyMock.replay;
27 import static org.easymock.classextension.EasyMock.reset;
28 import static org.easymock.classextension.EasyMock.verify;
29
30 import java.lang.reflect.Method JavaDoc;
31 import java.util.HashMap JavaDoc;
32 import java.util.Map JavaDoc;
33
34 import javax.jbi.component.Component;
35 import javax.jbi.messaging.MessageExchange;
36 import javax.jbi.servicedesc.ServiceEndpoint;
37 import javax.management.ObjectName JavaDoc;
38
39 import junit.framework.TestCase;
40
41 import org.objectweb.petals.jbi.component.lifecycle.ComponentLifeCycle;
42 import org.objectweb.petals.jbi.component.lifecycle.LifeCycleAbstract;
43 import org.objectweb.petals.jbi.messaging.MessageExchangeImpl;
44 import org.objectweb.petals.jbi.registry.InternalEndpoint;
45 import org.objectweb.petals.jbi.routing.mock.ComponentMock;
46 import org.objectweb.petals.util.LoggingUtil;
47 import org.w3c.dom.Document JavaDoc;
48
49 /**
50  * Test of the EndpointServiceImpl
51  *
52  * @author ddesjardins - eBMWebsourcing
53  */

54 public class AdminServiceTest extends TestCase {
55
56     
57     public void testGetBindingComponentByName() {
58         /*
59          * Test Case 1 There is no binding component matching this name
60          */

61         AdminService adminService = new AdminService();
62         LifeCycleManagerService lifeCycleManager = createMock(LifeCycleManagerImpl.class);
63         LoggingUtil log = createMock(LoggingUtil.class);
64         adminService.log = log;
65         ComponentLifeCycle lifecycle = createMock(ComponentLifeCycle.class);
66         ObjectName JavaDoc objectName = createMock(ObjectName JavaDoc.class);
67         /*
68          * Create Test parameters
69          */

70         Map JavaDoc<ObjectName JavaDoc, ComponentLifeCycle> bindings = new HashMap JavaDoc<ObjectName JavaDoc, ComponentLifeCycle>();
71         bindings.put(objectName, lifecycle);
72         /*
73          * Initialize Mocks
74          */

75         expect(lifeCycleManager.getBindingCompoLifeCycles())
76                 .andReturn(bindings);
77         expect(lifecycle.getName()).andReturn("bar");
78         replay(lifecycle);
79         replay(lifeCycleManager);
80         adminService.manager = lifeCycleManager;
81         ObjectName JavaDoc result = null;
82         String JavaDoc name = "foo";
83         /*
84          * Run Test Case 1
85          */

86         result = adminService.getBindingComponentByName(name);
87         assertNull("The result of invokation should be null", result);
88         verify(lifeCycleManager);
89         verify(lifecycle);
90         /*
91          * Test Case 2 There is one binding component matching this name
92          */

93         reset(lifeCycleManager);
94         reset(lifecycle);
95         /*
96          * Initialize Mocks
97          */

98         expect(lifeCycleManager.getBindingCompoLifeCycles())
99                 .andReturn(bindings);
100         expect(lifecycle.getName()).andReturn(name);
101         expect(lifecycle.getMBeanName()).andReturn(objectName);
102         replay(lifecycle);
103         replay(lifeCycleManager);
104         adminService.manager = lifeCycleManager;
105         /*
106          * Run Test Case 2
107          */

108         result = adminService.getBindingComponentByName(name);
109         assertEquals("Wrong invokation response", result, objectName);
110         verify(lifecycle);
111         verify(lifeCycleManager);
112     }
113
114     public void testGetBindingComponents() {
115         /*
116          * Test Case 1 Check if the result respect JBI specifications
117          */

118         AdminService adminService = new AdminService();
119         LifeCycleManagerService lifeCycleManager = createMock(LifeCycleManagerImpl.class);
120         ComponentLifeCycle lifecycle = createMock(ComponentLifeCycle.class);
121         ObjectName JavaDoc objectName = createMock(ObjectName JavaDoc.class);
122         Map JavaDoc<ObjectName JavaDoc, ComponentLifeCycle> bindings = new HashMap JavaDoc<ObjectName JavaDoc, ComponentLifeCycle>();
123         bindings.put(objectName, lifecycle);
124         /*
125          * Initialize Mocks
126          */

127         expect(lifeCycleManager.getBindingCompoLifeCycles())
128                 .andReturn(bindings);
129         replay(lifeCycleManager);
130         adminService.manager = lifeCycleManager;
131         LoggingUtil log = createMock(LoggingUtil.class);
132         adminService.log = log;
133         /*
134          * Run Test Case 1
135          */

136         ObjectName JavaDoc[] result = adminService.getBindingComponents();
137         assertNotNull("The result of GetBindingComponents Must be non null",
138                 result);
139         verify(lifeCycleManager);
140         assertTrue("Result does not have the right content", result[0]
141                 .equals(objectName));
142     }
143
144     public void testGetComponentByName() {
145         /*
146          * Create Mocks
147          */

148         Method JavaDoc method1 = null;
149         Method JavaDoc method2 = null;
150         try {
151             method1 = AdminService.class.getDeclaredMethod(
152                     "getBindingComponentByName", new Class JavaDoc[] {String JavaDoc.class});
153             method2 = AdminService.class.getDeclaredMethod(
154                     "getEngineComponentByName", new Class JavaDoc[] {String JavaDoc.class});
155
156         } catch (Exception JavaDoc e) {
157             e.printStackTrace();
158             fail("Could not retrieve mocked methods");
159         }
160         /*
161          * Test Case 1 the name parameter is null
162          */

163         Method JavaDoc[] mockedMethods = new Method JavaDoc[] {method1, method2};
164         AdminService adminService = createMock(AdminService.class,
165                 mockedMethods);
166         LifeCycleManagerService lifeCycleManager = new LifeCycleManagerImpl();
167         adminService.manager = lifeCycleManager;
168         LoggingUtil log = createMock(LoggingUtil.class);
169         adminService.log = log;
170         String JavaDoc name = null;
171         /*
172          * Run Test Case 1
173          */

174         try {
175             adminService.getComponentByName(name);
176             fail("No exception was raised");
177         } catch (Exception JavaDoc e) {
178             // Do nothing
179
}
180
181         /*
182          * Test Case 2 the name parameter is empty
183          */

184         name = "";
185         /*
186          * Run Test Case 2
187          */

188         try {
189             adminService.getComponentByName(name);
190             fail("No exception was raised");
191         } catch (Exception JavaDoc e) {
192             // Do nothing
193
}
194         /*
195          * Test Case 3 No component with this name exists
196          */

197         name = "foo";
198         expect(adminService.getBindingComponentByName(name)).andReturn(null);
199         expect(adminService.getEngineComponentByName(name)).andReturn(null);
200         replay(adminService);
201         /*
202          * Run Test Case 3
203          */

204         ObjectName JavaDoc result = adminService.getComponentByName(name);
205         assertNull("The result is incorrect", result);
206     }
207
208     public void testGetEngineComponentByName() {
209         /*
210          * Test Case 1 There is no binding component matching this name
211          */

212         AdminService adminService = new AdminService();
213         LifeCycleManagerService lifeCycleManager = createMock(LifeCycleManagerImpl.class);
214         LoggingUtil log = createMock(LoggingUtil.class);
215         adminService.log = log;
216         ComponentLifeCycle lifecycle = createMock(ComponentLifeCycle.class);
217         ObjectName JavaDoc objectName = createMock(ObjectName JavaDoc.class);
218         /*
219          * Create Test parameters
220          */

221         Map JavaDoc<ObjectName JavaDoc, ComponentLifeCycle> engines = new HashMap JavaDoc<ObjectName JavaDoc, ComponentLifeCycle>();
222         engines.put(objectName, lifecycle);
223         /*
224          * Initialize Mocks
225          */

226         expect(lifeCycleManager.getEngineCompoLifeCycles()).andReturn(engines);
227         expect(lifecycle.getName()).andReturn("bar");
228         replay(lifecycle);
229         replay(lifeCycleManager);
230         adminService.manager = lifeCycleManager;
231         ObjectName JavaDoc result = null;
232         String JavaDoc name = "foo";
233         /*
234          * Run Test Case 1
235          */

236         result = adminService.getEngineComponentByName(name);
237         assertNull("The result of invokation should be null", result);
238         verify(lifeCycleManager);
239         verify(lifecycle);
240         /*
241          * Test Case 2 There is one binding component matching this name
242          */

243         reset(lifeCycleManager);
244         reset(lifecycle);
245         /*
246          * Initialize Mocks
247          */

248         expect(lifeCycleManager.getEngineCompoLifeCycles()).andReturn(engines);
249         expect(lifecycle.getName()).andReturn(name);
250         expect(lifecycle.getMBeanName()).andReturn(objectName);
251         replay(lifecycle);
252         replay(lifeCycleManager);
253         adminService.manager = lifeCycleManager;
254         /*
255          * Run Test Case 2
256          */

257         result = adminService.getEngineComponentByName(name);
258         assertEquals("Wrong invokation response", result, objectName);
259         verify(lifecycle);
260         verify(lifeCycleManager);
261     }
262
263     public void testGetEngineComponents() {
264         /*
265          * Test Case 1 Check if the result respect JBI specifications
266          */

267         AdminService adminService = new AdminService();
268         LifeCycleManagerService lifeCycleManager = createMock(LifeCycleManagerImpl.class);
269         ComponentLifeCycle lifecycle = createMock(ComponentLifeCycle.class);
270         ObjectName JavaDoc objectName = createMock(ObjectName JavaDoc.class);
271         Map JavaDoc<ObjectName JavaDoc, ComponentLifeCycle> engines = new HashMap JavaDoc<ObjectName JavaDoc, ComponentLifeCycle>();
272         engines.put(objectName, lifecycle);
273         /*
274          * Initialize Mocks
275          */

276         expect(lifeCycleManager.getEngineCompoLifeCycles()).andReturn(engines);
277         replay(lifeCycleManager);
278         adminService.manager = lifeCycleManager;
279         LoggingUtil log = createMock(LoggingUtil.class);
280         adminService.log = log;
281         /*
282          * Run Test Case 1
283          */

284         ObjectName JavaDoc[] result = adminService.getEngineComponents();
285         assertNotNull("The result of GetEngineComponents Must be non null",
286                 result);
287         verify(lifeCycleManager);
288         assertTrue("Result does not have the right content", result[0]
289                 .equals(objectName));
290     }
291
292     public void testGetServiceDescription() {
293         /*
294          * Test Case 1 No component with this name is registered, an exception
295          * is raised
296          */

297         AdminService adminService = new AdminService();
298         LoggingUtil log = createMock(LoggingUtil.class);
299         adminService.log = log;
300         Document JavaDoc result = null;
301         String JavaDoc componentName = "fooComponent";
302         ServiceEndpoint endpoint = createMock(InternalEndpoint.class);
303         ComponentLifeCycle lifeCycle = createMock(ComponentLifeCycle.class);
304         Component component = new ComponentMock();
305         /*
306          * Run Test Case 1
307          */

308         try {
309             result = adminService
310                     .getServiceDescription(componentName, endpoint);
311             fail("No exception was raised");
312         } catch (Exception JavaDoc e) {
313             // Do nothing
314
}
315         /*
316          * Test Case 2 The requested component name exist but does not provide a
317          * service description
318          */

319         LifeCycleManagerService lifeCycleManager = createMock(LifeCycleManagerImpl.class);
320         expect(lifeCycle.getComponent()).andReturn(component);
321         expect(lifeCycleManager.getComponentByName(componentName)).andReturn(
322                 lifeCycle);
323         replay(lifeCycleManager);
324         replay(lifeCycle);
325         adminService.manager = lifeCycleManager;
326         /*
327          * Run Test Case 2
328          */

329         try {
330             result = adminService
331                     .getServiceDescription(componentName, endpoint);
332         } catch (Exception JavaDoc e) {
333             e.printStackTrace();
334             fail("Error during method invokation");
335         }
336         assertNull("The result should be null", result);
337         verify(lifeCycleManager);
338         verify(lifeCycle);
339
340         /*
341          * Test Case 3 The requested component name exist and its service
342          * description is returned
343          */

344         reset(lifeCycle);
345         reset(lifeCycleManager);
346         component = createMock(ComponentMock.class);
347         Document JavaDoc serviceDesc = createMock(Document JavaDoc.class);
348         expect(lifeCycleManager.getComponentByName(componentName)).andReturn(
349                 lifeCycle);
350         expect(lifeCycle.getComponent()).andReturn(component);
351         expect(component.getServiceDescription(endpoint))
352                 .andReturn(serviceDesc);
353         replay(lifeCycleManager);
354         replay(lifeCycle);
355         replay(component);
356         /*
357          * Run Test Case 3
358          */

359         try {
360             result = adminService
361                     .getServiceDescription(componentName, endpoint);
362         } catch (Exception JavaDoc e) {
363             e.printStackTrace();
364             fail("Error during method invokation");
365         }
366         assertEquals("Wrong result for invokation", result, serviceDesc);
367         verify(lifeCycleManager);
368         verify(lifeCycle);
369         verify(component);
370     }
371
372     public void testGetSystemInfo() {
373         /*
374          * Test Case 1 Checks the result of getSystemInfo respect JBI
375          * specifications
376          */

377         AdminService adminService = new AdminService();
378         /*
379          * Run Test Case 1
380          */

381         String JavaDoc result = adminService.getSystemInfo();
382         assertNotNull("Result of getSystemInfo must not be null", result);
383         assertFalse("Result of getSystemInfo must not be empty", result
384                 .length() == 0);
385     }
386
387     public void testGetSystemService() {
388         /*
389          * Test Case 1 The serviceName parameter is null, an exception is raised
390          */

391         AdminService adminService = new AdminService();
392         LoggingUtil log = createMock(LoggingUtil.class);
393         adminService.log = log;
394         /*
395          * Run Test Case 1
396          */

397         /*
398          * Create Test parameters
399          */

400         String JavaDoc serviceName = null;
401         try {
402             adminService.getSystemService(serviceName);
403             fail("No exception was raised");
404         } catch (Exception JavaDoc e) {
405             // Do nothing
406
}
407
408         /*
409          * Test Case 2 The serviceName parameter is empty, an exception is
410          * raised
411          */

412         /*
413          * Create Test parameters
414          */

415         serviceName = "";
416         /*
417          * Run Test Case 2
418          */

419         try {
420             adminService.getSystemService(serviceName);
421             fail("No exception was raised");
422         } catch (Exception JavaDoc e) {
423             // Do nothing
424
}
425
426         /*
427          * Test Case 3 The serviceName parameter is empty, an exception is
428          * raised
429          */

430         /*
431          * Create Test parameters
432          */

433         serviceName = "fooService";
434         LifeCycleManagerService lifeCycleManager = createMock(LifeCycleManagerImpl.class);
435         Map JavaDoc<ObjectName JavaDoc, LifeCycleAbstract> services = new HashMap JavaDoc<ObjectName JavaDoc, LifeCycleAbstract>();
436         ObjectName JavaDoc objectName = createMock(ObjectName JavaDoc.class);
437         ComponentLifeCycle lifeCycle = createMock(ComponentLifeCycle.class);
438         services.put(objectName, lifeCycle);
439         expect(lifeCycleManager.getSystemServices()).andReturn(services);
440         expect(lifeCycle.getName()).andReturn(serviceName);
441         expect(lifeCycle.getMBeanName()).andReturn(objectName);
442         replay(lifeCycleManager);
443         replay(lifeCycle);
444         adminService.manager = lifeCycleManager;
445         ObjectName JavaDoc result = null;
446         /*
447          * Run Test Case 3
448          */

449         try {
450             result = adminService.getSystemService(serviceName);
451         } catch (Exception JavaDoc e) {
452             fail("Error during invokation");
453         }
454         assertEquals("Wrong result for invokation", result, objectName);
455         verify(lifeCycle);
456         verify(lifeCycleManager);
457     }
458
459     public void testGetSystemServices() {
460         /*
461          * Test Case 1 Checks the result of getSystemServices respect JBI
462          * specifications
463          */

464         AdminService adminService = new AdminService();
465         LoggingUtil log = createMock(LoggingUtil.class);
466         adminService.log = log;
467         LifeCycleManagerService lifeCycleManager = createMock(LifeCycleManagerImpl.class);
468         Map JavaDoc<ObjectName JavaDoc, LifeCycleAbstract> services = new HashMap JavaDoc<ObjectName JavaDoc, LifeCycleAbstract>();
469         ObjectName JavaDoc objectName = createMock(ObjectName JavaDoc.class);
470         ComponentLifeCycle lifeCycle = createMock(ComponentLifeCycle.class);
471         services.put(objectName, lifeCycle);
472         expect(lifeCycleManager.getSystemServices()).andReturn(services);
473         replay(lifeCycleManager);
474         adminService.manager = lifeCycleManager;
475         /*
476          * Run Test Case 1
477          */

478         ObjectName JavaDoc[] result = adminService.getSystemServices();
479         assertNotNull("The result of getSystemServices must not be null",
480                 result);
481         assertTrue("The result is incorrect", result.length == 1);
482         verify(lifeCycleManager);
483     }
484
485     public void testIsBinding() {
486         /*
487          * Test Case 1 The componentName parameter is null, an exception is
488          * raised
489          */

490         AdminService adminService = new AdminService();
491         LoggingUtil log = createMock(LoggingUtil.class);
492         adminService.log = log;
493         /*
494          * Run Test Case 1
495          */

496         /*
497          * Create Test parameters
498          */

499         String JavaDoc componentName = null;
500         try {
501             adminService.isBinding(componentName);
502             fail("No exception was raised");
503         } catch (Exception JavaDoc e) {
504             // Do nothing
505
}
506
507         /*
508          * Test Case 2 The componentName parameter is empty, an exception is
509          * raised
510          */

511         /*
512          * Create Test parameters
513          */

514         componentName = "";
515         /*
516          * Run Test Case 2
517          */

518         try {
519             adminService.isBinding(componentName);
520             fail("No exception was raised");
521         } catch (Exception JavaDoc e) {
522             // Do nothing
523
}
524         /*
525          * Test Case 3 The requested compenent is not registered, false is
526          * returned
527          */

528         /*
529          * Create Mocks
530          */

531         LifeCycleManagerService lifeCycleManager = createMock(LifeCycleManagerImpl.class);
532         ComponentLifeCycle lifecycle = createMock(ComponentLifeCycle.class);
533         ObjectName JavaDoc objectName = createMock(ObjectName JavaDoc.class);
534         /*
535          * Create Test parameters
536          */

537         Map JavaDoc<ObjectName JavaDoc, ComponentLifeCycle> bindings = new HashMap JavaDoc<ObjectName JavaDoc, ComponentLifeCycle>();
538         bindings.put(objectName, lifecycle);
539         componentName = "fooCompo";
540         /*
541          * Initialize Mocks
542          */

543         expect(lifeCycleManager.getBindingCompoLifeCycles())
544                 .andReturn(bindings);
545         replay(lifeCycleManager);
546         adminService.manager = lifeCycleManager;
547         /*
548          * Run Test Case 3
549          */

550         boolean result = adminService.isBinding(componentName);
551         assertFalse("Result of invokation should be false", result);
552         verify(lifeCycleManager);
553     }
554
555     public void testIsEngine() {
556         /*
557          * Test Case 1 The componentName parameter is null, an exception is
558          * raised
559          */

560         AdminService adminService = new AdminService();
561         LoggingUtil log = createMock(LoggingUtil.class);
562         adminService.log = log;
563         /*
564          * Run Test Case 1
565          */

566         /*
567          * Create Test parameters
568          */

569         String JavaDoc componentName = null;
570         try {
571             adminService.isEngine(componentName);
572             fail("No exception was raised");
573         } catch (Exception JavaDoc e) {
574             // Do nothing
575
}
576
577         /*
578          * Test Case 2 The componentName parameter is empty, an exception is
579          * raised
580          */

581         /*
582          * Create Test parameters
583          */

584         componentName = "";
585         /*
586          * Run Test Case 2
587          */

588         try {
589             adminService.isEngine(componentName);
590             fail("No exception was raised");
591         } catch (Exception JavaDoc e) {
592             // Do nothing
593
}
594         /*
595          * Test Case 3 The requested compenent is not registered, false is
596          * returned
597          */

598         /*
599          * Create Mocks
600          */

601         LifeCycleManagerService lifeCycleManager = createMock(LifeCycleManagerImpl.class);
602         ComponentLifeCycle lifecycle = createMock(ComponentLifeCycle.class);
603         ObjectName JavaDoc objectName = createMock(ObjectName JavaDoc.class);
604         /*
605          * Create Test parameters
606          */

607         Map JavaDoc<ObjectName JavaDoc, ComponentLifeCycle> engines = new HashMap JavaDoc<ObjectName JavaDoc, ComponentLifeCycle>();
608         engines.put(objectName, lifecycle);
609         componentName = "fooCompo";
610         /*
611          * Initialize Mocks
612          */

613         expect(lifeCycleManager.getEngineCompoLifeCycles()).andReturn(engines);
614         replay(lifeCycleManager);
615         adminService.manager = lifeCycleManager;
616         /*
617          * Run Test Case 3
618          */

619         boolean result = adminService.isEngine(componentName);
620         assertFalse("Result of invokation should be false", result);
621         verify(lifeCycleManager);
622     }
623
624     public void testIsExchangeWithConsumerOkayForComponent() {
625         /*
626          * Test Case 1 There is no binding component matching this name
627          */

628         AdminService adminService = new AdminService();
629         LifeCycleManagerService lifeCycleManager = createMock(LifeCycleManagerImpl.class);
630         adminService.manager = lifeCycleManager;
631         LoggingUtil log = createMock(LoggingUtil.class);
632         adminService.log = log;
633         /*
634          * Create Test parameters
635          */

636         String JavaDoc componentName = "foo";
637         ServiceEndpoint internalEndpoint = createMock(InternalEndpoint.class);
638         MessageExchange exchange = createMock(MessageExchangeImpl.class);
639         /*
640          * Run Test Case 1
641          */

642         try {
643             adminService.isExchangeWithConsumerOkayForComponent(componentName,
644                     internalEndpoint, exchange);
645             fail("No exception was raised");
646         } catch (Exception JavaDoc e) {
647             // Do nothing
648
}
649
650         /*
651          * Test Case 2 There is one binding component matching this name
652          */

653         /*
654          * Create Test parameters
655          */

656         Component component = new ComponentMock();
657         ComponentLifeCycle lifeCycle = createMock(ComponentLifeCycle.class);
658         lifeCycleManager = createMock(LifeCycleManagerImpl.class);
659         /*
660          * Initialise Mocks
661          */

662         expect(lifeCycle.getComponent()).andReturn(component);
663         expect(lifeCycleManager.getComponentByName(componentName)).andReturn(
664                 lifeCycle);
665         replay(lifeCycleManager);
666         replay(lifeCycle);
667         adminService.manager = lifeCycleManager;
668         boolean result = false;
669         /*
670          * Run Test Case 2
671          */

672         try {
673             result = adminService.isExchangeWithConsumerOkayForComponent(
674                     componentName, internalEndpoint, exchange);
675         } catch (Exception JavaDoc e) {
676             e.printStackTrace();
677             fail("Error during invokation ");
678         }
679         assertTrue("the result of invokation should be true", result);
680         verify(lifeCycle);
681         verify(lifeCycleManager);
682     }
683
684     public void testIsExchangeWithProviderOkayForComponent() {
685         /*
686          * Test Case 1 There is no binding component matching this name
687          */

688         AdminService adminService = new AdminService();
689         LifeCycleManagerService lifeCycleManager = createMock(LifeCycleManagerImpl.class);
690         adminService.manager = lifeCycleManager;
691         LoggingUtil log = createMock(LoggingUtil.class);
692         adminService.log = log;
693         /*
694          * Create Test parameters
695          */

696         String JavaDoc componentName = "foo";
697         ServiceEndpoint internalEndpoint = createMock(InternalEndpoint.class);
698         MessageExchange exchange = createMock(MessageExchangeImpl.class);
699         /*
700          * Run Test Case 1
701          */

702         try {
703             adminService.isExchangeWithProviderOkayForComponent(componentName,
704                     internalEndpoint, exchange);
705             fail("No exception was raised");
706         } catch (Exception JavaDoc e) {
707             // Do nothing
708
}
709
710         /*
711          * Test Case 2 There is one binding component matching this name
712          */

713         /*
714          * Create Test parameters
715          */

716         Component component = new ComponentMock();
717         ComponentLifeCycle lifeCycle = createMock(ComponentLifeCycle.class);
718         lifeCycleManager = createMock(LifeCycleManagerImpl.class);
719         /*
720          * Initialise Mocks
721          */

722         expect(lifeCycle.getComponent()).andReturn(component);
723         expect(lifeCycleManager.getComponentByName(componentName)).andReturn(
724                 lifeCycle);
725         replay(lifeCycleManager);
726         replay(lifeCycle);
727         adminService.manager = lifeCycleManager;
728         boolean result = false;
729         /*
730          * Run Test Case 2
731          */

732         try {
733             result = adminService.isExchangeWithProviderOkayForComponent(
734                     componentName, internalEndpoint, exchange);
735         } catch (Exception JavaDoc e) {
736             e.printStackTrace();
737             fail("Error during invokation ");
738         }
739         assertTrue("the result of invokation should be true", result);
740         verify(lifeCycle);
741         verify(lifeCycleManager);
742     }
743
744     @Override JavaDoc
745     protected void setUp() {
746
747     }
748 }
749
Popular Tags