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,103 @@
1
+ require 'test/unit'
2
+ require 'rbpm'
3
+
4
+ #a simple join node
5
+ class MyNode
6
+ def action(token, caller)
7
+ token.workflow.class.log "mynode action"
8
+
9
+ parent_token = token.parent
10
+ token.done
11
+
12
+ result = parent_token.childs? ? nil : [[:default, parent_token]]
13
+
14
+ token.workflow.class.log "wait for other tokens" unless result
15
+
16
+ result
17
+ end
18
+ end
19
+
20
+ class DemoWorkflow < Workflow
21
+
22
+ def initialize(do_fork)
23
+ super()
24
+ @do_fork = do_fork
25
+ end
26
+
27
+ def self.log(s)
28
+ @@logs = [] unless defined? @@logs
29
+ @@logs << s
30
+ end
31
+
32
+ def self.logs
33
+ @@logs
34
+ end
35
+
36
+ start_node :start, :trans => :hello
37
+
38
+ node :hello,
39
+ :on_enter => lambda { |token, caller| log "entering hello node - hello world" },
40
+ :trans => :hello2,
41
+ :trans_action => lambda { |token, caller| log "leaving hello node using default transition" }
42
+
43
+ node :hello2,
44
+ :trans => :end,
45
+ :my_other_trans => :hello3,
46
+ :my_other_trans_action => lambda { log "leaving using my_other transition" }
47
+
48
+ def hello2_action(token, caller)
49
+ if @do_fork
50
+ clazz.log "node hello2 decides to leave using the my_other transition"
51
+ return [[:my_other, token.fork], [:my_other, token.fork]]
52
+ else
53
+ #turns hello2 into a simple fork action
54
+ clazz.log "node hello2 decides to leave using the default transition"
55
+ return [[:default, token]]
56
+ end
57
+ end
58
+
59
+ node :hello3,
60
+ :on_enter => lambda { log "entering in hello3" },
61
+ :action_singleton => MyNode.new,
62
+ :trans => :end
63
+
64
+ end_node :end,
65
+ :on_enter => lambda { log "entering end" }
66
+ end
67
+
68
+ class FirstRbpmTest < Test::Unit::TestCase
69
+
70
+ def test_misc_with_fork
71
+ do_test_misc(true)
72
+ end
73
+
74
+ def test_misc_without_fork
75
+ do_test_misc(false)
76
+ end
77
+
78
+ def do_test_misc(do_fork)
79
+ wf = DemoWorkflow.new(do_fork)
80
+
81
+ t = wf.start
82
+
83
+ assert_equal :end, t.node
84
+
85
+ assert_equal "entering hello node - hello world", wf.class.logs.shift
86
+ assert_equal "leaving hello node using default transition", wf.class.logs.shift
87
+
88
+ if do_fork
89
+ assert_equal "node hello2 decides to leave using the my_other transition", wf.class.logs.shift
90
+ assert_equal "leaving using my_other transition", wf.class.logs.shift
91
+ assert_equal "entering in hello3", wf.class.logs.shift
92
+ assert_equal "mynode action", wf.class.logs.shift
93
+ assert_equal "wait for other tokens", wf.class.logs.shift
94
+ assert_equal "leaving using my_other transition", wf.class.logs.shift
95
+ assert_equal "entering in hello3", wf.class.logs.shift
96
+ assert_equal "mynode action", wf.class.logs.shift
97
+ else
98
+ assert_equal "node hello2 decides to leave using the default transition", wf.class.logs.shift
99
+ end
100
+
101
+ assert_equal "entering end", wf.class.logs.shift
102
+ end
103
+ end
@@ -0,0 +1,61 @@
1
+ require 'test/unit'
2
+ require 'rbpm'
3
+
4
+ class DemoWorkflow2 < 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,
16
+ :on_enter => :my_start_enter_act,
17
+ :trans => :hello
18
+
19
+ def my_start_enter_act(token, caller)
20
+ clazz.log "entering start"
21
+ end
22
+
23
+ state_node :hello,
24
+ :on_enter => lambda { log "entering hello" },
25
+ :trans => :end
26
+
27
+ end_node :end
28
+
29
+ def end_on_enter(token, caller)
30
+ clazz.log "entering end"
31
+ end
32
+ end
33
+
34
+ class StateRbpmTest < Test::Unit::TestCase
35
+
36
+ def test_state_and_persistence
37
+ wf = DemoWorkflow2.new()
38
+ t = wf.start
39
+
40
+ assert_equal "entering start", wf.class.logs.shift
41
+ assert_equal "entering hello", wf.class.logs.shift
42
+ assert_equal :hello, t.node
43
+
44
+ File.open("demo_wf_2.txt", "w+") do |f|
45
+ Marshal.dump(wf, f)
46
+ end
47
+
48
+ wf, t = nil, nil
49
+ File.open("demo_wf_2.txt") do |f|
50
+ wf = Marshal.load(f)
51
+ end
52
+ t = wf.tokens[0]
53
+
54
+ assert_equal :hello, t.node
55
+
56
+ t.signal
57
+
58
+ assert_equal "entering end", wf.class.logs.shift
59
+ assert_equal :end, t.node
60
+ end
61
+ end
@@ -0,0 +1,94 @@
1
+ require 'test/unit'
2
+ require 'rbpm'
3
+
4
+ $mylog = {}
5
+
6
+ class TWf1 < Workflow
7
+ start_node :start,
8
+ :trans => :end,
9
+ :trans_action => :my_trans_action
10
+ end_node :end
11
+
12
+ def my_trans_action(token, caller)
13
+ $mylog[:trans_action] = true
14
+ end
15
+ end
16
+
17
+ class TWf2 < Workflow
18
+ start_node :start,
19
+ :trans => :end,
20
+ :trans_action => :my_trans_action
21
+ end_node :end
22
+
23
+ def self.my_trans_action(token, caller)
24
+ $mylog[:trans_action] = true
25
+ end
26
+ end
27
+
28
+ class TWf3 < Workflow
29
+ start_node :start, :trans => :end
30
+ end_node :end
31
+
32
+ def start_default_trans_action(token, caller)
33
+ $mylog[:trans_action] = true
34
+ end
35
+ end
36
+
37
+ class TWf4 < Workflow
38
+ start_node :start, :foo_trans => :end
39
+ end_node :end
40
+
41
+ def start_foo_trans_action(token, caller)
42
+ $mylog[:trans_action] = true
43
+ end
44
+ end
45
+
46
+ class TWf5 < Workflow
47
+ start_node :start, :trans => :end
48
+ end_node :end
49
+
50
+ def self.start_default_trans_action(token, caller)
51
+ $mylog[:trans_action] = true
52
+ end
53
+ end
54
+
55
+ class TWf6 < Workflow
56
+ start_node :start,
57
+ :trans => :end,
58
+ :trans_action => lambda { $mylog[:trans_action] = true }
59
+ end_node :end
60
+ end
61
+
62
+ class TWf7 < Workflow
63
+ start_node :start,
64
+ :no_trans => :no_end,
65
+ :no_trans_cond => '"no" == token[:my_cond]',
66
+ :yes_trans => :yes_end,
67
+ :yes_trans_cond => '"yes" == token[:my_cond]'
68
+ end_node :no_end
69
+ end_node :yes_end
70
+ end
71
+
72
+ class FewMoreRbpm2Test < Test::Unit::TestCase
73
+
74
+ def test_transition_ctions
75
+ [TWf1, TWf2, TWf3, TWf4, TWf5, TWf6].each do |workflow|
76
+ wf1 = workflow.new
77
+
78
+ $mylog.clear
79
+
80
+ t = wf1.start()
81
+
82
+ assert_equal :end, t.node
83
+ assert_not_nil $mylog[:trans_action]
84
+ end
85
+ end
86
+
87
+ def test_transition_conditions
88
+ ["no", "yes"].each do |no_yes|
89
+ wf = TWf7.new
90
+ t = wf.start :my_cond => no_yes
91
+ assert_equal (no_yes + "_end").to_sym, t.node
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,44 @@
1
+ require 'test/unit'
2
+ require 'rbpm'
3
+
4
+ module FooBarWorkflowVersion1
5
+ class FooBarWorkflow
6
+ def foo
7
+ "v1"
8
+ end
9
+ def bar
10
+ WorkflowVersionManager.create_workflow_instance('FooBarWorkflow', 1).foo
11
+ end
12
+ end
13
+ end
14
+
15
+ module FooBarWorkflowVersion3
16
+ class FooBarWorkflow
17
+ def foo
18
+ "v3"
19
+ end
20
+ end
21
+ end
22
+
23
+ module FooBarWorkflowVersion2
24
+ class FooBarWorkflow
25
+ def foo
26
+ "v2"
27
+ end
28
+ def bar
29
+ WorkflowVersionManager.create_workflow_instance('FooBarWorkflow').foo
30
+ end
31
+ end
32
+ end
33
+
34
+ class VersionningTests < Test::Unit::TestCase
35
+
36
+ def test_versionning
37
+ assert_equal "v3", WorkflowVersionManager.create_workflow_instance('FooBarWorkflow').foo
38
+ assert_equal "v3", WorkflowVersionManager.create_workflow_instance('FooBarWorkflow', 2).bar
39
+ assert_equal "v1", WorkflowVersionManager.create_workflow_instance('FooBarWorkflow', 1).bar
40
+ (1..3).each do |version|
41
+ assert_equal "v#{version}", WorkflowVersionManager.create_workflow_instance('FooBarWorkflow', version).foo
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,116 @@
1
+ require 'test/unit'
2
+
3
+ class FooClazz
4
+ def self.foo
5
+ "outer"
6
+ end
7
+ end
8
+
9
+ class FooBarClazz
10
+ def self.foo
11
+ "foobar"
12
+ end
13
+ end
14
+
15
+ module BarModule
16
+ class BarClazz
17
+ def self.foo
18
+ "bar"
19
+ end
20
+ end
21
+
22
+ class FooClazz
23
+ def self.foo
24
+ "inner"
25
+ end
26
+ end
27
+
28
+ class Test
29
+ def self.foo
30
+ return FooClazz.foo + ":" + BarClazz.foo + ":" + FooBarClazz.foo
31
+ end
32
+ end
33
+ end
34
+
35
+ $MY_V1 = <<-ecode
36
+ module MyV1
37
+ class MyClass
38
+ def foo
39
+ "v1"
40
+ end
41
+ end
42
+ end
43
+ ecode
44
+
45
+ $MY_V1_B = <<-ecode
46
+ module MyV1
47
+ class MyClass
48
+ def foo
49
+ "v1b"
50
+ end
51
+ end
52
+ end
53
+ ecode
54
+
55
+ $MY_V2 = <<-ecode
56
+ module MyV2
57
+ class MyClass
58
+ def foo
59
+ "v2"
60
+ end
61
+ end
62
+ end
63
+ ecode
64
+
65
+ class SimpleRubyLangTests < Test::Unit::TestCase
66
+
67
+ def test_if_stuff
68
+ a = 1
69
+ a = 2 if false
70
+ assert_equal 1, a
71
+ b = 1 if false
72
+ assert_nil b
73
+ end
74
+
75
+ def test_regexp
76
+ a = "willi"
77
+ assert_not_nil "a_willi_b" =~ /_#{a}_/
78
+ assert_nil "a-willi_b" =~ /_#{a}_/
79
+ end
80
+
81
+ def test_class_loading_stuff
82
+ m_before = []
83
+ ObjectSpace.each_object(Module) do |m|
84
+ m_before << m.to_s
85
+ end
86
+
87
+ assert_nil defined? MyV1::MyClass
88
+ assert_nil defined? MyV2::MyClass
89
+
90
+ eval($MY_V1)
91
+ assert_equal "v1", MyV1::MyClass.new.foo
92
+
93
+ assert_not_nil defined? MyV1::MyClass
94
+ assert_nil defined? MyV2::MyClass
95
+
96
+ eval($MY_V2)
97
+ assert_equal "v2", MyV2::MyClass.new.foo
98
+
99
+ eval($MY_V1_B)
100
+ assert_equal "v1b", MyV1::MyClass.new.foo
101
+
102
+ m_after = []
103
+ ObjectSpace.each_object(Module) do |m|
104
+ m_after << m.to_s
105
+ end
106
+
107
+ m_new = m_after - m_before
108
+ assert_equal 4, m_new.length #2 * (Module + Class within Module)
109
+
110
+ #puts m_new.join(", ") #=> SimpleRubyLangTests::MyV2::MyClass, SimpleRubyLangTests::MyV2, SimpleRubyLangTests::MyV1::MyClass, SimpleRubyLangTests::MyV1
111
+ end
112
+
113
+ def test_misc
114
+ assert_equal "inner:bar:foobar", BarModule::Test.foo
115
+ end
116
+ end
@@ -0,0 +1,14 @@
1
+ require 'test/unit'
2
+
3
+ require 'test/rbpm_action_tests'
4
+ require 'test/rbpm_ctxvars_tests.rb'
5
+ require 'test/rbpm_simple_tests.rb'
6
+ require 'test/rbpm_versionning_tests.rb'
7
+ require 'test/rbpm_call_tests.rb'
8
+ require 'test/rbpm_exceptions_tests.rb'
9
+ require 'test/rbpm_state_tests.rb'
10
+ require 'test/rbpm_condition_tests.rb'
11
+ require 'test/rbpm_fork_join_tests.rb'
12
+ require 'test/rbpm_transition_tests.rb'
13
+
14
+ require 'test/ruby_lang_tests.rb'
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.8.10
3
+ specification_version: 1
4
+ name: rbpm
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.0.1
7
+ date: 2006-01-05
8
+ summary: lightweight (jbpm-like) workflow framework
9
+ require_paths:
10
+ - lib
11
+ email: furthermore@tschenett.ch
12
+ homepage: http://rbpm.rubyforge.org
13
+ rubyforge_project:
14
+ description:
15
+ autorequire: rbpm
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: false
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ -
22
+ - ">"
23
+ - !ruby/object:Gem::Version
24
+ version: 0.0.0
25
+ version:
26
+ platform: ruby
27
+ authors:
28
+ - Christian Tschenett
29
+ files:
30
+ - test/rbpm_action_tests.rb
31
+ - test/rbpm_call_tests.rb
32
+ - test/rbpm_condition_tests.rb
33
+ - test/rbpm_ctxvars_tests.rb
34
+ - test/rbpm_exceptions_tests.rb
35
+ - test/rbpm_fork_join_tests.rb
36
+ - test/rbpm_simple_tests.rb
37
+ - test/rbpm_state_tests.rb
38
+ - test/rbpm_transition_tests.rb
39
+ - test/rbpm_versionning_tests.rb
40
+ - test/ruby_lang_tests.rb
41
+ - test/ts_all.rb
42
+ - lib/rbpm.rb
43
+ - docs/sub_processes.png
44
+ - docs/todo.txt
45
+ - README
46
+ test_files:
47
+ - test/ts_all.rb
48
+ rdoc_options: []
49
+ extra_rdoc_files:
50
+ - README
51
+ executables: []
52
+ extensions: []
53
+ requirements: []
54
+ dependencies: []