diff options
Diffstat (limited to 'ruby_1_8_6/test/wsdl/map')
-rw-r--r-- | ruby_1_8_6/test/wsdl/map/map.wsdl | 92 | ||||
-rw-r--r-- | ruby_1_8_6/test/wsdl/map/map.xml | 43 | ||||
-rw-r--r-- | ruby_1_8_6/test/wsdl/map/test_map.rb | 99 |
3 files changed, 234 insertions, 0 deletions
diff --git a/ruby_1_8_6/test/wsdl/map/map.wsdl b/ruby_1_8_6/test/wsdl/map/map.wsdl new file mode 100644 index 0000000000..e418a4cbbd --- /dev/null +++ b/ruby_1_8_6/test/wsdl/map/map.wsdl @@ -0,0 +1,92 @@ +<?xml version="1.0"?> +<definitions + name="map" + targetNamespace="urn:map" + xmlns:tns="urn:map" + xmlns:txd="urn:map" + xmlns="http://schemas.xmlsoap.org/wsdl/" + xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" + xmlns:xsd="http://www.w3.org/2001/XMLSchema" + xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" + xmlns:apachesoap="http://xml.apache.org/xml-soap"> + + <types> + <schema + xmlns="http://www.w3.org/2001/XMLSchema" + targetNamespace="http://xml.apache.org/xml-soap"> + <complexType name="Map"> + <sequence> + <element name="item" minOccurs="0" maxOccurs="unbounded"> + <complexType> + <sequence> + <element name="key" type="xsd:anyType" /> + <element name="value" type="xsd:anyType" /> + </sequence> + </complexType> + </element> + </sequence> + </complexType> + </schema> + </types> + + <message name="mapRequest"/> + <message name="mapResponse"> + <part name="return" type="apachesoap:Map"/> + </message> + + <message name="map2Request"> + <part name="arg" type="apachesoap:Map"/> + </message> + <message name="map2Response"> + <part name="return" type="apachesoap:Map"/> + </message> + + <portType name="MapServicePortType"> + <operation name="map" parameterOrder=""> + <input message="tns:mapRequest"/> + <output message="tns:mapResponse"/> + </operation> + + <operation name="map2" parameterOrder=""> + <input message="tns:map2Request"/> + <output message="tns:map2Response"/> + </operation> + </portType> + + <binding name="MapServicePortBinding" type="tns:MapServicePortType"> + <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> + <operation name="map"> + <soap:operation soapAction=""/> + <input> + <soap:body use="encoded" + encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" + namespace="urn:map"/> + </input> + <output> + <soap:body use="encoded" + encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" + namespace="urn:map"/> + </output> + </operation> + + <operation name="map2"> + <soap:operation soapAction=""/> + <input> + <soap:body use="encoded" + encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" + namespace="urn:map"/> + </input> + <output> + <soap:body use="encoded" + encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" + namespace="urn:map"/> + </output> + </operation> + </binding> + + <service name="MapService"> + <port name="MapServicePort" binding="tns:MapServicePortBinding"> + <soap:address location="http://raa.ruby-lang.org/soap/1.0.2/"/> + </port> + </service> +</definitions> diff --git a/ruby_1_8_6/test/wsdl/map/map.xml b/ruby_1_8_6/test/wsdl/map/map.xml new file mode 100644 index 0000000000..7106735ffc --- /dev/null +++ b/ruby_1_8_6/test/wsdl/map/map.xml @@ -0,0 +1,43 @@ +<?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> + <n2:mapResponse xmlns:n1="http://schemas.xmlsoap.org/soap/encoding/" xmlns:n2="http://www.ruby-lang.org/xmlns/soap/interface/RAA/0.0.2/" env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> + <return xmlns:n3="http://xml.apache.org/xml-soap" xsi:type="n3:Map"> + <item> + <key xsi:type="xsd:string">a</key> + <value xsi:type="n3:Map"> + <item> + <key xsi:type="xsd:string">a1</key> + <value xsi:type="n1:Array" n1:arrayType="xsd:anyType[1]"> + <item xsi:type="xsd:string">a1</item> + </value> + </item> + <item> + <key xsi:type="xsd:string">a2</key> + <value xsi:type="n1:Array" n1:arrayType="xsd:anyType[1]"> + <item xsi:type="xsd:string">a2</item> + </value> + </item> + </value> + </item> + <item> + <key xsi:type="xsd:string">b</key> + <value xsi:type="n3:Map"> + <item> + <key xsi:type="xsd:string">b1</key> + <value xsi:type="n1:Array" n1:arrayType="xsd:anyType[1]"> + <item xsi:type="xsd:string">b1</item> + </value> + </item> + <item> + <key xsi:type="xsd:string">b2</key> + <value xsi:type="n1:Array" n1:arrayType="xsd:anyType[1]"> + <item xsi:type="xsd:string">b2</item> + </value> + </item> + </value> + </item> + </return> + </n2:mapResponse> + </env:Body> +</env:Envelope> diff --git a/ruby_1_8_6/test/wsdl/map/test_map.rb b/ruby_1_8_6/test/wsdl/map/test_map.rb new file mode 100644 index 0000000000..68f7d76e05 --- /dev/null +++ b/ruby_1_8_6/test/wsdl/map/test_map.rb @@ -0,0 +1,99 @@ +require 'test/unit' +require 'soap/rpc/httpserver' +require 'soap/wsdlDriver' + + +module WSDL + + +class TestMap < Test::Unit::TestCase + Port = 17171 + DIR = File.dirname(File.expand_path(__FILE__)) + + class Server < ::SOAP::RPC::HTTPServer + def on_init + add_method(self, 'map') + add_method(self, 'map2', 'arg') + end + + def map + {1 => "a", 2 => "b"} + end + + def map2(arg) + arg + end + end + + def setup + setup_server + setup_client + end + + def setup_server + @server = Server.new( + :BindAddress => "0.0.0.0", + :Port => Port, + :AccessLog => [], + :SOAPDefaultNamespace => "urn:map" + ) + @server.level = Logger::Severity::ERROR + @t = Thread.new { + Thread.current.abort_on_exception = true + @server.start + } + end + + def setup_client + wsdl = File.join(DIR, 'map.wsdl') + @client = ::SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver + @client.endpoint_url = "http://localhost:#{Port}/" + @client.generate_explicit_type = true + @client.wiredump_dev = STDOUT if $DEBUG + end + + def teardown + teardown_server + teardown_client + end + + def teardown_server + @server.shutdown + @t.kill + @t.join + end + + def teardown_client + @client.reset_stream + end + + def test_by_wsdl + dir = File.dirname(File.expand_path(__FILE__)) + wsdlfile = File.join(dir, 'map.wsdl') + xml = File.open(File.join(dir, 'map.xml')) { |f| f.read } + wsdl = WSDL::Importer.import(wsdlfile) + service = wsdl.services[0] + port = service.ports[0] + wsdl_types = wsdl.collect_complextypes + rpc_decode_typemap = wsdl_types + wsdl.soap_rpc_complextypes(port.find_binding) + opt = {} + opt[:default_encodingstyle] = ::SOAP::EncodingNamespace + opt[:decode_typemap] = rpc_decode_typemap + header, body = ::SOAP::Processor.unmarshal(xml, opt) + map = ::SOAP::Mapping.soap2obj(body.response) + assert_equal(["a1"], map["a"]["a1"]) + assert_equal(["a2"], map["a"]["a2"]) + assert_equal(["b1"], map["b"]["b1"]) + assert_equal(["b2"], map["b"]["b2"]) + end + + def test_wsdldriver + assert_equal({1 => "a", 2 => "b"}, @client.map) + assert_equal({1 => 2}, @client.map2({1 => 2})) + assert_equal({1 => {2 => 3}}, @client.map2({1 => {2 => 3}})) + assert_equal({["a", 2] => {2 => 3}}, @client.map2({["a", 2] => {2 => 3}})) + end +end + + +end |