[MOBY-guts] biomoby commit
Frank Gibbons
fgibbons at pub.open-bio.org
Tue Sep 6 20:31:06 UTC 2005
fgibbons
Tue Sep 6 16:31:06 EDT 2005
Update of /home/repository/moby/moby-live/Perl/t
In directory pub.open-bio.org:/tmp/cvs-serv4254/t
Modified Files:
Client-CollectionArticle.t
Log Message:
- More tests for CollectionArticle.
moby-live/Perl/t Client-CollectionArticle.t,1.1,1.2
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/t/Client-CollectionArticle.t,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- /home/repository/moby/moby-live/Perl/t/Client-CollectionArticle.t 2005/08/31 14:17:11 1.1
+++ /home/repository/moby/moby-live/Perl/t/Client-CollectionArticle.t 2005/09/06 20:31:06 1.2
@@ -25,12 +25,7 @@
};
-TODO: {
- local $TODO = "Everything.";
-}
-
-my @autoload = qw/articleName Simples isSimple isCollection isSecondary
-XML XML_DOM/;
+my @autoload = qw/articleName Simples isSimple isCollection isSecondary XML XML_DOM/;
my @API = (@autoload, qw/new createFromXML createFromDOM addSimple/);
my $coll = MOBY::Client::CollectionArticle->new();
@@ -42,3 +37,64 @@
is($coll->isSecondary, 0) or diag("CollectionArticle cannot be Secondary");
is($coll->isCollection, 1) or diag("CollectionArticle must return isCollection=1");
+my $aName = 'my Article';
+# Check XML-generation code.
+# In reality, (XML, createFromXML) and (XML_DOM, createFromDOM) should behave the same.
+# Let's not assume that though.
+
+my ($artName, $ns, $id, $obj, $lsid)
+ = ('my Simple Article', 'SGD', 'S0005111', 'Object', 'urn:foo:bar:my_lsid');
+my ($collArtName) = "my Collection";
+my $xml_coll = <<XML;
+<Collection articleName='$collArtName'>
+<Simple lsid='$lsid' articleName='$artName'>
+<Object namespace='$ns' id='$id'/>
+</Simple>
+<Simple lsid='$lsid' articleName='$artName'>
+<Object namespace='$ns' id='$id'/>
+</Simple>
+</Collection>
+XML
+
+$coll = MOBY::Client::CollectionArticle->new( XML => $xml_coll);
+
+is($coll->articleName(), $collArtName)
+ or diag("CollectionArticle not correctly built from XML (articleName wrong)");
+
+is(scalar @{$coll->Simples()}, 2)
+ or diag("CollectionArticle didn't return correct number of Simples");
+
+TODO: {
+ local $TODO = "We should ideally check the contents of the Simples that are returned....";
+}
+
+sub XML_maker { # Turn XML text into DOM.
+ my $XML = shift;
+ my $parser = XML::LibXML->new();
+ my $doc;
+ eval { $doc = $parser->parse_string( $XML ); };
+ return '' if ( $EVAL_ERROR ); #("Couldn't parse '$XML' because:\n\t$EVAL_ERROR")
+ return $doc->getDocumentElement();
+}
+
+
+$coll = MOBY::Client::CollectionArticle->new( XML_DOM => XML_maker($xml_coll));
+
+is($coll->articleName(), $collArtName)
+ or diag("CollectionArticle not correctly built from XML_DOM (articleName wrong)");
+
+
+
+TODO: {
+ local $TODO = <<TODO;
+When I call CollectionArticle->new()->XML(\$xml),
+I expect that the XML will be *parsed*, to modify the object,
+not that the attribute 'XML' will be set, and the rest left unchanged."
+TODO
+
+ $coll = MOBY::Client::CollectionArticle->new();
+ $coll->XML($xml_coll);
+ is($coll->articleName, $collArtName)
+ or diag("Couldn't create CollectionArticle from autoloaded method XML(): articleName wrong");
+
+}
More information about the MOBY-guts
mailing list