2006-03-25 16:15:30 -05:00
|
|
|
require 'test/unit'
|
|
|
|
require 'mongrel'
|
2006-05-20 14:06:20 -04:00
|
|
|
require 'net/http'
|
2006-03-25 16:15:30 -05:00
|
|
|
|
|
|
|
$test_plugin_fired = 0
|
|
|
|
|
|
|
|
class TestPlugin < GemPlugin::Plugin "/handlers"
|
|
|
|
include Mongrel::HttpHandlerPlugin
|
|
|
|
|
|
|
|
def process(request, response)
|
|
|
|
$test_plugin_fired += 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
class Sentinel < GemPlugin::Plugin "/handlers"
|
|
|
|
include Mongrel::HttpHandlerPlugin
|
|
|
|
|
|
|
|
def process(request, response)
|
|
|
|
raise "This Sentinel plugin shouldn't run."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2006-03-26 18:57:11 -05:00
|
|
|
class ConfiguratorTest < Test::Unit::TestCase
|
2006-03-25 16:15:30 -05:00
|
|
|
|
|
|
|
def test_base_handler_config
|
|
|
|
config = Mongrel::Configurator.new :host => "localhost" do
|
2006-05-16 00:28:13 -04:00
|
|
|
listener :port => 4501 do
|
2006-03-25 16:15:30 -05:00
|
|
|
# 2 in front should run, but the sentinel shouldn't since dirhandler processes the request
|
|
|
|
uri "/", :handler => plugin("/handlers/testplugin")
|
|
|
|
uri "/", :handler => plugin("/handlers/testplugin")
|
2006-04-01 03:43:30 -05:00
|
|
|
uri "/", :handler => Mongrel::DirHandler.new(".")
|
2006-03-26 18:57:11 -05:00
|
|
|
uri "/", :handler => plugin("/handlers/testplugin")
|
2006-03-25 16:15:30 -05:00
|
|
|
|
|
|
|
uri "/test", :handler => plugin("/handlers/testplugin")
|
|
|
|
uri "/test", :handler => plugin("/handlers/testplugin")
|
2006-04-01 03:43:30 -05:00
|
|
|
uri "/test", :handler => Mongrel::DirHandler.new(".")
|
2006-03-26 18:57:11 -05:00
|
|
|
uri "/test", :handler => plugin("/handlers/testplugin")
|
2006-03-25 16:15:30 -05:00
|
|
|
run
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2006-03-26 18:57:11 -05:00
|
|
|
|
|
|
|
config.listeners.each do |host,listener|
|
|
|
|
puts "Registered URIs: #{listener.classifier.uris.inspect}"
|
|
|
|
assert listener.classifier.uris.length == 2, "Wrong number of registered URIs"
|
|
|
|
assert listener.classifier.uris.include?("/"), "/ not registered"
|
|
|
|
assert listener.classifier.uris.include?("/test"), "/test not registered"
|
|
|
|
end
|
|
|
|
|
2006-05-16 00:28:13 -04:00
|
|
|
res = Net::HTTP.get(URI.parse('http://localhost:4501/test'))
|
2006-03-25 16:15:30 -05:00
|
|
|
assert res != nil, "Didn't get a response"
|
2006-03-26 18:57:11 -05:00
|
|
|
assert $test_plugin_fired == 3, "Test filter plugin didn't run 3 times."
|
2006-03-25 16:15:30 -05:00
|
|
|
|
|
|
|
|
2006-05-16 00:28:13 -04:00
|
|
|
res = Net::HTTP.get(URI.parse('http://localhost:4501/'))
|
2006-03-25 16:15:30 -05:00
|
|
|
assert res != nil, "Didn't get a response"
|
2006-03-26 18:57:11 -05:00
|
|
|
assert $test_plugin_fired == 6, "Test filter plugin didn't run 6 times."
|
2006-03-25 16:15:30 -05:00
|
|
|
|
|
|
|
config.stop
|
2006-05-19 22:56:30 -04:00
|
|
|
|
2006-03-27 02:06:18 -05:00
|
|
|
assert_raise Errno::EBADF, Errno::ECONNREFUSED do
|
2006-05-16 00:28:13 -04:00
|
|
|
res = Net::HTTP.get(URI.parse("http://localhost:4501/"))
|
2006-03-25 16:15:30 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|