trinidad_jars 0.2.0 → 0.3.0.beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -11,22 +11,42 @@ This project was initially called "Tomcat-rails" but due to legal issues with th
11
11
 
12
12
  == USAGE:
13
13
 
14
- cd myrailsapp
15
- jruby -S trinidad
16
-
14
+ Rails applications:
15
+
16
+ $ cd myrailsapp
17
+ $ jruby -S trinidad
18
+
19
+ Rack applications:
20
+
21
+ $ cd myrackapplication
22
+
23
+ $ jruby -S trinidad -r path_to_rackup/rackup_file
24
+
25
+ or if the name of the file is config.ru
26
+
27
+ $ jruby -S trinidad -r path_to_rackup
28
+
29
+ or if config.ru is in the base directory
30
+
31
+ $ jruby -S trinidad -r
32
+
33
+ or if config.ru is under the directory WEB-INF
34
+
35
+ $ jruby -S trinidad
36
+
17
37
  == CONFIGURATION:
18
38
 
19
39
  Trinidad allows you to configure some parameters when the server is started from the command line, the following is a list of the currently supported options:
20
40
 
21
- * -p, --port PORT => port to bind to.
22
- * -e, --env ENVIRONMENT => rails environment.
23
- * -c, --context CONTEXT => application context path.
24
- * --lib, --jars LIBS_DIR => directory containing jars.
25
- * --classes CLASSES_DIR => directory containing classes.
26
- * --rackup [RACKUP_FILE] => run a provided rackup file instead of a rails application, by default it's config.ru.
27
- * --public PUBLIC_DIR => specify the public directory for your application, by default it's 'public'.
28
- * -t, --threadsafe => shortcut to work in threadsafe mode. Setting jruby_min_runtimes and jruby_max_runtimes to 1 in the configuration file the server behaves as the same way.
29
- * -l, --load EXTENSION_NAME => loads an extension to use its command line options.
41
+ * -p, --port PORT => port to bind to.
42
+ * -e, --env ENVIRONMENT => rails environment.
43
+ * -c, --context CONTEXT => application context path.
44
+ * --lib, --jars LIBS_DIR => directory containing jars.
45
+ * --classes CLASSES_DIR => directory containing classes.
46
+ * -r, --rackup [RACKUP_FILE] => run a provided rackup file instead of a rails application, by default it's config.ru.
47
+ * --public PUBLIC_DIR => specify the public directory for your application, by default it's 'public'.
48
+ * -t, --threadsafe => shortcut to work in threadsafe mode. Setting jruby_min_runtimes and jruby_max_runtimes to 1 in the configuration file the server behaves as the same way.
49
+ * -l, --load EXTENSION_NAME => loads an extension to use its command line options.
30
50
 
31
51
  The server can also be configured from a yaml file. If a file is not especified, the server tries to load the file <em>config/tomcat.yml</em>. Within this file you can add other options like jruby.min.runtimes(:jruby_min_runtimes) or jruby.max.runtimes(:jruby_max_runtimes).
32
52
 
@@ -44,6 +64,7 @@ From the version 0.8.0 Trinidad allows to extend the server with more Tomcat fea
44
64
  * Database connection pooling: http://github.com/calavera/trinidad-dbpool
45
65
  * Daemon, run Trinidad as a daemon: http://github.com/calavera/trinidad_daemon_extension
46
66
  * Hot deploy, do hot deploys monitorizing a temporal file, ala Passenger: http://github.com/calavera/trinidad_hotdeploy_extension
67
+ * Sandbox, management console and REST api: http://github.com/calavera/trinidad_sandbox_extension
47
68
 
48
69
  You can find further information on how to write your own extension in the wiki: http://wiki.github.com/calavera/trinidad/extensions
49
70
 
data/lib/trinidad/jars.rb CHANGED
@@ -5,9 +5,6 @@ $:.unshift(TRINIDAD_LIBS) unless
5
5
  module Trinidad
6
6
  require 'tomcat-core'
7
7
 
8
- require 'jruby-rack'
9
- require JRubyJars.jruby_rack_jar_path
10
-
11
8
  module Tomcat
12
9
  include_package 'org.apache.catalina'
13
10
  include_package 'org.apache.catalina.startup'
@@ -2,7 +2,7 @@ module Trinidad
2
2
  module Extensions
3
3
  class FooWebAppExtension < WebAppExtension
4
4
  def configure(tomcat, app_context)
5
- @options
5
+ app_context.doc_base = 'foo_app_extension' if app_context
6
6
  end
7
7
  end
8
8
 
@@ -37,4 +37,22 @@ describe Trinidad::Extensions do
37
37
  extended = Trinidad::Extensions.configure_server_extensions(extensions, tomcat)
38
38
  extended.should_not equal(tomcat)
39
39
  end
40
+
41
+ it "ignores extensions that don't exist for that scope" do
42
+ extensions = {:override_tomcat => {}}
43
+ tomcat = Trinidad::Tomcat::Tomcat.new
44
+
45
+ lambda {
46
+ Trinidad::Extensions.configure_webapp_extensions(extensions, tomcat, nil)
47
+ }.should_not raise_error
48
+ end
49
+
50
+ it "raises an error when the extension doesn't exist" do
51
+ extensions = {:foo_bar => {}}
52
+ tomcat = Trinidad::Tomcat::Tomcat.new
53
+
54
+ lambda {
55
+ Trinidad::Extensions.configure_webapp_extensions(extensions, tomcat, nil)
56
+ }.should raise_error
57
+ end
40
58
  end
@@ -17,8 +17,71 @@ EOF
17
17
  EOF
18
18
  end
19
19
 
20
+ def create_rails_web_xml
21
+ @rails_web_xml ||= config_file 'config/web.xml', <<-EOF
22
+ <?xml version="1.0" encoding="UTF-8"?>
23
+ <web-app>
24
+ <servlet>
25
+ <servlet-name>RackServlet</servlet-name>
26
+ <servlet-class>org.jruby.rack.RackServlet</servlet-class>
27
+ </servlet>
28
+
29
+ <servlet-mapping>
30
+ <servlet-name>RackServlet</servlet-name>
31
+ <url-pattern>/*</url-pattern>
32
+ </servlet-mapping>
33
+
34
+ <listener>
35
+ <listener-class>org.jruby.rack.rails.RailsServletContextListener</listener-class>
36
+ </listener>
37
+
38
+ </web-app>
39
+ EOF
40
+ end
41
+
42
+ def create_rackup_web_xml
43
+ @rackup_web_xml ||= config_file 'config/web.xml', <<-EOF
44
+ <?xml version="1.0" encoding="UTF-8"?>
45
+ <web-app>
46
+ <context-param>
47
+ <param-name>jruby.min.runtimes</param-name>
48
+ <param-value>1<param-value>
49
+ </context-param>
50
+
51
+ <context-param>
52
+ <param-name>jruby.max.runtimes</param-name>
53
+ <param-value>1</param-value>
54
+ </context-param>
55
+
56
+ <servlet>
57
+ <servlet-name>RackServlet</servlet-name>
58
+ <servlet-class>org.jruby.rack.RackServlet</servlet-class>
59
+ </servlet>
60
+
61
+ <servlet-mapping>
62
+ <servlet-name>RackServlet</servlet-name>
63
+ <url-pattern>/*</url-pattern>
64
+ </servlet-mapping>
65
+
66
+ <listener>
67
+ <listener-class>org.jruby.rack.RackServletContextListener</listener-class>
68
+ </listener>
69
+
70
+ </web-app>
71
+ EOF
72
+ end
73
+
74
+ def create_rackup_file(path = 'config')
75
+ @rackup ||= config_file File.join(path, 'config.ru'), <<-EOF
76
+ require 'rubygems'
77
+ require 'sinatra'
78
+
79
+ run App
80
+ EOF
81
+ end
82
+
20
83
  private
21
- def config_file(path, options)
22
- File.open(path, 'w') {|io| io.write(options) }
84
+ def config_file(path, content)
85
+ File.open(path, 'w') {|io| io.write(content) }
23
86
  end
24
87
  end
@@ -12,47 +12,50 @@ describe Trinidad::Server do
12
12
 
13
13
  it "enables catalina naming" do
14
14
  Trinidad::Server.new
15
- JSystem.getProperty(JContext.URL_PKG_PREFIXES).should include("org.apache.naming")
16
- JSystem.getProperty(JContext.INITIAL_CONTEXT_FACTORY).should == "org.apache.naming.java.javaURLContextFactory"
17
- JSystem.getProperty("catalina.useNaming").should == "true"
15
+ JSystem.get_property(JContext.URL_PKG_PREFIXES).should include("org.apache.naming")
16
+ JSystem.get_property(JContext.INITIAL_CONTEXT_FACTORY).should == "org.apache.naming.java.javaURLContextFactory"
17
+ JSystem.get_property("catalina.useNaming").should == "true"
18
18
  end
19
19
 
20
- it "should have ssl disabled when config param is nil" do
20
+ it "disables ssl when config param is nil" do
21
21
  server = Trinidad::Server.new
22
22
  server.ssl_enabled?.should be_false
23
23
  end
24
24
 
25
- it "should have ajp disabled when config param is nil" do
25
+ it "disables ajp when config param is nil" do
26
26
  server = Trinidad::Server.new
27
27
  server.ajp_enabled?.should be_false
28
28
  end
29
29
 
30
- it "should have ssl enabled when config param is a number" do
30
+ it "enables ssl when config param is a number" do
31
31
  server = Trinidad::Server.new({:ssl => {:port => 8443},
32
32
  :web_app_dir => MOCK_WEB_APP_DIR})
33
33
 
34
34
  server.ssl_enabled?.should be_true
35
+ File.exist?('ssl').should be_true
35
36
  end
36
37
 
37
- it "should have ajp enabled when config param is a number" do
38
+ it "enables ajp when config param is a number" do
38
39
  server = Trinidad::Server.new({:ajp => {:port => 8009}})
39
40
 
40
41
  server.ajp_enabled?.should be_true
41
42
  end
42
43
 
43
- it "should have a connector with https scheme" do
44
+ it "includes a connector with https scheme when ssl is enabled" do
44
45
  server = Trinidad::Server.new({:ssl => {:port => 8443},
45
46
  :web_app_dir => MOCK_WEB_APP_DIR})
46
47
 
47
- server.tomcat.service.findConnectors().should have(1).connectors
48
- server.tomcat.service.findConnectors()[0].scheme.should == 'https'
48
+ connectors = server.tomcat.service.find_connectors
49
+ connectors.should have(1).connector
50
+ connectors[0].scheme.should == 'https'
49
51
  end
50
52
 
51
- it "should have an ajp connector enabled" do
53
+ it "includes a connector with protocol AJP when ajp is enabled" do
52
54
  server = Trinidad::Server.new({:ajp => {:port => 8009}})
53
55
 
54
- server.tomcat.service.findConnectors().should have(1).connectors
55
- server.tomcat.service.findConnectors()[0].protocol.should == 'AJP/1.3'
56
+ connectors = server.tomcat.service.find_connectors
57
+ connectors.should have(1).connector
58
+ connectors[0].protocol.should == 'AJP/1.3'
56
59
  end
57
60
 
58
61
  it "loads one application for each option present into :web_apps" do
@@ -71,43 +74,100 @@ describe Trinidad::Server do
71
74
  }
72
75
  })
73
76
 
74
- context_loaded = server.tomcat.host.findChildren()
77
+ context_loaded = server.tomcat.host.find_children
75
78
  context_loaded.should have(3).web_apps
76
79
 
77
80
  expected = ['/mock1', '/mock2', '/']
78
81
  context_loaded.each do |context|
79
- expected.delete(context.getPath()).should == context.getPath()
82
+ expected.delete(context.path).should == context.path
80
83
  end
81
84
  end
82
85
 
83
86
  it "loads the default application from the current directory if :web_apps is not present" do
84
87
  server = Trinidad::Server.new({:web_app_dir => MOCK_WEB_APP_DIR})
85
88
 
86
- default_context_should_be_loaded(server.tomcat.host.findChildren())
89
+ default_context_should_be_loaded(server.tomcat.host.find_children)
87
90
  end
88
91
 
89
- it "loads the default application from the current directory using the rackup file if :web_apps is not present" do
92
+ it "removes default servlets from the application" do
93
+ server = Trinidad::Server.new({:web_app_dir => MOCK_WEB_APP_DIR})
94
+ app = server.tomcat.host.find_child('/')
95
+
96
+ app.find_child('default').should be_nil
97
+ app.find_child('jsp').should be_nil
98
+
99
+ app.find_servlet_mapping('*.jsp').should be_nil
100
+ app.find_servlet_mapping('*.jspx').should be_nil
101
+
102
+ app.process_tlds.should be_false
103
+ end
104
+
105
+ it "uses the default HttpConnector when http is not configured" do
106
+ server = Trinidad::Server.new({:web_app_dir => MOCK_WEB_APP_DIR})
107
+ server.http_configured?.should be_false
108
+
109
+ server.tomcat.connector.protocol_handler_class_name.should == 'org.apache.coyote.http11.Http11Protocol'
110
+ end
111
+
112
+ it "uses the NioConnector when the http configuration sets nio to true" do
90
113
  server = Trinidad::Server.new({
91
114
  :web_app_dir => MOCK_WEB_APP_DIR,
92
- :rackup => 'config.ru'
115
+ :http => {:nio => true}
93
116
  })
117
+ server.http_configured?.should be_true
94
118
 
95
- context = default_context_should_be_loaded(server.tomcat.host.findChildren())
96
- context.findParameter('rackup').gsub(/\s+/, ' ').should == "require 'rubygems' require 'sinatra'"
119
+ server.tomcat.connector.protocol_handler_class_name.should == 'org.apache.coyote.http11.Http11NioProtocol'
97
120
  end
98
121
 
99
- it "removes default servlets from the application" do
122
+ it "configures NioConnector with http option values" do
123
+ server = Trinidad::Server.new({
124
+ :web_app_dir => MOCK_WEB_APP_DIR,
125
+ :http => {
126
+ :nio => true,
127
+ 'maxKeepAliveRequests' => 4,
128
+ 'socket.bufferPool' => 1000
129
+ }
130
+ })
131
+ connector = server.tomcat.connector
132
+ connector.get_property('maxKeepAliveRequests').should == 4
133
+ connector.get_property('socket.bufferPool').should == '1000'
134
+ end
135
+
136
+ it "adds the WebAppLifecycleListener to each webapp" do
100
137
  server = Trinidad::Server.new({:web_app_dir => MOCK_WEB_APP_DIR})
101
- app = server.tomcat.host.find_child('/')
138
+ app_context = server.tomcat.host.find_child('/')
102
139
 
103
- app.find_child('default').should be_nil
104
- app.find_child('jsp').should be_nil
140
+ app_context.find_lifecycle_listeners.map {|l| l.class.name }.should include('Trinidad::WebAppLifecycleListener')
141
+ end
142
+
143
+ it "loads application extensions from the root of the configuration" do
144
+ server = Trinidad::Server.new({
145
+ :web_app_dir => MOCK_WEB_APP_DIR,
146
+ :extensions => { :foo => {} }
147
+ })
148
+
149
+ app_context = server.tomcat.host.find_child('/')
150
+ app_context.doc_base.should == 'foo_app_extension'
151
+ end
152
+
153
+ it "doesn't create a default keystore when the option SSLCertificateFile is present in the ssl configuration options" do
154
+ require 'fileutils'
155
+ FileUtils.rm_rf 'ssl'
156
+
157
+ server = Trinidad::Server.new({
158
+ :ssl => {
159
+ :port => 8443,
160
+ :SSLCertificateFile => '/usr/local/ssl/server.crt'
161
+ },
162
+ :web_app_dir => MOCK_WEB_APP_DIR})
163
+
164
+ File.exist?('ssl').should be_false
105
165
  end
106
166
 
107
167
  def default_context_should_be_loaded(children)
108
168
  children.should have(1).web_apps
109
- children[0].getDocBase().should == MOCK_WEB_APP_DIR
110
- children[0].getPath().should == '/'
169
+ children[0].doc_base.should == MOCK_WEB_APP_DIR
170
+ children[0].path.should == '/'
111
171
  children[0]
112
172
  end
113
173
  end
@@ -0,0 +1,179 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require File.dirname(__FILE__) + '/fakeapp'
3
+
4
+ include FakeApp
5
+
6
+ # adding accessor for tests
7
+ class Trinidad::WebAppLifecycleListener
8
+ attr_accessor :context
9
+ end
10
+
11
+ import org.apache.catalina.Lifecycle
12
+
13
+ describe Trinidad::WebAppLifecycleListener do
14
+ before do
15
+ @mock = mock
16
+ @mock.stubs(:type).returns(Lifecycle::BEFORE_START_EVENT)
17
+ @mock.stubs(:lifecycle).returns(Trinidad::Tomcat::StandardContext.new)
18
+
19
+ @tomcat = Trinidad::Tomcat::Tomcat.new
20
+ @tomcat.host.app_base = Dir.pwd
21
+ end
22
+
23
+ it "ignores the event when it's not BEFORE_START_EVENT" do
24
+ listener = Trinidad::WebAppLifecycleListener.new(nil)
25
+ @mock.stubs(:type).returns(Lifecycle::BEFORE_STOP_EVENT)
26
+ lambda {
27
+ listener.lifecycleEvent(@mock)
28
+ }.should_not raise_error
29
+ end
30
+
31
+ it "tries to initialize the context when the event is BEFORE_START_EVENT" do
32
+ listener = Trinidad::WebAppLifecycleListener.new(nil)
33
+ lambda {
34
+ listener.lifecycleEvent(@mock)
35
+ }.should raise_error
36
+ end
37
+
38
+ it "doesn't load a default web xml when the deployment descriptor is not provided" do
39
+ listener = Trinidad::WebAppLifecycleListener.new(Trinidad::RailsWebApp.new({}, {}))
40
+ listener.configure_deployment_descriptor.should be_nil
41
+ end
42
+
43
+ it "loads a default web xml when the deployment descriptor is provided" do
44
+ FakeFS do
45
+ create_rails_web_xml
46
+
47
+ listener = Trinidad::WebAppLifecycleListener.new(Trinidad::RailsWebApp.new({}, {
48
+ :web_app_dir => Dir.pwd,
49
+ :default_web_xml => 'config/web.xml'
50
+ }))
51
+ listener.context = Trinidad::Tomcat::StandardContext.new
52
+
53
+ expected_xml = File.join(Dir.pwd, 'config/web.xml')
54
+ listener.configure_deployment_descriptor.should == expected_xml
55
+ listener.context.default_web_xml.should == expected_xml
56
+
57
+ listener.context.find_lifecycle_listeners.
58
+ map {|l| l.class.name }.should include('Java::OrgApacheCatalinaStartup::ContextConfig')
59
+ end
60
+ end
61
+
62
+ it "adds the rack servlet and the mapping for /*" do
63
+ listener = Trinidad::WebAppLifecycleListener.new(Trinidad::RailsWebApp.new({}, {}))
64
+ listener.context = Trinidad::Tomcat::StandardContext.new
65
+
66
+ listener.configure_rack_servlet
67
+
68
+ servlet = listener.context.find_child('RackServlet')
69
+ servlet.should_not be_nil
70
+ servlet.servlet_class.should == 'org.jruby.rack.RackServlet'
71
+
72
+ listener.context.find_servlet_mapping('/*').should == 'RackServlet'
73
+ end
74
+
75
+ it "configures the rack context listener from the web app" do
76
+ listener = Trinidad::WebAppLifecycleListener.new(Trinidad::RackupWebApp.new({}, {}))
77
+ listener.context = Trinidad::Tomcat::StandardContext.new
78
+ listener.configure_rack_listener
79
+
80
+ listener.context.find_application_listeners.should include('org.jruby.rack.RackServletContextListener')
81
+ end
82
+
83
+ it "adds context parameters from the web app" do
84
+ listener = Trinidad::WebAppLifecycleListener.new(Trinidad::RailsWebApp.new({}, {
85
+ :jruby_min_runtimes => 1
86
+ }))
87
+ listener.context = Trinidad::Tomcat::StandardContext.new
88
+ listener.configure_init_params
89
+
90
+ listener.context.find_parameter('jruby.min.runtimes').should == '1'
91
+ end
92
+
93
+ it "ignores parameters already present in the deployment descriptor" do
94
+ listener = Trinidad::WebAppLifecycleListener.new(Trinidad::RailsWebApp.new({}, {
95
+ :jruby_max_runtimes => 1,
96
+ :web_app_dir => MOCK_WEB_APP_DIR,
97
+ :default_web_xml => 'config/web.xml'
98
+ }))
99
+ listener.init_defaults(@tomcat.add_webapp('/', Dir.pwd))
100
+
101
+ listener.context.find_parameter('jruby.max.runtimes').should be_nil
102
+ listener.context.start
103
+ listener.context.find_parameter('jruby.max.runtimes').should == '8'
104
+ end
105
+
106
+ it "doesn't load classes into a jar when the libs directory is not present" do
107
+ web_app = Trinidad::RailsWebApp.new({}, {})
108
+
109
+ listener = Trinidad::WebAppLifecycleListener.new(web_app)
110
+ listener.add_application_jars(web_app.class_loader)
111
+
112
+ lambda {
113
+ web_app.class_loader.find_class('org.ho.yaml.Yaml')
114
+ }.should raise_error
115
+ end
116
+
117
+ it "loads classes into a jar when the libs directory is provided" do
118
+ web_app = Trinidad::RailsWebApp.new({}, {
119
+ :web_app_dir => MOCK_WEB_APP_DIR,
120
+ :libs_dir => 'lib'
121
+ })
122
+
123
+ listener = Trinidad::WebAppLifecycleListener.new(web_app)
124
+ listener.add_application_jars(web_app.class_loader)
125
+
126
+ lambda {
127
+ web_app.class_loader.find_class('org.ho.yaml.Yaml').should_not be_nil
128
+ }.should_not raise_error
129
+ end
130
+
131
+ it "doesn't load java classes when the classes directory is not present" do
132
+ web_app = Trinidad::RailsWebApp.new({}, {})
133
+
134
+ listener = Trinidad::WebAppLifecycleListener.new(web_app)
135
+ listener.add_application_java_classes(web_app.class_loader)
136
+
137
+ lambda {
138
+ web_app.class_loader.find_class('HelloTomcat')
139
+ }.should raise_error
140
+ end
141
+
142
+ it "loads java classes when the classes directory is provided" do
143
+ web_app = Trinidad::RailsWebApp.new({}, {
144
+ :web_app_dir => MOCK_WEB_APP_DIR,
145
+ :classes_dir => 'classes'
146
+ })
147
+
148
+ listener = Trinidad::WebAppLifecycleListener.new(web_app)
149
+ listener.add_application_java_classes(web_app.class_loader)
150
+
151
+ lambda {
152
+ web_app.class_loader.find_class('HelloTomcat').should_not be_nil
153
+ }.should_not raise_error
154
+ end
155
+
156
+ it "creates a WebappLoader with the JRuby class loader" do
157
+ web_app = Trinidad::RailsWebApp.new({}, {})
158
+
159
+ listener = Trinidad::WebAppLifecycleListener.new(web_app)
160
+ listener.context = Trinidad::Tomcat::StandardContext.new
161
+ listener.configure_context_loader
162
+
163
+ loader = listener.context.loader
164
+
165
+ loader.should be_instance_of(Java::OrgApacheCatalinaLoader::WebappLoader)
166
+ end
167
+
168
+ it "loads the default application from the current directory using the rackup file if :web_apps is not present" do
169
+ web_app = Trinidad::RackupWebApp.new({
170
+ :web_app_dir => MOCK_WEB_APP_DIR,
171
+ :rackup => 'config.ru'
172
+ }, {})
173
+ listener = Trinidad::WebAppLifecycleListener.new(web_app)
174
+ listener.context = Trinidad::Tomcat::StandardContext.new
175
+ listener.configure_init_params
176
+
177
+ listener.context.find_parameter('rackup.path').should == "config.ru"
178
+ end
179
+ end
@@ -1,144 +1,175 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper'
2
+ require File.dirname(__FILE__) + '/fakeapp'
2
3
 
3
- describe Trinidad::WebApp do
4
- before do
5
- @tomcat = Trinidad::Tomcat::Tomcat.new
6
- @tomcat.host.app_base = Dir.pwd
7
- @tomcat_web_app = @tomcat.addWebapp('/', File.dirname(__FILE__) + '/../../')
8
-
9
- @app = {
10
- :web_app_dir => MOCK_WEB_APP_DIR,
11
- :context_path => '/'
12
- }
13
- @config = {
14
- :libs_dir => 'lib',
15
- :classes_dir => 'classes',
16
- :default_web_xml => 'config/web.xml',
17
- :jruby_min_runtimes => 2,
18
- :jruby_max_runtimes => 6,
19
- :web_apps => {
20
- :default => @app
21
- }
22
- }
23
- @web_app = Trinidad::RailsWebApp.new(@tomcat_web_app, @config, @app)
24
- end
4
+ include FakeApp
25
5
 
6
+ describe Trinidad::WebApp do
26
7
  it "creates a RailsWebApp if rackup option is not present" do
27
- app = Trinidad::WebApp.create(@tomcat_web_app, @config, @app)
8
+ app = Trinidad::WebApp.create({}, {})
28
9
  app.should be_an_instance_of(Trinidad::RailsWebApp)
29
10
  end
30
11
 
31
12
  it "creates a RackupWebApp if rackup option is present" do
32
- rackup_app = {:rackup => 'config.ru'}
33
- @config.deep_merge({:web_apps => {:default => rackup_app}})
34
- app = Trinidad::WebApp.create(@tomcat_web_app, @config, rackup_app)
13
+ app = Trinidad::WebApp.create({}, {:rackup => 'config.ru'})
35
14
  app.should be_an_instance_of(Trinidad::RackupWebApp)
36
15
  end
37
16
 
38
- it "should load custom jars" do
39
- class_loader = org.jruby.util.JRubyClassLoader.new(JRuby.runtime.jruby_class_loader)
40
- @web_app.add_application_libs(class_loader)
17
+ it "ignores rack_servlet when a deployment descriptor already provides it" do
18
+ FakeFS do
19
+ create_rails_web_xml
41
20
 
42
- resource = class_loader.find_class('org.ho.yaml.Yaml')
43
- resource.should_not be_nil
21
+ app = Trinidad::WebApp.create({}, {
22
+ :web_app_dir => Dir.pwd,
23
+ :default_web_xml => 'config/web.xml'
24
+ })
25
+ app.servlet.should be_nil
26
+ end
44
27
  end
45
28
 
46
- it "should load custom classes" do
47
- class_loader = org.jruby.util.JRubyClassLoader.new(JRuby.runtime.jruby_class_loader)
48
- @web_app.add_application_classes(class_loader)
29
+ it "ignores rack_listener when a deployment descriptor already provides it" do
30
+ FakeFS do
31
+ create_rails_web_xml
49
32
 
50
- resource = class_loader.find_class('HelloTomcat')
51
- resource.should_not be_nil
33
+ app = Trinidad::WebApp.create({}, {
34
+ :web_app_dir => Dir.pwd,
35
+ :default_web_xml => 'config/web.xml'
36
+ })
37
+ app.rack_listener.should be_nil
38
+ end
52
39
  end
53
40
 
54
- it "should start application context without errors" do
55
- start_context
41
+ it "uses rack_servlet as the default servlet when a deployment descriptor is not provided" do
42
+ app = Trinidad::WebApp.create({}, {})
43
+ app.servlet.should_not be_nil
44
+ app.servlet[:name].should == 'RackServlet'
45
+ app.servlet[:class].should == 'org.jruby.rack.RackServlet'
56
46
  end
57
47
 
58
- it "should add a filter from the default web.xml" do
59
- start_context_with_web_xml
60
- @web_app.context.findFilterDefs().should have(1).filters
48
+ it "uses rack_listener as the default listener when a deployment descriptor is not provided" do
49
+ app = Trinidad::WebApp.create({}, {})
50
+ app.rack_listener.should == 'org.jruby.rack.rails.RailsServletContextListener'
61
51
  end
62
52
 
63
- it "shouldn't duplicate init params" do
64
- start_context_with_web_xml
65
- lambda { @web_app.add_init_params }.should_not raise_error
53
+ it "loads the context parameters from the configuration when a deployment descriptor is not provided" do
54
+ app = Trinidad::WebApp.create({}, {
55
+ :jruby_min_runtimes => 1,
56
+ :jruby_max_runtimes => 1,
57
+ :public => 'foo',
58
+ :environment => :production
59
+ })
60
+ parameters = app.init_params
61
+ parameters['jruby.min.runtimes'].should == '1'
62
+ parameters['jruby.initial.runtimes'].should == '1'
63
+ parameters['jruby.max.runtimes'].should == '1'
64
+ parameters['public.root'].should == '/foo'
65
+ parameters['rails.env'].should == 'production'
66
+ parameters['rails.root'].should == '/'
66
67
  end
67
68
 
68
- it "loads init params from configuration root" do
69
- @web_app.add_init_params
69
+ it "adds the rackup script as a context parameter when it's provided" do
70
+ FakeFS do
71
+ create_rackup_file
72
+ app = Trinidad::WebApp.create({}, {
73
+ :web_app_dir => Dir.pwd,
74
+ :rackup => 'config/config.ru'
75
+ })
70
76
 
71
- @web_app.context.findParameter('jruby.min.runtimes').should == '2'
72
- @web_app.context.findParameter('jruby.max.runtimes').should == '6'
77
+ parameters = app.init_params
78
+ parameters['rackup.path'].should == 'config/config.ru'
79
+ end
73
80
  end
74
81
 
75
- it 'loads init params from application node' do
76
- @app[:jruby_min_runtimes] = 4
77
- @app[:jruby_max_runtimes] = 8
78
- @config[:web_apps][:default] = @app
82
+ it "ignores parameters from configuration when the deployment descriptor already contains them" do
83
+ FakeFS do
84
+ create_rackup_web_xml
79
85
 
80
- web_app = Trinidad::WebApp.create(@tomcat_web_app, @config, @app)
81
- web_app.add_init_params
86
+ app = Trinidad::WebApp.create({}, {
87
+ :web_app_dir => Dir.pwd,
88
+ :default_web_xml => 'config/web.xml',
89
+ :jruby_min_runtimes => 2,
90
+ :jruby_max_runtimes => 5
91
+ })
92
+ parameters = app.init_params
82
93
 
83
- web_app.context.findParameter('jruby.min.runtimes').should == '4'
84
- web_app.context.findParameter('jruby.max.runtimes').should == '8'
94
+ parameters['jruby.min.runtimes'].should be_nil
95
+ parameters['jruby.max.runtimes'].should be_nil
96
+ end
85
97
  end
86
98
 
87
- it "configures rack handler" do
88
- @web_app.configure_rack
89
- @web_app.context.findChild('RackServlet').should_not be_nil
99
+ it "ignores the deployment descriptor when it doesn't exist" do
100
+ app = Trinidad::WebApp.create({}, {
101
+ :web_app_dir => Dir.pwd,
102
+ :default_web_xml => 'config/web.xml'
103
+ })
104
+ app.default_deployment_descriptor.should be_nil
90
105
  end
91
106
 
92
- it "configures rack listener" do
93
- @web_app.add_rack_context_listener
94
- @web_app.context.findApplicationListeners().should have(1).listeners
107
+ it "doesn't load any web.xml when the deployment descriptor doesn't exist" do
108
+ app = Trinidad::WebApp.create({}, {
109
+ :web_app_dir => Dir.pwd,
110
+ :default_web_xml => 'config/web.xml'
111
+ })
112
+ app.rack_servlet_configured?.should be_false
113
+ app.rack_listener_configured?.should be_false
95
114
  end
96
115
 
97
- it "has rack handler already configured when web.xml includes it" do
98
- @web_app.load_default_web_xml
99
- @web_app.rack_configured?().should be_true
100
-
101
- @web_app.configure_rack
102
- @web_app.context.findChild('RackServlet').should be_nil
116
+ it "uses `public` as default public root directory" do
117
+ app = Trinidad::WebApp.create({}, {})
118
+ app.public_root.should == 'public'
103
119
  end
104
120
 
105
- it "has rack listener already configured when web.xml includes it" do
106
- @web_app.load_default_web_xml
107
- @web_app.rack_listener_configured?().should be_true
108
-
109
- @web_app.add_rack_context_listener
110
- @web_app.context.findApplicationListeners().should have(0).listeners
121
+ it "uses extensions from the global configuration" do
122
+ config = { :extensions => {:hotdeploy => {}} }
123
+ app = Trinidad::WebApp.create(config, {})
124
+ app.extensions.should include(:hotdeploy)
111
125
  end
112
126
 
113
- it "loads the provided web.xml for rails applications" do
114
- @config[:default_web_xml] = 'config/foo.xml'
115
- app = Trinidad::WebApp.create(@tomcat_web_app, @config, @app)
116
-
117
- app.load_default_web_xml
118
- app.context.default_web_xml.should =~ /rails_web.xml$/
127
+ it "overrides global extensions with application extensions" do
128
+ config = { :extensions => {:hotdeploy => {}} }
129
+ app_config = { :extensions => {:hotdeploy => {:delay => 30000}} }
130
+ app = Trinidad::WebApp.create(config, app_config)
131
+ app.extensions[:hotdeploy].should include(:delay)
119
132
  end
120
133
 
121
- it "loads the provided web.xml for rack applications" do
122
- @config[:default_web_xml] = 'config/foo.xml'
123
- @app[:rackup] = 'config.ru'
134
+ it "creates a rackup application when the rackup file is under WEB-INF directory" do
135
+ FakeFS do
136
+ create_rackup_file('WEB-INF')
137
+ app = Trinidad::WebApp.create({}, {})
138
+
139
+ app.should be_an_instance_of(Trinidad::RackupWebApp)
140
+ end
141
+ end
124
142
 
125
- app = Trinidad::WebApp.create(@tomcat_web_app, @config, @app)
126
- app.load_default_web_xml
127
- app.context.default_web_xml.should =~ /rackup_web.xml$/
128
- end
143
+ it "doesn't add the rackup init parameter when the rackup file is under WEB-INF directory" do
144
+ FakeFS do
145
+ create_rackup_file('WEB-INF')
146
+ app = Trinidad::WebApp.create({}, {})
129
147
 
130
- def start_context_with_web_xml
131
- @web_app.load_default_web_xml
132
- start_context
148
+ app.init_params.should_not include('rackup.path')
149
+ end
133
150
  end
134
151
 
135
- def start_context
136
- load_tomcat_libs
137
- lambda { @web_app.context.start }.should_not raise_error
152
+ it "loads rackup file from a given directory" do
153
+ FakeFS do
154
+ create_rackup_file('rack')
155
+ app = Trinidad::WebApp.create({}, {
156
+ :web_app_dir => Dir.pwd,
157
+ :rackup => 'rack'
158
+ })
159
+ app.init_params.should include('rackup.path')
160
+ app.init_params['rackup.path'].should == 'rack/config.ru'
161
+ end
138
162
  end
139
163
 
140
- def load_tomcat_libs
141
- @web_app.config[:libs_dir] = File.join(File.dirname(__FILE__), '..', '..', 'tomcat-libs')
142
- @web_app.add_context_loader
164
+ it "allows to configure the servlet from the configuration options" do
165
+ app = Trinidad::WebApp.create({}, {
166
+ :servlet => {
167
+ :class => 'org.jruby.trinidad.FakeServlet',
168
+ :name => 'FakeServlet'
169
+ }
170
+ })
171
+
172
+ app.servlet[:class].should == 'org.jruby.trinidad.FakeServlet'
173
+ app.servlet[:name].should == 'FakeServlet'
143
174
  end
144
175
  end
Binary file
metadata CHANGED
@@ -1,12 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trinidad_jars
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 31098201
5
+ prerelease: true
5
6
  segments:
6
7
  - 0
7
- - 2
8
+ - 3
8
9
  - 0
9
- version: 0.2.0
10
+ - beta
11
+ version: 0.3.0.beta
10
12
  platform: ruby
11
13
  authors:
12
14
  - David Calavera
@@ -14,7 +16,7 @@ autorequire:
14
16
  bindir: bin
15
17
  cert_chain: []
16
18
 
17
- date: 2010-04-28 00:00:00 +02:00
19
+ date: 2010-07-01 00:00:00 +02:00
18
20
  default_executable: trinidad
19
21
  dependencies: []
20
22
 
@@ -32,6 +34,16 @@ files:
32
34
  - trinidad-libs/tomcat-core.jar
33
35
  - LICENSE
34
36
  - README.rdoc
37
+ - spec/fixtures/trinidad_foo_extension.rb
38
+ - spec/fixtures/trinidad_override_tomcat_extension.rb
39
+ - spec/spec_helper.rb
40
+ - spec/trinidad/command_line_parser_spec.rb
41
+ - spec/trinidad/extensions_spec.rb
42
+ - spec/trinidad/fakeapp.rb
43
+ - spec/trinidad/server_spec.rb
44
+ - spec/trinidad/web_app_lifecycle_listener_spec.rb
45
+ - spec/trinidad/web_app_spec.rb
46
+ - bin/trinidad
35
47
  has_rdoc: true
36
48
  homepage: http://calavera.github.com/trinidad
37
49
  licenses: []
@@ -42,23 +54,29 @@ rdoc_options:
42
54
  require_paths:
43
55
  - lib
44
56
  required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
45
58
  requirements:
46
59
  - - ">="
47
60
  - !ruby/object:Gem::Version
61
+ hash: 3
48
62
  segments:
49
63
  - 0
50
64
  version: "0"
51
65
  required_rubygems_version: !ruby/object:Gem::Requirement
66
+ none: false
52
67
  requirements:
53
- - - ">="
68
+ - - ">"
54
69
  - !ruby/object:Gem::Version
70
+ hash: 25
55
71
  segments:
56
- - 0
57
- version: "0"
72
+ - 1
73
+ - 3
74
+ - 1
75
+ version: 1.3.1
58
76
  requirements: []
59
77
 
60
78
  rubyforge_project: trinidad_jars
61
- rubygems_version: 1.3.6
79
+ rubygems_version: 1.3.7
62
80
  signing_key:
63
81
  specification_version: 3
64
82
  summary: Common jars for Trinidad
@@ -70,4 +88,5 @@ test_files:
70
88
  - spec/trinidad/extensions_spec.rb
71
89
  - spec/trinidad/fakeapp.rb
72
90
  - spec/trinidad/server_spec.rb
91
+ - spec/trinidad/web_app_lifecycle_listener_spec.rb
73
92
  - spec/trinidad/web_app_spec.rb