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

root/trunk/test/wsdl/any/test_any.rb

Revision 2006, 5.7 kB (checked in by nahi, 1 year ago)
  • update tests for the previous change ('in' -> :in)
  • Property svn:eol-style set to native
  • Property svn:keywords set to author date id revision
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 Any
10
11
12 class TestAny < Test::Unit::TestCase
13   Namespace = 'urn:example.com:echo'
14   TypeNamespace = 'urn:example.com:echo-type'
15
16   class Server < ::SOAP::RPC::StandaloneServer
17     def on_init
18       # use WSDL to serialize/deserialize
19       wsdlfile = File.join(DIR, 'any.wsdl')
20       wsdl = WSDL::Importer.import(wsdlfile)
21       port = wsdl.services[0].ports[0]
22       wsdl_elements = wsdl.collect_elements
23       wsdl_types = wsdl.collect_complextypes + wsdl.collect_simpletypes
24       rpc_decode_typemap = wsdl_types +
25         wsdl.soap_rpc_complextypes(port.find_binding)
26       @router.mapping_registry =
27         ::SOAP::Mapping::WSDLEncodedRegistry.new(rpc_decode_typemap)
28       @router.literal_mapping_registry =
29         ::SOAP::Mapping::WSDLLiteralRegistry.new(wsdl_types, wsdl_elements)
30       # add method
31       add_document_method(
32         self,
33         Namespace + ':echo',
34         'echo',
35         XSD::QName.new(TypeNamespace, 'foo.bar'),
36         XSD::QName.new(TypeNamespace, 'foo.bar')
37       )
38       add_rpc_operation(self,
39         XSD::QName.new("urn:example.com:echo", "echoAny"),
40         "urn:example.com:echoAny",
41         "echoAny",
42         [ [:retval, "echoany_return", [XSD::QName.new("http://www.w3.org/2001/XMLSchema", "anyType")]] ],
43         { :request_style =>  :rpc, :request_use =>  :encoded,
44           :response_style => :rpc, :response_use => :encoded,
45           :faults => {} }
46       )
47     end
48  
49     def echo(arg)
50       res = FooBar.new(arg.before, arg.after)
51       res.set_any([
52         ::SOAP::SOAPElement.new("foo", "bar"),
53         ::SOAP::SOAPElement.new("baz", "qux")
54       ])
55       res
56       # TODO: arg
57     end
58
59     AnyStruct = Struct.new(:a, :b)
60     def echoAny
61       AnyStruct.new(1, Time.mktime(2007, 1, 1))
62     end
63   end
64
65   DIR = File.dirname(File.expand_path(__FILE__))
66
67   Port = 17171
68
69   def setup
70     setup_server
71     setup_classdef
72     @client = nil
73   end
74
75   def teardown
76     teardown_server if @server
77     unless $DEBUG
78       File.unlink(pathname('echo.rb')) if File.exist?(pathname('echo.rb'))
79       File.unlink(pathname('echoMappingRegistry.rb')) if File.exist?(pathname('echoMappingRegistry.rb'))
80       File.unlink(pathname('echoDriver.rb')) if File.exist?(pathname('echoDriver.rb'))
81       File.unlink(pathname('echoServant.rb')) if File.exist?(pathname('echoServant.rb'))
82       File.unlink(pathname('echo_service.rb')) if File.exist?(pathname('echo_service.rb'))
83       File.unlink(pathname('echo_serviceClient.rb')) if File.exist?(pathname('echo_serviceClient.rb'))
84     end
85     @client.reset_stream if @client
86   end
87
88   def setup_server
89     @server = Server.new('Test', Namespace, '0.0.0.0', Port)
90     @server.level = Logger::Severity::ERROR
91     @server_thread = TestUtil.start_server_thread(@server)
92   end
93
94   def setup_classdef
95     gen = WSDL::SOAP::WSDL2Ruby.new
96     gen.location = pathname("any.wsdl")
97     gen.basedir = DIR
98     gen.logger.level = Logger::FATAL
99     gen.opt['classdef'] = nil
100     gen.opt['mapping_registry'] = nil
101     gen.opt['module_path'] = self.class.to_s.sub(/::[^:]+$/, '')
102     gen.opt['driver'] = nil
103     gen.opt['force'] = true
104     gen.run
105     TestUtil.require(DIR, 'echoDriver.rb', 'echoMappingRegistry.rb', 'echo.rb')
106   end
107
108   def teardown_server
109     @server.shutdown
110     @server_thread.kill
111     @server_thread.join
112   end
113
114   def pathname(filename)
115     File.join(DIR, filename)
116   end
117
118   def test_any
119     gen = WSDL::SOAP::WSDL2Ruby.new
120     gen.location = pathname("any.wsdl")
121     gen.basedir = DIR
122     gen.logger.level = Logger::FATAL
123     gen.opt['module_path'] = self.class.to_s.sub(/::[^:]+$/, '')
124     gen.opt['classdef'] = nil
125     gen.opt['mapping_registry'] = nil
126     gen.opt['driver'] = nil
127     gen.opt['client_skelton'] = nil
128     gen.opt['servant_skelton'] = nil
129     gen.opt['standalone_server_stub'] = nil
130     gen.opt['force'] = true
131     TestUtil.silent do
132       gen.run
133     end
134     compare("expectedEcho.rb", "echo.rb")
135     compare("expectedMappingRegistry.rb", "echoMappingRegistry.rb")
136     compare("expectedDriver.rb", "echoDriver.rb")
137     compare("expectedService.rb", "echo_service.rb")
138   end
139
140   def compare(expected, actual)
141     TestUtil.filecompare(pathname(expected), pathname(actual))
142   end
143
144   def test_anyreturl_wsdl
145     wsdl = File.join(DIR, 'any.wsdl')
146     @client = ::SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
147     @client.endpoint_url = "http://localhost:#{Port}/"
148     @client.wiredump_dev = STDOUT if $DEBUG
149     res = @client.echoAny
150     assert_equal(1, res.a)
151     assert_equal(2007, res.b.year)
152   end
153
154   def test_wsdl
155     wsdl = File.join(DIR, 'any.wsdl')
156     @client = ::SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
157     @client.endpoint_url = "http://localhost:#{Port}/"
158     @client.wiredump_dev = STDOUT if $DEBUG
159     arg = FooBar.new("before", "after")
160     arg.set_any(
161       [
162         ::SOAP::SOAPElement.new("foo", "bar"),
163         ::SOAP::SOAPElement.new("baz", "qux")
164       ]
165     )
166     res = @client.echo(arg)
167     assert_equal(arg.before, res.before)
168     assert_equal("bar", res.foo)
169     assert_equal("qux", res.baz)
170     assert_equal(arg.after, res.after)
171   end
172
173   def test_naive
174     @client = Echo_port_type.new
175     @client.endpoint_url = "http://localhost:#{Port}/"
176     @client.wiredump_dev = STDOUT if $DEBUG
177     arg = FooBar.new("before", "after")
178     arg.set_any(
179       [
180         ::SOAP::SOAPElement.new("foo", "bar"),
181         ::SOAP::SOAPElement.new("baz", "qux")
182       ]
183     )
184     res = @client.echo(arg)
185     assert_equal(arg.before, res.before)
186     assert_equal("bar", res.foo)
187     assert_equal("qux", res.baz)
188     assert_equal(arg.after, res.after)
189   end
190 end
191
192
193 end; end
Note: See TracBrowser for help on using the browser.