~ubuntu-branches/ubuntu/hardy/ruby1.8/hardy-updates

« back to all changes in this revision

Viewing changes to test/soap/header/test_simplehandler.rb

  • Committer: Bazaar Package Importer
  • Author(s): akira yamada
  • Date: 2007-03-13 22:11:58 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20070313221158-h3oql37brlaf2go2
Tags: 1.8.6-1
* new upstream version, 1.8.6.
* libruby1.8 conflicts with libopenssl-ruby1.8 (< 1.8.6) (closes: #410018)
* changed packaging style to cdbs from dbs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require 'test/unit'
 
2
require 'soap/rpc/driver'
 
3
require 'soap/rpc/standaloneServer'
 
4
require 'soap/header/simplehandler'
 
5
 
 
6
 
 
7
module SOAP
 
8
module Header
 
9
 
 
10
 
 
11
class TestSimpleHandler < Test::Unit::TestCase
 
12
  Port = 17171
 
13
  PortName = 'http://tempuri.org/authHeaderPort'
 
14
 
 
15
  class PingPortServer < SOAP::RPC::StandaloneServer
 
16
    class PingService
 
17
      def self.create
 
18
        new
 
19
      end
 
20
 
 
21
      def ping
 
22
        Thread.current[:pingheader]
 
23
      end
 
24
    end
 
25
 
 
26
    def initialize(*arg)
 
27
      super
 
28
      add_rpc_servant(PingService.new, PortName)
 
29
      add_request_headerhandler(PingServerHeaderHandler)
 
30
    end
 
31
 
 
32
    class PingServerHeaderHandler < SOAP::Header::SimpleHandler
 
33
      MyHeaderName = XSD::QName.new("http://xmlsoap.org/Ping", "PingHeader")
 
34
  
 
35
      def self.create
 
36
        new
 
37
      end
 
38
 
 
39
      def initialize()
 
40
        super(MyHeaderName)
 
41
      end
 
42
 
 
43
      def on_simple_outbound
 
44
        "dummy"
 
45
      end
 
46
 
 
47
      def on_simple_inbound(my_header, mu)
 
48
        Thread.current[:pingheader] = my_header
 
49
      end
 
50
    end
 
51
  end
 
52
 
 
53
  class PingClientHeaderHandler < SOAP::Header::SimpleHandler
 
54
    MyHeaderName = XSD::QName.new("http://xmlsoap.org/Ping", "PingHeader")
 
55
 
 
56
    def initialize(pingHeader)
 
57
      super(MyHeaderName)
 
58
      @pingHeader = pingHeader
 
59
      @mustunderstand = false
 
60
    end
 
61
 
 
62
    def on_simple_outbound
 
63
      @pingHeader # --- note, not a Hash
 
64
    end
 
65
 
 
66
    def on_simple_inbound(my_header, mustunderstand)
 
67
      Thread.current[:pingheader] = my_header
 
68
    end
 
69
  end
 
70
 
 
71
  def setup
 
72
    @endpoint = "http://localhost:#{Port}/"
 
73
    setup_server
 
74
    setup_client
 
75
  end
 
76
 
 
77
  def setup_server
 
78
    @server = PingPortServer.new(self.class.name, nil, '0.0.0.0', Port)
 
79
    @server.level = Logger::Severity::ERROR
 
80
    @t = Thread.new {
 
81
      @server.start
 
82
    }
 
83
  end
 
84
 
 
85
  def setup_client
 
86
    @client = SOAP::RPC::Driver.new(@endpoint, PortName)
 
87
    @client.wiredump_dev = STDERR if $DEBUG
 
88
    @client.add_method('ping')
 
89
  end
 
90
 
 
91
  def teardown
 
92
    teardown_server
 
93
    teardown_client
 
94
  end
 
95
 
 
96
  def teardown_server
 
97
    @server.shutdown
 
98
    @t.kill
 
99
    @t.join
 
100
  end
 
101
 
 
102
  def teardown_client
 
103
    @client.reset_stream
 
104
  end
 
105
 
 
106
  def test_string
 
107
    h = PingClientHeaderHandler.new('pingheader')
 
108
    @client.headerhandler << h
 
109
    assert_equal("pingheader", @client.ping)
 
110
    assert_equal("dummy", Thread.current[:pingheader])
 
111
  end
 
112
end
 
113
 
 
114
 
 
115
end
 
116
end