1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
require 'test/unit'
require 'soap/rpc/standaloneServer'
require 'soap/wsdlDriver'
module SOAP
class TestDocument < Test::Unit::TestCase
Namespace = 'urn:example.com:document'
class Server < ::SOAP::RPC::StandaloneServer
def on_init
add_document_method(self, 'urn:example.com:document#submit', 'submit', XSD::QName.new(Namespace, 'ruby'), XSD::QName.new(Namespace, 'ruby'))
end
def submit(ruby)
ruby
end
end
DIR = File.dirname(File.expand_path(__FILE__))
Port = 17171
def setup
setup_server
setup_client
end
def setup_server
@server = Server.new('Test', Namespace, '0.0.0.0', Port)
@server.level = Logger::Severity::ERROR
@server_thread = start_server_thread(@server)
end
def setup_client
wsdl = File.join(DIR, 'document.wsdl')
@client = ::SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
@client.endpoint_url = "http://localhost:#{Port}/"
@client.wiredump_dev = STDOUT if $DEBUG
end
def teardown
teardown_server
teardown_client
end
def teardown_server
@server.shutdown
@server_thread.kill
@server_thread.join
end
def teardown_client
@client.reset_stream
end
def start_server_thread(server)
t = Thread.new {
Thread.current.abort_on_exception = true
server.start
}
t
end
def test_document
msg = {'myversion' => "1.9", 'date' => "2004-01-01T00:00:00Z"}
reply_msg = @client.submit(msg)
assert_equal('1.9', reply_msg.myversion)
assert_equal('1.9', reply_msg['myversion'])
assert_equal('2004-01-01T00:00:00Z', reply_msg.date)
assert_equal('2004-01-01T00:00:00Z', reply_msg['date'])
end
end
end
|