From aaea48fe9826b9e5d2d5b92795a297b8f238c58d Mon Sep 17 00:00:00 2001 From: Leon Breedt Date: Sat, 2 Apr 2005 21:03:36 +0000 Subject: * collapse 'ws' back into protocols, it just added complexity and indirection, and was hard to extend. * extract casting into seperate support file * ensure casting always does the right thing for return values, should fix interoperability issues with Ecto and possibly other XML-RPC clients * add functional unit tests for scaffolding * represent signature items with classes instead of symbols/Class objects, much more flexible * tweak logging to always show casted versions of parameters and return values, if possible. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1072 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionwebservice/test/abstract_dispatcher.rb | 96 ++++++++++----------- actionwebservice/test/abstract_unit.rb | 2 +- actionwebservice/test/api_test.rb | 16 ++-- actionwebservice/test/casting_test.rb | 82 ++++++++++++++++++ actionwebservice/test/client_soap_test.rb | 4 +- actionwebservice/test/client_xmlrpc_test.rb | 7 +- .../test/dispatcher_action_controller_soap_test.rb | 2 - .../dispatcher_action_controller_xmlrpc_test.rb | 2 - .../test/scaffolded_controller_test.rb | 67 +++++++++++++++ actionwebservice/test/struct_test.rb | 56 ++++++++----- actionwebservice/test/test_invoke_test.rb | 2 +- actionwebservice/test/ws/abstract_encoding.rb | 68 --------------- actionwebservice/test/ws/abstract_unit.rb | 13 --- actionwebservice/test/ws/gencov | 3 - actionwebservice/test/ws/run | 5 -- actionwebservice/test/ws/soap_marshaling_test.rb | 97 ---------------------- actionwebservice/test/ws/soap_rpc_encoding_test.rb | 47 ----------- actionwebservice/test/ws/types_test.rb | 43 ---------- actionwebservice/test/ws/xmlrpc_encoding_test.rb | 34 -------- 19 files changed, 247 insertions(+), 399 deletions(-) create mode 100644 actionwebservice/test/casting_test.rb create mode 100644 actionwebservice/test/scaffolded_controller_test.rb delete mode 100644 actionwebservice/test/ws/abstract_encoding.rb delete mode 100644 actionwebservice/test/ws/abstract_unit.rb delete mode 100755 actionwebservice/test/ws/gencov delete mode 100755 actionwebservice/test/ws/run delete mode 100644 actionwebservice/test/ws/soap_marshaling_test.rb delete mode 100644 actionwebservice/test/ws/soap_rpc_encoding_test.rb delete mode 100644 actionwebservice/test/ws/types_test.rb delete mode 100644 actionwebservice/test/ws/xmlrpc_encoding_test.rb (limited to 'actionwebservice/test') diff --git a/actionwebservice/test/abstract_dispatcher.rb b/actionwebservice/test/abstract_dispatcher.rb index 53be05f9f2..4784180518 100644 --- a/actionwebservice/test/abstract_dispatcher.rb +++ b/actionwebservice/test/abstract_dispatcher.rb @@ -1,4 +1,5 @@ require File.dirname(__FILE__) + '/abstract_unit' +require 'stringio' class ActionController::Base; def rescue_action(e) raise e end; end @@ -50,8 +51,9 @@ module DispatcherTest api_method :before_filtered api_method :after_filtered, :returns => [[:int]] api_method :struct_return, :returns => [[Node]] - api_method :struct_pass, :expects => [Person] + api_method :struct_pass, :expects => [{:person => Person}] api_method :base_struct_return, :returns => [[Person]] + api_method :hash_struct_return, :returns => [[Person]] api_method :thrower api_method :void end @@ -202,6 +204,12 @@ module DispatcherTest p2 = Person.new('id' => 2, 'name' => 'person2') [p1, p2] end + + def hash_struct_return + p1 = { :id => '1', 'name' => 'test' } + p2 = { 'id' => '2', :name => 'person2' } + [p1, p2] + end def void @void_called = @method_params @@ -234,22 +242,11 @@ module DispatcherCommonTests assert_equal(50, do_method_call(@direct_controller, 'Add2', 25, 25)) assert_equal(50, @direct_controller.added2) assert(@direct_controller.void_called == false) - case @encoder - when WS::Encoding::SoapRpcEncoding - assert(do_method_call(@direct_controller, 'Void', 3, 4, 5).nil?) - when WS::Encoding::XmlRpcEncoding - assert(do_method_call(@direct_controller, 'Void', 3, 4, 5) == true) - end + assert(do_method_call(@direct_controller, 'Void', 3, 4, 5).nil?) 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 + assert(result[0].is_a?(DispatcherTest::Person)) + assert(result[1].is_a?(DispatcherTest::Person)) end def test_direct_entrypoint @@ -288,12 +285,7 @@ module DispatcherCommonTests assert(is_exception?(result)) assert_match(/NonExistentMethod/, exception_message(result)) assert(service.void_called == false) - case @encoder - when WS::Encoding::SoapRpcEncoding - assert(do_method_call(@delegated_controller, 'Void', 3, 4, 5).nil?) - when WS::Encoding::XmlRpcEncoding - assert(do_method_call(@delegated_controller, 'Void', 3, 4, 5) == true) - end + assert(do_method_call(@delegated_controller, 'Void', 3, 4, 5).nil?) assert(service.void_called == []) end @@ -302,7 +294,7 @@ module DispatcherCommonTests controller.class.web_service_exception_reporting = true send_garbage_request = lambda do service_name = service_name(controller) - request = @protocol.create_action_pack_request(service_name, 'broken, method, name!', 'broken request body', :request_class => ActionController::TestRequest) + request = @protocol.encode_action_pack_request(service_name, 'broken, method, name!', 'broken request body', :request_class => ActionController::TestRequest) response = ActionController::TestResponse.new controller.process(request, response) # puts response.body @@ -327,18 +319,10 @@ module DispatcherCommonTests def test_ar_struct_return [@direct_controller, @delegated_controller].each do |controller| result = do_method_call(controller, 'StructReturn') - case @encoder - when WS::Encoding::SoapRpcEncoding - assert(result[0].is_a?(DispatcherTest::Node)) - assert(result[1].is_a?(DispatcherTest::Node)) - assert_equal('node1', result[0].name) - assert_equal('node2', result[1].name) - when WS::Encoding::XmlRpcEncoding - assert(result[0].is_a?(Hash)) - assert(result[1].is_a?(Hash)) - assert_equal('node1', result[0]['name']) - assert_equal('node2', result[1]['name']) - end + assert(result[0].is_a?(DispatcherTest::Node)) + assert(result[1].is_a?(DispatcherTest::Node)) + assert_equal('node1', result[0].name) + assert_equal('node2', result[1].name) end end @@ -351,15 +335,26 @@ module DispatcherCommonTests assert_equal person, @direct_controller.struct_pass_value assert !person.equal?(@direct_controller.struct_pass_value) result = do_method_call(@direct_controller, 'StructPass', {'id' => '1', 'name' => 'test'}) - case @encoder - when WS::Encoding::SoapRpcEncoding - # We don't cast complex types for SOAP. SOAP clients should have used the WSDL to - # send the correct types. - assert_equal({'id' => '1', 'name' => 'test'}, @direct_controller.struct_pass_value) - when WS::Encoding::XmlRpcEncoding + case @protocol + when ActionWebService::Protocol::Soap::SoapProtocol + assert_equal(person, @direct_controller.struct_pass_value) + assert !person.equal?(@direct_controller.struct_pass_value) + when ActionWebService::Protocol::XmlRpc::XmlRpcProtocol assert_equal(person, @direct_controller.struct_pass_value) assert !person.equal?(@direct_controller.struct_pass_value) end + assert_equal person, do_method_call(@direct_controller, 'HashStructReturn')[0] + end + + def test_logging + buf = "" + ActionController::Base.logger = Logger.new(StringIO.new(buf)) + test_casting + test_garbage_request + test_exception_marshaling + ActionController::Base.logger = nil + assert_match /Web Service Response/, buf + assert_match /Web Service Request/, buf end protected @@ -392,20 +387,27 @@ module DispatcherCommonTests api = container.web_service_object(service_name.to_sym).class.web_service_api service_name = self.service_name(container) end + @protocol.register_api(api) method = api.public_api_method_instance(public_method_name) - method ||= api.dummy_public_api_method_instance(public_method_name) - # we turn off strict so we can test our own handling of incorrectly typed parameters - body = method.encode_rpc_call(@marshaler, @encoder, params.dup, :strict => false) + virtual = false + unless method + virtual = true + method ||= ActionWebService::API::Method.new(public_method_name.underscore.to_sym, public_method_name, nil, nil) + end + body = @protocol.encode_request(public_method_name, params.dup, method.expects) # puts body - ap_request = protocol.create_action_pack_request(service_name, public_method_name, body, :request_class => ActionController::TestRequest) + ap_request = @protocol.encode_action_pack_request(service_name, public_method_name, body, :request_class => ActionController::TestRequest) ap_response = ActionController::TestResponse.new container.process(ap_request, ap_response) # puts ap_response.body - public_method_name, return_value = @encoder.decode_rpc_response(ap_response.body) - if @encoder.is_a?(WS::Encoding::SoapRpcEncoding) + public_method_name, return_value = @protocol.decode_response(ap_response.body) + unless is_exception?(return_value) || virtual + return_value = method.cast_returns(return_value) + end + if @protocol.is_a?(ActionWebService::Protocol::Soap::SoapProtocol) # http://dev.rubyonrails.com/changeset/920 assert_match(/Response$/, public_method_name) unless public_method_name == "fault" end - @marshaler.unmarshal(return_value).value + return_value end end diff --git a/actionwebservice/test/abstract_unit.rb b/actionwebservice/test/abstract_unit.rb index e8304e3790..cbeda66e90 100644 --- a/actionwebservice/test/abstract_unit.rb +++ b/actionwebservice/test/abstract_unit.rb @@ -1,5 +1,5 @@ +ENV["RAILS_ENV"] = "test" $:.unshift(File.dirname(__FILE__) + '/../lib') -$:.unshift(File.dirname(__FILE__) + '/../lib/action_web_service/vendor') require 'test/unit' require 'action_web_service' diff --git a/actionwebservice/test/api_test.rb b/actionwebservice/test/api_test.rb index 4a61ae8de7..f6d73866b7 100644 --- a/actionwebservice/test/api_test.rb +++ b/actionwebservice/test/api_test.rb @@ -37,17 +37,17 @@ class TC_API < Test::Unit::TestCase def test_signature_canonicalization assert_equal(nil, API.api_methods[:void].expects) assert_equal(nil, API.api_methods[:void].returns) - assert_equal([String], API.api_methods[:expects_and_returns].expects) - assert_equal([String], API.api_methods[:expects_and_returns].returns) - assert_equal([Integer, TrueClass], API.api_methods[:expects].expects) + assert_equal([String], API.api_methods[:expects_and_returns].expects.map{|x| x.type_class}) + assert_equal([String], API.api_methods[:expects_and_returns].returns.map{|x| x.type_class}) + assert_equal([Integer, TrueClass], API.api_methods[:expects].expects.map{|x| x.type_class}) assert_equal(nil, API.api_methods[:expects].returns) assert_equal(nil, API.api_methods[:returns].expects) - assert_equal([Integer, [String]], API.api_methods[:returns].returns) - assert_equal([{:appkey=>Integer}, {:publish=>TrueClass}], API.api_methods[:named_signature].expects) + assert_equal([Integer, [String]], API.api_methods[:returns].returns.map{|x| x.array?? [x.element_type.type_class] : x.type_class}) + assert_equal([[:appkey, Integer], [:publish, TrueClass]], API.api_methods[:named_signature].expects.map{|x| [x.name, x.type_class]}) assert_equal(nil, API.api_methods[:named_signature].returns) - assert_equal([Integer, String, TrueClass], API.api_methods[:string_types].expects) + assert_equal([Integer, String, TrueClass], API.api_methods[:string_types].expects.map{|x| x.type_class}) assert_equal(nil, API.api_methods[:string_types].returns) - assert_equal([TrueClass, Integer, String], API.api_methods[:class_types].expects) + assert_equal([TrueClass, Integer, String], API.api_methods[:class_types].expects.map{|x| x.type_class}) assert_equal(nil, API.api_methods[:class_types].returns) end @@ -75,6 +75,6 @@ class TC_API < Test::Unit::TestCase end def test_to_s - assert_equal 'void Expects(int p1, bool p2)', APITest::API.api_methods[:expects].to_s + assert_equal 'void Expects(int param0, bool param1)', APITest::API.api_methods[:expects].to_s end end diff --git a/actionwebservice/test/casting_test.rb b/actionwebservice/test/casting_test.rb new file mode 100644 index 0000000000..223313564b --- /dev/null +++ b/actionwebservice/test/casting_test.rb @@ -0,0 +1,82 @@ +require File.dirname(__FILE__) + '/abstract_unit' + +module CastingTest + class API < ActionWebService::API::Base + api_method :int, :expects => [:int] + api_method :str, :expects => [:string] + api_method :bool, :expects => [:bool] + api_method :float, :expects => [:float] + api_method :time, :expects => [:time] + api_method :datetime, :expects => [:datetime] + api_method :date, :expects => [:date] + + api_method :int_array, :expects => [[:int]] + api_method :str_array, :expects => [[:string]] + api_method :bool_array, :expects => [[:bool]] + end +end + +class TC_Casting < Test::Unit::TestCase + include CastingTest + + def test_base_type_casting_valid + assert_equal 10000, cast_expects(:int, '10000')[0] + assert_equal '10000', cast_expects(:str, 10000)[0] + [1, '1', 'true', 'y', 'yes'].each do |val| + assert_equal true, cast_expects(:bool, val)[0] + end + [0, '0', 'false', 'n', 'no'].each do |val| + assert_equal false, cast_expects(:bool, val)[0] + end + assert_equal 3.14159, cast_expects(:float, '3.14159')[0] + now = Time.at(Time.now.tv_sec) + casted = cast_expects(:time, now.to_s)[0] + assert_equal now, casted + now = DateTime.now + assert_equal now.to_s, cast_expects(:datetime, now.to_s)[0].to_s + today = Date.today + assert_equal today, cast_expects(:date, today.to_s)[0] + end + + def test_base_type_casting_invalid + assert_raises ArgumentError do + cast_expects(:int, 'this is not a number') + end + assert_raises ActionWebService::Casting::CastingError do + # neither true or false ;) + cast_expects(:bool, 'i always lie') + end + assert_raises ArgumentError do + cast_expects(:float, 'not a float') + end + assert_raises ArgumentError do + cast_expects(:time, '111111111111111111111111111111111') + end + assert_raises ArgumentError do + cast_expects(:datetime, '-1') + end + assert_raises ArgumentError do + cast_expects(:date, '') + end + end + + def test_array_type_casting + assert_equal [1, 2, 3213992, 4], cast_expects(:int_array, ['1', '2', '3213992', '4'])[0] + assert_equal ['one', 'two', '5.0', '200', '', 'true'], cast_expects(:str_array, [:one, 'two', 5.0, 200, nil, true])[0] + assert_equal [true, false, true, true, false], cast_expects(:bool_array, ['1', nil, 'y', true, 'false'])[0] + end + + def test_array_type_casting_failure + assert_raises ActionWebService::Casting::CastingError do + cast_expects(:bool_array, ['false', 'blahblah']) + end + assert_raises ArgumentError do + cast_expects(:int_array, ['1', '2.021', '4']) + end + end + + private + def cast_expects(method_name, *args) + API.api_method_instance(method_name.to_sym).cast_expects([*args]) + end +end diff --git a/actionwebservice/test/client_soap_test.rb b/actionwebservice/test/client_soap_test.rb index 941a642554..e118b4956e 100644 --- a/actionwebservice/test/client_soap_test.rb +++ b/actionwebservice/test/client_soap_test.rb @@ -68,9 +68,7 @@ class TC_ClientSoap < Test::Unit::TestCase assert_equal([5, 6], @container.value_normal) assert_equal(5, @client.normal("7", "8")) assert_equal([7, 8], @container.value_normal) - assert_raises(TypeError) do - assert_equal(5, @client.normal(true, false)) - end + assert_equal(5, @client.normal(true, false)) end def test_array_return diff --git a/actionwebservice/test/client_xmlrpc_test.rb b/actionwebservice/test/client_xmlrpc_test.rb index 3301113d95..de24d9a975 100644 --- a/actionwebservice/test/client_xmlrpc_test.rb +++ b/actionwebservice/test/client_xmlrpc_test.rb @@ -15,6 +15,7 @@ module ClientXmlRpcTest @controller.process(test_request, response) res.header['content-type'] = 'text/xml' res.body = response.body + # puts res.body rescue Exception => e $stderr.puts e.message $stderr.puts e.backtrace.join("\n") @@ -62,9 +63,7 @@ class TC_ClientXmlRpc < Test::Unit::TestCase assert_equal([5, 6], @container.value_normal) assert_equal(5, @client.normal("7", "8")) assert_equal([7, 8], @container.value_normal) - assert_raises(TypeError) do - assert_equal(5, @client.normal(true, false)) - end + assert_equal(5, @client.normal(true, false)) end def test_array_return @@ -91,7 +90,7 @@ class TC_ClientXmlRpc < Test::Unit::TestCase def test_named_parameters assert(@container.value_named_parameters.nil?) - assert_equal(nil, @client.named_parameters("xxx", 7)) + assert_equal(true, @client.named_parameters("xxx", 7)) assert_equal(["xxx", 7], @container.value_named_parameters) end diff --git a/actionwebservice/test/dispatcher_action_controller_soap_test.rb b/actionwebservice/test/dispatcher_action_controller_soap_test.rb index 76fc6094c2..3d7327be02 100644 --- a/actionwebservice/test/dispatcher_action_controller_soap_test.rb +++ b/actionwebservice/test/dispatcher_action_controller_soap_test.rb @@ -23,8 +23,6 @@ class TC_DispatcherActionControllerSoap < Test::Unit::TestCase include DispatcherCommonTests def setup - @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 diff --git a/actionwebservice/test/dispatcher_action_controller_xmlrpc_test.rb b/actionwebservice/test/dispatcher_action_controller_xmlrpc_test.rb index c92f270a1b..f1dc992818 100644 --- a/actionwebservice/test/dispatcher_action_controller_xmlrpc_test.rb +++ b/actionwebservice/test/dispatcher_action_controller_xmlrpc_test.rb @@ -6,8 +6,6 @@ class TC_DispatcherActionControllerXmlRpc < Test::Unit::TestCase def setup @protocol = ActionWebService::Protocol::XmlRpc::XmlRpcProtocol.new - @encoder = WS::Encoding::XmlRpcEncoding.new - @marshaler = WS::Marshaling::XmlRpcMarshaler.new @direct_controller = DirectController.new @delegated_controller = DelegatedController.new @layered_controller = LayeredController.new diff --git a/actionwebservice/test/scaffolded_controller_test.rb b/actionwebservice/test/scaffolded_controller_test.rb new file mode 100644 index 0000000000..2fa3a6030c --- /dev/null +++ b/actionwebservice/test/scaffolded_controller_test.rb @@ -0,0 +1,67 @@ +require File.dirname(__FILE__) + '/abstract_unit' + +ActionController::Routing::Routes.draw do |map| + map.connect '', :controller => 'scaffolded' +end + +class ScaffoldPerson < ActionWebService::Struct + member :id, :int + member :name, :string + + def ==(other) + self.id == other.id && self.name == other.name + end +end + +class ScaffoldedControllerTestAPI < ActionWebService::API::Base + api_method :hello, :expects => [{:integer=>:int}, :string], :returns => [:bool] + api_method :bye, :returns => [[ScaffoldPerson]] +end + +class ScaffoldedController < ActionController::Base + web_service_api ScaffoldedControllerTestAPI + web_service_scaffold :scaffold_invoke + + def hello(int, string) + 0 + end + + def bye + [ScaffoldPerson.new(:id => 1, :name => "leon"), ScaffoldPerson.new(:id => 2, :name => "paul")] + end + + def rescue_action(e) + raise e + end +end + +class ScaffoldedControllerTest < Test::Unit::TestCase + def setup + @controller = ScaffoldedController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + end + + def test_scaffold_invoke + get :scaffold_invoke + assert_rendered_file 'methods.rhtml' + end + + def test_scaffold_invoke_method_params + get :scaffold_invoke_method_params, :service => 'scaffolded', :method => 'Hello' + assert_rendered_file 'parameters.rhtml' + end + + def test_scaffold_invoke_submit_hello + post :scaffold_invoke_submit, :service => 'scaffolded', :method => 'Hello', :method_params => ['5', 'hello world'] + assert_rendered_file 'result.rhtml' + assert_equal false, @controller.instance_eval{ @method_return_value } + end + + def test_scaffold_invoke_submit_bye + post :scaffold_invoke_submit, :service => 'scaffolded', :method => 'Bye' + assert_rendered_file 'result.rhtml' + persons = [ScaffoldPerson.new(:id => 1, :name => "leon"), ScaffoldPerson.new(:id => 2, :name => "paul")] + assert_equal persons, @controller.instance_eval{ @method_return_value } + end +end diff --git a/actionwebservice/test/struct_test.rb b/actionwebservice/test/struct_test.rb index e6f1603c73..838cc2569c 100644 --- a/actionwebservice/test/struct_test.rb +++ b/actionwebservice/test/struct_test.rb @@ -11,30 +11,44 @@ module StructTest end class TC_Struct < Test::Unit::TestCase + include StructTest + + def setup + @struct = Struct.new(:id => 5, + :name => 'hello', + :items => ['one', 'two'], + :deleted => true, + :emails => ['test@test.com']) + end + def test_members - assert_equal(5, StructTest::Struct.members.size) - assert_equal(Integer, StructTest::Struct.members[:id]) - assert_equal(String, StructTest::Struct.members[:name]) - assert_equal([String], StructTest::Struct.members[:items]) - assert_equal(TrueClass, StructTest::Struct.members[:deleted]) - assert_equal([String], StructTest::Struct.members[:emails]) + assert_equal(5, Struct.members.size) + assert_equal(Integer, Struct.members[:id].type_class) + assert_equal(String, Struct.members[:name].type_class) + assert_equal(String, Struct.members[:items].element_type.type_class) + assert_equal(TrueClass, Struct.members[:deleted].type_class) + assert_equal(String, Struct.members[:emails].element_type.type_class) end def test_initializer_and_lookup - s = StructTest::Struct.new(:id => 5, - :name => 'hello', - :items => ['one', 'two'], - :deleted => true, - :emails => ['test@test.com']) - assert_equal(5, s.id) - assert_equal('hello', s.name) - assert_equal(['one', 'two'], s.items) - assert_equal(true, s.deleted) - assert_equal(['test@test.com'], s.emails) - assert_equal(5, s['id']) - assert_equal('hello', s['name']) - assert_equal(['one', 'two'], s['items']) - assert_equal(true, s['deleted']) - assert_equal(['test@test.com'], s['emails']) + assert_equal(5, @struct.id) + assert_equal('hello', @struct.name) + assert_equal(['one', 'two'], @struct.items) + assert_equal(true, @struct.deleted) + assert_equal(['test@test.com'], @struct.emails) + assert_equal(5, @struct['id']) + assert_equal('hello', @struct['name']) + assert_equal(['one', 'two'], @struct['items']) + assert_equal(true, @struct['deleted']) + assert_equal(['test@test.com'], @struct['emails']) + end + + def test_each_pair + members = {} + @struct.each_pair do |name, type| + members[name] = type + assert ActionWebService::BaseType === type + end + assert_equal members, Struct.members end end diff --git a/actionwebservice/test/test_invoke_test.rb b/actionwebservice/test/test_invoke_test.rb index cbfde9c3df..fb992472f4 100644 --- a/actionwebservice/test/test_invoke_test.rb +++ b/actionwebservice/test/test_invoke_test.rb @@ -65,7 +65,7 @@ class TestInvokeTest < Test::Unit::TestCase end def test_layered_add - @protocol = :xmlrpc + @protocol = ActionWebService::Protocol::XmlRpc::XmlRpcProtocol.new @controller = TestInvokeLayeredController.new [:one, :two].each do |service| assert_equal nil, @controller.web_service_object(service).invoked diff --git a/actionwebservice/test/ws/abstract_encoding.rb b/actionwebservice/test/ws/abstract_encoding.rb deleted file mode 100644 index 6032d94c48..0000000000 --- a/actionwebservice/test/ws/abstract_encoding.rb +++ /dev/null @@ -1,68 +0,0 @@ -require File.dirname(__FILE__) + '/abstract_unit' - -module Nested - class StructClass - attr_accessor :name - attr_accessor :version - - def initialize - @name = 5 - @version = "1.0" - end - - def ==(other) - @name == other.name && @version == other.version - end - end -end - -module EncodingTest - def setup - @call_signature = [:int, :bool, :string, :float, [:time], Nested::StructClass] - @call_params = [1, true, "string", 5.0, [Time.now], Nested::StructClass.new] - @response_signature = [:string] - @response_param = "hello world" - test_setup - end - - def test_abstract - obj = WS::Encoding::AbstractEncoding.new - assert_raises(NotImplementedError) do - obj.encode_rpc_call(nil, nil) - end - assert_raises(NotImplementedError) do - obj.decode_rpc_call(nil) - end - assert_raises(NotImplementedError) do - obj.encode_rpc_response(nil, nil) - end - assert_raises(NotImplementedError) do - obj.decode_rpc_response(nil) - end - end - - def encode_rpc_call(method_name, signature, params) - params = params.dup - (0..(signature.length-1)).each do |i| - type_binding = @marshaler.register_type(signature[i]) - 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) - end - - def decode_rpc_call(obj) - @encoder.decode_rpc_call(obj) - end - - def encode_rpc_response(method_name, signature, param) - type_binding = @marshaler.register_type(signature[0]) - 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 - - def decode_rpc_response(obj) - @encoder.decode_rpc_response(obj) - end -end diff --git a/actionwebservice/test/ws/abstract_unit.rb b/actionwebservice/test/ws/abstract_unit.rb deleted file mode 100644 index 5d4f5ce856..0000000000 --- a/actionwebservice/test/ws/abstract_unit.rb +++ /dev/null @@ -1,13 +0,0 @@ -require 'pathname' -$:.unshift(Pathname.new(File.dirname(__FILE__)).realpath.to_s + '/../../lib/action_web_service/vendor') -require 'test/unit' -require 'ws' -begin - require 'active_record' -rescue LoadError - begin - require 'rubygems' - require_gem 'activerecord', '>= 1.6.0' - rescue LoadError - end -end diff --git a/actionwebservice/test/ws/gencov b/actionwebservice/test/ws/gencov deleted file mode 100755 index 144233107a..0000000000 --- a/actionwebservice/test/ws/gencov +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -rcov -x '.*_test\.rb,rubygems,abstract_,/run' ./run diff --git a/actionwebservice/test/ws/run b/actionwebservice/test/ws/run deleted file mode 100755 index 5c6f8b2bc2..0000000000 --- a/actionwebservice/test/ws/run +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env ruby - -Dir[File.join(File.dirname(__FILE__), '*_test.rb')].each do |f| - require f -end diff --git a/actionwebservice/test/ws/soap_marshaling_test.rb b/actionwebservice/test/ws/soap_marshaling_test.rb deleted file mode 100644 index f350ad1124..0000000000 --- a/actionwebservice/test/ws/soap_marshaling_test.rb +++ /dev/null @@ -1,97 +0,0 @@ -require File.dirname(__FILE__) + '/abstract_unit' - -module Nested - class MyClass - attr_accessor :id - attr_accessor :name - - def initialize(id, name) - @id = id - @name = name - end - - def ==(other) - @id == other.id && @name == other.name - end - end -end - -class SoapMarshalingTest < Test::Unit::TestCase - def setup - @marshaler = WS::Marshaling::SoapMarshaler.new - end - - def test_abstract - marshaler = WS::Marshaling::AbstractMarshaler.new - assert_raises(NotImplementedError) do - marshaler.marshal(nil) - end - assert_raises(NotImplementedError) do - marshaler.unmarshal(nil) - end - assert_equal(nil, marshaler.register_type(nil)) - assert_raises(NotImplementedError) do - marshaler.cast_inbound_recursive(nil, nil) - end - assert_raises(NotImplementedError) do - marshaler.cast_outbound_recursive(nil, nil) - end - end - - def test_marshaling - 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, @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) - end - - def test_registration - type_binding1 = @marshaler.register_type(:int) - type_binding2 = @marshaler.register_type(:int) - assert(type_binding1.equal?(type_binding2)) - end - - def test_active_record - if Object.const_defined?('ActiveRecord') - node_class = Class.new(ActiveRecord::Base) do - def initialize(*args) - super(*args) - @new_record = false - end - - class << self - def name - "Node" - end - - def columns(*args) - [ - ActiveRecord::ConnectionAdapters::Column.new('id', 0, 'int'), - ActiveRecord::ConnectionAdapters::Column.new('name', nil, 'string'), - ActiveRecord::ConnectionAdapters::Column.new('email', nil, 'string'), - ] - end - - def connection - self - end - end - end - 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) - param = @marshaler.unmarshal(obj) - new_ar_obj = param.value - assert_equal(ar_obj, new_ar_obj) - assert(!ar_obj.equal?(new_ar_obj)) - end - end -end diff --git a/actionwebservice/test/ws/soap_rpc_encoding_test.rb b/actionwebservice/test/ws/soap_rpc_encoding_test.rb deleted file mode 100644 index e5dcbfeb1b..0000000000 --- a/actionwebservice/test/ws/soap_rpc_encoding_test.rb +++ /dev/null @@ -1,47 +0,0 @@ -require File.dirname(__FILE__) + '/abstract_encoding' -require 'time' - -class SoapRpcEncodingTest < Test::Unit::TestCase - include EncodingTest - - def test_setup - @encoder = WS::Encoding::SoapRpcEncoding.new - @marshaler = WS::Marshaling::SoapMarshaler.new - end - - def test_call_encoding_and_decoding - obj = encode_rpc_call('DecodeMe', @call_signature, @call_params) - method_name, decoded_params = decode_rpc_call(obj) - params = decoded_params.map{|x| @marshaler.unmarshal(x).value} - assert_equal(method_name, 'DecodeMe') - assert_equal(@call_params[0..3], params[0..3]) - # XXX: DateTime not marshaled correctly yet - assert_equal(@call_params[5..-1], params[5..-1]) - end - - def test_response_encoding_and_decoding_simple - obj = encode_rpc_response('DecodeMe', @response_signature, @response_param) - method_name, return_value = decode_rpc_response(obj) - return_value = @marshaler.unmarshal(return_value).value - assert_equal('DecodeMe', method_name) - assert_equal(@response_param, return_value) - end - - def test_response_encoding_and_decoding_struct - struct = Nested::StructClass.new - obj = encode_rpc_response('DecodeMe', [Nested::StructClass], struct) - method_name, return_value = decode_rpc_response(obj) - return_value = @marshaler.unmarshal(return_value).value - assert_equal('DecodeMe', method_name) - assert_equal(struct, return_value) - end - - def test_response_encoding_and_decoding_array - struct = Nested::StructClass.new - obj = encode_rpc_response('DecodeMe', [[Nested::StructClass]], [struct]) - method_name, return_value = decode_rpc_response(obj) - return_value = @marshaler.unmarshal(return_value).value - assert_equal('DecodeMe', method_name) - assert_equal([struct], return_value) - end -end diff --git a/actionwebservice/test/ws/types_test.rb b/actionwebservice/test/ws/types_test.rb deleted file mode 100644 index e66ae65945..0000000000 --- a/actionwebservice/test/ws/types_test.rb +++ /dev/null @@ -1,43 +0,0 @@ -require File.dirname(__FILE__) + '/abstract_unit' - -class TypesTest < Test::Unit::TestCase - include WS - - def setup - @caster = BaseTypeCaster.new - end - - def test_base_types - assert_equal(:int, BaseTypes.canonical_type_name(:integer)) - assert_equal(:int, BaseTypes.canonical_type_name(:fixnum)) - assert_equal(Integer, BaseTypes.type_name_to_class(:bignum)) - assert_equal(Date, BaseTypes.type_name_to_class(:date)) - assert_equal(Time, BaseTypes.type_name_to_class(:timestamp)) - assert_equal(TrueClass, BaseTypes.type_name_to_class(:bool)) - assert_equal(:int, BaseTypes.class_to_type_name(Bignum)) - assert_equal(:bool, BaseTypes.class_to_type_name(FalseClass)) - assert_equal(Integer, BaseTypes.canonical_type_class(Fixnum)) - assert_raises(TypeError) do - BaseTypes.canonical_type_name(:fake) - end - end - - def test_casting - assert_equal(5, @caster.cast("5", Fixnum)) - assert_equal('50.0', @caster.cast(50.0, String)) - assert_equal(true, @caster.cast('true', FalseClass)) - assert_equal(false, @caster.cast('false', TrueClass)) - assert_equal(true, @caster.cast(1, FalseClass)) - assert_equal(false, @caster.cast(0, TrueClass)) - assert_raises(TypeError) do - @caster.cast('yes', FalseClass) - end - assert_equal(3.14159, @caster.cast('3.14159', Float)) - now1 = Time.new - now2 = @caster.cast("#{now1}", Time) - assert_equal(now1.tv_sec, now2.tv_sec) - date1 = Date.parse('2004-01-01') - date2 = @caster.cast("#{date1}", Date) - assert_equal(date1, date2) - end -end diff --git a/actionwebservice/test/ws/xmlrpc_encoding_test.rb b/actionwebservice/test/ws/xmlrpc_encoding_test.rb deleted file mode 100644 index 45aaa901bd..0000000000 --- a/actionwebservice/test/ws/xmlrpc_encoding_test.rb +++ /dev/null @@ -1,34 +0,0 @@ -require File.dirname(__FILE__) + '/abstract_encoding' -require 'time' - -class XmlRpcEncodingTest < Test::Unit::TestCase - include EncodingTest - - def test_setup - @encoder = WS::Encoding::XmlRpcEncoding.new - @marshaler = WS::Marshaling::XmlRpcMarshaler.new - end - - def test_typed_call_encoding_and_decoding - obj = encode_rpc_call('DecodeMe', @call_signature, @call_params) - method_name, params = decode_rpc_call(obj) - (0..(@call_signature.length-1)).each do |i| - params[i] = @marshaler.typed_unmarshal(params[i], @call_signature[i]).value - end - assert_equal(method_name, 'DecodeMe') - assert_equal(@call_params[0..3], params[0..3]) - assert_equal(@call_params[5..-1], params[5..-1]) - end - - def test_untyped_call_encoding_and_decoding - obj = encode_rpc_call('DecodeMe', @call_signature, @call_params) - method_name, params = decode_rpc_call(obj) - (0..(@call_signature.length-1)).each do |i| - params[i] = @marshaler.unmarshal(params[i]).value - end - assert_equal(method_name, 'DecodeMe') - assert_equal(@call_params[0..3], params[0..3]) - assert_equal(@call_params[5].name, params[5]['name']) - assert_equal(@call_params[5].version, params[5]['version']) - end -end -- cgit v1.2.3