diff options
author | Leon Breedt <bitserf@gmail.com> | 2005-02-25 23:39:39 +0000 |
---|---|---|
committer | Leon Breedt <bitserf@gmail.com> | 2005-02-25 23:39:39 +0000 |
commit | 6f5a7b200443baf209d2f33c428ed4a4059782f7 (patch) | |
tree | 9c3942fe27be69c102873d9fdaa13f66dc12853d /actionwebservice/test/ws/soap_marshaling_test.rb | |
parent | 10faf204b712763f05a2b3155a4fd9c5338f1fb2 (diff) | |
download | rails-6f5a7b200443baf209d2f33c428ed4a4059782f7.tar.gz rails-6f5a7b200443baf209d2f33c428ed4a4059782f7.tar.bz2 rails-6f5a7b200443baf209d2f33c428ed4a4059782f7.zip |
merged the changes for the upcoming 0.6.0:
seperate out protocol marshaling into a small 'ws' library in vendor, so that
AWS itself only does integration with ActionPack, and so we can keep protocol
specific code in AWS proper to a minimum. refactor unit tests to get 95%
code coverage (for a baseline).
be far more relaxed about the types given to us by the remote side, don't do
any poor man's type checking, just try to cast and marshal to the correct types if
possible, and if not, return what they gave us anyway. this should make interoperating
with fuzzy XML-RPC clients easier.
if exception reporting is turned on, do best-effort error responses, so that
we can avoid "Internal protocol error" with no details if there is a bug in
AWS itself.
also perform extensive cleanups on AWS proper.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@800 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionwebservice/test/ws/soap_marshaling_test.rb')
-rw-r--r-- | actionwebservice/test/ws/soap_marshaling_test.rb | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/actionwebservice/test/ws/soap_marshaling_test.rb b/actionwebservice/test/ws/soap_marshaling_test.rb new file mode 100644 index 0000000000..ee6413478d --- /dev/null +++ b/actionwebservice/test/ws/soap_marshaling_test.rb @@ -0,0 +1,91 @@ +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)) + end + + def test_marshaling + info = WS::ParamInfo.create(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) + 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, 0, @marshaler.register_type(node_class)) + 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 |