[MOBY-guts] biomoby commit
Mark Wilkinson
mwilkinson at dev.open-bio.org
Fri Feb 9 00:19:01 UTC 2007
mwilkinson
Thu Feb 8 19:19:01 EST 2007
Update of /home/repository/moby/moby-live/Perl/t
In directory dev.open-bio.org:/tmp/cvs-serv31832/t
Modified Files:
CommonSubs.t
Log Message:
revamping test suite for CommonSubs to use only the new methods. Please God let the deprecated methods die a horrible death. There's a lot more cleaning-up that could be done in CommonSubs with respect to using 'Local' tags rather than testing whether or not the moby: namespace is there each time, but that can come later.
moby-live/Perl/t CommonSubs.t,1.6,1.7
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/t/CommonSubs.t,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- /home/repository/moby/moby-live/Perl/t/CommonSubs.t 2006/06/07 20:39:27 1.6
+++ /home/repository/moby/moby-live/Perl/t/CommonSubs.t 2007/02/09 00:19:01 1.7
@@ -54,30 +54,20 @@
my @must_implement = qw/
+ serviceInputParser
+ serviceResponseParser
+ simpleResponse
collectionResponse
complexResponse
- complexServiceInputParser
+ isCollectionArticle
+ isSecondaryArticle
+ isSimpleArticle
extractRawContent
- extractResponseArticles
- genericServiceInputParser
- genericServiceInputParserAsObject
- getArticles
- getCollectedSimples
getCrossReferences
- getInputArticles
- getInputID
- getInputs
getNodeContentWithArticle
- getResponseArticles
getServiceNotes
- getSimpleArticleIDs
- getSimpleArticleNamespaceURI
- isCollectionArticle
- isSecondaryArticle
- isSimpleArticle
responseFooter
responseHeader
- simpleResponse
validateNamespaces
validateThisNamespace
whichDeepestParentObject
@@ -86,34 +76,33 @@
can_ok('MOBY::CommonSubs', @must_implement)
or diag("CommonSubs doesn't implement all the methods that it should");
-# Test each function individually
-
-######## PARSE INPUTS #########
-# genericServiceInputParser
-# genericServiceInputParserAsObject
-# complexServiceInputParser
######## EXTRACT CONTENTS #########
-my @query_ids = (1, 'a', 23, 24);
-my $msg = <<EOF; # All possible types of input block: (moby:|)(queryInput|mobyData)
-<queryInput queryID='$query_ids[0]'></queryInput>
-<moby:queryInput queryID='$query_ids[1]'></moby:queryInput>
-<mobyData queryID='$query_ids[2]'/>
-<moby:mobyData queryID='$query_ids[3]'>foo</moby:mobyData>
-EOF
-
-my @inputs = getInputs(responseHeader() . $msg . responseFooter());
-is(scalar @inputs, scalar @query_ids)
- or diag("Wrong number of inputs returned from getInputs");
-for (my $i = 0; $i < @query_ids; $i++) {
- is(getInputID($inputs[$i]), $query_ids[$i])
- or diag("Wrong input ID returned for queryID $i: $inputs[$i]");
-}
+#my @query_ids = (1, 'a', 23, 24);
+#my $msg = <<EOF; # All possible types of input block: (moby:|)(queryInput|mobyData)
+#<mobyData queryID='$query_ids[2]'/>
+#<moby:mobyData queryID='$query_ids[3]'>foo</moby:mobyData>
+#EOF
+#
+#my @inputs = getInputs(responseHeader() . $msg . responseFooter());
+#is(scalar @inputs, scalar @query_ids)
+# or diag("Wrong number of inputs returned from getInputs");
+#for (my $i = 0; $i < @query_ids; $i++) {
+# is(getInputID($inputs[$i]), $query_ids[$i])
+# or diag("Wrong input ID returned for queryID $i: $inputs[$i]");
+#}
# This message contains two articles: Collection, and Parameter
# The Collection, of course, contains some Simple Articles, but they are not top-level articles.
-my $article_msg = <<ARTICLES;
-<mobyData>
- <Collection articleName='name1'>
+
+
+
+my $moby_msg = <<ARTICLES;
+<MOBY><mobyContent>
+<mobyData queryID="query1">
+ <Simple articleName='simple1'>
+ <String namespace='firstnamespace' id='mystring'>CONTENT</String>
+ </Simple>
+ <Collection articleName='collection1'>
<Simple>
<Object namespace="blah" id="blah"/>
</Simple>
@@ -124,98 +113,54 @@
<Parameter articleName='e value cutoff'>
<default>10</default>
</Parameter>
-</mobyData>
+</mobyData></mobyContent></MOBY>
ARTICLES
-my @articles = getArticles($article_msg);
-is(scalar @articles, 2) or diag("Wrong number of articles returned");
-my ($collection, $parameter) = @articles;
-# Check that first one is a Collection...
-is(isCollectionArticle($collection->[1]), 1) or diag("Expected Collection");
-# ...then pull out the Simples contained in it.
-is(scalar getCollectedSimples($collection->[1]), 2)
- or diag("Expected 2 Simples, didn't find them.");
-is(isSecondaryArticle($parameter->[1]), 1)
- or diag("Expected Secondary/Parameter");
-
-TODO: {
-local $TODO = "Need test for extractRawContent";
-#ok(extractRawContent($collection->[1])
-# =~ "<Simple>.*<\/Simple><Simple>.*<\/Simple>")
-# or diag("Couldn't extract raw content.");
-}
+my $responses = serviceResponseParser($moby_msg); # returns MOBY objects
+isa_ok ($responses, "HASH", "response parser returned a HASH" ) or die "serviceResponseParser didn't return a hashref\n";
+my @ids = keys %{$responses};
+ok (scalar(@ids) == 1) or die "serviceResponseParser didn't find right number of invocation messages\n";
+ok ($ids[0] eq "query1") or die "service4ResponseParser didn't find the query1 query id\n";
+
+my $this_invocation = $responses->{$ids[0]};
+ok ($this_invocation->{'simple1'}) or die "parser didn't find simple article in message\n";
+ok ($this_invocation->{'collection1'}) or die "parser didn't find collection article in message\n";
+ok ($this_invocation->{'e value cutoff'}) or die "parser didn't find secondary parameter article in message\n";
+
+my $simple = $this_invocation->{'simple1'};
+my $collection = $this_invocation->{'collection1'};
+my $secondary = $this_invocation->{'e value cutoff'};
+
+isa_ok($simple, "MOBY::Client::SimpleArticle") or die "retrieved Simple isn't a MOBY::Client::SimpleArticle object\n";
+isa_ok($collection, "MOBY::Client::CollectionArticle") or die "retrieved Collection isn't a MOBY::Client::CollectionArticle Object\n";
+isa_ok($secondary, "MOBY::Client::SecondaryArticle") or die "retrieved Secondary isn't a MOBY::Client::SecondaryArticle object\n";
+# other tests of the MOBY::Client::*Article should be done in their own test suite
# Test getInputArticles with one, and with more than one mobyData block.
my $two_mobyDatas = <<INP_ART;
+<MOBY xmlns:moby="http://local/namespace">
<moby:mobyContent>
- <moby:mobyData>
+ <moby:mobyData queryID="first">
<Simple>
<Object namespace="blah" id="blah"/>
</Simple>
</moby:mobyData>
- <moby:mobyData>
+ <moby:mobyData queryID="second">
<Simple>
<Object namespace="blah" id="blah"/>
</Simple>
</moby:mobyData>
</moby:mobyContent>
+ </MOBY>
INP_ART
-is(scalar getInputArticles(responseHeader()
- . $article_msg
- . responseFooter()), 1)
- or diag("Couldn't find right number of input articles");
-
-is(scalar getInputArticles(responseHeader()
- . $two_mobyDatas
- . responseFooter()), 2)
- or diag("Couldn't find right number of input articles");
-
-# getSimpleArticleIDs can be called in a number of ways, and of course, we have to test them all.
-# 1. If just one argument, it's assumed to be listref of Simple DOMs, and all ID's should be returned,
-# regardless of namespace
-# 2. If two arguments, first is taken to be namespace. Only articlenames from that namespace will
-# be returned; other articlenames will generate a 'undef' response, so that the number of inputs
-# matches the number of outputs.
-
-my @NS = ("Rub1", "Rub2");
-my $articles = [ XML_maker("<Simple><Object namespace='$NS[0]' id='163483'/></Simple>"),
- XML_maker("<Simple><Object namespace='invalid_ns' id='163483'/></Simple>"),
- XML_maker("<Simple><Object namespace='$NS[1]' id='S0005111'/></Simple>")
- ];
-
-is(getSimpleArticleIDs($articles), 3)
- or diag("Wrong number of Simple Articles IDs returned (no namespace)");
-for my $ns (@NS) { # Should get three responses (one for each input), but two should be 'undef'
- my @responses = getSimpleArticleIDs($ns, $articles);
- is(scalar @responses, 3)
- or diag("Wrong number of Simple Articles IDs returned (with namespace)");
- my $count_undef = 0;
- for my $r (@responses) { $count_undef++ if (!defined ($r)) }
- is($count_undef, 2)
- or diag("Wrong number of 'undef's returned by getSimpleArticleIDs");
-}
-
-my @bogus;
-my $bogus_ns = "bogus NS";
-eval { @bogus = getSimpleArticleIDs($bogus_ns, $articles) };
-isnt($@, undef)
- or diag("Invalid namespace '$bogus_ns' should have 'die'd, but didn't");
-is(scalar @bogus , 0)
- or diag("Wrong number of Simple Articles IDs returned " .
- "(expected zero for bogus namespace)");
-
-is(scalar getSimpleArticleIDs('Rub1', $articles), scalar @{$articles})
- or diag("Wrong number of Simple Articles IDs returned " .
- "(expected zero for valid but unused namespace)");
-
-ok(getSimpleArticleNamespaceURI($articles->[0])
- =~ /^urn\:lsid\:biomoby\.org\:namespacetype\:/)
- or diag("Got bad LSID for valid namespace");
-
-is( getSimpleArticleNamespaceURI($articles->[1]), undef)
-# =~ /^urn\:lsid\:biomoby\.org\:namespacetype\:/ ) )
- or diag("Got valid LSID for invalid namespace");
+$responses = serviceResponseParser($two_mobyDatas); # returns MOBY objects
+isa_ok ($responses, "HASH", "response parser returned a HASH" ) or die "serviceResponseParser didn't return a hashref for multiple input test\n";
+ at ids = keys %{$responses};
+ok (scalar(@ids) == 2) or die "serviceResponseParser didn't find right number of invocation messages when two were passed\n";
+ok ($ids[0] eq "first") or die "serviceResponseParser didn't find the first query id\n";
+ok ($ids[1] eq "second") or die "serviceResponseParser didn't find the second query id\n";
+
my $sequence = "TAGCTGATCGAGCTGATGCTGA";
my $articlename = "SequenceString";
@@ -374,10 +319,10 @@
# and that bogus ones do NOT.
my @LSIDs = validateNamespaces('bogus-ns', @ns, 'other bogus-ns');
foreach ($LSIDs[0], $LSIDs[-1]) {
- is($_, undef) or diag("Bogus namespace ($LSIDs[0]) got an LSID");
+ is($_, undef,"validate namespace lsids") or diag("Bogus namespace ($LSIDs[0]) got an LSID");
}
foreach (@LSIDs[1..-2]) {
- isnt($_, undef) or diag("Bona fide namespace ($_) had no LSID");
+ isnt($_, undef, "validate namespace lsids2") or diag("Bona fide namespace ($_) had no LSID");
}
######## GENERATE RESPONSE #########
@@ -389,14 +334,13 @@
. responseFooter());
$sresp = $sresp->getElementsByTagName('moby:mobyData');
# || $sresp->getElementsByTagName('mobyData');
-is($sresp->size(), 1)
+is($sresp->size(), 1,"response size OK")
or diag("SimpleResponse should contain only a single mobyData element.");
my $mobyData = $sresp->get_node(1);
is($mobyData->getAttribute('moby:queryID') || $mobyData->getAttribute('queryID'),
$qID)
or diag("SimpleResponse didn't contain right queryID");
-my $simple;
my $count_elements = 0;
foreach ($mobyData->childNodes->get_nodelist) {
if ($_->nodeType == ELEMENT_NODE) { $count_elements++ }
@@ -440,15 +384,15 @@
or diag("collectionResponse should have mobyData as outermost tag: got '$coll_resp'");
# Now parse the XML, and make sure it checks out according to DOM
my $coll_resp_dom = XML_maker(responseHeader() . $coll_resp . responseFooter());
- my $mData = $coll_resp_dom->getElementsByTagName('moby:mobyData');
- is($mData->size(), 1)
+ my $mData = $coll_resp_dom->getElementsByLocalName('mobyData');
+ is($mData->size(), 1,"collection response size is correct")
or diag("CollectionResponse should contain only a single mobyData element.");
$mData = $mData->get_node(1);
is($mData->getAttribute('moby:queryID') || $mData->getAttribute('queryID'),
$qID)
or diag("CollectionResponse's mobyData element didn't contain correct queryID");
- my $colls = $mData->getElementsByTagName("moby:Collection");
- is ($colls->size(), 1)
+ my $colls = $mData->getElementsByLocalName("Collection");
+ is ($colls->size(), 1,"collection has wrong number of children")
or diag("CollectionResponse should have only a single child: Collection.");
my $Coll = $colls->get_node(1);
is($Coll->getAttribute('moby:articleName') || $Coll->getAttribute('articleName'),
@@ -460,19 +404,9 @@
or diag("CollectionResponse contains wrong number of Simples");
# # Finally, parse the sucker with the tools in CommonSubs: it should be able to understand its own creations!
- my @inputs = getInputs(responseHeader() . $coll_resp . responseFooter() );
- is(scalar @inputs, 1)
- or diag("CollectionResponse should contain only one mobyData block");
- is(getInputID($inputs[0]), $qID)
- or diag("CollectionResponse returned mobyData block with incorrect queryID attribute");
- my @articles = getArticles($inputs[0]);
- is(scalar @articles, 1)
- or diag("CollectionResponse should contain only one Collection");
- is($articles[0]->[0], $aname)
- or diag("CollectionResponse had incorrect articleName");
- my @collected_simples = getCollectedSimples($articles[0]->[1]);
- is(scalar @collected_simples , scalar @{$data})
- or diag("CollectionResponse contained incorrect number of Simples");
+ my $inputs = serviceInputParser(responseHeader() . $coll_resp . responseFooter() );
+
+ok (scalar(keys %{$inputs}) == 1) or diag("can't eat my own dogfood!");
# Test response when one or more simples are empty/undef.
# They should result in empty Simple tags, but the total response should NOT be empty.
More information about the MOBY-guts
mailing list