1 20 21 package org.apache.directory.ldapstudio.dsmlv2.batchRequest; 22 23 24 import java.util.List ; 25 26 import org.apache.directory.ldapstudio.dsmlv2.AbstractTest; 27 import org.apache.directory.ldapstudio.dsmlv2.Dsmlv2Parser; 28 import org.apache.directory.ldapstudio.dsmlv2.request.BatchRequest; 29 import org.apache.directory.shared.ldap.codec.LdapMessage; 30 import org.apache.directory.shared.ldap.codec.abandon.AbandonRequest; 31 import org.apache.directory.shared.ldap.codec.add.AddRequest; 32 import org.apache.directory.shared.ldap.codec.bind.BindRequest; 33 import org.apache.directory.shared.ldap.codec.compare.CompareRequest; 34 import org.apache.directory.shared.ldap.codec.del.DelRequest; 35 import org.apache.directory.shared.ldap.codec.extended.ExtendedRequest; 36 import org.apache.directory.shared.ldap.codec.modify.ModifyRequest; 37 import org.apache.directory.shared.ldap.codec.modifyDn.ModifyDNRequest; 38 import org.apache.directory.shared.ldap.codec.search.SearchRequest; 39 40 41 47 public class BatchRequestTest extends AbstractTest 48 { 49 52 public void testResponseWithRequestId() 53 { 54 Dsmlv2Parser parser = null; 55 try 56 { 57 parser = new Dsmlv2Parser(); 58 59 parser 60 .setInputFile( BatchRequestTest.class.getResource( "request_with_requestID_attribute.xml" ).getFile() ); 61 62 parser.parse(); 63 } 64 catch ( Exception e ) 65 { 66 fail( e.getMessage() ); 67 } 68 69 BatchRequest batchRequest = parser.getBatchRequest(); 70 71 assertEquals( 1234567890, batchRequest.getRequestID() ); 72 } 73 74 77 public void testRequestWithRequestIdEquals0() 78 { 79 testParsingFail( BatchRequestTest.class, "request_with_requestID_equals_0.xml" ); 80 } 81 82 83 86 public void testResponseWith0Request() 87 { 88 Dsmlv2Parser parser = null; 89 try 90 { 91 parser = new Dsmlv2Parser(); 92 93 parser 94 .setInputFile( BatchRequestTest.class.getResource( "request_with_requestID_attribute.xml" ).getFile() ); 95 96 parser.parse(); 97 } 98 catch ( Exception e ) 99 { 100 fail( e.getMessage() ); 101 } 102 103 BatchRequest batchRequest = parser.getBatchRequest(); 104 105 assertEquals( 0, batchRequest.getRequests().size() ); 106 } 107 108 109 112 public void testResponseWith1AuthRequest() 113 { 114 Dsmlv2Parser parser = null; 115 try 116 { 117 parser = new Dsmlv2Parser(); 118 119 parser.setInputFile( BatchRequestTest.class.getResource( "request_with_1_AuthRequest.xml" ).getFile() ); 120 121 parser.parse(); 122 } 123 catch ( Exception e ) 124 { 125 fail( e.getMessage() ); 126 } 127 128 BatchRequest batchRequest = parser.getBatchRequest(); 129 130 assertEquals( 1, batchRequest.getRequests().size() ); 131 132 LdapMessage request = batchRequest.getCurrentRequest(); 133 134 if ( request instanceof BindRequest ) 135 { 136 assertTrue( true ); 137 } 138 else 139 { 140 fail(); 141 } 142 } 143 144 145 148 public void testResponseWith1AddRequest() 149 { 150 Dsmlv2Parser parser = null; 151 try 152 { 153 parser = new Dsmlv2Parser(); 154 155 parser.setInputFile( BatchRequestTest.class.getResource( "request_with_1_AddRequest.xml" ).getFile() ); 156 157 parser.parse(); 158 } 159 catch ( Exception e ) 160 { 161 fail( e.getMessage() ); 162 } 163 164 BatchRequest batchRequest = parser.getBatchRequest(); 165 166 assertEquals( 1, batchRequest.getRequests().size() ); 167 168 LdapMessage request = batchRequest.getCurrentRequest(); 169 170 if ( request instanceof AddRequest ) 171 { 172 assertTrue( true ); 173 } 174 else 175 { 176 fail(); 177 } 178 } 179 180 181 184 public void testResponseWith1CompareRequest() 185 { 186 Dsmlv2Parser parser = null; 187 try 188 { 189 parser = new Dsmlv2Parser(); 190 191 parser.setInputFile( BatchRequestTest.class.getResource( "request_with_1_CompareRequest.xml" ).getFile() ); 192 193 parser.parse(); 194 } 195 catch ( Exception e ) 196 { 197 fail( e.getMessage() ); 198 } 199 200 BatchRequest batchRequest = parser.getBatchRequest(); 201 202 assertEquals( 1, batchRequest.getRequests().size() ); 203 204 LdapMessage request = batchRequest.getCurrentRequest(); 205 206 if ( request instanceof CompareRequest ) 207 { 208 assertTrue( true ); 209 } 210 else 211 { 212 fail(); 213 } 214 } 215 216 217 220 public void testResponseWith1AbandonRequest() 221 { 222 Dsmlv2Parser parser = null; 223 try 224 { 225 parser = new Dsmlv2Parser(); 226 227 parser.setInputFile( BatchRequestTest.class.getResource( "request_with_1_AbandonRequest.xml" ).getFile() ); 228 229 parser.parse(); 230 } 231 catch ( Exception e ) 232 { 233 fail( e.getMessage() ); 234 } 235 236 BatchRequest batchRequest = parser.getBatchRequest(); 237 238 assertEquals( 1, batchRequest.getRequests().size() ); 239 240 LdapMessage request = batchRequest.getCurrentRequest(); 241 242 if ( request instanceof AbandonRequest ) 243 { 244 assertTrue( true ); 245 } 246 else 247 { 248 fail(); 249 } 250 } 251 252 253 256 public void testResponseWith1DelRequest() 257 { 258 Dsmlv2Parser parser = null; 259 try 260 { 261 parser = new Dsmlv2Parser(); 262 263 parser.setInputFile( BatchRequestTest.class.getResource( "request_with_1_DelRequest.xml" ).getFile() ); 264 265 parser.parse(); 266 } 267 catch ( Exception e ) 268 { 269 fail( e.getMessage() ); 270 } 271 272 BatchRequest batchRequest = parser.getBatchRequest(); 273 274 assertEquals( 1, batchRequest.getRequests().size() ); 275 276 LdapMessage request = batchRequest.getCurrentRequest(); 277 278 if ( request instanceof DelRequest ) 279 { 280 assertTrue( true ); 281 } 282 else 283 { 284 fail(); 285 } 286 } 287 288 289 292 public void testResponseWith1ExtendedRequest() 293 { 294 Dsmlv2Parser parser = null; 295 try 296 { 297 parser = new Dsmlv2Parser(); 298 299 parser.setInputFile( BatchRequestTest.class.getResource( "request_with_1_ExtendedRequest.xml" ).getFile() ); 300 301 parser.parse(); 302 } 303 catch ( Exception e ) 304 { 305 fail( e.getMessage() ); 306 } 307 308 BatchRequest batchRequest = parser.getBatchRequest(); 309 310 assertEquals( 1, batchRequest.getRequests().size() ); 311 312 LdapMessage request = batchRequest.getCurrentRequest(); 313 314 if ( request instanceof ExtendedRequest ) 315 { 316 assertTrue( true ); 317 } 318 else 319 { 320 fail(); 321 } 322 } 323 324 325 328 public void testResponseWith1ModDNRequest() 329 { 330 Dsmlv2Parser parser = null; 331 try 332 { 333 parser = new Dsmlv2Parser(); 334 335 parser.setInputFile( BatchRequestTest.class.getResource( "request_with_1_ModDNRequest.xml" ).getFile() ); 336 337 parser.parse(); 338 } 339 catch ( Exception e ) 340 { 341 fail( e.getMessage() ); 342 } 343 344 BatchRequest batchRequest = parser.getBatchRequest(); 345 346 assertEquals( 1, batchRequest.getRequests().size() ); 347 348 LdapMessage request = batchRequest.getCurrentRequest(); 349 350 if ( request instanceof ModifyDNRequest ) 351 { 352 assertTrue( true ); 353 } 354 else 355 { 356 fail(); 357 } 358 } 359 360 361 364 public void testResponseWith1ModifyRequest() 365 { 366 Dsmlv2Parser parser = null; 367 try 368 { 369 parser = new Dsmlv2Parser(); 370 371 parser.setInputFile( BatchRequestTest.class.getResource( "request_with_1_ModifyRequest.xml" ).getFile() ); 372 373 parser.parse(); 374 } 375 catch ( Exception e ) 376 { 377 fail( e.getMessage() ); 378 } 379 380 BatchRequest batchRequest = parser.getBatchRequest(); 381 382 assertEquals( 1, batchRequest.getRequests().size() ); 383 384 LdapMessage request = batchRequest.getCurrentRequest(); 385 386 if ( request instanceof ModifyRequest ) 387 { 388 assertTrue( true ); 389 } 390 else 391 { 392 fail(); 393 } 394 } 395 396 397 400 public void testResponseWith1SearchRequest() 401 { 402 Dsmlv2Parser parser = null; 403 try 404 { 405 parser = new Dsmlv2Parser(); 406 407 parser.setInputFile( BatchRequestTest.class.getResource( "request_with_1_SearchRequest.xml" ).getFile() ); 408 409 parser.parse(); 410 } 411 catch ( Exception e ) 412 { 413 fail( e.getMessage() ); 414 } 415 416 BatchRequest batchRequest = parser.getBatchRequest(); 417 418 assertEquals( 1, batchRequest.getRequests().size() ); 419 420 LdapMessage request = batchRequest.getCurrentRequest(); 421 422 if ( request instanceof SearchRequest ) 423 { 424 assertTrue( true ); 425 } 426 else 427 { 428 fail(); 429 } 430 } 431 432 433 436 public void testResponseWith2AddRequest() 437 { 438 Dsmlv2Parser parser = null; 439 try 440 { 441 parser = new Dsmlv2Parser(); 442 443 parser.setInputFile( BatchRequestTest.class.getResource( "request_with_2_AddRequest.xml" ).getFile() ); 444 445 parser.parse(); 446 } 447 catch ( Exception e ) 448 { 449 fail( e.getMessage() ); 450 } 451 452 BatchRequest batchRequest = parser.getBatchRequest(); 453 454 assertEquals( 2, batchRequest.getRequests().size() ); 455 456 LdapMessage request = batchRequest.getCurrentRequest(); 457 458 if ( request instanceof AddRequest ) 459 { 460 assertTrue( true ); 461 } 462 else 463 { 464 fail(); 465 } 466 } 467 468 469 472 public void testResponseWith2CompareRequest() 473 { 474 Dsmlv2Parser parser = null; 475 try 476 { 477 parser = new Dsmlv2Parser(); 478 479 parser.setInputFile( BatchRequestTest.class.getResource( "request_with_2_CompareRequest.xml" ).getFile() ); 480 481 parser.parse(); 482 } 483 catch ( Exception e ) 484 { 485 fail( e.getMessage() ); 486 } 487 488 BatchRequest batchRequest = parser.getBatchRequest(); 489 490 assertEquals( 2, batchRequest.getRequests().size() ); 491 492 LdapMessage request = batchRequest.getCurrentRequest(); 493 494 if ( request instanceof CompareRequest ) 495 { 496 assertTrue( true ); 497 } 498 else 499 { 500 fail(); 501 } 502 } 503 504 505 508 public void testResponseWith2AbandonRequest() 509 { 510 Dsmlv2Parser parser = null; 511 try 512 { 513 parser = new Dsmlv2Parser(); 514 515 parser.setInputFile( BatchRequestTest.class.getResource( "request_with_2_AbandonRequest.xml" ).getFile() ); 516 517 parser.parse(); 518 } 519 catch ( Exception e ) 520 { 521 fail( e.getMessage() ); 522 } 523 524 BatchRequest batchRequest = parser.getBatchRequest(); 525 526 assertEquals( 2, batchRequest.getRequests().size() ); 527 528 LdapMessage request = batchRequest.getCurrentRequest(); 529 530 if ( request instanceof AbandonRequest ) 531 { 532 assertTrue( true ); 533 } 534 else 535 { 536 fail(); 537 } 538 } 539 540 541 544 public void testResponseWith2DelRequest() 545 { 546 Dsmlv2Parser parser = null; 547 try 548 { 549 parser = new Dsmlv2Parser(); 550 551 parser.setInputFile( BatchRequestTest.class.getResource( "request_with_2_DelRequest.xml" ).getFile() ); 552 553 parser.parse(); 554 } 555 catch ( Exception e ) 556 { 557 fail( e.getMessage() ); 558 } 559 560 BatchRequest batchRequest = parser.getBatchRequest(); 561 562 assertEquals( 2, batchRequest.getRequests().size() ); 563 564 LdapMessage request = batchRequest.getCurrentRequest(); 565 566 if ( request instanceof DelRequest ) 567 { 568 assertTrue( true ); 569 } 570 else 571 { 572 fail(); 573 } 574 } 575 576 577 580 public void testResponseWith2ExtendedRequest() 581 { 582 Dsmlv2Parser parser = null; 583 try 584 { 585 parser = new Dsmlv2Parser(); 586 587 parser.setInputFile( BatchRequestTest.class.getResource( "request_with_2_ExtendedRequest.xml" ).getFile() ); 588 589 parser.parse(); 590 } 591 catch ( Exception e ) 592 { 593 fail( e.getMessage() ); 594 } 595 596 BatchRequest batchRequest = parser.getBatchRequest(); 597 598 assertEquals( 2, batchRequest.getRequests().size() ); 599 600 LdapMessage request = batchRequest.getCurrentRequest(); 601 602 if ( request instanceof ExtendedRequest ) 603 { 604 assertTrue( true ); 605 } 606 else 607 { 608 fail(); 609 } 610 } 611 612 613 616 public void testResponseWith2ModDNRequest() 617 { 618 Dsmlv2Parser parser = null; 619 try 620 { 621 parser = new Dsmlv2Parser(); 622 623 parser.setInputFile( BatchRequestTest.class.getResource( "request_with_2_ModDNRequest.xml" ).getFile() ); 624 625 parser.parse(); 626 } 627 catch ( Exception e ) 628 { 629 fail( e.getMessage() ); 630 } 631 632 BatchRequest batchRequest = parser.getBatchRequest(); 633 634 assertEquals( 2, batchRequest.getRequests().size() ); 635 636 LdapMessage request = batchRequest.getCurrentRequest(); 637 638 if ( request instanceof ModifyDNRequest ) 639 { 640 assertTrue( true ); 641 } 642 else 643 { 644 fail(); 645 } 646 } 647 648 649 652 public void testResponseWith2ModifyRequest() 653 { 654 Dsmlv2Parser parser = null; 655 try 656 { 657 parser = new Dsmlv2Parser(); 658 659 parser.setInputFile( BatchRequestTest.class.getResource( "request_with_2_ModifyRequest.xml" ).getFile() ); 660 661 parser.parse(); 662 } 663 catch ( Exception e ) 664 { 665 fail( e.getMessage() ); 666 } 667 668 BatchRequest batchRequest = parser.getBatchRequest(); 669 670 assertEquals( 2, batchRequest.getRequests().size() ); 671 672 LdapMessage request = batchRequest.getCurrentRequest(); 673 674 if ( request instanceof ModifyRequest ) 675 { 676 assertTrue( true ); 677 } 678 else 679 { 680 fail(); 681 } 682 } 683 684 685 688 public void testResponseWith2SearchRequest() 689 { 690 Dsmlv2Parser parser = null; 691 try 692 { 693 parser = new Dsmlv2Parser(); 694 695 parser.setInputFile( BatchRequestTest.class.getResource( "request_with_2_SearchRequest.xml" ).getFile() ); 696 697 parser.parse(); 698 } 699 catch ( Exception e ) 700 { 701 fail( e.getMessage() ); 702 } 703 704 BatchRequest batchRequest = parser.getBatchRequest(); 705 706 assertEquals( 2, batchRequest.getRequests().size() ); 707 708 LdapMessage request = batchRequest.getCurrentRequest(); 709 710 if ( request instanceof SearchRequest ) 711 { 712 assertTrue( true ); 713 } 714 else 715 { 716 fail(); 717 } 718 } 719 720 721 724 public void testResponseWith1AuthRequestAnd1AddRequest() 725 { 726 Dsmlv2Parser parser = null; 727 try 728 { 729 parser = new Dsmlv2Parser(); 730 731 parser.setInputFile( BatchRequestTest.class.getResource( "request_with_1_AuthRequest_1_AddRequest.xml" ) 732 .getFile() ); 733 734 parser.parse(); 735 } 736 catch ( Exception e ) 737 { 738 fail( e.getMessage() ); 739 } 740 741 BatchRequest batchRequest = parser.getBatchRequest(); 742 743 List requests = batchRequest.getRequests(); 744 745 assertEquals( 2, requests.size() ); 746 747 LdapMessage request = ( LdapMessage ) requests.get( 0 ); 748 749 if ( request instanceof BindRequest ) 750 { 751 assertTrue( true ); 752 } 753 else 754 { 755 fail(); 756 } 757 758 request = ( LdapMessage ) requests.get( 1 ); 759 760 if ( request instanceof AddRequest ) 761 { 762 assertTrue( true ); 763 } 764 else 765 { 766 fail(); 767 } 768 } 769 770 771 774 public void testRequestWithWrongPlacedAuthRequest() 775 { 776 testParsingFail( BatchRequestTest.class, "request_with_wrong_placed_AuthRequest.xml" ); 777 } 778 } 779
| Popular Tags
|