diff options
author | Leon Breedt <bitserf@gmail.com> | 2005-02-27 21:21:40 +0000 |
---|---|---|
committer | Leon Breedt <bitserf@gmail.com> | 2005-02-27 21:21:40 +0000 |
commit | 100015cd806e31578a03ba23ffbc12c093118a26 (patch) | |
tree | 20cd8b5f8fd8cbfb60f2b8d2f309c0c259889d50 /actionwebservice/test | |
parent | 19dddf24a63bd8a715ca47955963ba77d174d830 (diff) | |
download | rails-100015cd806e31578a03ba23ffbc12c093118a26.tar.gz rails-100015cd806e31578a03ba23ffbc12c093118a26.tar.bz2 rails-100015cd806e31578a03ba23ffbc12c093118a26.zip |
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
Diffstat (limited to 'actionwebservice/test')
6 files changed, 112 insertions, 15 deletions
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) diff --git a/actionwebservice/test/dispatcher_action_controller_soap_test.rb b/actionwebservice/test/dispatcher_action_controller_soap_test.rb index 9cb99be78d..6d50bbba8a 100644 --- a/actionwebservice/test/dispatcher_action_controller_soap_test.rb +++ b/actionwebservice/test/dispatcher_action_controller_soap_test.rb @@ -11,10 +11,11 @@ class TC_DispatcherActionControllerSoap < Test::Unit::TestCase include DispatcherCommonTests def setup - @encoder = WS::Encoding::SoapRpcEncoding.new - @marshaler = WS::Marshaling::SoapMarshaler.new + @encoder = WS::Encoding::SoapRpcEncoding.new 'urn:ActionWebService' + @marshaler = WS::Marshaling::SoapMarshaler.new 'urn:ActionWebService' @direct_controller = DirectController.new @delegated_controller = DelegatedController.new + @virtual_controller = VirtualController.new end def test_wsdl_generation @@ -23,8 +24,15 @@ class TC_DispatcherActionControllerSoap < Test::Unit::TestCase end def test_wsdl_action - ensure_valid_wsdl_action DelegatedController.new - ensure_valid_wsdl_action DirectController.new + delegated_types = ensure_valid_wsdl_action DelegatedController.new + delegated_names = delegated_types.map{|x| x.name.name} + assert(delegated_names.include?('DispatcherTest..NodeArray')) + assert(delegated_names.include?('DispatcherTest..Node')) + direct_types = ensure_valid_wsdl_action DirectController.new + direct_names = direct_types.map{|x| x.name.name} + assert(direct_names.include?('DispatcherTest..NodeArray')) + assert(direct_names.include?('DispatcherTest..Node')) + assert(direct_names.include?('IntegerArray')) end def test_autoloading @@ -80,6 +88,11 @@ class TC_DispatcherActionControllerSoap < Test::Unit::TestCase assert(port.name.name.index(':').nil?) end end + types = definitions.collect_complextypes.map{|x| x.name} + types.each do |type| + assert(type.namespace == 'urn:ActionWebService') + end + definitions.collect_complextypes end def ensure_valid_wsdl_action(controller) diff --git a/actionwebservice/test/dispatcher_action_controller_xmlrpc_test.rb b/actionwebservice/test/dispatcher_action_controller_xmlrpc_test.rb index 13f193e2c5..87677dec3e 100644 --- a/actionwebservice/test/dispatcher_action_controller_xmlrpc_test.rb +++ b/actionwebservice/test/dispatcher_action_controller_xmlrpc_test.rb @@ -9,6 +9,15 @@ class TC_DispatcherActionControllerXmlRpc < Test::Unit::TestCase @marshaler = WS::Marshaling::XmlRpcMarshaler.new @direct_controller = DirectController.new @delegated_controller = DelegatedController.new + @layered_controller = LayeredController.new + @virtual_controller = VirtualController.new + end + + def test_layered_dispatching + mt_cats = do_method_call(@layered_controller, 'mt.getCategories') + assert_equal(["mtCat1", "mtCat2"], mt_cats) + blogger_cats = do_method_call(@layered_controller, 'blogger.getCategories') + assert_equal(["bloggerCat1", "bloggerCat2"], blogger_cats) end protected diff --git a/actionwebservice/test/ws/abstract_encoding.rb b/actionwebservice/test/ws/abstract_encoding.rb index 9a6aec44e0..6032d94c48 100644 --- a/actionwebservice/test/ws/abstract_encoding.rb +++ b/actionwebservice/test/ws/abstract_encoding.rb @@ -45,7 +45,7 @@ module EncodingTest params = params.dup (0..(signature.length-1)).each do |i| type_binding = @marshaler.register_type(signature[i]) - info = WS::ParamInfo.create(signature[i], i, type_binding) + info = WS::ParamInfo.create(signature[i], type_binding, i) params[i] = @marshaler.marshal(WS::Param.new(params[i], info)) end @encoder.encode_rpc_call(method_name, params) @@ -57,7 +57,7 @@ module EncodingTest def encode_rpc_response(method_name, signature, param) type_binding = @marshaler.register_type(signature[0]) - info = WS::ParamInfo.create(signature[0], 0, type_binding) + info = WS::ParamInfo.create(signature[0], type_binding, 0) param = @marshaler.marshal(WS::Param.new(param, info)) @encoder.encode_rpc_response(method_name, param) end diff --git a/actionwebservice/test/ws/abstract_unit.rb b/actionwebservice/test/ws/abstract_unit.rb index f5015bea69..5d4f5ce856 100644 --- a/actionwebservice/test/ws/abstract_unit.rb +++ b/actionwebservice/test/ws/abstract_unit.rb @@ -1,6 +1,5 @@ -$:.unshift(File.dirname(File.dirname(__FILE__)) + '/../lib') -$:.unshift(File.dirname(File.dirname(__FILE__)) + '/../lib/action_web_service/vendor') -puts $:.inspect +require 'pathname' +$:.unshift(Pathname.new(File.dirname(__FILE__)).realpath.to_s + '/../../lib/action_web_service/vendor') require 'test/unit' require 'ws' begin diff --git a/actionwebservice/test/ws/soap_marshaling_test.rb b/actionwebservice/test/ws/soap_marshaling_test.rb index ee6413478d..7c7413190e 100644 --- a/actionwebservice/test/ws/soap_marshaling_test.rb +++ b/actionwebservice/test/ws/soap_marshaling_test.rb @@ -33,14 +33,14 @@ class SoapMarshalingTest < Test::Unit::TestCase end def test_marshaling - info = WS::ParamInfo.create(Nested::MyClass) + info = WS::ParamInfo.create(Nested::MyClass, @marshaler.register_type(Nested::MyClass)) param = WS::Param.new(Nested::MyClass.new(2, "name"), info) new_param = @marshaler.unmarshal(@marshaler.marshal(param)) assert(param == new_param) end def test_exception_marshaling - info = WS::ParamInfo.create(RuntimeError) + info = WS::ParamInfo.create(RuntimeError, @marshaler.register_type(RuntimeError)) param = WS::Param.new(RuntimeError.new("hello, world"), info) new_param = @marshaler.unmarshal(@marshaler.marshal(param)) assert_equal("hello, world", new_param.value.detail.cause.message) @@ -78,7 +78,7 @@ class SoapMarshalingTest < Test::Unit::TestCase end end end - info = WS::ParamInfo.create(node_class, 0, @marshaler.register_type(node_class)) + info = WS::ParamInfo.create(node_class, @marshaler.register_type(node_class), 0) ar_obj = node_class.new('name' => 'hello', 'email' => 'test@test.com') param = WS::Param.new(ar_obj, info) obj = @marshaler.marshal(param) |