First functional Bath test.
[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, \&found,
46                             "exception", \&error);
47     return ZOOM::IRSpy::Status::TASK_DONE;
48 }
49
50
51 sub found {
52     my($conn, $task, $udata, $event) = @_;
53
54     my $qindex = $udata->{qindex};
55     my $ref = $bath_queries[$qindex];
56     my($name, $use_attr) = @$ref;
57
58     my $n = $task->{rs}->size();
59
60     $conn->log("irspy_test",
61                "bath search #$qindex ('$name') found $n record",
62                $n==1 ? "" : "s");
63     my $rec = $conn->record();
64     $rec->append_entry("irspy:status",
65                        "<irspy:search_bath name='$name' ok='1'>" .
66                        isodate(time()) . "</irspy:search_bath>");
67
68     return start_search($conn, $qindex+1);
69 }
70
71
72 sub error {
73     my($conn, $task, $udata, $exception) = @_;
74
75     $conn->log("irspy_test", "bath search had error: $exception");
76     my $rec = $conn->record();
77     $rec->append_entry("irspy:status", "<irspy:search_bath ok='0'>" .
78                        isodate(time()) . "</irspy:search_bath>");
79     zoom_error_timeout_update($conn, $exception);
80     return ZOOM::IRSpy::Status::TASK_DONE;
81 }
82
83
84 1;