1
# -*-Perl-*- Test Harness script for Bioperl
2
# $Id: Biblio.t 15364 2009-01-13 17:18:10Z cjfields $
10
test_begin(-tests => 24);
12
use_ok('Bio::Biblio');
13
use_ok('Bio::Biblio::IO');
17
my $verbose = test_debug();
19
my $testfile = test_input_file('stress_test_medline.xml');
20
my $testfile2 = test_input_file('stress_test_pubmed.xml');
24
test_skip(-tests => 1, -requires_module => 'SOAP::Lite');
25
ok my $biblio = Bio::Biblio->new(-location => 'http://localhost:4567');
28
# check MEDLINE XML parser
31
test_skip(-tests => 4, -requires_module => 'XML::Parser');
33
ok defined ($io = Bio::Biblio::IO->new('-format' => 'medlinexml',
37
print "Reading and parsing MEDLINE XML file...\n" if $verbose;
38
is ($io->next_bibref->{'medlineID'}, 'Text1', 'citation 1');
39
is ($io->next_bibref->{'medlineID'}, 'Text248', 'citation 2');
40
is ($io->next_bibref->{'medlineID'}, 'Text495', 'citation 3');
44
test_skip(-tests => 4, -requires_module => 'XML::Parser');
45
print "Getting citations using callback...\n" if $verbose;
46
my (@ids) = ('Text1', 'Text248', 'Text495');
47
my $callback_used = 'no';
48
$io = Bio::Biblio::IO->new('-format' => 'medlinexml',
50
#'-result' => 'medline2ref', # this is default
51
'-callback' => \&callback);
53
is ( $callback_used, 'yes', 'calling callback');
57
$callback_used = 'yes';
58
is ($citation->{'_identifier'}, shift @ids, 'in callback');
63
test_skip(-tests => 2, -requires_module => 'XML::Parser');
65
$io = Bio::Biblio::IO->new('-format' => 'medlinexml',
69
<MedlineID>12345678</MedlineID>
70
<Article><Journal></Journal></Article>
73
<MedlineID>abcdefgh</MedlineID>
74
<Article><Journal></Journal></Article>
78
'-result' => 'medline2ref');
80
is ($io->next_bibref->{'_identifier'}, '12345678', 'citation 1');
81
is ($io->next_bibref->{'_identifier'}, 'abcdefgh', 'citation 2');
85
test_skip(-tests => 2, -requires_modules => [qw(XML::Parser IO::String)]);
87
print "Reading and parsing XML string handle...\n" if $verbose;
91
<MedlineID>87654321</MedlineID>
92
<Article><Journal></Journal></Article>
95
<MedlineID>hgfedcba</MedlineID>
96
<Article><Journal></Journal></Article>
101
$io = Bio::Biblio::IO->new('-format' => 'medlinexml',
102
'-fh' => IO::String->new ($data));
103
is (eval { $io->next_bibref->identifier }, '87654321', 'citation 1');
104
is (eval { $io->next_bibref->identifier }, 'hgfedcba', 'citation 2');
108
test_skip(-tests => 5, -requires_module => 'XML::Parser');
110
# check PUBMED XML parser
111
ok defined (eval { $io = Bio::Biblio::IO->new('-format' => 'pubmedxml',
112
'-file' => $testfile2,
113
'-result' => 'pubmed2ref') });
115
print "Reading and parsing PUBMED XML file...\n" if $verbose;
117
is ($io->next_bibref->identifier, '11223344', 'citation 1');
118
is ($io->next_bibref->identifier, '21583752', 'citation 2');
119
is ($io->next_bibref->identifier, '21465135', 'citation 3');
120
is ($io->next_bibref->identifier, '21138228', 'citation 4');
126
my @expvals = qw(11223344 21583752 21465135 21138228);
127
print "Testing FH\n" if $verbose;
129
$fh = Bio::Biblio::IO->newFh('-format' => 'pubmedxml',
130
'-file' => $testfile2,
131
'-result' => 'pubmed2ref');
133
is($_->identifier,shift @expvals, 'filehandle test');
137
skip("unable to use pubmedxml",4);