[MOBY-guts] biomoby commit

Eddie Kawas kawas at dev.open-bio.org
Thu Feb 12 19:29:47 UTC 2009


kawas
Thu Feb 12 14:29:47 EST 2009
Update of /home/repository/moby/moby-live/Perl/MOBY-Server/share/cgi
In directory dev.open-bio.org:/tmp/cvs-serv25605/Perl/MOBY-Server/share/cgi

Modified Files:
	service_unit_tester.pl 
Log Message:
updated the service unit tester to test moby, moby-async and cgi services.
fixed actual testing aspect to reflect that there can be 0<= x <= infinity unit tests per service.
moby-live/Perl/MOBY-Server/share/cgi service_unit_tester.pl,1.1,1.2
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY-Server/share/cgi/service_unit_tester.pl,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- /home/repository/moby/moby-live/Perl/MOBY-Server/share/cgi/service_unit_tester.pl	2008/11/25 19:39:36	1.1
+++ /home/repository/moby/moby-live/Perl/MOBY-Server/share/cgi/service_unit_tester.pl	2009/02/12 19:29:47	1.2
@@ -9,7 +9,7 @@
 # BETA
 #
 # This script goes ahead an asks a registry what services exist
-# and then goes ahead and extracts their signature urls. 
+# and then goes ahead and extracts their signature urls.
 #
 # The signature urls are then parsed into services and any service
 # with a valid unit test is tested and the data stored in an XML file.
@@ -22,10 +22,11 @@
 #   DIRECTORY		- the place to store details between jobs <optional>
 #
 # IMPORTANT NOTES:
-#    None.
+#    This script doesn't fork yet, so as more and more services provide
+#    unit tests, this script will take longer and longer to complete.
 #
 # This script works on windows/unix/linux. Other machines have not been
-# tested, but they may well work just fine since we don't do any black 
+# tested, but they may well work just fine since we don't do any black
 # magic.
 #-----------------------------------------------------------------
 
@@ -39,6 +40,7 @@
 use XML::LibXML;
 use HTTP::Request::Common qw(POST);
 use LWP::UserAgent;
+use MOBY::Async::Service;
 
 use Data::Dumper;
 
@@ -47,7 +49,7 @@
 my $TIMEOUT = 20;
 
 # the categories of services to unit test
-my @CATEGORIES = qw / moby /;
+my @CATEGORIES = qw / moby cgi moby-async /;
 
 ######-------------------------------------------######
 
@@ -141,86 +143,107 @@
 
 	# get the services from the URL
 	my $service_arrayref = $parser->getServices($sigurl);
-
 	# call their unit tests
 	foreach my $serv ( @{$service_arrayref} ) {
-		my $test = $serv->unitTest;
-		next unless $test;
-
-		if ( $test->xpath or $test->regex or $test->example_input ) {
-			my $name  = $serv->name;
-			my $auth  = $serv->authority;
-			my $url   = $serv->URL;
-			my $cat   = $serv->category;
-			my $out   = undef;
-			my $input = $test->example_input || _empty_input();
-			# add the authority if not yet in the hash
-			$RESULTS{$auth} = ()
-			  if not exists $RESULTS{$auth};
-			do {
-				my $soap =
-				  SOAP::Lite->uri("http://biomoby.org/")
-				  ->proxy( $url, timeout => $TIMEOUT )->on_fault(
-					sub {
-						my $soap = shift;
-						my $res  = shift;
-
+		my $tests = $serv->unitTests;
+		next unless $tests;
+		foreach my $test (@$tests) {
+			if ( $test->xpath or $test->regex or $test->example_input ) {
+				my $name  = $serv->name;
+				my $auth  = $serv->authority;
+				my $url   = $serv->URL;
+				my $cat   = $serv->category;
+				my $out   = undef;
+				my $input = $test->example_input || _empty_input();
+				print "\tTesting the service $name from $auth ($cat)...\n";
+
+				# add the authority if not yet in the hash
+				$RESULTS{$auth} = ()
+				  if not exists $RESULTS{$auth};
+				do {
+					my $soap =
+					  SOAP::Lite->uri("http://biomoby.org/")
+					  ->proxy( $url, timeout => $TIMEOUT )->on_fault(
+						sub {
+							my $soap = shift;
+							my $res  = shift;
+	
+							# record that the service failed the test ...
+							push @{ $RESULTS{$auth}{$name} },
+							  {
+								name   => $name,
+								xpath  => 'false',
+								regex  => 'false',
+								output => 'false'
+							  };
+							exit(0);
+						}
+					  );
+	
+					$out =
+					  $soap->$name( SOAP::Data->type( 'string' => "$input" ) )
+					  ->result;
+				} if $cat eq 'moby';
+	
+				# test cgi services
+				do {
+					my $ua = LWP::UserAgent->new;
+					$ua->timeout($TIMEOUT);
+					my $req = POST $url, [ data => $input ];
+					$req = $ua->request($req);
+					$out = $req->content if $req->is_success;
+					do {
+	
 						# record that the service failed the test ...
-						push @{ $RESULTS{$auth} },
+						push @{ $RESULTS{$auth}{$name} },
 						  {
 							name   => $name,
 							xpath  => 'false',
 							regex  => 'false',
 							output => 'false'
 						  };
-						exit(0);
-					}
-				  );
-
-				$out =
-				  $soap->$name( SOAP::Data->type( 'string' => "$input" ) )
-				  ->result;
-			} unless $cat eq 'cgi';
-
-			# test cgi services
-			do {
-				my $ua = LWP::UserAgent->new;
-				$ua->timeout($TIMEOUT);
-				my $req = POST $url, [ data => $input ];
-				$req = $ua->request($req);
-				$out = $req->content if $req->is_success;
+					} unless $req->is_success;
+				} if $cat eq 'cgi';
+	
+				# test async services
 				do {
-
-					# record that the service failed the test ...
-					push @{ $RESULTS{$auth} },
-					  {
-						name   => $name,
-						xpath  => 'false',
-						regex  => 'false',
-						output => 'false'
-					  };
-				} unless $req->is_success;
-			} if $cat eq 'cgi';
-
-			# nothing to test unless we have some output
-			next unless $out;
-
-			# perform the unit tests
-			my %unit;
-			$unit{name} = $name;
-			# test regex
-			if ($test->regex) {
-				$unit{regex} = $test->test_regex($out) ? 'true' : 'false'; 
-			}
-			# test xpath
-			if ($test->xpath) {
-				$unit{xpath} = $test->test_xpath($out) ? 'true' : 'false'; 
-			}
-			# semantically compare XML
-			if ($test->expected_output) {
-				$unit{output} = $test->test_output_xml($out) ? 'true' : 'false'; 
+					
+					my $WSDL = $central->retrieveService($serv);
+					my $async = MOBY::Async::Service->new(service => $WSDL);
+					eval {$out = $async->raw_execute($input);};
+					# record that we have an error if we failed the test
+					push @{ $RESULTS{$auth}{$name} },
+						  {
+							name   => $name,
+							xpath  => 'false',
+							regex  => 'false',
+							output => 'false'
+						  } if $@;
+				} if $cat eq 'moby-async';
+	
+				# nothing to test unless we have some output
+				next unless $out;
+	
+				# perform the unit tests
+				my %unit;
+				$unit{name} = $name;
+	
+				# test regex
+				if ( $test->regex ) {
+					$unit{regex} = $test->test_regex($out) ? 'true' : 'false';
+				}
+	
+				# test xpath
+				if ( $test->xpath ) {
+					$unit{xpath} = $test->test_xpath($out) ? 'true' : 'false';
+				}
+	
+				# semantically compare XML
+				if ( $test->expected_output ) {
+					$unit{output} = $test->test_output_xml($out) ? 'true' : 'false';
+				}
+				push @{ $RESULTS{$auth}{$name} }, \%unit;
 			}
-			push @{ $RESULTS{$auth} }, \%unit;
 		}
 	}
 }
@@ -230,26 +253,38 @@
 my $root = $doc->createElement('Services');
 $doc->setDocumentElement($root);
 
+# authorities
 for my $auth ( sort keys %RESULTS ) {
 	my $element = $doc->createElement('authority');
 	$element->setAttribute( 'id', $auth );
-	my @services = @{ $RESULTS{$auth} };
-	next unless @services;
-	foreach my $s (@services) {
-		next unless $s;
+	my %services = %{ $RESULTS{$auth} };
+	next unless %services;
+	# service names
+	foreach my $service (sort keys %services) {
+		my @tests = @{ $services{$service} };
+		next unless @tests;
 		my $child = $doc->createElement('service');
-		$child->setAttribute( 'id', $auth . ',' . $s->{name} );
-
-		# sets values to true/false
-		$child->setAttribute( 'xpath',  $s->{xpath} )  if $s->{xpath};
-		$child->setAttribute( 'regex',  $s->{regex} )  if $s->{regex};
-		$child->setAttribute( 'output', $s->{output} ) if $s->{output};
-
+		$child->setAttribute( 'id', $service );
+		my $unitTests = $doc->createElement('UnitTests');
+		#array of unit tests
+		foreach my $s (@tests) {
+			next unless $s;
+			my $test =  $doc->createElement('unitTest');
+			# sets values to true/false
+			$test->setAttribute( 'xpath',  $s->{xpath} )  if $s->{xpath};
+			$test->setAttribute( 'regex',  $s->{regex} )  if $s->{regex};
+			$test->setAttribute( 'output', $s->{output} ) if $s->{output};
+			# add the test to unittests
+			$unitTests->appendChild($test);
+		}
+		# add the unittests to $child
+		$child->appendChild($unitTests);
 		# append this child
 		$element->appendChild($child);
 	}
 	$root->appendChild($element);
 }
+
 # save our XML file
 open( OUT, ">$DIRECTORY/$FILENAME" )
   || die("Cannot Open File $DIRECTORY/$FILENAME $!");
@@ -267,3 +302,4 @@
 </moby:MOBY>
 END_OF_XML
 }
+




More information about the MOBY-guts mailing list