diff options
author | Leon Breedt <bitserf@gmail.com> | 2005-03-04 10:07:53 +0000 |
---|---|---|
committer | Leon Breedt <bitserf@gmail.com> | 2005-03-04 10:07:53 +0000 |
commit | d43392a50b4f7023b13747a67c4a6aa85e4036c4 (patch) | |
tree | 66203f6fceae6c4d7489a10664fddc9afd9d53be /actionwebservice/test | |
parent | b78283b3fcae6752e7f1698cc063eff6214d2104 (diff) | |
download | rails-d43392a50b4f7023b13747a67c4a6aa85e4036c4.tar.gz rails-d43392a50b4f7023b13747a67c4a6aa85e4036c4.tar.bz2 rails-d43392a50b4f7023b13747a67c4a6aa85e4036c4.zip |
add action_web_service/test_invoke, will be used by for testing APIs in
a Rails project instance.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@830 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionwebservice/test')
3 files changed, 79 insertions, 2 deletions
diff --git a/actionwebservice/test/dispatcher_action_controller_soap_test.rb b/actionwebservice/test/dispatcher_action_controller_soap_test.rb index 6d50bbba8a..dd945972d6 100644 --- a/actionwebservice/test/dispatcher_action_controller_soap_test.rb +++ b/actionwebservice/test/dispatcher_action_controller_soap_test.rb @@ -62,7 +62,7 @@ class TC_DispatcherActionControllerSoap < Test::Unit::TestCase test_request = ActionController::TestRequest.new test_request.request_parameters['action'] = service_name(container) test_request.env['REQUEST_METHOD'] = "POST" - test_request.env['HTTP_CONTENTTYPE'] = 'text/xml' + test_request.env['HTTP_CONTENT_TYPE'] = 'text/xml' test_request.env['HTTP_SOAPACTION'] = "/soap/#{service_name(container)}/#{public_method_name}" test_request.env['RAW_POST_DATA'] = body test_request diff --git a/actionwebservice/test/dispatcher_action_controller_xmlrpc_test.rb b/actionwebservice/test/dispatcher_action_controller_xmlrpc_test.rb index 87677dec3e..81ada70c9e 100644 --- a/actionwebservice/test/dispatcher_action_controller_xmlrpc_test.rb +++ b/actionwebservice/test/dispatcher_action_controller_xmlrpc_test.rb @@ -33,7 +33,7 @@ class TC_DispatcherActionControllerXmlRpc < Test::Unit::TestCase test_request = ActionController::TestRequest.new test_request.request_parameters['action'] = service_name(container) test_request.env['REQUEST_METHOD'] = "POST" - test_request.env['HTTP_CONTENTTYPE'] = 'text/xml' + test_request.env['HTTP_CONTENT_TYPE'] = 'text/xml' test_request.env['RAW_POST_DATA'] = body test_request end diff --git a/actionwebservice/test/test_invoke_test.rb b/actionwebservice/test/test_invoke_test.rb new file mode 100644 index 0000000000..cbfde9c3df --- /dev/null +++ b/actionwebservice/test/test_invoke_test.rb @@ -0,0 +1,77 @@ +require File.dirname(__FILE__) + '/abstract_unit' +require 'action_web_service/test_invoke' + +class TestInvokeAPI < ActionWebService::API::Base + api_method :add, :expects => [:int, :int], :returns => [:int] +end + +class TestInvokeService < ActionWebService::Base + web_service_api TestInvokeAPI + + attr :invoked + + def add(a, b) + @invoked = true + a + b + end +end + +class TestController < ActionController::Base + def rescue_action(e); raise e; end +end + +class TestInvokeDirectController < TestController + web_service_api TestInvokeAPI + + attr :invoked + + def add + @invoked = true + @method_params[0] + @method_params[1] + end +end + +class TestInvokeDelegatedController < TestController + web_service_dispatching_mode :delegated + web_service :service, TestInvokeService.new +end + +class TestInvokeLayeredController < TestController + web_service_dispatching_mode :layered + web_service :one, TestInvokeService.new + web_service :two, TestInvokeService.new +end + +class TestInvokeTest < Test::Unit::TestCase + def setup + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + end + + def test_direct_add + @controller = TestInvokeDirectController.new + assert_equal nil, @controller.invoked + result = invoke :add, 25, 25 + assert_equal 50, result + assert_equal true, @controller.invoked + end + + def test_delegated_add + @controller = TestInvokeDelegatedController.new + assert_equal nil, @controller.web_service_object(:service).invoked + result = invoke_delegated :service, :add, 100, 50 + assert_equal 150, result + assert_equal true, @controller.web_service_object(:service).invoked + end + + def test_layered_add + @protocol = :xmlrpc + @controller = TestInvokeLayeredController.new + [:one, :two].each do |service| + assert_equal nil, @controller.web_service_object(service).invoked + result = invoke_layered service, :add, 200, -50 + assert_equal 150, result + assert_equal true, @controller.web_service_object(service).invoked + end + end +end |