2005-02-25 18:39:39 -05:00
|
|
|
$:.unshift(File.dirname(__FILE__) + '/apis')
|
|
|
|
require File.dirname(__FILE__) + '/abstract_dispatcher'
|
|
|
|
require 'wsdl/parser'
|
|
|
|
|
2005-03-25 19:20:19 -05:00
|
|
|
class ActionController::Base
|
|
|
|
class << self
|
|
|
|
alias :inherited_without_name_error :inherited
|
|
|
|
def inherited(child)
|
|
|
|
begin
|
|
|
|
inherited_without_name_error(child)
|
|
|
|
rescue NameError => e
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-02-25 18:39:39 -05:00
|
|
|
class AutoLoadController < ActionController::Base; end
|
|
|
|
class FailingAutoLoadController < ActionController::Base; end
|
|
|
|
class BrokenAutoLoadController < ActionController::Base; end
|
|
|
|
|
|
|
|
class TC_DispatcherActionControllerSoap < Test::Unit::TestCase
|
|
|
|
include DispatcherTest
|
|
|
|
include DispatcherCommonTests
|
|
|
|
|
|
|
|
def setup
|
|
|
|
@direct_controller = DirectController.new
|
|
|
|
@delegated_controller = DelegatedController.new
|
2005-02-27 16:21:40 -05:00
|
|
|
@virtual_controller = VirtualController.new
|
2005-04-05 17:37:48 -04:00
|
|
|
@layered_controller = LayeredController.new
|
2005-06-25 02:27:39 -04:00
|
|
|
@protocol = ActionWebService::Protocol::Soap::SoapProtocol.create(@direct_controller)
|
2005-02-25 18:39:39 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_wsdl_generation
|
2005-06-25 02:27:39 -04:00
|
|
|
ensure_valid_wsdl_generation DelegatedController.new, DispatcherTest::WsdlNamespace
|
|
|
|
ensure_valid_wsdl_generation DirectController.new, DispatcherTest::WsdlNamespace
|
2005-02-25 18:39:39 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_wsdl_action
|
2005-02-27 16:21:40 -05:00
|
|
|
delegated_types = ensure_valid_wsdl_action DelegatedController.new
|
|
|
|
delegated_names = delegated_types.map{|x| x.name.name}
|
|
|
|
assert(delegated_names.include?('DispatcherTest..NodeArray'))
|
|
|
|
assert(delegated_names.include?('DispatcherTest..Node'))
|
|
|
|
direct_types = ensure_valid_wsdl_action DirectController.new
|
|
|
|
direct_names = direct_types.map{|x| x.name.name}
|
|
|
|
assert(direct_names.include?('DispatcherTest..NodeArray'))
|
|
|
|
assert(direct_names.include?('DispatcherTest..Node'))
|
|
|
|
assert(direct_names.include?('IntegerArray'))
|
2005-02-25 18:39:39 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_autoloading
|
|
|
|
assert(!AutoLoadController.web_service_api.nil?)
|
|
|
|
assert(AutoLoadController.web_service_api.has_public_api_method?('Void'))
|
|
|
|
assert(FailingAutoLoadController.web_service_api.nil?)
|
2005-03-25 19:20:19 -05:00
|
|
|
assert_raises(MissingSourceFile) do
|
2005-02-25 18:39:39 -05:00
|
|
|
FailingAutoLoadController.require_web_service_api :blah
|
|
|
|
end
|
|
|
|
assert_raises(ArgumentError) do
|
|
|
|
FailingAutoLoadController.require_web_service_api 50.0
|
|
|
|
end
|
|
|
|
assert(BrokenAutoLoadController.web_service_api.nil?)
|
|
|
|
end
|
|
|
|
|
2005-04-05 17:37:48 -04:00
|
|
|
def test_layered_dispatching
|
|
|
|
mt_cats = do_method_call(@layered_controller, 'mt.getCategories')
|
|
|
|
assert_equal(["mtCat1", "mtCat2"], mt_cats)
|
|
|
|
blogger_cats = do_method_call(@layered_controller, 'blogger.getCategories')
|
|
|
|
assert_equal(["bloggerCat1", "bloggerCat2"], blogger_cats)
|
|
|
|
end
|
|
|
|
|
2005-07-13 02:05:13 -04:00
|
|
|
def test_utf8
|
|
|
|
@direct_controller.web_service_exception_reporting = true
|
|
|
|
$KCODE = 'u'
|
|
|
|
assert_equal(Utf8String, do_method_call(@direct_controller, 'TestUtf8'))
|
2005-07-13 02:25:45 -04:00
|
|
|
retval = SOAP::Processor.unmarshal(@response_body).body.response
|
|
|
|
assert retval.is_a?(SOAP::SOAPString)
|
2005-04-28 13:55:34 -04:00
|
|
|
|
2005-07-13 02:05:13 -04:00
|
|
|
# If $KCODE is not set to UTF-8, any strings with non-ASCII UTF-8 data
|
|
|
|
# will be sent back as base64 by SOAP4R. By the time we get it here though,
|
|
|
|
# it will be decoded back into a string. So lets read the base64 value
|
|
|
|
# from the message body directly.
|
|
|
|
$KCODE = 'NONE'
|
|
|
|
do_method_call(@direct_controller, 'TestUtf8')
|
|
|
|
retval = SOAP::Processor.unmarshal(@response_body).body.response
|
|
|
|
assert retval.is_a?(SOAP::SOAPBase64)
|
|
|
|
assert_equal "T25lIFdvcmxkIENhZsOp", retval.data.to_s
|
|
|
|
end
|
2005-04-28 13:55:34 -04:00
|
|
|
|
2005-07-13 02:05:13 -04:00
|
|
|
protected
|
2005-02-25 18:39:39 -05:00
|
|
|
def exception_message(soap_fault_exception)
|
|
|
|
soap_fault_exception.detail.cause.message
|
|
|
|
end
|
|
|
|
|
|
|
|
def is_exception?(obj)
|
|
|
|
obj.respond_to?(:detail) && obj.detail.respond_to?(:cause) && \
|
|
|
|
obj.detail.cause.is_a?(Exception)
|
|
|
|
end
|
|
|
|
|
|
|
|
def service_name(container)
|
|
|
|
container.is_a?(DelegatedController) ? 'test_service' : 'api'
|
|
|
|
end
|
|
|
|
|
2005-06-25 02:27:39 -04:00
|
|
|
def ensure_valid_wsdl_generation(controller, expected_namespace)
|
2005-02-25 18:39:39 -05:00
|
|
|
wsdl = controller.generate_wsdl
|
2005-06-25 02:27:39 -04:00
|
|
|
ensure_valid_wsdl(controller, wsdl, expected_namespace)
|
2005-02-25 18:39:39 -05:00
|
|
|
end
|
|
|
|
|
2005-06-25 02:27:39 -04:00
|
|
|
def ensure_valid_wsdl(controller, wsdl, expected_namespace)
|
2005-02-25 18:39:39 -05:00
|
|
|
definitions = WSDL::Parser.new.parse(wsdl)
|
|
|
|
assert(definitions.is_a?(WSDL::Definitions))
|
|
|
|
definitions.bindings.each do |binding|
|
|
|
|
assert(binding.name.name.index(':').nil?)
|
|
|
|
end
|
|
|
|
definitions.services.each do |service|
|
|
|
|
service.ports.each do |port|
|
|
|
|
assert(port.name.name.index(':').nil?)
|
|
|
|
end
|
|
|
|
end
|
2005-02-27 16:21:40 -05:00
|
|
|
types = definitions.collect_complextypes.map{|x| x.name}
|
|
|
|
types.each do |type|
|
2005-06-25 02:27:39 -04:00
|
|
|
assert(type.namespace == expected_namespace)
|
2005-02-27 16:21:40 -05:00
|
|
|
end
|
2005-06-12 22:58:44 -04:00
|
|
|
location = definitions.services[0].ports[0].soap_address.location
|
|
|
|
if controller.is_a?(DelegatedController)
|
2006-08-31 22:18:52 -04:00
|
|
|
assert_match %r{http://test.host/dispatcher_test/delegated/test_service$}, location
|
2005-06-12 22:58:44 -04:00
|
|
|
elsif controller.is_a?(DirectController)
|
2006-08-31 22:18:52 -04:00
|
|
|
assert_match %r{http://test.host/dispatcher_test/direct/api$}, location
|
2005-06-12 22:58:44 -04:00
|
|
|
end
|
2005-02-27 16:21:40 -05:00
|
|
|
definitions.collect_complextypes
|
2005-02-25 18:39:39 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def ensure_valid_wsdl_action(controller)
|
|
|
|
test_request = ActionController::TestRequest.new({ 'action' => 'wsdl' })
|
|
|
|
test_response = ActionController::TestResponse.new
|
|
|
|
wsdl = controller.process(test_request, test_response).body
|
2005-06-25 02:27:39 -04:00
|
|
|
ensure_valid_wsdl(controller, wsdl, DispatcherTest::WsdlNamespace)
|
2005-02-25 18:39:39 -05:00
|
|
|
end
|
|
|
|
end
|