jmettraux / ruote-rest

restful workflow engine based on Rack and ruote (Warning : ruote-rest will be replaced by ruote-kit soon)

This URL has Read+Write access

commit  0901bd9236835294036ea9da85e8d3028b46bf40
tree    fa8a01ebdf42b1f73720c217c3a1a445654d34dc
parent  4fee6c3ab7d01427f748b9915c4a0814dc78cbe8
ruote-rest / test / st_errors.rb
100644 143 lines (88 sloc) 2.696 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
#
# Testing ruote-rest
#
# John Mettraux at OpenWFE dot org
#
# Fri May 30 21:13:22 JST 2008
#
 
require File.dirname(__FILE__) + '/testbase'
 
 
class StErrorsTest < Test::Unit::TestCase
 
  include TestBase
 
 
  def test_get_empty_errors
 
    get '/errors'
 
    #puts @response.body
 
    assert_equal(
      'application/xml',
      @response.content_type)
 
    assert_equal(
      "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors count=\"0\">\n <link href=\"/\" rel=\"via\"/>\n <link href=\"/errors\" rel=\"self\"/>\n</errors>\n",
      @response.body)
 
    assert_not_nil @response.headers['ETag']
    assert_nil @response.headers['Last-Modified']
  end
 
  def test_get_errors
 
    fei = launch_faulty_process
 
    get '/errors'
 
    #puts @response.body
 
    assert_not_nil @response.body.index(
      '<errors count="1">')
    assert_not_nil @response.body.match(
      '<message>pexp : no participant named .*tonto.*</message>')
 
    assert_not_nil @response.headers['ETag']
    assert_not_nil @response.headers['Last-Modified']
  end
 
  def test_replay_error
 
    fei = launch_faulty_process
 
    get '/errors'
 
    errors = OpenWFE::Xml.errors_from_xml(@response.body)
    error = errors.first
 
    fd0 = error.fdate
 
    delete error.href
    #puts @response.body
 
    sleep 0.450
 
    # error re-occured since root cause hasn't been fixed
 
    get error.href
    error = OpenWFE::Xml.error_from_xml(@response.body)
 
    assert_not_equal fd0, error.fdate
  end
 
  def test_replay_error_with_updated_workitem
 
    fei = launch_faulty_process
 
    err = get_error(fei.wfid)
 
    wi = err.workitem
    wi.attributes['kilroy'] = 'was here'
 
    post(
      "/errors/#{fei.wfid}/0_0",
      wi.to_h().to_json,
      { 'CONTENT_TYPE' => 'application/json' })
 
    assert_equal 200, @response.status
 
    sleep 0.450
 
    err = get_error(fei.wfid)
 
    assert_equal({ 'kilroy' => 'was here' }, err.workitem.attributes)
  end
 
  def test_replay_error_with_updated_workitem_attributes
 
    fei = launch_faulty_process
 
    err = get_error(fei.wfid)
 
    post(
      "/errors/#{fei.wfid}/0_0",
      { 'kilroy' => 'was there' }.to_json,
      { 'CONTENT_TYPE' => 'application/json' })
 
    assert_equal 200, @response.status
 
    sleep 0.450
 
    err = get_error(fei.wfid)
 
    assert_equal({ 'kilroy' => 'was there' }, err.workitem.attributes)
  end
 
  protected
 
  def launch_faulty_process
 
    fei = RuoteRest.engine.launch <<-EOS
<process-definition name="st_errors" revision="t1">
<participant ref="tonto" />
</process-definition>
EOS
 
    sleep 0.450
 
    fei
  end
 
  def get_error (wfid)
 
    get "/errors/#{wfid}/0_0"
 
    OpenWFE::Xml.error_from_xml(@response.body)
  end
end