1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
|
require 'test/unit'
require 'soap/rpc/standaloneServer'
require 'soap/wsdlDriver'
require 'wsdl/soap/wsdl2ruby'
require File.join(File.dirname(File.expand_path(__FILE__)), '..', '..', 'testutil.rb')
module WSDL
module Ref
class TestRef < Test::Unit::TestCase
Namespace = 'urn:ref'
class Server < ::SOAP::RPC::StandaloneServer
Namespace = TestRef::Namespace
def on_init
add_document_method(
self,
Namespace + ':echo',
'echo',
XSD::QName.new(Namespace, 'Product-Bag'),
XSD::QName.new(Namespace, 'Creator')
)
self.literal_mapping_registry = ProductMappingRegistry::LiteralRegistry
end
def echo(arg)
content = [
arg.bag[0].name,
arg.bag[0].rating,
arg.bag[1].name,
arg.bag[1].rating,
arg.xmlattr_version,
arg.xmlattr_yesno,
arg.rating[0],
arg.rating[1],
arg.rating[2],
arg.comment_1[0],
arg.comment_1[0].xmlattr_msgid,
arg.comment_1[1],
arg.comment_1[1].xmlattr_msgid,
arg.comment_2[0],
arg.comment_2[0].xmlattr_msgid,
arg.comment_2[1],
arg.comment_2[1].xmlattr_msgid
]
rv = Creator.new(content.join(" "))
rv.xmlattr_Role = "role"
rv
end
end
DIR = File.dirname(File.expand_path(__FILE__))
Port = 17171
def setup
setup_classdef
setup_server
@client = nil
end
def teardown
teardown_server if @server
unless $DEBUG
File.unlink(pathname('product.rb'))
File.unlink(pathname('productMappingRegistry.rb'))
File.unlink(pathname('productDriver.rb'))
end
@client.reset_stream if @client
end
def setup_server
@server = Server.new('Test', Namespace, '0.0.0.0', Port)
@server.level = Logger::Severity::ERROR
@server_thread = TestUtil.start_server_thread(@server)
end
def setup_classdef
gen = WSDL::SOAP::WSDL2Ruby.new
gen.location = pathname("product.wsdl")
gen.basedir = DIR
gen.logger.level = Logger::FATAL
gen.opt['module_path'] = self.class.to_s.sub(/::[^:]+$/, '')
gen.opt['classdef'] = nil
gen.opt['mapping_registry'] = nil
gen.opt['driver'] = nil
gen.opt['force'] = true
gen.run
TestUtil.require(DIR, 'product.rb', 'productMappingRegistry.rb', 'productDriver.rb')
end
def teardown_server
@server.shutdown
@server_thread.kill
@server_thread.join
end
def pathname(filename)
File.join(DIR, filename)
end
def compare(expected, actual)
TestUtil.filecompare(pathname(expected), pathname(actual))
end
def test_classdef
gen = WSDL::SOAP::WSDL2Ruby.new
gen.location = pathname("product.wsdl")
gen.basedir = DIR
gen.logger.level = Logger::FATAL
gen.opt['module_path'] = self.class.to_s.sub(/::[^:]+$/, '')
gen.opt['classdef'] = nil
gen.opt['force'] = true
TestUtil.silent do
gen.run
end
compare("expectedProduct.rb", "product.rb")
compare("expectedDriver.rb", "productDriver.rb")
end
def test_wsdl
wsdl = File.join(DIR, 'product.wsdl')
@client = ::SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
@client.endpoint_url = "http://localhost:#{Port}/"
@client.wiredump_dev = STDOUT if $DEBUG
p1 = e("bag")
p1.add(e("name", "foo"))
p1.add(e(q(Namespace, "Rating"), "0"))
p2 = e("bag")
p2.add(e("name", "bar"))
p2.add(e(q(Namespace, "Rating"), "+1"))
version = "version"
yesno = "N"
r1 = e(q(Namespace, "Rating"), "0")
r2 = e(q(Namespace, "Rating"), "+1")
r3 = e(q(Namespace, "Rating"), "-1")
c11 = e("Comment_1", "comment11")
c11.extraattr["msgid"] = "msgid11"
c12 = e("Comment_1", "comment12")
c12.extraattr["msgid"] = "msgid12"
c21 = e("comment-2", "comment21")
c21.extraattr["msgid"] = "msgid21"
c22 = e("comment-2", "comment22")
c22.extraattr["msgid"] = "msgid22"
bag = e(q(Namespace, "Product-Bag"))
bag.add(p1)
bag.add(p2)
bag.add(r1)
bag.add(r2)
bag.add(r3)
bag.add(c11)
bag.add(c12)
bag.add(c21)
bag.add(c22)
bag.extraattr[q(Namespace, "version")] = version
bag.extraattr[q(Namespace, "yesno")] = yesno
ret = @client.echo(bag)
assert_equal(
[
p1["name"].text, p1["Rating"].text,
p2["name"].text, p2["Rating"].text,
version, yesno,
r1.text, r2.text, r3.text,
c11.text, c11.extraattr["msgid"],
c12.text, c12.extraattr["msgid"],
c21.text, c21.extraattr["msgid"],
c22.text, c22.extraattr["msgid"]
].join(" "),
ret
)
assert_equal("role", ret.xmlattr_Role)
end
def test_wsdl_with_classdef
wsdl = File.join(DIR, 'product.wsdl')
@client = ::SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
@client.endpoint_url = "http://localhost:#{Port}/"
@client.literal_mapping_registry = ProductMappingRegistry::LiteralRegistry
@client.wiredump_dev = STDOUT if $DEBUG
p1 = Product.new("foo", Rating::C_0)
p2 = Product.new("bar", Rating::C_1)
version = "version"
yesno = Yesno::Y
r1 = Rating::C_0
r2 = Rating::C_1
r3 = Rating::C_1_2
c11 = ::SOAP::SOAPElement.new("Comment_1", "comment11")
c11.extraattr["msgid"] = "msgid11"
c12 = ::SOAP::SOAPElement.new("Comment_1", "comment12")
c12.extraattr["msgid"] = "msgid12"
c21 = Comment.new("comment21")
c21.xmlattr_msgid = "msgid21"
c22 = Comment.new("comment22")
c22.xmlattr_msgid = "msgid22"
bag = ProductBag.new([p1, p2], [r1, r2, r3], [c11, c12], [c21, c22])
bag.xmlattr_version = version
bag.xmlattr_yesno = yesno
ret = @client.echo(bag)
assert_equal(
[
p1.name, p1.rating,
p2.name, p2.rating,
version, yesno,
r1, r2, r3,
c11.text, c11.extraattr["msgid"],
c12.text, c12.extraattr["msgid"],
c21, c21.xmlattr_msgid,
c22, c22.xmlattr_msgid
].join(" "),
ret
)
assert_equal("role", ret.xmlattr_Role)
end
def test_naive
@client = Ref_porttype.new("http://localhost:#{Port}/")
@client.wiredump_dev = STDOUT if $DEBUG
p1 = Product.new("foo", Rating::C_0)
p2 = Product.new("bar", Rating::C_1)
version = "version"
yesno = Yesno::Y
r1 = Rating::C_0
r2 = Rating::C_1
r3 = Rating::C_1_2
c11 = ::SOAP::SOAPElement.new("Comment_1", "comment11")
c11.extraattr["msgid"] = "msgid11"
c12 = ::SOAP::SOAPElement.new("Comment_1", "comment12")
c12.extraattr["msgid"] = "msgid12"
c21 = Comment.new("comment21")
c21.xmlattr_msgid = "msgid21"
c22 = Comment.new("comment22")
c22.xmlattr_msgid = "msgid22"
pts = C__point.new("123")
bag = ProductBag.new([p1, p2], [r1, r2, r3], [c11, c12], [c21, c22], pts)
bag.xmlattr_version = version
bag.xmlattr_yesno = yesno
ret = @client.echo(bag)
assert_equal(
[
p1.name, p1.rating,
p2.name, p2.rating,
version, yesno,
r1, r2, r3,
c11.text, c11.extraattr["msgid"],
c12.text, c12.extraattr["msgid"],
c21, c21.xmlattr_msgid,
c22, c22.xmlattr_msgid
].join(" "),
ret
)
assert_equal("role", ret.xmlattr_Role)
end
def e(name, text = nil)
::SOAP::SOAPElement.new(name, text)
end
def q(ns, name)
XSD::QName.new(ns, name)
end
end
end
end
|