File: test_overload.rb

package info (click to toggle)
ruby-soap4r 2.0.5-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,032 kB
  • sloc: ruby: 52,729; xml: 266; sh: 42; javascript: 20; makefile: 13; perl: 10
file content (131 lines) | stat: -rw-r--r-- 3,452 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
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 Overload


class TestOverload < Test::Unit::TestCase
  TNS = "urn:overload"

  Methods = [
    [
      XSD::QName.new(TNS, 'methodAlpha'), "methodAlpha1", "method_alpha_1",
      [ [:in, "in0", ["::SOAP::SOAPString"]],
        [:in, "in1", ["::SOAP::SOAPString"]],
        [:in, "in2", ["::SOAP::SOAPString"]],
        [:retval, "methodAlphaReturn", ["::SOAP::SOAPLong"]] ]
    ], 
    [
      XSD::QName.new(TNS, 'methodAlpha'), "methodAlpha2", "method_alpha_2",
      [ [:in, "in0", ["::SOAP::SOAPString"]],
        [:in, "in1", ["::SOAP::SOAPString"]],
        [:retval, "methodAlphaReturn", ["::SOAP::SOAPLong"]] ]
    ]
  ]

  class Server < ::SOAP::RPC::StandaloneServer
    def on_init
      TestOverload::Methods.each do |definition|
        add_rpc_operation(self, *definition)
      end
    end
  
    def method_alpha_1(in0, in1, in2)
      3
    end
  
    def method_alpha_2(in0, in1)
      2
    end
  end

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

  Port = 17171

  def setup
    setup_server
    setup_classdef
    @client = nil
  end

  def teardown
    teardown_server if @server
    unless $DEBUG
      File.unlink(pathname('default.rb'))
      File.unlink(pathname('defaultMappingRegistry.rb'))
      File.unlink(pathname('defaultDriver.rb'))
      File.unlink(pathname('defaultServant.rb'))
      File.unlink(pathname('OverloadServiceClient.rb'))
    end
    @client.reset_stream if @client
  end

  def setup_server
    @server = Server.new('Test', "urn:rpc", '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("overload.wsdl")
    gen.basedir = DIR
    gen.logger.level = Logger::FATAL
    gen.opt['classdef'] = nil
    gen.opt['mapping_registry'] = nil
    gen.opt['driver'] = nil
    gen.opt['servant_skelton'] = nil
    gen.opt['client_skelton'] = nil
    gen.opt['force'] = true
    gen.run
    TestUtil.require(DIR, 'default.rb')
  end

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

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

  def test_compare
    compare("expectedDriver.rb", "defaultDriver.rb")
    compare("expectedServant.rb", "defaultServant.rb")
    compare("expectedClient.rb", "OverloadServiceClient.rb")
  end

  def test_wsdl
    wsdl = File.join(DIR, 'overload.wsdl')
    @client = ::SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
    @client.endpoint_url = "http://localhost:#{Port}/"
    @client.wiredump_dev = STDOUT if $DEBUG
    assert_equal(3, @client.call("methodAlpha1", "1", "2", "3"))
    assert_equal(2, @client.call("methodAlpha2", "1", "2"))
  end

  def test_native
    @client = ::SOAP::RPC::Driver.new("http://localhost:#{Port}/")
    Methods.each do |definition|
      @client.add_rpc_operation(*definition)
    end
    @client.wiredump_dev = STDOUT if $DEBUG
    assert_equal(3, @client.call("methodAlpha1", "1", "2", "3"))
    assert_equal(2, @client.call("methodAlpha2", "1", "2"))
  end

  def compare(expected, actual)
    TestUtil.filecompare(pathname(expected), pathname(actual))
  end
end


end; end