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

root/trunk/test/wsdl/simpletype/test_simpletype.rb

Revision 1963, 2.2 kB (checked in by nahi, 1 year ago)
  • update tests. do not crash at teardown when setup failed. closes #396.
  • Property svn:eol-style set to native
  • Property svn:keywords set to author date id revision
Line 
1 require 'test/unit'
2 require 'soap/rpc/standaloneServer'
3 require 'soap/wsdlDriver'
4 require File.join(File.dirname(File.expand_path(__FILE__)), '..', '..', 'testutil.rb')
5
6
7 module WSDL
8 module SimpleType
9
10
11 class TestSimpleType < Test::Unit::TestCase
12   class Server < ::SOAP::RPC::StandaloneServer
13     def on_init
14       add_document_method(self, 'urn:example.com:simpletype:ping', 'ping',
15         XSD::QName.new('urn:example.com:simpletype', 'ruby'),
16         XSD::QName.new('http://www.w3.org/2001/XMLSchema', 'string'))
17       add_document_method(self, 'urn:example.com:simpletype:ping_id', 'ping_id',
18         XSD::QName.new('urn:example.com:simpletype', 'myid'),
19         XSD::QName.new('urn:example.com:simpletype', 'myid'))
20     end
21  
22     def ping(ruby)
23       version = ruby["myversion"]
24       date = ruby["date"]
25       "#{version} (#{date})"
26     end
27
28     def ping_id(id)
29       id
30     end
31   end
32
33   DIR = File.dirname(File.expand_path(__FILE__))
34
35   Port = 17171
36
37   def setup
38     setup_server
39     setup_client
40   end
41
42   def setup_server
43     @server = Server.new('Test', "urn:example.com:simpletype", '0.0.0.0', Port)
44     @server.level = Logger::Severity::ERROR
45     @server_thread = TestUtil.start_server_thread(@server)
46   end
47
48   def setup_client
49     wsdl = File.join(DIR, 'simpletype.wsdl')
50     @client = ::SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
51     @client.endpoint_url = "http://localhost:#{Port}/"
52     @client.generate_explicit_type = false
53     @client.wiredump_dev = STDOUT if $DEBUG
54   end
55
56   def teardown
57     teardown_server if @server
58     teardown_client if @client
59   end
60
61   def teardown_server
62     @server.shutdown
63     @server_thread.kill
64     @server_thread.join
65   end
66
67   def teardown_client
68     @client.reset_stream
69   end
70
71   def test_ping
72     ret = @client.ping({:myversion => "1.9", :date => "2004-01-01T00:00:00Z"})
73     assert_equal("1.9 (2004-01-01T00:00:00Z)", ret)
74   end
75
76   def test_ping_id
77     ret = @client.ping_id("012345678901234567")
78     assert_equal("012345678901234567", ret)
79     # length
80     assert_raise(XSD::ValueSpaceError) do
81       @client.ping_id("0123456789012345678")
82     end
83     # pattern
84     assert_raise(XSD::ValueSpaceError) do
85       @client.ping_id("01234567890123456;")
86     end
87   end
88 end
89
90
91 end
92 end
Note: See TracBrowser for help on using the browser.