Welcome to the "trac"-ing site of soap4r!
[soap4r] [httpclient] [openpgp4u] [pkcs1] [logger] [csv] [vtr]

root/trunk/test/wsdl/ref/test_ref.rb

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