summaryrefslogtreecommitdiff
path: root/ruby_1_8_6/test/soap/swa/test_file.rb
diff options
context:
space:
mode:
Diffstat (limited to 'ruby_1_8_6/test/soap/swa/test_file.rb')
-rw-r--r--ruby_1_8_6/test/soap/swa/test_file.rb73
1 files changed, 73 insertions, 0 deletions
diff --git a/ruby_1_8_6/test/soap/swa/test_file.rb b/ruby_1_8_6/test/soap/swa/test_file.rb
new file mode 100644
index 0000000000..1ec7aa92a7
--- /dev/null
+++ b/ruby_1_8_6/test/soap/swa/test_file.rb
@@ -0,0 +1,73 @@
+require 'test/unit'
+require 'soap/rpc/driver'
+require 'soap/rpc/standaloneServer'
+require 'soap/attachment'
+
+
+module SOAP
+module SWA
+
+
+class TestFile < Test::Unit::TestCase
+ Port = 17171
+ THIS_FILE = File.expand_path(__FILE__)
+
+ class SwAService
+ def get_file
+ return {
+ 'name' => $0,
+ 'file' => SOAP::Attachment.new(File.open(THIS_FILE)) # closed when GCed.
+ }
+ end
+
+ def put_file(name, file)
+ "File '#{name}' was received ok."
+ end
+ end
+
+ def setup
+ @server = SOAP::RPC::StandaloneServer.new('SwAServer',
+ 'http://www.acmetron.com/soap', '0.0.0.0', Port)
+ @server.add_servant(SwAService.new)
+ @server.level = Logger::Severity::ERROR
+ @t = Thread.new {
+ @server.start
+ }
+ @endpoint = "http://localhost:#{Port}/"
+ @client = SOAP::RPC::Driver.new(@endpoint, 'http://www.acmetron.com/soap')
+ @client.add_method('get_file')
+ @client.add_method('put_file', 'name', 'file')
+ @client.wiredump_dev = STDERR if $DEBUG
+ end
+
+ def teardown
+ @server.shutdown
+ @t.kill
+ @t.join
+ @client.reset_stream
+ end
+
+ def test_get_file
+ assert_equal(
+ File.open(THIS_FILE) { |f| f.read },
+ @client.get_file['file'].content
+ )
+ end
+
+ def test_put_file
+ assert_equal(
+ "File 'foo' was received ok.",
+ @client.put_file('foo',
+ SOAP::Attachment.new(File.open(THIS_FILE)))
+ )
+ assert_equal(
+ "File 'bar' was received ok.",
+ @client.put_file('bar',
+ SOAP::Attachment.new(File.open(THIS_FILE) { |f| f.read }))
+ )
+ end
+end
+
+
+end
+end