1 $:.unshift(File.dirname(__FILE__) + '/apis')
2 require File.dirname(__FILE__) + '/abstract_dispatcher'
5 class ActionController::Base
7 alias :inherited_without_name_error :inherited
10 inherited_without_name_error(child)
17 class AutoLoadController < ActionController::Base; end
18 class FailingAutoLoadController < ActionController::Base; end
19 class BrokenAutoLoadController < ActionController::Base; end
21 class TC_DispatcherActionControllerSoap < Test::Unit::TestCase
22 include DispatcherTest
23 include DispatcherCommonTests
26 @direct_controller = DirectController.new
27 @delegated_controller = DelegatedController.new
28 @virtual_controller = VirtualController.new
29 @layered_controller = LayeredController.new
30 @protocol = ActionWebService::Protocol::Soap::SoapProtocol.create(@direct_controller)
33 def test_wsdl_generation
34 ensure_valid_wsdl_generation DelegatedController.new, DispatcherTest::WsdlNamespace
35 ensure_valid_wsdl_generation DirectController.new, DispatcherTest::WsdlNamespace
39 delegated_types = ensure_valid_wsdl_action DelegatedController.new
40 delegated_names = delegated_types.map{|x| x.name.name}
41 assert(delegated_names.include?('DispatcherTest..NodeArray'))
42 assert(delegated_names.include?('DispatcherTest..Node'))
43 direct_types = ensure_valid_wsdl_action DirectController.new
44 direct_names = direct_types.map{|x| x.name.name}
45 assert(direct_names.include?('DispatcherTest..NodeArray'))
46 assert(direct_names.include?('DispatcherTest..Node'))
47 assert(direct_names.include?('IntegerArray'))
51 assert(!AutoLoadController.web_service_api.nil?)
52 assert(AutoLoadController.web_service_api.has_public_api_method?('Void'))
53 assert(FailingAutoLoadController.web_service_api.nil?)
54 assert_raises(MissingSourceFile) do
55 FailingAutoLoadController.require_web_service_api :blah
57 assert_raises(ArgumentError) do
58 FailingAutoLoadController.require_web_service_api 50.0
60 assert(BrokenAutoLoadController.web_service_api.nil?)
63 def test_layered_dispatching
64 mt_cats = do_method_call(@layered_controller, 'mt.getCategories')
65 assert_equal(["mtCat1", "mtCat2"], mt_cats)
66 blogger_cats = do_method_call(@layered_controller, 'blogger.getCategories')
67 assert_equal(["bloggerCat1", "bloggerCat2"], blogger_cats)
71 @direct_controller.web_service_exception_reporting = true
73 assert_equal(Utf8String, do_method_call(@direct_controller, 'TestUtf8'))
74 retval = SOAP::Processor.unmarshal(@response_body).body.response
75 assert retval.is_a?(SOAP::SOAPString)
77 # If $KCODE is not set to UTF-8, any strings with non-ASCII UTF-8 data
78 # will be sent back as base64 by SOAP4R. By the time we get it here though,
79 # it will be decoded back into a string. So lets read the base64 value
80 # from the message body directly.
82 do_method_call(@direct_controller, 'TestUtf8')
83 retval = SOAP::Processor.unmarshal(@response_body).body.response
84 assert retval.is_a?(SOAP::SOAPBase64)
85 assert_equal "T25lIFdvcmxkIENhZsOp", retval.data.to_s
89 def exception_message(soap_fault_exception)
90 soap_fault_exception.detail.cause.message
93 def is_exception?(obj)
94 obj.respond_to?(:detail) && obj.detail.respond_to?(:cause) && \
95 obj.detail.cause.is_a?(Exception)
98 def service_name(container)
99 container.is_a?(DelegatedController) ? 'test_service' : 'api'
102 def ensure_valid_wsdl_generation(controller, expected_namespace)
103 wsdl = controller.generate_wsdl
104 ensure_valid_wsdl(controller, wsdl, expected_namespace)
107 def ensure_valid_wsdl(controller, wsdl, expected_namespace)
108 definitions = WSDL::Parser.new.parse(wsdl)
109 assert(definitions.is_a?(WSDL::Definitions))
110 definitions.bindings.each do |binding|
111 assert(binding.name.name.index(':').nil?)
113 definitions.services.each do |service|
114 service.ports.each do |port|
115 assert(port.name.name.index(':').nil?)
118 types = definitions.collect_complextypes.map{|x| x.name}
120 assert(type.namespace == expected_namespace)
122 location = definitions.services[0].ports[0].soap_address.location
123 if controller.is_a?(DelegatedController)
124 assert_match %r{http://test.host/dispatcher_test/delegated/test_service$}, location
125 elsif controller.is_a?(DirectController)
126 assert_match %r{http://test.host/dispatcher_test/direct/api$}, location
128 definitions.collect_complextypes
131 def ensure_valid_wsdl_action(controller)
132 test_request = ActionController::TestRequest.new({ 'action' => 'wsdl' })
133 test_response = ActionController::TestResponse.new
134 wsdl = controller.process(test_request, test_response).body
135 ensure_valid_wsdl(controller, wsdl, DispatcherTest::WsdlNamespace)