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

root/trunk/test/soap/test_custom_ns.rb

Revision 1975, 3.1 kB (checked in by nahi, 1 year ago)
  • XML attribute must not be affected by default namespace. closes #430.
Line 
1 require 'test/unit'
2 require 'soap/processor'
3
4
5 module SOAP
6
7
8 class TestCustomNs < Test::Unit::TestCase
9   NORMAL_XML = <<__XML__.chomp
10 <?xml version="1.0" encoding="utf-8" ?>
11 <env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
12     xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
13     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
14   <env:Header>
15       <n1:headeritem xmlns:n1="my:foo">hi</n1:headeritem>
16   </env:Header>
17   <env:Body>
18     <n2:test xmlns:n2="my:foo"
19         xmlns:n3="my:bar"
20         n3:baz="qux">bi</n2:test>
21   </env:Body>
22 </env:Envelope>
23 __XML__
24
25   CUSTOM_NS_XML = <<__XML__.chomp
26 <?xml version="1.0" encoding="utf-8" ?>
27 <ENV:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
28     xmlns:myns="my:foo"
29     xmlns:ENV="http://schemas.xmlsoap.org/soap/envelope/"
30     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
31   <ENV:Header>
32       <myns:headeritem>hi</myns:headeritem>
33   </ENV:Header>
34   <ENV:Body>
35     <myns:test xmlns:bar="my:bar"
36         bar:baz="qux">bi</myns:test>
37   </ENV:Body>
38 </ENV:Envelope>
39 __XML__
40
41   XML_WITH_DEFAULT_NS = <<__XML__.chomp
42 <?xml version="1.0" encoding="utf-8" ?>
43 <env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
44     xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
45     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
46   <env:Header>
47       <headeritem xmlns="my:foo">hi</headeritem>
48   </env:Header>
49   <env:Body>
50     <test xmlns:n1="my:bar"
51         xmlns:n2="my:foo"
52         n1:baz="qux"
53         n2:quxx="quxxx"
54         xmlns="my:foo">bi</test>
55   </env:Body>
56 </env:Envelope>
57 __XML__
58
59   def test_custom_ns
60     # create test env
61     header = SOAP::SOAPHeader.new()
62     hi = SOAP::SOAPElement.new(XSD::QName.new("my:foo", "headeritem"), 'hi')
63     header.add("test", hi)
64     body = SOAP::SOAPBody.new()
65     bi = SOAP::SOAPElement.new(XSD::QName.new("my:foo", "bodyitem"), 'bi')
66     bi.extraattr[XSD::QName.new('my:bar', 'baz')] = 'qux'
67     body.add("test", bi)
68     env = SOAP::SOAPEnvelope.new(header, body)
69     # normal
70     opt = {}
71     result = SOAP::Processor.marshal(env, opt)
72     assert_equal(NORMAL_XML, result)
73     # Envelope ns customize
74     env = SOAP::SOAPEnvelope.new(header, body)
75     ns = XSD::NS.new
76     ns.assign(SOAP::EnvelopeNamespace, 'ENV')
77     ns.assign('my:foo', 'myns')
78     # tag customize
79     tag = XSD::NS.new
80     tag.assign('my:bar', 'bar')
81     opt = { :default_ns => ns, :default_ns_tag => tag }
82     result = SOAP::Processor.marshal(env, opt)
83     assert_equal(CUSTOM_NS_XML, result)
84   end
85
86   def test_default_namespace
87     # create test env
88     header = SOAP::SOAPHeader.new()
89     hi = SOAP::SOAPElement.new(XSD::QName.new("my:foo", "headeritem"), 'hi')
90     header.add("test", hi)
91     body = SOAP::SOAPBody.new()
92     bi = SOAP::SOAPElement.new(XSD::QName.new("my:foo", "bodyitem"), 'bi')
93     bi.extraattr[XSD::QName.new('my:bar', 'baz')] = 'qux'
94     bi.extraattr[XSD::QName.new('my:foo', 'quxx')] = 'quxxx'
95     body.add("test", bi)
96     env = SOAP::SOAPEnvelope.new(header, body)
97     # normal
98     opt = {:use_default_namespace => true}
99     result = SOAP::Processor.marshal(env, opt)
100     assert_equal(XML_WITH_DEFAULT_NS, result)
101   end
102 end
103
104
105 end
Note: See TracBrowser for help on using the browser.