| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package PICA::Modification::TestQueue; |
|
2
|
|
|
|
|
|
|
{ |
|
3
|
|
|
|
|
|
|
$PICA::Modification::TestQueue::VERSION = '0.16'; |
|
4
|
|
|
|
|
|
|
} |
|
5
|
|
|
|
|
|
|
#ABSTRACT: Unit test implementations of PICA::Modification::Queue |
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
632
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
36
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
23
|
|
|
9
|
1
|
|
|
1
|
|
12
|
use v5.10; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
45
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
22
|
use Test::More 0.96; |
|
|
1
|
|
|
|
|
27
|
|
|
|
1
|
|
|
|
|
8
|
|
|
12
|
1
|
|
|
1
|
|
1251
|
use PICA::Modification; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use Test::JSON::Entails; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use parent 'Exporter'; |
|
16
|
|
|
|
|
|
|
our @EXPORT = qw(test_queue); |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub test_queue { |
|
19
|
|
|
|
|
|
|
my $queue = shift; |
|
20
|
|
|
|
|
|
|
my $name = shift; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
subtest $name => sub { |
|
23
|
|
|
|
|
|
|
my $test = bless { queue => $queue }, __PACKAGE__; |
|
24
|
|
|
|
|
|
|
$test->run; |
|
25
|
|
|
|
|
|
|
}; |
|
26
|
|
|
|
|
|
|
} |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub get { my $t = shift; $t->{queue}->get(@_); } |
|
29
|
|
|
|
|
|
|
sub request { my $t = shift; $t->{queue}->request(@_); } |
|
30
|
|
|
|
|
|
|
sub update { my $t = shift; $t->{queue}->update(@_); } |
|
31
|
|
|
|
|
|
|
sub delete { my $t = shift; $t->{queue}->delete(@_); } |
|
32
|
|
|
|
|
|
|
sub list { my $t = shift; $t->{queue}->list(@_); } |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub run { |
|
35
|
|
|
|
|
|
|
my $self = shift; |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my $list = $self->list(); |
|
38
|
|
|
|
|
|
|
is_deeply $list, [], 'empty queue'; |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my $mod = PICA::Modification->new( |
|
41
|
|
|
|
|
|
|
del => '012A', |
|
42
|
|
|
|
|
|
|
id => 'foo:ppn:123', |
|
43
|
|
|
|
|
|
|
); |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $id = $self->request( $mod ); |
|
46
|
|
|
|
|
|
|
ok( $id, "inserted modification" ); |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my $got = $self->get($id); |
|
49
|
|
|
|
|
|
|
entails $got => $mod->attributes, 'get stored modification'; |
|
50
|
|
|
|
|
|
|
isa_ok $got, 'PICA::Modification::Request'; |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
my $req = PICA::Modification::Request->new($mod); |
|
53
|
|
|
|
|
|
|
is $self->request($req), undef, 'reject insertion of modification requests'; |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
$list = $self->list(); |
|
56
|
|
|
|
|
|
|
is scalar @$list, 1, 'list size 1'; |
|
57
|
|
|
|
|
|
|
entails $list->[0] => $mod->attributes, 'list contains modification'; |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
$list = $self->list(limit => 1); |
|
60
|
|
|
|
|
|
|
is scalar @$list, 1, 'list option "limit"'; |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
$mod = PICA::Modification->new( del => '012A', id => 'bar:ppn:123' ); |
|
63
|
|
|
|
|
|
|
my $id2 = $self->request( $mod ); |
|
64
|
|
|
|
|
|
|
$list = $self->list( sort => 'id' ); |
|
65
|
|
|
|
|
|
|
is scalar @$list, 2, 'list size 2 after inserting second modification'; |
|
66
|
|
|
|
|
|
|
is $list->[0]->{id}, 'bar:ppn:123', 'list can be sorted'; |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
$list = $self->list( id => 'foo:ppn:123' ); |
|
69
|
|
|
|
|
|
|
is scalar @$list, 1, 'search by field value'; |
|
70
|
|
|
|
|
|
|
is $list->[0]->{id}, 'foo:ppn:123', 'only list matching modifications'; |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
foreach (0..4) { |
|
73
|
|
|
|
|
|
|
$mod = PICA::Modification->new( del => '012A', id => "doz:ppn:1$_" ); |
|
74
|
|
|
|
|
|
|
$self->request($mod); |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
$list = $self->list( sort => 'id', limit => 3 ); |
|
77
|
|
|
|
|
|
|
is scalar @$list, 3, 'inserted five additional modifications, limit works'; |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
$list = $self->list( sort => 'id', limit => 3, page => 2 ); |
|
80
|
|
|
|
|
|
|
is scalar @$list, 3, 'limit'; |
|
81
|
|
|
|
|
|
|
is $list->[0]->{id}, 'doz:ppn:12', 'page'; |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
$mod = PICA::Modification->new( add => '028A $xfoo', del => '028A', id => 'ab:ppn:1' ); |
|
84
|
|
|
|
|
|
|
$id2 = $self->update( $id => $mod ); |
|
85
|
|
|
|
|
|
|
is $id2, $id, 'update allowed'; |
|
86
|
|
|
|
|
|
|
$mod = $self->get($id); |
|
87
|
|
|
|
|
|
|
is $mod->{del}, '028A', 'update changed'; |
|
88
|
|
|
|
|
|
|
is $mod->{add}, '028A $xfoo', 'update changed'; |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
$mod = PICA::Modification->new( del => '012A', id => 'xxx' ); |
|
92
|
|
|
|
|
|
|
is $self->request($mod), undef, 'reject modification with error'; |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
$mod = PICA::Modification->new( del => '012A', id => 'xxx' ); |
|
95
|
|
|
|
|
|
|
is $self->update( $id => $mod), undef, 'reject modification with error'; |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
my $delid = $self->delete($id); |
|
98
|
|
|
|
|
|
|
is $delid, $id, 'deleted modification'; |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
$got = $self->get($id); |
|
101
|
|
|
|
|
|
|
is $got, undef, 'deleted modification returns undef'; |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
__END__ |