From 100015cd806e31578a03ba23ffbc12c093118a26 Mon Sep 17 00:00:00 2001 From: Leon Breedt Date: Sun, 27 Feb 2005 21:21:40 +0000 Subject: Make all custom types and method calls are declared in the 'urn:ActionWebService' namespace as a default, fixes SOAP marshaling for .NET, a regression since the merge. Make array annotation be recursive in WS::Marshaling::SoapMarshaling, this makes typed arrays buried in nested structures still be annotated correctly. Support :layered dispatching mode for XML-RPC namespaced method names. Change WS::ParamInfo.create signature to require type_binding, and update all uses of this. Restore #default_api_method functionality, fixes a regression since the merge. Fix marshalling of ActiveRecord::Base derivatives, fixes a regression since the merge. This changeset closes #676, #677, and #678. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@811 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionwebservice/test/abstract_dispatcher.rb | 82 +++++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 3 deletions(-) (limited to 'actionwebservice/test/abstract_dispatcher.rb') diff --git a/actionwebservice/test/abstract_dispatcher.rb b/actionwebservice/test/abstract_dispatcher.rb index b743afce4c..da07d2cf8c 100644 --- a/actionwebservice/test/abstract_dispatcher.rb +++ b/actionwebservice/test/abstract_dispatcher.rb @@ -9,7 +9,7 @@ module DispatcherTest class << self def name - "Node" + "DispatcherTest::Node" end def columns(*args) @@ -26,6 +26,11 @@ module DispatcherTest end end + class Person < ActionWebService::Struct + member :id, :int + member :name, :string + end + class API < ActionWebService::API::Base api_method :add, :expects => [:int, :int], :returns => [:int] api_method :interceptee @@ -38,9 +43,14 @@ module DispatcherTest api_method :before_filtered api_method :after_filtered, :returns => [[:int]] api_method :struct_return, :returns => [[Node]] + api_method :base_struct_return, :returns => [[Person]] api_method :thrower api_method :void end + + class VirtualAPI < ActionWebService::API::Base + default_api_method :fallback + end class Service < ActionWebService::Base web_service_api API @@ -78,6 +88,32 @@ module DispatcherTest end end + class MTAPI < ActionWebService::API::Base + inflect_names false + api_method :getCategories, :returns => [[:string]] + end + + class BloggerAPI < ActionWebService::API::Base + inflect_names false + api_method :getCategories, :returns => [[:string]] + end + + class MTService < ActionWebService::Base + web_service_api MTAPI + + def getCategories + ["mtCat1", "mtCat2"] + end + end + + class BloggerService < ActionWebService::Base + web_service_api BloggerAPI + + def getCategories + ["bloggerCat1", "bloggerCat2"] + end + end + class AbstractController < ActionController::Base def generate_wsdl to_wsdl @@ -89,6 +125,13 @@ module DispatcherTest web_service(:test_service) { @service ||= Service.new; @service } end + + class LayeredController < AbstractController + web_service_dispatching_mode :layered + + web_service(:mt) { @mt_service ||= MTService.new; @mt_service } + web_service(:blogger) { @blogger_service ||= BloggerService.new; @blogger_service } + end class DirectController < AbstractController web_service_api DirectAPI @@ -134,6 +177,12 @@ module DispatcherTest n2 = Node.new('id' => 2, 'name' => 'node2', 'description' => 'Node 2') [n1, n2] end + + def base_struct_return + p1 = Person.new('id' => 1, 'name' => 'person1') + p2 = Person.new('id' => 2, 'name' => 'person2') + [p1, p2] + end def void @void_called = @method_params @@ -149,6 +198,14 @@ module DispatcherTest @after_filter_called = true end end + + class VirtualController < AbstractController + web_service_api VirtualAPI + + def fallback + "fallback!" + end + end end module DispatcherCommonTests @@ -163,11 +220,25 @@ module DispatcherCommonTests assert(do_method_call(@direct_controller, 'Void', 3, 4, 5) == true) end assert(@direct_controller.void_called == []) + result = do_method_call(@direct_controller, 'BaseStructReturn') + case @encoder + when WS::Encoding::SoapRpcEncoding + assert(result[0].is_a?(DispatcherTest::Person)) + assert(result[1].is_a?(DispatcherTest::Person)) + when WS::Encoding::XmlRpcEncoding + assert(result[0].is_a?(Hash)) + assert(result[1].is_a?(Hash)) + end end def test_direct_entrypoint assert(@direct_controller.respond_to?(:api)) end + + def test_virtual_dispatching + assert_equal("fallback!", do_method_call(@virtual_controller, 'VirtualOne')) + assert_equal("fallback!", do_method_call(@virtual_controller, 'VirtualTwo')) + end def test_direct_filtering assert_equal(false, @direct_controller.before_filter_called) @@ -269,8 +340,13 @@ module DispatcherCommonTests api = container.class.web_service_api when :delegated api = container.web_service_object(service_name(container)).class.web_service_api + when :layered + service_name = nil + if public_method_name =~ /^([^\.]+)\.(.*)$/ + service_name = $1 + end + api = container.web_service_object(service_name.to_sym).class.web_service_api end - method_name = api.api_method_name(public_method_name) info = api.api_methods[method_name] || {} params = params.dup ((info[:expects] || []) + (info[:returns] || [])).each do |spec| @@ -279,7 +355,7 @@ module DispatcherCommonTests expects = info[:expects] (0..(params.length-1)).each do |i| type_binding = @marshaler.register_type(expects ? expects[i] : params[i].class) - info = WS::ParamInfo.create(expects ? expects[i] : params[i].class, i, type_binding) + info = WS::ParamInfo.create(expects ? expects[i] : params[i].class, type_binding, i) params[i] = @marshaler.marshal(WS::Param.new(params[i], info)) end body = @encoder.encode_rpc_call(public_method_name, params) -- cgit v1.2.3