| 1 |
require 'test/unit' |
|---|
| 2 |
require 'soap/rpc/standaloneServer' |
|---|
| 3 |
require 'soap/rpc/driver' |
|---|
| 4 |
require 'soap/header/handler' |
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
module SOAP |
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
class TestEmpty < Test::Unit::TestCase |
|---|
| 11 |
Port = 17171 |
|---|
| 12 |
|
|---|
| 13 |
class EmptyHeaderHandler < SOAP::Header::Handler |
|---|
| 14 |
def on_outbound(header) |
|---|
| 15 |
# dump Header even if no header item given. |
|---|
| 16 |
header.force_encode = true |
|---|
| 17 |
# no additional header item |
|---|
| 18 |
nil |
|---|
| 19 |
end |
|---|
| 20 |
end |
|---|
| 21 |
|
|---|
| 22 |
class NopServer < SOAP::RPC::StandaloneServer |
|---|
| 23 |
def initialize(*arg) |
|---|
| 24 |
super |
|---|
| 25 |
add_document_method(self, 'urn:empty:nop', 'nop', [], []) |
|---|
| 26 |
add_document_method(self, 'urn:empty:nop', 'nop_nil', nil, nil) |
|---|
| 27 |
end |
|---|
| 28 |
|
|---|
| 29 |
def nop |
|---|
| 30 |
[1, 2, 3] # ignored |
|---|
| 31 |
end |
|---|
| 32 |
|
|---|
| 33 |
def nop_nil |
|---|
| 34 |
[1, 2, 3] # ignored |
|---|
| 35 |
end |
|---|
| 36 |
end |
|---|
| 37 |
|
|---|
| 38 |
def setup |
|---|
| 39 |
@server = NopServer.new(self.class.name, nil, '0.0.0.0', Port) |
|---|
| 40 |
@server.level = Logger::Severity::ERROR |
|---|
| 41 |
@t = Thread.new { |
|---|
| 42 |
@server.start |
|---|
| 43 |
} |
|---|
| 44 |
@endpoint = "http://localhost:#{Port}/" |
|---|
| 45 |
@client = SOAP::RPC::Driver.new(@endpoint) |
|---|
| 46 |
@client.add_document_method('nop', 'urn:empty:nop', [], []) |
|---|
| 47 |
@client.add_document_method('nop_nil', 'urn:empty:nop', nil, nil) |
|---|
| 48 |
end |
|---|
| 49 |
|
|---|
| 50 |
def teardown |
|---|
| 51 |
@server.shutdown if @server |
|---|
| 52 |
if @t |
|---|
| 53 |
@t.kill |
|---|
| 54 |
@t.join |
|---|
| 55 |
end |
|---|
| 56 |
@client.reset_stream if @client |
|---|
| 57 |
end |
|---|
| 58 |
|
|---|
| 59 |
EMPTY_XML = %q[<?xml version="1.0" encoding="utf-8" ?> |
|---|
| 60 |
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" |
|---|
| 61 |
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" |
|---|
| 62 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> |
|---|
| 63 |
<env:Body></env:Body> |
|---|
| 64 |
</env:Envelope>] |
|---|
| 65 |
|
|---|
| 66 |
EMPTY_HEADER_XML = %q[<?xml version="1.0" encoding="utf-8" ?> |
|---|
| 67 |
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" |
|---|
| 68 |
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" |
|---|
| 69 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> |
|---|
| 70 |
<env:Header></env:Header> |
|---|
| 71 |
<env:Body></env:Body> |
|---|
| 72 |
</env:Envelope>] |
|---|
| 73 |
|
|---|
| 74 |
def test_nop |
|---|
| 75 |
@client.wiredump_dev = str = '' |
|---|
| 76 |
@client.nop |
|---|
| 77 |
assert_equal(EMPTY_XML, parse_requestxml(str)) |
|---|
| 78 |
assert_equal(EMPTY_XML, parse_responsexml(str)) |
|---|
| 79 |
end |
|---|
| 80 |
|
|---|
| 81 |
def test_nop_nil |
|---|
| 82 |
@client.wiredump_dev = str = '' |
|---|
| 83 |
@client.nop_nil |
|---|
| 84 |
assert_equal(EMPTY_XML, parse_requestxml(str)) |
|---|
| 85 |
assert_equal(EMPTY_XML, parse_responsexml(str)) |
|---|
| 86 |
end |
|---|
| 87 |
|
|---|
| 88 |
def test_empty_header |
|---|
| 89 |
@client.headerhandler << EmptyHeaderHandler.new(nil) |
|---|
| 90 |
@client.wiredump_dev = str = '' |
|---|
| 91 |
@client.nop |
|---|
| 92 |
assert_equal(EMPTY_HEADER_XML, parse_requestxml(str)) |
|---|
| 93 |
end |
|---|
| 94 |
|
|---|
| 95 |
def parse_requestxml(str) |
|---|
| 96 |
str.split(/\r?\n\r?\n/)[3] |
|---|
| 97 |
end |
|---|
| 98 |
|
|---|
| 99 |
def parse_responsexml(str) |
|---|
| 100 |
str.split(/\r?\n\r?\n/)[6] |
|---|
| 101 |
end |
|---|
| 102 |
end |
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
end |
|---|