|
483 | 483 | end |
484 | 484 | end |
485 | 485 |
|
486 | | - it "should use SID syntax when database starts with colon" do |
487 | | - url = PLSQL::JDBCConnection.jdbc_connection_url(host: "myhost", port: 1521, database: ":MYSID") |
488 | | - expect(url).to eq "jdbc:oracle:thin:@myhost:1521:MYSID" |
| 486 | + it "should use SID syntax when database starts with colon (deprecated)" do |
| 487 | + expect { |
| 488 | + url = PLSQL::JDBCConnection.jdbc_connection_url(host: "myhost", port: 1521, database: ":MYSID") |
| 489 | + expect(url).to eq "jdbc:oracle:thin:@myhost:1521:MYSID" |
| 490 | + }.to output(/deprecated/).to_stderr |
489 | 491 | end |
490 | 492 |
|
491 | 493 | it "should use service name syntax when database starts with slash" do |
|
515 | 517 | end |
516 | 518 | end |
517 | 519 |
|
518 | | - it "should use SID syntax when TNS_ADMIN is set and database starts with colon" do |
| 520 | + it "should use SID syntax when TNS_ADMIN is set and database starts with colon (deprecated)" do |
519 | 521 | original_tns_admin = ENV["TNS_ADMIN"] |
520 | 522 | ENV["TNS_ADMIN"] = "/path/to/tns" |
521 | 523 | begin |
522 | | - url = PLSQL::JDBCConnection.jdbc_connection_url(database: ":MYSID") |
523 | | - expect(url).to eq "jdbc:oracle:thin:@localhost:1521:MYSID" |
| 524 | + expect { |
| 525 | + url = PLSQL::JDBCConnection.jdbc_connection_url(database: ":MYSID") |
| 526 | + expect(url).to eq "jdbc:oracle:thin:@localhost:1521:MYSID" |
| 527 | + }.to output(/deprecated/).to_stderr |
524 | 528 | ensure |
525 | 529 | ENV["TNS_ADMIN"] = original_tns_admin |
526 | 530 | end |
|
537 | 541 | url = PLSQL::JDBCConnection.jdbc_connection_url(host: "myhost", database: "MYSERVICENAME", url: custom_url) |
538 | 542 | expect(url).to eq custom_url |
539 | 543 | end |
| 544 | + |
| 545 | + context ":sid option" do |
| 546 | + it "builds SID URL form" do |
| 547 | + url = PLSQL::JDBCConnection.jdbc_connection_url(host: "myhost", port: 1521, sid: "MYSID") |
| 548 | + expect(url).to eq "jdbc:oracle:thin:@myhost:1521:MYSID" |
| 549 | + end |
| 550 | + |
| 551 | + it "defaults host and port when not specified" do |
| 552 | + url = PLSQL::JDBCConnection.jdbc_connection_url(sid: "MYSID") |
| 553 | + expect(url).to eq "jdbc:oracle:thin:@localhost:1521:MYSID" |
| 554 | + end |
| 555 | + |
| 556 | + it "rejects values starting with '/'" do |
| 557 | + expect { |
| 558 | + PLSQL::JDBCConnection.jdbc_connection_url(sid: "/MYSID") |
| 559 | + }.to raise_error(ArgumentError, /Invalid :sid value/) |
| 560 | + end |
| 561 | + |
| 562 | + it "rejects values starting with ':'" do |
| 563 | + expect { |
| 564 | + PLSQL::JDBCConnection.jdbc_connection_url(sid: ":MYSID") |
| 565 | + }.to raise_error(ArgumentError, /Invalid :sid value/) |
| 566 | + end |
| 567 | + |
| 568 | + it "rejects TNS connect descriptors" do |
| 569 | + expect { |
| 570 | + PLSQL::JDBCConnection.jdbc_connection_url( |
| 571 | + sid: "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=foo)(PORT=1521))(CONNECT_DATA=(SID=XE)))" |
| 572 | + ) |
| 573 | + }.to raise_error(ArgumentError, /Invalid :sid value/) |
| 574 | + end |
| 575 | + end |
| 576 | + |
| 577 | + context ":service_name option" do |
| 578 | + it "builds service-name URL form" do |
| 579 | + url = PLSQL::JDBCConnection.jdbc_connection_url(host: "myhost", port: 1521, service_name: "MYSVC") |
| 580 | + expect(url).to eq "jdbc:oracle:thin:@//myhost:1521/MYSVC" |
| 581 | + end |
| 582 | + |
| 583 | + it "rejects values starting with '/'" do |
| 584 | + expect { |
| 585 | + PLSQL::JDBCConnection.jdbc_connection_url(service_name: "/MYSVC") |
| 586 | + }.to raise_error(ArgumentError, /Invalid :service_name value/) |
| 587 | + end |
| 588 | + end |
| 589 | + |
| 590 | + context "mutual exclusion" do |
| 591 | + it "raises when :database and :service_name are both set" do |
| 592 | + expect { |
| 593 | + PLSQL::JDBCConnection.jdbc_connection_url(database: "X", service_name: "Y") |
| 594 | + }.to raise_error(ArgumentError, /Cannot specify more than one of :database, :service_name/) |
| 595 | + end |
| 596 | + |
| 597 | + it "raises when :database and :sid are both set" do |
| 598 | + expect { |
| 599 | + PLSQL::JDBCConnection.jdbc_connection_url(database: "X", sid: "Y") |
| 600 | + }.to raise_error(ArgumentError, /Cannot specify more than one of :database, :sid/) |
| 601 | + end |
| 602 | + |
| 603 | + it "raises when :service_name and :sid are both set" do |
| 604 | + expect { |
| 605 | + PLSQL::JDBCConnection.jdbc_connection_url(service_name: "X", sid: "Y") |
| 606 | + }.to raise_error(ArgumentError, /Cannot specify more than one of :service_name, :sid/) |
| 607 | + end |
| 608 | + |
| 609 | + it "raises when all three are set" do |
| 610 | + expect { |
| 611 | + PLSQL::JDBCConnection.jdbc_connection_url(database: "X", service_name: "Y", sid: "Z") |
| 612 | + }.to raise_error(ArgumentError, /Cannot specify more than one of :database, :service_name, :sid/) |
| 613 | + end |
| 614 | + end |
540 | 615 | end if defined?(JRuby) |
541 | 616 |
|
| 617 | + describe "OCI connection string" do |
| 618 | + def captured_connection_string(params) |
| 619 | + captured = nil |
| 620 | + stub_oci8 = Class.new do |
| 621 | + define_singleton_method(:new) do |_user, _password, conn_str| |
| 622 | + captured = conn_str |
| 623 | + Object.new |
| 624 | + end |
| 625 | + end |
| 626 | + stub_const("OCI8", stub_oci8) |
| 627 | + PLSQL::OCIConnection.create_raw({ username: "u", password: "p" }.merge(params)) |
| 628 | + captured |
| 629 | + end |
| 630 | + |
| 631 | + context ":sid option" do |
| 632 | + it "builds an inline TNS connect descriptor" do |
| 633 | + conn_str = captured_connection_string(host: "myhost", port: 1521, sid: "MYSID") |
| 634 | + expect(conn_str).to eq "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=myhost)(PORT=1521))(CONNECT_DATA=(SID=MYSID)))" |
| 635 | + end |
| 636 | + |
| 637 | + it "defaults host and port when not specified" do |
| 638 | + conn_str = captured_connection_string(sid: "MYSID") |
| 639 | + expect(conn_str).to eq "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SID=MYSID)))" |
| 640 | + end |
| 641 | + |
| 642 | + it "rejects values starting with ':'" do |
| 643 | + expect { |
| 644 | + captured_connection_string(sid: ":MYSID") |
| 645 | + }.to raise_error(ArgumentError, /Invalid :sid value/) |
| 646 | + end |
| 647 | + end |
| 648 | + |
| 649 | + context ":service_name option" do |
| 650 | + it "builds the EZCONNECT-style connection string" do |
| 651 | + conn_str = captured_connection_string(host: "myhost", port: 1521, service_name: "MYSVC") |
| 652 | + expect(conn_str).to eq "//myhost:1521/MYSVC" |
| 653 | + end |
| 654 | + |
| 655 | + it "rejects values starting with '/'" do |
| 656 | + expect { |
| 657 | + captured_connection_string(service_name: "/MYSVC") |
| 658 | + }.to raise_error(ArgumentError, /Invalid :service_name value/) |
| 659 | + end |
| 660 | + end |
| 661 | + |
| 662 | + context "mutual exclusion" do |
| 663 | + it "raises when :database and :sid are both set" do |
| 664 | + expect { |
| 665 | + captured_connection_string(database: "X", sid: "Y") |
| 666 | + }.to raise_error(ArgumentError, /Cannot specify more than one of :database, :sid/) |
| 667 | + end |
| 668 | + |
| 669 | + it "raises when :service_name and :sid are both set" do |
| 670 | + expect { |
| 671 | + captured_connection_string(service_name: "X", sid: "Y") |
| 672 | + }.to raise_error(ArgumentError, /Cannot specify more than one of :service_name, :sid/) |
| 673 | + end |
| 674 | + end |
| 675 | + end unless defined?(JRuby) |
| 676 | + |
542 | 677 | describe "logoff" do |
543 | 678 | before(:each) do |
544 | 679 | # restore connection before each test |
|
0 commit comments