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

root/trunk/test/wsdl/anonymous/test_anonymous.rb

Revision 1979, 3.4 kB (checked in by nahi, 1 year ago)
  • when there are 2 unqualified anonymous elements which have the same name in a SOAP message, mapper cannot decode it to the correct object. introduced :is_anonymous in mapping_registry and do not search registry with anonymous element. closes #355.
Line 
1 require 'test/unit'
2 require 'wsdl/soap/wsdl2ruby'
3 require 'soap/rpc/standaloneServer'
4 require 'soap/wsdlDriver'
5 require File.join(File.dirname(File.expand_path(__FILE__)), '..', '..', 'testutil.rb')
6
7
8 if defined?(HTTPClient)
9
10 module WSDL; module Anonymous
11
12
13 class TestAnonymous < Test::Unit::TestCase
14   class Server < ::SOAP::RPC::StandaloneServer
15     Namespace = 'urn:lp'
16
17     def on_init
18       add_document_method(
19         self,
20         Namespace + ':login',
21         'login',
22         XSD::QName.new(Namespace, 'login'),
23         XSD::QName.new(Namespace, 'loginResponse')
24       )
25       add_document_method(
26         self,
27         Namespace + ':echo',
28         'echo',
29         XSD::QName.new(Namespace, 'Pack'),
30         XSD::QName.new(Namespace, 'Envelope')
31       )
32       self.literal_mapping_registry = LpMappingRegistry::LiteralRegistry
33     end
34  
35     def login(arg)
36       req = arg.loginRequest
37       sess = [req.username, req.password, req.timezone].join
38       LoginResponse.new(LoginResponse::LoginResult.new(sess))
39     end
40
41     def echo(pack)
42       raise unless pack.class == Pack
43       raise unless pack.header.class == Pack::Header
44       Envelope.new(Envelope::Header.new(pack.header.header1))
45     end
46   end
47
48   DIR = File.dirname(File.expand_path(__FILE__))
49   Port = 17171
50
51   def setup
52     setup_clientdef
53     setup_server
54     @client = nil
55   end
56
57   def teardown
58     teardown_server if @server
59     unless $DEBUG
60       File.unlink(pathname('lp.rb'))
61       File.unlink(pathname('lpMappingRegistry.rb'))
62       File.unlink(pathname('lpDriver.rb'))
63     end
64     @client.reset_stream if @client
65   end
66
67   def setup_server
68     @server = Server.new('Test', "urn:lp", '0.0.0.0', Port)
69     @server.level = Logger::Severity::ERROR
70     @server_thread = TestUtil.start_server_thread(@server)
71   end
72
73   def setup_clientdef
74     gen = WSDL::SOAP::WSDL2Ruby.new
75     gen.location = pathname("lp.wsdl")
76     gen.basedir = DIR
77     gen.logger.level = Logger::FATAL
78     gen.opt['module_path'] = self.class.to_s.sub(/::[^:]+$/, '')
79     gen.opt['classdef'] = nil
80     gen.opt['mapping_registry'] = nil
81     gen.opt['driver'] = nil
82     gen.opt['force'] = true
83     gen.run
84     TestUtil.require(DIR, 'lpDriver.rb', 'lpMappingRegistry.rb', 'lp.rb')
85   end
86
87   def teardown_server
88     @server.shutdown
89     @server_thread.kill
90     @server_thread.join
91   end
92
93   def pathname(filename)
94     File.join(DIR, filename)
95   end
96
97   def compare(expected, actual)
98     TestUtil.filecompare(pathname(expected), pathname(actual))
99   end
100
101   def test_stubgeneration
102     compare("expectedClassDef.rb", "lp.rb")
103     compare("expectedMappingRegistry.rb", "lpMappingRegistry.rb")
104     compare("expectedDriver.rb", "lpDriver.rb")
105   end
106
107   def test_stub
108     @client = Lp_porttype.new("http://localhost:#{Port}/")
109     @client.wiredump_dev = STDERR if $DEBUG
110     request = Login.new(Login::LoginRequest.new("username", "password", "tz"))
111     response = @client.login(request)
112     assert_equal(LoginResponse::LoginResult, response.loginResult.class)
113     assert_equal("usernamepasswordtz", response.loginResult.sessionID)
114   end
115
116   def test_anonymous_mapping
117     @client = Lp_porttype.new("http://localhost:#{Port}/")
118     @client.wiredump_dev = STDERR if $DEBUG
119     request = Pack.new(Pack::Header.new("pack_header"))
120     response = @client.echo(request)
121     assert_equal(Envelope, response.class)
122     assert_equal(Envelope::Header, response.header.class)
123     assert_equal("pack_header", response.header.header2)
124   end
125 end
126
127
128 end; end
129
130 end
Note: See TracBrowser for help on using the browser.