Permalink
Browse files

first working version. Everything green

  • Loading branch information...
1 parent f5b730c commit 7b6994d24fbbe336221e5f865956b8c6f454f472 @calavera calavera committed Mar 25, 2010
Showing with 26 additions and 8 deletions.
  1. +12 −4 lib/trinidad-dbpool/webapp_addon.rb
  2. +2 −2 spec/spec_helper.rb
  3. +12 −2 spec/trinidad_mysql_dbpool_extension_spec.rb
@@ -3,25 +3,33 @@ class DbpoolWebAppAddon
def configure(*args)
puts 'Configuring database connection pool'
splat = args.flatten
- create_resource(splat[0], splat[1], splat[2])
+ create_resource(splat[0], splat[1], splat[2], splat[3])
end
- def create_resource(app_context, class_loader, options)
+ def create_resource(tomcat, app_context, class_loader, options)
+ extension_name = options.delete('name')
+ jndi = options.delete('jndi')
+
resource = Trinidad::Tomcat::ContextResource.new
resource.setAuth("Container")
- resource.setName(options.delete('name'))
+ resource.setName(jndi)
resource.setType("javax.sql.DataSource")
resource.setDescription(options.delete('description')) if options.has_key?('description')
options.each do |key, value|
resource.setProperty(key.to_s, value.to_s)
end
- add_library_to_class_loader(class_loader, File.dirname(__FILE__) + '/../../trinidad-libs/tomcat-dbcp.jar')
add_library_to_class_loader(class_loader, driver_jar)
resource.setProperty("driverClassName", driver_name)
app_context.naming_resources.add_resource(resource)
+ app_context.naming_resources = resource.naming_resources
+
+ resource_context = tomcat.addContext("/#{extension_name}", '.')
+ resource_context.naming_resources.addResource(resource)
+ resource_context.naming_resources = resource.naming_resources
+
resource
end
View
@@ -5,6 +5,6 @@
require 'trinidad-mysql-dbpool-extension'
require 'spec'
-Spec::Runner.configure do |config|
-
+Spec::Runner.configure do |config|
+ config.mock_with :mocha
end
@@ -5,9 +5,19 @@
@addon = Trinidad::MysqlDbpoolWebAppAddon.new
@class_loader = org.jruby.util.JRubyClassLoader.new(JRuby.runtime.jruby_class_loader)
@context = Trinidad::Tomcat::StandardContext.new
+
+ @tomcat = mock
+ resource_context = mock
+ naming = mock
+
+ naming.stubs(:addResource)
+ resource_context.stubs(:naming_resources).returns(naming)
+ resource_context.stubs(:naming_resources=)
+ @tomcat.stubs(:addContext).returns(resource_context)
@opts = {
- 'name' => 'jdbc/TestDB'
+ 'name' => 'test',
+ 'jndi' => 'jdbc/TestDB'
}
end
@@ -37,6 +47,6 @@
end
def configure_addon
- @addon.configure(@context, @class_loader, @opts)
+ @addon.configure(@tomcat, @context, @class_loader, @opts)
end
end

0 comments on commit 7b6994d

Please sign in to comment.