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

root/trunk/test/wsdl/rpc/test_rpc_lit.rb

Revision 2011, 16.1 kB (checked in by nahi, 1 year ago)
  • merged from 1_5 branch.
    • enabled Sriver#generate_explicit_type for literal services.
    • test added.
    • removed generated files.
Line 
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) and defined?(OpenSSL)
9
10 module WSDL; module RPC
11
12
13 class TestRPCLIT < Test::Unit::TestCase
14   class Server < ::SOAP::RPC::StandaloneServer
15     Namespace = "http://soapbuilders.org/rpc-lit-test"
16
17     def on_init
18       self.generate_explicit_type = false
19       self.literal_mapping_registry = RPCLiteralTestDefinitionsMappingRegistry::LiteralRegistry
20       add_rpc_operation(self,
21         XSD::QName.new(Namespace, 'echoStringArray'),
22         nil,
23         'echoStringArray', [
24           [:in, 'inputStringArray', nil],
25           [:retval, 'return', nil]
26         ],
27         {
28           :request_style => :rpc,
29           :request_use => :literal,
30           :response_style => :rpc,
31           :response_use => :literal
32         }
33       )
34       add_rpc_operation(self,
35         XSD::QName.new(Namespace, 'echoStringArrayInline'),
36         nil,
37         'echoStringArrayInline', [
38           [:in, 'inputStringArray', nil],
39           [:retval, 'return', nil]
40         ],
41         {
42           :request_style => :rpc,
43           :request_use => :literal,
44           :response_style => :rpc,
45           :response_use => :literal
46         }
47       )
48       add_rpc_operation(self,
49         XSD::QName.new(Namespace, 'echoNestedStruct'),
50         nil,
51         'echoNestedStruct', [
52           [:in, 'inputNestedStruct', nil],
53           [:retval, 'return', nil]
54         ],
55         {
56           :request_style => :rpc,
57           :request_use => :literal,
58           :response_style => :rpc,
59           :response_use => :literal
60         }
61       )
62       add_rpc_operation(self,
63         XSD::QName.new(Namespace, 'echoStructArray'),
64         nil,
65         'echoStructArray', [
66           [:in, 'inputStructArray', nil],
67           [:retval, 'return', nil]
68         ],
69         {
70           :request_style => :rpc,
71           :request_use => :literal,
72           :response_style => :rpc,
73           :response_use => :literal
74         }
75       )
76     end
77  
78     def echoStringArray(strings)
79       # strings.stringItem => Array
80       ArrayOfstring[*strings.stringItem]
81     end
82
83     def echoStringArrayInline(strings)
84       ArrayOfstringInline[*strings.stringItem]
85     end
86
87     def echoNestedStruct(struct)
88       struct
89     end
90
91     def echoStructArray(ary)
92       ary
93     end
94   end
95
96   DIR = File.dirname(File.expand_path(__FILE__))
97
98   Port = 17171
99
100   def setup
101     setup_classdef
102     setup_server
103     @client = nil
104   end
105
106   def teardown
107     teardown_server if @server
108     unless $DEBUG
109       File.unlink(pathname('RPC-Literal-TestDefinitions.rb'))
110       File.unlink(pathname('RPC-Literal-TestDefinitionsMappingRegistry.rb'))
111       File.unlink(pathname('RPC-Literal-TestDefinitionsDriver.rb'))
112     end
113     @client.reset_stream if @client
114   end
115
116   def setup_server
117     @server = Server.new('Test', Server::Namespace, '0.0.0.0', Port)
118     @server.level = Logger::Severity::ERROR
119     @server_thread = TestUtil.start_server_thread(@server)
120   end
121
122   def setup_classdef
123     gen = WSDL::SOAP::WSDL2Ruby.new
124     gen.location = pathname("test-rpc-lit.wsdl")
125     gen.basedir = DIR
126     gen.logger.level = Logger::FATAL
127     gen.opt['module_path'] = self.class.to_s.sub(/::[^:]+$/, '')
128     gen.opt['classdef'] = nil
129     gen.opt['mapping_registry'] = nil
130     gen.opt['driver'] = nil
131     gen.opt['force'] = true
132     gen.run
133     TestUtil.require(DIR, 'RPC-Literal-TestDefinitions.rb', 'RPC-Literal-TestDefinitionsMappingRegistry.rb', 'RPC-Literal-TestDefinitionsDriver.rb')
134   end
135
136   def teardown_server
137     @server.shutdown
138     @server_thread.kill
139     @server_thread.join
140   end
141
142   def pathname(filename)
143     File.join(DIR, filename)
144   end
145
146   def test_wsdl_echoStringArray
147     wsdl = pathname('test-rpc-lit.wsdl')
148     @client = ::SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
149     @client.endpoint_url = "http://localhost:#{Port}/"
150     @client.wiredump_dev = STDOUT if $DEBUG
151     # response contains only 1 part.
152     result = @client.echoStringArray(ArrayOfstring["a", "b", "c"])[0]
153     assert_equal(["a", "b", "c"], result.stringItem)
154   end
155
156   ECHO_STRING_ARRAY_REQUEST =
157 %q[<?xml version="1.0" encoding="utf-8" ?>
158 <env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
159     xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
160     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
161   <env:Body>
162     <n1:echoStringArray xmlns:n1="http://soapbuilders.org/rpc-lit-test">
163       <inputStringArray xmlns:n2="http://soapbuilders.org/rpc-lit-test/types">
164         <n2:stringItem>a</n2:stringItem>
165         <n2:stringItem>b</n2:stringItem>
166         <n2:stringItem>c</n2:stringItem>
167       </inputStringArray>
168     </n1:echoStringArray>
169   </env:Body>
170 </env:Envelope>]
171
172   ECHO_STRING_ARRAY_RESPONSE =
173 %q[<?xml version="1.0" encoding="utf-8" ?>
174 <env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
175     xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
176     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
177   <env:Body>
178     <n1:echoStringArrayResponse xmlns:n1="http://soapbuilders.org/rpc-lit-test">
179       <n1:return xmlns:n2="http://soapbuilders.org/rpc-lit-test/types">
180         <n2:stringItem>a</n2:stringItem>
181         <n2:stringItem>b</n2:stringItem>
182         <n2:stringItem>c</n2:stringItem>
183       </n1:return>
184     </n1:echoStringArrayResponse>
185   </env:Body>
186 </env:Envelope>]
187
188   def test_stub_echoStringArray
189     drv = SoapTestPortTypeRpcLit.new("http://localhost:#{Port}/")
190     drv.wiredump_dev = str = ''
191     drv.generate_explicit_type = false
192     # response contains only 1 part.
193     result = drv.echoStringArray(ArrayOfstring["a", "b", "c"])[0]
194     assert_equal(ECHO_STRING_ARRAY_REQUEST, parse_requestxml(str),
195       [ECHO_STRING_ARRAY_REQUEST, parse_requestxml(str)].join("\n\n"))
196     assert_equal(ECHO_STRING_ARRAY_RESPONSE, parse_responsexml(str),
197       [ECHO_STRING_ARRAY_RESPONSE, parse_responsexml(str)].join("\n\n"))
198     assert_equal(ArrayOfstring["a", "b", "c"], result)
199   end
200
201   ECHO_STRING_ARRAY_INLINE_REQUEST =
202 %q[<?xml version="1.0" encoding="utf-8" ?>
203 <env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
204     xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
205     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
206   <env:Body>
207     <n1:echoStringArrayInline xmlns:n1="http://soapbuilders.org/rpc-lit-test">
208       <inputStringArray>
209         <stringItem>a</stringItem>
210         <stringItem>b</stringItem>
211         <stringItem>c</stringItem>
212       </inputStringArray>
213     </n1:echoStringArrayInline>
214   </env:Body>
215 </env:Envelope>]
216
217   ECHO_STRING_ARRAY_INLINE_RESPONSE =
218 %q[<?xml version="1.0" encoding="utf-8" ?>
219 <env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
220     xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
221     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
222   <env:Body>
223     <n1:echoStringArrayInlineResponse xmlns:n1="http://soapbuilders.org/rpc-lit-test">
224       <n1:return>
225         <stringItem>a</stringItem>
226         <stringItem>b</stringItem>
227         <stringItem>c</stringItem>
228       </n1:return>
229     </n1:echoStringArrayInlineResponse>
230   </env:Body>
231 </env:Envelope>]
232
233   def test_stub_echoStringArrayInline
234     drv = SoapTestPortTypeRpcLit.new("http://localhost:#{Port}/")
235     drv.wiredump_dev = str = ''
236     drv.generate_explicit_type = false
237     # response contains only 1 part.
238     result = drv.echoStringArrayInline(ArrayOfstringInline["a", "b", "c"])[0]
239     assert_equal(ArrayOfstring["a", "b", "c"], result)
240     assert_equal(ECHO_STRING_ARRAY_INLINE_REQUEST, parse_requestxml(str),
241       [ECHO_STRING_ARRAY_INLINE_REQUEST, parse_requestxml(str)].join("\n\n"))
242     assert_equal(ECHO_STRING_ARRAY_INLINE_RESPONSE, parse_responsexml(str))
243   end
244
245   ECHO_NESTED_STRUCT_REQUEST =
246 %q[<?xml version="1.0" encoding="utf-8" ?>
247 <env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
248     xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
249     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
250   <env:Body>
251     <n1:echoNestedStruct xmlns:n1="http://soapbuilders.org/rpc-lit-test">
252       <inputStruct xmlns:n2="http://soapbuilders.org/rpc-lit-test/types">
253         <varString>str</varString>
254         <varInt>1</varInt>
255         <varFloat>+1</varFloat>
256         <n2:structItem>
257           <varString>str</varString>
258           <varInt>1</varInt>
259           <varFloat>+1</varFloat>
260         </n2:structItem>
261       </inputStruct>
262     </n1:echoNestedStruct>
263   </env:Body>
264 </env:Envelope>]
265
266   ECHO_NESTED_STRUCT_RESPONSE =
267 %q[<?xml version="1.0" encoding="utf-8" ?>
268 <env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
269     xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
270     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
271   <env:Body>
272     <n1:echoNestedStructResponse xmlns:n1="http://soapbuilders.org/rpc-lit-test">
273       <n1:return xmlns:n2="http://soapbuilders.org/rpc-lit-test/types">
274         <varString>str</varString>
275         <varInt>1</varInt>
276         <varFloat>+1</varFloat>
277         <n2:structItem>
278           <varString>str</varString>
279           <varInt>1</varInt>
280           <varFloat>+1</varFloat>
281         </n2:structItem>
282       </n1:return>
283     </n1:echoNestedStructResponse>
284   </env:Body>
285 </env:Envelope>]
286
287   def test_wsdl_echoNestedStruct
288     wsdl = pathname('test-rpc-lit.wsdl')
289     @client = ::SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
290     @client.endpoint_url = "http://localhost:#{Port}/"
291     @client.wiredump_dev = str = ''
292     @client.generate_explicit_type = false
293     # response contains only 1 part.
294     result = @client.echoNestedStruct(SOAPStructStruct.new("str", 1, 1.0, SOAPStruct.new("str", 1, 1.0)))[0]
295     assert_equal('str', result.varString)
296     assert_equal('1', result.varInt)
297     assert_equal('+1', result.varFloat)
298     assert_equal('str', result.structItem.varString)
299     assert_equal('1', result.structItem.varInt)
300     assert_equal('+1', result.structItem.varFloat)
301     assert_equal(ECHO_NESTED_STRUCT_REQUEST, parse_requestxml(str),
302       [ECHO_NESTED_STRUCT_REQUEST, parse_requestxml(str)].join("\n\n"))
303     assert_equal(ECHO_NESTED_STRUCT_RESPONSE, parse_responsexml(str))
304   end
305
306   ECHO_NESTED_STRUCT_REQUEST_NIL =
307 %q[<?xml version="1.0" encoding="utf-8" ?>
308 <env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
309     xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
310     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
311   <env:Body>
312     <n1:echoNestedStruct xmlns:n1="http://soapbuilders.org/rpc-lit-test">
313       <inputStruct xmlns:n2="http://soapbuilders.org/rpc-lit-test/types">
314         <varString>str</varString>
315         <varFloat>+1</varFloat>
316         <n2:structItem>
317           <varString>str</varString>
318           <varInt xsi:nil="true"></varInt>
319           <varFloat>+1</varFloat>
320         </n2:structItem>
321       </inputStruct>
322     </n1:echoNestedStruct>
323   </env:Body>
324 </env:Envelope>]
325
326   ECHO_NESTED_STRUCT_RESPONSE_NIL =
327 %q[<?xml version="1.0" encoding="utf-8" ?>
328 <env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
329     xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
330     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
331   <env:Body>
332     <n1:echoNestedStructResponse xmlns:n1="http://soapbuilders.org/rpc-lit-test">
333       <n1:return xmlns:n2="http://soapbuilders.org/rpc-lit-test/types">
334         <varString>str</varString>
335         <varFloat>+1</varFloat>
336         <n2:structItem>
337           <varString>str</varString>
338           <varFloat>+1</varFloat>
339         </n2:structItem>
340       </n1:return>
341     </n1:echoNestedStructResponse>
342   </env:Body>
343 </env:Envelope>]
344   def test_wsdl_echoNestedStruct_nil
345     wsdl = pathname('test-rpc-lit.wsdl')
346     @client = ::SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
347     @client.endpoint_url = "http://localhost:#{Port}/"
348     @client.wiredump_dev = str = ''
349     @client.generate_explicit_type = false
350     result = @client.echoNestedStruct(SOAPStructStruct.new("str", nil, 1.0, SOAPStruct.new("str", ::SOAP::SOAPNil.new, 1.0)))[0]
351     assert(!result.respond_to?(:varInt))
352     assert(result.respond_to?(:varString))
353     assert_equal(ECHO_NESTED_STRUCT_REQUEST_NIL, parse_requestxml(str),
354       [ECHO_NESTED_STRUCT_REQUEST_NIL, parse_requestxml(str)].join("\n\n"))
355     assert_equal(ECHO_NESTED_STRUCT_RESPONSE_NIL, parse_responsexml(str))
356   end
357
358   def test_stub_echoNestedStruct
359     drv = SoapTestPortTypeRpcLit.new("http://localhost:#{Port}/")
360     drv.wiredump_dev = str = ''
361     drv.generate_explicit_type = false
362     # response contains only 1 part.
363     result = drv.echoNestedStruct(SOAPStructStruct.new("str", 1, 1.0, SOAPStruct.new("str", 1, 1.0)))[0]
364     assert_equal('str', result.varString)
365     assert_equal(1, result.varInt)
366     assert_equal(1.0, result.varFloat)
367     assert_equal('str', result.structItem.varString)
368     assert_equal(1, result.structItem.varInt)
369     assert_equal(1.0, result.structItem.varFloat)
370     assert_equal(ECHO_NESTED_STRUCT_REQUEST, parse_requestxml(str))
371     assert_equal(ECHO_NESTED_STRUCT_RESPONSE, parse_responsexml(str))
372   end
373
374   def test_stub_echoNestedStruct_nil
375     drv = SoapTestPortTypeRpcLit.new("http://localhost:#{Port}/")
376     drv.wiredump_dev = str = ''
377     drv.generate_explicit_type = false
378     # response contains only 1 part.
379     result = drv.echoNestedStruct(SOAPStructStruct.new("str", nil, 1.0, SOAPStruct.new("str", ::SOAP::SOAPNil.new, 1.0)))[0]
380     assert(result.respond_to?(:varInt))
381     assert(result.respond_to?(:varString))
382     assert_equal(ECHO_NESTED_STRUCT_REQUEST_NIL, parse_requestxml(str),
383       [ECHO_NESTED_STRUCT_REQUEST_NIL, parse_requestxml(str)].join("\n\n"))
384     assert_equal(ECHO_NESTED_STRUCT_RESPONSE_NIL, parse_responsexml(str))
385   end
386
387   ECHO_STRUCT_ARRAY_REQUEST =
388 %q[<?xml version="1.0" encoding="utf-8" ?>
389 <env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
390     xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
391     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
392   <env:Body>
393     <n1:echoStructArray xmlns:n1="http://soapbuilders.org/rpc-lit-test">
394       <inputStructArray xmlns:n2="http://soapbuilders.org/rpc-lit-test/types">
395         <n2:structItem>
396           <varString>str</varString>
397           <varInt>2</varInt>
398           <varFloat>+2.1</varFloat>
399         </n2:structItem>
400         <n2:structItem>
401           <varString>str</varString>
402           <varInt>2</varInt>
403           <varFloat>+2.1</varFloat>
404         </n2:structItem>
405       </inputStructArray>
406     </n1:echoStructArray>
407   </env:Body>
408 </env:Envelope>]
409
410   ECHO_STRUCT_ARRAY_RESPONSE =
411 %q[<?xml version="1.0" encoding="utf-8" ?>
412 <env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
413     xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
414     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
415   <env:Body>
416     <n1:echoStructArrayResponse xmlns:n1="http://soapbuilders.org/rpc-lit-test">
417       <n1:return xmlns:n2="http://soapbuilders.org/rpc-lit-test/types">
418         <n2:structItem>
419           <varString>str</varString>
420           <varInt>2</varInt>
421           <varFloat>+2.1</varFloat>
422         </n2:structItem>
423         <n2:structItem>
424           <varString>str</varString>
425           <varInt>2</varInt>
426           <varFloat>+2.1</varFloat>
427         </n2:structItem>
428       </n1:return>
429     </n1:echoStructArrayResponse>
430   </env:Body>
431 </env:Envelope>]
432
433   def test_wsdl_echoStructArray
434     wsdl = pathname('test-rpc-lit.wsdl')
435     @client = ::SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
436     @client.endpoint_url = "http://localhost:#{Port}/"
437     @client.wiredump_dev = str = ''
438     @client.generate_explicit_type = false
439     # response contains only 1 part.
440     e = SOAPStruct.new("str", 2, 2.1)
441     result = @client.echoStructArray(ArrayOfSOAPStruct[e, e])
442     assert_equal(ECHO_STRUCT_ARRAY_REQUEST, parse_requestxml(str),
443       [ECHO_STRUCT_ARRAY_REQUEST, parse_requestxml(str)].join("\n\n"))
444     assert_equal(ECHO_STRUCT_ARRAY_RESPONSE, parse_responsexml(str))
445   end
446
447   def test_stub_echoStructArray
448     drv = SoapTestPortTypeRpcLit.new("http://localhost:#{Port}/")
449     drv.wiredump_dev = str = ''
450     drv.generate_explicit_type = false
451     # response contains only 1 part.
452     e = SOAPStruct.new("str", 2, 2.1)
453     result = drv.echoStructArray(ArrayOfSOAPStruct[e, e])
454     assert_equal(ECHO_STRUCT_ARRAY_REQUEST, parse_requestxml(str))
455     assert_equal(ECHO_STRUCT_ARRAY_RESPONSE, parse_responsexml(str))
456   end
457
458   def parse_requestxml(str)
459     str.split(/\r?\n\r?\n/)[3]
460   end
461
462   def parse_responsexml(str)
463     str.split(/\r?\n\r?\n/)[6]
464   end
465 end
466
467
468 end; end
469
470 end
Note: See TracBrowser for help on using the browser.