actionwebservice 0.7.1 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +33 -0
- data/README +25 -6
- data/Rakefile +7 -7
- data/TODO +27 -6
- data/lib/action_web_service.rb +1 -0
- data/lib/action_web_service/api.rb +8 -11
- data/lib/action_web_service/casting.rb +8 -1
- data/lib/action_web_service/client/soap_client.rb +7 -8
- data/lib/action_web_service/container/action_controller_container.rb +8 -8
- data/lib/action_web_service/container/delegated_container.rb +1 -1
- data/lib/action_web_service/dispatcher/abstract.rb +13 -7
- data/lib/action_web_service/dispatcher/action_controller_dispatcher.rb +41 -41
- data/lib/action_web_service/protocol/abstract.rb +5 -2
- data/lib/action_web_service/protocol/discovery.rb +2 -2
- data/lib/action_web_service/protocol/soap_protocol.rb +35 -9
- data/lib/action_web_service/protocol/soap_protocol/marshaler.rb +54 -14
- data/lib/action_web_service/protocol/xmlrpc_protocol.rb +11 -3
- data/lib/action_web_service/scaffolding.rb +68 -40
- data/lib/action_web_service/support/signature_types.rb +39 -11
- data/lib/action_web_service/templates/scaffolds/layout.rhtml +1 -1
- data/lib/action_web_service/templates/scaffolds/parameters.rhtml +4 -2
- data/lib/action_web_service/test_invoke.rb +4 -7
- data/test/abstract_dispatcher.rb +52 -13
- data/test/api_test.rb +2 -2
- data/test/casting_test.rb +6 -2
- data/test/dispatcher_action_controller_soap_test.rb +24 -9
- data/test/dispatcher_action_controller_xmlrpc_test.rb +1 -1
- data/test/invocation_test.rb +1 -1
- data/test/scaffolded_controller_test.rb +1 -1
- data/test/test_invoke_test.rb +11 -9
- metadata +6 -6
@@ -1,6 +1,19 @@
|
|
1
1
|
module ActionWebService # :nodoc:
|
2
|
-
|
3
|
-
|
2
|
+
# Action Web Service supports the following base types in a signature:
|
3
|
+
#
|
4
|
+
# [<tt>:int</tt>] Represents an integer value, will be cast to an integer using <tt>Integer(value)</tt>
|
5
|
+
# [<tt>:string</tt>] Represents a string value, will be cast to an string using the <tt>to_s</tt> method on an object
|
6
|
+
# [<tt>:base64</tt>] Represents a Base 64 value, will contain the binary bytes of a Base 64 value sent by the caller
|
7
|
+
# [<tt>:bool</tt>] Represents a boolean value, whatever is passed will be cast to boolean (<tt>true</tt>, '1', 'true', 'y', 'yes' are taken to represent true; <tt>false</tt>, '0', 'false', 'n', 'no' and <tt>nil</tt> represent false)
|
8
|
+
# [<tt>:float</tt>] Represents a floating point value, will be cast to a float using <tt>Float(value)</tt>
|
9
|
+
# [<tt>:time</tt>] Represents a timestamp, will be cast to a <tt>Time</tt> object
|
10
|
+
# [<tt>:datetime</tt>] Represents a timestamp, will be cast to a <tt>DateTime</tt> object
|
11
|
+
# [<tt>:date</tt>] Represents a date, will be cast to a <tt>Date</tt> object
|
12
|
+
#
|
13
|
+
# For structured types, you'll need to pass in the Class objects of
|
14
|
+
# ActionWebService::Struct and ActiveRecord::Base derivatives.
|
15
|
+
module SignatureTypes
|
16
|
+
def canonical_signature(signature) # :nodoc:
|
4
17
|
return nil if signature.nil?
|
5
18
|
unless signature.is_a?(Array)
|
6
19
|
raise(ActionWebServiceError, "Expected signature to be an Array")
|
@@ -9,7 +22,7 @@ module ActionWebService # :nodoc:
|
|
9
22
|
signature.map{ |spec| canonical_signature_entry(spec, i += 1) }
|
10
23
|
end
|
11
24
|
|
12
|
-
def canonical_signature_entry(spec, i)
|
25
|
+
def canonical_signature_entry(spec, i) # :nodoc:
|
13
26
|
orig_spec = spec
|
14
27
|
name = "param#{i}"
|
15
28
|
if spec.is_a?(Hash)
|
@@ -28,20 +41,22 @@ module ActionWebService # :nodoc:
|
|
28
41
|
end
|
29
42
|
end
|
30
43
|
|
31
|
-
def canonical_type(type)
|
44
|
+
def canonical_type(type) # :nodoc:
|
32
45
|
type_name = symbol_name(type) || class_to_type_name(type)
|
33
46
|
type = type_name || type
|
34
47
|
return canonical_type_name(type) if type.is_a?(Symbol)
|
35
48
|
type
|
36
49
|
end
|
37
50
|
|
38
|
-
def canonical_type_name(name)
|
51
|
+
def canonical_type_name(name) # :nodoc:
|
39
52
|
name = name.to_sym
|
40
53
|
case name
|
41
54
|
when :int, :integer, :fixnum, :bignum
|
42
55
|
:int
|
43
|
-
when :string
|
56
|
+
when :string
|
44
57
|
:string
|
58
|
+
when :base64
|
59
|
+
:base64
|
45
60
|
when :bool, :boolean
|
46
61
|
:bool
|
47
62
|
when :float, :double
|
@@ -57,22 +72,24 @@ module ActionWebService # :nodoc:
|
|
57
72
|
end
|
58
73
|
end
|
59
74
|
|
60
|
-
def canonical_type_class(type)
|
75
|
+
def canonical_type_class(type) # :nodoc:
|
61
76
|
type = canonical_type(type)
|
62
77
|
type.is_a?(Symbol) ? type_name_to_class(type) : type
|
63
78
|
end
|
64
79
|
|
65
|
-
def symbol_name(name)
|
80
|
+
def symbol_name(name) # :nodoc:
|
66
81
|
return name.to_sym if name.is_a?(Symbol) || name.is_a?(String)
|
67
82
|
nil
|
68
83
|
end
|
69
84
|
|
70
|
-
def class_to_type_name(klass)
|
85
|
+
def class_to_type_name(klass) # :nodoc:
|
71
86
|
klass = klass.class unless klass.is_a?(Class)
|
72
87
|
if derived_from?(Integer, klass) || derived_from?(Fixnum, klass) || derived_from?(Bignum, klass)
|
73
88
|
:int
|
74
89
|
elsif klass == String
|
75
90
|
:string
|
91
|
+
elsif klass == Base64
|
92
|
+
:base64
|
76
93
|
elsif klass == TrueClass || klass == FalseClass
|
77
94
|
:bool
|
78
95
|
elsif derived_from?(Float, klass) || derived_from?(Precision, klass) || derived_from?(Numeric, klass)
|
@@ -88,12 +105,14 @@ module ActionWebService # :nodoc:
|
|
88
105
|
end
|
89
106
|
end
|
90
107
|
|
91
|
-
def type_name_to_class(name)
|
108
|
+
def type_name_to_class(name) # :nodoc:
|
92
109
|
case canonical_type_name(name)
|
93
110
|
when :int
|
94
111
|
Integer
|
95
112
|
when :string
|
96
113
|
String
|
114
|
+
when :base64
|
115
|
+
Base64
|
97
116
|
when :bool
|
98
117
|
TrueClass
|
99
118
|
when :float
|
@@ -109,7 +128,7 @@ module ActionWebService # :nodoc:
|
|
109
128
|
end
|
110
129
|
end
|
111
130
|
|
112
|
-
def derived_from?(ancestor, child)
|
131
|
+
def derived_from?(ancestor, child) # :nodoc:
|
113
132
|
child.ancestors.include?(ancestor)
|
114
133
|
end
|
115
134
|
|
@@ -150,6 +169,12 @@ module ActionWebService # :nodoc:
|
|
150
169
|
def structured?
|
151
170
|
false
|
152
171
|
end
|
172
|
+
|
173
|
+
def human_name(show_name=true)
|
174
|
+
type_type = array? ? element_type.type.to_s : self.type.to_s
|
175
|
+
str = array? ? (type_type + '[]') : type_type
|
176
|
+
show_name ? (str + " " + name.to_s) : str
|
177
|
+
end
|
153
178
|
end
|
154
179
|
|
155
180
|
class ArrayType < BaseType # :nodoc:
|
@@ -191,4 +216,7 @@ module ActionWebService # :nodoc:
|
|
191
216
|
true
|
192
217
|
end
|
193
218
|
end
|
219
|
+
|
220
|
+
class Base64 < String # :nodoc:
|
221
|
+
end
|
194
222
|
end
|
@@ -10,13 +10,15 @@
|
|
10
10
|
</p>
|
11
11
|
|
12
12
|
<% if @scaffold_method.expects %>
|
13
|
+
<% i = 0 %>
|
13
14
|
|
14
15
|
<strong>Method Parameters:</strong><br />
|
15
16
|
<% @scaffold_method.expects.each do |type| %>
|
16
17
|
<p>
|
17
|
-
<label for="method_params[]"><%= type.name
|
18
|
-
<%= method_parameter_input_fields(@scaffold_method, type) %>
|
18
|
+
<label for="method_params[<%= i %>]"><%= method_parameter_label(type.name, type) %> </label><br />
|
19
|
+
<%= method_parameter_input_fields(@scaffold_method, type, "method_params[#{i}]") %>
|
19
20
|
</p>
|
21
|
+
<% i += 1 %>
|
20
22
|
<% end %>
|
21
23
|
|
22
24
|
<% end %>
|
@@ -21,9 +21,6 @@ module Test # :nodoc:
|
|
21
21
|
|
22
22
|
# invoke the specified layered API method on the correct service
|
23
23
|
def invoke_layered(service_name, method_name, *args)
|
24
|
-
if protocol.is_a?(ActionWebService::Protocol::Soap::SoapProtocol)
|
25
|
-
raise "SOAP protocol support for :layered dispatching mode is not available"
|
26
|
-
end
|
27
24
|
prepare_request('api', service_name, method_name, *args)
|
28
25
|
@controller.process(@request, @response)
|
29
26
|
decode_rpc_response
|
@@ -66,7 +63,7 @@ module Test # :nodoc:
|
|
66
63
|
|
67
64
|
def public_method_name(service_name, api_method_name)
|
68
65
|
public_name = service_api(service_name).public_api_method_name(api_method_name)
|
69
|
-
if @controller.web_service_dispatching_mode == :layered
|
66
|
+
if @controller.web_service_dispatching_mode == :layered && protocol.is_a?(ActionWebService::Protocol::XmlRpc::XmlRpcProtocol)
|
70
67
|
'%s.%s' % [service_name.to_s, public_name]
|
71
68
|
else
|
72
69
|
public_name
|
@@ -84,13 +81,13 @@ module Test # :nodoc:
|
|
84
81
|
|
85
82
|
def protocol
|
86
83
|
if @protocol.nil?
|
87
|
-
@protocol ||= ActionWebService::Protocol::Soap::SoapProtocol.new
|
84
|
+
@protocol ||= ActionWebService::Protocol::Soap::SoapProtocol.new(@controller)
|
88
85
|
else
|
89
86
|
case @protocol
|
90
87
|
when :xmlrpc
|
91
|
-
@protocol = ActionWebService::Protocol::XmlRpc::XmlRpcProtocol.
|
88
|
+
@protocol = ActionWebService::Protocol::XmlRpc::XmlRpcProtocol.create(@controller)
|
92
89
|
when :soap
|
93
|
-
@protocol = ActionWebService::Protocol::Soap::SoapProtocol.
|
90
|
+
@protocol = ActionWebService::Protocol::Soap::SoapProtocol.create(@controller)
|
94
91
|
else
|
95
92
|
@protocol
|
96
93
|
end
|
data/test/abstract_dispatcher.rb
CHANGED
@@ -4,6 +4,8 @@ require 'stringio'
|
|
4
4
|
class ActionController::Base; def rescue_action(e) raise e end; end
|
5
5
|
|
6
6
|
module DispatcherTest
|
7
|
+
WsdlNamespace = 'http://rubyonrails.com/some/namespace'
|
8
|
+
|
7
9
|
class Node < ActiveRecord::Base
|
8
10
|
def initialize(*args)
|
9
11
|
super(*args)
|
@@ -56,6 +58,8 @@ module DispatcherTest
|
|
56
58
|
api_method :hash_struct_return, :returns => [[Person]]
|
57
59
|
api_method :thrower
|
58
60
|
api_method :void
|
61
|
+
api_method :hex, :expects => [:base64], :returns => [:string]
|
62
|
+
api_method :unhex, :expects => [:string], :returns => [:base64]
|
59
63
|
end
|
60
64
|
|
61
65
|
class VirtualAPI < ActionWebService::API::Base
|
@@ -126,18 +130,21 @@ module DispatcherTest
|
|
126
130
|
|
127
131
|
class AbstractController < ActionController::Base
|
128
132
|
def generate_wsdl
|
133
|
+
@request ||= ::ActionController::TestRequest.new
|
129
134
|
to_wsdl
|
130
135
|
end
|
131
136
|
end
|
132
137
|
|
133
138
|
class DelegatedController < AbstractController
|
134
139
|
web_service_dispatching_mode :delegated
|
140
|
+
wsdl_namespace WsdlNamespace
|
135
141
|
|
136
142
|
web_service(:test_service) { @service ||= Service.new; @service }
|
137
143
|
end
|
138
144
|
|
139
145
|
class LayeredController < AbstractController
|
140
146
|
web_service_dispatching_mode :layered
|
147
|
+
wsdl_namespace WsdlNamespace
|
141
148
|
|
142
149
|
web_service(:mt) { @mt_service ||= MTService.new; @mt_service }
|
143
150
|
web_service(:blogger) { @blogger_service ||= BloggerService.new; @blogger_service }
|
@@ -146,6 +153,7 @@ module DispatcherTest
|
|
146
153
|
class DirectController < AbstractController
|
147
154
|
web_service_api DirectAPI
|
148
155
|
web_service_dispatching_mode :direct
|
156
|
+
wsdl_namespace WsdlNamespace
|
149
157
|
|
150
158
|
before_filter :alwaysfail, :only => [:before_filtered]
|
151
159
|
after_filter :alwaysok, :only => [:after_filtered]
|
@@ -215,6 +223,14 @@ module DispatcherTest
|
|
215
223
|
@void_called = @method_params
|
216
224
|
end
|
217
225
|
|
226
|
+
def hex(s)
|
227
|
+
return s.unpack("H*")[0]
|
228
|
+
end
|
229
|
+
|
230
|
+
def unhex(s)
|
231
|
+
return [s].pack("H*")
|
232
|
+
end
|
233
|
+
|
218
234
|
protected
|
219
235
|
def alwaysfail
|
220
236
|
@before_filter_called = true
|
@@ -228,6 +244,7 @@ module DispatcherTest
|
|
228
244
|
|
229
245
|
class VirtualController < AbstractController
|
230
246
|
web_service_api VirtualAPI
|
247
|
+
wsdl_namespace WsdlNamespace
|
231
248
|
|
232
249
|
def fallback
|
233
250
|
"fallback!"
|
@@ -247,6 +264,8 @@ module DispatcherCommonTests
|
|
247
264
|
result = do_method_call(@direct_controller, 'BaseStructReturn')
|
248
265
|
assert(result[0].is_a?(DispatcherTest::Person))
|
249
266
|
assert(result[1].is_a?(DispatcherTest::Person))
|
267
|
+
assert_equal("cafe", do_method_call(@direct_controller, 'Hex', "\xca\xfe"))
|
268
|
+
assert_equal("\xca\xfe", do_method_call(@direct_controller, 'Unhex', "cafe"))
|
250
269
|
end
|
251
270
|
|
252
271
|
def test_direct_entrypoint
|
@@ -294,7 +313,7 @@ module DispatcherCommonTests
|
|
294
313
|
controller.class.web_service_exception_reporting = true
|
295
314
|
send_garbage_request = lambda do
|
296
315
|
service_name = service_name(controller)
|
297
|
-
request =
|
316
|
+
request = protocol.encode_action_pack_request(service_name, 'broken, method, name!', 'broken request body', :request_class => ActionController::TestRequest)
|
298
317
|
response = ActionController::TestResponse.new
|
299
318
|
controller.process(request, response)
|
300
319
|
# puts response.body
|
@@ -335,21 +354,21 @@ module DispatcherCommonTests
|
|
335
354
|
assert_equal person, @direct_controller.struct_pass_value
|
336
355
|
assert !person.equal?(@direct_controller.struct_pass_value)
|
337
356
|
result = do_method_call(@direct_controller, 'StructPass', {'id' => '1', 'name' => 'test'})
|
338
|
-
case
|
339
|
-
when
|
357
|
+
case
|
358
|
+
when soap?
|
340
359
|
assert_equal(person, @direct_controller.struct_pass_value)
|
341
360
|
assert !person.equal?(@direct_controller.struct_pass_value)
|
342
|
-
when
|
361
|
+
when xmlrpc?
|
343
362
|
assert_equal(person, @direct_controller.struct_pass_value)
|
344
363
|
assert !person.equal?(@direct_controller.struct_pass_value)
|
345
364
|
end
|
346
365
|
assert_equal person, do_method_call(@direct_controller, 'HashStructReturn')[0]
|
347
366
|
result = do_method_call(@direct_controller, 'StructPass', {'id' => '1', 'name' => 'test', 'nonexistent_attribute' => 'value'})
|
348
|
-
case
|
349
|
-
when
|
367
|
+
case
|
368
|
+
when soap?
|
350
369
|
assert_equal(person, @direct_controller.struct_pass_value)
|
351
370
|
assert !person.equal?(@direct_controller.struct_pass_value)
|
352
|
-
when
|
371
|
+
when xmlrpc?
|
353
372
|
assert_equal(person, @direct_controller.struct_pass_value)
|
354
373
|
assert !person.equal?(@direct_controller.struct_pass_value)
|
355
374
|
end
|
@@ -379,6 +398,24 @@ module DispatcherCommonTests
|
|
379
398
|
raise NotImplementedError
|
380
399
|
end
|
381
400
|
|
401
|
+
def update_request(ap_request)
|
402
|
+
end
|
403
|
+
|
404
|
+
def check_response(ap_response)
|
405
|
+
end
|
406
|
+
|
407
|
+
def protocol
|
408
|
+
@protocol
|
409
|
+
end
|
410
|
+
|
411
|
+
def soap?
|
412
|
+
protocol.is_a? ActionWebService::Protocol::Soap::SoapProtocol
|
413
|
+
end
|
414
|
+
|
415
|
+
def xmlrpc?
|
416
|
+
protocol.is_a? ActionWebService::Protocol::XmlRpc::XmlRpcProtocol
|
417
|
+
end
|
418
|
+
|
382
419
|
def do_method_call(container, public_method_name, *params)
|
383
420
|
request_env = {}
|
384
421
|
mode = container.web_service_dispatching_mode
|
@@ -398,7 +435,7 @@ module DispatcherCommonTests
|
|
398
435
|
service_name = $1
|
399
436
|
real_method_name = $2
|
400
437
|
end
|
401
|
-
if
|
438
|
+
if soap?
|
402
439
|
public_method_name = real_method_name
|
403
440
|
request_env['HTTP_SOAPACTION'] = "/soap/#{service_name}/#{real_method_name}"
|
404
441
|
end
|
@@ -406,24 +443,26 @@ module DispatcherCommonTests
|
|
406
443
|
method = api.public_api_method_instance(real_method_name)
|
407
444
|
service_name = self.service_name(container)
|
408
445
|
end
|
409
|
-
|
446
|
+
protocol.register_api(api)
|
410
447
|
virtual = false
|
411
448
|
unless method
|
412
449
|
virtual = true
|
413
450
|
method ||= ActionWebService::API::Method.new(public_method_name.underscore.to_sym, public_method_name, nil, nil)
|
414
451
|
end
|
415
|
-
body =
|
452
|
+
body = protocol.encode_request(public_method_name, params.dup, method.expects)
|
416
453
|
# puts body
|
417
|
-
ap_request =
|
454
|
+
ap_request = protocol.encode_action_pack_request(service_name, public_method_name, body, :request_class => ActionController::TestRequest)
|
418
455
|
ap_request.env.update(request_env)
|
456
|
+
update_request(ap_request)
|
419
457
|
ap_response = ActionController::TestResponse.new
|
420
458
|
container.process(ap_request, ap_response)
|
421
459
|
# puts ap_response.body
|
422
|
-
|
460
|
+
check_response(ap_response)
|
461
|
+
public_method_name, return_value = protocol.decode_response(ap_response.body)
|
423
462
|
unless is_exception?(return_value) || virtual
|
424
463
|
return_value = method.cast_returns(return_value)
|
425
464
|
end
|
426
|
-
if
|
465
|
+
if soap?
|
427
466
|
# http://dev.rubyonrails.com/changeset/920
|
428
467
|
assert_match(/Response$/, public_method_name) unless public_method_name == "fault"
|
429
468
|
end
|
data/test/api_test.rb
CHANGED
@@ -7,7 +7,7 @@ module APITest
|
|
7
7
|
api_method :expects, :expects => [:int, :bool]
|
8
8
|
api_method :returns, :returns => [:int, [:string]]
|
9
9
|
api_method :named_signature, :expects => [{:appkey=>:int}, {:publish=>:bool}]
|
10
|
-
api_method :string_types, :expects => ['int', 'string', 'bool']
|
10
|
+
api_method :string_types, :expects => ['int', 'string', 'bool', 'base64']
|
11
11
|
api_method :class_types, :expects => [TrueClass, Bignum, String]
|
12
12
|
end
|
13
13
|
end
|
@@ -45,7 +45,7 @@ class TC_API < Test::Unit::TestCase
|
|
45
45
|
assert_equal([Integer, [String]], API.api_methods[:returns].returns.map{|x| x.array?? [x.element_type.type_class] : x.type_class})
|
46
46
|
assert_equal([[:appkey, Integer], [:publish, TrueClass]], API.api_methods[:named_signature].expects.map{|x| [x.name, x.type_class]})
|
47
47
|
assert_equal(nil, API.api_methods[:named_signature].returns)
|
48
|
-
assert_equal([Integer, String, TrueClass], API.api_methods[:string_types].expects.map{|x| x.type_class})
|
48
|
+
assert_equal([Integer, String, TrueClass, ActionWebService::Base64], API.api_methods[:string_types].expects.map{|x| x.type_class})
|
49
49
|
assert_equal(nil, API.api_methods[:string_types].returns)
|
50
50
|
assert_equal([TrueClass, Integer, String], API.api_methods[:class_types].expects.map{|x| x.type_class})
|
51
51
|
assert_equal(nil, API.api_methods[:class_types].returns)
|
data/test/casting_test.rb
CHANGED
@@ -4,6 +4,7 @@ module CastingTest
|
|
4
4
|
class API < ActionWebService::API::Base
|
5
5
|
api_method :int, :expects => [:int]
|
6
6
|
api_method :str, :expects => [:string]
|
7
|
+
api_method :base64, :expects => [:base64]
|
7
8
|
api_method :bool, :expects => [:bool]
|
8
9
|
api_method :float, :expects => [:float]
|
9
10
|
api_method :time, :expects => [:time]
|
@@ -22,6 +23,9 @@ class TC_Casting < Test::Unit::TestCase
|
|
22
23
|
def test_base_type_casting_valid
|
23
24
|
assert_equal 10000, cast_expects(:int, '10000')[0]
|
24
25
|
assert_equal '10000', cast_expects(:str, 10000)[0]
|
26
|
+
base64 = cast_expects(:base64, 10000)[0]
|
27
|
+
assert_equal '10000', base64
|
28
|
+
assert_instance_of ActionWebService::Base64, base64
|
25
29
|
[1, '1', 'true', 'y', 'yes'].each do |val|
|
26
30
|
assert_equal true, cast_expects(:bool, val)[0]
|
27
31
|
end
|
@@ -62,8 +66,8 @@ class TC_Casting < Test::Unit::TestCase
|
|
62
66
|
|
63
67
|
def test_array_type_casting
|
64
68
|
assert_equal [1, 2, 3213992, 4], cast_expects(:int_array, ['1', '2', '3213992', '4'])[0]
|
65
|
-
assert_equal ['one', 'two', '5.0', '200',
|
66
|
-
assert_equal [true,
|
69
|
+
assert_equal ['one', 'two', '5.0', '200', nil, 'true'], cast_expects(:str_array, [:one, 'two', 5.0, 200, nil, true])[0]
|
70
|
+
assert_equal [true, nil, true, true, false], cast_expects(:bool_array, ['1', nil, 'y', true, 'false'])[0]
|
67
71
|
end
|
68
72
|
|
69
73
|
def test_array_type_casting_failure
|
@@ -27,12 +27,12 @@ class TC_DispatcherActionControllerSoap < Test::Unit::TestCase
|
|
27
27
|
@delegated_controller = DelegatedController.new
|
28
28
|
@virtual_controller = VirtualController.new
|
29
29
|
@layered_controller = LayeredController.new
|
30
|
-
@protocol = ActionWebService::Protocol::Soap::SoapProtocol.
|
30
|
+
@protocol = ActionWebService::Protocol::Soap::SoapProtocol.create(@direct_controller)
|
31
31
|
end
|
32
32
|
|
33
33
|
def test_wsdl_generation
|
34
|
-
ensure_valid_wsdl_generation DelegatedController.new
|
35
|
-
ensure_valid_wsdl_generation DirectController.new
|
34
|
+
ensure_valid_wsdl_generation DelegatedController.new, DispatcherTest::WsdlNamespace
|
35
|
+
ensure_valid_wsdl_generation DirectController.new, DispatcherTest::WsdlNamespace
|
36
36
|
end
|
37
37
|
|
38
38
|
def test_wsdl_action
|
@@ -68,6 +68,15 @@ class TC_DispatcherActionControllerSoap < Test::Unit::TestCase
|
|
68
68
|
end
|
69
69
|
|
70
70
|
protected
|
71
|
+
def update_request(ap_request)
|
72
|
+
ap_request.env.update('HTTP_CONTENT_TYPE' => 'text/xml; charset=us-ascii')
|
73
|
+
end
|
74
|
+
|
75
|
+
def check_response(ap_response)
|
76
|
+
assert_equal 'text/xml; charset=us-ascii', ap_response.headers['Content-Type']
|
77
|
+
assert_match /xml.*?encoding="us-ascii"/, ap_response.body
|
78
|
+
end
|
79
|
+
|
71
80
|
def exception_message(soap_fault_exception)
|
72
81
|
soap_fault_exception.detail.cause.message
|
73
82
|
end
|
@@ -81,12 +90,12 @@ class TC_DispatcherActionControllerSoap < Test::Unit::TestCase
|
|
81
90
|
container.is_a?(DelegatedController) ? 'test_service' : 'api'
|
82
91
|
end
|
83
92
|
|
84
|
-
def ensure_valid_wsdl_generation(controller)
|
93
|
+
def ensure_valid_wsdl_generation(controller, expected_namespace)
|
85
94
|
wsdl = controller.generate_wsdl
|
86
|
-
ensure_valid_wsdl(wsdl)
|
95
|
+
ensure_valid_wsdl(controller, wsdl, expected_namespace)
|
87
96
|
end
|
88
97
|
|
89
|
-
def ensure_valid_wsdl(wsdl)
|
98
|
+
def ensure_valid_wsdl(controller, wsdl, expected_namespace)
|
90
99
|
definitions = WSDL::Parser.new.parse(wsdl)
|
91
100
|
assert(definitions.is_a?(WSDL::Definitions))
|
92
101
|
definitions.bindings.each do |binding|
|
@@ -99,7 +108,13 @@ class TC_DispatcherActionControllerSoap < Test::Unit::TestCase
|
|
99
108
|
end
|
100
109
|
types = definitions.collect_complextypes.map{|x| x.name}
|
101
110
|
types.each do |type|
|
102
|
-
assert(type.namespace ==
|
111
|
+
assert(type.namespace == expected_namespace)
|
112
|
+
end
|
113
|
+
location = definitions.services[0].ports[0].soap_address.location
|
114
|
+
if controller.is_a?(DelegatedController)
|
115
|
+
assert_match %r{http://localhost/dispatcher_test/delegated/test_service$}, location
|
116
|
+
elsif controller.is_a?(DirectController)
|
117
|
+
assert_match %r{http://localhost/dispatcher_test/direct/api$}, location
|
103
118
|
end
|
104
119
|
definitions.collect_complextypes
|
105
120
|
end
|
@@ -107,9 +122,9 @@ class TC_DispatcherActionControllerSoap < Test::Unit::TestCase
|
|
107
122
|
def ensure_valid_wsdl_action(controller)
|
108
123
|
test_request = ActionController::TestRequest.new({ 'action' => 'wsdl' })
|
109
124
|
test_request.env['REQUEST_METHOD'] = 'GET'
|
110
|
-
test_request.env['HTTP_HOST'] = 'localhost
|
125
|
+
test_request.env['HTTP_HOST'] = 'localhost'
|
111
126
|
test_response = ActionController::TestResponse.new
|
112
127
|
wsdl = controller.process(test_request, test_response).body
|
113
|
-
ensure_valid_wsdl(wsdl)
|
128
|
+
ensure_valid_wsdl(controller, wsdl, DispatcherTest::WsdlNamespace)
|
114
129
|
end
|
115
130
|
end
|