| 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 TestUnqualified < Test::Unit::TestCase |
|---|
| 14 |
class Server < ::SOAP::RPC::StandaloneServer |
|---|
| 15 |
Namespace = 'urn:lp' |
|---|
| 16 |
|
|---|
| 17 |
def on_init |
|---|
| 18 |
add_document_method( |
|---|
| 19 |
self, |
|---|
| 20 |
Namespace + ':login', |
|---|
| 21 |
'login', |
|---|
| 22 |
XSD::QName.new(Namespace, 'login'), |
|---|
| 23 |
XSD::QName.new(Namespace, 'loginResponse') |
|---|
| 24 |
) |
|---|
| 25 |
end |
|---|
| 26 |
|
|---|
| 27 |
def login(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('lp.rb')) |
|---|
| 45 |
File.unlink(pathname('lpMappingRegistry.rb')) |
|---|
| 46 |
File.unlink(pathname('lpDriver.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("lp.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 'lp.rb' |
|---|
| 72 |
ensure |
|---|
| 73 |
$".delete('lp.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_UNTYPED = |
|---|
| 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:login xmlns:n1="urn:lp"> |
|---|
| 95 |
<username>NaHi</username> |
|---|
| 96 |
<password>passwd</password> |
|---|
| 97 |
<timezone>JST</timezone> |
|---|
| 98 |
</n1:login> |
|---|
| 99 |
</env:Body> |
|---|
| 100 |
</env:Envelope>] |
|---|
| 101 |
|
|---|
| 102 |
def test_wsdl |
|---|
| 103 |
wsdl = File.join(DIR, 'lp.wsdl') |
|---|
| 104 |
@client = nil |
|---|
| 105 |
backupdir = Dir.pwd |
|---|
| 106 |
begin |
|---|
| 107 |
Dir.chdir(DIR) |
|---|
| 108 |
@client = ::SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver |
|---|
| 109 |
ensure |
|---|
| 110 |
Dir.chdir(backupdir) |
|---|
| 111 |
end |
|---|
| 112 |
@client.endpoint_url = "http://localhost:#{Port}/" |
|---|
| 113 |
@client.wiredump_dev = str = '' |
|---|
| 114 |
@client.login(:timezone => 'JST', :password => 'passwd', |
|---|
| 115 |
:username => 'NaHi') |
|---|
| 116 |
# untyped because of passing a Hash |
|---|
| 117 |
assert_equal(LOGIN_REQUEST_QUALIFIED_UNTYPED, parse_requestxml(str)) |
|---|
| 118 |
end |
|---|
| 119 |
|
|---|
| 120 |
include ::SOAP |
|---|
| 121 |
def test_naive |
|---|
| 122 |
TestUtil.require(DIR, 'lpDriver.rb', 'lpMappingRegistry.rb', 'lp.rb') |
|---|
| 123 |
@client = Lp_porttype.new("http://localhost:#{Port}/") |
|---|
| 124 |
|
|---|
| 125 |
@client.wiredump_dev = str = '' |
|---|
| 126 |
@client.login(Login.new('NaHi', 'passwd', 'JST')) |
|---|
| 127 |
assert_equal(LOGIN_REQUEST_QUALIFIED_UNTYPED, parse_requestxml(str)) |
|---|
| 128 |
end |
|---|
| 129 |
|
|---|
| 130 |
def parse_requestxml(str) |
|---|
| 131 |
str.split(/\r?\n\r?\n/)[3] |
|---|
| 132 |
end |
|---|
| 133 |
end |
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 |
end |
|---|
| 137 |
|
|---|
| 138 |
end |
|---|