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