2005-02-18 05:35:25 -05:00
|
|
|
require File.dirname(__FILE__) + '/abstract_unit'
|
|
|
|
|
|
|
|
module ContainerTest
|
|
|
|
$immediate_service = Object.new
|
|
|
|
$deferred_service = Object.new
|
|
|
|
|
|
|
|
class DelegateContainer < ActionController::Base
|
2005-02-18 16:22:52 -05:00
|
|
|
web_service_dispatching_mode :delegated
|
2005-02-18 05:35:25 -05:00
|
|
|
|
|
|
|
attr :flag
|
|
|
|
attr :previous_flag
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
@previous_flag = nil
|
|
|
|
@flag = true
|
|
|
|
end
|
|
|
|
|
2005-02-18 16:22:52 -05:00
|
|
|
web_service :immediate_service, $immediate_service
|
|
|
|
web_service(:deferred_service) { @previous_flag = @flag; @flag = false; $deferred_service }
|
2005-02-18 05:35:25 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
class DirectContainer < ActionController::Base
|
2005-02-18 16:22:52 -05:00
|
|
|
web_service_dispatching_mode :direct
|
2005-02-25 18:39:39 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
class InvalidContainer
|
|
|
|
include ActionWebService::Container::Direct
|
|
|
|
end
|
2005-02-18 05:35:25 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
class TC_Container < Test::Unit::TestCase
|
2005-02-25 18:39:39 -05:00
|
|
|
include ContainerTest
|
|
|
|
|
2005-02-18 05:35:25 -05:00
|
|
|
def setup
|
2005-02-25 18:39:39 -05:00
|
|
|
@delegate_container = DelegateContainer.new
|
|
|
|
@direct_container = DirectContainer.new
|
2005-02-18 05:35:25 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_registration
|
2005-02-25 18:39:39 -05:00
|
|
|
assert(DelegateContainer.has_web_service?(:immediate_service))
|
|
|
|
assert(DelegateContainer.has_web_service?(:deferred_service))
|
|
|
|
assert(!DelegateContainer.has_web_service?(:fake_service))
|
|
|
|
assert_raises(ActionWebService::Container::Delegated::ContainerError) do
|
|
|
|
DelegateContainer.web_service('invalid')
|
|
|
|
end
|
2005-02-18 05:35:25 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_service_object
|
2005-02-25 18:39:39 -05:00
|
|
|
assert_raises(ActionWebService::Container::Delegated::ContainerError) do
|
|
|
|
@delegate_container.web_service_object(:nonexistent)
|
|
|
|
end
|
2005-02-18 05:35:25 -05:00
|
|
|
assert(@delegate_container.flag == true)
|
2005-02-18 16:22:52 -05:00
|
|
|
assert(@delegate_container.web_service_object(:immediate_service) == $immediate_service)
|
2005-02-18 05:35:25 -05:00
|
|
|
assert(@delegate_container.previous_flag.nil?)
|
|
|
|
assert(@delegate_container.flag == true)
|
2005-02-18 16:22:52 -05:00
|
|
|
assert(@delegate_container.web_service_object(:deferred_service) == $deferred_service)
|
2005-02-18 05:35:25 -05:00
|
|
|
assert(@delegate_container.previous_flag == true)
|
|
|
|
assert(@delegate_container.flag == false)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_direct_container
|
2005-02-25 18:39:39 -05:00
|
|
|
assert(DirectContainer.web_service_dispatching_mode == :direct)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_validity
|
|
|
|
assert_raises(ActionWebService::Container::Direct::ContainerError) do
|
|
|
|
InvalidContainer.web_service_api :test
|
|
|
|
end
|
|
|
|
assert_raises(ActionWebService::Container::Direct::ContainerError) do
|
|
|
|
InvalidContainer.web_service_api 50.0
|
|
|
|
end
|
2005-02-18 05:35:25 -05:00
|
|
|
end
|
|
|
|
end
|