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

root/trunk/test/wsdl/group/test_rpc.rb

Revision 1963, 3.8 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 Group
10
11
12 class TestGroup < Test::Unit::TestCase
13   class Server < ::SOAP::RPC::StandaloneServer
14     Namespace = 'urn:group'
15     TypeNamespace = 'urn:grouptype'
16
17     def on_init
18       add_document_method(
19         self,
20         Namespace + ':echo',
21         'echo',
22         XSD::QName.new(TypeNamespace, 'groupele'),
23         XSD::QName.new(TypeNamespace, 'groupele')
24       )
25       self.literal_mapping_registry = EchoMappingRegistry::LiteralRegistry
26     end
27  
28     def echo(arg)
29       # arg
30       # need to convert for 'any'
31       ret = Groupele_type.new(arg.comment, arg.element, arg.eletype, arg.var)
32       ret.xmlattr_attr_max = arg.xmlattr_attr_max
33       ret.xmlattr_attr_min = arg.xmlattr_attr_min
34       ret.set_any([::SOAP::SOAPElement.new("foo", arg.foo)])
35       ret
36     end
37   end
38
39   DIR = File.dirname(File.expand_path(__FILE__))
40
41   Port = 17171
42
43   def setup
44     setup_classdef
45     setup_server
46     @client = nil
47   end
48
49   def teardown
50     teardown_server if @server
51     File.unlink(pathname('echo.rb')) unless $DEBUG
52     File.unlink(pathname('echoMappingRegistry.rb')) unless $DEBUG
53     File.unlink(pathname('echoDriver.rb')) unless $DEBUG
54     @client.reset_stream if @client
55   end
56
57   def setup_server
58     @server = Server.new('Test', "urn:group", '0.0.0.0', Port)
59     @server.level = Logger::Severity::ERROR
60     @server_thread = TestUtil.start_server_thread(@server)
61   end
62
63   def setup_classdef
64     gen = WSDL::SOAP::WSDL2Ruby.new
65     gen.location = pathname("group.wsdl")
66     gen.basedir = DIR
67     gen.logger.level = Logger::FATAL
68     gen.opt['classdef'] = nil
69     gen.opt['mapping_registry'] = nil
70     gen.opt['driver'] = nil
71     gen.opt['module_path'] = self.class.to_s.sub(/::[^:]+$/, '')
72     gen.opt['force'] = true
73     gen.run
74     TestUtil.require(DIR, 'echoDriver.rb', 'echoMappingRegistry.rb', 'echo.rb')
75   end
76
77   def teardown_server
78     @server.shutdown
79     @server_thread.kill
80     @server_thread.join
81   end
82
83   def pathname(filename)
84     File.join(DIR, filename)
85   end
86
87   def compare(expected, actual)
88     TestUtil.filecompare(pathname(expected), pathname(actual))
89   end
90
91   def test_generate
92     compare("expectedClassdef.rb", "echo.rb")
93     compare("expectedMappingRegistry.rb", "echoMappingRegistry.rb")
94     compare("expectedDriver.rb", "echoDriver.rb")
95   end
96
97   def test_wsdl
98     wsdl = File.join(DIR, 'group.wsdl')
99     @client = ::SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
100     @client.endpoint_url = "http://localhost:#{Port}/"
101     @client.wiredump_dev = STDOUT if $DEBUG
102     @client.literal_mapping_registry = EchoMappingRegistry::LiteralRegistry
103     #
104     do_test_arg
105   end
106
107   def test_naive
108     @client = ::SOAP::RPC::Driver.new("http://localhost:#{Port}/")
109     @client.add_document_method('echo', 'urn:group:echo',
110       XSD::QName.new('urn:grouptype', 'groupele'),
111       XSD::QName.new('urn:grouptype', 'groupele'))
112     @client.literal_mapping_registry = EchoMappingRegistry::LiteralRegistry
113     @client.wiredump_dev = STDOUT if $DEBUG
114     #
115     do_test_arg
116   end
117
118   def test_stub
119     @client = Group_porttype.new("http://localhost:#{Port}/")
120     @client.wiredump_dev = STDOUT if $DEBUG
121     #
122     do_test_arg
123   end
124
125   def do_test_arg
126     arg = Groupele_type.new
127     arg.comment = "comment"
128     arg.set_any(
129       [::SOAP::SOAPElement.new("foo", "bar")]
130     )
131     arg.eletype = "eletype"
132     arg.var = "var"
133     arg.xmlattr_attr_min = -3
134     arg.xmlattr_attr_max = 3
135     ret = @client.echo(arg)
136     assert_equal(arg.comment, ret.comment)
137     assert_equal(arg.eletype, ret.eletype)
138     assert_nil(ret.element)
139     assert_equal(arg.var, ret.var)
140     assert_equal("bar", ret.foo)
141   end
142 end
143
144
145 end; end
Note: See TracBrowser for help on using the browser.