summaryrefslogtreecommitdiff
path: root/test/soap
diff options
context:
space:
mode:
authornahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-12-05 13:26:26 +0000
committernahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-12-05 13:26:26 +0000
commit1ed39b739237bffd9c78e696c09462ce67017b95 (patch)
tree032499118c88146a86aede2d89fa707bb242edc7 /test/soap
parent3be09a4f4ffee94601051c37e5303b9546d816e1 (diff)
* lib/soap/netHttpClient.rb: proxy support did not work. fixed.
* lib/soap/property.rb: add class methods for loading property from stream/file/propertyfile. propertyfile is a file which is located at somedir in $:. * lib/soap/soap.rb, lib/soap/wsdlDriver.rb, lib/soap/rpc/driver.rb, lib/wsdl/importer.rb: load property from propertyfile 'soap/property' e.g. /usr/local/lib/ruby/site_ruby/1.8/soap/property. * test/soap/test_property.rb, test/soap/test_streamhandler.rb: new file. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5121 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/soap')
-rw-r--r--test/soap/test_property.rb345
-rw-r--r--test/soap/test_streamhandler.rb197
2 files changed, 542 insertions, 0 deletions
diff --git a/test/soap/test_property.rb b/test/soap/test_property.rb
new file mode 100644
index 0000000..d7d6c2e
--- /dev/null
+++ b/test/soap/test_property.rb
@@ -0,0 +1,345 @@
+require 'test/unit'
+require 'soap/property'
+
+
+module SOAP
+
+
+class TestProperty < Test::Unit::TestCase
+ def setup
+ @prop = ::SOAP::Property.new
+ end
+
+ def teardown
+ # Nothing to do.
+ end
+
+ def test_s_load
+ propstr = <<__EOP__
+
+# comment1
+
+# comment2\r
+# comment2
+
+\r
+a.b.0 = 1
+a.b.1 = 2
+a.b.2 = 3
+client.protocol.http.proxy=http://myproxy:8080 \r
+client.protocol.http.no_proxy: intranet.example.com,local.example.com\r
+client.protocol.http.protocol_version = 1.0
+foo\\:bar\\=baz = qux
+foo\\\\.bar.baz=\tq\\\\ux\ttab
+ a\\ b = 1
+__EOP__
+ prop = Property.load(propstr)
+ assert_equal(["1", "2", "3"], prop["a.b"].values.sort)
+ assert_equal("intranet.example.com,local.example.com",
+ prop["client.protocol.http.no_proxy"])
+ assert_equal("http://myproxy:8080", prop["client.protocol.http.proxy"])
+ assert_equal("1.0", prop["client.protocol.http.protocol_version"])
+ assert_equal("q\\ux\ttab", prop['foo\.bar.baz'])
+ assert_equal("1", prop['a b'])
+ end
+
+ def test_initialize
+ prop = ::SOAP::Property.new
+ # store is empty
+ assert_nil(prop["a"])
+ # does hook work?
+ assert_equal(1, prop["a"] = 1)
+ end
+
+ def test_aref
+ # name_to_a
+ assert_nil(@prop[:foo])
+ assert_nil(@prop["foo"])
+ assert_nil(@prop[[:foo]])
+ assert_nil(@prop[["foo"]])
+ assert_raises(ArgumentError) do
+ @prop[1]
+ end
+ @prop[:foo] = :foo
+ assert_equal(:foo, @prop[:foo])
+ assert_equal(:foo, @prop["foo"])
+ assert_equal(:foo, @prop[[:foo]])
+ assert_equal(:foo, @prop[["foo"]])
+ end
+
+ def test_referent
+ # referent(1)
+ assert_nil(@prop["foo.foo"])
+ assert_nil(@prop[["foo", "foo"]])
+ assert_nil(@prop[["foo", :foo]])
+ @prop["foo.foo"] = :foo
+ assert_equal(:foo, @prop["foo.foo"])
+ assert_equal(:foo, @prop[["foo", "foo"]])
+ assert_equal(:foo, @prop[[:foo, "foo"]])
+ # referent(2)
+ @prop["bar.bar.bar"] = :bar
+ assert_equal(:bar, @prop["bar.bar.bar"])
+ assert_equal(:bar, @prop[["bar", "bar", "bar"]])
+ assert_equal(:bar, @prop[[:bar, "bar", :bar]])
+ end
+
+ def test_to_key_and_deref
+ @prop["foo.foo"] = :foo
+ assert_equal(:foo, @prop["fOo.FoO"])
+ assert_equal(:foo, @prop[[:fOO, :FOO]])
+ assert_equal(:foo, @prop[["FoO", :Foo]])
+ # deref_key negative test
+ assert_raises(ArgumentError) do
+ @prop["baz"] = 1
+ @prop["baz.qux"] = 2
+ end
+ end
+
+ def test_value_hook
+ tag = Object.new
+ tested = false
+ @prop.add_hook("FOO.BAR.BAZ") do |key, value|
+ assert_equal("foo.bar.baz", key)
+ assert_equal(tag, value)
+ tested = true
+ end
+ @prop["Foo.baR.baZ"] = tag
+ assert_equal(tag, @prop["foo.bar.baz"])
+ assert(tested)
+ @prop["foo.bar"] = 1 # unhook the above block
+ assert_equal(1, @prop["foo.bar"])
+ end
+
+ def test_key_hook
+ tag = Object.new
+ tested = 0
+ @prop.add_hook("foo") do |key, value|
+ assert_equal("foo.bar.baz.qux", key)
+ assert_equal(tag, value)
+ tested += 1
+ end
+ @prop.add_hook("foo.bar") do |key, value|
+ assert_equal("foo.bar.baz.qux", key)
+ assert_equal(tag, value)
+ tested += 1
+ end
+ @prop.add_hook("foo.bar.baz") do |key, value|
+ assert_equal("foo.bar.baz.qux", key)
+ assert_equal(tag, value)
+ tested += 1
+ end
+ @prop.add_hook("foo.bar.baz.qux") do |key, value|
+ assert_equal("foo.bar.baz.qux", key)
+ assert_equal(tag, value)
+ tested += 1
+ end
+ @prop["foo.bar.baz.qux"] = tag
+ assert_equal(tag, @prop["foo.bar.baz.qux"])
+ assert_equal(4, tested)
+ end
+
+ def test_keys
+ assert(@prop.keys.empty?)
+ @prop["foo"] = 1
+ @prop["bar"]
+ @prop["BAz"] = 2
+ assert_equal(2, @prop.keys.size)
+ assert(@prop.keys.member?("foo"))
+ assert(@prop.keys.member?("baz"))
+ #
+ assert_nil(@prop["a"])
+ @prop["a.a"] = 1
+ assert_instance_of(::SOAP::Property, @prop["a"])
+ @prop["a.b"] = 1
+ @prop["a.c"] = 1
+ assert_equal(3, @prop["a"].keys.size)
+ assert(@prop["a"].keys.member?("a"))
+ assert(@prop["a"].keys.member?("b"))
+ assert(@prop["a"].keys.member?("c"))
+ end
+
+ def test_lshift
+ assert(@prop.empty?)
+ @prop << 1
+ assert_equal([1], @prop.values)
+ assert_equal(1, @prop["0"])
+ @prop << 1
+ assert_equal([1, 1], @prop.values)
+ assert_equal(1, @prop["1"])
+ @prop << 1
+ assert_equal([1, 1, 1], @prop.values)
+ assert_equal(1, @prop["2"])
+ #
+ @prop["abc.def"] = o = SOAP::Property.new
+ tested = 0
+ o.add_hook do |k, v|
+ tested += 1
+ end
+ @prop["abc.def"] << 1
+ @prop["abc.def"] << 2
+ @prop["abc.def"] << 3
+ @prop["abc.def"] << 4
+ assert_equal(4, tested)
+ end
+
+ def test_lock_each
+ @prop["a.b.c.d.e"] = 1
+ @prop["a.b.d"] = branch = ::SOAP::Property.new
+ @prop["a.b.d.e.f"] = 2
+ @prop.lock
+ assert(@prop.locked?)
+ assert_instance_of(::SOAP::Property, @prop["a"])
+ assert_raises(TypeError) do
+ @prop["b"]
+ end
+ #
+ @prop["a"].lock
+ assert_raises(TypeError) do
+ @prop["a"]
+ end
+ assert_instance_of(::SOAP::Property, @prop["a.b"])
+ #
+ @prop["a.b"].lock
+ assert_raises(TypeError) do
+ @prop["a.b"]
+ end
+ assert_raises(TypeError) do
+ @prop["a"]
+ end
+ #
+ @prop["a.b.c.d"].lock
+ assert_instance_of(::SOAP::Property, @prop["a.b.c"])
+ assert_raises(TypeError) do
+ @prop["a.b.c.d"]
+ end
+ assert_instance_of(::SOAP::Property, @prop["a.b.d"])
+ #
+ branch["e"].lock
+ assert_instance_of(::SOAP::Property, @prop["a.b.d"])
+ assert_raises(TypeError) do
+ @prop["a.b.d.e"]
+ end
+ assert_raises(TypeError) do
+ branch["e"]
+ end
+ end
+
+ def test_lock_cascade
+ @prop["a.a"] = nil
+ @prop["a.b.c"] = 1
+ @prop["b"] = false
+ @prop.lock(true)
+ assert(@prop.locked?)
+ assert_equal(nil, @prop["a.a"])
+ assert_equal(1, @prop["a.b.c"])
+ assert_equal(false, @prop["b"])
+ assert_raises(TypeError) do
+ @prop["c"]
+ end
+ assert_raises(TypeError) do
+ @prop["c"] = 2
+ end
+ assert_raises(TypeError) do
+ @prop["a.b.R"]
+ end
+ assert_raises(TypeError) do
+ @prop.add_hook do
+ assert(false)
+ end
+ end
+ assert_raises(TypeError) do
+ @prop.add_hook("c") do
+ assert(false)
+ end
+ end
+ assert_raises(TypeError) do
+ @prop.add_hook("a.c") do
+ assert(false)
+ end
+ end
+ assert_nil(@prop["a.a"])
+ @prop["a.a"] = 2
+ assert_equal(2, @prop["a.a"])
+ #
+ @prop.unlock(true)
+ assert_nil(@prop["c"])
+ @prop["c"] = 2
+ assert_equal(2, @prop["c"])
+ @prop["a.d.a.a"] = :foo
+ assert_equal(:foo, @prop["a.d.a.a"])
+ tested = false
+ @prop.add_hook("a.c") do |name, value|
+ assert(true)
+ tested = true
+ end
+ @prop["a.c"] = 3
+ assert(tested)
+ end
+
+ def test_hook_then_lock
+ tested = false
+ @prop.add_hook("a.b.c") do |name, value|
+ assert_equal("a.b.c", name)
+ tested = true
+ end
+ @prop["a.b"].lock
+ assert(!tested)
+ @prop["a.b.c"] = 5
+ assert(tested)
+ assert_equal(5, @prop["a.b.c"])
+ assert_raises(TypeError) do
+ @prop["a.b.d"] = 5
+ end
+ end
+
+ def test_lock_unlock_return
+ assert_equal(@prop, @prop.lock)
+ assert_equal(@prop, @prop.unlock)
+ end
+
+ def test_lock_split
+ @prop["a.b.c"] = 1
+ assert_instance_of(::SOAP::Property, @prop["a.b"])
+ @prop["a.b.d"] = branch = ::SOAP::Property.new
+ @prop["a.b.d.e"] = 2
+ assert_equal(branch, @prop["a.b.d"])
+ assert_equal(branch, @prop[:a][:b][:d])
+ @prop.lock(true)
+ # split error 1
+ assert_raises(TypeError) do
+ @prop["a.b"]
+ end
+ # split error 2
+ assert_raises(TypeError) do
+ @prop["a"]
+ end
+ @prop["a.b.c"] = 2
+ assert_equal(2, @prop["a.b.c"])
+ # replace error
+ assert_raises(TypeError) do
+ @prop["a.b.c"] = ::SOAP::Property.new
+ end
+ # override error
+ assert_raises(TypeError) do
+ @prop["a.b"] = 1
+ end
+ #
+ assert_raises(TypeError) do
+ @prop["a.b.d"] << 1
+ end
+ assert_raises(TypeError) do
+ branch << 1
+ end
+ branch.unlock(true)
+ branch << 1
+ branch << 2
+ branch << 3
+ assert_equal(2, @prop["a.b.d.e"])
+ assert_equal(1, @prop["a.b.d.1"])
+ assert_equal(2, @prop["a.b.d.2"])
+ assert_equal(3, @prop["a.b.d.3"])
+ end
+end
+
+
+end
diff --git a/test/soap/test_streamhandler.rb b/test/soap/test_streamhandler.rb
new file mode 100644
index 0000000..3713e9e
--- /dev/null
+++ b/test/soap/test_streamhandler.rb
@@ -0,0 +1,197 @@
+require 'test/unit'
+require 'soap/rpc/driver'
+require 'webrick'
+require 'webrick/httpproxy'
+require 'logger'
+
+
+module SOAP
+
+
+class TestStreamHandler < Test::Unit::TestCase
+ Port = 17171
+ ProxyPort = 17172
+
+ def setup
+ @logger = Logger.new(STDERR)
+ @logger.level = Logger::Severity::ERROR
+ @url = "http://localhost:#{Port}/"
+ @proxyurl = "http://localhost:#{ProxyPort}/"
+ @server = @proxyserver = @client = nil
+ @server_thread = @proxyserver_thread = nil
+ setup_server
+ setup_client
+ end
+
+ def teardown
+ teardown_client
+ teardown_proxyserver if @proxyserver
+ teardown_server
+ end
+
+ def setup_server
+ @server = WEBrick::HTTPServer.new(
+ :BindAddress => "0.0.0.0",
+ :Logger => @logger,
+ :Port => Port,
+ :AccessLog => [],
+ :DocumentRoot => File.dirname(File.expand_path(__FILE__))
+ )
+ @server.mount(
+ '/',
+ WEBrick::HTTPServlet::ProcHandler.new(method(:do_server_proc).to_proc)
+ )
+ @server_thread = start_server_thread(@server)
+ end
+
+ def setup_proxyserver
+ @proxyserver = WEBrick::HTTPProxyServer.new(
+ :BindAddress => "0.0.0.0",
+ :Logger => @logger,
+ :Port => ProxyPort,
+ :AccessLog => []
+ )
+ @proxyserver_thread = start_server_thread(@proxyserver)
+ end
+
+ def setup_client
+ @client = SOAP::RPC::Driver.new(@url, '')
+ @client.add_method("do_server_proc")
+ end
+
+ def teardown_server
+ @server.shutdown
+ @server_thread.kill
+ @server_thread.join
+ end
+
+ def teardown_proxyserver
+ @proxyserver.shutdown
+ @proxyserver_thread.kill
+ @proxyserver_thread.join
+ end
+
+ def teardown_client
+ @client.reset_stream
+ end
+
+ def start_server_thread(server)
+ t = Thread.new {
+ Thread.current.abort_on_exception = true
+ server.start
+ }
+ while server.status != :Running
+ sleep 0.1
+ unless t.alive?
+ t.join
+ raise
+ end
+ end
+ t
+ end
+
+ def do_server_proc(req, res)
+ res['content-type'] = 'text/xml'
+ res.body = <<__EOX__
+<?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:do_server_proc xmlns:n1="urn:foo" env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
+ <return xsi:nil="true"/>
+ </n1:do_server_proc>
+ </env:Body>
+</env:Envelope>
+__EOX__
+ end
+
+ def parse_req_header(str)
+ if ::SOAP::StreamHandler::Client.to_s == 'SOAP::NetHttpClient'
+ str = eval(str.split(/\r?\n/)[4][3..-1])
+ end
+ parse_req_header_http_access2(str)
+ end
+
+ def parse_req_header_http_access2(str)
+ headerp = false
+ headers = {}
+ req = nil
+ str.split(/(?:\r?\n)/).each do |line|
+ if headerp and /^$/ =~line
+ headerp = false
+ break
+ end
+ if headerp
+ k, v = line.scan(/^([^:]+):\s*(.*)$/)[0]
+ headers[k.downcase] = v
+ end
+ if /^POST/ =~ line
+ req = line
+ headerp = true
+ end
+ end
+ return req, headers
+ end
+
+ def test_normal
+ str = ""
+ @client.wiredump_dev = str
+ assert_nil(@client.do_server_proc)
+ r, h = parse_req_header(str)
+ assert_match(%r"POST / HTTP/1.", r)
+ assert(/^text\/xml;/ =~ h["content-type"])
+ end
+
+ def test_basic_auth
+ unless Object.const_defined?('HTTPAccess2')
+ STDERR.puts("basic_auth is not supported")
+ return
+ end
+ str = ""
+ @client.wiredump_dev = str
+ @client.options["protocol.http.basic_auth"] << [@url, "foo", "bar"]
+ assert_nil(@client.do_server_proc)
+ r, h = parse_req_header(str)
+ assert_equal("Basic Zm9vOmJhcg==", h["authorization"])
+ end
+
+ def test_proxy
+ if Object.const_defined?('HTTPAccess2')
+ backup = HTTPAccess2::Client::NO_PROXY_HOSTS.dup
+ HTTPAccess2::Client::NO_PROXY_HOSTS.clear
+ else
+ backup = SOAP::NetHttpClient::NO_PROXY_HOSTS.dup
+ SOAP::NetHttpClient::NO_PROXY_HOSTS.clear
+ end
+ setup_proxyserver
+ str = ""
+ @client.wiredump_dev = str
+ @client.options["protocol.http.proxy"] = @proxyurl
+ assert_nil(@client.do_server_proc)
+ r, h = parse_req_header(str)
+ assert_match(%r"POST http://localhost:17171/ HTTP/1.", r)
+ ensure
+ if Object.const_defined?('HTTPAccess2')
+ HTTPAccess2::Client::NO_PROXY_HOSTS.replace(backup)
+ else
+ SOAP::NetHttpClient::NO_PROXY_HOSTS.replace(backup)
+ end
+ end
+
+ def test_charset
+ str = ""
+ @client.wiredump_dev = str
+ @client.options["protocol.http.charset"] = "iso-8859-8"
+ assert_nil(@client.do_server_proc)
+ r, h = parse_req_header(str)
+ assert_equal("text/xml; charset=iso-8859-8", h["content-type"])
+ #
+ str.replace("")
+ @client.options["protocol.http.charset"] = "iso-8859-3"
+ assert_nil(@client.do_server_proc)
+ r, h = parse_req_header(str)
+ assert_equal("text/xml; charset=iso-8859-3", h["content-type"])
+ end
+end
+
+
+end