KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > jbi > component > context > ComponentContextImplTest


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: ComponentContextImplTest.java 15:38:25 ddesjardins $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.jbi.component.context;
23
24 import java.io.IOException JavaDoc;
25 import java.lang.reflect.Method JavaDoc;
26 import java.net.URL JavaDoc;
27 import java.util.HashMap JavaDoc;
28 import java.util.HashSet JavaDoc;
29 import java.util.Map JavaDoc;
30 import java.util.MissingResourceException JavaDoc;
31 import java.util.ResourceBundle JavaDoc;
32 import java.util.Set JavaDoc;
33 import java.util.logging.Logger JavaDoc;
34
35 import javax.jbi.JBIException;
36 import javax.jbi.component.Component;
37 import javax.jbi.management.MBeanNames;
38 import javax.jbi.messaging.DeliveryChannel;
39 import javax.jbi.messaging.MessagingException;
40 import javax.jbi.servicedesc.ServiceEndpoint;
41 import javax.management.MBeanServer JavaDoc;
42 import javax.management.ObjectName JavaDoc;
43 import javax.xml.namespace.QName JavaDoc;
44
45 import junit.framework.TestCase;
46
47 import org.objectweb.petals.jbi.component.context.ComponentContextImpl;
48 import org.objectweb.petals.jbi.component.lifecycle.ComponentLifeCycle;
49 import org.objectweb.petals.jbi.component.mock.MockEndpointService;
50 import org.objectweb.petals.jbi.management.service.EndpointService;
51 import org.objectweb.petals.jbi.management.service.EndpointServiceImpl;
52 import org.objectweb.petals.jbi.management.service.LifeCycleManagerImpl;
53 import org.objectweb.petals.jbi.management.service.MBeanNamesImpl;
54 import org.objectweb.petals.jbi.messaging.DeliveryChannelImpl;
55 import org.objectweb.petals.jbi.registry.AbstractEndpoint;
56 import org.objectweb.petals.jbi.registry.ConsumerEndpoint;
57 import org.objectweb.petals.jbi.registry.ExternalEndpoint;
58 import org.objectweb.petals.jbi.registry.InternalEndpoint;
59 import org.objectweb.petals.tools.jbicommon.descriptor.ComponentDescription;
60 import org.objectweb.petals.tools.jbicommon.descriptor.Identification;
61 import org.objectweb.petals.tools.jbicommon.descriptor.JBIDescriptor;
62 import org.w3c.dom.DocumentFragment JavaDoc;
63
64 import static org.easymock.EasyMock.expect;
65 import static org.easymock.classextension.EasyMock.createMock;
66 import static org.easymock.classextension.EasyMock.replay;
67 import static org.easymock.classextension.EasyMock.reset;
68 import static org.easymock.classextension.EasyMock.verify;
69
70 import com.sun.org.apache.xerces.internal.dom.DocumentFragmentImpl;
71
72 /**
73  * Test of the ComponentContextImpl
74  *
75  * @author ddesjardins - eBMWebsourcing
76  * @author wjoseph - eBMWebsourcing
77  */

78 public class ComponentContextImplTest extends TestCase {
79
80     private ComponentContextImpl componentContextImpl;
81
82     private MockEndpointService endpointService;
83
84     @Override JavaDoc
85     protected void setUp() {
86         componentContextImpl = new ComponentContextImpl();
87         Logger JavaDoc logger = Logger.getLogger("test");
88         componentContextImpl.setRootLogger(logger);
89         endpointService = new MockEndpointService();
90         componentContextImpl.endpointService = endpointService;
91     }
92
93     public void testGetLogger() throws MissingResourceException JavaDoc, JBIException {
94         /*
95          * Test Case 1
96          * suffix is null
97          */

98         Logger JavaDoc rootLogger = Logger.getLogger("rootLogger");
99         componentContextImpl.rootLogger = rootLogger;
100         /*
101          * Run Test Case 1
102          */

103         String JavaDoc suffix = null;
104         try{
105             componentContextImpl.getLogger(suffix, null);
106             fail("No Exception is raised");
107         } catch (Exception JavaDoc e) {
108             // Do nothing
109
}
110         /*
111          * Test Case 2
112          * The suffix is an empty string
113          */

114         /*
115          * Run Test Case 2
116          */

117         suffix = "";
118         Logger JavaDoc result = componentContextImpl.getLogger(suffix, null);
119         assertNotNull(result);
120         assertEquals("Returned logger does not have the name of base componentn logger",result.getName(),rootLogger.getName());
121         /*
122          * Test Case 3
123          * The suffix is a string, the created logger must have a name containing this suffix
124          */

125         /*
126          * Run Test Case 3
127          */

128         suffix = "test";
129         result = componentContextImpl.getLogger(suffix, null);
130         assertNotNull(result);
131         assertEquals("Returned logger does not have the name of base componentn logger",result.getName(),rootLogger.getName()+"."+suffix);
132     }
133
134     public void testGetLoggerSameSuffix() throws MissingResourceException JavaDoc,
135         JBIException {
136         Logger JavaDoc logger = componentContextImpl.getLogger("suffix", null);
137         Logger JavaDoc logger1 = componentContextImpl.getLogger("suffix", null);
138         assertEquals(logger, logger1);
139     }
140
141     public void testGetLoggerResourceFile() throws MissingResourceException JavaDoc,
142         JBIException, IOException JavaDoc {
143         URL JavaDoc url = this.getClass().getClassLoader().getResource(
144             "myresources_fr.properties");
145         assertNotNull(url);
146         Logger JavaDoc logger = componentContextImpl.getLogger("resource",
147             "myresources");
148         ResourceBundle JavaDoc resourceBundle = logger.getResourceBundle();
149         assertEquals(resourceBundle.getString("Error"), "Erreur");
150     }
151
152     public void testActivateEndpoint() {
153         /*
154          * Test Case 1
155          * Everything goes well, a new InternalEndpoint is created
156          */

157         /*
158          * Create Mocks
159          */

160         Method JavaDoc method1 = null;
161         try {
162             method1 = EndpointServiceImpl.class.getDeclaredMethod("activateEndpoint", new Class JavaDoc[]{QName JavaDoc.class,String JavaDoc.class,ConsumerEndpoint.class});
163         } catch (Exception JavaDoc e) {
164             e.printStackTrace();
165             fail("Could not retrieve mocks methods");
166         }
167         Method JavaDoc[] mockedMethods = new Method JavaDoc[]{method1};
168         EndpointService epService = createMock(EndpointServiceImpl.class,mockedMethods);
169         String JavaDoc service = "fooService";
170         String JavaDoc namespace = "namespace";
171         QName JavaDoc serviceName = new QName JavaDoc(namespace,service);
172         String JavaDoc endpointName = "fooServiceEndpoint";
173         ConsumerEndpoint consumerEndpoint = createMock(ConsumerEndpoint.class);
174         InternalEndpoint internalEP = createMock(InternalEndpoint.class);
175         /*
176          * Initialize Mocks
177          */

178         try {
179         expect(epService.activateEndpoint(serviceName, endpointName, consumerEndpoint)).andReturn(internalEP);
180         } catch (JBIException e){
181             e.printStackTrace();
182             fail("Could not initialize mocks");
183         }
184         replay(epService);
185         componentContextImpl.endpointService = epService;
186         componentContextImpl.internalEndpoints = new HashSet JavaDoc<AbstractEndpoint>();
187         componentContextImpl.address = consumerEndpoint;
188         /*
189          * Run Test Case 1
190          */

191         ServiceEndpoint result = null;
192         try {
193             result = componentContextImpl.activateEndpoint(serviceName,endpointName);
194         } catch (JBIException e){
195             e.printStackTrace();
196             fail("Error during method invokation");
197         }
198         assertNotNull("The result of activateEndpoint must not be null",result);
199         assertEquals("Wrong endpoint created",internalEP, result);
200         assertTrue("ComponentContext does not contain the newly created ", componentContextImpl.internalEndpoints.contains(internalEP));
201         verify(epService);
202
203         /*
204          * Test Case 2
205          * The serviceName is null, an exception is raised
206          */

207         /*
208          * Run Test Case 2
209          */

210         try{
211         componentContextImpl.activateEndpoint(null,endpointName);
212         fail("No exception was raised");
213         } catch (Exception JavaDoc e) {
214         }
215         
216         /*
217          * Test Case 3
218          * The endpointName is null, an exception is raised
219          */

220         /*
221          * Run Test Case 3
222          */

223         try{
224         componentContextImpl.activateEndpoint(serviceName,null);
225         fail("No exception was raised");
226         } catch (Exception JavaDoc e) {
227         }
228         
229     }
230
231     public void testDeactivateEndpoint() {
232         /*
233          * Test Case 1
234          * Everything goes well, the InternalEndpoint is deactivated
235          */

236         EndpointService epService = createMock(EndpointServiceImpl.class);
237         AbstractEndpoint serviceEP = createMock(InternalEndpoint.class);
238         Set JavaDoc<AbstractEndpoint> endpoints = new HashSet JavaDoc<AbstractEndpoint>();
239         endpoints.add(serviceEP);
240         componentContextImpl.endpointService = epService;
241         componentContextImpl.internalEndpoints = endpoints;
242         /*
243          * Run Test Case 1
244          */

245         try {
246             componentContextImpl.deactivateEndpoint(serviceEP);
247         } catch (JBIException e){
248             e.printStackTrace();
249             fail("Error during method invokation");
250         }
251         assertFalse("The service endpoint was not properly deactivated", componentContextImpl.internalEndpoints.contains(serviceEP));
252         
253         /*
254          * Test Case 2
255          * endpoint is null, an exception is raised
256          */

257         /*
258          * Run Test Case 2
259          */

260         try {
261         componentContextImpl.deactivateEndpoint(null);
262         fail("No exception was thrown");
263         } catch (Exception JavaDoc e) {
264         }
265     }
266
267     public void testDeregisterAllEndpoints() {
268         componentContextImpl.internalEndpoints = new HashSet JavaDoc<AbstractEndpoint>();
269         componentContextImpl.externalEndpoints = new HashSet JavaDoc<ServiceEndpoint>();
270         InternalEndpoint internalEndpoint = new InternalEndpoint(new QName JavaDoc(
271             "service"), "endpoint", "compo", "0", null);
272         componentContextImpl.internalEndpoints.add(internalEndpoint);
273         ExternalEndpoint externalEndpoint = new ExternalEndpoint(
274             new ConsumerEndpoint("compo", "0"), "compo", "0");
275         componentContextImpl.externalEndpoints.add(externalEndpoint);
276         try {
277             componentContextImpl.deregisterAllEndpoints();
278         } catch (JBIException e){
279             e.printStackTrace();
280             fail("Error during method invokation");
281         }
282         assertEquals(componentContextImpl.internalEndpoints.size(), 0);
283         assertEquals(componentContextImpl.externalEndpoints.size(), 0);
284         assertTrue(endpointService.isDeregisterExternalEndpoint());
285         assertTrue(endpointService.isDeactivateEndpoint());
286     }
287
288     public void testDeregisterExternalEndpoint() {
289         ExternalEndpoint externalEndpoint = new ExternalEndpoint(
290             new ConsumerEndpoint("compo", "0"), "compo", "0");
291         componentContextImpl.externalEndpoints = new HashSet JavaDoc<ServiceEndpoint>();
292         componentContextImpl.externalEndpoints.add(externalEndpoint);
293         try {
294         componentContextImpl.deregisterExternalEndpoint(externalEndpoint);
295         } catch (JBIException e){
296             e.printStackTrace();
297             fail("Error during method invokation");
298         }
299         assertEquals(componentContextImpl.externalEndpoints.size(), 0);
300         assertTrue(endpointService.isDeregisterExternalEndpoint());
301     }
302     
303     public void testGetComponentName() {
304         /*
305          * Test Case 1
306          */

307         /*
308          * Create Mock
309          */

310         JBIDescriptor descriptor = createMock(JBIDescriptor.class);
311         ComponentDescription componentDescription = createMock(ComponentDescription.class);
312         Identification identification = createMock(Identification.class);
313         String JavaDoc componentName = "fooComponent";
314         expect(identification.getName()).andReturn(componentName);
315         expect(componentDescription.getIdentification()).andReturn(identification);
316         expect(descriptor.getComponent()).andReturn(componentDescription);
317         replay(identification);
318         replay(componentDescription);
319         replay(descriptor);
320         /*
321          * Create Test parameters
322          */

323         componentContextImpl.descriptor = descriptor;
324         /*
325          * Run Test Case 1
326          */

327         String JavaDoc result = componentContextImpl.getComponentName();
328         assertNotNull("The result can not be null",result);
329         assertFalse("The result can not be an empty String",result.length()==0);
330     }
331
332     public void testGetDeliveryChannel() throws MessagingException {
333         /*
334          * Test Case 1
335          * A delivery channel already exists in the ComponentContext but is not opened
336          */

337         Method JavaDoc method1 = null;
338         try {
339             method1 = ComponentContextImpl.class.getDeclaredMethod("createDeliveryChannel", new Class JavaDoc[]{});
340         } catch (Exception JavaDoc e) {
341             e.printStackTrace();
342             fail("Could not retrieve mocked methods");
343         }
344         Method JavaDoc[] mockedMethods = new Method JavaDoc[]{method1};
345         ComponentContextImpl componentContextImpl = createMock(ComponentContextImpl.class,mockedMethods);
346         DeliveryChannelImpl oldDeliveryChannel = createMock(DeliveryChannelImpl.class);
347         DeliveryChannelImpl newDeliveryChannel = createMock(DeliveryChannelImpl.class);
348         expect(oldDeliveryChannel.isOpened()).andReturn(false);
349         expect(componentContextImpl.createDeliveryChannel()).andReturn(newDeliveryChannel);
350         replay(oldDeliveryChannel);
351         replay(componentContextImpl);
352         componentContextImpl.deliveryChannel = oldDeliveryChannel;
353         /*
354          * Run Test Case 1
355          */

356         DeliveryChannel result = componentContextImpl.getDeliveryChannel();
357         assertNotNull("The result of GetDeliveryChannel can not be null",result);
358         assertEquals("Wrong DeliveryChannel returned",newDeliveryChannel, result);
359         verify(oldDeliveryChannel);
360         verify(componentContextImpl);
361         
362         /*
363          * Test Case 2
364          * A delivery channel already exists in the ComponentContext but is opened
365          * An exception will be raised
366          */

367         reset(oldDeliveryChannel);
368         componentContextImpl = createMock(ComponentContextImpl.class,mockedMethods);
369         expect(oldDeliveryChannel.isOpened()).andReturn(true);
370         replay(oldDeliveryChannel);
371         componentContextImpl.deliveryChannel = oldDeliveryChannel;
372         /*
373          * Run Test Case 2
374          */

375         try {
376         componentContextImpl.getDeliveryChannel();
377         fail("No exception was raised");
378         } catch (Exception JavaDoc e) {
379             verify(oldDeliveryChannel);
380         }
381         
382         /*
383          * Test Case 3
384          * No DeliveryChannel exists a new one is created
385          */

386         componentContextImpl = createMock(ComponentContextImpl.class,mockedMethods);
387         expect(componentContextImpl.createDeliveryChannel()).andReturn(newDeliveryChannel);
388         replay(componentContextImpl);
389         /*
390          * Run Test Case 3
391          */

392         try {
393         result = componentContextImpl.getDeliveryChannel();
394         } catch (Exception JavaDoc e) {
395             fail("Exception during method invokation");
396         }
397         assertNotNull("The result of GetDeliveryChannel can not be null",result);
398         assertEquals("Wrong DeliveryChannel returned",newDeliveryChannel, result);
399         verify(componentContextImpl);
400     }
401
402     public void testGetEndpoint() {
403         /*
404          * Test Case 1
405          * the parameter service is null, an exception is raised
406          */

407         /*
408          * Create Test parameters
409          */

410         QName JavaDoc serviceName = new QName JavaDoc("fooService");
411         String JavaDoc name = "fooService";
412         /*
413          * Run Test Case 1
414          */

415         try {
416         componentContextImpl.getEndpoint(null, name);
417         fail("No exception was raised");
418         } catch (Exception JavaDoc e) {
419         }
420         
421         /*
422          * Test Case 2
423          * the parameter name is null, an exception is raised
424          */

425         /*
426          * Run Test Case 2
427          */

428         try {
429         componentContextImpl.getEndpoint(serviceName, null);
430         fail("No exception was raised");
431         } catch (Exception JavaDoc e) {
432         }
433         /*
434          * Test Case 3
435          * the parameter service is null, an exception is raised
436          */

437         /*
438          * Run Test Case 3
439          */

440         componentContextImpl.getEndpoint(serviceName, name);
441         assertTrue(endpointService.isGetEndpoint());
442     }
443
444     public void testGetEndpointDescriptor() {
445         /*
446          * Test Case 1
447          * The endpoint is null, an exception is raised
448          */

449         /*
450          * Run Test Case 1
451          */

452         try {
453             componentContextImpl.getEndpointDescriptor(null);
454             fail("no exception was raised");
455         } catch (Exception JavaDoc e) {
456             // do nothing
457
}
458         /*
459          * Test Case 2
460          * The endpoint is not null
461          */

462         /*
463          * Create Mocks
464          */

465         Method JavaDoc method1 = null;
466         try {
467             method1 = ComponentContextImpl.class.getDeclaredMethod("getEndpoint", new Class JavaDoc[]{QName JavaDoc.class,String JavaDoc.class});
468         } catch (Exception JavaDoc e) {
469             e.printStackTrace();
470             fail("Could not retrieve mocked methods");
471         }
472         Method JavaDoc[] mockedMethods = new Method JavaDoc[]{method1};
473         componentContextImpl = createMock(ComponentContextImpl.class,mockedMethods);
474         InternalEndpoint internalEndpoint = new InternalEndpoint(new QName JavaDoc(
475             "test"), "endpoint", "compo", "0", null);
476         internalEndpoint.setDescription("<test></test>");
477         /*
478          * Initialize Mocks
479          */

480         expect(componentContextImpl.getEndpoint(internalEndpoint.getServiceName(), internalEndpoint.getEndpointName())).andReturn(internalEndpoint);
481         replay(componentContextImpl);
482         /*
483          * Run Test Case 2
484          */

485         try {
486             assertNotNull(componentContextImpl.getEndpointDescriptor(internalEndpoint));
487         } catch (JBIException e){
488             e.printStackTrace();
489             fail("Error during method invokation");
490         }
491         verify(componentContextImpl);
492     }
493
494     public void testGetEndpoints() {
495         ServiceEndpoint[] result = componentContextImpl.getEndpoints(null);
496         assertTrue(endpointService.isGetInternalEndpointsForInterface());
497         assertNotNull("The result can not be null",result);
498     }
499
500     public void testGetEndpointsForService() {
501         /*
502          * Test Case 1
503          * The service name is null, an exception is raised
504          */

505         /*
506          * Run Test Case 1
507          */

508         try{
509         componentContextImpl.getEndpointsForService(null);
510         fail("No exception was raised");
511         } catch (Exception JavaDoc e) {
512             // Do nothing
513
}
514         /*
515          * Test Case 2
516          * The service name not null, a ServiceEndpoint array is returned
517          */

518         /*
519          * Run Test Case 2
520          */

521         ServiceEndpoint[] endpoints = componentContextImpl.getEndpointsForService(new QName JavaDoc("fooService"));
522         assertTrue(endpointService.isGetInternalEndpointsForService());
523         assertNotNull("Result must not be null",endpoints);
524     }
525
526     public void testGetExternalEndpoints() {
527         /*
528          * Test Case 1
529          * The interface name is null, an exception is raised
530          */

531         /*
532          * Run Test Case1
533          */

534         try {
535         componentContextImpl.getExternalEndpoints(null);
536         fail("No exception was raised");
537         } catch (Exception JavaDoc e) {
538            // Do nothing
539
}
540         /*
541          * Test Case 2
542          * The service name not null, a ServiceEndpoint array is returned
543          */

544         /*
545          * Run Test Case 2
546          */

547         ServiceEndpoint[] endpoints = componentContextImpl.getExternalEndpoints(new QName JavaDoc("fooService"));
548         assertTrue(endpointService.isGetExternalEndpointsForInterface());
549         assertNotNull("Result must not be null",endpoints);
550     }
551
552     public void testGetExternalEndpointsForService() {
553         /*
554          * Test Case 1
555          * The interface name is null, an exception is raised
556          */

557         /*
558          * Run Test Case1
559          */

560         try {
561         componentContextImpl.getExternalEndpointsForService(null);
562         fail("No exception was raised");
563         } catch (Exception JavaDoc e) {
564            // Do nothing
565
}
566         /*
567          * Test Case 2
568          * The service name not null, a ServiceEndpoint array is returned
569          */

570         /*
571          * Run Test Case 2
572          */

573         ServiceEndpoint[] endpoints = componentContextImpl.getExternalEndpointsForService(new QName JavaDoc("fooService"));
574         assertNotNull("Result must not be null",endpoints);
575         assertTrue(endpointService.isGetExternalEndpointsForService());
576     }
577
578     public void testGetInstallRoot() {
579         componentContextImpl.installationRoot = "root";
580         String JavaDoc result = componentContextImpl.getInstallRoot();
581         assertNotNull("The result must not be null",result);
582         assertFalse("The result string must not be empty",result.length() == 0);
583         assertEquals(result, "root");
584     }
585
586     public void testGetMBeanNames() {
587         MBeanNames beanNames = new MBeanNamesImpl("test");
588         componentContextImpl.beanNames = beanNames;
589         MBeanNames result = componentContextImpl.getMBeanNames();
590         assertNotNull("Result of getMBeanNames must not be null",result);
591         assertEquals(result, beanNames);
592     }
593     
594     public void testGetMBeanServer() {
595      /*
596       * Test Case 1
597       */

598         componentContextImpl.beanServer = createMock(MBeanServer JavaDoc.class);
599       /*
600        * Run Test Case 1
601        */

602         MBeanServer JavaDoc result = componentContextImpl.getMBeanServer();
603         assertNotNull("Result of getMBeanServer must not be null",result);
604     }
605     
606     public void testGetNamingContext() {
607         try {
608             componentContextImpl.getNamingContext();
609             fail();
610         } catch (Error JavaDoc e) {
611             // Do nothing
612
}
613     }
614
615     public void testGetTransactionManager() {
616         try {
617             componentContextImpl.getTransactionManager();
618             fail();
619         } catch (Error JavaDoc e) {
620             // Do nothing
621
}
622     }
623
624     public void testGetWorkspaceRoot() {
625         /*
626          * Test Case 1
627          */

628         /*
629          * Run Test Case 1
630          */

631         componentContextImpl.workspaceRoot = "work";
632         String JavaDoc result = componentContextImpl.getWorkspaceRoot();
633         assertNotNull("The result of getWorkspaceRoot must be non null",result);
634         assertFalse("The result of getWorkspaceRoot must be non empty",result.length() == 0);
635         assertEquals(result, "work");
636     }
637
638     public void testRegisterExternalEndpoint() {
639         /*
640          * Test Case 1
641          * The externalEndpoint we want to register is null
642          */

643         /*
644          * Run Test Case 1
645          */

646         try{
647         componentContextImpl.registerExternalEndpoint(null);
648         fail("No Exception was raised");
649         } catch (Exception JavaDoc e) {
650             //Do nothing
651
}
652         /*
653          * Test Case 2
654          * The externalEndpoint we want to register is not null
655          */

656         ExternalEndpoint externalEndpoint = new ExternalEndpoint(
657             new InternalEndpoint(new QName JavaDoc("service"), "endpoint", "compo",
658                 "0", null), "compo", "0");
659         componentContextImpl.externalEndpoints = new HashSet JavaDoc<ServiceEndpoint>();
660         /*
661          * Run Test Case 2
662          */

663         try {
664         componentContextImpl.registerExternalEndpoint(externalEndpoint);
665         } catch (JBIException e){
666             e.printStackTrace();
667             fail("Error during method invokation");
668         }
669         assertEquals(componentContextImpl.externalEndpoints.size(), 1);
670         assertTrue(endpointService.isRegisterExternalEndpoint());
671     }
672     
673     public void testResolveEndpointReference() {
674         /*
675          * Test Case 1
676          * The document frangement parameter is not null, but the endpoint is not resolved
677          * Result is null
678          */

679         /*
680          * Create Mocks
681          */

682         Method JavaDoc method1 = null;
683         Method JavaDoc method2 = null;
684         try {
685             method1 = LifeCycleManagerImpl.class.getDeclaredMethod("getEngineCompoLifeCycles", new Class JavaDoc[]{});
686             method2 = LifeCycleManagerImpl.class.getDeclaredMethod("getBindingCompoLifeCycles", new Class JavaDoc[]{});
687         } catch (Exception JavaDoc e) {
688             e.printStackTrace();
689             fail("Could not retrieve mocked methods");
690         }
691         Method JavaDoc[] mockedMethods = new Method JavaDoc[]{method1, method2};
692         LifeCycleManagerImpl lyfeCycleManager = createMock(LifeCycleManagerImpl.class,mockedMethods);
693         /*
694          * Create Test parameters
695          */

696         DocumentFragment JavaDoc epr = createMock(DocumentFragmentImpl.class);
697         ComponentLifeCycle compoLifeCycle = createMock(ComponentLifeCycle.class);
698         ComponentLifeCycle engineLifeCycle = createMock(ComponentLifeCycle.class);
699         Component bindingComponent = createMock(Component.class);
700         Component engineComponent = createMock(Component.class);
701         ObjectName JavaDoc engineName = createMock(ObjectName JavaDoc.class);
702         ObjectName JavaDoc bindingName = createMock(ObjectName JavaDoc.class);
703         Map JavaDoc<ObjectName JavaDoc,ComponentLifeCycle> engines = new HashMap JavaDoc<ObjectName JavaDoc, ComponentLifeCycle>();
704         Map JavaDoc<ObjectName JavaDoc,ComponentLifeCycle> bindings = new HashMap JavaDoc<ObjectName JavaDoc, ComponentLifeCycle>();
705         engines.put(engineName, engineLifeCycle);
706         bindings.put(bindingName, compoLifeCycle);
707         try {
708             expect(lyfeCycleManager.getEngineCompoLifeCycles()).andReturn(engines);
709             expect(lyfeCycleManager.getBindingCompoLifeCycles()).andReturn(bindings);
710             expect(compoLifeCycle.getComponent()).andReturn(bindingComponent);
711             expect(engineLifeCycle.getComponent()).andReturn(engineComponent);
712         } catch (Exception JavaDoc e) {
713             e.printStackTrace();
714             fail("Could not register testing componentLyfeCycle");
715         }
716         replay(lyfeCycleManager);
717         replay(compoLifeCycle);
718         replay(engineLifeCycle);
719         componentContextImpl.manager = lyfeCycleManager;
720         /*
721          * Run Test Case 1
722          */

723         ServiceEndpoint result = null;
724         try {
725             result = componentContextImpl.resolveEndpointReference(epr);
726         } catch (Exception JavaDoc e) {
727             e.printStackTrace();
728             fail("Exception during method invokation");
729         }
730         assertNull("the result of resolveEndpointReference should be null",result);
731         verify(lyfeCycleManager);
732         verify(compoLifeCycle);
733         verify(engineLifeCycle);
734         /*
735          * Test Case 2
736          * The document frangement parameter is null, an exception is raised
737          */

738         /*
739          * Run Test Case 2
740          */

741         try{
742         componentContextImpl.resolveEndpointReference(null);
743         fail("No exception was raised");
744         } catch (Exception JavaDoc e) {
745             //Do nothing
746
}
747     }
748
749 }
750
Popular Tags