| 1 |
require 'test/unit' |
|---|
| 2 |
require 'soap/wsdlDriver' |
|---|
| 3 |
require 'wsdl/soap/wsdl2ruby' |
|---|
| 4 |
require File.join(File.dirname(File.expand_path(__FILE__)), '..', '..', 'testutil.rb') |
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
module WSDL |
|---|
| 8 |
module RAA |
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
class TestRAA < Test::Unit::TestCase |
|---|
| 12 |
DIR = File.dirname(File.expand_path(__FILE__)) |
|---|
| 13 |
|
|---|
| 14 |
Port = 17171 |
|---|
| 15 |
|
|---|
| 16 |
def setup |
|---|
| 17 |
setup_stub |
|---|
| 18 |
setup_server |
|---|
| 19 |
setup_client |
|---|
| 20 |
end |
|---|
| 21 |
|
|---|
| 22 |
def setup_stub |
|---|
| 23 |
gen = WSDL::SOAP::WSDL2Ruby.new |
|---|
| 24 |
gen.location = pathname("raa.wsdl") |
|---|
| 25 |
gen.basedir = DIR |
|---|
| 26 |
gen.logger.level = Logger::FATAL |
|---|
| 27 |
gen.opt['module_path'] = self.class.to_s.sub(/::[^:]+$/, '') |
|---|
| 28 |
gen.opt['classdef'] = nil |
|---|
| 29 |
gen.opt['mapping_registry'] = nil |
|---|
| 30 |
gen.opt['driver'] = nil |
|---|
| 31 |
gen.opt['force'] = true |
|---|
| 32 |
gen.run |
|---|
| 33 |
TestUtil.require(DIR, 'RAADriver.rb', 'RAAMappingRegistry.rb', 'RAA.rb') |
|---|
| 34 |
end |
|---|
| 35 |
|
|---|
| 36 |
def setup_server |
|---|
| 37 |
require pathname('RAAService.rb') |
|---|
| 38 |
@server = RAABaseServicePortTypeApp.new('RAA server', nil, '0.0.0.0', Port) |
|---|
| 39 |
@server.level = Logger::Severity::ERROR |
|---|
| 40 |
@t = Thread.new { |
|---|
| 41 |
Thread.current.abort_on_exception = true |
|---|
| 42 |
@server.start |
|---|
| 43 |
} |
|---|
| 44 |
end |
|---|
| 45 |
|
|---|
| 46 |
def setup_client |
|---|
| 47 |
wsdl = File.join(DIR, 'raa.wsdl') |
|---|
| 48 |
@raa = ::SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver |
|---|
| 49 |
@raa.endpoint_url = "http://localhost:#{Port}/" |
|---|
| 50 |
@raa.wiredump_dev = STDOUT if $DEBUG |
|---|
| 51 |
@raa.mapping_registry = RAAMappingRegistry::EncodedRegistry |
|---|
| 52 |
@raa.literal_mapping_registry = RAAMappingRegistry::LiteralRegistry |
|---|
| 53 |
end |
|---|
| 54 |
|
|---|
| 55 |
def teardown |
|---|
| 56 |
teardown_server if @server |
|---|
| 57 |
teardown_client if @client |
|---|
| 58 |
unless $DEBUG |
|---|
| 59 |
File.unlink(pathname('RAA.rb')) |
|---|
| 60 |
File.unlink(pathname('RAAMappingRegistry.rb')) |
|---|
| 61 |
File.unlink(pathname('RAADriver.rb')) |
|---|
| 62 |
end |
|---|
| 63 |
end |
|---|
| 64 |
|
|---|
| 65 |
def teardown_server |
|---|
| 66 |
@server.shutdown |
|---|
| 67 |
@t.kill |
|---|
| 68 |
@t.join |
|---|
| 69 |
end |
|---|
| 70 |
|
|---|
| 71 |
def teardown_client |
|---|
| 72 |
@raa.reset_stream |
|---|
| 73 |
end |
|---|
| 74 |
|
|---|
| 75 |
def test_stubgeneration |
|---|
| 76 |
compare("expectedClassDef.rb", "RAA.rb") |
|---|
| 77 |
compare("expectedMappingRegistry.rb", "RAAMappingRegistry.rb") |
|---|
| 78 |
compare("expectedDriver.rb", "RAADriver.rb") |
|---|
| 79 |
end |
|---|
| 80 |
|
|---|
| 81 |
def test_raa |
|---|
| 82 |
do_test_raa(@raa) |
|---|
| 83 |
end |
|---|
| 84 |
|
|---|
| 85 |
def test_stub |
|---|
| 86 |
client = RAABaseServicePortType.new("http://localhost:#{Port}/") |
|---|
| 87 |
do_test_raa(client) |
|---|
| 88 |
end |
|---|
| 89 |
|
|---|
| 90 |
def do_test_raa(client) |
|---|
| 91 |
assert_equal(["ruby", "soap4r"], client.getAllListings) |
|---|
| 92 |
info = client.getInfoFromName("SOAP4R") |
|---|
| 93 |
assert_equal(Info, info.class) |
|---|
| 94 |
assert_equal(Category, info.category.class) |
|---|
| 95 |
assert_equal(Product, info.product.class) |
|---|
| 96 |
assert_equal(Owner, info.owner.class) |
|---|
| 97 |
assert_equal("major", info.category.major) |
|---|
| 98 |
assert_equal("minor", info.category.minor) |
|---|
| 99 |
assert_equal(123, info.product.id) |
|---|
| 100 |
assert_equal("SOAP4R", info.product.name) |
|---|
| 101 |
assert_equal("short description", info.product.short_description) |
|---|
| 102 |
assert_equal("version", info.product.version) |
|---|
| 103 |
assert_equal("status", info.product.status) |
|---|
| 104 |
assert_equal("http://example.com/homepage", info.product.homepage.to_s) |
|---|
| 105 |
assert_equal("http://example.com/download", info.product.download.to_s) |
|---|
| 106 |
assert_equal("license", info.product.license) |
|---|
| 107 |
assert_equal("description", info.product.description) |
|---|
| 108 |
assert_equal(456, info.owner.id) |
|---|
| 109 |
assert_equal("mailto:email@example.com", info.owner.email.to_s) |
|---|
| 110 |
assert_equal("name", info.owner.name) |
|---|
| 111 |
assert(!info.created.nil?) |
|---|
| 112 |
assert(!info.updated.nil?) |
|---|
| 113 |
end |
|---|
| 114 |
|
|---|
| 115 |
def compare(expected, actual) |
|---|
| 116 |
TestUtil.filecompare(pathname(expected), pathname(actual)) |
|---|
| 117 |
end |
|---|
| 118 |
|
|---|
| 119 |
def pathname(filename) |
|---|
| 120 |
File.join(DIR, filename) |
|---|
| 121 |
end |
|---|
| 122 |
end |
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
end |
|---|
| 126 |
end |
|---|