-
Notifications
You must be signed in to change notification settings - Fork 11
/
workflow.t
170 lines (140 loc) · 5.84 KB
/
workflow.t
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
#!/usr/bin/env perl
use strict;
use lib qw(../lib lib ../t t);
use TestUtil;
use Test::More;
use Test::Exception;
eval "require DBI";
if ( $@ ) {
plan skip_all => 'DBI not installed';
} else {
plan tests => 37;
}
require_ok( 'Workflow' );
my $factory = TestUtil->init_factory();
TestUtil->init_mock_persister();
my $persister = $factory->get_persister( 'TestPersister' );
my $handle = $persister->handle;
# add a separate configuration for the observed workflow
eval {
$factory->add_config_from_file( workflow => 'workflow_observer.xml' )
};
$@ && diag( "Error: $@" );
ok( ! $@, "Added configuration for workflow with observer" );
{
SomeObserver->clear_observations;
my $wf = $factory->create_workflow( 'ObservedTicket' );
my @observations = SomeObserver->get_observations;
is( scalar @observations, 2,
'One observation sent on workflow create to two observers' );
is( $observations[0]->[0], 'class',
'Observation sent to configured class observer first' );
is( $observations[0]->[2], 'create',
'Class observer sent the correct create action' );
is( $observations[1]->[0], 'sub',
'Observation sent to configured subroutine observer second' );
is( $observations[1]->[2], 'create',
'Subroutine observer sent the correct create action' );
}
my $date = DateTime->now;
my @result_fields = ( 'state', 'last_update' );
my @result_data = ( 'INITIAL', $date );
# Check object data.
{
$handle->{mock_add_resultset} = [ \@result_fields, \@result_data ];
my $wf = $factory->fetch_workflow( 'ObservedTicket', 1 );
is( $wf->type(), 'ObservedTicket', 'Got workflow type.');
is( $wf->description(),
'This is the workflow for sample application Ticket',
'Got workflow description.');
is( $wf->time_zone(), 'floating', 'Got floating time zone.');
}
{
SomeObserver->clear_observations;
#The order of these statements are important, see RT #53909
#https://rt.cpan.org/Ticket/Display.html?id=53909
#So this is a temp work around since, the actual perl issue highlighted here
#seem to be fixed in blead (See: Changes file)
$handle->{mock_add_resultset} = [ \@result_fields, \@result_data ];
my $wf = $factory->fetch_workflow( 'ObservedTicket', 1 );
my @observations = SomeObserver->get_observations;
is( scalar @observations, 2,
'One observation sent on workflow fetch to two observers' );
is( $observations[0]->[0], 'class',
'Observation sent to configured class observer first' );
is( $observations[0]->[2], 'fetch',
'Class observer sent the correct fetch action' );
is( $observations[1]->[0], 'sub',
'Observation sent to configured subroutine observer second' );
is( $observations[1]->[2], 'fetch',
'Subroutine observer sent the correct fetch action' );
}
{
$handle->{mock_add_resultset} = [ \@result_fields, \@result_data ];
my $wf = $factory->fetch_workflow( 'ObservedTicket', 1 );
SomeObserver->clear_observations;
$factory->save_workflow( $wf );
my @observations = SomeObserver->get_observations;
is( scalar @observations, 2,
'One observation sent on workflow store to two observers' );
is( $observations[0]->[0], 'class',
'Observation sent to configured class observer first' );
is( $observations[0]->[2], 'save',
'Class observer sent the correct save action' );
is( $observations[1]->[0], 'sub',
'Observation sent to configured subroutine observer second' );
is( $observations[1]->[2], 'save',
'Subroutine observer sent the correct save action' );
}
{
$handle->{mock_add_resultset} = [ \@result_fields, \@result_data ];
my $wf = $factory->fetch_workflow( 'ObservedTicket', 1 );
SomeObserver->clear_observations;
$wf->execute_action( 'null' );
my @observations = SomeObserver->get_observations;
is( scalar @observations, 6,
'Three observations sent on workflow execute to two observers' );
is( $observations[0]->[2], 'save',
'Save observation generated first to first observer' );
is( $observations[1]->[2], 'save',
'Save observation generated first to second observer' );
is( $observations[2]->[0], 'class',
'Observation sent to configured class observer first' );
is( $observations[2]->[2], 'execute',
'Class observer sent the correct execute action' );
is( $observations[2]->[3], 'INITIAL',
'Class observer sent the correct old state for execute' );
is( $observations[3]->[0], 'sub',
'Observation sent to configured subroutine observer second' );
is( $observations[3]->[2], 'execute',
'Subroutine observer sent the correct execute action' );
is( $observations[3]->[3], 'INITIAL',
'Subroutine observer sent the correct old state for execute' );
is( $observations[4]->[0], 'class',
'Observation sent to configured class observer first' );
is( $observations[4]->[2], 'state change',
'Class observer sent the correct state change action' );
is( $observations[4]->[3], 'INITIAL',
'Class observer sent the correct old state for state change' );
is( $observations[5]->[0], 'sub',
'Observation sent to configured subroutine observer second' );
is( $observations[5]->[2], 'state change',
'Subroutine observer sent the correct state change action' );
is( $observations[5]->[3], 'INITIAL',
'Subroutine observer sent the correct old state for state change' );
}
{
throws_ok {
$factory->add_config(
workflow => {
type => 'MyType',
observer => [
{
'sub' => 'SomeObserver::i_dont_exist'
},
],
},
)
} 'Workflow::Exception', "subroutine i_dont_exist causes exception";
like($@, qr/not found/, "expected error string: $@");
}