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

root/trunk/test/wsdl/overload/test_overload.rb

Revision 2006, 3.4 kB (checked in by nahi, 1 year ago)
  • update tests for the previous change ('in' -> :in)
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 Overload
10
11
12 class TestOverload < Test::Unit::TestCase
13   TNS = "urn:overload"
14
15   Methods = [
16     [
17       XSD::QName.new(TNS, 'methodAlpha'), "methodAlpha1", "method_alpha_1",
18       [ [:in, "in0", ["::SOAP::SOAPString"]],
19         [:in, "in1", ["::SOAP::SOAPString"]],
20         [:in, "in2", ["::SOAP::SOAPString"]],
21         [:retval, "methodAlphaReturn", ["::SOAP::SOAPLong"]] ]
22     ],
23     [
24       XSD::QName.new(TNS, 'methodAlpha'), "methodAlpha2", "method_alpha_2",
25       [ [:in, "in0", ["::SOAP::SOAPString"]],
26         [:in, "in1", ["::SOAP::SOAPString"]],
27         [:retval, "methodAlphaReturn", ["::SOAP::SOAPLong"]] ]
28     ]
29   ]
30
31   class Server < ::SOAP::RPC::StandaloneServer
32     def on_init
33       TestOverload::Methods.each do |definition|
34         add_rpc_operation(self, *definition)
35       end
36     end
37  
38     def method_alpha_1(in0, in1, in2)
39       3
40     end
41  
42     def method_alpha_2(in0, in1)
43       2
44     end
45   end
46
47   DIR = File.dirname(File.expand_path(__FILE__))
48
49   Port = 17171
50
51   def setup
52     setup_server
53     setup_classdef
54     @client = nil
55   end
56
57   def teardown
58     teardown_server if @server
59     unless $DEBUG
60       File.unlink(pathname('default.rb'))
61       File.unlink(pathname('defaultMappingRegistry.rb'))
62       File.unlink(pathname('defaultDriver.rb'))
63       File.unlink(pathname('defaultServant.rb'))
64       File.unlink(pathname('OverloadServiceClient.rb'))
65     end
66     @client.reset_stream if @client
67   end
68
69   def setup_server
70     @server = Server.new('Test', "urn:rpc", '0.0.0.0', Port)
71     @server.level = Logger::Severity::ERROR
72     @server_thread = TestUtil.start_server_thread(@server)
73   end
74
75   def setup_classdef
76     gen = WSDL::SOAP::WSDL2Ruby.new
77     gen.location = pathname("overload.wsdl")
78     gen.basedir = DIR
79     gen.logger.level = Logger::FATAL
80     gen.opt['classdef'] = nil
81     gen.opt['mapping_registry'] = nil
82     gen.opt['driver'] = nil
83     gen.opt['servant_skelton'] = nil
84     gen.opt['client_skelton'] = nil
85     gen.opt['force'] = true
86     gen.run
87     TestUtil.require(DIR, 'default.rb')
88   end
89
90   def teardown_server
91     @server.shutdown
92     @server_thread.kill
93     @server_thread.join
94   end
95
96   def pathname(filename)
97     File.join(DIR, filename)
98   end
99
100   def test_compare
101     compare("expectedDriver.rb", "defaultDriver.rb")
102     compare("expectedServant.rb", "defaultServant.rb")
103     compare("expectedClient.rb", "OverloadServiceClient.rb")
104   end
105
106   def test_wsdl
107     wsdl = File.join(DIR, 'overload.wsdl')
108     @client = ::SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
109     @client.endpoint_url = "http://localhost:#{Port}/"
110     @client.wiredump_dev = STDOUT if $DEBUG
111     assert_equal(3, @client.call("methodAlpha1", "1", "2", "3"))
112     assert_equal(2, @client.call("methodAlpha2", "1", "2"))
113   end
114
115   def test_native
116     @client = ::SOAP::RPC::Driver.new("http://localhost:#{Port}/")
117     Methods.each do |definition|
118       @client.add_rpc_operation(*definition)
119     end
120     @client.wiredump_dev = STDOUT if $DEBUG
121     assert_equal(3, @client.call("methodAlpha1", "1", "2", "3"))
122     assert_equal(2, @client.call("methodAlpha2", "1", "2"))
123   end
124
125   def compare(expected, actual)
126     TestUtil.filecompare(pathname(expected), pathname(actual))
127   end
128 end
129
130
131 end; end
Note: See TracBrowser for help on using the browser.