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

root/trunk/test/wsdl/list/test_list.rb

Revision 1963, 3.3 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 List
10
11
12 class TestList < Test::Unit::TestCase
13   class Server < ::SOAP::RPC::StandaloneServer
14     Namespace = 'urn:list'
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     end
25  
26     def echo(arg)
27       arg
28     end
29   end
30
31   DIR = File.dirname(File.expand_path(__FILE__))
32
33   Port = 17171
34
35   def setup
36     setup_server
37     setup_classdef
38     @client = nil
39   end
40
41   def teardown
42     teardown_server if @server
43     File.unlink(pathname('list.rb')) unless $DEBUG
44     File.unlink(pathname('listMappingRegistry.rb')) unless $DEBUG
45     File.unlink(pathname('listDriver.rb')) unless $DEBUG
46     @client.reset_stream if @client
47   end
48
49   def setup_server
50     @server = Server.new('Test', Server::Namespace, '0.0.0.0', Port)
51     @server.level = Logger::Severity::ERROR
52     @server_thread = TestUtil.start_server_thread(@server)
53   end
54
55   def setup_classdef
56     gen = WSDL::SOAP::WSDL2Ruby.new
57     gen.location = pathname("list.wsdl")
58     gen.basedir = DIR
59     gen.logger.level = Logger::FATAL
60     gen.opt['module_path'] = self.class.to_s.sub(/::[^:]+$/, '')
61     gen.opt['classdef'] = nil
62     gen.opt['mapping_registry'] = nil
63     gen.opt['driver'] = nil
64     gen.opt['force'] = true
65     gen.run
66     TestUtil.require(DIR, 'listDriver.rb', 'listMappingRegistry.rb', 'list.rb')
67   end
68
69   def teardown_server
70     @server.shutdown
71     @server_thread.kill
72     @server_thread.join
73   end
74
75   def pathname(filename)
76     File.join(DIR, filename)
77   end
78
79   def test_wsdl
80     wsdl = File.join(DIR, 'list.wsdl')
81     @client = ::SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
82     @client.endpoint_url = "http://localhost:#{Port}/"
83     @client.wiredump_dev = STDOUT if $DEBUG
84     e1 = Langlistinline.new([Langlistinline::Inlineruby,
85       Langlistinline::Inlineperl])
86     e2 = Langlist.new([Language::Python, Language::Smalltalk])
87     ret = @client.echo(Echoele.new(e1, e2))
88     # in the future...
89     #   assert_equal(e1, ret.e1)
90     #   assert_equal(e2, ret.e2)
91     assert_equal(e1.join(" "), ret.e1)
92     assert_equal(e2.join(" "), ret.e2)
93   end
94
95   def test_naive
96     @client = List_porttype.new("http://localhost:#{Port}/")
97     @client.wiredump_dev = STDOUT if $DEBUG
98     e1 = Langlistinline.new([Langlistinline::Inlineruby,
99       Langlistinline::Inlineperl])
100     e2 = Langlist.new([Language::Python, Language::Smalltalk])
101     ret = @client.echo(Echoele.new(e1, e2))
102     # in the future...
103     #   assert_equal(e1, ret.e1)
104     #   assert_equal(e2, ret.e2)
105     assert_equal(e1.join(" "), ret.e1)
106     assert_equal(e2.join(" "), ret.e2)
107   end
108
109   def test_string_as_a_value
110     @client = List_porttype.new("http://localhost:#{Port}/")
111     @client.wiredump_dev = STDOUT if $DEBUG
112     e1 = ['inlineruby', 'inlineperl']
113     e2 = 'python smalltalk'
114     ret = @client.echo(Echoele.new(e1, e2))
115     # in the future...
116     #   assert_equal(e1, ret.e1)
117     #   assert_equal(e2, ret.e2)
118     assert_equal(e1.join(" "), ret.e1)
119     assert_equal(e2, ret.e2)
120   end
121 end
122
123
124 end; end
Note: See TracBrowser for help on using the browser.