Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

still cleaning tests

  • Loading branch information...
commit 72af7431e5ffb60420d39710f8a792c381e9800f 1 parent b634fe7
@mokko authored
View
55 lib/HTTP/OAI/DataProvider/Test.pm
@@ -26,7 +26,8 @@ use vars '@EXPORT';
isLMFprefix
isOAIerror
- okIfBadArgument
+
+ failOnRequestError
loadWorkingTestConfig
xpathTester
@@ -107,7 +108,7 @@ sub okListSets {
sub _okType {
my $response = shift or die "Need xml as string!";
my $type = shift or die "Need type!";
- my $msg=shift || "response validates and is of type $type\n";
+ my $msg = shift || "response validates and is of type $type\n";
isScalar($response);
if (
$type !~ /^Identify$|
@@ -122,14 +123,14 @@ sub _okType {
}
my $xpath = "/oai:OAI-PMH/oai:$type";
- my $lax = ( $type =~ /^ListRecords$|^GetRecord$/) ? 'lax' : '';
+ my $lax = ( $type =~ /^ListRecords$|^GetRecord$/ ) ? 'lax' : '';
- #print "LAX:$lax|type:$type\n";
+ print "LAX:$lax|type:$type\n";
if ( !_validateOAIresponse( $response, $lax ) ) {
fail '$type response does not validate $lax';
}
- _failIfOAIerror (_response2dom($response));
+ _failIfOAIerror( _response2dom($response) );
my $xt = xpathTester($response);
@@ -177,19 +178,24 @@ sub isOAIerror {
my $code = shift or die "Need error type to look for!";
isScalar($response);
isScalar($code);
+ if ($code !~ /badArgument|cannotDisseminate|noRecordMatches|idDoesNotExist/) {
+ print "Unrecognized OAI error code\n";
+ }
my $dom = _response2dom($response);
-
_failValidationError($dom);
my $oaiError = _failNoOAIerror($dom);
ok( defined $oaiError->{$code}, "expect OAIerror of type '$code'" );
-
}
=func okIfBadArgument ($response);
-passes if response is OAI error badArgument
+passes if response is OAI error badArgument.
+
+DEPRECATED!
+Instead use:
+ C<isOAIerror ($response, 'badArgument');>
=cut
@@ -269,6 +275,22 @@ sub oaiError {
return;
}
+=func failOnRequestError(%params);
+
+Expects the parameters you are about to hand over to data provider as a hash.
+Fails with meaninggful error message and exists if the parameters are not
+valid. (Wrapper around HTTP::OAI::Repository::validate_request.)
+
+=cut
+
+sub failOnRequestError {
+ if ( my @e = HTTP::OAI::Repository::validate_request(@_) ) {
+ fail "Query error: " . grep ($_->code, @e) . "\n";
+ exit 1;
+ }
+}
+
+
=func my $xt=xpathTester($response);
returns an Test::XPath object, so you can do things like:
@@ -311,7 +333,7 @@ sub _failIfOAIerror {
my $oaiError = oaiError($dom);
if ($oaiError) {
- my @e=keys %{$oaiError};
+ my @e = keys %{$oaiError};
fail "Error:Unexpected OAI error (@e)!";
exit 1;
}
@@ -388,9 +410,11 @@ sub okIfXpathExists {
oks if response has at least one
/oai:OAI-PMH/oai:ListIdentifiers/oai:header[1]/oai:identifier
+DEPRECATED
+
=cut
-sub okIfIdentifierExists {
+sub _okIfIdentifierExists {
my $doc = shift or die "Error: Need doc!";
okIfXpathExists(
$doc,
@@ -425,7 +449,7 @@ sub isMetadataFormat {
=func isSetSpec ($response, $setSpec, $msg);
-TODO DOESNT WORK YET
+UNTESTED
=cut
@@ -435,9 +459,7 @@ sub isSetSpec {
isScalar($response);
isScalar($setSpec);
my $msg = "setSpec '$setSpec' exists";
- my $xpath = '/oai:OAI-PMH/oai:ListSets/oai:set/oai:setSpec[1]';
-
- # . "[. = $setSpec]";
+ my $xpath = "/oai:OAI-PMH/oai:ListSets/oai:set[oai:setSpec = $setSpec]";
my $xt = xpathTester($response);
$xt->is( $xpath, $setSpec, $msg );
@@ -448,9 +470,11 @@ sub isSetSpec {
Currently it works only for a GetRecord/record/metadata. Should it also work
for ListRecords/record/metadata?
+DEPRECATED
+
=cut
-sub okIfMetadataExists {
+sub _okIfMetadataExists {
my $doc = shift or die "Error: Need doc!";
okIfXpathExists(
$doc,
@@ -544,7 +568,6 @@ sub _validateOAIresponse {
=head1 DEPRECATED UTILITY FUNCTIONS
-
=func my $xc=registerOAI($dom);
Register the uri 'http://www.openarchives.org/OAI/2.0/' as the prefix 'oai' and
View
0  t/02-Common/01-load.pl → t/000-common-load.t
File renamed without changes
View
0  t/02-Common/10-common.t → t/001-common.t
File renamed without changes
View
0  t/03-Test/01-load.pl → t/010-test-load.t
File renamed without changes
View
19 t/010-test.t
@@ -0,0 +1,19 @@
+#!perl
+
+use strict; #test the test (this is so meta...)
+use warnings;
+use Test::More tests => 1;
+use HTTP::OAI::DataProvider::Test;
+use HTTP::OAI;
+
+#use Data::Dumper qw(Dumper); #only for debugging tests
+
+my $id=new HTTP::OAI::Identify(
+ adminEmail => 'billg@microsoft.com',
+ baseURL => 'http://www.myarchives.org/oai',
+ repositoryName => 'www.myarchives.org'
+);
+
+my $response=$id->toDOM->toString;
+print "$response\n";
+okIdentify($response);
View
0  t/04-valid/00-load.t → t/020-valid-load.t
File renamed without changes
View
0  t/04-valid/10-valid.t → t/020-valid.t
File renamed without changes
View
10 t/03-Test/01-test.t
@@ -1,10 +0,0 @@
-#test the test (this is so meta...)
-use strict;
-use warnings;
-use HTTP::OAI::DataProvider::Test plan=>1;
-use Test::More;
-
-#use Data::Dumper qw(Dumper); #only for debugging tests
-
-
-ok(1,'todo');
View
0  t/05_chunkCache/00-load.t → t/050-chunkCache-load.t
File renamed without changes
View
0  t/05_chunkCache/01-test.t → t/051-chunkCache.t
File renamed without changes
View
6 t/10-identify.t
@@ -4,7 +4,7 @@ use strict;
use warnings;
use Test::More tests => 10;
use HTTP::OAI::DataProvider;
-use HTTP::OAI::DataProvider::Test qw(xpathTester okIdentify okIfBadArgument);
+use HTTP::OAI::DataProvider::Test;
use XML::LibXML;
use Test::Xpath;
@@ -69,12 +69,12 @@ foreach my $key ( keys %{$expected} ) {
{
my $response = $provider->Identify( bla => 'meschugge', 1 );
- okIfBadArgument($response);
+ isOAIerror($response, 'badArgument');
}
{
my $response = $provider->Identify( 1, identifier => 'meschugge' );
- okIfBadArgument($response);
+ isOAIerror($response, 'badArgument');
}
View
11 t/20-listMetadataFormats.t
@@ -3,7 +3,7 @@ use warnings;
use Test::More;
use HTTP::OAI::DataProvider;
use HTTP::OAI::DataProvider::Test
- qw/isLMFprefix okIfBadArgument okListMetadataFormats xpathTester isOAIerror/;
+ qw/isLMFprefix okListMetadataFormats xpathTester isOAIerror/;
use Test::Xpath;
use XML::LibXML;
@@ -42,14 +42,12 @@ my $baseURL = 'http://localhost:3000/oai';
}
{
-
#testing badArgument
- #diag "ListMetadataFormats with badArgument";
my $response =
$provider->ListMetadataFormats( $baseURL, iddentifiier => 'wrong' );
- okIfBadArgument($response);
+ isOAIerror($response, 'badArgument');
$response = $provider->Identify( 1, identifier => 'meschugge' );
- okIfBadArgument($response);
+ isOAIerror($response, 'badArgument');
}
{
@@ -58,4 +56,5 @@ my $baseURL = 'http://localhost:3000/oai';
isOAIerror( $response, 'idDoesNotExist' );
}
-#DataProvider with globalFormats cant really respond with noMetadataFormats.
+#DataProvider with globalFormats cant really respond with noMetadataFormats
+#(There are no metadata formats available for the specified item.).
View
7 t/30-listIdentifiers.t
@@ -141,8 +141,7 @@ my $baseURL = 'http://localhost:3000/oai';
isOAIerror( $response, 'noRecordsMatch' );
}
-#TODO:
-#noSetHierarchy
+#TODO: noSetHierarchy
#
#
@@ -155,7 +154,11 @@ here? I need to know that an error is not caused by the params.
Using fail is probably bad style, because it changes the number of tests, but
it gives me an error message in the right color.
+Could also be called
+ failOnRequestError (%params);
+and be placed in DP::Test
=cut
+
sub validateRequest {
if ( my @e = HTTP::OAI::Repository::validate_request(@_) ) {
fail "Query error: " . $e[0]->code . "\n";
View
12 t/40-GetRecord.t
@@ -19,7 +19,7 @@ my $baseURL = 'http://localhost:3000/oai';
#
# the actual tests
-#
+# 1-see if it works
{
my %params = (
metadataPrefix => 'mpx',
@@ -29,16 +29,20 @@ my $baseURL = 'http://localhost:3000/oai';
okGetRecord($response);
}
+#
+# 2-OAI errors
+#
+
{
my %params = ( identifier => 'spk-berlin.de:EM-objId-40008', );
my $response = $provider->GetRecord( $baseURL, %params );
- okIfBadArgument($response);
+ isOAIerror($response, 'badArgument');
}
{
my %params = ( metadataPrefix => 'mpx', );
my $response = $provider->GetRecord( $baseURL, %params );
- okIfBadArgument($response);
+ isOAIerror($response, 'badArgument');
}
{
@@ -48,7 +52,7 @@ my $baseURL = 'http://localhost:3000/oai';
meschugge => 'schixe',
);
my $response = $provider->GetRecord( $baseURL, %params );
- okIfBadArgument($response);
+ isOAIerror($response, 'badArgument');
}
{
View
10 t/50-ListRecords.t
@@ -3,7 +3,7 @@
use Test::More tests => 1;
use HTTP::OAI::DataProvider;
use HTTP::OAI::Repository qw(validate_request);
-use HTTP::OAI::DataProvider::Test qw(okListRecords);
+use HTTP::OAI::DataProvider::Test qw(okListRecords failOnRequestError);
my $config = HTTP::OAI::DataProvider::Test::loadWorkingTestConfig();
my $provider = new HTTP::OAI::DataProvider($config);
@@ -13,14 +13,8 @@ my %params = (
metadataPrefix => 'mpx',
);
-my $error = HTTP::OAI::Repository::validate_request(%params);
+failOnRequestError (%params); #I do want to make sure that params are correct
-#this test is not about query testing, just make sure it works
-if ($error) {
- die "Query error: $error";
-}
-
-#execute verb
my $response =
$provider->ListRecords( $baseURL, %params ); #response should be a xml string
Please sign in to comment.
Something went wrong with that request. Please try again.