mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
418d487020
* move dispatching out of the Container into Dispatcher, it makes more sense for Container to only contain the list of web services defined in it. * collapse Wsdl and ActionController "routers" into an ActionController-specific module, no advantage to having them seperate as they were quite tightly coupled. rename to Dispatcher, to avoi confusion with Routing. * add a "_thing" suffix to concept-specific filenames. this is so that we don't end up with many soap.rb files, for example. * remove "virtual invocation" support. adds complexity, and it doesn't seem to add any value. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@679 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
147 lines
3.7 KiB
Ruby
147 lines
3.7 KiB
Ruby
require File.dirname(__FILE__) + '/abstract_unit'
|
|
require 'xmlrpc/parser'
|
|
require 'xmlrpc/create'
|
|
require 'xmlrpc/config'
|
|
|
|
module XMLRPC
|
|
class XmlRpcTestHelper
|
|
include ParserWriterChooseMixin
|
|
|
|
def create_request(methodName, *args)
|
|
create().methodCall(methodName, *args)
|
|
end
|
|
|
|
def parse_response(response)
|
|
parser().parseMethodResponse(response)
|
|
end
|
|
end
|
|
end
|
|
|
|
module ProtocolXmlRpcTest
|
|
class Person < ActionWebService::Struct
|
|
member :firstname, String
|
|
member :lastname, String
|
|
member :active, TrueClass
|
|
end
|
|
|
|
class API < ActionWebService::API::Base
|
|
api_method :add, :expects => [Integer, Integer], :returns => [Integer]
|
|
api_method :hash_returner, :returns => [Hash]
|
|
api_method :array_returner, :returns => [[Integer]]
|
|
api_method :something_hash, :expects => [Hash]
|
|
api_method :struct_array_returner, :returns => [[Person]]
|
|
|
|
default_api_method :default
|
|
end
|
|
|
|
class Service < ActionWebService::Base
|
|
web_service_api API
|
|
|
|
attr :result
|
|
attr :hashvalue
|
|
attr :default_args
|
|
|
|
def initialize
|
|
@result = nil
|
|
@hashvalue = nil
|
|
@default_args = nil
|
|
end
|
|
|
|
def add(a, b)
|
|
@result = a + b
|
|
end
|
|
|
|
def something_hash(hash)
|
|
@hashvalue = hash
|
|
end
|
|
|
|
def array_returner
|
|
[1, 2, 3]
|
|
end
|
|
|
|
def hash_returner
|
|
{'name' => 1, 'value' => 2}
|
|
end
|
|
|
|
def struct_array_returner
|
|
person = Person.new
|
|
person.firstname = "John"
|
|
person.lastname = "Doe"
|
|
person.active = true
|
|
[person]
|
|
end
|
|
|
|
def default(*args)
|
|
@default_args = args
|
|
nil
|
|
end
|
|
end
|
|
|
|
$service = Service.new
|
|
|
|
class Container < ActionController::Base
|
|
def protocol_request(request)
|
|
probe_request_protocol(request)
|
|
end
|
|
|
|
def dispatch_request(protocol_request)
|
|
dispatch_protocol_request(protocol_request)
|
|
end
|
|
|
|
web_service :xmlrpc, $service
|
|
web_service_dispatching_mode :delegated
|
|
end
|
|
end
|
|
|
|
class TC_ProtocolXmlRpc < Test::Unit::TestCase
|
|
def setup
|
|
@helper = XMLRPC::XmlRpcTestHelper.new
|
|
@container = ProtocolXmlRpcTest::Container.new
|
|
end
|
|
|
|
def test_xmlrpc_request_dispatching
|
|
retval = do_xmlrpc_call('Add', 50, 30)
|
|
assert(retval == [true, 80])
|
|
end
|
|
|
|
def test_array_returning
|
|
retval = do_xmlrpc_call('ArrayReturner')
|
|
assert(retval == [true, [1, 2, 3]])
|
|
end
|
|
|
|
def test_hash_returning
|
|
retval = do_xmlrpc_call('HashReturner')
|
|
assert(retval == [true, {'name' => 1, 'value' => 2}])
|
|
end
|
|
|
|
def test_struct_array_returning
|
|
retval = do_xmlrpc_call('StructArrayReturner')
|
|
assert(retval == [true, [{"firstname"=>"John", "lastname"=>"Doe", "active"=>true}]])
|
|
end
|
|
|
|
def test_hash_parameter
|
|
retval = do_xmlrpc_call('SomethingHash', {'name' => 1, 'value' => 2})
|
|
assert(retval == [true, true])
|
|
assert($service.hashvalue == {'name' => 1, 'value' => 2})
|
|
end
|
|
|
|
def test_default_api_method
|
|
retval = do_xmlrpc_call('SomeNonexistentMethod', 'test', [1, 2], {'name'=>'value'})
|
|
assert(retval == [true, true])
|
|
assert($service.default_args == ['test', [1, 2], {'name'=>'value'}])
|
|
end
|
|
|
|
private
|
|
def do_xmlrpc_call(public_method_name, *args)
|
|
service_name = 'xmlrpc'
|
|
raw_request = @helper.create_request(public_method_name, *args)
|
|
test_request = ActionController::TestRequest.new
|
|
test_request.request_parameters['action'] = service_name
|
|
test_request.env['REQUEST_METHOD'] = "POST"
|
|
test_request.env['HTTP_CONTENTTYPE'] = 'text/xml'
|
|
test_request.env['RAW_POST_DATA'] = raw_request
|
|
protocol_request = @container.protocol_request(test_request)
|
|
response = @container.dispatch_request(protocol_request)
|
|
@helper.parse_response(response.raw_body)
|
|
end
|
|
end
|