rbpm 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,14 @@
1
1
  require 'test/unit'
2
- require 'rbpm'
2
+
3
+ begin
4
+ require 'rbpm'
5
+ rescue LoadError
6
+ require '../lib/rbpm'
7
+ end
3
8
 
4
9
  $mylog = {}
5
10
 
6
- class Wf1 < Workflow
11
+ class Wf1 < Rbpm::Workflow
7
12
  start_node :start,
8
13
  :trans => :end,
9
14
  :on_enter => :my_on_enter,
@@ -25,7 +30,7 @@ class Wf1 < Workflow
25
30
  end
26
31
  end
27
32
 
28
- class Wf2 < Workflow
33
+ class Wf2 < Rbpm::Workflow
29
34
  start_node :start,
30
35
  :trans => :end,
31
36
  :on_enter => :my_on_enter,
@@ -47,7 +52,7 @@ class Wf2 < Workflow
47
52
  end
48
53
  end
49
54
 
50
- class Wf3 < Workflow
55
+ class Wf3 < Rbpm::Workflow
51
56
  start_node :start, :trans => :end
52
57
  end_node :end
53
58
 
@@ -65,7 +70,7 @@ class Wf3 < Workflow
65
70
  end
66
71
  end
67
72
 
68
- class Wf4 < Workflow
73
+ class Wf4 < Rbpm::Workflow
69
74
  start_node :start, :trans => :end
70
75
  end_node :end
71
76
 
@@ -98,12 +103,12 @@ class Wf5Helper
98
103
  end
99
104
  end
100
105
 
101
- class Wf5 < Workflow
106
+ class Wf5 < Rbpm::Workflow
102
107
  start_node :start, :trans => :end, :action_singleton => Wf5Helper.new
103
108
  end_node :end
104
109
  end
105
110
 
106
- class Wf6 < Workflow
111
+ class Wf6 < Rbpm::Workflow
107
112
  start_node :start,
108
113
  :trans => :end,
109
114
  :on_enter => lambda { |token,caller| $mylog[:on_enter] = true },
@@ -112,7 +117,7 @@ class Wf6 < Workflow
112
117
  end_node :end
113
118
  end
114
119
 
115
- class Wf7 < Workflow
120
+ class Wf7 < Rbpm::Workflow
116
121
  start_node :start, :trans => :end
117
122
  end_node :end
118
123
 
@@ -130,9 +135,9 @@ class Wf7 < Workflow
130
135
  end
131
136
  end
132
137
 
133
- class FewMoreRbpmTest < Test::Unit::TestCase
138
+ class RbpmActionTests < Test::Unit::TestCase
134
139
 
135
- def test_instance_callback_and_actions
140
+ def test_events_and_actions
136
141
  [Wf1, Wf2, Wf3, Wf4, Wf5, Wf6, Wf7].each do |workflow|
137
142
  wf1 = workflow.new
138
143
 
@@ -1,7 +1,12 @@
1
1
  require 'test/unit'
2
- require 'rbpm'
3
2
 
4
- class DemoWorkflow6b < Workflow
3
+ begin
4
+ require 'rbpm'
5
+ rescue LoadError
6
+ require '../lib/rbpm'
7
+ end
8
+
9
+ class DemoWorkflow6b < Rbpm::Workflow
5
10
 
6
11
  start_node :start,
7
12
  :trans => :end,
@@ -10,7 +15,7 @@ class DemoWorkflow6b < Workflow
10
15
  end_node :end
11
16
  end
12
17
 
13
- class DemoWorkflow6 < Workflow
18
+ class DemoWorkflow6 < Rbpm::Workflow
14
19
 
15
20
  start_node :start, :trans => :call
16
21
 
@@ -24,7 +29,7 @@ class DemoWorkflow6 < Workflow
24
29
  end
25
30
 
26
31
  module DemoWorkflow6bSymVersion1
27
- class DemoWorkflow6bSym < Workflow
32
+ class DemoWorkflow6bSym < Rbpm::Workflow
28
33
  start_node :start,
29
34
  :trans => :end,
30
35
  :trans_action => lambda { |token,caller| token[:result_var] = "(1)Hallo " + token[:param_var] }
@@ -33,7 +38,7 @@ module DemoWorkflow6bSymVersion1
33
38
  end
34
39
 
35
40
  module DemoWorkflow6bSymVersion2
36
- class DemoWorkflow6bSym < Workflow
41
+ class DemoWorkflow6bSym < Rbpm::Workflow
37
42
  start_node :start,
38
43
  :trans => :end,
39
44
  :trans_action => lambda { |token,caller| token[:result_var] = "(2)Hallo " + token[:param_var] }
@@ -42,7 +47,7 @@ module DemoWorkflow6bSymVersion2
42
47
  end
43
48
 
44
49
  module DemoWorkflow6bSymVersion3
45
- class DemoWorkflow6bSym < Workflow
50
+ class DemoWorkflow6bSym < Rbpm::Workflow
46
51
  start_node :start,
47
52
  :trans => :end,
48
53
  :trans_action => lambda { |token,caller| token[:result_var] = "(3)Hallo " + token[:param_var] }
@@ -50,7 +55,7 @@ module DemoWorkflow6bSymVersion3
50
55
  end
51
56
  end
52
57
 
53
- class DemoWorkflow6Sym < Workflow
58
+ class DemoWorkflow6Sym < Rbpm::Workflow
54
59
 
55
60
  start_node :start, :trans => :call
56
61
 
@@ -64,7 +69,7 @@ class DemoWorkflow6Sym < Workflow
64
69
  end_node :end
65
70
  end
66
71
 
67
- class DemoWorkflow7b < Workflow
72
+ class DemoWorkflow7b < Rbpm::Workflow
68
73
 
69
74
  start_node :start,
70
75
  :trans => :state,
@@ -75,7 +80,7 @@ class DemoWorkflow7b < Workflow
75
80
  end_node :end
76
81
  end
77
82
 
78
- class DemoWorkflow7 < Workflow
83
+ class DemoWorkflow7 < Rbpm::Workflow
79
84
 
80
85
  start_node :start, :trans => :call
81
86
 
@@ -88,9 +93,9 @@ class DemoWorkflow7 < Workflow
88
93
  end_node :end
89
94
  end
90
95
 
91
- class CallRbpmTest < Test::Unit::TestCase
96
+ class CallRbpmTests < Test::Unit::TestCase
92
97
 
93
- def test_simplistic_case
98
+ def test_simplistic_call_case
94
99
  wf = DemoWorkflow6.new
95
100
  t = wf.start(:my_var => "Welt")
96
101
 
@@ -98,15 +103,15 @@ class CallRbpmTest < Test::Unit::TestCase
98
103
  assert_equal "Hallo Welt", t[:my_var2]
99
104
  end
100
105
 
101
- def test_with_versionning
102
- wf = WorkflowVersionManager.create_workflow_instance('DemoWorkflow6Sym')
106
+ def test_call_with_versionning
107
+ wf = Rbpm::WorkflowVersionManager.create_workflow_instance('DemoWorkflow6Sym')
103
108
  t = wf.start(:my_var => "Welt")
104
109
 
105
110
  assert_equal :end, t.node
106
111
  assert_equal "(2)Hallo Welt", t[:my_var2]
107
112
  end
108
113
 
109
- def test_subworkflow_with_state
114
+ def test_call_subworkflow_with_state
110
115
  wf = DemoWorkflow7.new
111
116
  t = wf.start(:my_var => "Welt")
112
117
 
@@ -1,7 +1,12 @@
1
1
  require 'test/unit'
2
- require 'rbpm'
3
2
 
4
- class DemoWorkflow5 < Workflow
3
+ begin
4
+ require 'rbpm'
5
+ rescue LoadError
6
+ require '../lib/rbpm'
7
+ end
8
+
9
+ class DemoWorkflow5 < Rbpm::Workflow
5
10
 
6
11
  start_node :start,
7
12
  :a_trans => :end_a,
@@ -14,9 +19,9 @@ class DemoWorkflow5 < Workflow
14
19
  end_node :end_b
15
20
  end
16
21
 
17
- class ConditionRbpmTest < Test::Unit::TestCase
22
+ class RbpmConditionTests < Test::Unit::TestCase
18
23
 
19
- def test_misc
24
+ def test_conditions
20
25
  wf = DemoWorkflow5.new
21
26
  t = wf.start(:my_ctx_value => 5)
22
27
  assert_equal :end_b, t.node
@@ -1,7 +1,12 @@
1
1
  require 'test/unit'
2
- require 'rbpm'
3
2
 
4
- class DemoWorkflow3 < Workflow
3
+ begin
4
+ require 'rbpm'
5
+ rescue LoadError
6
+ require '../lib/rbpm'
7
+ end
8
+
9
+ class DemoWorkflow3 < Rbpm::Workflow
5
10
 
6
11
  def self.log(s)
7
12
  @@logs = [] unless defined? @@logs
@@ -14,17 +19,16 @@ class DemoWorkflow3 < Workflow
14
19
 
15
20
  start_node :start, :trans => :end
16
21
 
17
- #TODO fix this crappy lambda syntax :)
18
- transition_action(:start, :default, lambda do |token,caller|
22
+ transit(:start, :default) do |token,caller|
19
23
  token[:billi] = "Modified"
20
24
 
21
25
  log "Willi=#{token[:willi]}"
22
- end)
26
+ end
23
27
 
24
28
  end_node :end
25
29
  end
26
30
 
27
- class CtxVarRbpmTest < Test::Unit::TestCase
31
+ class RbpmCtxVarTest < Test::Unit::TestCase
28
32
 
29
33
  def test_misc
30
34
  wf = DemoWorkflow3.new
@@ -1,7 +1,12 @@
1
1
  require 'test/unit'
2
- require 'rbpm'
3
2
 
4
- class ExceptionWf1 < Workflow
3
+ begin
4
+ require 'rbpm'
5
+ rescue LoadError
6
+ require '../lib/rbpm'
7
+ end
8
+
9
+ class ExceptionWf1 < Rbpm::Workflow
5
10
  start_node :start,
6
11
  :trans => :end,
7
12
  :exception => :error_end
@@ -13,7 +18,7 @@ class ExceptionWf1 < Workflow
13
18
  end
14
19
  end
15
20
 
16
- class ExceptionWf2 < Workflow
21
+ class ExceptionWf2 < Rbpm::Workflow
17
22
  start_node :start,
18
23
  :trans => :end,
19
24
  :exception => :error_end
@@ -25,7 +30,7 @@ class ExceptionWf2 < Workflow
25
30
  end
26
31
  end
27
32
 
28
- class ExceptionWf3 < Workflow
33
+ class ExceptionWf3 < Rbpm::Workflow
29
34
  start_node :start,
30
35
  :trans => :end,
31
36
  :exception => :error_end
@@ -39,39 +44,39 @@ end
39
44
 
40
45
  #note: exceptions thrown within node actions are frame work exceptions. don't put business logic in node actions.
41
46
 
42
- class ExceptionRbpmTest < Test::Unit::TestCase
47
+ class RbpmExceptionTests < Test::Unit::TestCase
43
48
 
44
49
  def test_on_enter_exception_handling
45
- wf = WorkflowVersionManager.create_workflow_instance(:ExceptionWf1)
50
+ wf = Rbpm::WorkflowVersionManager.create_workflow_instance(:ExceptionWf1)
46
51
  t = wf.start(:raise => true)
47
52
  assert_equal :error_end, t.node
48
53
  assert_not_nil t[:exception]
49
54
 
50
- wf = WorkflowVersionManager.create_workflow_instance(:ExceptionWf1)
55
+ wf = Rbpm::WorkflowVersionManager.create_workflow_instance(:ExceptionWf1)
51
56
  t = wf.start(:raise => false)
52
57
  assert_equal :end, t.node
53
58
  assert_nil t[:exception]
54
59
  end
55
60
 
56
61
  def test_on_leave_exception_handling
57
- wf = WorkflowVersionManager.create_workflow_instance(:ExceptionWf2)
62
+ wf = Rbpm::WorkflowVersionManager.create_workflow_instance(:ExceptionWf2)
58
63
  t = wf.start(:raise => true)
59
64
  assert_equal :error_end, t.node
60
65
  assert_not_nil t[:exception]
61
66
 
62
- wf = WorkflowVersionManager.create_workflow_instance(:ExceptionWf2)
67
+ wf = Rbpm::WorkflowVersionManager.create_workflow_instance(:ExceptionWf2)
63
68
  t = wf.start(:raise => false)
64
69
  assert_equal :end, t.node
65
70
  assert_nil t[:exception]
66
71
  end
67
72
 
68
73
  def test_transition_action_exception_handling
69
- wf = WorkflowVersionManager.create_workflow_instance(:ExceptionWf3)
74
+ wf = Rbpm::WorkflowVersionManager.create_workflow_instance(:ExceptionWf3)
70
75
  t = wf.start(:raise => true)
71
76
  assert_equal :error_end, t.node
72
77
  assert_not_nil t[:exception]
73
78
 
74
- wf = WorkflowVersionManager.create_workflow_instance(:ExceptionWf3)
79
+ wf = Rbpm::WorkflowVersionManager.create_workflow_instance(:ExceptionWf3)
75
80
  t = wf.start(:raise => false)
76
81
  assert_equal :end, t.node
77
82
  assert_nil t[:exception]
@@ -1,7 +1,12 @@
1
1
  require 'test/unit'
2
- require 'rbpm'
3
2
 
4
- class DemoWorkflow4 < Workflow
3
+ begin
4
+ require 'rbpm'
5
+ rescue LoadError
6
+ require '../lib/rbpm'
7
+ end
8
+
9
+ class DemoWorkflow4 < Rbpm::Workflow
5
10
 
6
11
  def self.log(s)
7
12
  @@logs = [] unless defined? @@logs
@@ -49,9 +54,9 @@ class DemoWorkflow4 < Workflow
49
54
  end
50
55
  end
51
56
 
52
- class ForkJoinRbpmTest < Test::Unit::TestCase
57
+ class RbpmForkJoinTest < Test::Unit::TestCase
53
58
 
54
- def test_misc
59
+ def test_join_fork
55
60
  wf = DemoWorkflow4.new
56
61
  t = wf.start(:msg => "Parent", :sub_ctxs => [{:msg => "Child1"}, {:msg => "Child2"}])
57
62
 
@@ -1,7 +1,12 @@
1
1
  require 'test/unit'
2
- require 'rbpm'
3
2
 
4
- #a simple join node
3
+ begin
4
+ require 'rbpm'
5
+ rescue LoadError
6
+ require '../lib/rbpm'
7
+ end
8
+
9
+ #a simple join node (this test is older than rbpm 0.0.1 ;-)
5
10
  class MyNode
6
11
  def action(token, caller)
7
12
  token.workflow.class.log "mynode action"
@@ -17,7 +22,7 @@ class MyNode
17
22
  end
18
23
  end
19
24
 
20
- class DemoWorkflow < Workflow
25
+ class DemoWorkflow < Rbpm::Workflow
21
26
 
22
27
  def initialize(do_fork)
23
28
  super()
@@ -67,11 +72,11 @@ end
67
72
 
68
73
  class FirstRbpmTest < Test::Unit::TestCase
69
74
 
70
- def test_misc_with_fork
75
+ def test_misc_with_custom_fork
71
76
  do_test_misc(true)
72
77
  end
73
78
 
74
- def test_misc_without_fork
79
+ def test_misc_without_custom_fork
75
80
  do_test_misc(false)
76
81
  end
77
82
 
@@ -1,7 +1,12 @@
1
1
  require 'test/unit'
2
- require 'rbpm'
3
2
 
4
- class DemoWorkflow2 < Workflow
3
+ begin
4
+ require 'rbpm'
5
+ rescue LoadError
6
+ require '../lib/rbpm'
7
+ end
8
+
9
+ class DemoWorkflow2 < Rbpm::Workflow
5
10
 
6
11
  def self.log(s)
7
12
  @@logs = [] unless defined? @@logs
@@ -31,9 +36,9 @@ class DemoWorkflow2 < Workflow
31
36
  end
32
37
  end
33
38
 
34
- class StateRbpmTest < Test::Unit::TestCase
39
+ class RbpmStateNodeTest < Test::Unit::TestCase
35
40
 
36
- def test_state_and_persistence
41
+ def test_state_node_and_workflow_persistence
37
42
  wf = DemoWorkflow2.new()
38
43
  t = wf.start
39
44
 
@@ -51,6 +56,8 @@ class StateRbpmTest < Test::Unit::TestCase
51
56
  end
52
57
  t = wf.tokens[0]
53
58
 
59
+ File.delete("demo_wf_2.txt")
60
+
54
61
  assert_equal :hello, t.node
55
62
 
56
63
  t.signal
@@ -0,0 +1,210 @@
1
+ require 'test/unit'
2
+
3
+ begin
4
+ require 'rbpm'
5
+ rescue LoadError
6
+ require '../lib/rbpm'
7
+ end
8
+
9
+ #test, prototype, conceptual test - whatever
10
+
11
+ class WorkflowTask
12
+ attr_reader :role, :user_id, :task_type
13
+
14
+ #constraint: role XOR user_id
15
+ def initialize(role, user_id, task_type, input_var_mapping, ouput_var_mapping, owner_token_variable, token)
16
+ @role = role
17
+ @user_id = user_id
18
+ @task_type = task_type
19
+ @input_var_mapping = input_var_mapping
20
+ @ouput_var_mapping = ouput_var_mapping
21
+ @owner_token_variable = owner_token_variable
22
+ @token = token
23
+ end
24
+
25
+ def assign(user_id)
26
+ @role = nil
27
+ @user_id = user_id
28
+ @token[@owner_token_variable] = user_id if @owner_token_variable
29
+ end
30
+
31
+ def done
32
+ @token.signal
33
+ end
34
+
35
+ def input_var(key)
36
+ @token[@input_var_mapping.invert[key]]
37
+ end
38
+
39
+ def set_output_var(key, value)
40
+ @token[@ouput_var_mapping[key]] = value
41
+ end
42
+ end
43
+
44
+ class TaskManager
45
+ def initialize
46
+ @tasks = []
47
+ end
48
+
49
+ def create_task(options = {})
50
+ @tasks << WorkflowTask.new(options[:role], options[:user_id], options[:task], options[:input_mapping],
51
+ options[:output_mapping], options[:owner_token_variable], options[:token])
52
+ end
53
+
54
+ def unassigned_tasks
55
+ @tasks.find_all do |task|
56
+ task.user_id.nil?
57
+ end
58
+ end
59
+
60
+ def shift_user_task(user_id)
61
+ @tasks.each do |task|
62
+ if task.user_id == user_id
63
+ @tasks.delete task
64
+ return task
65
+ end
66
+ end
67
+ nil
68
+ end
69
+ end
70
+
71
+ #TODO find app_context solution (dependency injection?)
72
+
73
+ $app_context = {}
74
+ $app_context[:task_manager] = TaskManager.new
75
+
76
+ class QuestionAnswerWorkflow < Rbpm::Workflow
77
+ start_node :start, :trans => :evaluate_question
78
+ state_node :evaluate_question,
79
+ :accept_trans => :anwser_question,
80
+ :accept_trans_cond => "token[:question_evaluation] == :accept",
81
+ :reject_trans => :reject_question,
82
+ :reject_trans_cond => "token[:question_evaluation] == :reject"
83
+ state_node :anwser_question, :trans => :evaluate_answer
84
+ node :reject_question, :trans => :note_rejected_question
85
+ state_node :evaluate_answer,
86
+ :accept_trans => :accept_answer,
87
+ :accept_trans_cond => "token[:answer_evaluation] == :accept",
88
+ :reject_trans => :reject_answer,
89
+ :reject_trans_cond => "token[:answer_evaluation] == :reject"
90
+ node :accept_answer, :trans => :end
91
+ node :reject_answer, :trans => :evaluate_question
92
+ node :note_rejected_question, :trans => :end
93
+ end_node :end
94
+
95
+ enter(:evaluate_question) do |token,caller|
96
+ unless token[:domain_expert_id]
97
+ $app_context[:task_manager].create_task :role => :domain_expert, :task => :evaluate_question, :token => token,
98
+ :input_mapping => {:question => :asked_question}, :output_mapping => {:evaluation => :question_evaluation},
99
+ :owner_token_variable => :domain_expert_id
100
+ else
101
+ $app_context[:task_manager].create_task :user_id => token[:domain_expert_id], :task => :re_evaluate_question, :token => token,
102
+ :input_mapping => {:question => :asked_question}, :output_mapping => {:evaluation => :question_evaluation}
103
+ end
104
+ end
105
+
106
+ enter(:anwser_question) do |token,caller|
107
+ $app_context[:task_manager].create_task :user_id => token[:domain_expert_id], :task => :answer_question, :token => token,
108
+ :input_mapping => {:question => :asked_question}, :output_mapping => {:answer => :answer}
109
+ end
110
+
111
+ enter(:evaluate_answer) do |token,caller|
112
+ $app_context[:task_manager].create_task :user_id => token[:user_id], :task => :evaluate_answer, :token => token,
113
+ :input_mapping => {:question => :question, :answer => :answer},
114
+ :output_mapping => {:evaluation => :answer_evaluation, :extended_question => :question}
115
+ end
116
+ end
117
+
118
+ class RbpmTaskRoleConceptsTest < Test::Unit::TestCase
119
+
120
+ def test_task_and_role_concepts
121
+ tm = $app_context[:task_manager]
122
+
123
+ #user: start workflow: new question
124
+
125
+ wf = QuestionAnswerWorkflow.new
126
+ t = wf.start :user_id => 2001, :question => "black's RGB value?"
127
+
128
+ assert_equal :evaluate_question, t.node
129
+
130
+ #domain expert: unassigned tasks in my inbox?
131
+
132
+ assert_equal 1, tm.unassigned_tasks.length
133
+
134
+ #domain expert: accept task
135
+
136
+ task = tm.unassigned_tasks[0].assign 1001
137
+
138
+ #domain expert: close task: accept question
139
+
140
+ task = tm.shift_user_task 1001
141
+ assert_not_nil task
142
+ assert_equal :evaluate_question, task.task_type
143
+ assert_equal "black's RGB value?", task.input_var(:asked_question)
144
+
145
+ task.set_output_var(:evaluation, :accept)
146
+ task.done
147
+
148
+ assert_equal :anwser_question, t.node
149
+
150
+ #domain expert: close follow-up task: answer question
151
+
152
+ task = tm.shift_user_task 1001
153
+
154
+ assert_not_nil task
155
+ assert_equal "black's RGB value?", task.input_var(:asked_question)
156
+
157
+ task.set_output_var(:answer, "0xff 0xff 0xff")
158
+ task.done
159
+
160
+ #domain expert: other unassigned or assigned tasks in my inbox?
161
+
162
+ assert_equal 0, tm.unassigned_tasks.length
163
+
164
+ task = tm.shift_user_task 1001
165
+ assert_nil task
166
+
167
+ assert_equal :evaluate_answer, t.node
168
+
169
+ #user: close follow-up task: reject answer
170
+
171
+ task = tm.shift_user_task 2001
172
+
173
+ assert_not_nil task
174
+ assert_equal "0xff 0xff 0xff", task.input_var(:answer)
175
+
176
+ task.set_output_var(:evaluation, :reject)
177
+ task.set_output_var(:extended_question, task.input_var(:question) + ", in decimal")
178
+ task.done
179
+
180
+ assert_equal :evaluate_question, t.node
181
+
182
+ #domain expert: close j-up: accept extended question, close f-up: answer extended question
183
+
184
+ task = tm.shift_user_task 1001
185
+ task.set_output_var(:evaluation, :accept)
186
+ task.done
187
+
188
+ assert_equal :anwser_question, t.node
189
+
190
+ task = tm.shift_user_task 1001
191
+ assert_not_nil task
192
+ assert_equal "black's RGB value?, in decimal", task.input_var(:asked_question)
193
+ task.set_output_var(:answer, "255 255 255")
194
+ task.done
195
+
196
+ assert_equal :evaluate_answer, t.node
197
+
198
+ #user: close f-up: accept 2nd answer
199
+
200
+ task = tm.shift_user_task 2001
201
+ assert_not_nil task
202
+ assert_equal "255 255 255", task.input_var(:answer)
203
+ task.set_output_var(:evaluation, :accept)
204
+ task.done
205
+
206
+ assert_equal :end, t.node
207
+ end
208
+ end
209
+
210
+ #conclusion: task and role stuff is doable w/o extending the workflow syntax