public
Description: RESTful workflow / bpm engine based on Rack and OpenWFEru
Homepage: http://openwferu.rubyforge.org
Clone URL: git://github.com/jmettraux/ruote-rest.git
ruote-rest / test / st_expressions.rb
100644 170 lines (114 sloc) 3.462 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
170
#
# Testing ruote-rest
#
# John Mettraux at OpenWFE dot org
#
# Mon Apr 14 15:45:00 JST 2008
#
 
require 'rubygems'
 
require 'testbase'
require 'ruote_rest.rb'
 
 
class StExpressionsTest < Test::Unit::TestCase
 
  include TestBase
 
 
  def test_0
 
    li = OpenWFE::LaunchItem.new <<-EOS
class TestStExpressions < OpenWFE::ProcessDefinition
sequence do
alpha
bravo
end
end
EOS
 
    #p OpenWFE::Xml.launchitem_to_xml(li)
 
    post(
      "/processes",
      OpenWFE::Xml.launchitem_to_xml(li),
      { "CONTENT_TYPE" => "application/xml" })
 
    fei = OpenWFE::Xml.fei_from_xml @response.body
 
    sleep 0.350
 
    get "/expressions/#{fei.wfid}"
    #puts
    #puts @response.body
    #puts
    assert_not_nil @response.body.index(' count="5"')
 
 
    get "/expressions/#{fei.wfid}/0_0"
 
    assert_not_nil @response.body.index(
      '<class>OpenWFE::SequenceExpression</class>')
 
    get "/expressions/#{fei.wfid}/0e"
    #puts
    #puts @response.body
    #puts
    assert_not_nil(
      @response.body.index('<class>OpenWFE::Environment</class>'),
      "GET /0e --> not an environment")
 
 
    get "/expressions/#{fei.wfid}/0"
 
    assert_not_nil(
      @response.body.index('<class>OpenWFE::DefineExpression</class>'),
      "GET /0e --> not an 'process-definition'")
 
    #
    # cancel process
 
    delete "/expressions/#{fei.wfid}/0"
 
    assert_equal 303, @response.status
 
    sleep 0.350
 
    # done.
  end
 
  def test_1
 
    li = OpenWFE::LaunchItem.new <<-EOS
class TestStExpressions < OpenWFE::ProcessDefinition
nada
surf
end
EOS
 
    post(
      "/processes",
      OpenWFE::Xml.launchitem_to_xml(li),
      { "CONTENT_TYPE" => "application/xml" })
 
    fei = OpenWFE::Xml.fei_from_xml @response.body
 
    sleep 0.350
 
    get "/expressions/#{fei.wfid}/0_0?format=yaml"
 
    assert_equal 'application/yaml', @response['Content-Type']
 
    exp = YAML.load @response.body
    assert_kind_of OpenWFE::FlowExpression, exp
 
    exp.attributes = { :toto => :surf }
 
    put(
      "/expressions/#{fei.wfid}/0_0",
      exp.to_yaml,
      { 'CONTENT_TYPE' => 'application/yaml' })
 
    assert_equal(
      "http://example.org/expressions/#{fei.wfid}/0_0",
      @response['Location'])
 
    # GET expression as yaml
 
    get(
      "/expressions/#{fei.wfid}/0_0",
      nil,
      { 'HTTP_ACCEPT' => 'application/yaml' })
 
    exp = YAML.load @response.body
 
    assert_equal :surf, exp.attributes[:toto]
 
    # GET expression/raw as json
 
    get(
      "/expressions/#{fei.wfid}/0_0/raw",
      nil,
      { 'HTTP_ACCEPT' => 'application/json' })
 
    assert_equal ["nada", {}, []], json_parse(@response.body)
 
    # PUT some other expression/raw
 
    put(
      "/expressions/#{fei.wfid}/0_1/raw",
      '["surfbis",{},[]]',
      { 'CONTENT_TYPE' => 'application/json' })
 
    assert_equal 303, @response.status
 
    get(
      "/expressions/#{fei.wfid}/0_1/raw",
      nil,
      { 'HTTP_ACCEPT' => 'application/json' })
 
    assert false # TODO : add test for form input !!!!!!!!!!!!!!!!!!!!!!!!
 
    assert_equal ["surfbis", {}, []], json_parse(@response.body)
 
    assert_equal(
      [ "process-definition",
        {"name"=>"TestStExpressions", "revision"=>"0"},
        [["nada", {}, []], ["surfbis", {}, []]] ],
      $app.engine.process_status(fei.wfid).all_expressions.representation)
 
    # over.
 
    $app.engine.cancel_process fei
 
    sleep 0.350
  end
end