File: test_mapping.rb

package info (click to toggle)
ruby-soap4r 2.0.5-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,032 kB
  • sloc: ruby: 52,729; xml: 266; sh: 42; javascript: 20; makefile: 13; perl: 10
file content (131 lines) | stat: -rw-r--r-- 3,030 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
require 'test/unit'
require 'soap/mapping'
require 'soap/marshal'


module SOAP


class TestMapping < Test::Unit::TestCase

  class MappablePerson
    attr_reader :name
    attr_reader :age

    def initialize(name, age)
      @name, @age = name, age
    end

    def self.soap_marshallable
      true
    end
  end

  class UnmappablePerson
    attr_reader :name
    attr_reader :age

    def initialize(name, age)
      @name, @age = name, age
    end

    def self.soap_marshallable
      false
    end
  end

  def test_mappable
    xml = <<__XML__
<?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>
    <SOAP..TestMapping..MappablePerson env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
      <name>nahi</name>
      <age>37</age>
    </SOAP..TestMapping..MappablePerson>
  </env:Body>
</env:Envelope>
__XML__
    obj = SOAP::Marshal.load(xml)
    assert_equal(SOAP::TestMapping::MappablePerson, obj.class)
    #
    xml = <<__XML__
<?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>
    <SOAP..TestMapping..UnmappablePerson env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
      <name>nahi</name>
      <age>37</age>
    </SOAP..TestMapping..UnmappablePerson>
  </env:Body>
</env:Envelope>
__XML__
    obj = SOAP::Marshal.load(xml)
    assert_equal(SOAP::Mapping::Object, obj.class)
  end

  def test_nestedexception
    ele = Thread.new {}
    obj = [ele]
    begin
      SOAP::Marshal.dump(obj)
    rescue ::SOAP::Mapping::MappingError => e
      assert(e.backtrace.find { |line| /\[NESTED\]/ =~ line })
    end
  end

  def test_date
    targets = [
      ["2002-12-31",
	"2002-12-31Z"],
      ["2002-12-31+00:00",
	"2002-12-31Z"],
      ["2002-12-31-00:00",
	"2002-12-31Z"],
      ["-2002-12-31",
	"-2002-12-31Z"],
      ["-2002-12-31+00:00",
	"-2002-12-31Z"],
      ["-2002-12-31-00:00",
	"-2002-12-31Z"],
    ]
    targets.each do |str, expectec|
      d = Date.parse(str)
      assert_equal(d.class, convert(d).class)
      assert_equal(d, convert(d))
    end
  end

  def test_datetime
    targets = [
      ["2002-12-31T23:59:59.00",
	"2002-12-31T23:59:59Z"],
      ["2002-12-31T23:59:59+00:00",
	"2002-12-31T23:59:59Z"],
      ["2002-12-31T23:59:59-00:00",
	"2002-12-31T23:59:59Z"],
      ["-2002-12-31T23:59:59.00",
	"-2002-12-31T23:59:59Z"],
      ["-2002-12-31T23:59:59+00:00",
	"-2002-12-31T23:59:59Z"],
      ["-2002-12-31T23:59:59-00:00",
	"-2002-12-31T23:59:59Z"],
    ]
    targets.each do |str, expectec|
      d = DateTime.parse(str)
      assert_equal(d.class, convert(d).class)
      assert_equal(d, convert(d))
    end
  end

  def convert(obj)
    SOAP::Mapping.soap2obj(SOAP::Mapping.obj2soap(obj))
  end
end


end