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

root/trunk/test/wsdl/choice/test_choice.rb

Revision 1963, 9.4 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 'wsdl/parser'
3 require 'wsdl/soap/wsdl2ruby'
4 require 'soap/rpc/standaloneServer'
5 require 'soap/wsdlDriver'
6 require File.join(File.dirname(File.expand_path(__FILE__)), '..', '..', 'testutil.rb')
7
8
9 module WSDL; module Choice
10
11
12 class TestChoice < Test::Unit::TestCase
13   class Server < ::SOAP::RPC::StandaloneServer
14     Namespace = 'urn:choice'
15
16     def on_init
17       add_document_method(
18         self,
19         Namespace + ':echo',
20         'echo',
21         XSD::QName.new(Namespace, 'echoele'),
22         XSD::QName.new(Namespace, 'echo_response')
23       )
24       add_document_method(
25         self,
26         Namespace + ':echo_complex',
27         'echo_complex',
28         XSD::QName.new(Namespace, 'echoele_complex'),
29         XSD::QName.new(Namespace, 'echo_complex_response')
30       )
31       add_document_method(
32         self,
33         Namespace + ':echo_complex_emptyArrayAtFirst',
34         'echo_complex_emptyArrayAtFirst',
35         XSD::QName.new(Namespace, 'echoele_complex_emptyArrayAtFirst'),
36         XSD::QName.new(Namespace, 'echoele_complex_emptyArrayAtFirst')
37       )
38       @router.literal_mapping_registry = ChoiceMappingRegistry::LiteralRegistry
39     end
40  
41     def echo(arg)
42       arg
43     end
44
45     def echo_complex(arg)
46       Echo_complex_response.new(arg.data)
47     end
48
49     def echo_complex_emptyArrayAtFirst(arg)
50       arg
51     end
52   end
53
54   DIR = File.dirname(File.expand_path(__FILE__))
55
56   Port = 17171
57
58   def setup
59     setup_classdef
60     setup_server
61     @client = nil
62   end
63
64   def teardown
65     teardown_server if @server
66     unless $DEBUG
67       File.unlink(pathname('choice.rb'))
68       File.unlink(pathname('choiceMappingRegistry.rb'))
69       File.unlink(pathname('choiceDriver.rb'))
70     end
71     @client.reset_stream if @client
72   end
73
74   def setup_server
75     @server = Server.new('Test', Server::Namespace, '0.0.0.0', Port)
76     @server.level = Logger::Severity::ERROR
77     @server_thread = TestUtil.start_server_thread(@server)
78   end
79
80   def setup_classdef
81     gen = WSDL::SOAP::WSDL2Ruby.new
82     gen.location = pathname("choice.wsdl")
83     gen.basedir = DIR
84     gen.logger.level = Logger::FATAL
85     gen.opt['classdef'] = nil
86     gen.opt['mapping_registry'] = nil
87     gen.opt['module_path'] = self.class.to_s.sub(/::[^:]+$/, '')
88     gen.opt['driver'] = nil
89     gen.opt['force'] = true
90     gen.run
91     TestUtil.require(DIR, 'choiceDriver.rb', 'choiceMappingRegistry.rb', 'choice.rb')
92   end
93
94   def teardown_server
95     @server.shutdown
96     @server_thread.kill
97     @server_thread.join
98   end
99
100   def pathname(filename)
101     File.join(DIR, filename)
102   end
103
104   def test_wsdl
105     wsdl = File.join(DIR, 'choice.wsdl')
106     @client = ::SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
107     @client.endpoint_url = "http://localhost:#{Port}/"
108     @client.wiredump_dev = STDOUT if $DEBUG
109     @client.literal_mapping_registry = ChoiceMappingRegistry::LiteralRegistry
110
111     ret = @client.echo(Echoele.new(TerminalID.new("imei", nil)))
112     assert_equal("imei", ret.terminalID.imei)
113     assert_nil(ret.terminalID.devId)
114     ret = @client.echo(Echoele.new(TerminalID.new(nil, 'devId')))
115     assert_equal("devId", ret.terminalID.devId)
116     assert_nil(ret.terminalID.imei)
117   end
118
119   include ::SOAP
120   def test_naive
121     @client = ::SOAP::RPC::Driver.new("http://localhost:#{Port}/")
122     @client.add_document_method('echo', 'urn:choice:echo',
123       XSD::QName.new('urn:choice', 'echoele'),
124       XSD::QName.new('urn:choice', 'echo_response'))
125     @client.wiredump_dev = STDOUT if $DEBUG
126     @client.literal_mapping_registry = ChoiceMappingRegistry::LiteralRegistry
127
128     echo = SOAPElement.new('echoele')
129     echo.add(terminalID = SOAPElement.new('terminalID'))
130     terminalID.add(SOAPElement.new('imei', 'imei'))
131     ret = @client.echo(echo)
132     assert_equal("imei", ret.terminalID.imei)
133     assert_nil(ret.terminalID.devId)
134
135     echo = SOAPElement.new('echoele')
136     echo.add(terminalID = SOAPElement.new('terminalID'))
137     terminalID.add(SOAPElement.new('devId', 'devId'))
138     ret = @client.echo(echo)
139     assert_equal("devId", ret.terminalID.devId)
140     assert_nil(ret.terminalID.imei)
141   end
142
143   def test_wsdl_with_map_complex
144     wsdl = File.join(DIR, 'choice.wsdl')
145     @client = ::SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
146     @client.endpoint_url = "http://localhost:#{Port}/"
147     @client.wiredump_dev = STDOUT if $DEBUG
148     do_test_with_map_complex(@client)
149   end
150
151   def test_wsdl_with_stub_complex
152     wsdl = File.join(DIR, 'choice.wsdl')
153     @client = ::SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
154     @client.endpoint_url = "http://localhost:#{Port}/"
155     @client.wiredump_dev = STDOUT if $DEBUG
156     @client.literal_mapping_registry = ChoiceMappingRegistry::LiteralRegistry
157     do_test_with_stub_complex(@client)
158   end
159
160   def test_naive_with_map_complex
161     @client = ::SOAP::RPC::Driver.new("http://localhost:#{Port}/")
162     @client.add_document_method('echo_complex', 'urn:choice:echo_complex',
163       XSD::QName.new('urn:choice', 'echoele_complex'),
164       XSD::QName.new('urn:choice', 'echo_complex_response'))
165     @client.wiredump_dev = STDOUT if $DEBUG
166     do_test_with_map_complex(@client)
167   end
168
169   def test_naive_with_stub_complex
170     @client = ::SOAP::RPC::Driver.new("http://localhost:#{Port}/")
171     @client.add_document_method('echo_complex', 'urn:choice:echo_complex',
172       XSD::QName.new('urn:choice', 'echoele_complex'),
173       XSD::QName.new('urn:choice', 'echo_complex_response'))
174     @client.wiredump_dev = STDOUT if $DEBUG
175     @client.literal_mapping_registry = ChoiceMappingRegistry::LiteralRegistry
176     do_test_with_stub_complex(@client)
177   end
178
179   def do_test_with_map_complex(client)
180     req = {
181       :data => {
182         :A => "A",
183         :B1 => "B1",
184         :C1 => "C1",
185         :C2 => "C2"
186       }
187     }
188     ret = client.echo_complex(req)
189     assert_equal("A", ret.data["A"])
190     assert_equal("B1", ret.data["B1"])
191     assert_equal(nil, ret.data["B2a"])
192     assert_equal(nil, ret.data["B2b"])
193     assert_equal(nil, ret.data["B3a"])
194     assert_equal(nil, ret.data["B3b"])
195     assert_equal("C1", ret.data["C1"])
196     assert_equal("C2", ret.data["C2"])
197     #
198     req = {
199       :data => {
200         :A => "A",
201         :B2a => "B2a",
202         :B2b => "B2b",
203         :C1 => "C1",
204         :C2 => "C2"
205       }
206     }
207     ret = client.echo_complex(req)
208     assert_equal("A", ret.data["A"])
209     assert_equal(nil, ret.data["B1"])
210     assert_equal("B2a", ret.data["B2a"])
211     assert_equal("B2b", ret.data["B2b"])
212     assert_equal(nil, ret.data["B3a"])
213     assert_equal(nil, ret.data["B3b"])
214     assert_equal("C1", ret.data["C1"])
215     assert_equal("C2", ret.data["C2"])
216     #
217     req = {
218       :data => {
219         :A => "A",
220         :B3a => "B3a",
221         :C1 => "C1",
222         :C2 => "C2"
223       }
224     }
225     ret = client.echo_complex(req)
226     assert_equal("A", ret.data["A"])
227     assert_equal(nil, ret.data["B1"])
228     assert_equal(nil, ret.data["B2a"])
229     assert_equal(nil, ret.data["B2b"])
230     assert_equal("B3a", ret.data["B3a"])
231     assert_equal(nil, ret.data["B3b"])
232     assert_equal("C1", ret.data["C1"])
233     assert_equal("C2", ret.data["C2"])
234     #
235     req = {
236       :data => {
237         :A => "A",
238         :B3b => "B3b",
239         :C1 => "C1",
240         :C2 => "C2"
241       }
242     }
243     ret = client.echo_complex(req)
244     assert_equal("A", ret.data["A"])
245     assert_equal(nil, ret.data["B1"])
246     assert_equal(nil, ret.data["B2a"])
247     assert_equal(nil, ret.data["B2b"])
248     assert_equal(nil, ret.data["B3a"])
249     assert_equal("B3b", ret.data["B3b"])
250     assert_equal("C1", ret.data["C1"])
251     assert_equal("C2", ret.data["C2"])
252   end
253
254   def do_test_with_stub_complex(client)
255     ret = client.echo_complex(Echoele_complex.new(Andor.new("A", "B1", nil, nil, nil, nil, "C1", "C2")))
256     assert_equal("A", ret.data.a)
257     assert_equal("B1", ret.data.b1)
258     assert_equal(nil, ret.data.b2a)
259     assert_equal(nil, ret.data.b2b)
260     assert_equal(nil, ret.data.b3a)
261     assert_equal(nil, ret.data.b3b)
262     assert_equal("C1", ret.data.c1)
263     assert_equal("C2", ret.data.c2)
264     #
265     ret = client.echo_complex(Echoele_complex.new(Andor.new("A", nil, "B2a", "B2b", nil, nil, "C1", "C2")))
266     assert_equal("A", ret.data.a)
267     assert_equal(nil, ret.data.b1)
268     assert_equal("B2a", ret.data.b2a)
269     assert_equal("B2b", ret.data.b2b)
270     assert_equal(nil, ret.data.b3a)
271     assert_equal(nil, ret.data.b3b)
272     assert_equal("C1", ret.data.c1)
273     assert_equal("C2", ret.data.c2)
274     #
275     ret = client.echo_complex(Echoele_complex.new(Andor.new("A", nil, nil, nil, "B3a", nil, "C1", "C2")))
276     assert_equal("A", ret.data.a)
277     assert_equal(nil, ret.data.b1)
278     assert_equal(nil, ret.data.b2a)
279     assert_equal(nil, ret.data.b2b)
280     assert_equal("B3a", ret.data.b3a)
281     assert_equal(nil, ret.data.b3b)
282     assert_equal("C1", ret.data.c1)
283     assert_equal("C2", ret.data.c2)
284     #
285     ret = client.echo_complex(Echoele_complex.new(Andor.new("A", nil, nil, nil, nil, "B3b", "C1", "C2")))
286     assert_equal("A", ret.data.a)
287     assert_equal(nil, ret.data.b1)
288     assert_equal(nil, ret.data.b2a)
289     assert_equal(nil, ret.data.b2b)
290     assert_equal(nil, ret.data.b3a)
291     assert_equal("B3b", ret.data.b3b)
292     assert_equal("C1", ret.data.c1)
293     assert_equal("C2", ret.data.c2)
294   end
295
296   def test_stub_emptyArrayAtFirst
297     @client = Choice_porttype.new("http://localhost:#{Port}/")
298     @client.wiredump_dev = STDOUT if $DEBUG
299     #
300     arg = EmptyArrayAtFirst.new
301     arg.b1 = "b1"
302     ret = @client.echo_complex_emptyArrayAtFirst(Echoele_complex_emptyArrayAtFirst.new(arg))
303     assert_nil(ret.data.a)
304     assert_equal("b1", ret.data.b1)
305     assert_nil(ret.data.b2)
306   end
307 end
308
309
310 end; end
Note: See TracBrowser for help on using the browser.