diff options
author | nahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-11-30 04:33:02 +0000 |
---|---|---|
committer | nahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-11-30 04:33:02 +0000 |
commit | d268bf305e926b5418d843098e35462cf97df662 (patch) | |
tree | 4268267cc8e52a533e4c78490ce6c2009971f972 /test/wsdl | |
parent | 165d101eed53d09aa614d93557b077305a52006b (diff) |
* lib/soap/encodingstyle/soapHandler.rb: refactoring - Simplifying
Conditional Expressions.
* lib/wsdl/soap/definitions.rb: refactoring - Move Method.
* test/xsd/{test_noencoding.rb,noencoding.xml}: new files. test for
encoding unspecified XML file parsing.
* test/wsdl/{test_fault.rb,map,datetime}: new files. test of
SOAPFault, dateTime and Apache's Map.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5060 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/wsdl')
-rw-r--r-- | test/wsdl/datetime/DatetimeService.rb | 38 | ||||
-rw-r--r-- | test/wsdl/datetime/datetime.rb | 0 | ||||
-rw-r--r-- | test/wsdl/datetime/datetime.wsdl | 45 | ||||
-rw-r--r-- | test/wsdl/datetime/datetimeServant.rb | 21 | ||||
-rw-r--r-- | test/wsdl/datetime/test_datetime.rb | 81 | ||||
-rw-r--r-- | test/wsdl/map/map.wsdl | 66 | ||||
-rw-r--r-- | test/wsdl/map/map.xml | 43 | ||||
-rw-r--r-- | test/wsdl/map/test_map.rb | 37 | ||||
-rw-r--r-- | test/wsdl/test_fault.rb | 51 |
9 files changed, 382 insertions, 0 deletions
diff --git a/test/wsdl/datetime/DatetimeService.rb b/test/wsdl/datetime/DatetimeService.rb new file mode 100644 index 0000000000..91c006005d --- /dev/null +++ b/test/wsdl/datetime/DatetimeService.rb @@ -0,0 +1,38 @@ +#!/usr/bin/env ruby +require 'datetimeServant.rb' + +require 'soap/rpc/standaloneServer' + +class DatetimePortType + MappingRegistry = SOAP::Mapping::Registry.new + + # No mapping definition + + Methods = [ + ["now", "now", [ + ["in", "now", + [SOAP::SOAPDateTime]], + ["retval", "now", + [SOAP::SOAPDateTime]]], "", "urn:jp.gr.jin.rrr.example.datetime"] + ] +end + +class DatetimePortTypeApp < SOAP::RPC::StandaloneServer + def initialize(*arg) + super + + servant = DatetimePortType.new + DatetimePortType::Methods.each do |name_as, name, params, soapaction, namespace| + qname = XSD::QName.new(namespace, name_as) + @soaplet.app_scope_router.add_method(servant, qname, soapaction, + name, params) + end + + self.mapping_registry = DatetimePortType::MappingRegistry + end +end + +# Change listen port. +if $0 == __FILE__ + DatetimePortTypeApp.new('app', nil, '0.0.0.0', 10080).start +end diff --git a/test/wsdl/datetime/datetime.rb b/test/wsdl/datetime/datetime.rb new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/test/wsdl/datetime/datetime.rb diff --git a/test/wsdl/datetime/datetime.wsdl b/test/wsdl/datetime/datetime.wsdl new file mode 100644 index 0000000000..4998dc48d6 --- /dev/null +++ b/test/wsdl/datetime/datetime.wsdl @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="UTF-8"?> +<wsdl:definitions name = "datetime" + targetNamespace="urn:jp.gr.jin.rrr.example.datetime" + xmlns:tns="urn:jp.gr.jin.rrr.example.datetime" + xmlns="http://schemas.xmlsoap.org/wsdl/" + xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" + xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" + xmlns:xsd="http://www.w3.org/2001/XMLSchema"> + + <wsdl:message name="nowRequest"> + <wsdl:part name="now" type="xsd:dateTime"/> + </wsdl:message> + + <wsdl:message name="nowResponse"> + <wsdl:part name="now" type="xsd:dateTime"/> + </wsdl:message> + + <wsdl:portType name="DatetimePortType"> + <wsdl:operation name="now"> + <wsdl:input message="tns:nowRequest" name="nowRequest"/> + <wsdl:output message="tns:nowResponse" name="nowResponse"/> + </wsdl:operation> + </wsdl:portType> + + <wsdl:binding name="DatetimeBinding" type="tns:DatetimePortType"> + <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> + <wsdl:operation name="now"> + <soap:operation soapAction=""/> + <wsdl:input name="nowRequest"> + <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" + namespace="urn:jp.gr.jin.rrr.example.datetime" use="encoded"/> + </wsdl:input> + <wsdl:output name="nowResponse"> + <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" + namespace="urn:jp.gr.jin.rrr.example.datetime" use="encoded"/> + </wsdl:output> + </wsdl:operation> + </wsdl:binding> + + <wsdl:service name="DatetimeService"> + <wsdl:port binding="tns:DatetimeBinding" name="DatetimePort"> + <soap:address location="http://localhost:10080/"/> + </wsdl:port> + </wsdl:service> +</wsdl:definitions> diff --git a/test/wsdl/datetime/datetimeServant.rb b/test/wsdl/datetime/datetimeServant.rb new file mode 100644 index 0000000000..14145c42e5 --- /dev/null +++ b/test/wsdl/datetime/datetimeServant.rb @@ -0,0 +1,21 @@ +require 'datetime.rb' + +class DatetimePortType + # SYNOPSIS + # now(now) + # + # ARGS + # now - {http://www.w3.org/2001/XMLSchema}dateTime + # + # RETURNS + # now - {http://www.w3.org/2001/XMLSchema}dateTime + # + # RAISES + # (undefined) + # + def now(now) + #raise NotImplementedError.new + now + 1 + end +end + diff --git a/test/wsdl/datetime/test_datetime.rb b/test/wsdl/datetime/test_datetime.rb new file mode 100644 index 0000000000..a60d9b70a0 --- /dev/null +++ b/test/wsdl/datetime/test_datetime.rb @@ -0,0 +1,81 @@ +require 'test/unit' +require 'soap/wsdlDriver' + + +module WSDL +module Datetime + + +class TestDatetime < Test::Unit::TestCase + DIR = File.dirname(File.expand_path(__FILE__)) + + Port = 17171 + + def setup + setup_server + setup_client + end + + def setup_server + $:.push(DIR) + require File.join(DIR, 'DatetimeService.rb') + $:.delete(DIR) + @server = DatetimePortTypeApp.new('Datetime server', nil, '0.0.0.0', Port) + @server.level = Logger::Severity::ERROR + @t = Thread.new { + Thread.current.abort_on_exception = true + @server.start + } + while @server.server.nil? or @server.server.status != :Running + sleep 0.1 + unless @t.alive? + @t.join + raise + end + end + end + + def setup_client + wsdl = File.join(DIR, 'datetime.wsdl') + @client = ::SOAP::WSDLDriverFactory.new(wsdl).create_driver + @client.endpoint_url = "http://localhost:#{Port}/" + @client.generate_explicit_type = true + end + + def teardown + teardown_server + teardown_client + end + + def teardown_server + @server.server.shutdown + @t.kill + @t.join + end + + def teardown_client + @client.reset_stream + end + + def test_datetime + d = DateTime.now + assert_equal(d + 1, @client.now(d)) + end + + def test_time + d = DateTime.now + t = Time.gm(d.year, d.month, d.day, d.hour, d.min, d.sec) + d2 = d + 1 + t2 = @client.now(t) + assert_equal(d2.year, t2.year) + assert_equal(d2.month, t2.month) + assert_equal(d2.day, t2.day) + assert_equal(d2.hour, t2.hour) + assert_equal(d2.min, t2.min) + assert_equal(d2.sec, t2.sec) + end +end + + +end +end diff --git a/test/wsdl/map/map.wsdl b/test/wsdl/map/map.wsdl new file mode 100644 index 0000000000..7b1a140827 --- /dev/null +++ b/test/wsdl/map/map.wsdl @@ -0,0 +1,66 @@ +<?xml version="1.0"?> +<definitions + name="RAA" + targetNamespace="http://www.ruby-lang.org/xmlns/soap/interface/RAA/0.0.2/" + xmlns:tns="http://www.ruby-lang.org/xmlns/soap/interface/RAA/0.0.2/" + xmlns:txd="http://www.ruby-lang.org/xmlns/soap/interface/RAA/0.0.2/" + 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="anyType" /> + <element name="value" type="anyType" /> + </sequence> + </complexType> + </element> + </sequence> + </complexType> + </schema> + </types> + + <message name="mapRequest"/> + <message name="mapResponse"> + <part name="return" type="apachesoap:Map"/> + </message> + + <portType name="RAABaseServicePortType"> + <operation name="map" parameterOrder=""> + <input message="tns:mapRequest"/> + <output message="tns:mapResponse"/> + </operation> + </portType> + + <binding name="RAABaseServicePortBinding" type="tns:RAABaseServicePortType"> + <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="http://www.ruby-lang.org/xmlns/soap/interface/RAA/0.0.2/"/> + </input> + <output> + <soap:body use="encoded" + encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" + namespace="http://www.ruby-lang.org/xmlns/soap/interface/RAA/0.0.2/"/> + </output> + </operation> + </binding> + + <service name="RAAService"> + <port name="RAABaseServicePort" binding="tns:RAABaseServicePortBinding"> + <soap:address location="http://raa.ruby-lang.org/soap/1.0.2/"/> + </port> + </service> +</definitions> diff --git a/test/wsdl/map/map.xml b/test/wsdl/map/map.xml new file mode 100644 index 0000000000..7106735ffc --- /dev/null +++ b/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/test/wsdl/map/test_map.rb b/test/wsdl/map/test_map.rb new file mode 100644 index 0000000000..b0f2fb5a53 --- /dev/null +++ b/test/wsdl/map/test_map.rb @@ -0,0 +1,37 @@ +require 'test/unit' +require 'soap/processor' +require 'soap/mapping' +require 'soap/rpc/element' +require 'wsdl/importer' + + +module WSDL + + +class TestMap < Test::Unit::TestCase + def setup + 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 +end + + +end diff --git a/test/wsdl/test_fault.rb b/test/wsdl/test_fault.rb new file mode 100644 index 0000000000..ec414528ee --- /dev/null +++ b/test/wsdl/test_fault.rb @@ -0,0 +1,51 @@ +require 'test/unit' +require 'soap/processor' +require 'soap/mapping' +require 'soap/rpc/element' +require 'wsdl/parser' + + +module WSDL + + +class TestFault < Test::Unit::TestCase + def setup + @xml =<<__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> + <env:Fault xmlns:n1="http://schemas.xmlsoap.org/soap/encoding/" + env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> + <faultcode xsi:type="xsd:string">Server</faultcode> + <faultstring xsi:type="xsd:string">faultstring</faultstring> + <faultactor xsi:type="xsd:string">faultactor</faultactor> + <detail xmlns:n2="http://www.ruby-lang.org/xmlns/ruby/type/custom" + xsi:type="n2:SOAPException"> + <excn_type_name xsi:type="xsd:string">type</excn_type_name> + <cause href="#id123"/> + </detail> + </env:Fault> + <cause id="id123" xsi:type="xsd:int">5</cause> + </env:Body> +</env:Envelope> +__EOX__ + end + + def test_by_wsdl + rpc_decode_typemap = WSDL::Definitions.soap_rpc_complextypes + opt = {} + opt[:default_encodingstyle] = ::SOAP::EncodingNamespace + opt[:decode_typemap] = rpc_decode_typemap + header, body = ::SOAP::Processor.unmarshal(@xml, opt) + fault = ::SOAP::Mapping.soap2obj(body.response) + assert_equal("Server", fault.faultcode) + assert_equal("faultstring", fault.faultstring) + assert_equal(URI.parse("faultactor"), fault.faultactor) + assert_equal(5, fault.detail.cause) + end +end + + +end |