Skip to content

Instantly share code, notes, and snippets.

@jrun
Created April 2, 2010 18:26
Show Gist options
  • Save jrun/353508 to your computer and use it in GitHub Desktop.
Save jrun/353508 to your computer and use it in GitHub Desktop.
An example spec_config.rb that can be used to run sequel's integration tests with JNDI
# This is an example spec_config.rb that can be used to run sequel's
# integration tests.
# jars used to run the integration tests for sqlite and mysql
#
# commons-dbcp-1.2.2.jar
# commons-pool-1.4.jar
# fscontext.jar
# mysql-connector-java-5.0.5.jar
# providerutil.jar
# sqlitejdbc-v056.jar
#
Dir[File.expand_path('~/tmp/sequel_integration_jars/*.jar')].each do |jar|
require jar
end
# Taken from activerecord-jdbc-adapter
#
require 'fileutils'
System = java.lang.System
Context = javax.naming.Context
InitialContext = javax.naming.InitialContext
Reference = javax.naming.Reference
StringRefAddr = javax.naming.StringRefAddr
System.set_property(Context::INITIAL_CONTEXT_FACTORY,
'com.sun.jndi.fscontext.RefFSContextFactory')
project_path = File.expand_path(File.dirname(__FILE__) + '/..')
jndi_dir = project_path + '/jndi_test'
jdbc_dir = jndi_dir + '/jdbc'
FileUtils.mkdir_p jdbc_dir unless File.exist?(jdbc_dir)
System.set_property(Context::PROVIDER_URL, "file://#{jndi_dir}")
ref = Reference.new('javax.sql.DataSource',
'org.apache.commons.dbcp.BasicDataSourceFactory',
nil)
# mysql
#ref.add StringRefAddr.new('driverClassName', 'org.gjt.mm.mysql.Driver')
#ref.add StringRefAddr.new('url', 'jdbc:mysql://localhost:3306/sequel_integration_tests')
#ref.add StringRefAddr.new('username', '')
#ref.add StringRefAddr.new('password', '')
# sqlite
ref.add StringRefAddr.new('driverClassName', 'org.sqlite.JDBC')
ref.add StringRefAddr.new('url', 'jdbc:sqlite::memory:')
InitialContext.new.rebind("jdbc/sequel_integration_tests", ref)
INTEGRATION_DB = Sequel.connect("jdbc:jndi:jdbc/sequel_integration_tests")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment