| 1 |
require 'test/unit' |
|---|
| 2 |
require 'soap/rpc/standaloneServer' |
|---|
| 3 |
require 'soap/rpc/driver' |
|---|
| 4 |
|
|---|
| 5 |
if defined?(HTTPClient) |
|---|
| 6 |
|
|---|
| 7 |
module SOAP |
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
class TestNoIndent < Test::Unit::TestCase |
|---|
| 11 |
Port = 17171 |
|---|
| 12 |
|
|---|
| 13 |
class NopServer < SOAP::RPC::StandaloneServer |
|---|
| 14 |
def initialize(*arg) |
|---|
| 15 |
super |
|---|
| 16 |
add_rpc_method(self, 'nop') |
|---|
| 17 |
end |
|---|
| 18 |
|
|---|
| 19 |
def nop |
|---|
| 20 |
SOAP::RPC::SOAPVoid.new |
|---|
| 21 |
end |
|---|
| 22 |
end |
|---|
| 23 |
|
|---|
| 24 |
def setup |
|---|
| 25 |
@server = NopServer.new(self.class.name, nil, '0.0.0.0', Port) |
|---|
| 26 |
@server.level = Logger::Severity::ERROR |
|---|
| 27 |
@t = Thread.new { |
|---|
| 28 |
@server.start |
|---|
| 29 |
} |
|---|
| 30 |
@endpoint = "http://localhost:#{Port}/" |
|---|
| 31 |
@client = SOAP::RPC::Driver.new(@endpoint) |
|---|
| 32 |
@client.add_rpc_method('nop') |
|---|
| 33 |
end |
|---|
| 34 |
|
|---|
| 35 |
def teardown |
|---|
| 36 |
@server.shutdown if @server |
|---|
| 37 |
if @t |
|---|
| 38 |
@t.kill |
|---|
| 39 |
@t.join |
|---|
| 40 |
end |
|---|
| 41 |
@client.reset_stream if @client |
|---|
| 42 |
end |
|---|
| 43 |
|
|---|
| 44 |
INDENT_XML = |
|---|
| 45 |
%q[<?xml version="1.0" encoding="utf-8" ?> |
|---|
| 46 |
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" |
|---|
| 47 |
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" |
|---|
| 48 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> |
|---|
| 49 |
<env:Body> |
|---|
| 50 |
<nop env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> |
|---|
| 51 |
</nop> |
|---|
| 52 |
</env:Body> |
|---|
| 53 |
</env:Envelope>] |
|---|
| 54 |
|
|---|
| 55 |
NO_INDENT_XML = |
|---|
| 56 |
%q[<?xml version="1.0" encoding="utf-8" ?> |
|---|
| 57 |
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" |
|---|
| 58 |
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" |
|---|
| 59 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> |
|---|
| 60 |
<env:Body> |
|---|
| 61 |
<nop env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> |
|---|
| 62 |
</nop> |
|---|
| 63 |
</env:Body> |
|---|
| 64 |
</env:Envelope>] |
|---|
| 65 |
|
|---|
| 66 |
def test_indent |
|---|
| 67 |
@client.wiredump_dev = str = '' |
|---|
| 68 |
@client.options["soap.envelope.no_indent"] = false |
|---|
| 69 |
@client.nop |
|---|
| 70 |
assert_equal(INDENT_XML, parse_requestxml(str)) |
|---|
| 71 |
end |
|---|
| 72 |
|
|---|
| 73 |
def test_no_indent |
|---|
| 74 |
@client.wiredump_dev = str = '' |
|---|
| 75 |
@client.options["soap.envelope.no_indent"] = true |
|---|
| 76 |
@client.nop |
|---|
| 77 |
assert_equal(NO_INDENT_XML, parse_requestxml(str)) |
|---|
| 78 |
end |
|---|
| 79 |
|
|---|
| 80 |
def parse_requestxml(str) |
|---|
| 81 |
str.split(/\r?\n\r?\n/)[3] |
|---|
| 82 |
end |
|---|
| 83 |
end |
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
end |
|---|
| 87 |
|
|---|
| 88 |
end |
|---|