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

root/trunk/test/wsdl/document/test_number.rb

Revision 1963, 2.1 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 Document
10
11
12 class TestNumber < Test::Unit::TestCase
13   class Server < ::SOAP::RPC::StandaloneServer
14     Namespace = 'urn:foo'
15
16     def on_init
17       add_document_method(
18         self,
19         Namespace + ':get_foo',
20         'get_foo',
21         XSD::QName.new(Namespace, 'get_foo'),
22         XSD::QName.new(Namespace, 'get_foo_response')
23       )
24     end
25  
26     def get_foo(arg)
27       arg.number
28     end
29   end
30
31   DIR = File.dirname(File.expand_path(__FILE__))
32   Port = 17171
33
34   def setup
35     setup_server
36     setup_classdef
37     @client = nil
38   end
39
40   def teardown
41     teardown_server if @server
42     File.unlink(pathname('foo.rb'))
43     @client.reset_stream if @client
44   end
45
46   def setup_server
47     @server = Server.new('Test', "urn:rpc", '0.0.0.0', Port)
48     @server.level = Logger::Severity::ERROR
49     @server_thread = TestUtil.start_server_thread(@server)
50   end
51
52   def setup_classdef
53     gen = WSDL::SOAP::WSDL2Ruby.new
54     gen.location = pathname("number.wsdl")
55     gen.basedir = DIR
56     gen.logger.level = Logger::FATAL
57     gen.opt['classdef'] = nil
58     gen.opt['force'] = true
59     gen.run
60     TestUtil.require(DIR, 'foo.rb')
61   end
62
63   def teardown_server
64     @server.shutdown
65     @server_thread.kill
66     @server_thread.join
67   end
68
69   def pathname(filename)
70     File.join(DIR, filename)
71   end
72
73   def test_wsdl
74     wsdl = File.join(DIR, 'number.wsdl')
75     @client = ::SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
76     @client.endpoint_url = "http://localhost:#{Port}/"
77     @client.wiredump_dev = STDOUT if $DEBUG
78
79     # with the Struct defined in foo.rb, which is generated from WSDL
80     assert_equal("12345", @client.get_foo(Get_foo.new("12345")))
81
82     # with Hash
83     assert_equal("12345", @client.get_foo({:number => "12345"}))
84
85     # with Original struct
86     get_foo_struct = Struct.new(:number)
87     assert_equal("12345", @client.get_foo(get_foo_struct.new("12345")))
88   end
89 end
90
91
92 end; end
Note: See TracBrowser for help on using the browser.