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

root/trunk/test/wsdl/soaptype/test_soaptype.rb

Revision 1963, 4.8 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 RPC
10
11
12 class TestSOAPTYPE < Test::Unit::TestCase
13   include ::SOAP
14
15   class Server < ::SOAP::RPC::StandaloneServer
16     include ::SOAP
17
18     def on_init
19       #self.generate_explicit_type = false
20       add_rpc_method(self, 'echo_soaptype', 'arg')
21     end
22  
23     def echo_soaptype(arg)
24       res = Wrapper.new
25       res.short = SOAPShort.new(arg.short)
26       res.long = SOAPLong.new(arg.long)
27       res.double = SOAPFloat.new(arg.double)
28       res
29     end
30   end
31
32   DIR = File.dirname(File.expand_path(__FILE__))
33
34   Port = 17171
35
36   def setup
37     setup_server
38     setup_classdef
39     @client = nil
40   end
41
42   def teardown
43     teardown_server if @server
44     unless $DEBUG
45       File.unlink(pathname('echo.rb'))
46       File.unlink(pathname('echoMappingRegistry.rb'))
47       File.unlink(pathname('echoDriver.rb'))
48     end
49     @client.reset_stream if @client
50   end
51
52   def setup_server
53     @server = Server.new('Test', "urn:soaptype", '0.0.0.0', Port)
54     @server.level = Logger::Severity::ERROR
55     @server_thread = TestUtil.start_server_thread(@server)
56   end
57
58   def setup_classdef
59     gen = WSDL::SOAP::WSDL2Ruby.new
60     gen.location = pathname("soaptype.wsdl")
61     gen.basedir = DIR
62     gen.logger.level = Logger::FATAL
63     gen.opt['classdef'] = nil
64     gen.opt['mapping_registry'] = nil
65     gen.opt['driver'] = nil
66     gen.opt['force'] = true
67     gen.opt['module_path'] = self.class.to_s.sub(/::[^:]+$/, '')
68     gen.run
69     TestUtil.require(DIR, 'echo.rb', 'echoMappingRegistry.rb', 'echoDriver.rb')
70   end
71
72   def teardown_server
73     @server.shutdown
74     @server_thread.kill
75     @server_thread.join
76   end
77
78   def pathname(filename)
79     File.join(DIR, filename)
80   end
81
82 SOAPTYPE_WSDL_XML = %q[<?xml version="1.0" encoding="utf-8" ?>
83 <env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
84     xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
85     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
86   <env:Body>
87     <n1:echo_soaptype xmlns:n1="urn:soaptype"
88         env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
89       <arg xmlns:n2="urn:soaptype-type"
90           xsi:type="n2:wrapper">
91         <short xsi:type="xsd:short">123</short>
92         <long xsi:type="xsd:long">456</long>
93         <double xsi:type="xsd:double">+789</double>
94       </arg>
95     </n1:echo_soaptype>
96   </env:Body>
97 </env:Envelope>]
98
99 SOAPTYPE_NATIVE_XML = %q[<?xml version="1.0" encoding="utf-8" ?>
100 <env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
101     xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
102     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
103   <env:Body>
104     <n1:echo_soaptype xmlns:n1="urn:soaptype"
105         env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
106       <arg xsi:type="xsd:anyType">
107         <short xsi:type="xsd:short">123</short>
108         <long xsi:type="xsd:long">456</long>
109         <double xsi:type="xsd:double">+789</double>
110       </arg>
111     </n1:echo_soaptype>
112   </env:Body>
113 </env:Envelope>]
114
115   def test_wsdl
116     wsdl = File.join(DIR, 'soaptype.wsdl')
117     @client = ::SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
118     @client.endpoint_url = "http://localhost:#{Port}/"
119     @client.wiredump_dev = str = ''
120
121     arg = Wrapper.new
122     arg.short = 123
123     arg.long = 456
124     arg.double = 789
125     res = @client.echo_soaptype(arg)
126
127     assert_equal(123, res.short)
128     assert_equal(456, res.long)
129     assert_equal(789.0, res.double)
130
131     assert_equal(SOAPTYPE_WSDL_XML, parse_requestxml(str))
132   end
133
134   def test_stub
135     @client = WSDL::RPC::Echo_port_type.new("http://localhost:#{Port}/")
136     @client.wiredump_dev = str = ''
137
138     arg = WSDL::RPC::Wrapper.new
139     arg.short = 123
140     arg.long = 456
141     arg.double = 789
142     res = @client.echo_soaptype(arg)
143
144     assert_equal(123, res.short)
145     assert_equal(456, res.long)
146     assert_equal(789.0, res.double)
147
148     assert_equal(SOAPTYPE_WSDL_XML, parse_requestxml(str))
149   end
150
151   def test_native
152     @client = ::SOAP::RPC::Driver.new("http://localhost:#{Port}/", 'urn:soaptype')
153     @client.endpoint_url = "http://localhost:#{Port}/"
154     @client.add_method('echo_soaptype', 'arg')
155     @client.wiredump_dev = str = ''
156     @client.mapping_registry = WSDL::RPC::EchoMappingRegistry::EncodedRegistry
157     @client.literal_mapping_registry = WSDL::RPC::EchoMappingRegistry::LiteralRegistry
158
159     arg = ::Struct.new(:short, :long, :double).new
160     arg.short = SOAPShort.new(123)
161     arg.long = SOAPLong.new(456)
162     arg.double = SOAPDouble.new(789)
163     res = @client.echo_soaptype(arg)
164
165     assert_equal(123, res.short)
166     assert_equal(456, res.long)
167     assert_equal(789.0, res.double)
168
169     assert_equal(SOAPTYPE_NATIVE_XML, parse_requestxml(str))
170   end
171
172   def parse_requestxml(str)
173     str.split(/\r?\n\r?\n/)[3]
174   end
175 end
176
177
178 end; end
Note: See TracBrowser for help on using the browser.