| 1 |
require 'test/unit' |
|---|
| 2 |
require 'soap/rpc/driver' |
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
class TestInteropR4 < Test::Unit::TestCase |
|---|
| 6 |
include SOAP |
|---|
| 7 |
|
|---|
| 8 |
class ArrayOfBinary < Array; end |
|---|
| 9 |
MappingRegistry = Mapping::DefaultRegistry.dup |
|---|
| 10 |
MappingRegistry.add( |
|---|
| 11 |
ArrayOfBinary, |
|---|
| 12 |
SOAPArray, |
|---|
| 13 |
Mapping::Registry::TypedArrayFactory, |
|---|
| 14 |
{ :type => XSD::XSDBase64Binary::Type } |
|---|
| 15 |
) |
|---|
| 16 |
|
|---|
| 17 |
class << self |
|---|
| 18 |
include SOAP |
|---|
| 19 |
def setup(name, location) |
|---|
| 20 |
setup_log(name) |
|---|
| 21 |
setup_drv(location) |
|---|
| 22 |
end |
|---|
| 23 |
|
|---|
| 24 |
def teardown |
|---|
| 25 |
end |
|---|
| 26 |
|
|---|
| 27 |
private |
|---|
| 28 |
|
|---|
| 29 |
def setup_log(name) |
|---|
| 30 |
filename = File.basename($0).sub(/\.rb$/, '') << '.log' |
|---|
| 31 |
@@log = File.open(filename, 'w') |
|---|
| 32 |
@@log << "File: #{ filename } - Wiredumps for SOAP4R client / #{ name } server.\n" |
|---|
| 33 |
@@log << "Date: #{ Time.now }\n\n" |
|---|
| 34 |
end |
|---|
| 35 |
|
|---|
| 36 |
def setup_drv(location) |
|---|
| 37 |
namespace = "http://soapinterop.org/attachments/" |
|---|
| 38 |
soap_action = "http://soapinterop.org/attachments/" |
|---|
| 39 |
@@drv = RPC::Driver.new(location, namespace, soap_action) |
|---|
| 40 |
@@drv.mapping_registry = MappingRegistry |
|---|
| 41 |
@@drv.wiredump_dev = @@log |
|---|
| 42 |
method_def(@@drv, soap_action) |
|---|
| 43 |
end |
|---|
| 44 |
|
|---|
| 45 |
def method_def(drv, soap_action = nil) |
|---|
| 46 |
drv.add_method("EchoAttachment", |
|---|
| 47 |
[['in', 'In', nil], ['retval', 'Out', nil]]) |
|---|
| 48 |
drv.add_method("EchoAttachments", |
|---|
| 49 |
[['in', 'In', nil], ['retval', 'Out', nil]]) |
|---|
| 50 |
drv.add_method("EchoAttachmentAsBase64", |
|---|
| 51 |
[['in', 'In', nil], ['retval', 'Out', nil]]) |
|---|
| 52 |
drv.add_method("EchoBase64AsAttachment", |
|---|
| 53 |
[['in', 'In', nil], ['retval', 'Out', nil]]) |
|---|
| 54 |
end |
|---|
| 55 |
end |
|---|
| 56 |
|
|---|
| 57 |
def setup |
|---|
| 58 |
end |
|---|
| 59 |
|
|---|
| 60 |
def teardown |
|---|
| 61 |
end |
|---|
| 62 |
|
|---|
| 63 |
def drv |
|---|
| 64 |
@@drv |
|---|
| 65 |
end |
|---|
| 66 |
|
|---|
| 67 |
def log_test |
|---|
| 68 |
/`([^']+)'/ =~ caller(1)[0] |
|---|
| 69 |
title = $1 |
|---|
| 70 |
title = "==== " + title + " " << "=" * (title.length > 72 ? 0 : (72 - title.length)) |
|---|
| 71 |
@@log << "#{title}\n\n" |
|---|
| 72 |
end |
|---|
| 73 |
|
|---|
| 74 |
def test_EchoAttachment |
|---|
| 75 |
log_test |
|---|
| 76 |
var = drv.EchoAttachment(Attachment.new("foobar")) |
|---|
| 77 |
assert_equal("foobar", var.content) |
|---|
| 78 |
end |
|---|
| 79 |
|
|---|
| 80 |
def test_EchoAttachments |
|---|
| 81 |
log_test |
|---|
| 82 |
var = drv.EchoAttachments( |
|---|
| 83 |
ArrayOfBinary[ |
|---|
| 84 |
Attachment.new("foobar"), |
|---|
| 85 |
Attachment.new("abc\0\0\0def"), |
|---|
| 86 |
Attachment.new("ghi") |
|---|
| 87 |
] |
|---|
| 88 |
) |
|---|
| 89 |
assert_equal(3, var.size) |
|---|
| 90 |
assert_equal("foobar", var[0].content) |
|---|
| 91 |
assert_equal("abc\0\0\0def", var[1].content) |
|---|
| 92 |
assert_equal("ghi", var[2].content) |
|---|
| 93 |
end |
|---|
| 94 |
|
|---|
| 95 |
def test_EchoAttachmentAsBase64 |
|---|
| 96 |
log_test |
|---|
| 97 |
var = drv.EchoAttachmentAsBase64(Attachment.new("foobar")) |
|---|
| 98 |
assert_equal("foobar", var) |
|---|
| 99 |
end |
|---|
| 100 |
|
|---|
| 101 |
def test_EchoBase64AsAttachment |
|---|
| 102 |
log_test |
|---|
| 103 |
var = drv.EchoBase64AsAttachment("abc\0\1\2def") |
|---|
| 104 |
assert_equal("abc\0\1\2def", var.content) |
|---|
| 105 |
end |
|---|
| 106 |
end |
|---|
| 107 |
|
|---|
| 108 |
if $0 == __FILE__ |
|---|
| 109 |
name = ARGV.shift || 'localhost' |
|---|
| 110 |
location = ARGV.shift || 'http://localhost:10080/' |
|---|
| 111 |
TestInteropR4.setup(name, location) |
|---|
| 112 |
end |
|---|