1 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 ; 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 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 endpointServiceImp.log = new LoggingUtil(new MockLogger()); 59 } 60 61 public void testActivateEndpoint() throws JBIException { 62 endpointServiceImp.activateEndpoint(new QName ("service"), "endpoint", 63 new ConsumerEndpoint("compo", "0")); 64 assertTrue(registry.isRegisterInternalEndpoint()); 65 } 66 67 public void testActivateEndpointAddressNull() { 68 try { 69 endpointServiceImp.activateEndpoint(new QName ("serv"), "endpoint", 70 null); 71 fail(); 72 } catch (Exception e) { 73 } 75 } 76 77 public void testActivateEndpointEndpointNull() { 78 try { 79 endpointServiceImp.activateEndpoint(new QName ("serv"), null, null); 80 fail(); 81 } catch (Exception e) { 82 } 84 } 85 86 public void testActivateEndpointServiceNull() { 87 try { 88 endpointServiceImp.activateEndpoint(null, null, null); 89 fail(); 90 } catch (Exception e) { 91 } 93 } 94 95 public void testCreateConnection() throws JBIException { 96 endpointServiceImp.createConnection(new QName ("serv"), "ep", new QName ( 97 "toserv"), "toep"); 98 assertTrue(registry.isRegisterConnection()); 99 } 100 101 public void testCreateConnectionEndpointNull() { 102 try { 103 endpointServiceImp.createConnection(new QName ("serv"), null, null, 104 null); 105 fail(); 106 } catch (Exception e) { 107 } 109 } 110 111 public void testCreateConnectionInter() throws JBIException { 112 endpointServiceImp.createConnection(new QName ("inter"), new QName ( 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 e) { 122 } 124 } 125 126 public void testCreateConnectionInterToEndpointNull() { 127 try { 128 endpointServiceImp.createConnection(new QName ("inter"), new QName ( 129 "toserv"), null); 130 fail(); 131 } catch (Exception e) { 132 } 134 } 135 136 public void testCreateConnectionInterToServNull() { 137 try { 138 endpointServiceImp.createConnection(new QName ("inter"), null, null); 139 fail(); 140 } catch (Exception e) { 141 } 143 } 144 145 public void testCreateConnectionServNull() { 146 try { 147 endpointServiceImp.createConnection(null, null, null, null); 148 fail(); 149 } catch (Exception e) { 150 } 152 } 153 154 public void testCreateConnectionToEndpointNull() { 155 try { 156 endpointServiceImp.createConnection(new QName ("serv"), "ep", 157 new QName ("toserv"), null); 158 fail(); 159 } catch (Exception e) { 160 } 162 } 163 164 public void testCreateConnectionToServNull() { 165 try { 166 endpointServiceImp.createConnection(new QName ("serv"), "ep", null, 167 null); 168 fail(); 169 } catch (Exception e) { 170 } 172 } 173 174 public void testDeactivateEndpoint() throws JBIException { 175 InternalEndpoint internalEndpoint = new InternalEndpoint(new QName ( 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 e) { 186 } 188 } 189 190 public void testDeleteConnection() throws JBIException { 191 endpointServiceImp.deleteConnection(new QName ("serv"), "ep", new QName ( 192 "toserv"), "toep"); 193 assertTrue(registry.isDeregisterConnection()); 194 } 195 196 public void testDeleteConnectionEndpointNull() { 197 try { 198 endpointServiceImp.deleteConnection(new QName ("serv"), null, null, 199 null); 200 fail(); 201 } catch (Exception e) { 202 } 204 } 205 206 public void testDeleteConnectionInter() throws JBIException { 207 endpointServiceImp.deleteConnection(new QName ("inter"), new QName ( 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 e) { 217 } 219 } 220 221 public void testDeleteConnectionInterToEndpointNull() { 222 try { 223 endpointServiceImp.deleteConnection(new QName ("inter"), new QName ( 224 "toserv"), null); 225 fail(); 226 } catch (Exception e) { 227 } 229 } 230 231 public void testDeleteConnectionInterToServNull() { 232 try { 233 endpointServiceImp.deleteConnection(new QName ("inter"), null, null); 234 fail(); 235 } catch (Exception e) { 236 } 238 } 239 240 public void testDeleteConnectionServNull() { 241 try { 242 endpointServiceImp.deleteConnection(null, null, null, null); 243 fail(); 244 } catch (Exception e) { 245 } 247 } 248 249 public void testDeleteConnectionToEndpointNull() { 250 try { 251 endpointServiceImp.deleteConnection(new QName ("serv"), "ep", 252 new QName ("toserv"), null); 253 fail(); 254 } catch (Exception e) { 255 } 257 } 258 259 public void testDeleteConnectionToServNull() { 260 try { 261 endpointServiceImp.deleteConnection(new QName ("serv"), "ep", null, 262 null); 263 fail(); 264 } catch (Exception e) { 265 } 267 } 268 269 public void testDeregisterExternaIEndpoint() throws JBIException { 270 InternalEndpoint internalEndpoint = new InternalEndpoint(new QName ( 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 e) { 281 } 283 } 284 285 public void testGetEndpoint() throws Exception { 286 endpointServiceImp.getEndpoint(new QName ("service"), "name"); 287 assertTrue(registry.isGetInternalEndpoint()); 288 } 289 290 public void testGetEndpointDescriptorForEndpoint() throws JBIException { 291 InternalEndpoint internalEndpoint = new InternalEndpoint(new QName ( 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 e) { 301 } 303 } 304 305 public void testGetEndpointEndpointNull() { 306 try { 307 endpointServiceImp.getEndpoint(new QName ("serv"), null); 308 fail(); 309 } catch (Exception e) { 310 } 312 } 313 314 public void testGetEndpointServiceNull() { 315 try { 316 endpointServiceImp.getEndpoint(null, null); 317 fail(); 318 } catch (Exception e) { 319 } 321 } 322 323 public void testGetExternalEndpointsForInterface() throws Exception { 324 endpointServiceImp 325 .getExternalEndpointsForInterface(new QName ("service")); 326 assertTrue(registry.isGetExternalEndpointsForInterface()); 327 } 328 329 public void testGetExternalEndpointsForInterfaceNull() { 330 try { 331 endpointServiceImp.getExternalEndpointsForInterface(null); 332 fail(); 333 } catch (Exception e) { 334 } 336 } 337 338 public void testGetExternalEndpointsForService() throws Exception { 339 endpointServiceImp.getExternalEndpointsForService(new QName ("service")); 340 assertTrue(registry.isGetExternalEndpointsForService()); 341 } 342 343 public void testGetExternalEndpointsForServiceNull() { 344 try { 345 endpointServiceImp.getExternalEndpointsForService(null); 346 fail(); 347 } catch (Exception e) { 348 } 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 ( 364 "http://127.0.0.1:8080/axis/Helloworld.jws", "HelloworldService"), 365 "endpoint", "compo", "0", endpointServiceImp); 366 367 QName [] 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 ( 388 "HelloworldService"), "endpoint", "compo", "0", endpointServiceImp); 389 390 QName [] 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 e) { 402 } 404 } 405 406 public void testGetInternalEndpointsForInterface() { 407 ServiceEndpoint[] endpoints = endpointServiceImp 408 .getInternalEndpointsForInterface(new QName ("inter")); 409 assertEquals(1, endpoints.length); 410 } 411 412 public void testGetInternalEndpointsForInterfaceNotRegistered() { 413 ServiceEndpoint[] endpoints = endpointServiceImp 414 .getInternalEndpointsForInterface(new QName ("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 e) { 424 } 426 } 427 428 public void testGetInternalEndpointsForService() { 429 ServiceEndpoint[] endpoints = endpointServiceImp 430 .getInternalEndpointsForService(new QName ("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 e) { 441 } 443 } 444 445 public void testIsExchangeWithProviderOkayForComponentNull() { 446 try { 447 endpointServiceImp.isExchangeWithProviderOkayForComponent(null, 448 null); 449 fail(); 450 } catch (Exception e) { 451 } 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 ( 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 ( 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 e) { 502 } 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 |