| 1 |
require 'test/unit' |
|---|
| 2 |
require 'wsdl/soap/wsdl2ruby' |
|---|
| 3 |
require 'soap/rpc/standaloneServer' |
|---|
| 4 |
require 'soap/wsdlDriver' |
|---|
| 5 |
require File.join(File.dirname(File.expand_path(__FILE__)), '..', '..', 'testutil.rb') |
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
if defined?(HTTPClient) |
|---|
| 9 |
|
|---|
| 10 |
module WSDL |
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
class TestQualified < Test::Unit::TestCase |
|---|
| 14 |
class Server < ::SOAP::RPC::StandaloneServer |
|---|
| 15 |
Namespace = 'http://www50.brinkster.com/vbfacileinpt/np' |
|---|
| 16 |
|
|---|
| 17 |
def on_init |
|---|
| 18 |
add_document_method( |
|---|
| 19 |
self, |
|---|
| 20 |
Namespace + '/GetPrimeNumbers', |
|---|
| 21 |
'GetPrimeNumbers', |
|---|
| 22 |
XSD::QName.new(Namespace, 'GetPrimeNumbers'), |
|---|
| 23 |
XSD::QName.new(Namespace, 'GetPrimeNumbersResponse') |
|---|
| 24 |
) |
|---|
| 25 |
end |
|---|
| 26 |
|
|---|
| 27 |
def GetPrimeNumbers(arg) |
|---|
| 28 |
nil |
|---|
| 29 |
end |
|---|
| 30 |
end |
|---|
| 31 |
|
|---|
| 32 |
DIR = File.dirname(File.expand_path(__FILE__)) |
|---|
| 33 |
Port = 17171 |
|---|
| 34 |
|
|---|
| 35 |
def setup |
|---|
| 36 |
setup_server |
|---|
| 37 |
setup_clientdef |
|---|
| 38 |
@client = nil |
|---|
| 39 |
end |
|---|
| 40 |
|
|---|
| 41 |
def teardown |
|---|
| 42 |
teardown_server if @server |
|---|
| 43 |
unless $DEBUG |
|---|
| 44 |
File.unlink(pathname('default.rb')) |
|---|
| 45 |
File.unlink(pathname('defaultMappingRegistry.rb')) |
|---|
| 46 |
File.unlink(pathname('defaultDriver.rb')) |
|---|
| 47 |
end |
|---|
| 48 |
@client.reset_stream if @client |
|---|
| 49 |
end |
|---|
| 50 |
|
|---|
| 51 |
def setup_server |
|---|
| 52 |
@server = Server.new('Test', "urn:lp", '0.0.0.0', Port) |
|---|
| 53 |
@server.level = Logger::Severity::ERROR |
|---|
| 54 |
@server_thread = TestUtil.start_server_thread(@server) |
|---|
| 55 |
end |
|---|
| 56 |
|
|---|
| 57 |
def setup_clientdef |
|---|
| 58 |
backupdir = Dir.pwd |
|---|
| 59 |
begin |
|---|
| 60 |
Dir.chdir(DIR) |
|---|
| 61 |
gen = WSDL::SOAP::WSDL2Ruby.new |
|---|
| 62 |
gen.location = pathname("np.wsdl") |
|---|
| 63 |
gen.basedir = DIR |
|---|
| 64 |
gen.logger.level = Logger::FATAL |
|---|
| 65 |
gen.opt['module_path'] = self.class.to_s.sub(/::[^:]+$/, '') |
|---|
| 66 |
gen.opt['classdef'] = nil |
|---|
| 67 |
gen.opt['mapping_registry'] = nil |
|---|
| 68 |
gen.opt['driver'] = nil |
|---|
| 69 |
gen.opt['force'] = true |
|---|
| 70 |
gen.run |
|---|
| 71 |
require 'default.rb' |
|---|
| 72 |
ensure |
|---|
| 73 |
$".delete('default.rb') |
|---|
| 74 |
Dir.chdir(backupdir) |
|---|
| 75 |
end |
|---|
| 76 |
end |
|---|
| 77 |
|
|---|
| 78 |
def teardown_server |
|---|
| 79 |
@server.shutdown |
|---|
| 80 |
@server_thread.kill |
|---|
| 81 |
@server_thread.join |
|---|
| 82 |
end |
|---|
| 83 |
|
|---|
| 84 |
def pathname(filename) |
|---|
| 85 |
File.join(DIR, filename) |
|---|
| 86 |
end |
|---|
| 87 |
|
|---|
| 88 |
LOGIN_REQUEST_QUALIFIED = |
|---|
| 89 |
%q[<?xml version="1.0" encoding="utf-8" ?> |
|---|
| 90 |
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" |
|---|
| 91 |
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" |
|---|
| 92 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> |
|---|
| 93 |
<env:Body> |
|---|
| 94 |
<n1:GetPrimeNumbers xmlns:n1="http://www50.brinkster.com/vbfacileinpt/np"> |
|---|
| 95 |
<Min>2</Min> |
|---|
| 96 |
<n1:Max>10</n1:Max> |
|---|
| 97 |
</n1:GetPrimeNumbers> |
|---|
| 98 |
</env:Body> |
|---|
| 99 |
</env:Envelope>] |
|---|
| 100 |
|
|---|
| 101 |
def test_wsdl |
|---|
| 102 |
wsdl = File.join(DIR, 'np.wsdl') |
|---|
| 103 |
@client = nil |
|---|
| 104 |
backupdir = Dir.pwd |
|---|
| 105 |
begin |
|---|
| 106 |
Dir.chdir(DIR) |
|---|
| 107 |
@client = ::SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver |
|---|
| 108 |
ensure |
|---|
| 109 |
Dir.chdir(backupdir) |
|---|
| 110 |
end |
|---|
| 111 |
@client.endpoint_url = "http://localhost:#{Port}/" |
|---|
| 112 |
@client.wiredump_dev = str = '' |
|---|
| 113 |
@client.GetPrimeNumbers(:Min => 2, :Max => 10) |
|---|
| 114 |
assert_equal(LOGIN_REQUEST_QUALIFIED, parse_requestxml(str), |
|---|
| 115 |
[LOGIN_REQUEST_QUALIFIED, parse_requestxml(str)].join("\n\n")) |
|---|
| 116 |
end |
|---|
| 117 |
|
|---|
| 118 |
include ::SOAP |
|---|
| 119 |
def test_naive |
|---|
| 120 |
TestUtil.require(DIR, 'defaultDriver.rb', 'defaultMappingRegistry.rb', 'default.rb') |
|---|
| 121 |
@client = PnumSoap.new("http://localhost:#{Port}/") |
|---|
| 122 |
|
|---|
| 123 |
@client.wiredump_dev = str = '' |
|---|
| 124 |
@client.getPrimeNumbers(GetPrimeNumbers.new(2, 10)) |
|---|
| 125 |
assert_equal(LOGIN_REQUEST_QUALIFIED, parse_requestxml(str), |
|---|
| 126 |
[LOGIN_REQUEST_QUALIFIED, parse_requestxml(str)].join("\n\n")) |
|---|
| 127 |
end |
|---|
| 128 |
|
|---|
| 129 |
def parse_requestxml(str) |
|---|
| 130 |
str.split(/\r?\n\r?\n/)[3] |
|---|
| 131 |
end |
|---|
| 132 |
end |
|---|
| 133 |
|
|---|
| 134 |
|
|---|
| 135 |
end |
|---|
| 136 |
|
|---|
| 137 |
end |
|---|