[MOBY-guts] biomoby commit

Frank Gibbons fgibbons at pub.open-bio.org
Fri Sep 2 14:32:15 UTC 2005


fgibbons
Fri Sep  2 10:32:15 EDT 2005
Update of /home/repository/moby/moby-live/Perl/t
In directory pub.open-bio.org:/tmp/cvs-serv10603/t

Modified Files:
	Client-SimpleArticle.t 
Log Message:
 - Check API for SimpleArticle. Looks like calls to ->XML() don't do what you'd expect: parse the XML, and modify the object.

moby-live/Perl/t Client-SimpleArticle.t,1.1,1.2
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/t/Client-SimpleArticle.t,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- /home/repository/moby/moby-live/Perl/t/Client-SimpleArticle.t	2005/08/31 14:17:11	1.1
+++ /home/repository/moby/moby-live/Perl/t/Client-SimpleArticle.t	2005/09/02 14:32:15	1.2
@@ -31,7 +31,7 @@
 
 my @autoload = qw/articleName objectType objectLSID namespaces id
   XML XML_DOM isSimple isCollection isSecondary/;
-my @API = (@autoload, qw/new createFromXML createFromDOM/);
+my @API = (@autoload, qw/new addNamespace value /); # createFrom[XML|DOM] are not meant to be public
 
 my $smpl = MOBY::Client::SimpleArticle->new();
 foreach (@autoload) {eval{$smpl->$_};} # Call all AUTOLOAD methods, to create them.
@@ -43,3 +43,105 @@
 is($smpl->isSecondary, 0)  or diag("SimpleArticle cannot be Secondary");
 is($smpl->isCollection, 0) or diag("SimpleArticle cannot be Collection");
 
+my $aName = 'my Article';
+is($smpl->articleName($aName), $aName) or diag("Couldn't set articleName");
+is($smpl->articleName(), $aName) or diag("Couldn't get articleName");
+
+my $obj_type = 'String';
+is($smpl->objectType($obj_type), $obj_type) or diag("Couldn't set objectType");
+is($smpl->objectType(), $obj_type) or diag("Couldn't get objectType");
+
+my $obj_lsid = 'String';
+is($smpl->objectLSID($obj_lsid), $obj_lsid) or diag("Couldn't set objectLSID");
+is($smpl->objectLSID(), $obj_lsid) or diag("Couldn't get objectLSID");
+
+my @ns = qw/SGD FB GO/;
+eq_array($smpl->namespaces(\@ns), \@ns) or diag("Couldn't set namespaces");
+eq_array($smpl->namespaces(), \@ns) or diag("Couldn't get namespaces");
+
+my $new_ns = 'NCBI_gi';
+# Order is critical in this test: FIRST get existing namespaces, THEN add one, and CHECK
+eq_array( [@{$smpl->namespaces()}, $new_ns ], $smpl->addNamespace($new_ns))
+  or diag("Couldn't add new namespace ('$new_ns')");
+
+# 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 Article', 'SGD', 'S0005111', 'Object', 'urn:foo:bar:my_lsid');
+my $xml_smpl = <<XML;
+<Simple lsid='$lsid' articleName='$artName'>
+<Object namespace='$ns' id='$id'/>
+</Simple>
+XML
+
+$smpl = MOBY::Client::SimpleArticle->new( XML => $xml_smpl);
+
+is($smpl->objectLSID(), $lsid)
+  or diag("SimpleArticle not correctly built from XML (LSID wrong)");
+
+is($smpl->articleName(), $artName)
+  or diag("SimpleArticle not correctly built from XML (articleName wrong)");
+
+is($smpl->objectType(), $obj) 
+  or diag("SimpleArticle not correctly built from XML (objectType wrong)");
+
+eq_array($smpl->namespaces(), [$ns])
+  or diag("SimpleArticle not correctly built from XML (namespace wrong)");
+
+is($smpl->id(), $id) 
+  or diag("SimpleArticle not correctly built from XML (id wrong)");
+
+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();
+}
+
+
+$smpl = MOBY::Client::SimpleArticle->new( XML_DOM => XML_maker($xml_smpl));
+
+is($smpl->objectLSID(), $lsid)
+  or diag("SimpleArticle not correctly built from XML_DOM (LSID wrong)");
+
+is($smpl->articleName(), $artName)
+  or diag("SimpleArticle not correctly built from XML_DOM (articleName wrong)");
+
+is($smpl->objectType(), $obj) 
+  or diag("SimpleArticle not correctly built from XML_DOM (objectType wrong)");
+
+eq_array($smpl->namespaces(), [$ns])
+  or diag("SimpleArticle not correctly built from XML_DOM (namespace wrong)");
+
+is($smpl->id(), $id) 
+  or diag("SimpleArticle not correctly built from XML_DOM (id wrong)");
+
+
+TODO: {
+  local $TODO = <<TODO;
+When I call SimpleArticle->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
+
+  $smpl = MOBY::Client::SimpleArticle->new();
+  $smpl->XML($xml_smpl);
+  is($smpl->objectLSID(), $lsid)
+    or diag("Couldn't create SimpleArticle from autoloaded method XML(): LSID wrong");
+
+  is($smpl->articleName, $artName) 
+    or diag("Couldn't create SimpleArticle from autoloaded method XML(): articleName wrong");
+
+  is($smpl->objectType(), $obj) 
+    or diag("Couldn't create SimpleArticle from autoloaded method XML(): objectType wrong");
+
+  eq_array($smpl->namespaces(), [$ns])
+    or diag("Couldn't create SimpleArticle from autoloaded method XML(): namespaces wrong");
+
+  is($smpl->id(), $id) 
+    or diag("Couldn't create SimpleArticle from autoloaded method XML(): id wrong");
+}




More information about the MOBY-guts mailing list