1 16 17 package org.springframework.jca.cci; 18 19 import java.sql.SQLException ; 20 21 import javax.resource.ResourceException ; 22 import javax.resource.cci.Connection ; 23 import javax.resource.cci.ConnectionFactory ; 24 import javax.resource.cci.ConnectionSpec ; 25 import javax.resource.cci.IndexedRecord ; 26 import javax.resource.cci.Interaction ; 27 import javax.resource.cci.InteractionSpec ; 28 import javax.resource.cci.MappedRecord ; 29 import javax.resource.cci.Record ; 30 import javax.resource.cci.RecordFactory ; 31 import javax.resource.cci.ResultSet ; 32 33 import junit.framework.TestCase; 34 import org.easymock.MockControl; 35 36 import org.springframework.jca.cci.connection.ConnectionSpecConnectionFactoryAdapter; 37 import org.springframework.jca.cci.core.CciTemplate; 38 import org.springframework.jca.cci.core.ConnectionCallback; 39 import org.springframework.jca.cci.core.InteractionCallback; 40 import org.springframework.jca.cci.core.RecordCreator; 41 import org.springframework.jca.cci.core.RecordExtractor; 42 43 47 public class CciTemplateTests extends TestCase { 48 49 public void testCreateIndexedRecord() throws ResourceException { 50 MockControl connectionFactoryControl = MockControl.createStrictControl(ConnectionFactory .class); 51 ConnectionFactory connectionFactory = (ConnectionFactory ) connectionFactoryControl.getMock(); 52 MockControl recordFactoryControl = MockControl.createStrictControl(RecordFactory .class); 53 RecordFactory recordFactory = (RecordFactory ) recordFactoryControl.getMock(); 54 MockControl indexedRecordControl = MockControl.createStrictControl(IndexedRecord .class); 55 IndexedRecord indexedRecord = (IndexedRecord ) indexedRecordControl.getMock(); 56 57 connectionFactory.getRecordFactory(); 58 connectionFactoryControl.setReturnValue(recordFactory, 1); 59 60 recordFactory.createIndexedRecord("name"); 61 recordFactoryControl.setReturnValue(indexedRecord, 1); 62 63 connectionFactoryControl.replay(); 64 recordFactoryControl.replay(); 65 66 CciTemplate ct = new CciTemplate(connectionFactory); 67 ct.createIndexedRecord("name"); 68 69 connectionFactoryControl.verify(); 70 recordFactoryControl.verify(); 71 } 72 73 public void testCreateMappedRecord() throws ResourceException { 74 MockControl connectionFactoryControl = MockControl.createStrictControl(ConnectionFactory .class); 75 ConnectionFactory connectionFactory = (ConnectionFactory ) connectionFactoryControl.getMock(); 76 MockControl recordFactoryControl = MockControl.createStrictControl(RecordFactory .class); 77 RecordFactory recordFactory = (RecordFactory ) recordFactoryControl.getMock(); 78 MockControl mappedRecordControl = MockControl.createStrictControl(MappedRecord .class); 79 MappedRecord mappedRecord = (MappedRecord ) mappedRecordControl.getMock(); 80 81 connectionFactory.getRecordFactory(); 82 connectionFactoryControl.setReturnValue(recordFactory, 1); 83 84 recordFactory.createMappedRecord("name"); 85 recordFactoryControl.setReturnValue(mappedRecord, 1); 86 87 connectionFactoryControl.replay(); 88 recordFactoryControl.replay(); 89 90 CciTemplate ct = new CciTemplate(connectionFactory); 91 ct.createMappedRecord("name"); 92 93 connectionFactoryControl.verify(); 94 recordFactoryControl.verify(); 95 } 96 97 public void testTemplateExecuteInputOutput() throws ResourceException { 98 MockControl connectionFactoryControl = MockControl.createStrictControl(ConnectionFactory .class); 99 ConnectionFactory connectionFactory = (ConnectionFactory ) connectionFactoryControl.getMock(); 100 MockControl connectionControl = MockControl.createStrictControl(Connection .class); 101 Connection connection = (Connection ) connectionControl.getMock(); 102 MockControl interactionControl = MockControl.createStrictControl(Interaction .class); 103 Interaction interaction = (Interaction ) interactionControl.getMock(); 104 105 MockControl inputRecordControl = MockControl.createStrictControl(Record .class); 106 Record inputRecord = (Record ) inputRecordControl.getMock(); 107 MockControl outputRecordControl = MockControl.createStrictControl(Record .class); 108 Record outputRecord = (Record ) outputRecordControl.getMock(); 109 110 MockControl interactionSpecControl = MockControl.createStrictControl(InteractionSpec .class); 111 InteractionSpec interactionSpec = (InteractionSpec ) interactionSpecControl.getMock(); 112 113 connectionFactory.getConnection(); 114 connectionFactoryControl.setReturnValue(connection, 1); 115 116 connection.createInteraction(); 117 connectionControl.setReturnValue(interaction, 1); 118 119 interaction.execute(interactionSpec, inputRecord, outputRecord); 120 interactionControl.setReturnValue(true, 1); 121 122 interaction.close(); 123 interactionControl.setVoidCallable(1); 124 125 connection.close(); 126 connectionControl.setVoidCallable(1); 127 128 connectionFactoryControl.replay(); 129 connectionControl.replay(); 130 interactionControl.replay(); 131 132 CciTemplate ct = new CciTemplate(connectionFactory); 133 ct.execute(interactionSpec, inputRecord, outputRecord); 134 135 connectionFactoryControl.verify(); 136 connectionControl.verify(); 137 interactionControl.verify(); 138 } 139 140 public void testTemplateExecuteInputTrueWithCreator() throws ResourceException { 141 MockControl connectionFactoryControl = MockControl.createStrictControl(ConnectionFactory .class); 142 ConnectionFactory connectionFactory = (ConnectionFactory ) connectionFactoryControl.getMock(); 143 MockControl recordFactoryControl = MockControl.createStrictControl(RecordFactory .class); 144 RecordFactory recordFactory = (RecordFactory ) recordFactoryControl.getMock(); 145 MockControl connectionControl = MockControl.createStrictControl(Connection .class); 146 Connection connection = (Connection ) connectionControl.getMock(); 147 MockControl interactionControl = MockControl.createStrictControl(Interaction .class); 148 Interaction interaction = (Interaction ) interactionControl.getMock(); 149 MockControl creatorControl = MockControl.createStrictControl(RecordCreator.class); 150 RecordCreator creator = (RecordCreator) creatorControl.getMock(); 151 152 MockControl inputRecordControl = MockControl.createStrictControl(Record .class); 153 Record inputRecord = (Record ) inputRecordControl.getMock(); 154 MockControl outputRecordControl = MockControl.createStrictControl(Record .class); 155 Record outputRecord = (Record ) outputRecordControl.getMock(); 156 157 MockControl interactionSpecControl = MockControl.createStrictControl(InteractionSpec .class); 158 InteractionSpec interactionSpec = (InteractionSpec ) interactionSpecControl.getMock(); 159 160 connectionFactory.getConnection(); 161 connectionFactoryControl.setReturnValue(connection); 162 163 connectionFactory.getRecordFactory(); 164 connectionFactoryControl.setReturnValue(recordFactory, 1); 165 166 connection.createInteraction(); 167 connectionControl.setReturnValue(interaction); 168 169 creator.createRecord(recordFactory); 170 creatorControl.setReturnValue(outputRecord); 171 172 interaction.execute(interactionSpec, inputRecord, outputRecord); 173 interactionControl.setReturnValue(true, 1); 174 175 interaction.close(); 176 interactionControl.setVoidCallable(1); 177 178 connection.close(); 179 connectionControl.setVoidCallable(1); 180 181 connectionFactoryControl.replay(); 182 connectionControl.replay(); 183 interactionControl.replay(); 184 creatorControl.replay(); 185 186 CciTemplate ct = new CciTemplate(connectionFactory); 187 ct.setOutputRecordCreator(creator); 188 ct.execute(interactionSpec, inputRecord); 189 190 connectionFactoryControl.verify(); 191 connectionControl.verify(); 192 interactionControl.verify(); 193 creatorControl.verify(); 194 } 195 196 public void testTemplateExecuteInputFalse() throws ResourceException { 197 MockControl connectionFactoryControl = MockControl.createStrictControl(ConnectionFactory .class); 198 ConnectionFactory connectionFactory = (ConnectionFactory ) connectionFactoryControl.getMock(); 199 MockControl connectionControl = MockControl.createStrictControl(Connection .class); 200 Connection connection = (Connection ) connectionControl.getMock(); 201 MockControl interactionControl = MockControl.createStrictControl(Interaction .class); 202 Interaction interaction = (Interaction ) interactionControl.getMock(); 203 204 MockControl inputRecordControl = MockControl.createStrictControl(Record .class); 205 Record inputRecord = (Record ) inputRecordControl.getMock(); 206 MockControl outputRecordControl = MockControl.createStrictControl(Record .class); 207 Record outputRecord = (Record ) outputRecordControl.getMock(); 208 209 MockControl interactionSpecControl = MockControl.createStrictControl(InteractionSpec .class); 210 InteractionSpec interactionSpec = (InteractionSpec ) interactionSpecControl.getMock(); 211 212 connectionFactory.getConnection(); 213 connectionFactoryControl.setReturnValue(connection); 214 215 connection.createInteraction(); 216 connectionControl.setReturnValue(interaction); 217 218 interaction.execute(interactionSpec, inputRecord); 219 interactionControl.setReturnValue(outputRecord, 1); 220 221 interaction.close(); 222 interactionControl.setVoidCallable(1); 223 224 connection.close(); 225 connectionControl.setVoidCallable(1); 226 227 connectionFactoryControl.replay(); 228 connectionControl.replay(); 229 interactionControl.replay(); 230 231 CciTemplate ct = new CciTemplate(connectionFactory); 232 ct.execute(interactionSpec, inputRecord); 233 234 connectionFactoryControl.verify(); 235 connectionControl.verify(); 236 interactionControl.verify(); 237 } 238 239 public void testTemplateExecuteInputExtractorTrueWithCreator() throws ResourceException , SQLException { 240 MockControl connectionFactoryControl = MockControl.createStrictControl(ConnectionFactory .class); 241 ConnectionFactory connectionFactory = (ConnectionFactory ) connectionFactoryControl.getMock(); 242 MockControl recordFactoryControl = MockControl.createStrictControl(RecordFactory .class); 243 RecordFactory recordFactory = (RecordFactory ) recordFactoryControl.getMock(); 244 MockControl connectionControl = MockControl.createStrictControl(Connection .class); 245 Connection connection = (Connection ) connectionControl.getMock(); 246 MockControl interactionControl = MockControl.createStrictControl(Interaction .class); 247 Interaction interaction = (Interaction ) interactionControl.getMock(); 248 MockControl extractorControl = MockControl.createStrictControl(RecordExtractor.class); 249 RecordExtractor extractor = (RecordExtractor) extractorControl.getMock(); 250 MockControl creatorControl = MockControl.createStrictControl(RecordCreator.class); 251 RecordCreator creator = (RecordCreator) creatorControl.getMock(); 252 253 MockControl inputRecordControl = MockControl.createStrictControl(Record .class); 254 Record inputRecord = (Record ) inputRecordControl.getMock(); 255 MockControl outputRecordControl = MockControl.createStrictControl(Record .class); 256 Record outputRecord = (Record ) outputRecordControl.getMock(); 257 258 MockControl interactionSpecControl = MockControl.createStrictControl(InteractionSpec .class); 259 InteractionSpec interactionSpec = (InteractionSpec ) interactionSpecControl.getMock(); 260 261 Object obj = new Object (); 262 263 connectionFactory.getConnection(); 264 connectionFactoryControl.setReturnValue(connection); 265 266 connection.createInteraction(); 267 connectionControl.setReturnValue(interaction); 268 269 connectionFactory.getRecordFactory(); 270 connectionFactoryControl.setReturnValue(recordFactory, 1); 271 272 creator.createRecord(recordFactory); 273 creatorControl.setReturnValue(outputRecord); 274 275 interaction.execute(interactionSpec, inputRecord, outputRecord); 276 interactionControl.setReturnValue(true, 1); 277 278 extractor.extractData(outputRecord); 279 extractorControl.setReturnValue(obj); 280 281 interaction.close(); 282 interactionControl.setVoidCallable(1); 283 284 connection.close(); 285 connectionControl.setVoidCallable(1); 286 287 connectionFactoryControl.replay(); 288 connectionControl.replay(); 289 interactionControl.replay(); 290 extractorControl.replay(); 291 creatorControl.replay(); 292 293 CciTemplate ct = new CciTemplate(connectionFactory); 294 ct.setOutputRecordCreator(creator); 295 ct.execute(interactionSpec, inputRecord, extractor); 296 297 connectionFactoryControl.verify(); 298 connectionControl.verify(); 299 interactionControl.verify(); 300 extractorControl.verify(); 301 creatorControl.verify(); 302 } 303 304 public void testTemplateExecuteInputExtractorFalse() throws ResourceException , SQLException { 305 MockControl connectionFactoryControl = MockControl.createStrictControl(ConnectionFactory .class); 306 ConnectionFactory connectionFactory = (ConnectionFactory ) connectionFactoryControl.getMock(); 307 MockControl connectionControl = MockControl.createStrictControl(Connection .class); 308 Connection connection = (Connection ) connectionControl.getMock(); 309 MockControl interactionControl = MockControl.createStrictControl(Interaction .class); 310 Interaction interaction = (Interaction ) interactionControl.getMock(); 311 MockControl extractorControl = MockControl.createStrictControl(RecordExtractor.class); 312 RecordExtractor extractor = (RecordExtractor) extractorControl.getMock(); 313 314 MockControl inputRecordControl = MockControl.createStrictControl(Record .class); 315 Record inputRecord = (Record ) inputRecordControl.getMock(); 316 MockControl outputRecordControl = MockControl.createStrictControl(Record .class); 317 Record outputRecord = (Record ) outputRecordControl.getMock(); 318 319 MockControl interactionSpecControl = MockControl.createStrictControl(InteractionSpec .class); 320 InteractionSpec interactionSpec = (InteractionSpec ) interactionSpecControl.getMock(); 321 322 Object obj = new Object (); 323 324 connectionFactory.getConnection(); 325 connectionFactoryControl.setReturnValue(connection); 326 327 connection.createInteraction(); 328 connectionControl.setReturnValue(interaction); 329 330 interaction.execute(interactionSpec, inputRecord); 331 interactionControl.setReturnValue(outputRecord, 1); 332 333 extractor.extractData(outputRecord); 334 extractorControl.setReturnValue(obj); 335 336 interaction.close(); 337 interactionControl.setVoidCallable(1); 338 339 connection.close(); 340 connectionControl.setVoidCallable(1); 341 342 connectionFactoryControl.replay(); 343 connectionControl.replay(); 344 interactionControl.replay(); 345 extractorControl.replay(); 346 347 CciTemplate ct = new CciTemplate(connectionFactory); 348 ct.execute(interactionSpec, inputRecord, extractor); 349 350 connectionFactoryControl.verify(); 351 connectionControl.verify(); 352 interactionControl.verify(); 353 extractorControl.verify(); 354 } 355 356 public void testTemplateExecuteInputGeneratorTrueWithCreator() throws ResourceException { 357 MockControl connectionFactoryControl = MockControl.createStrictControl(ConnectionFactory .class); 358 ConnectionFactory connectionFactory = (ConnectionFactory ) connectionFactoryControl.getMock(); 359 MockControl recordFactoryControl = MockControl.createStrictControl(RecordFactory .class); 360 RecordFactory recordFactory = (RecordFactory ) recordFactoryControl.getMock(); 361 MockControl connectionControl = MockControl.createStrictControl(Connection .class); 362 Connection connection = (Connection ) connectionControl.getMock(); 363 MockControl interactionControl = MockControl.createStrictControl(Interaction .class); 364 Interaction interaction = (Interaction ) interactionControl.getMock(); 365 MockControl generatorControl = MockControl.createStrictControl(RecordCreator.class); 366 RecordCreator generator = (RecordCreator) generatorControl.getMock(); 367 MockControl creatorControl = MockControl.createStrictControl(RecordCreator.class); 368 RecordCreator creator = (RecordCreator) creatorControl.getMock(); 369 370 MockControl inputRecordControl = MockControl.createStrictControl(Record .class); 371 Record inputRecord = (Record ) inputRecordControl.getMock(); 372 MockControl outputRecordControl = MockControl.createStrictControl(Record .class); 373 Record outputRecord = (Record ) outputRecordControl.getMock(); 374 375 MockControl interactionSpecControl = MockControl.createStrictControl(InteractionSpec .class); 376 InteractionSpec interactionSpec = (InteractionSpec ) interactionSpecControl.getMock(); 377 378 connectionFactory.getRecordFactory(); 379 connectionFactoryControl.setReturnValue(recordFactory, 1); 380 381 generator.createRecord(recordFactory); 382 generatorControl.setReturnValue(inputRecord); 383 384 connectionFactory.getConnection(); 385 connectionFactoryControl.setReturnValue(connection); 386 387 connection.createInteraction(); 388 connectionControl.setReturnValue(interaction); 389 390 creator.createRecord(recordFactory); 391 creatorControl.setReturnValue(outputRecord); 392 393 connectionFactory.getRecordFactory(); 394 connectionFactoryControl.setReturnValue(recordFactory, 1); 395 396 interaction.execute(interactionSpec, inputRecord, outputRecord); 397 interactionControl.setReturnValue(true, 1); 398 399 interaction.close(); 400 interactionControl.setVoidCallable(1); 401 402 connection.close(); 403 connectionControl.setVoidCallable(1); 404 405 connectionFactoryControl.replay(); 406 connectionControl.replay(); 407 interactionControl.replay(); 408 generatorControl.replay(); 409 creatorControl.replay(); 410 411 CciTemplate ct = new CciTemplate(connectionFactory); 412 ct.setOutputRecordCreator(creator); 413 ct.execute(interactionSpec, generator); 414 415 connectionFactoryControl.verify(); 416 connectionControl.verify(); 417 interactionControl.verify(); 418 generatorControl.verify(); 419 creatorControl.verify(); 420 } 421 422 public void testTemplateExecuteInputGeneratorFalse() throws ResourceException { 423 MockControl connectionFactoryControl = MockControl.createStrictControl(ConnectionFactory .class); 424 ConnectionFactory connectionFactory = (ConnectionFactory ) connectionFactoryControl.getMock(); 425 MockControl recordFactoryControl = MockControl.createStrictControl(RecordFactory .class); 426 RecordFactory recordFactory = (RecordFactory ) recordFactoryControl.getMock(); 427 MockControl connectionControl = MockControl.createStrictControl(Connection .class); 428 Connection connection = (Connection ) connectionControl.getMock(); 429 MockControl interactionControl = MockControl.createStrictControl(Interaction .class); 430 Interaction interaction = (Interaction ) interactionControl.getMock(); 431 MockControl generatorControl = MockControl.createStrictControl(RecordCreator.class); 432 RecordCreator generator = (RecordCreator) generatorControl.getMock(); 433 434 MockControl inputRecordControl = MockControl.createStrictControl(Record .class); 435 Record inputRecord = (Record ) inputRecordControl.getMock(); 436 MockControl outputRecordControl = MockControl.createStrictControl(Record .class); 437 Record outputRecord = (Record ) outputRecordControl.getMock(); 438 439 MockControl interactionSpecControl = MockControl.createStrictControl(InteractionSpec .class); 440 InteractionSpec interactionSpec = (InteractionSpec ) interactionSpecControl.getMock(); 441 442 connectionFactory.getRecordFactory(); 443 connectionFactoryControl.setReturnValue(recordFactory, 1); 444 445 connectionFactory.getConnection(); 446 connectionFactoryControl.setReturnValue(connection); 447 448 connection.createInteraction(); 449 connectionControl.setReturnValue(interaction); 450 451 generator.createRecord(recordFactory); 452 generatorControl.setReturnValue(inputRecord); 453 454 interaction.execute(interactionSpec, inputRecord); 455 interactionControl.setReturnValue(outputRecord, 1); 456 457 interaction.close(); 458 interactionControl.setVoidCallable(1); 459 460 connection.close(); 461 connectionControl.setVoidCallable(1); 462 463 connectionFactoryControl.replay(); 464 connectionControl.replay(); 465 interactionControl.replay(); 466 generatorControl.replay(); 467 468 CciTemplate ct = new CciTemplate(connectionFactory); 469 ct.execute(interactionSpec, generator); 470 471 connectionFactoryControl.verify(); 472 connectionControl.verify(); 473 interactionControl.verify(); 474 generatorControl.verify(); 475 } 476 477 public void testTemplateExecuteInputGeneratorExtractorTrueWithCreator() throws ResourceException , SQLException { 478 MockControl connectionFactoryControl = MockControl.createStrictControl(ConnectionFactory .class); 479 ConnectionFactory connectionFactory = (ConnectionFactory ) connectionFactoryControl.getMock(); 480 MockControl recordFactoryControl = MockControl.createStrictControl(RecordFactory .class); 481 RecordFactory recordFactory = (RecordFactory ) recordFactoryControl.getMock(); 482 MockControl connectionControl = MockControl.createStrictControl(Connection .class); 483 Connection connection = (Connection ) connectionControl.getMock(); 484 MockControl interactionControl = MockControl.createStrictControl(Interaction .class); 485 Interaction interaction = (Interaction ) interactionControl.getMock(); 486 MockControl generatorControl = MockControl.createStrictControl(RecordCreator.class); 487 RecordCreator generator = (RecordCreator) generatorControl.getMock(); 488 MockControl extractorControl = MockControl.createStrictControl(RecordExtractor.class); 489 RecordExtractor extractor = (RecordExtractor) extractorControl.getMock(); 490 MockControl creatorControl = MockControl.createStrictControl(RecordCreator.class); 491 RecordCreator creator = (RecordCreator) creatorControl.getMock(); 492 493 MockControl inputRecordControl = MockControl.createStrictControl(Record .class); 494 Record inputRecord = (Record ) inputRecordControl.getMock(); 495 MockControl outputRecordControl = MockControl.createStrictControl(Record .class); 496 Record outputRecord = (Record ) outputRecordControl.getMock(); 497 498 MockControl interactionSpecControl = MockControl.createStrictControl(InteractionSpec .class); 499 InteractionSpec interactionSpec = (InteractionSpec ) interactionSpecControl.getMock(); 500 501 Object obj = new Object (); 502 503 connectionFactory.getRecordFactory(); 504 connectionFactoryControl.setReturnValue(recordFactory, 1); 505 506 connectionFactory.getConnection(); 507 connectionFactoryControl.setReturnValue(connection); 508 509 connection.createInteraction(); 510 connectionControl.setReturnValue(interaction); 511 512 creator.createRecord(recordFactory); 513 creatorControl.setReturnValue(outputRecord); 514 515 connectionFactory.getRecordFactory(); 516 connectionFactoryControl.setReturnValue(recordFactory, 1); 517 518 generator.createRecord(recordFactory); 519 generatorControl.setReturnValue(inputRecord); 520 521 interaction.execute(interactionSpec, inputRecord, outputRecord); 522 interactionControl.setReturnValue(true, 1); 523 524 extractor.extractData(outputRecord); 525 extractorControl.setReturnValue(obj); 526 527 interaction.close(); 528 interactionControl.setVoidCallable(1); 529 530 connection.close(); 531 connectionControl.setVoidCallable(1); 532 533 connectionFactoryControl.replay(); 534 connectionControl.replay(); 535 interactionControl.replay(); 536 generatorControl.replay(); 537 extractorControl.replay(); 538 creatorControl.replay(); 539 540 CciTemplate ct = new CciTemplate(connectionFactory); 541 ct.setOutputRecordCreator(creator); 542 assertEquals(obj, ct.execute(interactionSpec, generator, extractor)); 543 544 connectionFactoryControl.verify(); 545 connectionControl.verify(); 546 interactionControl.verify(); 547 generatorControl.verify(); 548 extractorControl.verify(); 549 creatorControl.verify(); 550 } 551 552 public void testTemplateExecuteInputGeneratorExtractorFalse() throws ResourceException , SQLException { 553 MockControl connectionFactoryControl = MockControl.createStrictControl(ConnectionFactory .class); 554 ConnectionFactory connectionFactory = (ConnectionFactory ) connectionFactoryControl.getMock(); 555 MockControl recordFactoryControl = MockControl.createStrictControl(RecordFactory .class); 556 RecordFactory recordFactory = (RecordFactory ) recordFactoryControl.getMock(); 557 MockControl connectionControl = MockControl.createStrictControl(Connection .class); 558 Connection connection = (Connection ) connectionControl.getMock(); 559 MockControl interactionControl = MockControl.createStrictControl(Interaction .class); 560 Interaction interaction = (Interaction ) interactionControl.getMock(); 561 MockControl generatorControl = MockControl.createStrictControl(RecordCreator.class); 562 RecordCreator generator = (RecordCreator) generatorControl.getMock(); 563 MockControl extractorControl = MockControl.createStrictControl(RecordExtractor.class); 564 RecordExtractor extractor = (RecordExtractor) extractorControl.getMock(); 565 566 MockControl inputRecordControl = MockControl.createStrictControl(Record .class); 567 Record inputRecord = (Record ) inputRecordControl.getMock(); 568 MockControl outputRecordControl = MockControl.createStrictControl(Record .class); 569 Record outputRecord = (Record ) outputRecordControl.getMock(); 570 571 MockControl interactionSpecControl = MockControl.createStrictControl(InteractionSpec .class); 572 InteractionSpec interactionSpec = (InteractionSpec ) interactionSpecControl.getMock(); 573 574 Object obj = new Object (); 575 576 connectionFactory.getRecordFactory(); 577 connectionFactoryControl.setReturnValue(recordFactory, 1); 578 579 connectionFactory.getConnection(); 580 connectionFactoryControl.setReturnValue(connection); 581 582 connection.createInteraction(); 583 connectionControl.setReturnValue(interaction); 584 585 generator.createRecord(recordFactory); 586 generatorControl.setReturnValue(inputRecord); 587 588 interaction.execute(interactionSpec, inputRecord); 589 interactionControl.setReturnValue(outputRecord, 1); 590 591 extractor.extractData(outputRecord); 592 extractorControl.setReturnValue(obj); 593 594 interaction.close(); 595 interactionControl.setVoidCallable(1); 596 597 connection.close(); 598 connectionControl.setVoidCallable(1); 599 600 connectionFactoryControl.replay(); 601 connectionControl.replay(); 602 interactionControl.replay(); 603 generatorControl.replay(); 604 extractorControl.replay(); 605 606 CciTemplate ct = new CciTemplate(connectionFactory); 607 ct.execute(interactionSpec, generator, extractor); 608 609 connectionFactoryControl.verify(); 610 connectionControl.verify(); 611 interactionControl.verify(); 612 generatorControl.verify(); 613 extractorControl.verify(); 614 } 615 616 public void testTemplateExecuteInputOutputConnectionSpec() throws ResourceException { 617 MockControl connectionFactoryControl = MockControl.createStrictControl(ConnectionFactory .class); 618 ConnectionFactory connectionFactory = (ConnectionFactory ) connectionFactoryControl.getMock(); 619 MockControl connectionControl = MockControl.createStrictControl(Connection .class); 620 Connection connection = (Connection ) connectionControl.getMock(); 621 MockControl interactionControl = MockControl.createStrictControl(Interaction .class); 622 Interaction interaction = (Interaction ) interactionControl.getMock(); 623 624 MockControl inputRecordControl = MockControl.createStrictControl(Record .class); 625 Record inputRecord = (Record ) inputRecordControl.getMock(); 626 MockControl outputRecordControl = MockControl.createStrictControl(Record .class); 627 Record outputRecord = (Record ) outputRecordControl.getMock(); 628 629 MockControl connectionSpecControl = MockControl.createStrictControl(ConnectionSpec .class); 630 ConnectionSpec connectionSpec = (ConnectionSpec ) connectionSpecControl.getMock(); 631 MockControl interactionSpecControl = MockControl.createStrictControl(InteractionSpec .class); 632 InteractionSpec interactionSpec = (InteractionSpec ) interactionSpecControl.getMock(); 633 634 connectionFactory.getConnection(connectionSpec); 635 connectionFactoryControl.setReturnValue(connection, 1); 636 637 connection.createInteraction(); 638 connectionControl.setReturnValue(interaction, 1); 639 640 interaction.execute(interactionSpec, inputRecord, outputRecord); 641 interactionControl.setReturnValue(true, 1); 642 643 interaction.close(); 644 interactionControl.setVoidCallable(1); 645 646 connection.close(); 647 connectionControl.setVoidCallable(1); 648 649 connectionFactoryControl.replay(); 650 connectionControl.replay(); 651 interactionControl.replay(); 652 653 ConnectionSpecConnectionFactoryAdapter adapter = new ConnectionSpecConnectionFactoryAdapter(); 654 adapter.setTargetConnectionFactory(connectionFactory); 655 adapter.setConnectionSpec(connectionSpec); 656 CciTemplate ct = new CciTemplate(adapter); 657 ct.execute(interactionSpec, inputRecord, outputRecord); 658 659 connectionFactoryControl.verify(); 660 connectionControl.verify(); 661 interactionControl.verify(); 662 } 663 664 public void testTemplateExecuteInputOutputResultsSetFalse() throws ResourceException , SQLException { 665 MockControl connectionFactoryControl = MockControl.createStrictControl(ConnectionFactory .class); 666 ConnectionFactory connectionFactory = (ConnectionFactory ) connectionFactoryControl.getMock(); 667 MockControl recordFactoryControl = MockControl.createStrictControl(RecordFactory .class); 668 RecordFactory recordFactory = (RecordFactory ) recordFactoryControl.getMock(); 669 MockControl connectionControl = MockControl.createStrictControl(Connection .class); 670 Connection connection = (Connection ) connectionControl.getMock(); 671 MockControl interactionControl = MockControl.createStrictControl(Interaction .class); 672 Interaction interaction = (Interaction ) interactionControl.getMock(); 673 MockControl recordControl = MockControl.createStrictControl(Record .class); 674 Record record = (Record ) recordControl.getMock(); 675 MockControl resultsetControl = MockControl.createStrictControl(ResultSet .class); 676 ResultSet resultset = (ResultSet ) resultsetControl.getMock(); 677 MockControl generatorControl = MockControl.createStrictControl(RecordCreator.class); 678 RecordCreator generator = (RecordCreator) generatorControl.getMock(); 679 MockControl extractorControl = MockControl.createStrictControl(RecordExtractor.class); 680 RecordExtractor extractor = (RecordExtractor) extractorControl.getMock(); 681 682 MockControl interactionSpecControl = MockControl.createStrictControl(InteractionSpec .class); 683 InteractionSpec interactionSpec = (InteractionSpec ) interactionSpecControl.getMock(); 684 685 Object obj = new Object (); 686 687 connectionFactory.getRecordFactory(); 688 connectionFactoryControl.setReturnValue(recordFactory, 1); 689 690 connectionFactory.getConnection(); 691 connectionFactoryControl.setReturnValue(connection); 692 693 connection.createInteraction(); 694 connectionControl.setReturnValue(interaction); 695 696 generator.createRecord(recordFactory); 697 generatorControl.setReturnValue(record); 698 699 interaction.execute(interactionSpec, record); 700 interactionControl.setReturnValue(resultset, 1); 701 702 extractor.extractData(resultset); 703 extractorControl.setReturnValue(obj); 704 705 resultset.close(); 706 resultsetControl.setVoidCallable(1); 707 708 interaction.close(); 709 interactionControl.setVoidCallable(1); 710 711 connection.close(); 712 connectionControl.setVoidCallable(1); 713 714 connectionFactoryControl.replay(); 715 connectionControl.replay(); 716 interactionControl.replay(); 717 generatorControl.replay(); 718 extractorControl.replay(); 719 resultsetControl.replay(); 720 721 CciTemplate ct = new CciTemplate(connectionFactory); 722 ct.execute(interactionSpec, generator, extractor); 723 724 connectionFactoryControl.verify(); 725 connectionControl.verify(); 726 interactionControl.verify(); 727 generatorControl.verify(); 728 extractorControl.verify(); 729 resultsetControl.verify(); 730 } 731 732 public void testTemplateExecuteConnectionCallback() throws ResourceException , SQLException { 733 MockControl connectionFactoryControl = MockControl.createStrictControl(ConnectionFactory .class); 734 ConnectionFactory connectionFactory = (ConnectionFactory ) connectionFactoryControl.getMock(); 735 MockControl connectionControl = MockControl.createStrictControl(Connection .class); 736 Connection connection = (Connection ) connectionControl.getMock(); 737 MockControl connectionCallbackControl = MockControl.createStrictControl(ConnectionCallback.class); 738 ConnectionCallback connectionCallback = (ConnectionCallback) connectionCallbackControl.getMock(); 739 740 Object obj = new Object (); 741 742 connectionFactory.getConnection(); 743 connectionFactoryControl.setReturnValue(connection); 744 745 connectionCallback.doInConnection(connection, connectionFactory); 746 connectionCallbackControl.setReturnValue(obj); 747 748 connection.close(); 749 connectionControl.setVoidCallable(1); 750 751 connectionFactoryControl.replay(); 752 connectionControl.replay(); 753 connectionCallbackControl.replay(); 754 755 CciTemplate ct = new CciTemplate(connectionFactory); 756 ct.execute(connectionCallback); 757 758 connectionFactoryControl.verify(); 759 connectionControl.verify(); 760 connectionCallbackControl.verify(); 761 } 762 763 public void testTemplateExecuteInteractionCallback() throws ResourceException , SQLException { 764 MockControl connectionFactoryControl = MockControl.createStrictControl(ConnectionFactory .class); 765 ConnectionFactory connectionFactory = (ConnectionFactory ) connectionFactoryControl.getMock(); 766 MockControl connectionControl = MockControl.createStrictControl(Connection .class); 767 Connection connection = (Connection ) connectionControl.getMock(); 768 MockControl interactionControl = MockControl.createStrictControl(Interaction .class); 769 Interaction interaction = (Interaction ) interactionControl.getMock(); 770 MockControl interactionCallbackControl = MockControl.createStrictControl(InteractionCallback.class); 771 InteractionCallback interactionCallback = (InteractionCallback) interactionCallbackControl.getMock(); 772 773 Object obj = new Object (); 774 775 connectionFactory.getConnection(); 776 connectionFactoryControl.setReturnValue(connection); 777 778 connection.createInteraction(); 779 connectionControl.setReturnValue(interaction); 780 781 interactionCallback.doInInteraction(interaction, connectionFactory); 782 interactionCallbackControl.setReturnValue(obj); 783 784 interaction.close(); 785 interactionControl.setVoidCallable(1); 786 787 connection.close(); 788 connectionControl.setVoidCallable(1); 789 790 connectionFactoryControl.replay(); 791 connectionControl.replay(); 792 interactionControl.replay(); 793 interactionCallbackControl.replay(); 794 795 CciTemplate ct = new CciTemplate(connectionFactory); 796 ct.execute(interactionCallback); 797 798 connectionFactoryControl.verify(); 799 connectionControl.verify(); 800 interactionControl.verify(); 801 interactionCallbackControl.verify(); 802 } 803 804 public void testTemplateExecuteInputTrueTrueWithCreator() throws ResourceException { 805 MockControl connectionFactoryControl = MockControl.createStrictControl(ConnectionFactory .class); 806 ConnectionFactory connectionFactory = (ConnectionFactory ) connectionFactoryControl.getMock(); 807 MockControl connectionControl = MockControl.createStrictControl(Connection .class); 808 Connection connection = (Connection ) connectionControl.getMock(); 809 MockControl interactionControl = MockControl.createStrictControl(Interaction .class); 810 Interaction interaction = (Interaction ) interactionControl.getMock(); 811 MockControl creatorControl = MockControl.createStrictControl(RecordCreator.class); 812 RecordCreator creator = (RecordCreator) creatorControl.getMock(); 813 814 MockControl inputOutputRecordControl = MockControl.createStrictControl(Record .class); 815 Record inputOutputRecord = (Record ) inputOutputRecordControl.getMock(); 816 817 MockControl interactionSpecControl = MockControl.createStrictControl(InteractionSpec .class); 818 InteractionSpec interactionSpec = (InteractionSpec ) interactionSpecControl.getMock(); 819 820 connectionFactory.getConnection(); 821 connectionFactoryControl.setReturnValue(connection); 822 823 connection.createInteraction(); 824 connectionControl.setReturnValue(interaction); 825 826 interaction.execute(interactionSpec, inputOutputRecord, inputOutputRecord); 827 interactionControl.setReturnValue(true, 1); 828 829 interaction.close(); 830 interactionControl.setVoidCallable(1); 831 832 connection.close(); 833 connectionControl.setVoidCallable(1); 834 835 connectionFactoryControl.replay(); 836 connectionControl.replay(); 837 interactionControl.replay(); 838 creatorControl.replay(); 839 840 CciTemplate ct = new CciTemplate(connectionFactory); 841 ct.setOutputRecordCreator(creator); 842 ct.execute(interactionSpec, inputOutputRecord, inputOutputRecord); 843 844 connectionFactoryControl.verify(); 845 connectionControl.verify(); 846 interactionControl.verify(); 847 creatorControl.verify(); 848 } 849 850 public void testTemplateExecuteInputTrueTrue() throws ResourceException { 851 MockControl connectionFactoryControl = MockControl.createStrictControl(ConnectionFactory .class); 852 ConnectionFactory connectionFactory = (ConnectionFactory ) connectionFactoryControl.getMock(); 853 MockControl connectionControl = MockControl.createStrictControl(Connection .class); 854 Connection connection = (Connection ) connectionControl.getMock(); 855 MockControl interactionControl = MockControl.createStrictControl(Interaction .class); 856 Interaction interaction = (Interaction ) interactionControl.getMock(); 857 858 MockControl inputOutputRecordControl = MockControl.createStrictControl(Record .class); 859 Record inputOutputRecord = (Record ) inputOutputRecordControl.getMock(); 860 861 MockControl interactionSpecControl = MockControl.createStrictControl(InteractionSpec .class); 862 InteractionSpec interactionSpec = (InteractionSpec ) interactionSpecControl.getMock(); 863 864 connectionFactory.getConnection(); 865 connectionFactoryControl.setReturnValue(connection); 866 867 connection.createInteraction(); 868 connectionControl.setReturnValue(interaction); 869 870 interaction.execute(interactionSpec, inputOutputRecord, inputOutputRecord); 871 interactionControl.setReturnValue(true, 1); 872 873 interaction.close(); 874 interactionControl.setVoidCallable(1); 875 876 connection.close(); 877 connectionControl.setVoidCallable(1); 878 879 connectionFactoryControl.replay(); 880 connectionControl.replay(); 881 interactionControl.replay(); 882 883 CciTemplate ct = new CciTemplate(connectionFactory); 884 ct.execute(interactionSpec, inputOutputRecord, inputOutputRecord); 885 886 connectionFactoryControl.verify(); 887 connectionControl.verify(); 888 interactionControl.verify(); 889 } 890 891 public void testTemplateExecuteInputFalseTrue() throws ResourceException { 892 MockControl connectionFactoryControl = MockControl.createStrictControl(ConnectionFactory .class); 893 ConnectionFactory connectionFactory = (ConnectionFactory ) connectionFactoryControl.getMock(); 894 MockControl connectionControl = MockControl.createStrictControl(Connection .class); 895 Connection connection = (Connection ) connectionControl.getMock(); 896 MockControl interactionControl = MockControl.createStrictControl(Interaction .class); 897 Interaction interaction = (Interaction ) interactionControl.getMock(); 898 899 MockControl inputOutputRecordControl = MockControl.createStrictControl(Record .class); 900 Record inputOutputRecord = (Record ) inputOutputRecordControl.getMock(); 901 902 MockControl interactionSpecControl = MockControl.createStrictControl(InteractionSpec .class); 903 InteractionSpec interactionSpec = (InteractionSpec ) interactionSpecControl.getMock(); 904 905 connectionFactory.getConnection(); 906 connectionFactoryControl.setReturnValue(connection); 907 908 connection.createInteraction(); 909 connectionControl.setReturnValue(interaction); 910 911 interaction.execute(interactionSpec, inputOutputRecord); 912 interactionControl.setReturnValue(null, 1); 913 914 interaction.close(); 915 interactionControl.setVoidCallable(1); 916 917 connection.close(); 918 connectionControl.setVoidCallable(1); 919 920 connectionFactoryControl.replay(); 921 connectionControl.replay(); 922 interactionControl.replay(); 923 924 CciTemplate ct = new CciTemplate(connectionFactory); 925 Record tmpOutputRecord = (Record ) ct.execute(interactionSpec, inputOutputRecord); 926 assertNull(tmpOutputRecord); 927 928 connectionFactoryControl.verify(); 929 connectionControl.verify(); 930 interactionControl.verify(); 931 } 932 933 } 934 | Popular Tags |