File: test_aspdotnet.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 (123 lines) | stat: -rw-r--r-- 3,647 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
require 'test/unit'
require 'soap/rpc/standaloneServer'
require 'soap/rpc/driver'
require File.join(File.dirname(File.expand_path(__FILE__)), '..', '..', 'testutil.rb')


module SOAP; module ASPDotNet


class TestASPDotNet < Test::Unit::TestCase
  class Server < ::SOAP::RPC::StandaloneServer
    Namespace = "http://localhost/WebService/"

    def on_init
      add_document_method(
        self,
        Namespace + 'SayHello',
        'sayHello',
        XSD::QName.new(Namespace, 'SayHello'),
        XSD::QName.new(Namespace, 'SayHelloResponse')
      )
    end
  
    def sayHello(arg)
      name = arg['name']
      "Hello #{name}"
    end
  end

  Port = 17171
  Endpoint = "http://localhost:#{Port}/"

  def setup
    setup_server
    @client = nil
  end

  def teardown
    teardown_server if @server
    @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 teardown_server
    @server.shutdown
    @server_thread.kill
    @server_thread.join
  end

  def test_document_method
    @client = SOAP::RPC::Driver.new(Endpoint, Server::Namespace)
    @client.wiredump_dev = STDOUT if $DEBUG
    @client.add_document_method('sayHello', Server::Namespace + 'SayHello',
      XSD::QName.new(Server::Namespace, 'SayHello'),
      XSD::QName.new(Server::Namespace, 'SayHelloResponse'))
    assert_equal("Hello Mike", @client.sayHello(:name => "Mike"))
  end

  def test_xml
    @client = SOAP::RPC::Driver.new(Endpoint, Server::Namespace)
    @client.wiredump_dev = STDOUT if $DEBUG
    @client.add_document_method('sayHello', Server::Namespace + 'SayHello',
      XSD::QName.new(Server::Namespace, 'SayHello'),
      XSD::QName.new(Server::Namespace, 'SayHelloResponse'))
    require 'rexml/document'
    xml = <<__XML__
<n1:sayHello xmlns:n1="http://localhost/WebService/">
  <n1:name>Mike</n1:name>
</n1:sayHello>
__XML__
    ele = REXML::Document.new(xml)
    assert_equal("Hello Mike", @client.sayHello(ele))
    def xml.to_xmlpart; to_s; end
    assert_equal("Hello Mike", @client.sayHello(xml))
  end

  def test_aspdotnethandler
    @client = SOAP::RPC::Driver.new(Endpoint, Server::Namespace)
    @client.wiredump_dev = STDOUT if $DEBUG
    @client.add_method_with_soapaction('sayHello', Server::Namespace + 'SayHello', 'name')
    @client.default_encodingstyle = SOAP::EncodingStyle::ASPDotNetHandler::Namespace
    assert_equal("Hello Mike", @client.sayHello("Mike"))
  end

  if defined?(HTTPClient)

    # qualified!
    REQUEST_ASPDOTNETHANDLER =
%q[<?xml version="1.0" encoding="utf-8" ?>
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <env:Body>
    <n1:sayHello xmlns:n1="http://localhost/WebService/">
      <n1:name>Mike</n1:name>
    </n1:sayHello>
  </env:Body>
</env:Envelope>]

    def test_aspdotnethandler_envelope
      @client = SOAP::RPC::Driver.new(Endpoint, Server::Namespace)
      @client.wiredump_dev = str = ''
      @client.add_method_with_soapaction('sayHello', Server::Namespace + 'SayHello', 'name')
      @client.default_encodingstyle = SOAP::EncodingStyle::ASPDotNetHandler::Namespace
      assert_equal("Hello Mike", @client.sayHello("Mike"))
      assert_equal(REQUEST_ASPDOTNETHANDLER, parse_requestxml(str),
        [REQUEST_ASPDOTNETHANDLER, parse_requestxml(str)].join("\n\n"))
    end

    def parse_requestxml(str)
      str.split(/\r?\n\r?\n/)[3]
    end

  end
end


end; end