Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Commit

Permalink
* test URI strings and test the connection
Browse files Browse the repository at this point in the history
* test jdbc URI strings for jruby only

* test URIs which come in as DataObject::URI
  • Loading branch information
mkristian committed Nov 21, 2009
1 parent 9c24ffe commit 7c88b55
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 5 deletions.
7 changes: 4 additions & 3 deletions data_objects/lib/data_objects/connection.rb
Expand Up @@ -20,12 +20,13 @@ def self.new(uri_s)
when :jdbc
warn 'JDBC URLs (connection strings) are only for use with JRuby' unless RUBY_PLATFORM =~ /java/

driver_name = if uri.path.split(':').first == 'sqlite'
path = uri.path.sub(/jdbc:/, '')
driver_name = if path.split(':').first == 'sqlite'
'sqlite3'
elsif uri.path.split(':').first == 'postgresql'
elsif path.split(':').first == 'postgresql'
'postgres'
else
uri.path.split(':').first
path.split(':').first
end

conn_uri = uri_s # NOTE: for now, do not reformat this JDBC connection
Expand Down
37 changes: 37 additions & 0 deletions data_objects/lib/data_objects/spec/connection_spec.rb
Expand Up @@ -60,6 +60,43 @@
it { @connection.create_command('This is a dummy command').should be_kind_of(DataObjects::Command) }
end

describe 'various connection URIs' do

def test_connection(conn)
reader = conn.create_command(CONFIG.testsql || "SELECT 1").execute_reader
reader.next!
reader.values[0]
end

after do
@open_connection.close if @open_connection
end

it 'should open with an uri object' do
uri = DataObjects::URI.new(
@driver,
@user,
@password,
@host,
@port.to_i,
@database,
nil, nil
)
test_connection(DataObjects::Connection.new(uri)).should == 1
end

it 'should work with non jdbc URIs' do
conn = DataObjects::Connection.new("#{CONFIG.uri.sub(/jdbc:/, '')}")
test_connection(conn).should == 1
end

if JRUBY
it 'should work with jdbc URIs' do
conn = DataObjects::Connection.new(CONFIG.jdbc_uri || "jdbc:#{CONFIG.uri.sub(/jdbc:/, '')}")
test_connection(conn).should == 1
end
end
end
end

share_examples_for 'a Connection with authentication support' do
Expand Down
1 change: 1 addition & 0 deletions do_derby/spec/spec_helper.rb
Expand Up @@ -52,6 +52,7 @@
# CONFIG.database = ENV['DO_DERBY_DATABASE'] || "#{File.expand_path(File.dirname(__FILE__))}/testdb"

CONFIG.uri = ENV["DO_DERBY_SPEC_URI"] || "jdbc:derby:testdb;create=true"
CONFIG.testsql = "SELECT 1 FROM SYSIBM.SYSDUMMY1"

module DataObjectsSpecHelpers

Expand Down
1 change: 1 addition & 0 deletions do_hsqldb/spec/spec_helper.rb
Expand Up @@ -52,6 +52,7 @@
# CONFIG.database = ENV['DO_HSQLDB_DATABASE'] || "#{File.expand_path(File.dirname(__FILE__))}/testdb"

CONFIG.uri = ENV["DO_HSQLDB_SPEC_URI"] || "jdbc:hsqldb:mem:test"
CONFIG.testsql = "select 1 from INFORMATION_SCHEMA.SYSTEM_USERS"

module DataObjectsSpecHelpers

Expand Down
2 changes: 1 addition & 1 deletion do_jdbc/src/main/java/data_objects/Connection.java
Expand Up @@ -23,9 +23,9 @@
import org.jruby.runtime.Arity;
import org.jruby.runtime.Block;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.Visibility;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.callback.Callback;
import org.jruby.runtime.Visibility;

import data_objects.drivers.DriverDefinition;
import data_objects.util.JDBCUtil;
Expand Down
Expand Up @@ -177,7 +177,7 @@ public URI parseConnectionURI(IRubyObject connection_uri)

if (user != null && !"".equals(user)) {
userInfo.append(user);
if (password != null && !"".equals(password)) {
if (password != null) {
userInfo.append(":").append(password);
}
}
Expand Down
1 change: 1 addition & 0 deletions do_oracle/spec/spec_helper.rb
Expand Up @@ -56,6 +56,7 @@

CONFIG.uri = ENV["DO_ORACLE_SPEC_URI"] ||"#{CONFIG.scheme}://#{CONFIG.user}:#{CONFIG.pass}@#{CONFIG.host}:#{CONFIG.port}#{CONFIG.database}"
CONFIG.sleep = "BEGIN SYS.DBMS_LOCK.sleep(seconds => 1); END;"
CONFIG.testsql = "SELECT 1 FROM dual"

module DataObjectsSpecHelpers

Expand Down
1 change: 1 addition & 0 deletions do_postgres/spec/spec_helper.rb
Expand Up @@ -56,6 +56,7 @@
CONFIG.database = ENV['DO_POSTGRES_DATABASE'] || '/do_test'

CONFIG.uri = ENV["DO_POSTGRES_SPEC_URI"] ||"#{CONFIG.scheme}://#{CONFIG.user_info}#{CONFIG.host}:#{CONFIG.port}#{CONFIG.database}"
CONFIG.jdbc_uri = CONFIG.uri.sub(/postgres/,"jdbc:postgresql")
CONFIG.sleep = "SELECT pg_sleep(1)"

module DataObjectsSpecHelpers
Expand Down
1 change: 1 addition & 0 deletions do_sqlite3/spec/spec_helper.rb
Expand Up @@ -48,6 +48,7 @@

CONFIG.uri = ENV["DO_SQLITE3_SPEC_URI"] || "#{CONFIG.scheme}://#{CONFIG.database}"
CONFIG.jdbc_driver = 'org.sqlite.JDBC'
CONFIG.jdbc_uri = CONFIG.uri.sub(/postgres/,"jdbc:postgresql")

module DataObjectsSpecHelpers

Expand Down

0 comments on commit 7c88b55

Please sign in to comment.