summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/network/http/mongrel.rb16
-rw-r--r--lib/puppet/network/http/webrick.rb15
-rw-r--r--spec/unit/network/http/mongrel.rb30
-rw-r--r--spec/unit/network/http/webrick.rb20
-rw-r--r--spec/unit/network/server.rb9
5 files changed, 47 insertions, 43 deletions
diff --git a/lib/puppet/network/http/mongrel.rb b/lib/puppet/network/http/mongrel.rb
index ab1e616b1..5b14d93c9 100644
--- a/lib/puppet/network/http/mongrel.rb
+++ b/lib/puppet/network/http/mongrel.rb
@@ -14,10 +14,10 @@ class Puppet::Network::HTTP::Mongrel
@protocols = args[:protocols]
@handlers = args[:handlers]
-
- setup_handlers
-
@server = Mongrel::HttpServer.new(args[:address], args[:port])
+
+ setup_handlers
+
@server.run
@listening = true
end
@@ -37,12 +37,16 @@ class Puppet::Network::HTTP::Mongrel
def setup_handlers
@protocols.each do |protocol|
@handlers.each do |handler|
- class_for_protocol_handler(protocol, handler).new
+ class_for_protocol(protocol).new(:server => @server, :handler => handler)
end
end
end
- def class_for_protocol_handler(protocol, handler)
- Class.new
+ # TODO/FIXME: need a spec which forces delegation to the real class
+ def class_for_protocol(protocol)
+ Class.new do
+ def initialize(args = {})
+ end
+ end
end
end
diff --git a/lib/puppet/network/http/webrick.rb b/lib/puppet/network/http/webrick.rb
index 00d13437c..474f66e4f 100644
--- a/lib/puppet/network/http/webrick.rb
+++ b/lib/puppet/network/http/webrick.rb
@@ -14,12 +14,11 @@ class Puppet::Network::HTTP::WEBrick
raise "WEBrick server is already listening" if listening?
@protocols = args[:protocols]
- @handlers = args[:handlers]
+ @handlers = args[:handlers]
+ @server = WEBrick::HTTPServer.new(:BindAddress => args[:address], :Port => args[:port])
setup_handlers
- @server = WEBrick::HTTPServer.new(:BindAddress => args[:address], :Port => args[:port])
-
# TODO / FIXME is this really necessary? -- or can we do it in both mongrel and webrick?
Puppet.newservice(@server)
Puppet.start
@@ -42,12 +41,16 @@ class Puppet::Network::HTTP::WEBrick
def setup_handlers
@handlers.each do |handler|
@protocols.each do |protocol|
- class_for_protocol_handler(protocol, handler).new
+ class_for_protocol(protocol).new(:server => @server, :handler => handler)
end
end
end
- def class_for_protocol_handler(protocol, handler)
- Class.new
+ # TODO/FIXME: need a spec which forces delegation to the real class
+ def class_for_protocol(protocol)
+ Class.new do
+ def initialize(args = {})
+ end
+ end
end
end
diff --git a/spec/unit/network/http/mongrel.rb b/spec/unit/network/http/mongrel.rb
index 6c8b65582..0990a42d0 100644
--- a/spec/unit/network/http/mongrel.rb
+++ b/spec/unit/network/http/mongrel.rb
@@ -60,28 +60,16 @@ describe Puppet::Network::HTTP::Mongrel, "when turning on listening" do
@server.should be_listening
end
- it "should instantiate a specific handler (mongrel+rest, e.g.) for each named handler, for each named protocol)" do
- @listen_params[:handlers].each do |handler|
- @listen_params[:protocols].each do |protocol|
- mock_handler = mock("handler instance for [#{protocol}]+[#{handler}]")
- mock_handler_class = mock("handler class for [#{protocol}]+[#{handler}]")
- mock_handler_class.expects(:new).returns(mock_handler)
- @server.expects(:class_for_protocol_handler).with(protocol, handler).returns(mock_handler_class)
- end
- end
- @server.listen(@listen_params)
- end
-
- it "should mount each handler on a mongrel path" do
- pending "a moment of clarity"
- @listen_params[:handlers].each do |handler|
- @listen_params[:protocols].each do |protocol|
- mock_handler = mock("handler instance for [#{protocol}]+[#{handler}]")
- mock_handler_class = mock("handler class for [#{protocol}]+[#{handler}]")
- mock_handler_class.stubs(:new).returns(mock_handler)
- @server.stubs(:class_for_protocol_handler).with(protocol, handler).returns(mock_handler_class)
- # TODO / FIXME : HERE -- need to begin resolving the model behind the indirection
+ it "should instantiate a handler for each protocol+handler pair to configure web server routing" do
+ @listen_params[:protocols].each do |protocol|
+ mock_handler = mock("handler instance for [#{protocol}]")
+ mock_handler_class = mock("handler class for [#{protocol}]")
+ @listen_params[:handlers].each do |handler|
+ mock_handler_class.expects(:new).with {|args|
+ args[:server] == @mock_mongrel and args[:handler] == handler
+ }.returns(mock_handler)
end
+ @server.expects(:class_for_protocol).with(protocol).at_least_once.returns(mock_handler_class)
end
@server.listen(@listen_params)
end
diff --git a/spec/unit/network/http/webrick.rb b/spec/unit/network/http/webrick.rb
index b94a6a78d..4d914dc76 100644
--- a/spec/unit/network/http/webrick.rb
+++ b/spec/unit/network/http/webrick.rb
@@ -60,19 +60,19 @@ describe Puppet::Network::HTTP::WEBrick, "when turning on listening" do
@server.should be_listening
end
- it "should instantiate a specific handler (mongrel+rest, e.g.) for each named handler, for each named protocol)" do
- @listen_params[:handlers].each do |handler|
- @listen_params[:protocols].each do |protocol|
- mock_handler = mock("handler instance for [#{protocol}]+[#{handler}]")
- mock_handler_class = mock("handler class for [#{protocol}]+[#{handler}]")
- mock_handler_class.expects(:new).returns(mock_handler)
- @server.expects(:class_for_protocol_handler).with(protocol, handler).returns(mock_handler_class)
+ it "should instantiate a handler for each protocol+handler pair to configure web server routing" do
+ @listen_params[:protocols].each do |protocol|
+ mock_handler = mock("handler instance for [#{protocol}]")
+ mock_handler_class = mock("handler class for [#{protocol}]")
+ @listen_params[:handlers].each do |handler|
+ mock_handler_class.expects(:new).with {|args|
+ args[:server] == @mock_webrick and args[:handler] == handler
+ }.returns(mock_handler)
end
+ @server.expects(:class_for_protocol).with(protocol).at_least_once.returns(mock_handler_class)
end
- @server.listen(@listen_params)
+ @server.listen(@listen_params)
end
-
- it "should mount handlers on a webrick path"
end
describe Puppet::Network::HTTP::WEBrick, "when turning off listening" do
diff --git a/spec/unit/network/server.rb b/spec/unit/network/server.rb
index 6802c6aaa..528d47d0e 100644
--- a/spec/unit/network/server.rb
+++ b/spec/unit/network/server.rb
@@ -268,6 +268,15 @@ describe Puppet::Network::Server, "when listening is being turned off" do
end
end
+
+ # TODO / FIXME : HERE -- need to begin resolving the model behind the indirection
+ # looks like: get the handler class, providing @server to it
+ # have the handler class register the handler @ the right URL
+ # handler class knows the correct path to use, correct registration method to call
+ # handler also know how to get the model class from the indirection name
+ # do we change indirection name to indirection (instead of saying "handlers")?
+
+
describe Class.new, "Puppet::Network::Handler::*::* (handler class (e.g., webrick+rest or mongrel+xmlrpc))" do
it "should be able to unserialize a request from the given httpserver answering for the given protocol handler, to be used by a controller"
it "should be able to serialize a result from a controller for return by the given httpserver responding with the given protocol"