aboutsummaryrefslogtreecommitdiffstats
path: root/actionservice/test/abstract_client.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-02-18 10:35:25 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-02-18 10:35:25 +0000
commite7a29380292902eae4799b2658507b3cfffb9cec (patch)
tree99a7cd3c7d720ef73f998c2756be1fef77ff0ee1 /actionservice/test/abstract_client.rb
parente39bf105941133d3d6699c52c18dbd3b9aa0bf5c (diff)
downloadrails-e7a29380292902eae4799b2658507b3cfffb9cec.tar.gz
rails-e7a29380292902eae4799b2658507b3cfffb9cec.tar.bz2
rails-e7a29380292902eae4799b2658507b3cfffb9cec.zip
Added Action Service to the repository
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@658 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionservice/test/abstract_client.rb')
-rw-r--r--actionservice/test/abstract_client.rb124
1 files changed, 124 insertions, 0 deletions
diff --git a/actionservice/test/abstract_client.rb b/actionservice/test/abstract_client.rb
new file mode 100644
index 0000000000..662bdd9431
--- /dev/null
+++ b/actionservice/test/abstract_client.rb
@@ -0,0 +1,124 @@
+require File.dirname(__FILE__) + '/abstract_unit'
+require 'webrick'
+require 'webrick/log'
+require 'singleton'
+
+module ClientTest
+ class Person < ActionService::Struct
+ member :firstnames, [:string]
+ member :lastname, :string
+
+ def ==(other)
+ firstnames == other.firstnames && lastname == other.lastname
+ end
+ end
+
+ class API < ActionService::API::Base
+ api_method :void
+ api_method :normal, :expects => [:int, :int], :returns => [:int]
+ api_method :array_return, :returns => [[Person]]
+ api_method :struct_pass, :expects => [[Person]], :returns => [:bool]
+ api_method :client_container, :returns => [:int]
+ end
+
+ class NullLogOut
+ def <<(*args); end
+ end
+
+ class Container < ActionController::Base
+ service_api API
+
+ attr :value_void
+ attr :value_normal
+ attr :value_array_return
+ attr :value_struct_pass
+
+ def initialize
+ @session = @assigns = {}
+ @value_void = nil
+ @value_normal = nil
+ @value_array_return = nil
+ @value_struct_pass = nil
+ end
+
+ def void
+ @value_void = @method_params
+ end
+
+ def normal
+ @value_normal = @method_params
+ 5
+ end
+
+ def array_return
+ person = Person.new
+ person.firstnames = ["one", "two"]
+ person.lastname = "last"
+ @value_array_return = [person]
+ end
+
+ def struct_pass
+ @value_struct_pass = @method_params
+ true
+ end
+
+ def client_container
+ 50
+ end
+
+ def protocol_request(request)
+ probe_request_protocol(request)
+ end
+
+ def dispatch_request(protocol_request)
+ dispatch_service_request(protocol_request)
+ end
+ end
+
+ class AbstractClientLet < WEBrick::HTTPServlet::AbstractServlet
+ def initialize(controller)
+ @controller = controller
+ end
+
+ def get_instance(*args)
+ self
+ end
+
+ def require_path_info?
+ false
+ end
+
+ def do_GET(req, res)
+ raise WEBrick::HTTPStatus::MethodNotAllowed, "GET request not allowed."
+ end
+
+ def do_POST(req, res)
+ raise NotImplementedError
+ end
+ end
+
+ class AbstractServer
+ include ClientTest
+ include Singleton
+ attr :container
+ def initialize
+ @container = Container.new
+ @clientlet = create_clientlet(@container)
+ log = WEBrick::BasicLog.new(NullLogOut.new)
+ @server = WEBrick::HTTPServer.new(:Port => server_port, :Logger => log, :AccessLog => log)
+ @server.mount('/', @clientlet)
+ @thr = Thread.new { @server.start }
+ until @server.status == :Running; end
+ at_exit { @server.stop; @thr.join }
+ end
+
+ protected
+ def create_clientlet
+ raise NotImplementedError
+ end
+
+ def server_port
+ raise NotImplementedError
+ end
+ end
+end