1 # -*-Perl-*- Test Harness script for Bioperl
10 test_begin(-tests => 29,
11 -requires_networking => 1);
13 use_ok('Bio::Root::HTTPget');
16 my $TESTURL = 'http://www.google.com/index.html';
18 my $TEST_PROXY = 'http://myproxy';
20 my @TEST_AUTHENTICATION = qw(foo bar);
26 =head1 Bio::Root::HTTPget comments
28 This module is a bit schizophrenic in that it is called in three different
29 ways; as an instance method, a class method, or as an explicit subroutine.
31 These tests check for all call types. They are by no means incomplete.
35 # test object method calls
36 my $obj = Bio::Root::HTTPget->new();
38 ok defined($obj) && $obj->isa('Bio::Root::Root');
40 lives_ok {$obj->get($TESTURL)};
41 lives_ok {$fh = $obj->getFH($TESTURL)};
42 isa_ok($fh, 'IO::Socket::INET');
46 is ($obj->proxy(), undef);
47 is_deeply([$obj->authentication], []);
48 $obj->proxy('http', $TEST_PROXY);
49 $obj->authentication(@TEST_AUTHENTICATION);
50 is ($obj->proxy(), $TEST_PROXY);
51 is_deeply([$obj->authentication], \@TEST_AUTHENTICATION);
53 # test class method calls; note that mixing class and sub calls pollutes the
56 lives_ok {Bio::Root::HTTPget->get($TESTURL)};
57 lives_ok {$fh = Bio::Root::HTTPget->getFH($TESTURL)};
58 isa_ok($fh, 'IO::Socket::INET');
62 is (Bio::Root::HTTPget->proxy(), undef);
63 is_deeply([Bio::Root::HTTPget->authentication], []);
64 Bio::Root::HTTPget->proxy('http', $TEST_PROXY);
65 Bio::Root::HTTPget->authentication(@TEST_AUTHENTICATION);
66 is (Bio::Root::HTTPget->proxy('http'), $TEST_PROXY);
67 is_deeply([Bio::Root::HTTPget->authentication], \@TEST_AUTHENTICATION);
69 # test sub calls (not called as method)
71 lives_ok {Bio::Root::HTTPget::get($TESTURL)};
72 lives_ok {$fh = Bio::Root::HTTPget::getFH($TESTURL)};
73 isa_ok($fh, 'IO::Socket::INET');
77 # note that mixing class and sub calls pollutes the class attributes, have to
79 Bio::Root::HTTPget->authentication(undef, undef);
81 my $old = Bio::Root::HTTPget->clear_proxy('http');
82 is (Bio::Root::HTTPget::proxy(), undef);
83 is ($old, $TEST_PROXY);
85 is_deeply([Bio::Root::HTTPget->authentication], [undef, undef]);
86 Bio::Root::HTTPget::proxy('http', $TEST_PROXY);
87 Bio::Root::HTTPget::authentication(@TEST_AUTHENTICATION);
88 is (Bio::Root::HTTPget::proxy('http'), $TEST_PROXY);
89 is_deeply([Bio::Root::HTTPget->authentication], \@TEST_AUTHENTICATION);
91 # check to make sure new instance attributes are not polluted by class attrbutes
94 my $newobj = Bio::Root::HTTPget->new();
96 ok defined($newobj) && $obj->isa('Bio::Root::Root');
98 is ($newobj->proxy(), undef);
99 is_deeply([$newobj->authentication], []);
100 $newobj->proxy('http', $TEST_PROXY);
101 $newobj->authentication(@TEST_AUTHENTICATION);
102 is ($newobj->proxy(), $TEST_PROXY);
103 is_deeply([$newobj->authentication], \@TEST_AUTHENTICATION);