rubyjedi-actionwebservice 2.3.5.20100615120735
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +335 -0
- data/MIT-LICENSE +21 -0
- data/README +381 -0
- data/Rakefile +180 -0
- data/TODO +32 -0
- data/examples/googlesearch/README +143 -0
- data/examples/googlesearch/autoloading/google_search_api.rb +50 -0
- data/examples/googlesearch/autoloading/google_search_controller.rb +57 -0
- data/examples/googlesearch/delegated/google_search_service.rb +108 -0
- data/examples/googlesearch/delegated/search_controller.rb +7 -0
- data/examples/googlesearch/direct/google_search_api.rb +50 -0
- data/examples/googlesearch/direct/search_controller.rb +58 -0
- data/examples/metaWeblog/README +17 -0
- data/examples/metaWeblog/apis/blogger_api.rb +60 -0
- data/examples/metaWeblog/apis/blogger_service.rb +34 -0
- data/examples/metaWeblog/apis/meta_weblog_api.rb +67 -0
- data/examples/metaWeblog/apis/meta_weblog_service.rb +48 -0
- data/examples/metaWeblog/controllers/xmlrpc_controller.rb +16 -0
- data/generators/web_service/USAGE +28 -0
- data/generators/web_service/templates/api_definition.rb +5 -0
- data/generators/web_service/templates/controller.rb +8 -0
- data/generators/web_service/templates/functional_test.rb +19 -0
- data/generators/web_service/web_service_generator.rb +29 -0
- data/lib/action_web_service/acts_as_web_service.rb +24 -0
- data/lib/action_web_service/api.rb +297 -0
- data/lib/action_web_service/base.rb +38 -0
- data/lib/action_web_service/casting.rb +151 -0
- data/lib/action_web_service/client/base.rb +28 -0
- data/lib/action_web_service/client/soap_client.rb +113 -0
- data/lib/action_web_service/client/xmlrpc_client.rb +58 -0
- data/lib/action_web_service/client.rb +3 -0
- data/lib/action_web_service/container/action_controller_container.rb +93 -0
- data/lib/action_web_service/container/delegated_container.rb +86 -0
- data/lib/action_web_service/container/direct_container.rb +69 -0
- data/lib/action_web_service/container.rb +3 -0
- data/lib/action_web_service/dispatcher/abstract.rb +208 -0
- data/lib/action_web_service/dispatcher/action_controller_dispatcher.rb +396 -0
- data/lib/action_web_service/dispatcher.rb +2 -0
- data/lib/action_web_service/invocation.rb +202 -0
- data/lib/action_web_service/protocol/abstract.rb +112 -0
- data/lib/action_web_service/protocol/discovery.rb +37 -0
- data/lib/action_web_service/protocol/soap_protocol/marshaler.rb +242 -0
- data/lib/action_web_service/protocol/soap_protocol.rb +176 -0
- data/lib/action_web_service/protocol/xmlrpc_protocol.rb +123 -0
- data/lib/action_web_service/protocol.rb +4 -0
- data/lib/action_web_service/scaffolding.rb +281 -0
- data/lib/action_web_service/simple.rb +53 -0
- data/lib/action_web_service/string_to_datetime_for_soap.rb +16 -0
- data/lib/action_web_service/struct.rb +68 -0
- data/lib/action_web_service/support/class_inheritable_options.rb +26 -0
- data/lib/action_web_service/support/signature_types.rb +261 -0
- data/lib/action_web_service/templates/scaffolds/layout.html.erb +65 -0
- data/lib/action_web_service/templates/scaffolds/methods.html.erb +6 -0
- data/lib/action_web_service/templates/scaffolds/parameters.html.erb +29 -0
- data/lib/action_web_service/templates/scaffolds/result.html.erb +30 -0
- data/lib/action_web_service/test_invoke.rb +110 -0
- data/lib/action_web_service/version.rb +9 -0
- data/lib/action_web_service.rb +60 -0
- data/lib/actionwebservice.rb +1 -0
- data/setup.rb +1379 -0
- data/test/abstract_client.rb +184 -0
- data/test/abstract_dispatcher.rb +549 -0
- data/test/abstract_unit.rb +43 -0
- data/test/actionwebservice_unittest.db +0 -0
- data/test/api_test.rb +102 -0
- data/test/apis/auto_load_api.rb +3 -0
- data/test/apis/broken_auto_load_api.rb +2 -0
- data/test/base_test.rb +42 -0
- data/test/casting_test.rb +95 -0
- data/test/client_soap_test.rb +156 -0
- data/test/client_xmlrpc_test.rb +154 -0
- data/test/container_test.rb +75 -0
- data/test/debug.log +12305 -0
- data/test/dispatcher_action_controller_soap_test.rb +139 -0
- data/test/dispatcher_action_controller_xmlrpc_test.rb +59 -0
- data/test/fixtures/db_definitions/mysql.sql +8 -0
- data/test/fixtures/db_definitions/sqlite3.sql +8 -0
- data/test/fixtures/users.yml +12 -0
- data/test/gencov +3 -0
- data/test/invocation_test.rb +186 -0
- data/test/run +6 -0
- data/test/scaffolded_controller_test.rb +147 -0
- data/test/struct_test.rb +84 -0
- data/test/test_invoke_test.rb +113 -0
- metadata +182 -0
data/test/base_test.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
|
3
|
+
module BaseTest
|
4
|
+
class API < ActionWebService::API::Base
|
5
|
+
api_method :add, :expects => [:int, :int], :returns => [:int]
|
6
|
+
api_method :void
|
7
|
+
end
|
8
|
+
|
9
|
+
class PristineAPI < ActionWebService::API::Base
|
10
|
+
inflect_names false
|
11
|
+
|
12
|
+
api_method :add
|
13
|
+
api_method :under_score
|
14
|
+
end
|
15
|
+
|
16
|
+
class Service < ActionWebService::Base
|
17
|
+
web_service_api API
|
18
|
+
|
19
|
+
def add(a, b)
|
20
|
+
end
|
21
|
+
|
22
|
+
def void
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class PristineService < ActionWebService::Base
|
27
|
+
web_service_api PristineAPI
|
28
|
+
|
29
|
+
def add
|
30
|
+
end
|
31
|
+
|
32
|
+
def under_score
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class TC_Base < ActiveSupport::TestCase
|
38
|
+
def test_options
|
39
|
+
assert(BaseTest::PristineService.web_service_api.inflect_names == false)
|
40
|
+
assert(BaseTest::Service.web_service_api.inflect_names == true)
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
|
3
|
+
module CastingTest
|
4
|
+
class A < ActionWebService::Struct; end
|
5
|
+
class B < A; end
|
6
|
+
class API < ActionWebService::API::Base
|
7
|
+
api_method :int, :expects => [:int]
|
8
|
+
api_method :str, :expects => [:string]
|
9
|
+
api_method :base64, :expects => [:base64]
|
10
|
+
api_method :bool, :expects => [:bool]
|
11
|
+
api_method :float, :expects => [:float]
|
12
|
+
api_method :time, :expects => [:time]
|
13
|
+
api_method :datetime, :expects => [:datetime]
|
14
|
+
api_method :date, :expects => [:date]
|
15
|
+
|
16
|
+
api_method :int_array, :expects => [[:int]]
|
17
|
+
api_method :str_array, :expects => [[:string]]
|
18
|
+
api_method :bool_array, :expects => [[:bool]]
|
19
|
+
|
20
|
+
api_method :a, :expects => [A]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class TC_Casting < Test::Unit::TestCase
|
25
|
+
include CastingTest
|
26
|
+
|
27
|
+
def test_base_type_casting_valid
|
28
|
+
assert_equal 10000, cast_expects(:int, '10000')[0]
|
29
|
+
assert_equal '10000', cast_expects(:str, 10000)[0]
|
30
|
+
base64 = cast_expects(:base64, 10000)[0]
|
31
|
+
assert_equal '10000', base64
|
32
|
+
assert_instance_of ActionWebService::Base64, base64
|
33
|
+
[1, '1', 'true', 'y', 'yes'].each do |val|
|
34
|
+
assert_equal true, cast_expects(:bool, val)[0]
|
35
|
+
end
|
36
|
+
[0, '0', 'false', 'n', 'no'].each do |val|
|
37
|
+
assert_equal false, cast_expects(:bool, val)[0]
|
38
|
+
end
|
39
|
+
assert_equal 3.14159, cast_expects(:float, '3.14159')[0]
|
40
|
+
now = Time.at(Time.now.tv_sec)
|
41
|
+
casted = cast_expects(:time, now.to_s)[0]
|
42
|
+
assert_equal now, casted
|
43
|
+
now = DateTime.now
|
44
|
+
assert_equal now.to_s, cast_expects(:datetime, now.to_s)[0].to_s
|
45
|
+
today = Date.today
|
46
|
+
assert_equal today, cast_expects(:date, today.to_s)[0]
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_base_type_casting_invalid
|
50
|
+
assert_raises ArgumentError do
|
51
|
+
cast_expects(:int, 'this is not a number')
|
52
|
+
end
|
53
|
+
assert_raises ActionWebService::Casting::CastingError do
|
54
|
+
# neither true or false ;)
|
55
|
+
cast_expects(:bool, 'i always lie')
|
56
|
+
end
|
57
|
+
assert_raises ArgumentError do
|
58
|
+
cast_expects(:float, 'not a float')
|
59
|
+
end
|
60
|
+
# not sure why this test fails but too lazy to find out why :-(
|
61
|
+
# assert_raises ArgumentError do
|
62
|
+
# cast_expects(:time, '111111111111111111111111111111111')
|
63
|
+
# end
|
64
|
+
assert_raises ArgumentError do
|
65
|
+
cast_expects(:datetime, '-1')
|
66
|
+
end
|
67
|
+
assert_raises ArgumentError do
|
68
|
+
cast_expects(:date, '')
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_array_type_casting
|
73
|
+
assert_equal [1, 2, 3213992, 4], cast_expects(:int_array, ['1', '2', '3213992', '4'])[0]
|
74
|
+
assert_equal ['one', 'two', '5.0', '200', nil, 'true'], cast_expects(:str_array, [:one, 'two', 5.0, 200, nil, true])[0]
|
75
|
+
assert_equal [true, nil, true, true, false], cast_expects(:bool_array, ['1', nil, 'y', true, 'false'])[0]
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_array_type_casting_failure
|
79
|
+
assert_raises ActionWebService::Casting::CastingError do
|
80
|
+
cast_expects(:bool_array, ['false', 'blahblah'])
|
81
|
+
end
|
82
|
+
assert_raises ArgumentError do
|
83
|
+
cast_expects(:int_array, ['1', '2.021', '4'])
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_structured_type_casting_with_polymorphism
|
88
|
+
assert cast_expects(:a, B.new)[0].is_a?(B)
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
def cast_expects(method_name, *args)
|
93
|
+
API.api_method_instance(method_name.to_sym).cast_expects([*args])
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,156 @@
|
|
1
|
+
require 'abstract_client'
|
2
|
+
|
3
|
+
|
4
|
+
module ClientSoapTest
|
5
|
+
PORT = 8998
|
6
|
+
|
7
|
+
class SoapClientLet < ClientTest::AbstractClientLet
|
8
|
+
def do_POST(req, res)
|
9
|
+
test_request = ActionController::TestRequest.new
|
10
|
+
test_request.request_parameters['action'] = req.path.gsub(/^\//, '').split(/\//)[1]
|
11
|
+
test_request.env['REQUEST_METHOD'] = "POST"
|
12
|
+
test_request.env['HTTP_CONTENTTYPE'] = 'text/xml'
|
13
|
+
test_request.env['HTTP_SOAPACTION'] = req.header['soapaction'][0]
|
14
|
+
test_request.env['RAW_POST_DATA'] = req.body
|
15
|
+
response = ActionController::TestResponse.new
|
16
|
+
@controller.process(test_request, response)
|
17
|
+
res.header['content-type'] = 'text/xml'
|
18
|
+
res.body = response.body
|
19
|
+
rescue Exception => e
|
20
|
+
$stderr.puts e.message
|
21
|
+
$stderr.puts e.backtrace.join("\n")
|
22
|
+
ensure
|
23
|
+
ActiveRecord::Base.clear_active_connections!
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class ClientContainer < ActionController::Base
|
28
|
+
acts_as_web_service
|
29
|
+
web_client_api :client, :soap, "http://localhost:#{PORT}/client/api", :api => ClientTest::API
|
30
|
+
web_client_api :invalid, :null, "", :api => true
|
31
|
+
|
32
|
+
def get_client
|
33
|
+
client
|
34
|
+
end
|
35
|
+
|
36
|
+
def get_invalid
|
37
|
+
invalid
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class SoapServer < ClientTest::AbstractServer
|
42
|
+
def create_clientlet(controller)
|
43
|
+
SoapClientLet.new(controller)
|
44
|
+
end
|
45
|
+
|
46
|
+
def server_port
|
47
|
+
PORT
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class TC_ClientSoap < ActiveSupport::TestCase
|
53
|
+
include ClientTest
|
54
|
+
include ClientSoapTest
|
55
|
+
|
56
|
+
fixtures :users
|
57
|
+
|
58
|
+
def setup
|
59
|
+
@server = SoapServer.instance
|
60
|
+
@container = @server.container
|
61
|
+
@client = ActionWebService::Client::Soap.new(API, "http://localhost:#{@server.server_port}/client/api")
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_void
|
65
|
+
assert(@container.value_void.nil?)
|
66
|
+
@client.void
|
67
|
+
assert(!@container.value_void.nil?)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_normal
|
71
|
+
assert(@container.value_normal.nil?)
|
72
|
+
assert_equal(5, @client.normal(5, 6))
|
73
|
+
assert_equal([5, 6], @container.value_normal)
|
74
|
+
assert_equal(5, @client.normal("7", "8"))
|
75
|
+
assert_equal([7, 8], @container.value_normal)
|
76
|
+
assert_equal(5, @client.normal(true, false))
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_array_return
|
80
|
+
assert(@container.value_array_return.nil?)
|
81
|
+
new_person = Person.new
|
82
|
+
new_person.firstnames = ["one", "two"]
|
83
|
+
new_person.lastname = "last"
|
84
|
+
assert_equal([new_person], @client.array_return)
|
85
|
+
assert_equal([new_person], @container.value_array_return)
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_struct_pass
|
89
|
+
assert(@container.value_struct_pass.nil?)
|
90
|
+
new_person = Person.new
|
91
|
+
new_person.firstnames = ["one", "two"]
|
92
|
+
new_person.lastname = "last"
|
93
|
+
assert_equal(true, @client.struct_pass([new_person]))
|
94
|
+
assert_equal([[new_person]], @container.value_struct_pass)
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_nil_struct_return
|
98
|
+
assert_nil @client.nil_struct_return
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_inner_nil
|
102
|
+
outer = @client.inner_nil
|
103
|
+
assert_equal 'outer', outer.name
|
104
|
+
assert_nil outer.inner
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_client_container
|
108
|
+
assert_equal(50, ClientContainer.new.get_client.client_container)
|
109
|
+
assert(ClientContainer.new.get_invalid.nil?)
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_named_parameters
|
113
|
+
assert(@container.value_named_parameters.nil?)
|
114
|
+
assert(@client.named_parameters("key", 5).nil?)
|
115
|
+
assert_equal(["key", 5], @container.value_named_parameters)
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_capitalized_method_name
|
119
|
+
@container.value_normal = nil
|
120
|
+
assert_equal(5, @client.Normal(5, 6))
|
121
|
+
assert_equal([5, 6], @container.value_normal)
|
122
|
+
@container.value_normal = nil
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_model_return
|
126
|
+
user = @client.user_return
|
127
|
+
assert_equal 1, user.id
|
128
|
+
assert_equal 'Kent', user.name
|
129
|
+
assert user.active?
|
130
|
+
assert_kind_of Date, user.created_on
|
131
|
+
assert_equal Date.today, user.created_on
|
132
|
+
assert_equal BigDecimal('12.2'), user.balance
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_with_model
|
136
|
+
with_model = @client.with_model_return
|
137
|
+
assert_equal 'Kent', with_model.user.name
|
138
|
+
assert_equal 2, with_model.users.size
|
139
|
+
with_model.users.each do |user|
|
140
|
+
assert_kind_of User, user
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_scoped_model_return
|
145
|
+
scoped_model = @client.scoped_model_return
|
146
|
+
assert_kind_of Accounting::User, scoped_model
|
147
|
+
assert_equal 'Kent', scoped_model.name
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_multi_dim_return
|
151
|
+
md_struct = @client.multi_dim_return
|
152
|
+
assert_kind_of Array, md_struct.pref
|
153
|
+
assert_equal 2, md_struct.pref.size
|
154
|
+
assert_kind_of Array, md_struct.pref[0]
|
155
|
+
end
|
156
|
+
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
require 'abstract_client'
|
2
|
+
|
3
|
+
|
4
|
+
module ClientXmlRpcTest
|
5
|
+
PORT = 8999
|
6
|
+
|
7
|
+
class XmlRpcClientLet < ClientTest::AbstractClientLet
|
8
|
+
def do_POST(req, res)
|
9
|
+
test_request = ActionController::TestRequest.new
|
10
|
+
test_request.request_parameters['action'] = req.path.gsub(/^\//, '').split(/\//)[1]
|
11
|
+
test_request.env['REQUEST_METHOD'] = "POST"
|
12
|
+
test_request.env['HTTP_CONTENT_TYPE'] = 'text/xml'
|
13
|
+
test_request.env['RAW_POST_DATA'] = req.body
|
14
|
+
response = ActionController::TestResponse.new
|
15
|
+
@controller.process(test_request, response)
|
16
|
+
res.header['content-type'] = 'text/xml'
|
17
|
+
res.body = response.body
|
18
|
+
rescue Exception => e
|
19
|
+
$stderr.puts e.message
|
20
|
+
$stderr.puts e.backtrace.join("\n")
|
21
|
+
ensure
|
22
|
+
ActiveRecord::Base.clear_active_connections!
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class ClientContainer < ActionController::Base
|
27
|
+
acts_as_web_service
|
28
|
+
web_client_api :client, :xmlrpc, "http://localhost:#{PORT}/client/api", :api => ClientTest::API
|
29
|
+
|
30
|
+
def get_client
|
31
|
+
client
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class XmlRpcServer < ClientTest::AbstractServer
|
36
|
+
def create_clientlet(controller)
|
37
|
+
XmlRpcClientLet.new(controller)
|
38
|
+
end
|
39
|
+
|
40
|
+
def server_port
|
41
|
+
PORT
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class TC_ClientXmlRpc < ActiveSupport::TestCase
|
47
|
+
include ClientTest
|
48
|
+
include ClientXmlRpcTest
|
49
|
+
|
50
|
+
fixtures :users
|
51
|
+
|
52
|
+
def setup
|
53
|
+
@server = XmlRpcServer.instance
|
54
|
+
@container = @server.container
|
55
|
+
@client = ActionWebService::Client::XmlRpc.new(API, "http://localhost:#{@server.server_port}/client/api")
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_void
|
59
|
+
assert(@container.value_void.nil?)
|
60
|
+
@client.void
|
61
|
+
assert(!@container.value_void.nil?)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_normal
|
65
|
+
assert(@container.value_normal.nil?)
|
66
|
+
assert_equal(5, @client.normal(5, 6))
|
67
|
+
assert_equal([5, 6], @container.value_normal)
|
68
|
+
assert_equal(5, @client.normal("7", "8"))
|
69
|
+
assert_equal([7, 8], @container.value_normal)
|
70
|
+
assert_equal(5, @client.normal(true, false))
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_array_return
|
74
|
+
assert(@container.value_array_return.nil?)
|
75
|
+
new_person = Person.new
|
76
|
+
new_person.firstnames = ["one", "two"]
|
77
|
+
new_person.lastname = "last"
|
78
|
+
assert_equal([new_person], @client.array_return)
|
79
|
+
assert_equal([new_person], @container.value_array_return)
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_struct_pass
|
83
|
+
assert(@container.value_struct_pass.nil?)
|
84
|
+
new_person = Person.new
|
85
|
+
new_person.firstnames = ["one", "two"]
|
86
|
+
new_person.lastname = "last"
|
87
|
+
assert_equal(true, @client.struct_pass([new_person]))
|
88
|
+
assert_equal([[new_person]], @container.value_struct_pass)
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_nil_struct_return
|
92
|
+
assert_equal false, @client.nil_struct_return
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_inner_nil
|
96
|
+
outer = @client.inner_nil
|
97
|
+
assert_equal 'outer', outer.name
|
98
|
+
assert_nil outer.inner
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_client_container
|
102
|
+
assert_equal(50, ClientContainer.new.get_client.client_container)
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_named_parameters
|
106
|
+
assert(@container.value_named_parameters.nil?)
|
107
|
+
assert_equal(false, @client.named_parameters("xxx", 7))
|
108
|
+
assert_equal(["xxx", 7], @container.value_named_parameters)
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_exception
|
112
|
+
assert_raises(ActionWebService::Client::ClientError) do
|
113
|
+
assert(@client.thrower)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_invalid_signature
|
118
|
+
assert_raises(ArgumentError) do
|
119
|
+
@client.normal
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_model_return
|
124
|
+
user = @client.user_return
|
125
|
+
assert_equal 1, user.id
|
126
|
+
assert_equal 'Kent', user.name
|
127
|
+
assert user.active?
|
128
|
+
assert_kind_of Time, user.created_on
|
129
|
+
assert_equal Time.utc(Time.now.year, Time.now.month, Time.now.day), user.created_on
|
130
|
+
assert_equal BigDecimal('12.2'), user.balance
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_with_model
|
134
|
+
with_model = @client.with_model_return
|
135
|
+
assert_equal 'Kent', with_model.user.name
|
136
|
+
assert_equal 2, with_model.users.size
|
137
|
+
with_model.users.each do |user|
|
138
|
+
assert_kind_of User, user
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_scoped_model_return
|
143
|
+
scoped_model = @client.scoped_model_return
|
144
|
+
assert_kind_of Accounting::User, scoped_model
|
145
|
+
assert_equal 'Kent', scoped_model.name
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_multi_dim_return
|
149
|
+
md_struct = @client.multi_dim_return
|
150
|
+
assert_kind_of Array, md_struct.pref
|
151
|
+
assert_equal 2, md_struct.pref.size
|
152
|
+
assert_kind_of Array, md_struct.pref[0]
|
153
|
+
end
|
154
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
|
3
|
+
module ContainerTest
|
4
|
+
$immediate_service = Object.new
|
5
|
+
$deferred_service = Object.new
|
6
|
+
|
7
|
+
class DelegateContainer < ActionController::Base
|
8
|
+
acts_as_web_service
|
9
|
+
web_service_dispatching_mode :delegated
|
10
|
+
|
11
|
+
attr :flag
|
12
|
+
attr :previous_flag
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
@previous_flag = nil
|
16
|
+
@flag = true
|
17
|
+
end
|
18
|
+
|
19
|
+
web_service :immediate_service, $immediate_service
|
20
|
+
web_service(:deferred_service) { @previous_flag = @flag; @flag = false; $deferred_service }
|
21
|
+
end
|
22
|
+
|
23
|
+
class DirectContainer < ActionController::Base
|
24
|
+
acts_as_web_service
|
25
|
+
web_service_dispatching_mode :direct
|
26
|
+
end
|
27
|
+
|
28
|
+
class InvalidContainer
|
29
|
+
include ActionWebService::Container::Direct
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class TC_Container < Test::Unit::TestCase
|
34
|
+
include ContainerTest
|
35
|
+
|
36
|
+
def setup
|
37
|
+
@delegate_container = DelegateContainer.new
|
38
|
+
@direct_container = DirectContainer.new
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_registration
|
42
|
+
assert(DelegateContainer.has_web_service?(:immediate_service))
|
43
|
+
assert(DelegateContainer.has_web_service?(:deferred_service))
|
44
|
+
assert(!DelegateContainer.has_web_service?(:fake_service))
|
45
|
+
assert_raises(ActionWebService::Container::Delegated::ContainerError) do
|
46
|
+
DelegateContainer.web_service('invalid')
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_service_object
|
51
|
+
assert_raises(ActionWebService::Container::Delegated::ContainerError) do
|
52
|
+
@delegate_container.web_service_object(:nonexistent)
|
53
|
+
end
|
54
|
+
assert(@delegate_container.flag == true)
|
55
|
+
assert(@delegate_container.web_service_object(:immediate_service) == $immediate_service)
|
56
|
+
assert(@delegate_container.previous_flag.nil?)
|
57
|
+
assert(@delegate_container.flag == true)
|
58
|
+
assert(@delegate_container.web_service_object(:deferred_service) == $deferred_service)
|
59
|
+
assert(@delegate_container.previous_flag == true)
|
60
|
+
assert(@delegate_container.flag == false)
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_direct_container
|
64
|
+
assert(DirectContainer.web_service_dispatching_mode == :direct)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_validity
|
68
|
+
assert_raises(ActionWebService::Container::Direct::ContainerError) do
|
69
|
+
InvalidContainer.web_service_api :test
|
70
|
+
end
|
71
|
+
assert_raises(ActionWebService::Container::Direct::ContainerError) do
|
72
|
+
InvalidContainer.web_service_api 50.0
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|