public
Description: the [OpenWFEru] workflow and BPM engine (ruby)
Homepage: http://openwferu.rubyforge.org
Clone URL: git://github.com/jmettraux/ruote.git
ruote / test / clone_test.rb
100644 169 lines (133 sloc) 3.247 kb
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#
# Testing OpenWFEru
#
# John Mettraux at openwfe.org
#
 
require 'test/unit'
require 'rexml/document'
 
require 'openwfe/utils'
require 'openwfe/workitem'
 
 
class FullDupTest < Test::Unit::TestCase
 
  #def setup
  #end
 
  #def teardown
  #end
 
  class MyClass
 
    attr_reader :name
 
    def initialize (name)
      @name = name
    end
  end
 
  def test_fulldup
 
    o0 = MyClass.new("cow")
 
    o1 = OpenWFE.fulldup(o0)
 
    assert_not_equal o0.object_id, o1.object_id
    assert_equal o0.name, o1.name
  end
 
  def test_yaml
 
    require 'yaml'
 
    o0 = MyClass.new("pig")
    o1 = YAML.load(o0.to_yaml)
 
    assert_not_equal o0.object_id, o1.object_id
    assert_equal o0.name, o1.name
  end
 
  def test_dup_0
    a0 = A.new
    a0.a = 1
    a0.b = 2
    a1 = OpenWFE::fulldup(a0)
 
    #puts a0
    #puts a1
 
    assert_equal a0, a1, "dup() utility not working"
  end
 
  def test_dup_1
    d = REXML::Document.new("<document/>")
    d1 = OpenWFE.fulldup(d)
    assert d.object_id != d1.object_id
  end
 
  def test_dup_2
    d = REXML::Document.new("<document>text</document>")
    d1 = OpenWFE::fulldup(d)
    assert d.object_id != d1.object_id
  end
 
  PAT_XML = <<END
<?xml version="1.0" encoding="UTF-8"?>
<sps:GetFeasibilityRequestResponse xmlns:gml="http://www.opengis.net/gml"
xmlns:sps="http://www.opengis.net/sps" xmlns="">
<sps:Feasibility status="feasible" id="106">
<DOY>106</DOY>
<UTC>2007-04-16 09:20:00</UTC>
<SZA>27.41</SZA>
<TYPE>NADIR</TYPE>
<PATH>52</PATH>
<ROW>186</ROW>
<COST>2600.85</COST>
<![CDATA[
<blah/>boum
]]>
<sps:LatestResponseTime>
<gml:TimeInstant>
<gml:timePosition>2007-04-16T09:20:00Z</gml:timePosition>
</gml:TimeInstant>
</sps:LatestResponseTime>
</sps:Feasibility>
</sps:GetFeasibilityRequestResponse>
END
 
  def test_dup_2b
    d = REXML::Document.new PAT_XML
    d1 = OpenWFE::fulldup(d)
    assert_not_equal d.object_id, d1.object_id
    assert_equal d.to_s, d1.to_s
  end
 
  def test_dup_3
    d = REXML::Text.new "toto"
    d1 = OpenWFE::fulldup(d)
    assert d.object_id != d1.object_id
  end
 
  def test_dup_4
    wi = OpenWFE::InFlowWorkItem.new
    wi.xml_stuff = REXML::Text.new "whatever"
    wi1 = wi.dup
    assert wi.object_id != wi1.object_id
    assert wi.xml_stuff.object_id != wi1.xml_stuff.object_id
    assert_equal wi.xml_stuff, wi1.xml_stuff
  end
 
  def test_dup_5
    require 'date'
    d = DateTime.now
    d1 = OpenWFE::fulldup(d)
    assert_not_equal d.object_id, d1.object_id
    assert_equal d.to_s, d1.to_s
  end
 
  def test_dup_6
    t = Time.new
    sleep 0.100
    t1 = OpenWFE::fulldup(t)
    assert_not_equal t.object_id, t1.object_id
    assert_equal t.to_f, t1.to_f
  end
 
  def test_dup_7
    s = :symbol
    s1 = OpenWFE::fulldup(s)
    assert_equal s.object_id, s1.object_id
    assert_equal s, s1
  end
 
  def test_dup_8
    require 'rational'
    r = Rational(4, 5)
    r1 = OpenWFE.fulldup(r)
    assert_not_equal r.object_id, r1.object_id
    assert_equal r, r1
  end
 
  private
 
    class A
      attr_accessor :a, :b
 
      def == (other)
        return false if not other.kind_of?(A)
        (self.a == other.a and self.b == other.b)
      end
 
      def to_s
        "A : a='#{a}', b='#{b}'"
      end
    end
end