1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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
|