d00596cfefc35104b26718f768001ca5e1065247
[irspy-moved-to-github.git] / lib / ZOOM / IRSpy / Test / Search / Bath.pm
1 # This tests the main searches specified The Bath Profile, Release 2.0, 
2 #       http://www.collectionscanada.gc.ca/bath/tp-bath2-e.htm
3 # Specifically section 5.A.0 ("Functional Area A: Level 0 Basic
4 # Bibliographic Search and Retrieval") the its subsections.
5
6 package ZOOM::IRSpy::Test::Search::Bath;
7
8 use 5.008;
9 use strict;
10 use warnings;
11
12 use ZOOM::IRSpy::Test;
13 our @ISA = qw(ZOOM::IRSpy::Test);
14
15 use ZOOM::IRSpy::Utils qw(isodate);
16
17
18 my @bath_queries = (
19     [ author => 1003 ], # 5.A.0.1
20     [ title => 4 ],     # 5.A.0.2
21     [ subject => 21 ],  # 5.A.0.3
22     [ any => 1016 ],    # 5.A.0.4
23     );
24
25
26 sub start {
27     my $class = shift();
28     my($conn) = @_;
29
30     start_search($conn, 0);
31 }
32
33
34 sub start_search {
35     my($conn, $qindex) = @_;
36
37     return ZOOM::IRSpy::Status::TEST_GOOD
38         if $qindex >= @bath_queries;
39
40     my $ref = $bath_queries[$qindex];
41     my($name, $use_attr) = @$ref;
42
43     my $query = "\@attr 1=$use_attr \@attr 2=3 \@attr 3=3 \@attr 4=2 \@attr 5=100 \@attr 6=1 the";
44     $conn->irspy_search_pqf($query, { qindex => $qindex }, {},
45                             ZOOM::Event::ZEND, \&search_complete,
46                             "exception", \&search_complete);
47     return ZOOM::IRSpy::Status::TASK_DONE;
48 }
49
50
51 sub search_complete {
52     my($conn, $task, $udata, $event) = @_;
53     my $ok = ref $event && $event->isa("ZOOM::Exception") ? 0 : 1;
54
55     my $qindex = $udata->{qindex};
56     my $ref = $bath_queries[$qindex];
57     my($name, $use_attr) = @$ref;
58
59     my $n = $task->{rs}->size();
60
61     $conn->log("irspy_test", "bath search #$qindex ('$name') ",
62                $ok ? ("found $n record", $n==1 ? "" : "s") :
63                       "had error: $event");
64
65     my $rec = $conn->record();
66     $rec->append_entry("irspy:status",
67                        "<irspy:search_bath name='$name' ok='$ok'>" .
68                        isodate(time()) . "</irspy:search_bath>");
69
70     return start_search($conn, $qindex+1);
71 }
72
73
74 1;