|
467 | 467 |
|
468 | 468 | end |
469 | 469 |
|
| 470 | + describe "JDBC connection URL" do |
| 471 | + it "should use service name syntax by default" do |
| 472 | + url = PLSQL::JDBCConnection.jdbc_connection_url(host: "myhost", port: 1521, database: "MYSERVICENAME") |
| 473 | + expect(url).to eq "jdbc:oracle:thin:@//myhost:1521/MYSERVICENAME" |
| 474 | + end |
| 475 | + |
| 476 | + it "should use default host and port when not specified" do |
| 477 | + original_tns_admin = ENV.delete("TNS_ADMIN") |
| 478 | + begin |
| 479 | + url = PLSQL::JDBCConnection.jdbc_connection_url(database: "/MYSERVICENAME") |
| 480 | + expect(url).to eq "jdbc:oracle:thin:@//localhost:1521/MYSERVICENAME" |
| 481 | + ensure |
| 482 | + ENV["TNS_ADMIN"] = original_tns_admin |
| 483 | + end |
| 484 | + end |
| 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" |
| 489 | + end |
| 490 | + |
| 491 | + it "should use service name syntax when database starts with slash" do |
| 492 | + url = PLSQL::JDBCConnection.jdbc_connection_url(host: "myhost", port: 1521, database: "/MYSERVICENAME") |
| 493 | + expect(url).to eq "jdbc:oracle:thin:@//myhost:1521/MYSERVICENAME" |
| 494 | + end |
| 495 | + |
| 496 | + it "should use TNS alias when TNS_ADMIN is set and no host specified" do |
| 497 | + original_tns_admin = ENV["TNS_ADMIN"] |
| 498 | + ENV["TNS_ADMIN"] = "/path/to/tns" |
| 499 | + begin |
| 500 | + url = PLSQL::JDBCConnection.jdbc_connection_url(database: "MYALIAS") |
| 501 | + expect(url).to eq "jdbc:oracle:thin:@MYALIAS" |
| 502 | + ensure |
| 503 | + ENV["TNS_ADMIN"] = original_tns_admin |
| 504 | + end |
| 505 | + end |
| 506 | + |
| 507 | + it "should use service name syntax when TNS_ADMIN is set and database starts with slash" do |
| 508 | + original_tns_admin = ENV["TNS_ADMIN"] |
| 509 | + ENV["TNS_ADMIN"] = "/path/to/tns" |
| 510 | + begin |
| 511 | + url = PLSQL::JDBCConnection.jdbc_connection_url(database: "/MYSERVICENAME") |
| 512 | + expect(url).to eq "jdbc:oracle:thin:@//localhost:1521/MYSERVICENAME" |
| 513 | + ensure |
| 514 | + ENV["TNS_ADMIN"] = original_tns_admin |
| 515 | + end |
| 516 | + end |
| 517 | + |
| 518 | + it "should use SID syntax when TNS_ADMIN is set and database starts with colon" do |
| 519 | + original_tns_admin = ENV["TNS_ADMIN"] |
| 520 | + ENV["TNS_ADMIN"] = "/path/to/tns" |
| 521 | + begin |
| 522 | + url = PLSQL::JDBCConnection.jdbc_connection_url(database: ":MYSID") |
| 523 | + expect(url).to eq "jdbc:oracle:thin:@localhost:1521:MYSID" |
| 524 | + ensure |
| 525 | + ENV["TNS_ADMIN"] = original_tns_admin |
| 526 | + end |
| 527 | + end |
| 528 | + |
| 529 | + it "should raise ArgumentError when database and url are not provided" do |
| 530 | + expect { |
| 531 | + PLSQL::JDBCConnection.jdbc_connection_url(host: "myhost") |
| 532 | + }.to raise_error(ArgumentError, /database or url option is required/) |
| 533 | + end |
| 534 | + |
| 535 | + it "should use custom URL when provided" do |
| 536 | + custom_url = "jdbc:oracle:thin:@//custom:1522/MYSERVICENAME" |
| 537 | + url = PLSQL::JDBCConnection.jdbc_connection_url(host: "myhost", database: "MYSERVICENAME", url: custom_url) |
| 538 | + expect(url).to eq custom_url |
| 539 | + end |
| 540 | + end if defined?(JRuby) |
| 541 | + |
470 | 542 | describe "logoff" do |
471 | 543 | before(:each) do |
472 | 544 | # restore connection before each test |
|
0 commit comments