rbpm 0.0.1

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.
@@ -0,0 +1,148 @@
1
+ require 'test/unit'
2
+ require 'rbpm'
3
+
4
+ $mylog = {}
5
+
6
+ class Wf1 < Workflow
7
+ start_node :start,
8
+ :trans => :end,
9
+ :on_enter => :my_on_enter,
10
+ :on_leave => :my_on_leave,
11
+ :action => :my_action
12
+ end_node :end
13
+
14
+ def my_on_enter(token,caller)
15
+ $mylog[:on_enter] = true
16
+ end
17
+
18
+ def my_on_leave(token,caller)
19
+ $mylog[:on_leave] = true
20
+ end
21
+
22
+ def my_action(token,caller)
23
+ $mylog[:action] = true
24
+ return [[:default, token]]
25
+ end
26
+ end
27
+
28
+ class Wf2 < Workflow
29
+ start_node :start,
30
+ :trans => :end,
31
+ :on_enter => :my_on_enter,
32
+ :on_leave => :my_on_leave,
33
+ :action => :my_action
34
+ end_node :end
35
+
36
+ def self.my_on_enter(token,caller)
37
+ $mylog[:on_enter] = true
38
+ end
39
+
40
+ def self.my_on_leave(token,caller)
41
+ $mylog[:on_leave] = true
42
+ end
43
+
44
+ def my_action(token,caller)
45
+ $mylog[:action] = true
46
+ return [[:default, token]]
47
+ end
48
+ end
49
+
50
+ class Wf3 < Workflow
51
+ start_node :start, :trans => :end
52
+ end_node :end
53
+
54
+ def start_on_enter(token,caller)
55
+ $mylog[:on_enter] = true
56
+ end
57
+
58
+ def start_on_leave(token,caller)
59
+ $mylog[:on_leave] = true
60
+ end
61
+
62
+ def start_action(token,caller)
63
+ $mylog[:action] = true
64
+ return [[:default, token]]
65
+ end
66
+ end
67
+
68
+ class Wf4 < Workflow
69
+ start_node :start, :trans => :end
70
+ end_node :end
71
+
72
+ def self.start_on_enter(token,caller)
73
+ $mylog[:on_enter] = true
74
+ end
75
+
76
+ def self.start_on_leave(token,caller)
77
+ $mylog[:on_leave] = true
78
+ end
79
+
80
+ def self.start_action(token,caller)
81
+ $mylog[:action] = true
82
+ return [[:default, token]]
83
+ end
84
+ end
85
+
86
+ class Wf5Helper
87
+ def on_enter(token,caller)
88
+ $mylog[:on_enter] = true
89
+ end
90
+
91
+ def on_leave(token,caller)
92
+ $mylog[:on_leave] = true
93
+ end
94
+
95
+ def action(token,caller)
96
+ $mylog[:action] = true
97
+ return [[:default, token]]
98
+ end
99
+ end
100
+
101
+ class Wf5 < Workflow
102
+ start_node :start, :trans => :end, :action_singleton => Wf5Helper.new
103
+ end_node :end
104
+ end
105
+
106
+ class Wf6 < Workflow
107
+ start_node :start,
108
+ :trans => :end,
109
+ :on_enter => lambda { |token,caller| $mylog[:on_enter] = true },
110
+ :on_leave => lambda { |token,caller| $mylog[:on_leave] = true },
111
+ :action => lambda { |token,caller| $mylog[:action] = true ; [[:default, token]] }
112
+ end_node :end
113
+ end
114
+
115
+ class Wf7 < Workflow
116
+ start_node :start, :trans => :end
117
+ end_node :end
118
+
119
+ enter(:start) do |token,caller|
120
+ $mylog[:on_enter] = true
121
+ end
122
+
123
+ leave(:start) do |token,caller|
124
+ $mylog[:on_leave] = true
125
+ end
126
+
127
+ action(:start) do |token,caller|
128
+ $mylog[:action] = true
129
+ [[:default, token]] #no return here!!!!
130
+ end
131
+ end
132
+
133
+ class FewMoreRbpmTest < Test::Unit::TestCase
134
+
135
+ def test_instance_callback_and_actions
136
+ [Wf1, Wf2, Wf3, Wf4, Wf5, Wf6, Wf7].each do |workflow|
137
+ wf1 = workflow.new
138
+
139
+ $mylog.clear
140
+ t = wf1.start()
141
+ assert_equal :end, t.node
142
+
143
+ assert_not_nil $mylog[:on_enter]
144
+ assert_not_nil $mylog[:on_leave]
145
+ assert_not_nil $mylog[:action]
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,125 @@
1
+ require 'test/unit'
2
+ require 'rbpm'
3
+
4
+ class DemoWorkflow6b < Workflow
5
+
6
+ start_node :start,
7
+ :trans => :end,
8
+ :trans_action => lambda { |token,caller| token[:result_var] = "Hallo " + token[:param_var] }
9
+
10
+ end_node :end
11
+ end
12
+
13
+ class DemoWorkflow6 < Workflow
14
+
15
+ start_node :start, :trans => :call
16
+
17
+ call_node :call,
18
+ :workflow => DemoWorkflow6b,
19
+ :call_in => {:my_var => :param_var},
20
+ :call_out => {:result_var => :my_var2},
21
+ :trans => :end
22
+
23
+ end_node :end
24
+ end
25
+
26
+ module DemoWorkflow6bSymVersion1
27
+ class DemoWorkflow6bSym < Workflow
28
+ start_node :start,
29
+ :trans => :end,
30
+ :trans_action => lambda { |token,caller| token[:result_var] = "(1)Hallo " + token[:param_var] }
31
+ end_node :end
32
+ end
33
+ end
34
+
35
+ module DemoWorkflow6bSymVersion2
36
+ class DemoWorkflow6bSym < Workflow
37
+ start_node :start,
38
+ :trans => :end,
39
+ :trans_action => lambda { |token,caller| token[:result_var] = "(2)Hallo " + token[:param_var] }
40
+ end_node :end
41
+ end
42
+ end
43
+
44
+ module DemoWorkflow6bSymVersion3
45
+ class DemoWorkflow6bSym < Workflow
46
+ start_node :start,
47
+ :trans => :end,
48
+ :trans_action => lambda { |token,caller| token[:result_var] = "(3)Hallo " + token[:param_var] }
49
+ end_node :end
50
+ end
51
+ end
52
+
53
+ class DemoWorkflow6Sym < Workflow
54
+
55
+ start_node :start, :trans => :call
56
+
57
+ call_node :call,
58
+ :workflow => :DemoWorkflow6bSym,
59
+ :workflow_version => 2,
60
+ :call_in => {:my_var => :param_var},
61
+ :call_out => {:result_var => :my_var2},
62
+ :trans => :end
63
+
64
+ end_node :end
65
+ end
66
+
67
+ class DemoWorkflow7b < Workflow
68
+
69
+ start_node :start,
70
+ :trans => :state,
71
+ :trans_action => lambda { |token,caller| token[:result_var] = "Hallo " + token[:param_var] }
72
+
73
+ state_node :state, :trans => :end
74
+
75
+ end_node :end
76
+ end
77
+
78
+ class DemoWorkflow7 < Workflow
79
+
80
+ start_node :start, :trans => :call
81
+
82
+ call_node :call,
83
+ :workflow => DemoWorkflow7b,
84
+ :call_in => {:my_var => :param_var},
85
+ :call_out => {:result_var => :my_var2},
86
+ :trans => :end
87
+
88
+ end_node :end
89
+ end
90
+
91
+ class CallRbpmTest < Test::Unit::TestCase
92
+
93
+ def test_simplistic_case
94
+ wf = DemoWorkflow6.new
95
+ t = wf.start(:my_var => "Welt")
96
+
97
+ assert_equal :end, t.node
98
+ assert_equal "Hallo Welt", t[:my_var2]
99
+ end
100
+
101
+ def test_with_versionning
102
+ wf = WorkflowVersionManager.create_workflow_instance('DemoWorkflow6Sym')
103
+ t = wf.start(:my_var => "Welt")
104
+
105
+ assert_equal :end, t.node
106
+ assert_equal "(2)Hallo Welt", t[:my_var2]
107
+ end
108
+
109
+ def test_subworkflow_with_state
110
+ wf = DemoWorkflow7.new
111
+ t = wf.start(:my_var => "Welt")
112
+
113
+ assert_equal :state, t.sub_process.node
114
+ assert_equal :call, t.node
115
+ fail if t.end?
116
+ fail if t.sub_process.end?
117
+
118
+ t.sub_process.signal
119
+
120
+ fail "end expected" if not t.end?
121
+ assert_nil t.sub_process
122
+ assert_equal :end, t.node
123
+ assert_equal "Hallo Welt", t[:my_var2]
124
+ end
125
+ end
@@ -0,0 +1,28 @@
1
+ require 'test/unit'
2
+ require 'rbpm'
3
+
4
+ class DemoWorkflow5 < Workflow
5
+
6
+ start_node :start,
7
+ :a_trans => :end_a,
8
+ :a_trans_cond => "token[:my_ctx_value] > 10",
9
+ :b_trans => :end_b,
10
+ :b_trans_cond => "token[:my_ctx_value] <= 10"
11
+
12
+ end_node :end_a
13
+
14
+ end_node :end_b
15
+ end
16
+
17
+ class ConditionRbpmTest < Test::Unit::TestCase
18
+
19
+ def test_misc
20
+ wf = DemoWorkflow5.new
21
+ t = wf.start(:my_ctx_value => 5)
22
+ assert_equal :end_b, t.node
23
+
24
+ wf = DemoWorkflow5.new
25
+ t = wf.start(:my_ctx_value => 15)
26
+ assert_equal :end_a, t.node
27
+ end
28
+ end
@@ -0,0 +1,40 @@
1
+ require 'test/unit'
2
+ require 'rbpm'
3
+
4
+ class DemoWorkflow3 < Workflow
5
+
6
+ def self.log(s)
7
+ @@logs = [] unless defined? @@logs
8
+ @@logs << s
9
+ end
10
+
11
+ def self.logs
12
+ @@logs
13
+ end
14
+
15
+ start_node :start, :trans => :end
16
+
17
+ #TODO fix this crappy lambda syntax :)
18
+ transition_action(:start, :default, lambda do |token,caller|
19
+ token[:billi] = "Modified"
20
+
21
+ log "Willi=#{token[:willi]}"
22
+ end)
23
+
24
+ end_node :end
25
+ end
26
+
27
+ class CtxVarRbpmTest < Test::Unit::TestCase
28
+
29
+ def test_misc
30
+ wf = DemoWorkflow3.new
31
+ t = wf.start(:willi => "Wuff", :billi => "Buff")
32
+
33
+ assert_equal :end, t.node
34
+
35
+ assert_equal 1, DemoWorkflow3.logs.length
36
+ assert_equal "Willi=Wuff", wf.class.logs.shift
37
+
38
+ assert_equal "Modified", t[:billi]
39
+ end
40
+ end
@@ -0,0 +1,79 @@
1
+ require 'test/unit'
2
+ require 'rbpm'
3
+
4
+ class ExceptionWf1 < Workflow
5
+ start_node :start,
6
+ :trans => :end,
7
+ :exception => :error_end
8
+ end_node :end
9
+ end_node :error_end
10
+
11
+ def start_on_enter(token,caller)
12
+ raise if token[:raise]
13
+ end
14
+ end
15
+
16
+ class ExceptionWf2 < Workflow
17
+ start_node :start,
18
+ :trans => :end,
19
+ :exception => :error_end
20
+ end_node :end
21
+ end_node :error_end
22
+
23
+ def start_on_leave(token,caller)
24
+ raise if token[:raise]
25
+ end
26
+ end
27
+
28
+ class ExceptionWf3 < Workflow
29
+ start_node :start,
30
+ :trans => :end,
31
+ :exception => :error_end
32
+ end_node :end
33
+ end_node :error_end
34
+
35
+ def self.start_default_trans_action(token, caller)
36
+ raise if token[:raise]
37
+ end
38
+ end
39
+
40
+ #note: exceptions thrown within node actions are frame work exceptions. don't put business logic in node actions.
41
+
42
+ class ExceptionRbpmTest < Test::Unit::TestCase
43
+
44
+ def test_on_enter_exception_handling
45
+ wf = WorkflowVersionManager.create_workflow_instance(:ExceptionWf1)
46
+ t = wf.start(:raise => true)
47
+ assert_equal :error_end, t.node
48
+ assert_not_nil t[:exception]
49
+
50
+ wf = WorkflowVersionManager.create_workflow_instance(:ExceptionWf1)
51
+ t = wf.start(:raise => false)
52
+ assert_equal :end, t.node
53
+ assert_nil t[:exception]
54
+ end
55
+
56
+ def test_on_leave_exception_handling
57
+ wf = WorkflowVersionManager.create_workflow_instance(:ExceptionWf2)
58
+ t = wf.start(:raise => true)
59
+ assert_equal :error_end, t.node
60
+ assert_not_nil t[:exception]
61
+
62
+ wf = WorkflowVersionManager.create_workflow_instance(:ExceptionWf2)
63
+ t = wf.start(:raise => false)
64
+ assert_equal :end, t.node
65
+ assert_nil t[:exception]
66
+ end
67
+
68
+ def test_transition_action_exception_handling
69
+ wf = WorkflowVersionManager.create_workflow_instance(:ExceptionWf3)
70
+ t = wf.start(:raise => true)
71
+ assert_equal :error_end, t.node
72
+ assert_not_nil t[:exception]
73
+
74
+ wf = WorkflowVersionManager.create_workflow_instance(:ExceptionWf3)
75
+ t = wf.start(:raise => false)
76
+ assert_equal :end, t.node
77
+ assert_nil t[:exception]
78
+ end
79
+ end
@@ -0,0 +1,72 @@
1
+ require 'test/unit'
2
+ require 'rbpm'
3
+
4
+ class DemoWorkflow4 < Workflow
5
+
6
+ def self.log(s)
7
+ @@logs = [] unless defined? @@logs
8
+ @@logs << s
9
+ end
10
+
11
+ def self.logs
12
+ @@logs
13
+ end
14
+
15
+ start_node :start, :trans => :fork
16
+
17
+ def start_on_enter(token, caller)
18
+ clazz.log "entering start with message=#{token[:msg]}"
19
+ end
20
+
21
+ def start_on_leave(token, caller)
22
+ clazz.log "leaving start with message=#{token[:msg]}"
23
+ end
24
+
25
+ fork_node :fork, :trans => :join, :children_ctx => :sub_ctxs
26
+
27
+ def fork_on_enter(token, caller)
28
+ clazz.log "entering fork with message=#{token[:msg]}"
29
+ end
30
+
31
+ def fork_on_leave(token, caller)
32
+ clazz.log "leaving fork with message=#{token[:msg]}"
33
+ end
34
+
35
+ join_node :join, :trans => :end
36
+
37
+ def join_on_enter(token, caller)
38
+ clazz.log "entering join with message=#{token[:msg]}"
39
+ end
40
+
41
+ def join_on_leave(token, caller)
42
+ clazz.log "leaving join with message=#{token[:msg]}"
43
+ end
44
+
45
+ end_node :end
46
+
47
+ def end_on_enter(token, caller)
48
+ clazz.log "entering end with message=#{token[:msg]}"
49
+ end
50
+ end
51
+
52
+ class ForkJoinRbpmTest < Test::Unit::TestCase
53
+
54
+ def test_misc
55
+ wf = DemoWorkflow4.new
56
+ t = wf.start(:msg => "Parent", :sub_ctxs => [{:msg => "Child1"}, {:msg => "Child2"}])
57
+
58
+ assert_equal :end, t.node
59
+
60
+ assert_equal 9, DemoWorkflow4.logs.length
61
+
62
+ assert_equal "entering start with message=Parent", wf.class.logs.shift
63
+ assert_equal "leaving start with message=Parent", wf.class.logs.shift
64
+ assert_equal "entering fork with message=Parent", wf.class.logs.shift
65
+ assert_equal "leaving fork with message=Child1", wf.class.logs.shift
66
+ assert_equal "entering join with message=Child1", wf.class.logs.shift
67
+ assert_equal "leaving fork with message=Child2", wf.class.logs.shift
68
+ assert_equal "entering join with message=Child2", wf.class.logs.shift
69
+ assert_equal "leaving join with message=Parent", wf.class.logs.shift
70
+ assert_equal "entering end with message=Parent", wf.class.logs.shift
71
+ end
72
+ end