Fix tests; need to look at Analysis::soap::results()
[bioperl-run.git] / t / Analysis_soap.t
blob7d7e6b2a4bda1d54cc89e34dcc66edead2c37e56
1 # This is -*-Perl-*- code
2 ## Bioperl Test Harness Script for Modules
3 ##
4 # $Id$
6 # Before `make install' is performed this script should be runnable with
7 # `make test'. After `make install' it should work as `perl Analysis_soap.t'
9 use strict;
10 use vars qw($NUMTESTS);
11 use lib '..','./blib/lib';
12 use Data::Dumper;
13 my $error;
15 BEGIN { 
16     # to handle systems with no installed Test module
17     # we include the t dir (where a copy of Test.pm is located)
18     # as a fallback
19     eval { require Test; };
20     $error = 0;
21     if( $@ ) {
22         use lib 't';
23     }
24     use Test;
25     $NUMTESTS = 17;
26     plan tests => $NUMTESTS;
29 my $testnum;
30 my $verbose = 0;
32 ## End of black magic.
34 ## Insert additional test code below but remember to change
35 ## the 'plan tests =>...' in the BEGIN block to reflect the
36 ## total number of tests that will be run. 
38 my $serror = 0;
40 my $format = ($ENV{'TEST_DETAILS'} ? '%-40s' : '');
42 # check 'use ...'
43 eval { require Bio::Tools::Run::Analysis };
44 print sprintf ($format, 'use Bio::Tools::Run::Analysis '); ok (%Bio::Tools::Run::Analysis::);
45 &print_error;
47 # TBD:
48 # Here I should add some tests for the various methods doing just
49 # data conversions...
51 # the rest makes sense only with SOAP::Lite installed
52 unless (eval "require SOAP::Lite; 1;") {
53     print STDERR "SOAP::Lite not installed. Skipping some tests.\n";
54     $serror = 1;
56 if ($serror) {
57     foreach ( $Test::ntest..$NUMTESTS) { 
58         skip (1,1);
59     }
60     exit (0);
63 # check 'new with a default access...'
64 my $seqret;
65 #eval { $seqret = new Bio::Tools::Run::Analysis (-name => 'edit.seqret'); };
66 $seqret = new Bio::Tools::Run::Analysis (-name => 'edit.seqret');
67 print sprintf ($format, 'new ...Analysis (-name=>seqret) '); skip ($serror, defined $seqret);
68 &print_error;
70 # the rest makes sense only if an Analysis object was created
71 unless ($seqret) {
72     foreach ($Test::ntest..$NUMTESTS) { 
73         skip (1,1);
74     }
75     exit (0);
79 # check if the remote service is accessible
80 print sprintf ($format, 'checking service availability ');
81 eval { $seqret->analysis_name };
82 if ($@) {
83     print STDERR "Warning: Couldn't connect to $$seqret{'_location'}.\n" . $@;
84     foreach ( $Test::ntest..$NUMTESTS) { 
85         skip ('skip (probably) because of no network access',1);
86     }
87     exit(0);
88 } else {
89     ok (1);
92 # some testing data (for seqret)
93 my $seq = 'tatacga';
94 my %inputs = ('sequence_direct_data' => $seq,
95               'osformat'             => 'raw',
96               );
98 # check using a real service
99 print sprintf ($format, 'calling "analysis_name" ');
100 skip ($serror, eval { 'seqret' eq $seqret->analysis_name });
101 &print_error;
103 print sprintf ($format, 'calling "analysis_spec" ');
104 skip ($serror, eval { ref ($seqret->analysis_spec) eq 'HASH' });
105 &print_error;
107 my $spec;
108 print sprintf ($format, 'calling "input_spec" ');
109 eval { $spec = $seqret->input_spec };
110 skip ($serror, ref ($spec) eq 'ARRAY' && @$spec > 0 && ref ($$spec[0]) eq 'HASH');
111 &print_error;
113 print sprintf ($format, 'calling "result_spec" ');
114 eval { $spec = $seqret->result_spec };
115 skip ($serror, ref ($spec) eq 'ARRAY' && @$spec > 0 && ref ($$spec[0]) eq 'HASH');
116 &print_error;
118 print sprintf ($format, 'calling "describe" ');
119 skip ($serror, eval { $seqret->describe =~ /^<\?xml / });
120 &print_error;
122 my $job;
123 print sprintf ($format, 'calling "create_job" ');
124 eval { $job = $seqret->create_job (\%inputs) };
125 skip ($serror, ref ($job) =~ /^Bio::Tools::Run::Analysis::Job/);
126 &print_error;
128 my $next_dependent_tests = 4;
129 if ($job) {
130     print sprintf ($format, 'calling "job->status" ');
131     skip ($serror, eval { $job->status eq 'CREATED' });
132     &print_error;
134     my $clone_job;
135     eval { $clone_job = $seqret->create_job ($job->{'_id'}) };
136     print sprintf ($format, 'cloning job ');
137     skip ($serror, ref ($clone_job) =~ /^Bio::Tools::Run::Analysis::Job/);
138     &print_error;
140     $next_dependent_tests = 2;
141     if ($clone_job) {
142         print sprintf ($format, 'calling "new_job->last_event" ');
143         skip ($serror, eval { $clone_job->last_event =~ /^<\?xml / });
144         &print_error;
146         print sprintf ($format, 'calling "new_job->remove" ');
147         eval { $clone_job->remove };
148         skip ($serror, $clone_job->{'_destroy_on_exit'} == 1);
149         &print_error;
150     } else {
151         &skip_tests ($next_dependent_tests);
152     }
153 } else {
154     &skip_tests ($next_dependent_tests);
157 #my $empty_job;
158 #eval { $empty_job = $seqret->create_job() };
159 #print sprintf ($format, 'creating an empty job ');
160 #skip ($serror, ref ($empty_job) =~ /^Bio::Tools::Run::Analysis::Job/);
161 #&print_error;
163 #$next_dependent_tests = 1;
164 #if ($empty_job) {
166 ##    TBD (should be mentioned in TODO)
167 ##    print sprintf ($format, 'calling "empty_job->status" ');
168 ##    skip ($serror, eval { $empty_job->status eq 'CREATED' });
169 ##    &print_error;
171 #    print sprintf ($format, 'calling "empty_job->remove" ');
172 #    eval { $empty_job->remove };
173 #    skip ($serror, $empty_job->{'_destroy_on_exit'} == 1);
174 #    &print_error;
175 #} else {
176 #    &skip_tests ($next_dependent_tests);
179 print sprintf ($format, 'calling "wait_for" ');
180 eval { $job = $seqret->wait_for (\%inputs) };
181 skip ($serror, ref ($job) =~ /^Bio::Tools::Run::Analysis::Job/);
182 &print_error;
184 $next_dependent_tests = 3;
185 if ($job) {
187         # repeated calls to results() retrieves empty hashes;
188         # cache hash ref in a variable
189         my $results = $job->results;
190         
191     print sprintf ($format, 'checking "detailed_status" ');
192     skip ($serror, eval { $results->{'detailed_status'} == 0 });
193     &print_error;
195     print sprintf ($format, 'checking "report" ');
196     skip ($serror, eval { $results->{'report'} =~ /successfully/i });
197     &print_error;
198         
199     print sprintf ($format, 'checking "outseq" ');
200     skip ($serror, eval { $results->{'outseq'} =~ /^$seq$/ });
201     &print_error;
203 } else {
204     &skip_tests ($next_dependent_tests);
209 # skip the next $count tests
210 sub skip_tests {
211     my ($count) = @_;
212     my $msg = "skip because of failure in test " . ($Test::ntest - 1);
213     foreach ( $Test::ntest..($Test::ntest + $count - 1)) { 
214         skip ($msg,1);
215     }
218 # print an error on stderr if there is an error and TEST_DETAILS is on
219 sub print_error {
220     print STDERR $@ if $@ && $ENV{'TEST_DETAILS'};
223 __END__