1 package test.crispy; 2 3 import java.util.Iterator; 4 import java.util.Properties; 5 6 import junit.framework.TestCase; 7 import net.sf.crispy.IServiceManager; 8 import net.sf.crispy.Interceptor; 9 import net.sf.crispy.Modifier; 10 import net.sf.crispy.Property; 11 import net.sf.crispy.filter.NamePatternInterceptorFilter; 12 import net.sf.crispy.filter.SimpleNameInterceptorFilter; 13 import net.sf.crispy.impl.HttpExecutor; 14 import net.sf.crispy.impl.RmiExecutor; 15 import net.sf.crispy.impl.ServiceManager; 16 import net.sf.crispy.impl.StaticBurlapProxy; 17 import net.sf.crispy.impl.StaticLocalObjectProxy; 18 import net.sf.crispy.interceptor.LogInterceptor; 19 import net.sf.crispy.interceptor.StopWatchInterceptor; 20 import test.crispy.concurrent.AsynchronousCallbackForTests; 21 import test.crispy.example.interceptor.WaitInterceptor; 22 import test.crispy.example.modify.EchoModifierAfter; 23 import test.crispy.example.modify.EchoModifierBefore; 24 import test.crispy.example.service.Calculator; 25 import test.crispy.example.service.CalculatorImpl; 26 import test.crispy.example.service.Echo; 27 import test.crispy.example.service.EchoImpl; 28 import test.crispy.example.service.MyService; 29 30 public class ServiceManagerTest extends TestCase { 31 32 33 public void testRegisterModifier() throws Exception { 34 Properties lvProperties = new Properties(); 35 lvProperties.put(Property.MODIFIER_CLASS, EchoModifierAfter.class.getName()); 36 IServiceManager lvServiceManager = new ServiceManager(lvProperties); 37 Modifier lvModifier = lvServiceManager.getModifier(); 38 assertNotNull(lvModifier); 39 assertTrue(lvModifier instanceof EchoModifierAfter); 40 41 lvServiceManager.setModifier(null); 42 assertNull(lvServiceManager.getModifier()); 43 44 lvServiceManager.setModifier(new EchoModifierBefore()); 45 lvModifier = lvServiceManager.getModifier(); 46 assertNotNull(lvModifier); 47 assertTrue(lvModifier instanceof EchoModifierBefore); 48 } 49 50 public void testRegisterInterceptor() throws Exception { 51 Properties lvProperties = new Properties(); 52 lvProperties.put(Property.INTERCEPTOR_CLASS, StopWatchInterceptor.class.getName()); 53 IServiceManager lvServiceManager = new ServiceManager(lvProperties); 54 int size = lvServiceManager.getInterceptorSize(); 55 assertTrue(size == 1); 56 Interceptor lvInterceptor = lvServiceManager.getInterceptorByPos(0); 57 assertTrue(lvInterceptor instanceof StopWatchInterceptor); 58 59 lvServiceManager.removeInterceptorByPos(0); 60 assertTrue(lvServiceManager.getInterceptorSize() == 0); 61 62 lvServiceManager.addInterceptor(new LogInterceptor ()); 63 size = lvServiceManager.getInterceptorSize(); 64 assertTrue(size == 1); 65 lvInterceptor = lvServiceManager.getInterceptorByPos(0); 66 assertTrue(lvInterceptor instanceof LogInterceptor); 67 } 68 69 public void testRegisterProperty() throws Exception { 70 Properties lvProperties = new Properties(); 71 lvProperties.put(Property.INTERCEPTOR_CLASS, StopWatchInterceptor.class.getName()); 72 lvProperties.put(Property.EXECUTOR_CLASS, RmiExecutor.class.getName()); 73 IServiceManager lvServiceManager = new ServiceManager(lvProperties); 74 75 String lvProperty = lvServiceManager.getProperty(Property.INTERCEPTOR_CLASS); 76 assertNotNull(lvProperty); 77 assertEquals(lvProperty, StopWatchInterceptor.class.getName()); 78 79 Iterator it = lvServiceManager.getPropertyKeys(); 80 int size = 0; 81 while (it.hasNext()) { size++; it.next(); } 82 assertTrue(size == 2); 83 } 84 85 public void testCreateService() throws Exception { 86 Properties lvProperties = new Properties(); 87 lvProperties.put(Echo.class.getName(), EchoImpl.class.getName()); 88 IServiceManager lvServiceManager = new ServiceManager(lvProperties); 89 Echo lvEcho = (Echo) lvServiceManager.createService(Echo.class); 90 assertNotNull(lvEcho); 91 } 92 93 public void testNullProperties() throws Exception { 94 ServiceManager lvManager = new ServiceManager(); 95 try { 96 lvManager.createService(Echo.class); 97 fail("Can't create service without properties"); 98 } catch (Exception e) { 99 assertTrue(true); 100 } 101 } 102 103 public void testNullServiceClass() throws Exception { 104 Properties lvProperties = new Properties(); 105 lvProperties.put(Echo.class.getName(), EchoImpl.class.getName()); 106 107 ServiceManager lvManager = new ServiceManager(lvProperties); 108 try { 109 lvManager.createService(null); 110 fail("Can't create service without service class"); 111 } catch (Exception e) { 112 assertTrue(true); 113 } 114 115 } 116 117 public void testValideInterceptor() throws Exception { 118 Properties lvProperties = new Properties(); 119 lvProperties.put(Property.INTERCEPTOR_CLASS, StopWatchInterceptor.class.getName()); 120 ServiceManager lvManager = new ServiceManager(lvProperties); 121 122 assertEquals(lvManager.getInterceptorSize(), 1); 123 Iterator it = lvManager.getInterceptorIterator(); 124 assertTrue(it.hasNext()); 125 Object o = it.next(); 126 assertNotNull(o); 127 assertTrue(o instanceof StopWatchInterceptor); 128 } 129 130 public void testNotValideInterceptor() throws Exception { 131 Properties lvProperties = new Properties(); 132 lvProperties.put(Property.INTERCEPTOR_CLASS, String.class.getName()); 133 try { 134 new ServiceManager(lvProperties); 135 fail("String ist not a Interceptor."); 136 } catch (Exception e) { 137 assertTrue(true); 138 } 139 } 140 141 public void testNotValideModifier() throws Exception { 142 Properties lvProperties = new Properties(); 143 lvProperties.put(Property.MODIFIER_CLASS, String.class.getName()); 144 try { 145 new ServiceManager(lvProperties); 146 fail("String ist not a Modifier."); 147 } catch (Exception e) { 148 assertTrue(true); 149 } 150 } 151 152 public void testNotValideStaticProxy() throws Exception { 153 Properties lvProperties = new Properties(); 154 lvProperties.put(Property.STATIC_PROXY_CLASS, String.class.getName()); 155 try { 156 new ServiceManager(lvProperties).createService(Echo.class); 157 fail("String ist not a StaticProxy."); 158 } catch (Exception e) { 159 assertTrue(true); 160 } 161 } 162 163 public void testNotValideStaticProxy2() throws Exception { 164 Properties lvProperties = new Properties(); 165 lvProperties.put(Property.STATIC_PROXY_CLASS, Integer.class.getName()); 166 try { 167 new ServiceManager(lvProperties).createService(Echo.class); 168 fail("String ist not a StaticProxy."); 169 } catch (Exception e) { 170 assertTrue(true); 171 } 172 } 173 174 public void testNotValideDynamicProxy() throws Exception { 175 Properties lvProperties = new Properties(); 176 lvProperties.put(Property.DYNAMIC_PROXY_CLASS, String.class.getName()); 177 ServiceManager lvManager = new ServiceManager(lvProperties); 178 try { 179 lvManager.createService(Echo.class); 180 fail("No valide properties to create service."); 181 } catch (Exception e) { 182 assertTrue(true); 183 } 184 } 185 186 public void testNotValideDynamicProxy2() throws Exception { 187 Properties lvProperties = new Properties(); 188 lvProperties.put(Property.DYNAMIC_PROXY_CLASS, Integer.class.getName()); 189 ServiceManager lvManager = new ServiceManager(lvProperties); 190 try { 191 lvManager.createService(Echo.class); 192 fail("No valide properties to create service."); 193 } catch (Exception e) { 194 assertTrue(true); 195 } 196 } 197 198 public void testNotValideExecutor() throws Exception { 199 Properties lvProperties = new Properties(); 200 lvProperties.put(Property.EXECUTOR_CLASS, String.class.getName()); 201 try { 202 new ServiceManager(lvProperties).createService(Echo.class); 203 fail("String ist not a Executor."); 204 } catch (Exception e) { 205 assertTrue(true); 206 } 207 } 208 209 public void testInterceptorFilter() throws Exception { 210 Properties lvProperties = new Properties(); 211 lvProperties.put(Echo.class.getName(), EchoImpl.class.getName()); 212 lvProperties.put(Calculator.class.getName(), CalculatorImpl.class.getName()); 213 ServiceManager lvServiceManager = new ServiceManager(lvProperties); 214 215 lvServiceManager.addInterceptor(new WaitInterceptor()); 216 StopWatchInterceptor lvStopWatch = new StopWatchInterceptor(); 217 lvServiceManager.addInterceptor(lvStopWatch); 218 219 SimpleNameInterceptorFilter lvFilter = new SimpleNameInterceptorFilter(new String[] {"ping", "echo"}, SimpleNameInterceptorFilter.FILTER_TYPE_METHOD); 220 lvServiceManager.addInterceptorFilter(lvFilter); 221 222 Calculator lvCalculator = (Calculator) lvServiceManager.createService(Calculator.class); 223 lvCalculator.add(123, 345); 224 long lvStopTime = lvStopWatch.getStopTimeInvokeMethod(); 225 assertTrue("StopTime is " + lvStopTime, lvStopTime == -1); 226 227 Echo lvEcho = (Echo) lvServiceManager.createService(Echo.class); 228 lvEcho.ping(); 229 lvStopTime = lvStopWatch.getStopTimeInvokeMethod(); 230 assertTrue("StopTime is " + lvStopTime, lvStopTime > 10); 231 232 assertEquals(lvServiceManager.getInterceptorFilterSize(), 1); 233 } 234 235 public void testInterceptorFilterRemove() throws Exception { 236 Properties lvProperties = new Properties(); 237 lvProperties.put(Echo.class.getName(), EchoImpl.class.getName()); 238 lvProperties.put(Calculator.class.getName(), CalculatorImpl.class.getName()); 239 ServiceManager lvServiceManager = new ServiceManager(lvProperties); 240 241 lvServiceManager.addInterceptor(new WaitInterceptor()); 242 StopWatchInterceptor lvStopWatch = new StopWatchInterceptor(); 243 lvServiceManager.addInterceptor(lvStopWatch); 244 245 SimpleNameInterceptorFilter lvFilter = new SimpleNameInterceptorFilter(new String[] {"ping", "echo"}, SimpleNameInterceptorFilter.FILTER_TYPE_METHOD); 246 lvServiceManager.addInterceptorFilter(lvFilter); 247 248 Calculator lvCalculator = (Calculator) lvServiceManager.createService(Calculator.class); 249 lvCalculator.add(123, 345); 250 long lvStopTime = lvStopWatch.getStopTimeInvokeMethod(); 251 assertTrue("StopTime is " + lvStopTime, lvStopTime == -1); 252 253 Echo lvEcho = (Echo) lvServiceManager.createService(Echo.class); 254 lvEcho.ping(); 255 lvStopTime = lvStopWatch.getStopTimeInvokeMethod(); 256 assertTrue("StopTime is " + lvStopTime, lvStopTime > 10); 257 258 assertEquals(lvServiceManager.getInterceptorFilterSize(), 1); 259 260 lvServiceManager.removeInterceptorFilterByPos(0); 261 assertEquals(lvServiceManager.getInterceptorFilterSize(), 0); 262 263 assertTrue(lvServiceManager.getInterceptorSize() > 0); 264 lvServiceManager.removeAllInterceptors(); 265 assertTrue(lvServiceManager.getInterceptorSize() == 0); 266 } 267 268 public void testInterceptorFilterNegate() throws Exception { 269 Properties lvProperties = new Properties(); 270 lvProperties.put(Echo.class.getName(), EchoImpl.class.getName()); 271 lvProperties.put(Calculator.class.getName(), CalculatorImpl.class.getName()); 272 ServiceManager lvServiceManager = new ServiceManager(lvProperties); 273 274 lvServiceManager.addInterceptor(new WaitInterceptor()); 275 StopWatchInterceptor lvStopWatch = new StopWatchInterceptor(); 276 lvServiceManager.addInterceptor(lvStopWatch); 277 278 SimpleNameInterceptorFilter lvFilter = new SimpleNameInterceptorFilter(new String[] {"ping", "echo"}, SimpleNameInterceptorFilter.FILTER_TYPE_METHOD); 279 lvFilter.setNegate(true); 280 lvServiceManager.addInterceptorFilter(lvFilter); 281 282 Calculator lvCalculator = (Calculator) lvServiceManager.createService(Calculator.class); 283 lvCalculator.add(123, 345); 284 long lvStopTime = lvStopWatch.getStopTimeInvokeMethod(); 285 assertTrue("StopTime is " + lvStopTime, lvStopTime != -1); 286 287 lvStopWatch.clearStopTimeInvokeMethod(); 288 Echo lvEcho = (Echo) lvServiceManager.createService(Echo.class); 289 lvEcho.ping(); 290 lvStopTime = lvStopWatch.getStopTimeInvokeMethod(); 291 assertTrue("StopTime is " + lvStopTime, lvStopTime == 0); 292 293 assertEquals(lvServiceManager.getInterceptorFilterSize(), 1); 294 } 295 296 public void testInterceptorFilter2() throws Exception { 297 Properties lvProperties = new Properties(); 298 lvProperties.put(Echo.class.getName(), EchoImpl.class.getName()); 299 lvProperties.put(Calculator.class.getName(), CalculatorImpl.class.getName()); 300 lvProperties.put(Property.INTERCEPTOR_CLASS, WaitInterceptor.class.getName()); 301 lvProperties.put(Property.INTERCEPTOR_CLASS_2, StopWatchInterceptor.class.getName()); 302 ServiceManager lvServiceManager = new ServiceManager(lvProperties); 303 304 StopWatchInterceptor lvStopWatch = (StopWatchInterceptor) lvServiceManager.getInterceptorByPos(1); 305 306 SimpleNameInterceptorFilter lvFilter = new SimpleNameInterceptorFilter(new String[] {"ping", "echo"}, SimpleNameInterceptorFilter.FILTER_TYPE_METHOD); 307 lvServiceManager.addInterceptorFilter(lvFilter); 308 309 Calculator lvCalculator = (Calculator) lvServiceManager.createService(Calculator.class); 310 lvCalculator.add(123, 345); 311 long lvStopTime = lvStopWatch.getStopTimeInvokeMethod(); 312 assertTrue("StopTime is " + lvStopTime, lvStopTime == -1); 313 314 315 Echo lvEcho = (Echo) lvServiceManager.createService(Echo.class); 316 lvEcho.ping(); 317 lvStopTime = lvStopWatch.getStopTimeInvokeMethod(); 318 assertTrue("StopTime is " + lvStopTime, lvStopTime > 10); 319 320 321 assertEquals(lvServiceManager.getInterceptorFilterSize(), 1); 322 } 323 324 public void testInterceptorNamePatternFilter() throws Exception { 325 Properties lvProperties = new Properties(); 326 lvProperties.put(Echo.class.getName(), EchoImpl.class.getName()); 327 lvProperties.put(Calculator.class.getName(), CalculatorImpl.class.getName()); 328 lvProperties.put(Property.INTERCEPTOR_CLASS, WaitInterceptor.class.getName()); 329 lvProperties.put(Property.INTERCEPTOR_CLASS_2, StopWatchInterceptor.class.getName()); 330 ServiceManager lvServiceManager = new ServiceManager(lvProperties); 331 332 StopWatchInterceptor lvStopWatch = (StopWatchInterceptor) lvServiceManager.getInterceptorByPos(1); 333 334 NamePatternInterceptorFilter lvFilter = new NamePatternInterceptorFilter(".*Echo.*", NamePatternInterceptorFilter.FILTER_TYPE_CLASS); 335 lvServiceManager.addInterceptorFilter(lvFilter); 336 337 Calculator lvCalculator = (Calculator) lvServiceManager.createService(Calculator.class); 338 lvCalculator.add(123, 345); 339 long lvStopTime = lvStopWatch.getStopTimeInvokeMethod(); 340 assertTrue("StopTime is " + lvStopTime, lvStopTime == -1); 341 342 343 Echo lvEcho = (Echo) lvServiceManager.createService(Echo.class); 344 lvEcho.ping(); 345 lvStopTime = lvStopWatch.getStopTimeInvokeMethod(); 346 assertTrue("StopTime is " + lvStopTime, lvStopTime > 10); 347 348 349 assertEquals(lvServiceManager.getInterceptorFilterSize(), 1); 350 } 351 352 public void testTransporterClassByServiceInterfaceWithInvalideServiceInterface() throws Exception { 353 Properties prop = new Properties(); 354 prop.put(Calculator.class.getName(), CalculatorImpl.class.getName()); 355 ServiceManager lvServiceManager = new ServiceManager(prop); 356 lvServiceManager.createService(Calculator.class); 357 Class lvTransporterClass = lvServiceManager.getTransporterClassByServiceInterface(Echo.class); 358 assertNull(lvTransporterClass); 359 } 360 361 public void testTransporterClassByServiceInterfaceWithNoSetTransporter() throws Exception { 362 Properties prop = new Properties(); 363 prop.put(Calculator.class.getName(), CalculatorImpl.class.getName()); 364 ServiceManager lvServiceManager = new ServiceManager(prop); 365 lvServiceManager.createService(Calculator.class); 366 367 Class lvTransporterClass = lvServiceManager.getTransporterClassByServiceInterface(Calculator.class); 368 assertNotNull(lvTransporterClass); 369 assertEquals(lvTransporterClass, StaticLocalObjectProxy.class); 370 } 371 372 public void testTransporterClassByServiceInterfaceWithSetTransporterAsStaticProxy() throws Exception { 373 Properties prop = new Properties(); 374 prop.put(Calculator.class.getName(), CalculatorImpl.class.getName()); 375 prop.put(Property.STATIC_PROXY_CLASS, HttpExecutor.class.getName()); 376 ServiceManager lvServiceManager = new ServiceManager(prop); 377 lvServiceManager.createService(Calculator.class); 378 379 Class lvTransporterClass = lvServiceManager.getTransporterClassByServiceInterface(Calculator.class); 380 assertNotNull(lvTransporterClass); 381 assertEquals(lvTransporterClass, HttpExecutor.class); 382 } 383 384 public void testTransporterClassByServiceInterfaceWithSetTransporterAsExecutor() throws Exception { 385 Properties prop = new Properties(); 386 prop.put(Calculator.class.getName(), CalculatorImpl.class.getName()); 387 prop.put(Property.EXECUTOR_CLASS, HttpExecutor.class.getName()); 388 ServiceManager lvServiceManager = new ServiceManager(prop); 389 lvServiceManager.createService(Calculator.class); 390 391 Class lvTransporterClass = lvServiceManager.getTransporterClassByServiceInterface(Calculator.class); 392 assertNotNull(lvTransporterClass); 393 assertEquals(lvTransporterClass, HttpExecutor.class); 394 } 395 396 public void testTransporterClassByServiceInterfaceWithSetTransporterAsStaticProxyAndExecutor() throws Exception { 397 Properties prop = new Properties(); 398 prop.put(Calculator.class.getName(), CalculatorImpl.class.getName()); 399 prop.put(Property.STATIC_PROXY_CLASS, HttpExecutor.class.getName()); 400 prop.put(Property.EXECUTOR_CLASS, HttpExecutor.class.getName()); 401 ServiceManager lvServiceManager = new ServiceManager(prop); 402 lvServiceManager.createService(Calculator.class); 403 404 Class lvTransporterClass = lvServiceManager.getTransporterClassByServiceInterface(Calculator.class); 405 assertNotNull(lvTransporterClass); 406 assertEquals(lvTransporterClass, HttpExecutor.class); 407 } 408 409 public void testTransporterClassByServiceInterfaceWithSetTransporterAsStaticProxyStatic() throws Exception { 410 Properties prop = new Properties(); 411 prop.put(Calculator.class.getName(), CalculatorImpl.class.getName()); 412 prop.put(Property.STATIC_PROXY_CLASS, StaticBurlapProxy.class.getName()); 413 ServiceManager lvServiceManager = new ServiceManager(prop); 414 lvServiceManager.createService(Calculator.class); 415 416 Class lvTransporterClass = lvServiceManager.getTransporterClassByServiceInterface(Calculator.class); 417 assertNotNull(lvTransporterClass); 418 assertEquals(lvTransporterClass, StaticBurlapProxy.class); 419 } 420 421 public void testTransporterClassByServiceInterfaceWithSetTransporterAsExecutorStatic() throws Exception { 422 Properties prop = new Properties(); 423 prop.put(Calculator.class.getName(), CalculatorImpl.class.getName()); 424 prop.put(Property.EXECUTOR_CLASS, StaticBurlapProxy.class.getName()); 425 ServiceManager lvServiceManager = new ServiceManager(prop); 426 lvServiceManager.createService(Calculator.class); 427 428 Class lvTransporterClass = lvServiceManager.getTransporterClassByServiceInterface(Calculator.class); 429 assertNotNull(lvTransporterClass); 430 assertEquals(lvTransporterClass, StaticBurlapProxy.class); 431 } 432 433 public void testTransporterClassByServiceInterfaceWithSetTransporterAsStaticProxyAndExecutorStatic() throws Exception { 434 Properties prop = new Properties(); 435 prop.put(Calculator.class.getName(), CalculatorImpl.class.getName()); 436 prop.put(Property.STATIC_PROXY_CLASS, StaticBurlapProxy.class.getName()); 437 prop.put(Property.EXECUTOR_CLASS, StaticBurlapProxy.class.getName()); 438 ServiceManager lvServiceManager = new ServiceManager(prop); 439 lvServiceManager.createService(Calculator.class); 440 441 Class lvTransporterClass = lvServiceManager.getTransporterClassByServiceInterface(Calculator.class); 442 assertNotNull(lvTransporterClass); 443 assertEquals(lvTransporterClass, StaticBurlapProxy.class); 444 } 445 446 public void testTransporterClassByServiceInterfaceWithSetTransporterAsStaticProxyAndExecutorBoth() throws Exception { 447 Properties prop = new Properties(); 448 prop.put(Calculator.class.getName(), CalculatorImpl.class.getName()); 449 prop.put(Property.STATIC_PROXY_CLASS, HttpExecutor.class.getName()); 450 prop.put(Property.EXECUTOR_CLASS, StaticBurlapProxy.class.getName()); 451 ServiceManager lvServiceManager = new ServiceManager(prop); 452 lvServiceManager.createService(Calculator.class); 453 454 Class lvTransporterClass = lvServiceManager.getTransporterClassByServiceInterface(Calculator.class); 455 assertNotNull(lvTransporterClass); 456 assertEquals(lvTransporterClass, StaticBurlapProxy.class); 457 } 458 459 public void testTransporterClassByServiceInterfaceWithSetTransporterAsStaticProxyAndExecutorBoth2() throws Exception { 460 Properties prop = new Properties(); 461 prop.put(Calculator.class.getName(), CalculatorImpl.class.getName()); 462 prop.put(Property.STATIC_PROXY_CLASS, StaticBurlapProxy.class.getName()); 463 prop.put(Property.EXECUTOR_CLASS, HttpExecutor.class.getName()); 464 ServiceManager lvServiceManager = new ServiceManager(prop); 465 lvServiceManager.createService(Calculator.class); 466 467 Class lvTransporterClass = lvServiceManager.getTransporterClassByServiceInterface(Calculator.class); 468 assertNotNull(lvTransporterClass); 469 assertEquals(lvTransporterClass, StaticBurlapProxy.class); 470 } 471 472 public void testNotAsynchronousCallback() throws Exception { 473 Properties prop = new Properties(); 474 prop.put(Echo.class.getName(), EchoImpl.class.getName()); 475 prop.put(Property.EXECUTOR_CLASS, HttpExecutor.class.getName()); 476 477 ServiceManager lvServiceManager = new ServiceManager(prop); 478 lvServiceManager.createService(Echo.class); 479 480 assertFalse(lvServiceManager.isInvocationAsynchronous(Echo.class)); 481 assertNull(lvServiceManager.getAsynchronousCallback(Echo.class)); 482 } 483 484 public void testAsynchronousCallback() throws Exception { 485 Properties prop = new Properties(); 486 prop.put(Echo.class.getName(), EchoImpl.class.getName()); 487 prop.put(Property.EXECUTOR_CLASS, HttpExecutor.class.getName()); 488 prop.put(Property.ASYNCHRONOUS_CALLBACK_CLASS, AsynchronousCallbackForTests.class.getName()); 489 490 ServiceManager lvServiceManager = new ServiceManager(prop); 491 lvServiceManager.createService(Echo.class); 492 493 assertTrue(lvServiceManager.isInvocationAsynchronous(Echo.class)); 494 assertNotNull(lvServiceManager.getAsynchronousCallback(Echo.class)); 495 } 496 497 public void testNullServiceInterface() throws Exception { 498 Properties prop = new Properties(); 499 prop.put(Echo.class.getName(), EchoImpl.class.getName()); 500 501 try { 502 ServiceManager lvServiceManager = new ServiceManager(prop); 503 lvServiceManager.createService(null); 504 fail("Null by ServiceInterface is not supported"); 505 } catch (Exception e) { 506 assertTrue(true); 507 } 508 509 try { 510 ServiceManager lvServiceManager = new ServiceManager(prop); 511 lvServiceManager.createService(null, null, null, 0); 512 fail("Null by ServiceInterface is not supported"); 513 } catch (Exception e) { 514 assertTrue(true); 515 } 516 } 517 518 public void testDoubleSynchAndAsynchService() throws Exception { 519 Properties prop = new Properties(); 520 prop.put(Echo.class.getName(), EchoImpl.class.getName()); 521 prop.put(Property.DYNAMIC_PROXY_CLASS, Property.VALUE_FOR_JDK_DYNAMIC_PROXY); 522 523 ServiceManager lvServiceManager = new ServiceManager(prop); 524 lvServiceManager.createService(Echo.class); 525 526 try { 527 lvServiceManager.createService(Echo.class, new AsynchronousCallbackForTests(), null, 3); 528 lvServiceManager.createService(null, null, null, 0); 529 fail("For the same Service Interface can't create a Service"); 530 } catch (Exception e) { 531 assertTrue(true); 532 } 533 } 534 535 public void testDoubleAsynchAndSynchService() throws Exception { 536 Properties prop = new Properties(); 537 prop.put(Echo.class.getName(), EchoImpl.class.getName()); 538 prop.put(Property.DYNAMIC_PROXY_CLASS, Property.VALUE_FOR_JDK_DYNAMIC_PROXY); 539 540 ServiceManager lvServiceManager = new ServiceManager(prop); 541 lvServiceManager.createService(Echo.class, new AsynchronousCallbackForTests(), null, 3); 542 543 try { 544 lvServiceManager.createService(Echo.class); 545 lvServiceManager.createService(null, null, null, 0); 546 fail("For the same Service Interface can't create a Service"); 547 } catch (Exception e) { 548 assertTrue(true); 549 } 550 } 551 552 public void testNoDynamicProxyIsSet() throws Exception { 553 Properties prop = new Properties(); 554 prop.put(Echo.class.getName(), EchoImpl.class.getName()); 555 556 ServiceManager lvServiceManager = new ServiceManager(prop); 557 lvServiceManager.createService(Echo.class, new AsynchronousCallbackForTests(), null, 3); 558 } 559 560 public void testGetAsynchronousCallback() throws Exception { 561 Properties prop = new Properties(); 562 prop.put(Echo.class.getName(), EchoImpl.class.getName()); 563 564 ServiceManager lvServiceManager = new ServiceManager(prop); 565 assertNull(lvServiceManager.getAsynchronousCallback(Echo.class)); 566 } 567 568 public void testGetAsynchronousCallback2() throws Exception { 569 Properties prop = new Properties(); 570 prop.put(Echo.class.getName(), EchoImpl.class.getName()); 571 prop.put(Property.ASYNCHRONOUS_CALLBACK_CLASS, AsynchronousCallbackForTests.class.getName()); 572 573 ServiceManager lvServiceManager = new ServiceManager(prop); 574 assertNull(lvServiceManager.getAsynchronousCallback(Echo.class)); 575 } 576 577 public void testGetAsynchronousCallback3() throws Exception { 578 Properties prop = new Properties(); 579 prop.put(Property.STATIC_PROXY_CLASS, StaticBurlapProxy.class.getName()); 580 prop.put(Property.ASYNCHRONOUS_CALLBACK_CLASS, AsynchronousCallbackForTests.class.getName()); 581 582 ServiceManager lvServiceManager = new ServiceManager(prop); 583 lvServiceManager.createService(Echo.class); 584 assertNull(lvServiceManager.getAsynchronousCallback(Echo.class)); 585 } 586 587 588 public void testAllInterceptorsStaticProxy() throws Exception { 589 Properties prop = new Properties(); 590 prop.put(Property.STATIC_PROXY_CLASS, StaticBurlapProxy.class.getName()); 591 prop.put(Property.ASYNCHRONOUS_CALLBACK_CLASS, AsynchronousCallbackForTests.class.getName()); 592 593 ServiceManager lvServiceManager = new ServiceManager(prop); 594 lvServiceManager.createService(Echo.class); 595 lvServiceManager.removeAllInterceptors(); 596 } 597 598 public void testAllInterceptorsWithDynamicProxy() throws Exception { 599 Properties prop = new Properties(); 600 prop.put(Property.STATIC_PROXY_CLASS, StaticBurlapProxy.class.getName()); 601 prop.put(Property.DYNAMIC_PROXY_CLASS, Property.VALUE_FOR_JDK_DYNAMIC_PROXY); 602 prop.put(Property.ASYNCHRONOUS_CALLBACK_CLASS, AsynchronousCallbackForTests.class.getName()); 603 604 ServiceManager lvServiceManager = new ServiceManager(prop); 605 lvServiceManager.createService(Echo.class); 606 lvServiceManager.removeAllInterceptors(); 607 } 608 609 public void testAllInterceptorsWithDynamicProxy2() throws Exception { 610 Properties prop = new Properties(); 611 prop.put(Property.EXECUTOR_CLASS, HttpExecutor.class.getName()); 612 prop.put(Property.ASYNCHRONOUS_CALLBACK_CLASS, AsynchronousCallbackForTests.class.getName()); 613 614 ServiceManager lvServiceManager = new ServiceManager(prop); 615 lvServiceManager.createService(Echo.class); 616 lvServiceManager.removeAllInterceptors(); 617 } 618 619 public void testRemoveAsynchronousCallback() throws Exception { 620 Properties prop = new Properties(); 621 prop.put(Property.EXECUTOR_CLASS, HttpExecutor.class.getName()); 622 prop.put(Property.ASYNCHRONOUS_CALLBACK_CLASS, AsynchronousCallbackForTests.class.getName()); 623 624 ServiceManager lvServiceManager = new ServiceManager(prop); 625 lvServiceManager.createService(Echo.class); 626 627 lvServiceManager.removeAsynchronousCallback(Echo.class); 628 lvServiceManager.removeAsynchronousCallback(MyService.class); 629 } 630 }