Sync with trunk
[bioperl-live.git] / t / RemoteDB / HIV / HIV.t
blob936d13d9910e097dbd670785c72f8757a57b3698
1 # testing Bio::DB::HIV
2 #$Id: HIV.t 232 2008-12-11 14:51:51Z maj $#
3 use strict;
4 use warnings;
6 BEGIN {
7     use Bio::Root::Test;
8     test_begin(
9         -tests => 29,
10         -requires_modules => [qw( XML::Simple HTTP::Request::Common)],
11         );
12     use_ok('Bio::DB::HIV');
13     use_ok('Bio::DB::WebDBSeqI');
14     use_ok('Bio::DB::HIV::HIVAnnotProcessor');
17 my $tobj= Bio::DB::HIV->new();
19 $tobj->ua->timeout(90);
21 #object tests
22 isa_ok($tobj, 'Bio::DB::HIV');
24 #compliance tests
25 isa_ok($tobj, 'Bio::Root::Root');
26 can_ok($tobj, qw( get_request postprocess_data ));
28 #methods
29 can_ok($tobj, qw( get_seq_stream get_Stream_by_acc get_Stream_by_query _request ));
31 #internals
32 can_ok($tobj, qw( lanl_base map_db make_search_if search_ _map_db_uri _make_search_if_uri _search_uri _session_id _sorry ));
34 # defaults tests
35 ok($tobj->lanl_base, 'lanl_base set in default object');
36 ok($tobj->map_db, 'map_db set in default object');
37 ok($tobj->make_search_if, 'make_search_if set in default object');
38 ok($tobj->search_, 'search_ set in default object');
39 ok($tobj->url_base_address, 'url_base_address set in default object');
40 is(($tobj->request_format)[0], "fasta", 'default sequence request format (fasta)');
42 #todos
43 throws_ok { $tobj->get_request('mode'=>'version', 'uids'=>['K03455.1']) } qr/Bio::HIVSorry::Exception/, 'sorry till implemented';
45 throws_ok {$tobj->get_request('mode'=>'gi', 'uids'=>['1906382'])} qr/Bio::HIVSorry::Exception/, 'sorry till implemented';
47 #exception tests
48 my $badq = bless({}, "Not::A::Query");
49 throws_ok {$tobj->get_Stream_by_query($badq)} qr/HIVQuery required/, 'HIVQuery type exception check';
51 # network tests
52 SKIP: {
53     test_skip(-tests => 12,
54           -requires_networking => 1);
55     
56     # WebDBSeqI compliance-
57     # (this requires network access, since request is built after establishing
58     # the LANL session...)
59     my $req;
60     eval {$req = $tobj->get_request('mode'=>'single','uids'=>['17756'])};
61     if ($@) {
62         diag("Error: $@");
63         skip("Network problems, skipping all tests: $@", 12)
64     }
65     isa_ok($req, 'HTTP::Request', 'Object returned from get_request');
66     # get_... functionality
67     eval {
68         ok($tobj->get_Seq_by_id('17756'), 'get HXB2 by LANL id');
69         ok($tobj->get_Seq_by_acc('K03455'), 'get HXB2 by GB accession');
70     };
71     if ($@) {
72         diag("Error: $@");
73         skip("Network problems, skipping all tests: $@", 11)
74     }
75     my ($seqio, $hxb2);
76     eval {
77         ok($seqio = $tobj->get_Stream_by_id(['17756']), 'get HXB2 in a stream');
78         ok($seqio = $tobj->get_Stream_by_acc(['K03455']), 'get HXB2 in a stream by accession');
79     };
80     if ($@) {
81         diag("Error: $@");
82         skip("Network problems, skipping all tests: $@", 9)
83     }
84     $hxb2 =  $seqio->next_seq;
85     is($hxb2->primary_id, 'K03455', 'checking returned stream');
86     is($hxb2->alphabet,'dna', 'checking returned stream');
87     ok(!($hxb2->seq !~ /atgc/i), 'checking returned sequence');
88     #network exceptions
89     
90     # bad id exception
91     throws_ok { $tobj->get_Seq_by_id('XXXXXX') } qr/no sequences found/i, 'bad id exception check';
92     # session id exception
93     $tobj->_session_id('555-1212');
94     throws_ok {$tobj->get_Seq_by_id('17756')} qr/request failed/, 'bad session exception check';
95     # bad url exception
96     $tobj->_session_id('');
97     $tobj->map_db('');
98     $tobj->url_base_address('http://socrates_jones_et_cie.us');
99     throws_ok {$tobj->get_Seq_by_id('17756')} qr/Connect failed/, 'bad url exception check';
100     # wrong url exception 
101     $tobj->url_base_address('http://fortinbras.us');
102     throws_ok {$tobj->get_Seq_by_id('17756')} qr/Session not established/, 'wrong url exception check';
103     
104 # check ..._by_query functions in HIVQuery.t