fdv-actionwebservice 2.3.8
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +320 -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.rb +66 -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 +149 -0
- data/lib/action_web_service/client.rb +3 -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/container.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/dispatcher.rb +2 -0
- data/lib/action_web_service/dispatcher/abstract.rb +207 -0
- data/lib/action_web_service/dispatcher/action_controller_dispatcher.rb +379 -0
- data/lib/action_web_service/invocation.rb +202 -0
- data/lib/action_web_service/protocol.rb +4 -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.rb +176 -0
- data/lib/action_web_service/protocol/soap_protocol/marshaler.rb +242 -0
- data/lib/action_web_service/protocol/xmlrpc_protocol.rb +122 -0
- data/lib/action_web_service/scaffolding.rb +281 -0
- data/lib/action_web_service/struct.rb +64 -0
- data/lib/action_web_service/support/class_inheritable_options.rb +26 -0
- data/lib/action_web_service/support/signature_types.rb +226 -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/actionwebservice.rb +1 -0
- data/setup.rb +1379 -0
- data/test/abstract_client.rb +183 -0
- data/test/abstract_dispatcher.rb +548 -0
- data/test/abstract_unit.rb +43 -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 +155 -0
- data/test/client_xmlrpc_test.rb +153 -0
- data/test/container_test.rb +73 -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/users.yml +12 -0
- data/test/gencov +3 -0
- data/test/invocation_test.rb +185 -0
- data/test/run +6 -0
- data/test/scaffolded_controller_test.rb +146 -0
- data/test/struct_test.rb +52 -0
- data/test/test_invoke_test.rb +112 -0
- metadata +166 -0
data/test/gencov
ADDED
@@ -0,0 +1,185 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/abstract_unit'
|
2
|
+
|
3
|
+
module InvocationTest
|
4
|
+
class API < ActionWebService::API::Base
|
5
|
+
api_method :add, :expects => [:int, :int], :returns => [:int]
|
6
|
+
api_method :transmogrify, :expects_and_returns => [:string]
|
7
|
+
api_method :fail_with_reason
|
8
|
+
api_method :fail_generic
|
9
|
+
api_method :no_before
|
10
|
+
api_method :no_after
|
11
|
+
api_method :only_one
|
12
|
+
api_method :only_two
|
13
|
+
end
|
14
|
+
|
15
|
+
class Interceptor
|
16
|
+
attr :args
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
@args = nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def intercept(*args)
|
23
|
+
@args = args
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
InterceptorClass = Interceptor.new
|
28
|
+
|
29
|
+
class Service < ActionController::Base
|
30
|
+
web_service_api API
|
31
|
+
|
32
|
+
before_invocation :intercept_before, :except => [:no_before]
|
33
|
+
after_invocation :intercept_after, :except => [:no_after]
|
34
|
+
prepend_after_invocation :intercept_after_first, :except => [:no_after]
|
35
|
+
prepend_before_invocation :intercept_only, :only => [:only_one, :only_two]
|
36
|
+
after_invocation(:only => [:only_one]) do |*args|
|
37
|
+
args[0].instance_variable_set('@block_invoked', args[1])
|
38
|
+
end
|
39
|
+
after_invocation InterceptorClass, :only => [:only_one]
|
40
|
+
|
41
|
+
attr_accessor :before_invoked
|
42
|
+
attr_accessor :after_invoked
|
43
|
+
attr_accessor :after_first_invoked
|
44
|
+
attr_accessor :only_invoked
|
45
|
+
attr_accessor :block_invoked
|
46
|
+
attr_accessor :invocation_result
|
47
|
+
|
48
|
+
def initialize
|
49
|
+
@before_invoked = nil
|
50
|
+
@after_invoked = nil
|
51
|
+
@after_first_invoked = nil
|
52
|
+
@only_invoked = nil
|
53
|
+
@invocation_result = nil
|
54
|
+
@block_invoked = nil
|
55
|
+
end
|
56
|
+
|
57
|
+
def add(a, b)
|
58
|
+
a + b
|
59
|
+
end
|
60
|
+
|
61
|
+
def transmogrify(str)
|
62
|
+
str.upcase
|
63
|
+
end
|
64
|
+
|
65
|
+
def fail_with_reason
|
66
|
+
end
|
67
|
+
|
68
|
+
def fail_generic
|
69
|
+
end
|
70
|
+
|
71
|
+
def no_before
|
72
|
+
5
|
73
|
+
end
|
74
|
+
|
75
|
+
def no_after
|
76
|
+
end
|
77
|
+
|
78
|
+
def only_one
|
79
|
+
end
|
80
|
+
|
81
|
+
def only_two
|
82
|
+
end
|
83
|
+
|
84
|
+
protected
|
85
|
+
def intercept_before(name, args)
|
86
|
+
@before_invoked = name
|
87
|
+
return [false, "permission denied"] if name == :fail_with_reason
|
88
|
+
return false if name == :fail_generic
|
89
|
+
end
|
90
|
+
|
91
|
+
def intercept_after(name, args, result)
|
92
|
+
@after_invoked = name
|
93
|
+
@invocation_result = result
|
94
|
+
end
|
95
|
+
|
96
|
+
def intercept_after_first(name, args, result)
|
97
|
+
@after_first_invoked = name
|
98
|
+
end
|
99
|
+
|
100
|
+
def intercept_only(name, args)
|
101
|
+
raise "Interception error" unless name == :only_one || name == :only_two
|
102
|
+
@only_invoked = name
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
class TC_Invocation < Test::Unit::TestCase
|
108
|
+
include ActionWebService::Invocation
|
109
|
+
|
110
|
+
def setup
|
111
|
+
@service = InvocationTest::Service.new
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_invocation
|
115
|
+
assert(perform_invocation(:add, 5, 10) == 15)
|
116
|
+
assert(perform_invocation(:transmogrify, "hello") == "HELLO")
|
117
|
+
assert_raises(NoMethodError) do
|
118
|
+
perform_invocation(:nonexistent_method_xyzzy)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_interceptor_registration
|
123
|
+
assert(InvocationTest::Service.before_invocation_interceptors.length == 2)
|
124
|
+
assert(InvocationTest::Service.after_invocation_interceptors.length == 4)
|
125
|
+
assert_equal(:intercept_only, InvocationTest::Service.before_invocation_interceptors[0])
|
126
|
+
assert_equal(:intercept_after_first, InvocationTest::Service.after_invocation_interceptors[0])
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_interception
|
130
|
+
assert(@service.before_invoked.nil?)
|
131
|
+
assert(@service.after_invoked.nil?)
|
132
|
+
assert(@service.only_invoked.nil?)
|
133
|
+
assert(@service.block_invoked.nil?)
|
134
|
+
assert(@service.invocation_result.nil?)
|
135
|
+
perform_invocation(:add, 20, 50)
|
136
|
+
assert(@service.before_invoked == :add)
|
137
|
+
assert(@service.after_invoked == :add)
|
138
|
+
assert(@service.invocation_result == 70)
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_interception_canceling
|
142
|
+
reason = nil
|
143
|
+
perform_invocation(:fail_with_reason){|r| reason = r}
|
144
|
+
assert(@service.before_invoked == :fail_with_reason)
|
145
|
+
assert(@service.after_invoked.nil?)
|
146
|
+
assert(@service.invocation_result.nil?)
|
147
|
+
assert(reason == "permission denied")
|
148
|
+
reason = true
|
149
|
+
@service.before_invoked = @service.after_invoked = @service.invocation_result = nil
|
150
|
+
perform_invocation(:fail_generic){|r| reason = r}
|
151
|
+
assert(@service.before_invoked == :fail_generic)
|
152
|
+
assert(@service.after_invoked.nil?)
|
153
|
+
assert(@service.invocation_result.nil?)
|
154
|
+
assert(reason == true)
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_interception_except_conditions
|
158
|
+
perform_invocation(:no_before)
|
159
|
+
assert(@service.before_invoked.nil?)
|
160
|
+
assert(@service.after_first_invoked == :no_before)
|
161
|
+
assert(@service.after_invoked == :no_before)
|
162
|
+
assert(@service.invocation_result == 5)
|
163
|
+
@service.before_invoked = @service.after_invoked = @service.invocation_result = nil
|
164
|
+
perform_invocation(:no_after)
|
165
|
+
assert(@service.before_invoked == :no_after)
|
166
|
+
assert(@service.after_invoked.nil?)
|
167
|
+
assert(@service.invocation_result.nil?)
|
168
|
+
end
|
169
|
+
|
170
|
+
def test_interception_only_conditions
|
171
|
+
assert(@service.only_invoked.nil?)
|
172
|
+
perform_invocation(:only_one)
|
173
|
+
assert(@service.only_invoked == :only_one)
|
174
|
+
assert(@service.block_invoked == :only_one)
|
175
|
+
assert(InvocationTest::InterceptorClass.args[1] == :only_one)
|
176
|
+
@service.only_invoked = nil
|
177
|
+
perform_invocation(:only_two)
|
178
|
+
assert(@service.only_invoked == :only_two)
|
179
|
+
end
|
180
|
+
|
181
|
+
private
|
182
|
+
def perform_invocation(method_name, *args, &block)
|
183
|
+
@service.perform_invocation(method_name, args, &block)
|
184
|
+
end
|
185
|
+
end
|
data/test/run
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'test/unit'
|
3
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
4
|
+
args = Dir[File.join(File.dirname(__FILE__), '*_test.rb')] + Dir[File.join(File.dirname(__FILE__), 'ws/*_test.rb')]
|
5
|
+
(r = Test::Unit::AutoRunner.new(true)).process_args(args)
|
6
|
+
exit r.run
|
@@ -0,0 +1,146 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/abstract_unit'
|
2
|
+
|
3
|
+
ActionController::Routing::Routes.draw do |map|
|
4
|
+
map.connect '', :controller => 'scaffolded'
|
5
|
+
map.connect ':controller/:action/:id'
|
6
|
+
end
|
7
|
+
|
8
|
+
ActionController::Base.view_paths = [ '.' ]
|
9
|
+
|
10
|
+
class ScaffoldPerson < ActionWebService::Struct
|
11
|
+
member :id, :int
|
12
|
+
member :name, :string
|
13
|
+
member :birth, :date
|
14
|
+
|
15
|
+
def ==(other)
|
16
|
+
self.id == other.id && self.name == other.name
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class ScaffoldedControllerTestAPI < ActionWebService::API::Base
|
21
|
+
api_method :hello, :expects => [{:integer=>:int}, :string], :returns => [:bool]
|
22
|
+
api_method :hello_struct_param, :expects => [{:person => ScaffoldPerson}], :returns => [:bool]
|
23
|
+
api_method :date_of_birth, :expects => [ScaffoldPerson], :returns => [:string]
|
24
|
+
api_method :bye, :returns => [[ScaffoldPerson]]
|
25
|
+
api_method :date_diff, :expects => [{:start_date => :date}, {:end_date => :date}], :returns => [:int]
|
26
|
+
api_method :time_diff, :expects => [{:start_time => :time}, {:end_time => :time}], :returns => [:int]
|
27
|
+
api_method :base64_upcase, :expects => [:base64], :returns => [:base64]
|
28
|
+
end
|
29
|
+
|
30
|
+
class ScaffoldedController < ActionController::Base
|
31
|
+
web_service_api ScaffoldedControllerTestAPI
|
32
|
+
web_service_scaffold :scaffold_invoke
|
33
|
+
|
34
|
+
def hello(int, string)
|
35
|
+
0
|
36
|
+
end
|
37
|
+
|
38
|
+
def hello_struct_param(person)
|
39
|
+
0
|
40
|
+
end
|
41
|
+
|
42
|
+
def date_of_birth(person)
|
43
|
+
person.birth.to_s
|
44
|
+
end
|
45
|
+
|
46
|
+
def bye
|
47
|
+
[ScaffoldPerson.new(:id => 1, :name => "leon"), ScaffoldPerson.new(:id => 2, :name => "paul")]
|
48
|
+
end
|
49
|
+
|
50
|
+
def rescue_action(e)
|
51
|
+
raise e
|
52
|
+
end
|
53
|
+
|
54
|
+
def date_diff(start_date, end_date)
|
55
|
+
end_date - start_date
|
56
|
+
end
|
57
|
+
|
58
|
+
def time_diff(start_time, end_time)
|
59
|
+
end_time - start_time
|
60
|
+
end
|
61
|
+
|
62
|
+
def base64_upcase(data)
|
63
|
+
data.upcase
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class ScaffoldedControllerTest < ActionController::TestCase
|
68
|
+
# def setup
|
69
|
+
# @controller = ScaffoldedController.new
|
70
|
+
# @request = ActionController::TestRequest.new
|
71
|
+
# @response = ActionController::TestResponse.new
|
72
|
+
# end
|
73
|
+
|
74
|
+
def test_scaffold_invoke
|
75
|
+
get :scaffold_invoke
|
76
|
+
assert_template 'methods.html.erb'
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_scaffold_invoke_method_params
|
80
|
+
get :scaffold_invoke_method_params, :service => 'scaffolded', :method => 'Hello'
|
81
|
+
assert_template 'parameters.html.erb'
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_scaffold_invoke_method_params_with_struct
|
85
|
+
get :scaffold_invoke_method_params, :service => 'scaffolded', :method => 'HelloStructParam'
|
86
|
+
assert_template 'parameters.html.erb'
|
87
|
+
assert_tag :tag => 'form'
|
88
|
+
assert_tag :tag => 'input', :attributes => {:name => "method_params[0][name]"}
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_scaffold_invoke_submit_hello
|
92
|
+
post :scaffold_invoke_submit, :service => 'scaffolded', :method => 'Hello', :method_params => {'0' => '5', '1' => 'hello world'}
|
93
|
+
assert_template 'result.html.erb'
|
94
|
+
assert_equal false, @controller.instance_eval{ @method_return_value }
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_scaffold_invoke_submit_bye
|
98
|
+
post :scaffold_invoke_submit, :service => 'scaffolded', :method => 'Bye'
|
99
|
+
assert_template 'result.html.erb'
|
100
|
+
persons = [ScaffoldPerson.new(:id => 1, :name => "leon"), ScaffoldPerson.new(:id => 2, :name => "paul")]
|
101
|
+
assert_equal persons, @controller.instance_eval{ @method_return_value }
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_scaffold_date_params
|
105
|
+
get :scaffold_invoke_method_params, :service => 'scaffolded', :method => 'DateDiff'
|
106
|
+
(0..1).each do |param|
|
107
|
+
(1..3).each do |date_part|
|
108
|
+
assert_tag :tag => 'select', :attributes => {:name => "method_params[#{param}][#{date_part}]"},
|
109
|
+
:children => {:greater_than => 1, :only => {:tag => 'option'}}
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
post :scaffold_invoke_submit, :service => 'scaffolded', :method => 'DateDiff',
|
114
|
+
:method_params => {'0' => {'1' => '2006', '2' => '2', '3' => '1'}, '1' => {'1' => '2006', '2' => '2', '3' => '2'}}
|
115
|
+
assert_equal 1, @controller.instance_eval{ @method_return_value }
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_scaffold_struct_date_params
|
119
|
+
post :scaffold_invoke_submit, :service => 'scaffolded', :method => 'DateOfBirth',
|
120
|
+
:method_params => {'0' => {'birth' => {'1' => '2006', '2' => '2', '3' => '1'}, 'id' => '1', 'name' => 'person'}}
|
121
|
+
assert_equal '2006-02-01', @controller.instance_eval{ @method_return_value }
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_scaffold_time_params
|
125
|
+
get :scaffold_invoke_method_params, :service => 'scaffolded', :method => 'TimeDiff'
|
126
|
+
(0..1).each do |param|
|
127
|
+
(1..6).each do |date_part|
|
128
|
+
assert_tag :tag => 'select', :attributes => {:name => "method_params[#{param}][#{date_part}]"},
|
129
|
+
:children => {:greater_than => 1, :only => {:tag => 'option'}}
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
post :scaffold_invoke_submit, :service => 'scaffolded', :method => 'TimeDiff',
|
134
|
+
:method_params => {'0' => {'1' => '2006', '2' => '2', '3' => '1', '4' => '1', '5' => '1', '6' => '1'},
|
135
|
+
'1' => {'1' => '2006', '2' => '2', '3' => '2', '4' => '1', '5' => '1', '6' => '1'}}
|
136
|
+
assert_equal 86400, @controller.instance_eval{ @method_return_value }
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_scaffold_base64
|
140
|
+
get :scaffold_invoke_method_params, :service => 'scaffolded', :method => 'Base64Upcase'
|
141
|
+
assert_tag :tag => 'textarea', :attributes => {:name => 'method_params[0]'}
|
142
|
+
|
143
|
+
post :scaffold_invoke_submit, :service => 'scaffolded', :method => 'Base64Upcase', :method_params => {'0' => 'scaffold'}
|
144
|
+
assert_equal 'SCAFFOLD', @controller.instance_eval{ @method_return_value }
|
145
|
+
end
|
146
|
+
end
|
data/test/struct_test.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/abstract_unit'
|
2
|
+
|
3
|
+
module StructTest
|
4
|
+
class Struct < ActionWebService::Struct
|
5
|
+
member :id, Integer
|
6
|
+
member :name, String
|
7
|
+
member :items, [String]
|
8
|
+
member :deleted, :bool
|
9
|
+
member :emails, [:string]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class TC_Struct < Test::Unit::TestCase
|
14
|
+
include StructTest
|
15
|
+
|
16
|
+
def setup
|
17
|
+
@struct = Struct.new(:id => 5,
|
18
|
+
:name => 'hello',
|
19
|
+
:items => ['one', 'two'],
|
20
|
+
:deleted => true,
|
21
|
+
:emails => ['test@test.com'])
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_members
|
25
|
+
assert_equal(5, Struct.members.size)
|
26
|
+
assert_equal(Integer, Struct.members[:id].type_class)
|
27
|
+
assert_equal(String, Struct.members[:name].type_class)
|
28
|
+
assert_equal(String, Struct.members[:items].element_type.type_class)
|
29
|
+
assert_equal(TrueClass, Struct.members[:deleted].type_class)
|
30
|
+
assert_equal(String, Struct.members[:emails].element_type.type_class)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_initializer_and_lookup
|
34
|
+
assert_equal(5, @struct.id)
|
35
|
+
assert_equal('hello', @struct.name)
|
36
|
+
assert_equal(['one', 'two'], @struct.items)
|
37
|
+
assert_equal(true, @struct.deleted)
|
38
|
+
assert_equal(['test@test.com'], @struct.emails)
|
39
|
+
assert_equal(5, @struct['id'])
|
40
|
+
assert_equal('hello', @struct['name'])
|
41
|
+
assert_equal(['one', 'two'], @struct['items'])
|
42
|
+
assert_equal(true, @struct['deleted'])
|
43
|
+
assert_equal(['test@test.com'], @struct['emails'])
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_each_pair
|
47
|
+
@struct.each_pair do |name, value|
|
48
|
+
assert_equal @struct.__send__(name), value
|
49
|
+
assert_equal @struct[name], value
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/abstract_unit'
|
2
|
+
require 'action_web_service/test_invoke'
|
3
|
+
|
4
|
+
class TestInvokeAPI < ActionWebService::API::Base
|
5
|
+
api_method :null
|
6
|
+
api_method :add, :expects => [:int, :int], :returns => [:int]
|
7
|
+
end
|
8
|
+
|
9
|
+
class TestInvokeService < ActionWebService::Base
|
10
|
+
web_service_api TestInvokeAPI
|
11
|
+
|
12
|
+
attr :invoked
|
13
|
+
|
14
|
+
def add(a, b)
|
15
|
+
@invoked = true
|
16
|
+
a + b
|
17
|
+
end
|
18
|
+
|
19
|
+
def null
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class TestController < ActionController::Base
|
24
|
+
def rescue_action(e); raise e; end
|
25
|
+
end
|
26
|
+
|
27
|
+
class TestInvokeDirectController < TestController
|
28
|
+
web_service_api TestInvokeAPI
|
29
|
+
|
30
|
+
attr :invoked
|
31
|
+
|
32
|
+
def add
|
33
|
+
@invoked = true
|
34
|
+
@method_params[0] + @method_params[1]
|
35
|
+
end
|
36
|
+
|
37
|
+
def null
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class TestInvokeDelegatedController < TestController
|
42
|
+
web_service_dispatching_mode :delegated
|
43
|
+
web_service :service, TestInvokeService.new
|
44
|
+
end
|
45
|
+
|
46
|
+
class TestInvokeLayeredController < TestController
|
47
|
+
web_service_dispatching_mode :layered
|
48
|
+
web_service(:one) { @service_one ||= TestInvokeService.new }
|
49
|
+
web_service(:two) { @service_two ||= TestInvokeService.new }
|
50
|
+
end
|
51
|
+
|
52
|
+
class TestInvokeTest < ActiveSupport::TestCase
|
53
|
+
def setup
|
54
|
+
@request = ActionController::TestRequest.new
|
55
|
+
@response = ActionController::TestResponse.new
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_direct_add
|
59
|
+
@controller = TestInvokeDirectController.new
|
60
|
+
assert_equal nil, @controller.invoked
|
61
|
+
result = invoke :add, 25, 25
|
62
|
+
assert_equal 50, result
|
63
|
+
assert_equal true, @controller.invoked
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_delegated_add
|
67
|
+
@controller = TestInvokeDelegatedController.new
|
68
|
+
assert_equal nil, @controller.web_service_object(:service).invoked
|
69
|
+
result = invoke_delegated :service, :add, 100, 50
|
70
|
+
assert_equal 150, result
|
71
|
+
assert_equal true, @controller.web_service_object(:service).invoked
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_layered_add
|
75
|
+
[:soap, :xmlrpc].each do |protocol|
|
76
|
+
@protocol = protocol
|
77
|
+
[:one, :two].each do |service|
|
78
|
+
@controller = TestInvokeLayeredController.new
|
79
|
+
assert_equal nil, @controller.web_service_object(service).invoked
|
80
|
+
result = invoke_layered service, :add, 200, -50
|
81
|
+
assert_equal 150, result
|
82
|
+
assert_equal true, @controller.web_service_object(service).invoked
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_layered_fail_with_wrong_number_of_arguments
|
88
|
+
[:soap, :xmlrpc].each do |protocol|
|
89
|
+
@protocol = protocol
|
90
|
+
[:one, :two].each do |service|
|
91
|
+
@controller = TestInvokeLayeredController.new
|
92
|
+
assert_raise(ArgumentError) { invoke_layered service, :add, 1 }
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_delegated_fail_with_wrong_number_of_arguments
|
98
|
+
@controller = TestInvokeDelegatedController.new
|
99
|
+
assert_raise(ArgumentError) { invoke_delegated :service, :add, 1 }
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_direct_fail_with_wrong_number_of_arguments
|
103
|
+
@controller = TestInvokeDirectController.new
|
104
|
+
assert_raise(ArgumentError) { invoke :add, 1 }
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_with_no_parameters_declared
|
108
|
+
@controller = TestInvokeDirectController.new
|
109
|
+
assert_nil invoke(:null)
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|