KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.jbi.JBIException;
25 import javax.jbi.servicedesc.ServiceEndpoint;
26 import javax.xml.namespace.QName JavaDoc;
27
28 import junit.framework.TestCase;
29
30 import org.easymock.classextension.EasyMock;
31 import org.objectweb.fractal.api.control.IllegalLifeCycleException;
32 import org.objectweb.petals.PetalsException;
33 import org.objectweb.petals.jbi.management.service.mock.MockDistributedJMXServer;
34 import org.objectweb.petals.jbi.management.service.mock.MockRegistry;
35 import org.objectweb.petals.jbi.messaging.mock.MockLogger;
36 import org.objectweb.petals.jbi.registry.ConsumerEndpoint;
37 import org.objectweb.petals.jbi.registry.ExternalEndpoint;
38 import org.objectweb.petals.jbi.registry.InternalEndpoint;
39 import org.objectweb.petals.kernel.admin.DistributedJMXServerFactoryImpl;
40 import org.objectweb.petals.util.LoggingUtil;
41
42 /**
43  * Test of the EndpointServiceImpl
44  *
45  * @author ddesjardins - eBMWebsourcing
46  */

47 public class EndpointServiceImplTest extends TestCase {
48
49     private EndpointServiceImpl endpointServiceImp;
50
51     private MockRegistry registry;
52
53     public void setUp() {
54         endpointServiceImp = new EndpointServiceImpl();
55         registry = new MockRegistry();
56         endpointServiceImp.registry = registry;
57         // Attach the log
58
endpointServiceImp.log = new LoggingUtil(new MockLogger());
59     }
60
61     public void testActivateEndpoint() throws JBIException {
62         endpointServiceImp.activateEndpoint(new QName JavaDoc("service"), "endpoint",
63             new ConsumerEndpoint("compo", "0"));
64         assertTrue(registry.isRegisterInternalEndpoint());
65     }
66
67     public void testActivateEndpointAddressNull() {
68         try {
69             endpointServiceImp.activateEndpoint(new QName JavaDoc("serv"), "endpoint",
70                 null);
71             fail();
72         } catch (Exception JavaDoc e) {
73             // Do nothing
74
}
75     }
76
77     public void testActivateEndpointEndpointNull() {
78         try {
79             endpointServiceImp.activateEndpoint(new QName JavaDoc("serv"), null, null);
80             fail();
81         } catch (Exception JavaDoc e) {
82             // Do nothing
83
}
84     }
85
86     public void testActivateEndpointServiceNull() {
87         try {
88             endpointServiceImp.activateEndpoint(null, null, null);
89             fail();
90         } catch (Exception JavaDoc e) {
91             // Do nothing
92
}
93     }
94
95     public void testCreateConnection() throws JBIException {
96         endpointServiceImp.createConnection(new QName JavaDoc("serv"), "ep", new QName JavaDoc(
97             "toserv"), "toep");
98         assertTrue(registry.isRegisterConnection());
99     }
100
101     public void testCreateConnectionEndpointNull() {
102         try {
103             endpointServiceImp.createConnection(new QName JavaDoc("serv"), null, null,
104                 null);
105             fail();
106         } catch (Exception JavaDoc e) {
107             // do nothing
108
}
109     }
110
111     public void testCreateConnectionInter() throws JBIException {
112         endpointServiceImp.createConnection(new QName JavaDoc("inter"), new QName JavaDoc(
113             "toserv"), "toendpoint");
114         assertTrue(registry.isRegisterConnection());
115     }
116
117     public void testCreateConnectionInterInterNull() {
118         try {
119             endpointServiceImp.createConnection(null, null, null);
120             fail();
121         } catch (Exception JavaDoc e) {
122             // Do nothing
123
}
124     }
125
126     public void testCreateConnectionInterToEndpointNull() {
127         try {
128             endpointServiceImp.createConnection(new QName JavaDoc("inter"), new QName JavaDoc(
129                 "toserv"), null);
130             fail();
131         } catch (Exception JavaDoc e) {
132             // Do nothing
133
}
134     }
135
136     public void testCreateConnectionInterToServNull() {
137         try {
138             endpointServiceImp.createConnection(new QName JavaDoc("inter"), null, null);
139             fail();
140         } catch (Exception JavaDoc e) {
141             // Do nothing
142
}
143     }
144
145     public void testCreateConnectionServNull() {
146         try {
147             endpointServiceImp.createConnection(null, null, null, null);
148             fail();
149         } catch (Exception JavaDoc e) {
150             // do nothing
151
}
152     }
153
154     public void testCreateConnectionToEndpointNull() {
155         try {
156             endpointServiceImp.createConnection(new QName JavaDoc("serv"), "ep",
157                 new QName JavaDoc("toserv"), null);
158             fail();
159         } catch (Exception JavaDoc e) {
160             // do nothing
161
}
162     }
163
164     public void testCreateConnectionToServNull() {
165         try {
166             endpointServiceImp.createConnection(new QName JavaDoc("serv"), "ep", null,
167                 null);
168             fail();
169         } catch (Exception JavaDoc e) {
170             // do nothing
171
}
172     }
173
174     public void testDeactivateEndpoint() throws JBIException {
175         InternalEndpoint internalEndpoint = new InternalEndpoint(new QName JavaDoc(
176             "service"), "endpoint", "compo", "0", null);
177         endpointServiceImp.deactivateEndpoint(internalEndpoint);
178         assertTrue(registry.isDeregisterInternalEndpoint());
179     }
180
181     public void testDeactivateEndpointNullException() {
182         try {
183             endpointServiceImp.deactivateEndpoint(null);
184             fail();
185         } catch (Exception JavaDoc e) {
186             // do nothing
187
}
188     }
189
190     public void testDeleteConnection() throws JBIException {
191         endpointServiceImp.deleteConnection(new QName JavaDoc("serv"), "ep", new QName JavaDoc(
192             "toserv"), "toep");
193         assertTrue(registry.isDeregisterConnection());
194     }
195
196     public void testDeleteConnectionEndpointNull() {
197         try {
198             endpointServiceImp.deleteConnection(new QName JavaDoc("serv"), null, null,
199                 null);
200             fail();
201         } catch (Exception JavaDoc e) {
202             // do nothing
203
}
204     }
205
206     public void testDeleteConnectionInter() throws JBIException {
207         endpointServiceImp.deleteConnection(new QName JavaDoc("inter"), new QName JavaDoc(
208             "toserv"), "toep");
209         assertTrue(registry.isDeregisterConnection());
210     }
211
212     public void testDeleteConnectionInterInterNull() {
213         try {
214             endpointServiceImp.deleteConnection(null, null, null);
215             fail();
216         } catch (Exception JavaDoc e) {
217             // do nothing
218
}
219     }
220
221     public void testDeleteConnectionInterToEndpointNull() {
222         try {
223             endpointServiceImp.deleteConnection(new QName JavaDoc("inter"), new QName JavaDoc(
224                 "toserv"), null);
225             fail();
226         } catch (Exception JavaDoc e) {
227             // do nothing
228
}
229     }
230
231     public void testDeleteConnectionInterToServNull() {
232         try {
233             endpointServiceImp.deleteConnection(new QName JavaDoc("inter"), null, null);
234             fail();
235         } catch (Exception JavaDoc e) {
236             // do nothing
237
}
238     }
239
240     public void testDeleteConnectionServNull() {
241         try {
242             endpointServiceImp.deleteConnection(null, null, null, null);
243             fail();
244         } catch (Exception JavaDoc e) {
245             // do nothing
246
}
247     }
248
249     public void testDeleteConnectionToEndpointNull() {
250         try {
251             endpointServiceImp.deleteConnection(new QName JavaDoc("serv"), "ep",
252                 new QName JavaDoc("toserv"), null);
253             fail();
254         } catch (Exception JavaDoc e) {
255             // do nothing
256
}
257     }
258
259     public void testDeleteConnectionToServNull() {
260         try {
261             endpointServiceImp.deleteConnection(new QName JavaDoc("serv"), "ep", null,
262                 null);
263             fail();
264         } catch (Exception JavaDoc e) {
265             // do nothing
266
}
267     }
268
269     public void testDeregisterExternaIEndpoint() throws JBIException {
270         InternalEndpoint internalEndpoint = new InternalEndpoint(new QName JavaDoc(
271             "service"), "endpoint", "compo", "0", null);
272         endpointServiceImp.deregisterExternalEndpoint(internalEndpoint);
273         assertTrue(registry.isDeregisterExternalEndpoint());
274     }
275
276     public void testDeregisterExternalEndpointNullException() {
277         try {
278             endpointServiceImp.deregisterExternalEndpoint(null);
279             fail();
280         } catch (Exception JavaDoc e) {
281             // do nothing
282
}
283     }
284
285     public void testGetEndpoint() throws Exception JavaDoc {
286         endpointServiceImp.getEndpoint(new QName JavaDoc("service"), "name");
287         assertTrue(registry.isGetInternalEndpoint());
288     }
289
290     public void testGetEndpointDescriptorForEndpoint() throws JBIException {
291         InternalEndpoint internalEndpoint = new InternalEndpoint(new QName JavaDoc(
292             "serv"), "endpoint", "compo", "0", endpointServiceImp);
293         endpointServiceImp.getEndpointDescriptorForEndpoint(internalEndpoint);
294     }
295
296     public void testGetEndpointDescriptorForEndpointNull() {
297         try {
298             endpointServiceImp.getEndpointDescriptorForEndpoint(null);
299             fail();
300         } catch (Exception JavaDoc e) {
301             // do nothing
302
}
303     }
304
305     public void testGetEndpointEndpointNull() {
306         try {
307             endpointServiceImp.getEndpoint(new QName JavaDoc("serv"), null);
308             fail();
309         } catch (Exception JavaDoc e) {
310             // do nothing
311
}
312     }
313
314     public void testGetEndpointServiceNull() {
315         try {
316             endpointServiceImp.getEndpoint(null, null);
317             fail();
318         } catch (Exception JavaDoc e) {
319             // do nothing
320
}
321     }
322
323     public void testGetExternalEndpointsForInterface() throws Exception JavaDoc {
324         endpointServiceImp
325             .getExternalEndpointsForInterface(new QName JavaDoc("service"));
326         assertTrue(registry.isGetExternalEndpointsForInterface());
327     }
328
329     public void testGetExternalEndpointsForInterfaceNull() {
330         try {
331             endpointServiceImp.getExternalEndpointsForInterface(null);
332             fail();
333         } catch (Exception JavaDoc e) {
334             // do nothing
335
}
336     }
337
338     public void testGetExternalEndpointsForService() throws Exception JavaDoc {
339         endpointServiceImp.getExternalEndpointsForService(new QName JavaDoc("service"));
340         assertTrue(registry.isGetExternalEndpointsForService());
341     }
342
343     public void testGetExternalEndpointsForServiceNull() {
344         try {
345             endpointServiceImp.getExternalEndpointsForService(null);
346             fail();
347         } catch (Exception JavaDoc e) {
348             // do nothing
349
}
350     }
351
352     public void testGetInterfacesForEndpoint() throws PetalsException {
353         DistributedJMXServerFactoryImpl distributedJMXServerFactoryImpl = EasyMock
354             .createMock(DistributedJMXServerFactoryImpl.class);
355         MockDistributedJMXServer distributedJMXServer = new MockDistributedJMXServer(
356             null);
357         EasyMock.expect(
358             distributedJMXServerFactoryImpl.createDistributedJMXServer("0"))
359             .andReturn(distributedJMXServer).anyTimes();
360         EasyMock.replay(distributedJMXServerFactoryImpl);
361         endpointServiceImp.serverManager = distributedJMXServerFactoryImpl;
362
363         InternalEndpoint internalEndpoint = new InternalEndpoint(new QName JavaDoc(
364             "http://127.0.0.1:8080/axis/Helloworld.jws", "HelloworldService"),
365             "endpoint", "compo", "0", endpointServiceImp);
366
367         QName JavaDoc[] interfs = endpointServiceImp
368             .getInterfacesForEndpoint(internalEndpoint);
369         assertTrue(distributedJMXServer.isGetAdminServiceMBeanName());
370         assertTrue(distributedJMXServer.isInvoke());
371         assertTrue(registry.isValidateEndpoint());
372         assertEquals(1, interfs.length);
373     }
374
375     public void testGetInterfacesForEndpointBadServiceName()
376         throws PetalsException {
377         DistributedJMXServerFactoryImpl distributedJMXServerFactoryImpl = EasyMock
378             .createMock(DistributedJMXServerFactoryImpl.class);
379         MockDistributedJMXServer distributedJMXServer = new MockDistributedJMXServer(
380             null);
381         EasyMock.expect(
382             distributedJMXServerFactoryImpl.createDistributedJMXServer("0"))
383             .andReturn(distributedJMXServer).anyTimes();
384         EasyMock.replay(distributedJMXServerFactoryImpl);
385         endpointServiceImp.serverManager = distributedJMXServerFactoryImpl;
386
387         InternalEndpoint internalEndpoint = new InternalEndpoint(new QName JavaDoc(
388             "HelloworldService"), "endpoint", "compo", "0", endpointServiceImp);
389
390         QName JavaDoc[] interfs = endpointServiceImp
391             .getInterfacesForEndpoint(internalEndpoint);
392         assertTrue(distributedJMXServer.isGetAdminServiceMBeanName());
393         assertTrue(distributedJMXServer.isInvoke());
394         assertEquals(0, interfs.length);
395     }
396
397     public void testGetInterfacesForEndpointNull() {
398         try {
399             endpointServiceImp.getInterfacesForEndpoint(null);
400             fail();
401         } catch (Exception JavaDoc e) {
402             // do nothing
403
}
404     }
405
406     public void testGetInternalEndpointsForInterface() {
407         ServiceEndpoint[] endpoints = endpointServiceImp
408             .getInternalEndpointsForInterface(new QName JavaDoc("inter"));
409         assertEquals(1, endpoints.length);
410     }
411
412     public void testGetInternalEndpointsForInterfaceNotRegistered() {
413         ServiceEndpoint[] endpoints = endpointServiceImp
414             .getInternalEndpointsForInterface(new QName JavaDoc("inter1"));
415         assertEquals(0, endpoints.length);
416         assertTrue(registry.isGetInternalEndpointsForInterface());
417     }
418
419     public void testGetInternalEndpointsForServiceNull() {
420         try {
421             endpointServiceImp.getInternalEndpointsForService(null);
422             fail();
423         } catch (Exception JavaDoc e) {
424             // do nothing
425
}
426     }
427
428     public void testGetInternalEndpointsForService() {
429         ServiceEndpoint[] endpoints = endpointServiceImp
430             .getInternalEndpointsForService(new QName JavaDoc("serv"));
431         assertEquals(1, endpoints.length);
432         assertTrue(registry.isGetInternalEndpointsForService());
433     }
434
435     public void testIsExchangeWithConsumerOkayForComponentNull() {
436         try {
437             endpointServiceImp.isExchangeWithConsumerOkayForComponent(null,
438                 null);
439             fail();
440         } catch (Exception JavaDoc e) {
441             // do nothing
442
}
443     }
444
445     public void testIsExchangeWithProviderOkayForComponentNull() {
446         try {
447             endpointServiceImp.isExchangeWithProviderOkayForComponent(null,
448                 null);
449             fail();
450         } catch (Exception JavaDoc e) {
451             // do nothing
452
}
453     }
454
455     public void testIsExchangeWithConsumerOkayForComponent()
456         throws PetalsException {
457         DistributedJMXServerFactoryImpl distributedJMXServerFactoryImpl = EasyMock
458             .createMock(DistributedJMXServerFactoryImpl.class);
459         MockDistributedJMXServer distributedJMXServer = new MockDistributedJMXServer(
460             null);
461         EasyMock.expect(
462             distributedJMXServerFactoryImpl.createDistributedJMXServer("0"))
463             .andReturn(distributedJMXServer).anyTimes();
464         EasyMock.replay(distributedJMXServerFactoryImpl);
465         endpointServiceImp.serverManager = distributedJMXServerFactoryImpl;
466
467         InternalEndpoint internalEndpoint = new InternalEndpoint(new QName JavaDoc(
468             "serv"), "endpoint", "compo", "0", endpointServiceImp);
469         boolean test = endpointServiceImp
470             .isExchangeWithConsumerOkayForComponent(internalEndpoint, null);
471         assertTrue(distributedJMXServer.isGetAdminServiceMBeanName());
472         assertTrue(distributedJMXServer.isInvoke());
473         assertTrue(test);
474     }
475
476     public void testIsExchangeWithProviderOkayForComponent()
477         throws PetalsException {
478         DistributedJMXServerFactoryImpl distributedJMXServerFactoryImpl = EasyMock
479             .createMock(DistributedJMXServerFactoryImpl.class);
480         MockDistributedJMXServer distributedJMXServer = new MockDistributedJMXServer(
481             null);
482         EasyMock.expect(
483             distributedJMXServerFactoryImpl.createDistributedJMXServer("0"))
484             .andReturn(distributedJMXServer).anyTimes();
485         EasyMock.replay(distributedJMXServerFactoryImpl);
486         endpointServiceImp.serverManager = distributedJMXServerFactoryImpl;
487
488         InternalEndpoint internalEndpoint = new InternalEndpoint(new QName JavaDoc(
489             "serv"), "endpoint", "compo", "0", endpointServiceImp);
490         boolean test = endpointServiceImp
491             .isExchangeWithProviderOkayForComponent(internalEndpoint, null);
492         assertTrue(distributedJMXServer.isGetAdminServiceMBeanName());
493         assertTrue(distributedJMXServer.isInvoke());
494         assertTrue(test);
495     }
496
497     public void testRegisterExternalEndpointNull() {
498         try {
499             endpointServiceImp.registerExternalEndpoint(null);
500             fail();
501         } catch (Exception JavaDoc e) {
502             // do nothing
503
}
504     }
505
506     public void testRegisterExternalEndpoint() throws JBIException {
507         ExternalEndpoint externalEndpoint = new ExternalEndpoint(
508             new ConsumerEndpoint("compo", "0"), "compo", "0");
509         endpointServiceImp.registerExternalEndpoint(externalEndpoint);
510         assertTrue(registry.isRegisterExternalEndpoint());
511     }
512
513     public void testStop() throws IllegalLifeCycleException {
514         endpointServiceImp.stop();
515     }
516
517 }
518
Popular Tags