2005-02-18 05:35:25 -05:00
|
|
|
require File.dirname(__FILE__) + '/abstract_client'
|
|
|
|
|
|
|
|
|
|
|
|
module ClientXmlRpcTest
|
|
|
|
PORT = 8999
|
|
|
|
|
|
|
|
class XmlRpcClientLet < ClientTest::AbstractClientLet
|
|
|
|
def do_POST(req, res)
|
|
|
|
test_request = ActionController::TestRequest.new
|
|
|
|
test_request.request_parameters['action'] = req.path.gsub(/^\//, '').split(/\//)[1]
|
|
|
|
test_request.env['REQUEST_METHOD'] = "POST"
|
2005-02-25 18:39:39 -05:00
|
|
|
test_request.env['HTTP_CONTENT_TYPE'] = 'text/xml'
|
2005-02-18 05:35:25 -05:00
|
|
|
test_request.env['RAW_POST_DATA'] = req.body
|
2005-02-25 18:39:39 -05:00
|
|
|
response = ActionController::TestResponse.new
|
|
|
|
@controller.process(test_request, response)
|
2005-02-18 05:35:25 -05:00
|
|
|
res.header['content-type'] = 'text/xml'
|
2005-02-25 18:39:39 -05:00
|
|
|
res.body = response.body
|
2005-04-02 16:03:36 -05:00
|
|
|
# puts res.body
|
2005-02-18 05:35:25 -05:00
|
|
|
rescue Exception => e
|
|
|
|
$stderr.puts e.message
|
|
|
|
$stderr.puts e.backtrace.join("\n")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class ClientContainer < ActionController::Base
|
2005-02-18 16:22:52 -05:00
|
|
|
web_client_api :client, :xmlrpc, "http://localhost:#{PORT}/client/api", :api => ClientTest::API
|
2005-02-18 05:35:25 -05:00
|
|
|
|
|
|
|
def get_client
|
|
|
|
client
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class XmlRpcServer < ClientTest::AbstractServer
|
|
|
|
def create_clientlet(controller)
|
|
|
|
XmlRpcClientLet.new(controller)
|
|
|
|
end
|
|
|
|
|
|
|
|
def server_port
|
|
|
|
PORT
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class TC_ClientXmlRpc < Test::Unit::TestCase
|
|
|
|
include ClientTest
|
|
|
|
include ClientXmlRpcTest
|
|
|
|
|
|
|
|
def setup
|
|
|
|
@server = XmlRpcServer.instance
|
|
|
|
@container = @server.container
|
2005-02-18 18:55:29 -05:00
|
|
|
@client = ActionWebService::Client::XmlRpc.new(API, "http://localhost:#{@server.server_port}/client/api")
|
2005-02-18 05:35:25 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_void
|
|
|
|
assert(@container.value_void.nil?)
|
|
|
|
@client.void
|
|
|
|
assert(!@container.value_void.nil?)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_normal
|
|
|
|
assert(@container.value_normal.nil?)
|
|
|
|
assert_equal(5, @client.normal(5, 6))
|
|
|
|
assert_equal([5, 6], @container.value_normal)
|
2005-03-27 22:20:13 -05:00
|
|
|
assert_equal(5, @client.normal("7", "8"))
|
|
|
|
assert_equal([7, 8], @container.value_normal)
|
2005-04-02 16:03:36 -05:00
|
|
|
assert_equal(5, @client.normal(true, false))
|
2005-02-18 05:35:25 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_array_return
|
|
|
|
assert(@container.value_array_return.nil?)
|
|
|
|
new_person = Person.new
|
|
|
|
new_person.firstnames = ["one", "two"]
|
|
|
|
new_person.lastname = "last"
|
|
|
|
assert_equal([new_person], @client.array_return)
|
|
|
|
assert_equal([new_person], @container.value_array_return)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_struct_pass
|
|
|
|
assert(@container.value_struct_pass.nil?)
|
|
|
|
new_person = Person.new
|
|
|
|
new_person.firstnames = ["one", "two"]
|
|
|
|
new_person.lastname = "last"
|
|
|
|
assert_equal(true, @client.struct_pass([new_person]))
|
|
|
|
assert_equal([[new_person]], @container.value_struct_pass)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_client_container
|
|
|
|
assert_equal(50, ClientContainer.new.get_client.client_container)
|
|
|
|
end
|
2005-02-19 04:07:35 -05:00
|
|
|
|
|
|
|
def test_named_parameters
|
|
|
|
assert(@container.value_named_parameters.nil?)
|
2005-04-02 16:03:36 -05:00
|
|
|
assert_equal(true, @client.named_parameters("xxx", 7))
|
2005-02-19 04:07:35 -05:00
|
|
|
assert_equal(["xxx", 7], @container.value_named_parameters)
|
|
|
|
end
|
2005-02-25 18:39:39 -05:00
|
|
|
|
|
|
|
def test_exception
|
|
|
|
assert_raises(ActionWebService::Client::ClientError) do
|
|
|
|
assert(@client.thrower)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_invalid_signature
|
2005-03-27 22:20:13 -05:00
|
|
|
assert_raises(ArgumentError) do
|
2005-02-25 18:39:39 -05:00
|
|
|
@client.normal
|
|
|
|
end
|
|
|
|
end
|
2005-02-18 05:35:25 -05:00
|
|
|
end
|