aboutsummaryrefslogtreecommitdiffstats
path: root/actionwebservice/test
diff options
context:
space:
mode:
authorLeon Breedt <bitserf@gmail.com>2005-03-28 03:20:13 +0000
committerLeon Breedt <bitserf@gmail.com>2005-03-28 03:20:13 +0000
commit594063f23cf8e7cecd24329e801992784f420b55 (patch)
treed52e9a6fc0521d51fcc3875162adf0411ee6caa0 /actionwebservice/test
parent439a216dcb65ac83d86ca04bb898e1797a87ce70 (diff)
downloadrails-594063f23cf8e7cecd24329e801992784f420b55.tar.gz
rails-594063f23cf8e7cecd24329e801992784f420b55.tar.bz2
rails-594063f23cf8e7cecd24329e801992784f420b55.zip
generalize casting code to be used by both SOAP and XML-RPC (previously only XML-RPC). switch
to better model for API methods, and improve the ability to generate protocol requests/response, will be required by upcoming scaffolding. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1030 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionwebservice/test')
-rw-r--r--actionwebservice/test/abstract_dispatcher.rb53
-rw-r--r--actionwebservice/test/api_test.rb21
-rw-r--r--actionwebservice/test/client_soap_test.rb5
-rw-r--r--actionwebservice/test/client_xmlrpc_test.rb9
-rwxr-xr-xactionwebservice/test/run1
-rw-r--r--actionwebservice/test/ws/soap_marshaling_test.rb6
6 files changed, 74 insertions, 21 deletions
diff --git a/actionwebservice/test/abstract_dispatcher.rb b/actionwebservice/test/abstract_dispatcher.rb
index 3657f8a5ee..21b9a0f5a9 100644
--- a/actionwebservice/test/abstract_dispatcher.rb
+++ b/actionwebservice/test/abstract_dispatcher.rb
@@ -1,5 +1,7 @@
require File.dirname(__FILE__) + '/abstract_unit'
+class ActionController::Base; def rescue_action(e) raise e end; end
+
module DispatcherTest
class Node < ActiveRecord::Base
def initialize(*args)
@@ -29,6 +31,10 @@ module DispatcherTest
class Person < ActionWebService::Struct
member :id, :int
member :name, :string
+
+ def ==(other)
+ self.id == other.id && self.name == other.name
+ end
end
class API < ActionWebService::API::Base
@@ -44,6 +50,7 @@ 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 :base_struct_return, :returns => [[Person]]
api_method :thrower
api_method :void
@@ -148,6 +155,7 @@ module DispatcherTest
attr :after_filter_called
attr :after_filter_target_called
attr :void_called
+ attr :struct_pass_value
def initialize
@before_filter_called = false
@@ -155,6 +163,7 @@ module DispatcherTest
@after_filter_called = false
@after_filter_target_called = false
@void_called = false
+ @struct_pass_value = false
end
def add
@@ -184,6 +193,10 @@ module DispatcherTest
[n1, n2]
end
+ def struct_pass(person)
+ @struct_pass_value = person
+ end
+
def base_struct_return
p1 = Person.new('id' => 1, 'name' => 'person1')
p2 = Person.new('id' => 2, 'name' => 'person2')
@@ -328,6 +341,26 @@ module DispatcherCommonTests
end
end
+ def test_casting
+ assert_equal 70, do_method_call(@direct_controller, 'Add', "50", "20")
+ assert_equal false, @direct_controller.struct_pass_value
+ person = DispatcherTest::Person.new(:id => 1, :name => 'test')
+ result = do_method_call(@direct_controller, 'StructPass', person)
+ assert(nil == result || true == result)
+ 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
+ assert_equal(person, @direct_controller.struct_pass_value)
+ assert !person.equal?(@direct_controller.struct_pass_value)
+ end
+ end
+
protected
def service_name(container)
raise NotImplementedError
@@ -355,24 +388,20 @@ module DispatcherCommonTests
end
api = container.web_service_object(service_name.to_sym).class.web_service_api
end
- info = api.api_methods[method_name] || {}
- params = params.dup
- ((info[:expects] || []) + (info[:returns] || [])).each do |spec|
- @marshaler.register_type(spec)
- end
- 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, type_binding, i)
- params[i] = @marshaler.marshal(WS::Param.new(params[i], info))
- end
- body = @encoder.encode_rpc_call(public_method_name, params)
+ 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)
# puts body
ap_request = create_ap_request(container, body, public_method_name, *params)
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)
+ # http://dev.rubyonrails.com/changeset/920
+ assert_match(/Response$/, public_method_name) unless public_method_name == "fault"
+ end
@marshaler.unmarshal(return_value).value
end
end
diff --git a/actionwebservice/test/api_test.rb b/actionwebservice/test/api_test.rb
index a3679335fc..42b1dfbef2 100644
--- a/actionwebservice/test/api_test.rb
+++ b/actionwebservice/test/api_test.rb
@@ -35,13 +35,20 @@ class TC_API < Test::Unit::TestCase
end
def test_signature_canonicalization
- assert_equal({:expects=>nil, :returns=>nil}, API.api_methods[:void])
- assert_equal({:expects=>[String], :returns=>[String]}, API.api_methods[:expects_and_returns])
- assert_equal({:expects=>[Integer, TrueClass], :returns=>nil}, API.api_methods[:expects])
- assert_equal({:expects=>nil, :returns=>[Integer, [String]]}, API.api_methods[:returns])
- assert_equal({:expects=>[{:appkey=>Integer}, {:publish=>TrueClass}], :returns=>nil}, API.api_methods[:named_signature])
- assert_equal({:expects=>[Integer, String, TrueClass], :returns=>nil}, API.api_methods[:string_types])
- assert_equal({:expects=>[TrueClass, Integer, String], :returns=>nil}, API.api_methods[:class_types])
+ 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(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(nil, API.api_methods[:named_signature].returns)
+ assert_equal([Integer, String, TrueClass], API.api_methods[:string_types].expects)
+ assert_equal(nil, API.api_methods[:string_types].returns)
+ assert_equal([TrueClass, Integer, String], API.api_methods[:class_types].expects)
+ assert_equal(nil, API.api_methods[:class_types].returns)
end
def test_not_instantiable
diff --git a/actionwebservice/test/client_soap_test.rb b/actionwebservice/test/client_soap_test.rb
index 94a4f24c26..941a642554 100644
--- a/actionwebservice/test/client_soap_test.rb
+++ b/actionwebservice/test/client_soap_test.rb
@@ -66,6 +66,11 @@ class TC_ClientSoap < Test::Unit::TestCase
assert(@container.value_normal.nil?)
assert_equal(5, @client.normal(5, 6))
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
end
def test_array_return
diff --git a/actionwebservice/test/client_xmlrpc_test.rb b/actionwebservice/test/client_xmlrpc_test.rb
index 53b6de51e1..3301113d95 100644
--- a/actionwebservice/test/client_xmlrpc_test.rb
+++ b/actionwebservice/test/client_xmlrpc_test.rb
@@ -60,6 +60,11 @@ class TC_ClientXmlRpc < Test::Unit::TestCase
assert(@container.value_normal.nil?)
assert_equal(5, @client.normal(5, 6))
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
end
def test_array_return
@@ -86,7 +91,7 @@ class TC_ClientXmlRpc < Test::Unit::TestCase
def test_named_parameters
assert(@container.value_named_parameters.nil?)
- assert_equal(true, @client.named_parameters("xxx", 7))
+ assert_equal(nil, @client.named_parameters("xxx", 7))
assert_equal(["xxx", 7], @container.value_named_parameters)
end
@@ -97,7 +102,7 @@ class TC_ClientXmlRpc < Test::Unit::TestCase
end
def test_invalid_signature
- assert_raises(ActionWebService::Client::ClientError) do
+ assert_raises(ArgumentError) do
@client.normal
end
end
diff --git a/actionwebservice/test/run b/actionwebservice/test/run
index 90ad85fff5..c8c0372776 100755
--- a/actionwebservice/test/run
+++ b/actionwebservice/test/run
@@ -1,5 +1,6 @@
#!/usr/bin/env ruby
require 'test/unit'
+$:.unshift(File.dirname(__FILE__) + '/../lib')
args = Dir[File.join(File.dirname(__FILE__), '*_test.rb')] + Dir[File.join(File.dirname(__FILE__), 'ws/*_test.rb')]
(r = Test::Unit::AutoRunner.new(true)).process_args(args)
exit r.run
diff --git a/actionwebservice/test/ws/soap_marshaling_test.rb b/actionwebservice/test/ws/soap_marshaling_test.rb
index 7c7413190e..f350ad1124 100644
--- a/actionwebservice/test/ws/soap_marshaling_test.rb
+++ b/actionwebservice/test/ws/soap_marshaling_test.rb
@@ -30,6 +30,12 @@ class SoapMarshalingTest < Test::Unit::TestCase
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