diff options
Diffstat (limited to 'actionwebservice/test')
-rw-r--r-- | actionwebservice/test/abstract_client.rb | 2 | ||||
-rw-r--r-- | actionwebservice/test/dispatcher_action_controller_test.rb (renamed from actionwebservice/test/router_action_controller_test.rb) | 89 | ||||
-rw-r--r-- | actionwebservice/test/invocation_test.rb | 13 | ||||
-rw-r--r-- | actionwebservice/test/protocol_soap_test.rb | 60 | ||||
-rw-r--r-- | actionwebservice/test/protocol_xmlrpc_test.rb | 14 | ||||
-rw-r--r-- | actionwebservice/test/router_wsdl_test.rb | 100 |
6 files changed, 116 insertions, 162 deletions
diff --git a/actionwebservice/test/abstract_client.rb b/actionwebservice/test/abstract_client.rb index 0197b87d63..b443fa8ffb 100644 --- a/actionwebservice/test/abstract_client.rb +++ b/actionwebservice/test/abstract_client.rb @@ -71,7 +71,7 @@ module ClientTest end def dispatch_request(protocol_request) - dispatch_web_service_request(protocol_request) + dispatch_protocol_request(protocol_request) end end diff --git a/actionwebservice/test/router_action_controller_test.rb b/actionwebservice/test/dispatcher_action_controller_test.rb index 4f6d40e738..11ab21c6a6 100644 --- a/actionwebservice/test/router_action_controller_test.rb +++ b/actionwebservice/test/dispatcher_action_controller_test.rb @@ -1,11 +1,18 @@ require File.dirname(__FILE__) + '/abstract_soap' require 'wsdl/parser' -module RouterActionControllerTest +module DispatcherActionControllerTest class API < ActionWebService::API::Base api_method :add, :expects => [:int, :int], :returns => [:int] end + class DirectAPI < ActionWebService::API::Base + api_method :add, :expects => [{:a=>:int}, {:b=>:int}], :returns => [:int] + api_method :before_filtered + api_method :after_filtered, :returns => [:int] + api_method :thrower + end + class Service < ActionWebService::Base web_service_api API @@ -15,21 +22,20 @@ module RouterActionControllerTest @added = a + b end end - - class DelegatedController < ActionController::Base + + class AbstractController < ActionController::Base + def generate_wsdl(container, uri, soap_action_base) + to_wsdl(container, uri, soap_action_base) + end + end + + class DelegatedController < AbstractController web_service_dispatching_mode :delegated web_service(:test_service) { @service ||= Service.new; @service } end - - class DirectAPI < ActionWebService::API::Base - api_method :add, :expects => [{:a=>:int}, {:b=>:int}], :returns => [:int] - api_method :before_filtered - api_method :after_filtered, :returns => [:int] - api_method :thrower - end - - class DirectController < ActionController::Base + + class DirectController < AbstractController web_service_api DirectAPI web_service_dispatching_mode :direct @@ -78,20 +84,22 @@ module RouterActionControllerTest end end -class TC_RouterActionController < AbstractSoapTest - def test_direct_routing - @container = RouterActionControllerTest::DirectController.new +class TC_DispatcherActionController < AbstractSoapTest + include DispatcherActionControllerTest + + def test_direct_dispatching + @container = DirectController.new assert(do_soap_call('Add', 20, 50) == 70) assert(@container.added == 70) end def test_direct_entrypoint - @container = RouterActionControllerTest::DirectController.new + @container = DirectController.new assert(@container.respond_to?(:api)) end def test_direct_filtering - @container = RouterActionControllerTest::DirectController.new + @container = DirectController.new assert(@container.before_filter_called == false) assert(@container.before_filter_target_called == false) assert(do_soap_call('BeforeFiltered').nil?) @@ -104,14 +112,14 @@ class TC_RouterActionController < AbstractSoapTest assert(@container.after_filter_target_called == true) end - def test_delegated_routing - @container = RouterActionControllerTest::DelegatedController.new + def test_delegated_dispatching + @container = DelegatedController.new assert(do_soap_call('Add', 50, 80) == 130) assert(service.added == 130) end def test_exception_marshaling - @container = RouterActionControllerTest::DirectController.new + @container = DirectController.new result = do_soap_call('Thrower') exception = result.detail assert(exception.cause.is_a?(RuntimeError)) @@ -122,9 +130,21 @@ class TC_RouterActionController < AbstractSoapTest end end + def test_wsdl_generation + ensure_valid_wsdl_generation DelegatedController.new + ensure_valid_wsdl_generation DirectController.new + end + + def + + def test_wsdl_action + ensure_valid_wsdl_action DelegatedController.new + ensure_valid_wsdl_action DirectController.new + end + protected def service_name - @container.is_a?(RouterActionControllerTest::DelegatedController) ? 'test_service' : 'api' + @container.is_a?(DelegatedController) ? 'test_service' : 'api' end def service @@ -136,4 +156,31 @@ class TC_RouterActionController < AbstractSoapTest response = @container.process(test_request, test_response) end end + + def ensure_valid_wsdl_generation(controller) + wsdl = controller.generate_wsdl(controller, 'http://localhost:3000/test/', '/test') + ensure_valid_wsdl(wsdl) + end + + def ensure_valid_wsdl(wsdl) + definitions = WSDL::Parser.new.parse(wsdl) + assert(definitions.is_a?(WSDL::Definitions)) + definitions.bindings.each do |binding| + assert(binding.name.name.index(':').nil?) + end + definitions.services.each do |service| + service.ports.each do |port| + assert(port.name.name.index(':').nil?) + end + end + end + + def ensure_valid_wsdl_action(controller) + test_request = ActionController::TestRequest.new({ 'action' => 'wsdl' }) + test_request.env['REQUEST_METHOD'] = 'GET' + test_request.env['HTTP_HOST'] = 'localhost:3000' + test_response = ActionController::TestResponse.new + wsdl = controller.process(test_request, test_response).body + ensure_valid_wsdl(wsdl) + end end diff --git a/actionwebservice/test/invocation_test.rb b/actionwebservice/test/invocation_test.rb index 8ca80ec8f2..0d519bf770 100644 --- a/actionwebservice/test/invocation_test.rb +++ b/actionwebservice/test/invocation_test.rb @@ -58,9 +58,6 @@ module InvocationTest def only_two end - def not_public - end - protected def intercept_before(name, args) @before_invoked = name @@ -90,10 +87,7 @@ class TC_Invocation < Test::Unit::TestCase def test_invocation assert(perform_invocation(:add, 5, 10) == 15) assert(perform_invocation(:transmogrify, "hello") == "HELLO") - assert_raises(InvocationError) do - perform_invocation(:not_public) - end - assert_raises(InvocationError) do + assert_raises(NoMethodError) do perform_invocation(:nonexistent_method_xyzzy) end end @@ -150,9 +144,6 @@ class TC_Invocation < Test::Unit::TestCase private def perform_invocation(method_name, *args, &block) - public_method_name = @service.class.web_service_api.public_api_method_name(method_name) - args ||= [] - request = InvocationRequest.new(ConcreteInvocation, public_method_name, method_name, args) - @service.perform_invocation(request, &block) + @service.perform_invocation(method_name, args, &block) end end diff --git a/actionwebservice/test/protocol_soap_test.rb b/actionwebservice/test/protocol_soap_test.rb index 1130dff3a7..c55b7f55af 100644 --- a/actionwebservice/test/protocol_soap_test.rb +++ b/actionwebservice/test/protocol_soap_test.rb @@ -12,6 +12,13 @@ module ProtocolSoapTest end end + class EmptyAPI < ActionWebService::API::Base + end + + class EmptyService < ActionWebService::Base + web_service_api EmptyAPI + end + class API < ActionWebService::API::Base api_method :argument_passing, :expects => [{:int=>:int}, {:string=>:string}, {:array=>[:int]}], :returns => [:bool] api_method :array_returner, :returns => [[:int]] @@ -72,26 +79,19 @@ module ProtocolSoapTest end end - class AbstractContainer - include ActionWebService::API - include ActionWebService::Container - include ActionWebService::Protocol::Registry - include ActionWebService::Protocol::Soap - + class AbstractContainer < ActionController::Base wsdl_service_name 'Test' - def protocol_request(request) - probe_request_protocol(request) - end - - def dispatch_request(protocol_request) - dispatch_web_service_request(protocol_request) + def dispatch_request(request) + protocol_request = probe_request_protocol(request) + dispatch_protocol_request(protocol_request) end end class DelegatedContainer < AbstractContainer web_service_dispatching_mode :delegated web_service :protocol_soap_service, Service.new + web_service :empty_service, EmptyService.new end class DirectContainer < AbstractContainer @@ -144,12 +144,18 @@ module ProtocolSoapTest nil end end + + class EmptyContainer < AbstractContainer + web_service_dispatching_mode :delegated + web_service :empty_service, EmptyService.new + end end class TC_ProtocolSoap < AbstractSoapTest def setup @delegated_container = ProtocolSoapTest::DelegatedContainer.new @direct_container = ProtocolSoapTest::DirectContainer.new + @empty_container = ProtocolSoapTest::EmptyContainer.new end def test_argument_passing @@ -180,6 +186,13 @@ class TC_ProtocolSoap < AbstractSoapTest end end + def test_nonexistent_method + @container = @empty_container + assert_raises(ActionWebService::Dispatcher::DispatcherError) do + do_soap_call('NonexistentMethod') + end + end + def test_exception_thrower in_all_containers do assert_raises(RuntimeError) do @@ -203,15 +216,29 @@ class TC_ProtocolSoap < AbstractSoapTest protected def service_name - @container == @direct_container ? 'api' : 'protocol_soap_service' + case + when @container == @direct_container + 'api' + when @container == @delegated_container + 'protocol_soap_service' + when @container == @empty_container + 'empty_service' + end end def service - @container == @direct_container ? @container : @container.web_service_object(:protocol_soap_service) + case + when @container == @direct_container + @container + when @container == @delegated_container + @container.web_service_object(:protocol_soap_service) + when @container == @empty_container + @container.web_service_object(:empty_service) + end end def in_all_containers(&block) - [@direct_container].each do |container| + [@direct_container, @delegated_container].each do |container| @container = container block.call end @@ -219,8 +246,7 @@ class TC_ProtocolSoap < AbstractSoapTest def do_soap_call(public_method_name, *args) super(public_method_name, *args) do |test_request, test_response| - protocol_request = @container.protocol_request(test_request) - @container.dispatch_request(protocol_request) + @container.dispatch_request(test_request) end end end diff --git a/actionwebservice/test/protocol_xmlrpc_test.rb b/actionwebservice/test/protocol_xmlrpc_test.rb index 7dc5cf0252..cda0bba6d3 100644 --- a/actionwebservice/test/protocol_xmlrpc_test.rb +++ b/actionwebservice/test/protocol_xmlrpc_test.rb @@ -79,18 +79,13 @@ module ProtocolXmlRpcTest $service = Service.new - class Container - include ActionWebService::Container - include ActionWebService::Protocol::Registry - include ActionWebService::Protocol::Soap - include ActionWebService::Protocol::XmlRpc - + class Container < ActionController::Base def protocol_request(request) probe_request_protocol(request) end def dispatch_request(protocol_request) - dispatch_web_service_request(protocol_request) + dispatch_protocol_request(protocol_request) end web_service :xmlrpc, $service @@ -136,11 +131,6 @@ class TC_ProtocolXmlRpc < Test::Unit::TestCase assert($service.default_args == ['test', [1, 2], {'name'=>'value'}]) end - def test_xmlrpc_introspection - retval = do_xmlrpc_call('system.listMethods', 'test', [1, 2], {'name'=>'value'}) - assert(retval == [true, ["Add", "ArrayReturner", "HashReturner", "SomethingHash", "StructArrayReturner"]]) - end - private def do_xmlrpc_call(public_method_name, *args) service_name = 'xmlrpc' diff --git a/actionwebservice/test/router_wsdl_test.rb b/actionwebservice/test/router_wsdl_test.rb deleted file mode 100644 index a441e73f37..0000000000 --- a/actionwebservice/test/router_wsdl_test.rb +++ /dev/null @@ -1,100 +0,0 @@ -require File.dirname(__FILE__) + '/abstract_unit' -require 'wsdl/parser' - -module RouterWsdlTest - class Person < ActionWebService::Struct - member :id, Integer - member :names, [String] - member :lastname, String - member :deleted, TrueClass - end - - class API < ActionWebService::API::Base - api_method :add, :expects => [{:a=>:int}, {:b=>:int}], :returns => [:int] - api_method :find_people, :returns => [[Person]] - api_method :nil_returner - end - - class Service < ActionWebService::Base - web_service_api API - - def add(a, b) - a + b - end - - def find_people - [] - end - - def nil_returner - end - end - - class AbstractController < ActionController::Base - def generate_wsdl(container, uri, soap_action_base) - to_wsdl(container, uri, soap_action_base) - end - end - - class DirectController < AbstractController - web_service_api API - - def add - end - - def find_people - end - - def nil_returner - end - end - - class DelegatedController < AbstractController - web_service_dispatching_mode :delegated - web_service(:test_service) { Service.new } - end -end - -class TC_RouterWsdl < Test::Unit::TestCase - include RouterWsdlTest - - def test_wsdl_generation - ensure_valid_generation DelegatedController.new - ensure_valid_generation DirectController.new - end - - def - - def test_wsdl_action - ensure_valid_wsdl_action DelegatedController.new - ensure_valid_wsdl_action DirectController.new - end - - protected - def ensure_valid_generation(controller) - wsdl = controller.generate_wsdl(controller, 'http://localhost:3000/test/', '/test') - ensure_valid_wsdl(wsdl) - end - - def ensure_valid_wsdl(wsdl) - definitions = WSDL::Parser.new.parse(wsdl) - assert(definitions.is_a?(WSDL::Definitions)) - definitions.bindings.each do |binding| - assert(binding.name.name.index(':').nil?) - end - definitions.services.each do |service| - service.ports.each do |port| - assert(port.name.name.index(':').nil?) - end - end - end - - def ensure_valid_wsdl_action(controller) - test_request = ActionController::TestRequest.new({ 'action' => 'wsdl' }) - test_request.env['REQUEST_METHOD'] = 'GET' - test_request.env['HTTP_HOST'] = 'localhost:3000' - test_response = ActionController::TestResponse.new - wsdl = controller.process(test_request, test_response).body - ensure_valid_wsdl(wsdl) - end -end |