Koha/t/db_dependent/lib/KohaTest/ImportBatch.pm
Srdjan 12ff7355bb bug_7613: OCLC Connexion gateway
svc/import_bib:
* takes POST request with parameters in url and MARC XML as DATA
* pushes MARC XML to an impoort bach queue of type 'webservice'
* returns status and imported record XML
* is a drop-in replacement for svc/new_bib

misc/cronjobs/import_webservice_batch.pl:
* a cron job for processing impoort bach queues of type 'webservice'
* batches can also be processed through the UI

misc/bin/connexion_import_daemon.pl:
* a daemon that listens for OCLC Connexion requests and is compliant
  with OCLC Gateway spec
* takes request with MARC XML
* takes import batch params from a config file and forwards the lot to
  svc/import_bib
* returns status

ImportBatches:
* Added new import batch type of 'webservice'
* Changed interface to AddImportBatch() - now it takes a hashref
* Replaced batch_type = 'batch' with
  batch_type IN ( 'batch', 'webservice' ) in some SELECTs

Signed-off-by: MJ Ray <mjr@phonecoop.coop>
2012-04-06 17:26:20 +02:00

126 lines
4.2 KiB
Perl

package KohaTest::ImportBatch;
use base qw(KohaTest);
use strict;
use warnings;
use Test::More;
use C4::ImportBatch;
use C4::Matcher;
sub testing_class { 'C4::ImportBatch' };
sub routines : Test( 1 ) {
my $self = shift;
my @routines = qw(
GetZ3950BatchId
GetImportRecordMarc
AddImportBatch
GetImportBatch
AddBiblioToBatch
ModBiblioInBatch
BatchStageMarcRecords
AddItemsToImportBiblio
BatchFindBibDuplicates
BatchCommitBibRecords
BatchCommitItems
BatchRevertBibRecords
BatchRevertItems
CleanBatch
GetAllImportBatches
GetImportBatchRangeDesc
GetItemNumbersFromImportBatch
GetNumberOfNonZ3950ImportBatches
GetImportBibliosRange
GetBestRecordMatch
GetImportBatchStatus
SetImportBatchStatus
GetImportBatchOverlayAction
SetImportBatchOverlayAction
GetImportBatchNoMatchAction
SetImportBatchNoMatchAction
GetImportBatchItemAction
SetImportBatchItemAction
GetImportBatchItemAction
SetImportBatchItemAction
GetImportBatchMatcher
SetImportBatchMatcher
GetImportRecordOverlayStatus
SetImportRecordOverlayStatus
GetImportRecordStatus
SetImportRecordStatus
GetImportRecordMatches
SetImportRecordMatches
_create_import_record
_update_import_record_marc
_add_biblio_fields
_update_biblio_fields
_parse_biblio_fields
_update_batch_record_counts
_get_commit_action
_get_revert_action
);
can_ok($self->testing_class, @routines);
}
sub startup_50_add_matcher : Test( startup => 1 ) {
my $self = shift;
# create test MARC21 ISBN matcher
my $matcher = C4::Matcher->new('biblio');
$matcher->threshold(1000);
$matcher->code('TESTISBN');
$matcher->description('test MARC21 ISBN matcher');
$matcher->add_simple_matchpoint('isbn', 1000, '020', 'a', -1, 0, '');
my $matcher_id = $matcher->store();
like($matcher_id, qr/^\d+$/, "store new matcher and get back ID");
$self->{'matcher_id'} = $matcher_id;
}
sub shutdown_50_remove_matcher : Test( shutdown => 6) {
my $self = shift;
my @matchers = C4::Matcher::GetMatcherList();
cmp_ok(scalar(@matchers), ">=", 1, "at least one matcher present");
my $matcher_id;
my $testisbn_count = 0;
# look for TESTISBN
foreach my $matcher (@matchers) {
if ($matcher->{'code'} eq 'TESTISBN') {
$testisbn_count++;
$matcher_id = $matcher->{'matcher_id'};
}
}
ok($testisbn_count == 1, "only one TESTISBN matcher");
like($matcher_id, qr/^\d+$/, "matcher ID is valid");
my $matcher = C4::Matcher->fetch($matcher_id);
ok(defined($matcher), "got back a matcher");
ok($matcher_id == $matcher->{'id'}, "got back the correct matcher");
C4::Matcher->delete($matcher_id);
my $matcher2 = C4::Matcher->fetch($matcher_id);
ok(not(defined($matcher2)), "matcher removed");
delete $self->{'matcher_id'};
}
=head2 UTILITY METHODS
=cut
sub add_import_batch {
my $self = shift;
my $test_batch = shift
|| {
overlay_action => 'create_new',
import_status => 'staging',
batch_type => 'batch',
file_name => 'foo',
comments => 'inserted during automated testing',
};
my $batch_id = AddImportBatch( $test_batch );
return $batch_id;
}
1;