Welcome to the "trac"-ing site of soap4r!
[soap4r] [httpclient] [openpgp4u] [pkcs1] [logger] [csv] [vtr]

root/trunk/test/wsdl/axisArray/test_axisarray.rb

Revision 1958, 4.9 kB (checked in by nahi, 1 year ago)
  • Property svn:eol-style set to native
  • Property svn:keywords set to author date id revision
Line 
1 require 'test/unit'
2 require 'soap/processor'
3 require 'soap/mapping'
4 require 'soap/rpc/element'
5 require 'wsdl/importer'
6 require 'wsdl/soap/wsdl2ruby'
7 require File.join(File.dirname(File.expand_path(__FILE__)), '..', '..', 'testutil.rb')
8
9
10 module WSDL
11 module AxisArray
12
13
14 class TestAxisArray < Test::Unit::TestCase
15   DIR = File.dirname(File.expand_path(__FILE__))
16
17   def setup
18     @xml =<<__EOX__
19 <?xml version="1.0" encoding="UTF-8"?>
20 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
21   <soapenv:Body>
22     <ns1:listItemResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="urn:jp.gr.jin.rrr.example.itemList">
23       <list href="#id0"/>
24     </ns1:listItemResponse>
25     <multiRef id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns2:ItemList" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2="urn:jp.gr.jin.rrr.example.itemListType">
26       <Item href="#id1"/>
27       <Item href="#id2"/>
28       <Item href="#id3"/>
29     </multiRef>
30     <multiRef id="id3" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns3:Item" xmlns:ns3="urn:jp.gr.jin.rrr.example.itemListType" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
31       <name xsi:type="xsd:string">name3</name>
32     </multiRef>
33     <multiRef id="id1" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns4:Item" xmlns:ns4="urn:jp.gr.jin.rrr.example.itemListType" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
34       <name xsi:type="xsd:string">name1</name>
35     </multiRef>
36     <multiRef id="id2" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns5:Item" xmlns:ns5="urn:jp.gr.jin.rrr.example.itemListType" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
37       <name xsi:type="xsd:string">name2</name>
38     </multiRef>
39   </soapenv:Body>
40 </soapenv:Envelope>
41 __EOX__
42     setup_classdef
43   end
44
45   def teardown
46     unless $DEBUG
47       File.unlink(pathname('itemList.rb'))
48       File.unlink(pathname('itemListMappingRegistry.rb'))
49       File.unlink(pathname('itemListDriver.rb'))
50     end
51   end
52
53   def setup_classdef
54     gen = WSDL::SOAP::WSDL2Ruby.new
55     gen.location = pathname("axisArray.wsdl")
56     gen.basedir = DIR
57     gen.logger.level = Logger::FATAL
58     gen.opt['classdef'] = nil
59     gen.opt['mapping_registry'] = nil
60     gen.opt['module_path'] = self.class.to_s.sub(/::[^:]+$/, '')
61     gen.opt['driver'] = nil
62     gen.opt['force'] = true
63     gen.run
64     TestUtil.require(DIR, 'itemListDriver.rb', 'itemList.rb', 'itemListMappingRegistry.rb')
65   end
66
67   def test_by_stub
68     driver = ItemListPortType.new
69     driver.test_loopback_response << @xml
70     ary = driver.listItem
71     assert_equal(3, ary.size)
72     assert_equal("name1", ary[0].name)
73     assert_equal("name2", ary[1].name)
74     assert_equal("name3", ary[2].name)
75   end
76
77   def test_by_wsdl
78     wsdlfile = File.join(File.dirname(File.expand_path(__FILE__)), 'axisArray.wsdl')
79     wsdl = WSDL::Importer.import(wsdlfile)
80     service = wsdl.services[0]
81     port = service.ports[0]
82     wsdl_types = wsdl.collect_complextypes
83     rpc_decode_typemap = wsdl_types + wsdl.soap_rpc_complextypes(port.find_binding)
84     opt = {}
85     opt[:default_encodingstyle] = ::SOAP::EncodingNamespace
86     opt[:decode_typemap] = rpc_decode_typemap
87     header, body = ::SOAP::Processor.unmarshal(@xml, opt)
88     ary = ::SOAP::Mapping.soap2obj(body.response)
89     assert_equal(3, ary.size)
90     assert_equal("name1", ary[0].name)
91     assert_equal("name2", ary[1].name)
92     assert_equal("name3", ary[2].name)
93   end
94
95 XML_LONG = <<__XML__
96 <?xml version="1.0" encoding="utf-8"?>
97 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
98   <soapenv:Body>
99     <ns1:getMeetingInfoResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="urn:jp.gr.jin.rrr.example.itemList">
100       <getMeetingInfoReturn href="#id0"/>
101     </ns1:getMeetingInfoResponse>
102     <multiRef id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns2:MeetingInfo" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2="urn:long">
103       <meetingId href="#id11"/>
104     </multiRef>
105     <multiRef id="id11" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="xsd:long" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">105759347</multiRef>
106   </soapenv:Body>
107 </soapenv:Envelope>
108 __XML__
109
110   def test_multiref_long
111     driver = ItemListPortType.new
112     driver.test_loopback_response << XML_LONG
113     ret = driver.getMeetingInfo
114     assert_equal(105759347, ret.meetingId)
115   end
116
117   def pathname(filename)
118     File.join(DIR, filename)
119   end
120 end
121
122
123 end
124 end
Note: See TracBrowser for help on using the browser.