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
|
require 'test/unit'
require 'soap/rpc/driver'
require 'soap/rpc/standaloneServer'
require 'soap/attachment'
module SOAP
module SWA
class TestFile < Test::Unit::TestCase
Port = 17171
THIS_FILE = File.expand_path(__FILE__)
class SwAService
def get_file
return {
'name' => $0,
'file' => SOAP::Attachment.new(File.open(THIS_FILE)) # closed when GCed.
}
end
def put_file(name, file)
"File '#{name}' was received ok."
end
end
def setup
@server = SOAP::RPC::StandaloneServer.new('SwAServer',
'http://www.acmetron.com/soap', '0.0.0.0', Port)
@server.add_servant(SwAService.new)
@server.level = Logger::Severity::ERROR
@t = Thread.new {
@server.start
}
@endpoint = "http://localhost:#{Port}/"
@client = SOAP::RPC::Driver.new(@endpoint, 'http://www.acmetron.com/soap')
@client.add_method('get_file')
@client.add_method('put_file', 'name', 'file')
@client.wiredump_dev = STDERR if $DEBUG
end
def teardown
@server.shutdown
@t.kill
@t.join
@client.reset_stream
end
def test_get_file
assert_equal(
File.open(THIS_FILE) { |f| f.read },
@client.get_file['file'].content
)
end
def test_put_file
assert_equal(
"File 'foo' was received ok.",
@client.put_file('foo',
SOAP::Attachment.new(File.open(THIS_FILE)))
)
assert_equal(
"File 'bar' was received ok.",
@client.put_file('bar',
SOAP::Attachment.new(File.open(THIS_FILE) { |f| f.read }))
)
end
end
end
end
|