KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > jbi > registry > JNDIRegistryTest


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: JoramRegistryTest.java 10:05:48 ddesjardins $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.jbi.registry;
23
24 import java.lang.reflect.Method JavaDoc;
25 import java.util.List JavaDoc;
26
27 import javax.jbi.JBIException;
28 import javax.naming.Context JavaDoc;
29 import javax.naming.InitialContext JavaDoc;
30 import javax.naming.LinkRef JavaDoc;
31 import javax.naming.Name JavaDoc;
32 import javax.naming.NameClassPair JavaDoc;
33 import javax.naming.NamingException JavaDoc;
34 import javax.xml.namespace.QName JavaDoc;
35
36 import junit.framework.TestCase;
37
38 import org.easymock.classextension.EasyMock;
39 import org.objectweb.fractal.api.control.IllegalLifeCycleException;
40 import org.objectweb.petals.jbi.registry.mock.MockContext;
41 import org.objectweb.petals.jbi.registry.mock.MockInitialContext;
42 import org.objectweb.petals.jbi.registry.mock.MockLinkRef;
43 import org.objectweb.petals.kernel.registry.jndi.NamingEnumerationImpl;
44 import org.objectweb.petals.util.LoggingUtil;
45 import org.objectweb.petals.util.NamingHelper;
46 import org.objectweb.util.monolog.api.Logger;
47
48 /**
49  * Test of the JoramRegistry
50  *
51  * @author ddesjardins - eBMWebsourcing
52  */

53 public class JNDIRegistryTest extends TestCase {
54
55     private MockContext endpointsContext = new MockContext();
56
57     private MockContext interfacesContext = new MockContext();
58
59     private MockContext newEndpointContext = new MockContext();
60
61     private JNDIRegistry registry;
62
63     private MockInitialContext rootContext;
64
65     private MockContext servicesContext = new MockContext();
66
67     public void setUp() throws NamingException JavaDoc {
68         registry = new JNDIRegistry();
69         rootContext = new MockInitialContext();
70
71         rootContext.bind(JNDIRegistry.ENDPOINTS_REF, endpointsContext);
72         rootContext.bind(JNDIRegistry.INTERFACES_REF, interfacesContext);
73         rootContext.bind(JNDIRegistry.NEW_ENDPOINTS_REF, newEndpointContext);
74         rootContext.bind(JNDIRegistry.SERVICES_REF, servicesContext);
75
76         registry.rootContext = rootContext;
77
78         Logger logger = EasyMock.createMock(Logger.class);
79         registry.logger = logger;
80         registry.log = EasyMock.createMock(LoggingUtil.class);
81
82         registry.endpointsContext = endpointsContext;
83         registry.interfacesContext = interfacesContext;
84         registry.newEndpointContext = newEndpointContext;
85         registry.servicesContext = servicesContext;
86     }
87
88     public void testDeregisterConnection() throws RegistryException {
89         LinkedEndpoint linkedEndpoint = new LinkedEndpoint(new QName JavaDoc("serv"),
90             "endpoint", new QName JavaDoc("toserv"), "endpoint", null);
91         InternalEndpoint internalEndpoint = new InternalEndpoint(new QName JavaDoc(
92             "toserv"), "endpoint", "compo", "0", null);
93         endpointsContext.getBindings().put("endpoint", internalEndpoint);
94         registry.registerConnection(linkedEndpoint);
95         registry.deregisterConnection(linkedEndpoint);
96         assertEquals(interfacesContext.getBindings().size(), 0);
97     }
98
99     public void testDeregisterConnectionWithInterfaces()
100         throws RegistryException {
101         LinkedEndpoint linkedEndpoint = new LinkedEndpoint(new QName JavaDoc("inter"),
102             new QName JavaDoc("toserv"), "endpoint", null);
103         InternalEndpoint internalEndpoint = new InternalEndpoint(new QName JavaDoc(
104             "toserv"), "endpoint", "compo", "0", null);
105         internalEndpoint.setInterfaces(new QName JavaDoc[] {new QName JavaDoc("test")});
106         endpointsContext.getBindings().put("endpoint", internalEndpoint);
107         registry.registerConnection(linkedEndpoint);
108         registry.deregisterConnection(linkedEndpoint);
109         assertEquals(interfacesContext.getBindings().size(), 0);
110     }
111
112     public void testDeregisterConnectionExceptionNull() {
113         try {
114             registry.deregisterConnection(null);
115             fail();
116         } catch (Exception JavaDoc e) {
117             // Do nothing
118
}
119     }
120
121     public void testDeregisterConnectionWithInterfacesStillNewEndpoints()
122         throws RegistryException {
123         LinkedEndpoint linkedEndpoint = new LinkedEndpoint(new QName JavaDoc("inter"),
124             new QName JavaDoc("toserv"), "endpoint", null);
125         InternalEndpoint internalEndpoint = new InternalEndpoint(new QName JavaDoc(
126             "toserv"), "endpoint", "compo", "0", null);
127         endpointsContext.getBindings().put("endpoint", internalEndpoint);
128         newEndpointContext.getBindings().put("endpoint", internalEndpoint);
129         registry.registerConnection(linkedEndpoint);
130         registry.deregisterConnection(linkedEndpoint);
131         assertEquals(interfacesContext.getBindings().size(), 1);
132         assertEquals(((MockContext) interfacesContext.getBindings()
133             .get("inter")).getBindings().size(), 0);
134     }
135
136     public void testDeregisterConnectionWithInterfacesNotRegistered()
137         throws RegistryException {
138         LinkedEndpoint linkedEndpoint = new LinkedEndpoint(new QName JavaDoc("inter"),
139             new QName JavaDoc("toserv"), "endpoint", null);
140         try {
141             registry.deregisterConnection(linkedEndpoint);
142             fail();
143         } catch (Exception JavaDoc e) {
144             // Do nothing
145
}
146     }
147
148     public void testDeregisterExternalEndpoint() throws JBIException,
149         NamingException JavaDoc {
150         AbstractEndpoint endpoint = new InternalEndpoint(new QName JavaDoc("test"),
151             "endpoint", "axis2bc", "0", null);
152         testRegisterInternalEndpoint();
153         registry.deregisterExternalEndpoint(endpoint);
154         assertEquals(endpointsContext.getBindings().size(), 0);
155     }
156
157     public void testDeregisterExternalEndpointException() {
158         try {
159             registry.deregisterExternalEndpoint(null);
160             fail();
161         } catch (Exception JavaDoc e) {
162             // Do nothing
163
}
164     }
165
166     public void testDeregisterInternalEndpoint() throws JBIException,
167         NamingException JavaDoc {
168         AbstractEndpoint endpoint = new InternalEndpoint(new QName JavaDoc("test"),
169             "endpoint", "axis2bc", "0", null);
170         testRegisterInternalEndpoint();
171         registry.deregisterInternalEndpoint(endpoint);
172         assertEquals(endpointsContext.getBindings().size(), 0);
173     }
174
175     public void testDeregisterInternalEndpointException() {
176         InternalEndpoint internalEndpoint = new InternalEndpoint(new QName JavaDoc(
177             "serv"), "endpoint", "compo", "0", null);
178         try {
179             registry.deregisterInternalEndpoint(internalEndpoint);
180             fail();
181         } catch (Exception JavaDoc e) {
182             // Do nothing
183
}
184     }
185
186     public void testDeregisterInternalEndpointExceptionInterface()
187         throws RegistryException, NamingException JavaDoc {
188         AbstractEndpoint endpoint = new InternalEndpoint(new QName JavaDoc("test"),
189             "endpoint", "axis2bc", "0", null);
190         endpoint.setInterfaces(new QName JavaDoc[] {new QName JavaDoc("foo")});
191         registry.registerInternalEndpoint(endpoint);
192         MockContext context = new MockContext();
193         interfacesContext.bind("inter", context);
194         MockLinkRef linkRef = new MockLinkRef("endpoint");
195         linkRef.setClassName(InternalEndpoint.class.getName());
196         context.bind("endpoint", linkRef);
197         try {
198             registry.deregisterInternalEndpoint(endpoint);
199             fail();
200         } catch (Exception JavaDoc e) {
201             // Do nothing
202
}
203     }
204
205     public void testDeregisterInternalEndpointExceptionNull() {
206         try {
207             registry.deregisterInternalEndpoint(null);
208             fail();
209         } catch (Exception JavaDoc e) {
210             // do nothing
211
}
212     }
213
214     public void testDeregisterInternalEndpointExceptionService()
215         throws RegistryException {
216         AbstractEndpoint endpoint = new InternalEndpoint(new QName JavaDoc("test"),
217             "endpoint", "axis2bc", "0", null);
218         registry.registerInternalEndpoint(endpoint);
219         servicesContext.getBindings().clear();
220         try {
221             registry.deregisterInternalEndpoint(endpoint);
222             fail();
223         } catch (Exception JavaDoc e) {
224             // Do nothing
225
}
226     }
227
228     public void testDeregisterInternalEndpointWithInterfaces()
229         throws JBIException, NamingException JavaDoc {
230         AbstractEndpoint endpoint = new InternalEndpoint(new QName JavaDoc("test"),
231             "endpoint", "axis2bc", "0", null);
232         endpoint.setInterfaces(new QName JavaDoc[] {new QName JavaDoc("inter")});
233         registry.registerInternalEndpoint(endpoint);
234         MockContext context = new MockContext();
235         interfacesContext.bind("inter", context);
236         MockLinkRef linkRef = new MockLinkRef("endpoint");
237         linkRef.setClassName(InternalEndpoint.class.getName());
238         context.bind("endpoint", linkRef);
239         registry.deregisterInternalEndpoint(endpoint);
240         assertEquals(endpointsContext.getBindings().size(), 0);
241     }
242
243     public void testGetExternalEndpoint() throws JBIException, NamingException JavaDoc {
244         InternalEndpoint internalEndpoint = new InternalEndpoint(new QName JavaDoc(
245             "service"), "endpoint", "compo", "0", null);
246         ExternalEndpoint externalEndpoint = new ExternalEndpoint(
247             internalEndpoint, "compo", "0");
248         endpointsContext.getBindings().put("endpoint", externalEndpoint);
249         AbstractEndpoint endpoint = registry.getExternalEndpoint(new QName JavaDoc(
250             "test"), "endpoint");
251         assertEquals(endpoint.containerName, "0");
252     }
253
254     public void testGetExternalEndpointsForInterface() throws JBIException,
255         NamingException JavaDoc {
256         ExternalEndpoint externalEndpoint = new ExternalEndpoint(
257             new ConsumerEndpoint("compo", "0"), "compo", "0");
258         rootContext.bind("test-link", externalEndpoint);
259         MockContext context = (MockContext) interfacesContext
260             .createSubcontext("test");
261         MockLinkRef linkRef = new MockLinkRef("test-link");
262         linkRef.setClassName(ExternalEndpoint.class.getName());
263         context.bind("inter1", linkRef);
264         AbstractEndpoint[] endpoints = registry
265             .getExternalEndpointsForInterface(new QName JavaDoc("test"));
266         assertEquals(endpoints[0], externalEndpoint);
267     }
268
269     public void testGetExternalEndpointsForInterfaceNotRegisteredInterface()
270         throws RegistryException {
271         assertEquals(0, registry.getExternalEndpointsForInterface(new QName JavaDoc(
272             "test")).length);
273     }
274
275     public void testGetExternalEndpointsForService() throws JBIException,
276         NamingException JavaDoc {
277         ExternalEndpoint externalEndpoint = new ExternalEndpoint(
278             new ConsumerEndpoint("compo", "0"), "compo", "0");
279         rootContext.bind("test-link", externalEndpoint);
280         MockContext context = (MockContext) servicesContext
281             .createSubcontext("test");
282         MockLinkRef linkRef = new MockLinkRef("test-link");
283         linkRef.setClassName(ExternalEndpoint.class.getName());
284         context.bind("inter1", linkRef);
285         AbstractEndpoint[] endpoints = registry
286             .getExternalEndpointsForService(new QName JavaDoc("test"));
287         assertEquals(endpoints[0], externalEndpoint);
288     }
289
290     public void testGetInternalEndpoint() throws JBIException, NamingException JavaDoc {
291         InternalEndpoint internalEndpoint = new InternalEndpoint(new QName JavaDoc(
292             "service"), "endpoint", "compo", "0", null);
293         endpointsContext.getBindings().put("endpoint", internalEndpoint);
294         AbstractEndpoint endpoint = registry.getInternalEndpoint(new QName JavaDoc(
295             "test"), "endpoint");
296         assertEquals(endpoint.containerName, "0");
297     }
298
299     public void testGetInternalEndpointsForInterface() throws JBIException,
300         NamingException JavaDoc {
301         InternalEndpoint internalEndpoint = new InternalEndpoint(new QName JavaDoc(
302             "service"), "endpoint", "compo", "0", null);
303         rootContext.bind("test-link", internalEndpoint);
304         MockContext context = (MockContext) interfacesContext
305             .createSubcontext("test");
306         MockLinkRef linkRef = new MockLinkRef("test-link");
307         linkRef.setClassName(InternalEndpoint.class.getName());
308         context.bind("inter1", linkRef);
309         AbstractEndpoint[] endpoints = registry
310             .getInternalEndpointsForInterface(new QName JavaDoc("test"));
311         assertEquals(endpoints[0], internalEndpoint);
312     }
313
314     public void testGetInternalEndpointsForInterface1() throws JBIException,
315         NamingException JavaDoc {
316         testRegisterInternalEndpoint();
317         AbstractEndpoint[] endpoints = registry
318             .getInternalEndpointsForInterface(null);
319         assertEquals(endpoints[0].containerName, "0");
320     }
321
322     public void testGetInternalEndpointsForService() throws JBIException,
323         NamingException JavaDoc {
324         InternalEndpoint internalEndpoint = new InternalEndpoint(new QName JavaDoc(
325             "serv"), "endpoint", "compo", "0", null);
326         rootContext.bind("test-link", internalEndpoint);
327         MockContext context = (MockContext) servicesContext
328             .createSubcontext("test");
329         MockLinkRef linkRef = new MockLinkRef("test-link");
330         linkRef.setClassName(InternalEndpoint.class.getName());
331         context.bind("inter1", linkRef);
332         AbstractEndpoint[] endpoints = registry
333             .getInternalEndpointsForService(new QName JavaDoc("test"));
334         assertEquals(endpoints[0], internalEndpoint);
335     }
336
337     public void testRegisterConnectionExceptionNull() {
338         try {
339             registry.registerConnection(null);
340             fail();
341         } catch (Exception JavaDoc e) {
342             // Do nothing
343
}
344     }
345
346     public void testRegisterConnectionWithInterfaces() throws RegistryException {
347         LinkedEndpoint linkedEndpoint = new LinkedEndpoint(new QName JavaDoc("inter"),
348             new QName JavaDoc("toserv"), "endpoint", null);
349         InternalEndpoint internalEndpoint = new InternalEndpoint(new QName JavaDoc(
350             "toserv"), "endpoint", "compo", "0", null);
351         endpointsContext.getBindings().put("endpoint", internalEndpoint);
352         registry.registerConnection(linkedEndpoint);
353         assertEquals(interfacesContext.getBindings().size(), 1);
354     }
355
356     public void testRegisterConnectionWithoutInterface()
357         throws RegistryException {
358         LinkedEndpoint linkedEndpoint = new LinkedEndpoint(
359             new QName JavaDoc("service"), "endpoint", new QName JavaDoc("toservice"),
360             "toendpoint", null);
361         registry.registerInternalEndpoint(new InternalEndpoint(new QName JavaDoc(
362             "toservice"), "toendpoint", "compo", "0", null));
363         registry.registerConnection(linkedEndpoint);
364         assertNotNull(endpointsContext.getBindings().get("endpoint"));
365     }
366
367     @SuppressWarnings JavaDoc("unchecked")
368     public void testRegisterExternalEndpoint() throws JBIException {
369         ExternalEndpoint externalEndpoint = new ExternalEndpoint(
370             new ConsumerEndpoint("compo", "0"), "compo", "0");
371         externalEndpoint.setServiceName(new QName JavaDoc("test"));
372         registry.registerExternalEndpoint(externalEndpoint);
373         // Check if the endpointcontext
374
AbstractEndpoint endpoint = (AbstractEndpoint) endpointsContext
375             .getBindings().values().iterator().next();
376         assertEquals(externalEndpoint, endpoint);
377         // Check if the newendpointcontext
378
LinkRef JavaDoc linkRef = (LinkRef JavaDoc) newEndpointContext.getBindings().values()
379             .iterator().next();
380         assertNotNull(linkRef);
381     }
382
383     /**
384      * test registration failure of an endpoint already bound
385      * (by another component or container)
386      * @throws JBIException
387      */

388     public void testRegisterExternalEndpointException() {
389         ExternalEndpoint externalEndpoint = new ExternalEndpoint(
390             new InternalEndpoint(new QName JavaDoc("test"), "endpoint", "compo", "0",
391                 null), "compo", "0");
392         endpointsContext.getBindings().put("endpoint", externalEndpoint);
393         
394         ExternalEndpoint externalEndpoint2 = new ExternalEndpoint(
395             new InternalEndpoint(new QName JavaDoc("test"), "endpoint", "compo", "0",
396                 null), "compo", "1");
397         
398         try {
399             registry.registerExternalEndpoint(externalEndpoint2);
400             fail();
401         } catch (RegistryException e) {
402         }
403     }
404
405     public void testRegisterExternalEndpointExceptionNull() {
406         try {
407             registry.registerExternalEndpoint(null);
408             fail();
409         } catch (Exception JavaDoc e) {
410             // Do nothing
411
}
412     }
413
414     /**
415      * Check if the endpoint is registered in all the contexts
416      *
417      * @throws JBIException
418      * @throws NamingException
419      */

420     @SuppressWarnings JavaDoc("unchecked")
421     public void testRegisterInternalEndpoint() throws JBIException,
422         NamingException JavaDoc {
423         AbstractEndpoint endpoint = new InternalEndpoint(new QName JavaDoc("test"),
424             "endpoint", "axis2bc", "0", null);
425         registry.registerInternalEndpoint(endpoint);
426         // Check if the endpointcontext
427
AbstractEndpoint ep = (AbstractEndpoint) endpointsContext.getBindings()
428             .values().iterator().next();
429         assertEquals(endpoint, ep);
430         // Check if the newendpointcontext
431
LinkRef JavaDoc linkRef = (LinkRef JavaDoc) newEndpointContext.getBindings().values()
432             .iterator().next();
433         assertNotNull(linkRef);
434     }
435
436     /**
437      * test registration failure of an endpoint already bound
438      * (by another component or container)
439      * @throws JBIException
440      */

441     public void testRegisterInternalEndpointAlreadyRegistered() {
442         InternalEndpoint internalEndpoint = new InternalEndpoint(new QName JavaDoc(
443             "serv"), "endpoint", "compo", "0", null);
444         endpointsContext.getBindings().put("endpoint", internalEndpoint);
445
446         InternalEndpoint internalEndpoint2 = new InternalEndpoint(new QName JavaDoc(
447         "serv"), "endpoint", "compo", "1", null);
448
449         try {
450             registry.registerInternalEndpoint(internalEndpoint2);
451             fail();
452         } catch (Exception JavaDoc e) {
453
454         }
455     }
456
457     public void testRegisterInternalEndpointExceptionNull() {
458         try {
459             registry.registerInternalEndpoint(null);
460             fail();
461         } catch (Exception JavaDoc e) {
462             // Do nothing
463
}
464     }
465
466     @SuppressWarnings JavaDoc("unchecked")
467     public void testRegisterInternalEndpointWithLinkedEndpoint()
468         throws JBIException, NamingException JavaDoc {
469         AbstractEndpoint endpoint = new LinkedEndpoint(new QName JavaDoc("service1"),
470             "endpoint1", new QName JavaDoc("service2"), "endpoint2", null);
471         registry.registerInternalEndpoint(endpoint);
472         // Check if the endpointcontext
473
AbstractEndpoint ep = (AbstractEndpoint) endpointsContext.getBindings()
474             .values().iterator().next();
475         assertEquals(endpoint, ep);
476         // Check if the newendpointcontext
477
LinkRef JavaDoc linkRef = (LinkRef JavaDoc) newEndpointContext.getBindings().values()
478             .iterator().next();
479         assertNotNull(linkRef);
480     }
481
482     public void testRetreiveNewEndpoints() throws JBIException, NamingException JavaDoc {
483         AbstractEndpoint endpoint = new InternalEndpoint(new QName JavaDoc("test"),
484             "endpoint", "axis2bc", "0", null);
485         testRegisterInternalEndpoint();
486         rootContext.bind("/endpoints/endpoint", endpoint);
487         List JavaDoc<AbstractEndpoint> endpoints = registry.retrieveNewEndpoints();
488         assertEquals(((AbstractEndpoint) endpoints.get(0)).containerName, "0");
489     }
490
491     public void testUnRegisterConnectionWithoutInterface()
492         throws RegistryException {
493         LinkedEndpoint linkedEndpoint = new LinkedEndpoint(
494             new QName JavaDoc("service"), "endpoint", new QName JavaDoc("toservice"),
495             "toendpoint", null);
496         registry.registerInternalEndpoint(new InternalEndpoint(new QName JavaDoc(
497             "toservice"), "toendpoint", "compo", "0", null));
498         registry.registerConnection(linkedEndpoint);
499         assertNotNull(endpointsContext.getBindings().get("endpoint"));
500         registry.deregisterConnection(linkedEndpoint);
501         assertNull(endpointsContext.getBindings().get("endpoint"));
502     }
503
504     public void testValidateEndpoint() throws JBIException {
505         InternalEndpoint endpoint = new InternalEndpoint(new QName JavaDoc("service"),
506             "endpoint", "compo", "0", null);
507         endpoint.setInterfaces(new QName JavaDoc[] {new QName JavaDoc("inter")});
508         endpoint.setDescription("<xml><test />");
509         registry.validateEndpoint(endpoint);
510         assertEquals(interfacesContext.getBindings().size(), 1);
511     }
512
513     public void testValidateEndpointExceptionNull() {
514         try {
515             registry.validateEndpoint(null);
516             fail();
517         } catch (Exception JavaDoc e) {
518             // Do nothing
519
}
520     }
521
522     public void testValidateEndpointWithInterfaces() throws JBIException {
523         InternalEndpoint endpoint = new InternalEndpoint(new QName JavaDoc("service"),
524             "endpoint", "compo", "0", null);
525         endpoint.setInterfaces(new QName JavaDoc[] {new QName JavaDoc("inter")});
526         endpoint.setDescription("<xml><test />");
527         interfacesContext.getBindings().put("inter", new MockContext());
528         registry.validateEndpoint(endpoint);
529         assertEquals(interfacesContext.getBindings().size(), 1);
530     }
531
532     public void testRetrieveNewEndpointsException() throws NamingException JavaDoc {
533         LoggingUtil loggingUtil = EasyMock.createNiceMock(LoggingUtil.class);
534         InitialContext JavaDoc rootContext = EasyMock.createMock(InitialContext JavaDoc.class);
535         NamingException JavaDoc namingException = new NamingException JavaDoc();
536
537         loggingUtil.start();
538         EasyMock.expect(rootContext.listBindings("new-endpoints")).andThrow(
539             namingException);
540
541         EasyMock.replay(loggingUtil);
542         EasyMock.replay(rootContext);
543
544         registry.log = loggingUtil;
545         registry.rootContext = rootContext;
546
547         try {
548             registry.retrieveNewEndpoints();
549             fail();
550         } catch (RegistryException e) {
551             // do nothing
552
}
553     }
554
555     public void testStart() throws SecurityException JavaDoc, NoSuchMethodException JavaDoc,
556         IllegalLifeCycleException {
557         JNDIRegistry registry = EasyMock.createMock(JNDIRegistry.class,
558             new Method JavaDoc[] {JNDIRegistry.class.getDeclaredMethod("initContexts",
559                 new Class JavaDoc[0])});
560         Logger logger = EasyMock.createMock(Logger.class);
561
562         registry.logger = logger;
563
564         registry.start();
565
566         assertNotNull(registry.log);
567     }
568
569     public void testDeregisterConnectionWithInterfacesException()
570         throws NamingException JavaDoc {
571         LoggingUtil loggingUtil = EasyMock.createNiceMock(LoggingUtil.class);
572         InitialContext JavaDoc rootContext = EasyMock.createMock(InitialContext JavaDoc.class);
573         NamingException JavaDoc namingException = new NamingException JavaDoc();
574         Context JavaDoc interContext = EasyMock.createMock(Context JavaDoc.class);
575
576         EasyMock.expect(rootContext.list("interfaces")).andReturn(
577             new NamingEnumerationImpl<NameClassPair JavaDoc>(
578                 new NameClassPair JavaDoc[] {new NameClassPair JavaDoc("inter", "test")}));
579         EasyMock.expect(rootContext.list("new-endpoints")).andReturn(
580             new NamingEnumerationImpl<NameClassPair JavaDoc>(
581                 new NameClassPair JavaDoc[] {new NameClassPair JavaDoc("toep", "ep")}));
582         EasyMock.expect(
583             interContext.lookup(NamingHelper.qNameToName(new QName JavaDoc("inter"))))
584             .andThrow(namingException);
585
586         EasyMock.replay(loggingUtil);
587         EasyMock.replay(rootContext);
588         EasyMock.replay(interContext);
589
590         registry.log = loggingUtil;
591         registry.rootContext = rootContext;
592         registry.interfacesContext = interContext;
593
594         LinkedEndpoint linkedEndpoint = new LinkedEndpoint(new QName JavaDoc("inter"),
595             new QName JavaDoc("toserv"), "toep", null);
596
597         try {
598             registry.deregisterConnection(linkedEndpoint);
599             fail();
600         } catch (RegistryException e) {
601             // do nothing
602
}
603     }
604
605     public void testDeregisterConnectionWithServiceEndpointNotBound()
606         throws NamingException JavaDoc {
607         LoggingUtil loggingUtil = EasyMock.createMock(LoggingUtil.class);
608         InitialContext JavaDoc rootContext = EasyMock.createMock(InitialContext JavaDoc.class);
609
610         loggingUtil.start();
611         EasyMock.expect(rootContext.list("endpoints")).andReturn(
612             new NamingEnumerationImpl<NameClassPair JavaDoc>(new NameClassPair JavaDoc[0]));
613         loggingUtil
614             .error("The provider endpoint ep is not registered in the endpoints");
615
616         EasyMock.replay(loggingUtil);
617         EasyMock.replay(rootContext);
618
619         registry.log = loggingUtil;
620         registry.rootContext = rootContext;
621
622         LinkedEndpoint linkedEndpoint = new LinkedEndpoint(new QName JavaDoc("serv"),
623             "ep", new QName JavaDoc("toserv"), "toep", null);
624
625         try {
626             registry.deregisterConnection(linkedEndpoint);
627             fail();
628         } catch (RegistryException e) {
629             // do nothing
630
}
631     }
632
633     public void testDeregisterConnectionWithServiceException()
634         throws NamingException JavaDoc, SecurityException JavaDoc, NoSuchMethodException JavaDoc {
635         JNDIRegistry registry = EasyMock.createMock(JNDIRegistry.class,
636             new Method JavaDoc[] {JNDIRegistry.class.getDeclaredMethod(
637                 "retrieveServiceContext", new Class JavaDoc[] {Name JavaDoc.class})});
638         LoggingUtil loggingUtil = EasyMock.createNiceMock(LoggingUtil.class);
639         InitialContext JavaDoc rootContext = EasyMock.createMock(InitialContext JavaDoc.class);
640         NamingException JavaDoc namingException = new NamingException JavaDoc();
641
642         EasyMock.expect(rootContext.list("endpoints")).andReturn(
643             new NamingEnumerationImpl<NameClassPair JavaDoc>(
644                 new NameClassPair JavaDoc[] {new NameClassPair JavaDoc("ep", "foo")}));
645         EasyMock.expect(
646             registry.retrieveServiceContext(NamingHelper.qNameToName(new QName JavaDoc(
647                 "serv")))).andThrow(namingException);
648
649         EasyMock.replay(registry);
650         EasyMock.replay(loggingUtil);
651         EasyMock.replay(rootContext);
652
653         registry.log = loggingUtil;
654         registry.rootContext = rootContext;
655
656         LinkedEndpoint linkedEndpoint = new LinkedEndpoint(new QName JavaDoc("serv"),
657             "ep", new QName JavaDoc("toserv"), "toep", null);
658
659         try {
660             registry.deregisterConnection(linkedEndpoint);
661             fail();
662         } catch (RegistryException e) {
663             // do nothing
664
}
665     }
666 }
667
Popular Tags