Added some extra debugging.
[irspy-moved-to-github.git] / lib / ZOOM / IRSpy / Test / Record / Fetch.pm
1 # $Id: Fetch.pm,v 1.6 2006-10-25 11:44:35 sondberg Exp $
2
3 # See the "Main" test package for documentation
4
5 package ZOOM::IRSpy::Test::Record::Fetch;
6
7 use 5.008;
8 use strict;
9 use warnings;
10
11 use ZOOM::IRSpy::Test;
12 our @ISA = qw(ZOOM::IRSpy::Test);
13
14
15 sub start {
16     my $class = shift();
17     my($conn) = @_;
18     my @syntax = (
19                    'canmarc',
20                    'danmarc',
21                    'grs-1',
22                    'ibermarc',
23                    'intermarc',
24                    'jpmarc',
25                    'librismarc',
26                    'mab',
27                    'normarc',
28                    'opac',
29                    'picamarc',
30                    'rusmarc',
31                    'summary',
32                    'sutrs',
33                    'swemarc',
34                    'ukmarc',
35                    'unimarc',
36                    'usmarc',
37                    'xml'
38                 );
39
40     foreach my $syn (@syntax) {
41         ## Here I want to get a use attribute from the session, which we've
42         ## managed to search for in the Search/Bib1 or Search/Dan1 tests. But
43         ## how? So far we search for title: 1=4
44         $conn->irspy_search_pqf("\@attr 1=4 mineral",
45                                 {'syntax' => $syn},
46                                 { start => 0, count => 1,
47                                   preferredRecordSyntax => $syn },
48                                 ZOOM::Event::RECV_RECORD, \&record,
49                                 exception => \&error);
50     }
51 }
52
53
54 sub record {
55     my($conn, $task, $test_args, $event) = @_;
56     my $syn = $test_args->{'syntax'};
57     my $rs = $task->{rs};
58
59     if (1) {
60         print STDERR "Hits: ", $rs->size(), "\n";
61         print STDERR "Syntax: ", $syn, "\n";
62         print STDERR $rs->record(0)->render();
63     }
64
65     $conn->log("irspy_test", "Successfully retrieved a $syn record");
66     $conn->record()->store_result('record_fetch',
67                                   'syntax'   => $syn,
68                                   'ok'       => 1);
69
70     return ZOOM::IRSpy::Status::TASK_DONE;
71 }
72
73
74 sub error {
75     my($conn, $task, $test_args, $exception) = @_;
76     my $syn = $test_args->{'syntax'};
77
78     $conn->log("irspy_test", "Retrieval of $syn record failed: ", $exception);
79     $conn->record()->store_result('record_fetch',
80                                   'syntax'       => $syn,
81                                   'ok'        => 0);
82     return ZOOM::IRSpy::Status::TASK_DONE;
83 }
84
85
86 1;