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