File: test_array.rb

package info (click to toggle)
ruby-soap4r 2.0.5-9
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 5,032 kB
  • sloc: ruby: 52,729; xml: 266; sh: 42; javascript: 20; makefile: 13; perl: 10
file content (201 lines) | stat: -rw-r--r-- 5,834 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
require 'test/unit'
require 'wsdl/parser'
require 'wsdl/soap/wsdl2ruby'
require 'soap/rpc/standaloneServer'
require 'soap/wsdlDriver'
require File.join(File.dirname(File.expand_path(__FILE__)), '..', '..', '..', 'testutil.rb')


module WSDL; module Document


class TestArray < Test::Unit::TestCase
  class Server < ::SOAP::RPC::StandaloneServer
    Namespace = 'http://tempuri.org/'

    def on_init
      add_document_method(
        self,
        Namespace + 'echo',
        'echo',
        XSD::QName.new(Namespace, 'echo'),
        XSD::QName.new(Namespace, 'echoResponse')
      )
      add_document_method(
        self,
        Namespace + 'echo2',
        'echo2',
        XSD::QName.new(Namespace, 'echo2'),
        XSD::QName.new(Namespace, 'echo2Response')
      )
      add_document_method(
        self,
        Namespace + 'echo3',
        'echo3',
        XSD::QName.new(Namespace, 'ArrayOfRecord'),
        XSD::QName.new(Namespace, 'ArrayOfRecord')
      )
      self.literal_mapping_registry = DoubleMappingRegistry::LiteralRegistry
    end
  
    def echo(arg)
      arg
    end
  
    def echo2(arg)
      arg
    end

    def echo3(arg)
      arg
    end
  end

  DIR = File.dirname(File.expand_path(__FILE__))

  Port = 17171

  def setup
    setup_classdef
    setup_server
    @client = nil
  end

  def teardown
    teardown_server if @server
    unless $DEBUG
      File.unlink(pathname('double.rb'))
      File.unlink(pathname('doubleMappingRegistry.rb'))
      File.unlink(pathname('doubleDriver.rb'))
    end
    @client.reset_stream if @client
  end

  def setup_server
    @server = Server.new('Test', Server::Namespace, '0.0.0.0', Port)
    @server.level = Logger::Severity::ERROR
    @server_thread = TestUtil.start_server_thread(@server)
  end

  def setup_classdef
    gen = WSDL::SOAP::WSDL2Ruby.new
    gen.location = pathname("double.wsdl")
    gen.basedir = DIR
    gen.logger.level = Logger::FATAL
    gen.opt['classdef'] = nil
    gen.opt['mapping_registry'] = nil
    gen.opt['driver'] = nil
    gen.opt['module_path'] = self.class.to_s.sub(/::[^:]+$/, '')
    gen.opt['force'] = true
    gen.run
    TestUtil.require(DIR, 'doubleDriver.rb', 'doubleMappingRegistry.rb', 'double.rb')
  end

  def teardown_server
    @server.shutdown
    @server_thread.kill
    @server_thread.join
  end

  def pathname(filename)
    File.join(DIR, filename)
  end

  def test_stub
    @client = PricerSoap.new
    @client.endpoint_url = "http://localhost:#{Port}/"
    @client.wiredump_dev = STDOUT if $DEBUG
    arg = ArrayOfComplex[c1 = Complex.new, c2 = Complex.new, c3 = Complex.new]
    c1.string = "str_c1"
    c1.double = 1.1
    c2.string = "str_c2"
    c2.double = 2.2
    c3.string = "str_c3"
    c3.double = 3.3
    ret = @client.echo2(Echo2.new(arg))
    assert_equal(ArrayOfComplex, ret.arg.class)
    assert_equal(Complex, ret.arg[0].class)
    assert_equal(arg[0].string, ret.arg[0].string)
    assert_equal(arg[1].string, ret.arg[1].string)
    assert_equal(arg[2].string, ret.arg[2].string)
  end

  def test_wsdl_stubclassdef
    wsdl = File.join(DIR, 'double.wsdl')
    @client = ::SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
    @client.endpoint_url = "http://localhost:#{Port}/"
    @client.literal_mapping_registry = DoubleMappingRegistry::LiteralRegistry
    @client.wiredump_dev = STDOUT if $DEBUG
    arg = ArrayOfDouble[0.1, 0.2, 0.3]
    assert_equal(arg, @client.echo(Echo.new(arg)).ary)
  end

  def test_wsdl
    wsdl = File.join(DIR, 'double.wsdl')
    @client = ::SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
    @client.endpoint_url = "http://localhost:#{Port}/"
    @client.literal_mapping_registry = DoubleMappingRegistry::LiteralRegistry
    @client.wiredump_dev = STDOUT if $DEBUG
    double = [0.1, 0.2, 0.3]
    assert_equal(double, @client.echo(:ary => double).ary)
  end

  def test_stub
    @client = ::WSDL::Document::PricerSoap.new("http://localhost:#{Port}/")
    @client.wiredump_dev = STDOUT if $DEBUG
    double = [0.1, 0.2, 0.3]
    assert_equal(double, @client.echo(:ary => double).ary)
  end

  def test_stub_nil
    @client = ::WSDL::Document::PricerSoap.new("http://localhost:#{Port}/")
    @client.wiredump_dev = STDOUT if $DEBUG
    assert_equal(nil, @client.echo(Echo.new).ary)
  end

  def test_attribute_array
    @client = ::WSDL::Document::PricerSoap.new("http://localhost:#{Port}/")
    @client.wiredump_dev = STDOUT if $DEBUG
    #
    r1 = ReportRecord.new
    r1.xmlattr_a = "r1_xmlattr_a"
    r1.xmlattr_b = "r1_xmlattr_b"
    r1.xmlattr_c = "r1_xmlattr_c"
    r2 = ReportRecord.new
    r2.xmlattr_a = "r2_xmlattr_a"
    r2.xmlattr_b = "r2_xmlattr_b"
    r2.xmlattr_c = "r2_xmlattr_c"
    arg = ArrayOfRecord[r1, r2]
    ret = @client.echo3(arg)
    assert_equal(arg.class , ret.class)
    assert_equal(arg.size , ret.size)
    assert_equal(2, ret.size)
    assert_equal(arg[0].class, ret[0].class)
    assert_equal(arg[0].xmlattr_a, ret[0].xmlattr_a)
    assert_equal(arg[0].xmlattr_b, ret[0].xmlattr_b)
    assert_equal(arg[0].xmlattr_c, ret[0].xmlattr_c)
    assert_equal(arg[1].class, ret[1].class)
    assert_equal(arg[1].xmlattr_a, ret[1].xmlattr_a)
    assert_equal(arg[1].xmlattr_b, ret[1].xmlattr_b)
    assert_equal(arg[1].xmlattr_c, ret[1].xmlattr_c)
    #
    arg = ArrayOfRecord[r1]
    ret = @client.echo3(arg)
    assert_equal(arg.class , ret.class)
    assert_equal(arg.size , ret.size)
    assert_equal(1, ret.size)
    assert_equal(arg[0].class, ret[0].class)
    assert_equal(arg[0].xmlattr_a, ret[0].xmlattr_a)
    assert_equal(arg[0].xmlattr_b, ret[0].xmlattr_b)
    assert_equal(arg[0].xmlattr_c, ret[0].xmlattr_c)
    #
    arg = ArrayOfRecord[]
    ret = @client.echo3(arg)
    assert_equal(arg.class , ret.class)
    assert_equal(arg.size , ret.size)
    assert_equal(0, ret.size)
  end
end


end; end