3 #testing SoapEUtilities and components
10 $home = '.'; # set to '.' for Build use,
11 # '..' for debugging from .t file
13 test_begin(-tests => 139,
14 -requires_modules => [qw(Bio::DB::ESoap
16 Bio::DB::SoapEUtilities
17 Bio::DB::SoapEUtilities::Result
18 Bio::DB::SoapEUtilities::FetchAdaptor
19 Bio::DB::SoapEUtilities::LinkAdaptor
20 Bio::DB::SoapEUtilities::DocSumAdaptor
26 # use data files for most unit testing
27 # see skip section for network tests
30 my $NCBI_SOAP_SVC = "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/soap/v2.0/soap_adapter_2_0.cgi";
31 my @EUTILS = qw( einfo esearch elink egquery epost espell esummary);
33 diag("NOTE: No network access required for these tests; all are local file-based.");
35 ok my $wsdl = Bio::DB::ESoap::WSDL->new(-wsdl => test_input_file('eutils.wsdl')), "wsdl parse from file";
37 is_deeply ( [sort values %{$wsdl->operations}], [sort @EUTILS ], "available operations (as of 1/9/10)" );
38 is $wsdl->service, $NCBI_SOAP_SVC, "correct soap svc url (as of 1/9/10)";
40 is_deeply( $wsdl->request_parameters('einfo'),
45 ] } , 'einfo request parameters');
46 is_deeply( $wsdl->response_parameters('einfo'),
49 {'DbList' => [{'DbName|' => 1 }]},
78 ]}, 'einfo response parameters');
79 is_deeply( $wsdl->request_parameters('egquery'),
80 { 'eGqueryRequest' => [
84 ] } , 'egquery request parameters');
85 is_deeply( $wsdl->response_parameters('egquery'),
88 { 'eGQueryResult' => [
97 ]} , 'egquery response parameters');
101 ok my $dumfac = Bio::DB::ESoap->new( -util => 'run_eLink',
102 -wsdl_file => test_input_file('eutils.wsdl') ), "dummy ESoap factory";
104 is $dumfac->util, 'run_eLink', 'operation accessor';
105 ok $dumfac = Bio::DB::ESoap->new( -util => 'elink',
106 -wsdl_file => test_input_file('eutils.wsdl') ), "dummy ESoap factory";
107 is $dumfac->util, 'run_eLink', 'operation name converted';
109 is( (File::Spec->splitpath($dumfac->wsdl_file))[-1], 'eutils.wsdl', 'wsdl filename accessor' );
110 is $dumfac->_request_elt_name, 'eLinkRequest', 'request element name';
111 is $dumfac->_result_elt_name, 'eLinkResult', 'result element name';
112 is_deeply( [sort $dumfac->available_parameters], [sort qw( db id reldate mindate maxdate datetype term dbfrom linkname WebEnv query_key cmd tool email )], 'elink available parameters via Bio::ParameterBaseI');
113 ok $dumfac->set_parameters( -db => 'gene', -id => 12345, -tool => 'ESoapTest' ), 'set_parameters';
114 ok $dumfac->parameters_changed, "parameters_changed flag set";
115 is_deeply( [$dumfac->get_parameters], [qw( db gene id 12345 tool ESoapTest )],
117 ok !$dumfac->parameters_changed, "parameters_changed flag cleared";
118 is $dumfac->db, 'gene', 'parameter as accessor';
119 is $dumfac->tool, 'ESoapTest', 'parameter as accessor (2)';
120 ok $dumfac->reset_parameters, "reset_parameters";
121 ok $dumfac->parameters_changed, "parameters_changed flipped";
125 ok $dumfac = Bio::DB::SoapEUtilities->new( -wsdl_file => test_input_file('eutils.wsdl') ), "make SoapEU factory";
127 ok $dumfac->esearch( -db => 'gene', -term => 'bat guano' ), "esearch instance";
128 ok $dumfac->elink( -dbfrom => 'protein', -db => 'taxonomy', -id => [1234,5678] ),
130 is_deeply( [$dumfac->esearch->get_parameters],
131 [qw( db gene term ), "bat guano"], "esearch get_parameters");
132 is_deeply( [$dumfac->elink->get_parameters],
133 [qw(db taxonomy dbfrom protein id ), [1234, 5678]],
134 "elink get_parameters" );
135 is $dumfac->esearch->db, 'gene', "esearch delegation";
136 is $dumfac->elink->db, 'taxonomy', "elink delegation";
137 ok $dumfac->esearch->db('protein'), "esearch set parameter by accessor";
138 ok $dumfac->esearch->parameters_changed, "esearch parameters_changed";
139 is $dumfac->esearch->db, 'protein', "was set";
140 ok !$dumfac->elink->parameters_changed, "elink not parameters_changed";
142 # work over SoapEUtilities::Result
145 open my $xmlsumf, test_input_file('esum_result.xml');
147 $dumfac->{'_response_message'} = SOAP::Deserializer->deserialize(<$xmlsumf>);
150 ok my $result = Bio::DB::SoapEUtilities::Result->new($dumfac), "create Result object (esummary)";
151 is $result->util, 'esummary', 'util accessor';
152 is $result->count, 3, "count";
153 is_deeply( $result->ids, [828392, 790, 470338], "ids" );
156 open my $xmlf, test_input_file('esearch_result.xml');
158 $dumfac->{'_response_message'} = SOAP::Deserializer->deserialize(<$xmlf>);
160 ok $result = Bio::DB::SoapEUtilities::Result->new($dumfac), "create Result object (esearch)";
161 is $result->util, 'esearch', 'util accessor';
162 is $result->count, 777, "count";
163 is_deeply $result->ids, [qw(
187 open $xmlf, test_input_file('elink_result.xml');
189 $dumfac->{'_response_message'} = SOAP::Deserializer->deserialize(<$xmlf>);
191 ok $result = Bio::DB::SoapEUtilities::Result->new($dumfac, -no_parse=>1), "create Result object (elink, don't parse)";
192 ok !$result->count, "as requested, did not parse accessors";
193 ok $result->parse_methods( { 'ids' => 'LinkSet_IdList_Id' } ), "parse_methods on object";
194 is $result->util, 'elink', 'util accessor';
195 is $result->count, 3, "count";
196 is_deeply( [sort @{$result->ids}], [sort qw(828392 790 470338)], "ids" );
198 # check accessors; one for each xml tree tip below <eLinkResult>
199 is_deeply( [sort $result->accessors], [ sort qw(
201 LinkSet_DbFrom LinkSet_IdList_Id
202 LinkSet_LinkSetDb_DbTo
203 LinkSet_LinkSetDb_LinkName
204 LinkSet_LinkSetDb_Link_Id) ],
205 "accessors for each response tip" );
207 is ( ref $result->LinkSet, 'HASH', "autoload higher level accessor returns hashref");
208 is( ref $result->LinkSet_LinkSetDb_DbTo, 'ARRAY', "created accessor return arrayref" );
209 is ( $result->count, scalar @{$result->LinkSet_LinkSetDb_DbTo}, "count same as number of records same as number elts returned by accessor");
210 is_deeply( [sort keys %{$result->LinkSet_LinkSetDb}], [sort qw(
211 LinkSet_LinkSetDb_DbTo
212 LinkSet_LinkSetDb_LinkName
213 LinkSet_LinkSetDb_Link_Id) ],
214 "autoload higher level accessor, return list");
215 ok $result->LinkSet_LinkSetDb_LinkName, "LinkName is present";
216 ok $result = Bio::DB::SoapEUtilities::Result->new($dumfac,
221 '//LinkSet/LinkSetDb/LinkName'
222 ), "result, parse but prune at single node //LinkSet/LinkSetDb/LinkName";
223 is ($result->LinkSet_DbFrom->[0], 'gene', "DbFrom");
224 is ($result->gefilte_fish->[0], 'gene', "alias correct");
225 ok $result->LinkSet_LinkSetDb_DbTo, "DbTo present, but..";
226 ok !$result->LinkSet_LinkSetDb_LinkName, "LinkName is not";
227 ok $result = Bio::DB::SoapEUtilities::Result->new($dumfac,
229 ['//LinkSet/LinkSetDb',
231 ), " prune at multiple nodes: //LinkSet/LinkSetDb, //LinkSet/";
233 ok grep(/LinkSet_IdList_Id/, $result->accessors), "IdList_Id present";
234 ok !grep(/LinkSet_LinkSetDb/, $result->accessors), "LinkSet_LinkSetDb not present";
243 'db_to' => 'taxonomy',
244 'link_name' => 'gene_taxonomy',
245 'submitted_ids' => [ [790], [828392], [470338] ],
246 'ids' => [ [9606], [3702], [9598] ],
247 'submitted_ids_flat' => [790, 828392, 470338 ],
248 'ids_flat' => [ 9606, 3702, 9598 ]
251 ok my $links = Bio::DB::SoapEUtilities::LinkAdaptor->new(
253 ), "get linkset adapator";
255 for ($i = 0; my $linkset = $links->next_linkset; $i++) {
256 for ( keys %testdata ) {
259 is_deeply( [$linkset->$_], $testdata{$_}->[$i], "linkset accessor ($_)");
262 is $linkset->$_, $testdata{$_}, "linkset accessor ($_)";
265 is ($links->id_map($testdata{'submitted_ids_flat'}->[$i]),
266 $testdata{'ids_flat'}->[$i], 'id_map correct correspondence');
270 is ($i, 3, "all linksets accessed");
272 ok $links->next_linkset, "rewind works";
278 open $xmlf, test_input_file('esum_result.xml');
280 $dumfac->{'_response_message'} = SOAP::Deserializer->deserialize(<$xmlf>);
282 $result = Bio::DB::SoapEUtilities::Result->new($dumfac, -no_parse=>1);
284 ok my $docsums = Bio::DB::SoapEUtilities::DocSumAdaptor->new(
286 ), "get docsum adaptor";
290 'id' => [828392, 790, 470338],
291 'Name' => [qw(PYR4 CAD CAD)],
292 'Orgname' => [qw(Arabidopsis Homo Pan)],
293 'TaxID' => [3702, 9606, 9598],
294 'ChrAccVer' => [qw( NC_003075.7 NC_000002.11 NC_006469.2 )]
297 for ( $i=0; my $docsum = $docsums->next_docsum; $i++ ) {
298 foreach (keys %testdata) {
300 my $t = $testdata{$_}->[$i];
301 like $docsum->$_, qr/$t/, "docsum accessor ($_)";
304 is ($docsum->GenomicInfo->{$_}, $testdata{$_}->[$i], "docsum hash accessor (GenomicInfo/$_)");
308 is ($i, 3, "all docsums accessed");
310 ok $docsums->next_docsum, "rewind works";
333 is_deeply( [$docsums->next_docsum->item_names], [@item_names], "docsum item list" );
336 ### test FetchAdaptors : add test set with local wsdls and xml result data
337 ### for each new subclass...
338 ### create local wsdls by including and importing types/schemas by hand into
339 ### the local copy (to avoid network hits in this .t)
344 #my ($dumfac, $xmlf,$result,%testdata,$i);
346 ok $dumfac = Bio::DB::SoapEUtilities->new( -wsdl_file => test_input_file('efetch_seq.wsdl') ), "change wsdl";
348 open $xmlf, test_input_file('gb_result.xml');
350 $dumfac->{'_response_message'} = SOAP::Deserializer->deserialize(<$xmlf>);
352 ok $result = Bio::DB::SoapEUtilities::Result->new($dumfac, -no_parse=>1), "create Result object (efetch protein (GenBank), don't parse methods)";
354 ok my $seqio = Bio::DB::SoapEUtilities::FetchAdaptor->new( -result => $result ),
355 "create FetchAdaptor";
357 isa_ok $seqio, 'Bio::DB::SoapEUtilities::FetchAdaptor::seq';
360 'id' => [qw( CAB02640 EAS10332 )],
361 'seq' => [qw( mgaagdaaigres mgapdqsgsdrelmsa )],
362 'alphabet' => [qw( protein protein )],
363 'molecule' => [qw( AA AA )],
364 'seq_version' => [ 1, 1 ],
365 'feats' => [{ 'Region' => { 'start' => [11,11],
368 'region_name' => [qw( Pribosyltran Pribosyltran )]
375 'coded_by' => [qw( BX842576.1:169611..170192
376 AAPA01000007.1:178491..179072)]
383 'title' => ['Deciphering the biology',
384 'Sequencing of the draft'],
385 'consortium' => [ undef, 'JGI-PGF' ],
386 'pubmed' => [9634230, undef]
390 'genus' => [qw( Mycobacterium Mycobacterium )],
391 'binomial' => [qw( tuberculosis gilvum ) ]
396 for ( $i=0; my $seq = $seqio->next_seq; $i++ ) {
397 is( $seq->id, $testdata{id}->[$i], 'id' );
398 like $seq->seq, qr/${$testdata{seq}}[$i]/, 'seq';
399 is $seq->alphabet, $testdata{alphabet}->[$i], 'alphabet';
400 is $seq->molecule, $testdata{molecule}->[$i], 'molecule';
401 is $seq->version, 1, 'seq_version';
402 like $seq->species->genus, qr/${$testdata{species}}{genus}[$i]/, 'species/genus';
403 like $seq->species->binomial, qr/${$testdata{species}}{binomial}[$i]/,
405 my @feats = $seq->get_SeqFeatures;
406 foreach my $testf (@{$testdata{feats}}) {
407 foreach my $pt (keys %$testf) {
408 my ($feat) = grep { $_->primary_tag eq $pt } @feats;
409 is $feat->start, $testf->{$pt}{'start'}[$i], "$pt/start";
410 is $feat->end, $testf->{$pt}{'end'}[$i], "$pt/end";
411 foreach my $tag (keys %{$testf->{$pt}{tags}}) {
412 my $tdata = $testf->{$pt}{tags}{$tag}[$i];
413 is (($feat->get_tag_values($tag))[0], $tdata, "$pt/$tag");
418 foreach my $testa (@{$testdata{annotation}}) {
419 foreach (keys %$testa) {
420 my ($ann) = $seq->annotation->get_Annotations($_);
421 foreach my $key (keys %{$testa->{$_}}) {
422 my $tdata = $testa->{$_}{$key}[$i];
423 if (!defined $tdata && !defined $ann->$key) {
427 like $ann->$key, qr/$tdata/, "$_/$key";
433 is ($i, 2, "got all seqs");
437 #sub test_input_file { "data/".shift };