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

root/trunk/test/wsdl/abstract/test_abstract.rb

Revision 2006, 4.8 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 Abstract
10
11
12 class TestAbstract < Test::Unit::TestCase
13   class Server < ::SOAP::RPC::StandaloneServer
14     def on_init
15       add_rpc_method(self, 'echo', 'name', 'author')
16       add_rpc_method(self, 'echoDerived', 'parameter')
17       add_document_operation(
18         self,
19         "",
20         "echoLiteral",
21         [ [:in, "author", ["::SOAP::SOAPElement", "urn:www.example.org:abstract", "Author"]],
22           [:out, "return", ["::SOAP::SOAPElement", "urn:www.example.org:abstract", "Book"]] ],
23         { :request_style =>  :document, :request_use =>  :literal,
24           :response_style => :document, :response_use => :literal,
25           :faults => {} }
26       )
27       self.mapping_registry = AbstractMappingRegistry::EncodedRegistry
28       self.literal_mapping_registry = AbstractMappingRegistry::LiteralRegistry
29     end
30  
31     def echo(name, author)
32       Book.new(name, author)
33     end
34
35     def echoLiteral(author)
36       author
37     end
38
39     def echoDerived(parameter)
40       parameter
41     end
42   end
43
44   DIR = File.dirname(File.expand_path(__FILE__))
45
46   Port = 17171
47
48   def setup
49     setup_classdef
50     setup_server
51     @client = nil
52   end
53
54   def teardown
55     teardown_server if @server
56     unless $DEBUG
57       File.unlink(pathname('abstract.rb'))
58       File.unlink(pathname('abstractMappingRegistry.rb'))
59       File.unlink(pathname('abstractDriver.rb'))
60     end
61     @client.reset_stream if @client
62   end
63
64   def setup_server
65     @server = Server.new('Test', "urn:www.example.org:abstract", '0.0.0.0', Port)
66     @server.level = Logger::Severity::ERROR
67     @server_thread = TestUtil.start_server_thread(@server)
68   end
69
70   def setup_classdef
71     gen = WSDL::SOAP::WSDL2Ruby.new
72     gen.location = pathname("abstract.wsdl")
73     gen.basedir = DIR
74     gen.logger.level = Logger::FATAL
75     gen.opt['classdef'] = nil
76     gen.opt['mapping_registry'] = nil
77     gen.opt['module_path'] = self.class.to_s.sub(/::[^:]+$/, '')
78     gen.opt['driver'] = nil
79     gen.opt['force'] = true
80     gen.run
81     TestUtil.require(DIR, 'abstractDriver.rb', 'abstract.rb', 'abstractMappingRegistry.rb')
82   end
83
84   def teardown_server
85     @server.shutdown
86     @server_thread.kill
87     @server_thread.join
88   end
89
90   def pathname(filename)
91     File.join(DIR, filename)
92   end
93
94   def test_wsdl
95     wsdl = File.join(DIR, 'abstract.wsdl')
96     @client = ::SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
97     @client.mapping_registry = AbstractMappingRegistry::EncodedRegistry
98     @client.endpoint_url = "http://localhost:#{Port}/"
99     @client.wiredump_dev = STDERR if $DEBUG
100
101     author = UserAuthor.new("first", "last", "uid")
102     ret = @client.echo("book1", author)
103     assert_equal("book1", ret.name)
104     assert_equal(author.firstname, ret.author.firstname)
105     assert_equal(author.lastname, ret.author.lastname)
106     assert_equal(author.userid, ret.author.userid)
107
108     author = NonUserAuthor.new("first", "last", "nonuserid")
109     ret = @client.echo("book2", author)
110     assert_equal("book2", ret.name)
111     assert_equal(author.firstname, ret.author.firstname)
112     assert_equal(author.lastname, ret.author.lastname)
113     assert_equal(author.nonuserid, ret.author.nonuserid)
114   end
115
116   def test_stub
117     @client = AbstractService.new("http://localhost:#{Port}/")
118     @client.wiredump_dev = STDERR if $DEBUG
119
120     author = UserAuthor.new("first", "last", "uid")
121     ret = @client.echo("book1", author)
122     assert_equal("book1", ret.name)
123     assert_equal(author.firstname, ret.author.firstname)
124     assert_equal(author.lastname, ret.author.lastname)
125     assert_equal(author.userid, ret.author.userid)
126     #
127     author = NonUserAuthor.new("first", "last", "nonuserid")
128     ret = @client.echo("book2", author)
129     assert_equal("book2", ret.name)
130     assert_equal(author.firstname, ret.author.firstname)
131     assert_equal(author.lastname, ret.author.lastname)
132     assert_equal(author.nonuserid, ret.author.nonuserid)
133   end
134
135   def test_literal_stub
136     @client = AbstractService.new("http://localhost:#{Port}/")
137     @client.wiredump_dev = STDERR if $DEBUG
138     author = NonUserAuthor.new("first", "last", "nonuserid")
139     ret = @client.echoLiteral(author)
140     assert_equal(author.firstname, ret.firstname)
141     assert_equal(author.lastname, ret.lastname)
142     assert_equal(author.nonuserid, ret.nonuserid)
143     assert_equal(NonUserAuthor, ret.class)
144   end
145
146   def test_stub_derived
147     @client = AbstractService.new("http://localhost:#{Port}/")
148     @client.wiredump_dev = STDERR if $DEBUG
149
150     parameter = DerivedClass1.new(123, "someVar1")
151     ret = @client.echoDerived(parameter)
152     assert_equal(123, ret.id)
153     assert_equal(["someVar1"], ret.someVar1)
154     assert_equal(DerivedClass1, ret.class)
155   end
156 end
157
158
159 end; end
Note: See TracBrowser for help on using the browser.