Skip to content
Snippets Groups Projects
Commit 3e7bc652 authored by bolkun's avatar bolkun
Browse files

bagit full check tests completed for lix and win systems

parent 9ba9c305
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,7 @@ use strict;
use warnings;
use diagnostics;
use Test::More tests => 114;
use Test::More tests => 126;
use Test::Output;
use Test::Exception;
use Test::File;
......@@ -18,6 +18,81 @@ use File::Path qw(rmtree);
# Start scipt in the project directory to run all tests properly.
# Tested on Win10 and Debian 10
sub workaroundBagInfoTXT($$$){
my $file_path = $_[0];
my $key = $_[1];
my $value = $_[2];
my $file_name = SLUB::LZA::SIPBuilderBagIt::getFileName($file_path);
# read a data file into an array
open my $handle, '<', $file_path;
chomp(my @lines = <$handle>);
close $handle;
# grep and change certain array element
foreach my $zeile(@lines) {
my @keyvalue = split(/: /, $zeile, 2); # split on first :
if($keyvalue[0] eq $key){
$zeile = "$key: $value";
}
}
# save array back to file
open my $fh, '>', $file_path or die "Cannot open $file_path: $!";
foreach (@lines){
print $fh "$_\n"; # Print each entry in our array to the file
}
close $fh;
}
sub workaroundTagmanifestMD5($$$){
my $file_path = $_[0];
my $key = $_[1];
my $value = $_[2];
my $file_name = SLUB::LZA::SIPBuilderBagIt::getFileName($file_path);
# read a data file into an array
open my $handle, '<', $file_path;
chomp(my @lines = <$handle>);
close $handle;
# grep and change certain array element
foreach my $zeile(@lines) {
my @keyvalue = split(/ /, $zeile, 2); # split
if($keyvalue[1] eq $value){
$zeile = "$key $value";
}
}
# save array back to file
open my $fh, '>', $file_path or die "Cannot open $file_path: $!";
foreach (@lines){
print $fh "$_\n"; # Print each entry in our array to the file
}
close $fh;
}
sub workaroundTagmanifestSHA512($$$){
my $file_path = $_[0];
my $key = $_[1];
my $value = $_[2];
my $file_name = SLUB::LZA::SIPBuilderBagIt::getFileName($file_path);
# read a data file into an array
open my $handle, '<', $file_path;
chomp(my @lines = <$handle>);
close $handle;
# grep and change certain array element
foreach my $zeile(@lines) {
my @keyvalue = split(/ /, $zeile, 2); # split
if($keyvalue[1] eq $value){
$zeile = "$key $value";
}
}
# save array back to file
open my $fh, '>', $file_path or die "Cannot open $file_path: $!";
foreach (@lines){
print $fh "$_\n"; # Print each entry in our array to the file
}
close $fh;
}
sub equalFilesByIgnoringCRLF_LF($$){
my $file_path1 = $_[0];
my $file_path2 = $_[1];
......@@ -715,9 +790,11 @@ throws_ok{ SLUB::LZA::SIPBuilderBagIt::validateRightsXML(undef, $xsdName); } qr/
throws_ok{ SLUB::LZA::SIPBuilderBagIt::validateRightsXML($input_rightsFilePath, undef); } qr/xsd name not defined/, "validateRightsXML(\$rightsFilePath, \$xsdName), xsdName undef";
throws_ok{ SLUB::LZA::SIPBuilderBagIt::validateRightsXML($input_metaPath . "/mods.xml", $xsdName); } qr/failed validation/, "validateRightsXML(\$rightsFilePath, \$xsdName), rights.xml is not valid according to $xsdName";
#
my $system_prefix = 'lin_';
if($^O eq 'MSWin32'){ $system_prefix = 'win_'; }
my $ie = 'test';
my $bag = 'test_bag';
my $valid_bag = 'valid_test_bag';
my $valid_bag = $system_prefix . 'valid_test_bag';
my @addBagInfo;
push @addBagInfo, {'SLUBArchiv-sipVersion' => 'v2020.1'};
push @addBagInfo, {'SLUBArchiv-externalWorkflow' => 'kitodo'};
......@@ -745,19 +822,24 @@ throws_ok{ SLUB::LZA::SIPBuilderBagIt::create_slub_bagit(undef, \@addBagInfo); }
throws_ok{ SLUB::LZA::SIPBuilderBagIt::create_slub_bagit($bag_output_path, undef); } qr/array of hashes not defined for bag-info.txt/, "create_slub_bagit(\$bagPath, \$refAddBagInfo), refAddBagInfo undef";
throws_ok{ SLUB::LZA::SIPBuilderBagIt::create_slub_bagit("", \@addBagInfo); } qr/path is not directory/, "create_slub_bagit(\$bagPath, \$refAddBagInfo), bagPath is not a directory";
# workaround bag-info.txt, tagmanifest-md5.txt, tagmanifest-sha512.txt
workaroundBagInfoTXT($bag_output_path . '/bag-info.txt', 'Bagging-Date', 'xxxx-xx-xx');
workaroundTagmanifestMD5($bag_output_path . '/tagmanifest-md5.txt', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'bag-info.txt');
workaroundTagmanifestSHA512($bag_output_path . '/tagmanifest-sha512.txt', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'bag-info.txt');
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/data/00000001.tif', $valid_bag_path . '/data/00000001.tif'), 1, "create_slub_bagit() $bag: validate data/00000001.tif");
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/meta/mods.xml', $valid_bag_path . '/meta/mods.xml'), 1, "create_slub_bagit() $bag: validate meta/mods.xml");
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/meta/rights.xml', $valid_bag_path . '/meta/rights.xml'), 1, "create_slub_bagit() $bag: validate meta/rights.xml");
# is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/bag-info.txt', $valid_bag_path . '/bag-info.txt'), 1, "create_slub_bagit() $bag: validate bag-info.txt"); # will fail, bacause Bagging-Date is auto generated
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/bag-info.txt', $valid_bag_path . '/bag-info.txt'), 1, "create_slub_bagit() $bag: validate bag-info.txt"); # workaround
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/bagit.txt', $valid_bag_path . '/bagit.txt'), 1, "create_slub_bagit() $bag: validate bagit.txt");
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/manifest-md5.txt', $valid_bag_path . '/manifest-md5.txt'), 1, "create_slub_bagit() $bag: manifest-md5.txt");
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/manifest-sha512.txt', $valid_bag_path . '/manifest-sha512.txt'), 1, "create_slub_bagit() $bag: manifest-sha512.txt");
# is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/tagmanifest-md5.txt', $valid_bag_path . '/tagmanifest-md5.txt'), 1, "create_slub_bagit() $bag: tagmanifest-md5.txt"); # will fail, bacause bag-info.txt checksum
# is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/tagmanifest-sha512.txt', $valid_bag_path . '/tagmanifest-sha512.txt'), 1, "create_slub_bagit() $bag: tagmanifest-sha512.txt"); # will fail, bacause bag-info.txt checksum
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/tagmanifest-md5.txt', $valid_bag_path . '/tagmanifest-md5.txt'), 1, "create_slub_bagit() $bag: tagmanifest-md5.txt"); # workaround
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/tagmanifest-sha512.txt', $valid_bag_path . '/tagmanifest-sha512.txt'), 1, "create_slub_bagit() $bag: tagmanifest-sha512.txt"); # workaround
#
$ie = 'test2';
$bag = 'test2_bag';
$valid_bag = 'valid_test2_bag';
$valid_bag = $system_prefix .'valid_test2_bag';
$ie_input_path = $input_path . '/' . $ie;
$bag_output_path = $output_path . '/' . $bag;
$data_output_path = $bag_output_path . '/data';
......@@ -766,21 +848,26 @@ $valid_bag_path = $input_path . '/' . $valid_bag;
ok(SLUB::LZA::SIPBuilderBagIt::buildBagWithCopyOption($ppn, $noppn, $ie_input_path, $input_rightsFilePath, \@addMetaFile, \@addBagInfo, $bag_output_path, $data_output_path, $meta_output_path), "buildBagWithCopyOption()");
# workaround bag-info.txt, tagmanifest-md5.txt, tagmanifest-sha512.txt
workaroundBagInfoTXT($bag_output_path . '/bag-info.txt', 'Bagging-Date', 'xxxx-xx-xx');
workaroundTagmanifestMD5($bag_output_path . '/tagmanifest-md5.txt', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'bag-info.txt');
workaroundTagmanifestSHA512($bag_output_path . '/tagmanifest-sha512.txt', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'bag-info.txt');
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/data/scans_tif/00000001.tif', $valid_bag_path . '/data/scans_tif/00000001.tif'), 1, "create_slub_bagit() $bag: validate data/scans_tif/00000001.tif");
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/data/scans_tif/00000002.tif', $valid_bag_path . '/data/scans_tif/00000002.tif'), 1, "create_slub_bagit() $bag: validate data/scans_tif/00000002.tif");
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/data/test.txt', $valid_bag_path . '/data/test.txt'), 1, "create_slub_bagit() $bag: validate data/test.txt");
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/data/test.tiff', $valid_bag_path . '/data/test.tiff'), 1, "create_slub_bagit() $bag: validate data/test.tiff");
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/meta/mods.xml', $valid_bag_path . '/meta/mods.xml'), 1, "create_slub_bagit() $bag: validate meta/mods.xml");
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/meta/rights.xml', $valid_bag_path . '/meta/rights.xml'), 1, "create_slub_bagit() $bag: validate meta/rights.xml");
# is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/bag-info.txt', $valid_bag_path . '/bag-info.txt'), 1, "create_slub_bagit() $bag: validate bag-info.txt"); # will fail, bacause Bagging-Date is auto generated
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/bag-info.txt', $valid_bag_path . '/bag-info.txt'), 1, "create_slub_bagit() $bag: validate bag-info.txt"); # workaround
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/bagit.txt', $valid_bag_path . '/bagit.txt'), 1, "create_slub_bagit() $bag: validate bagit.txt");
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/manifest-md5.txt', $valid_bag_path . '/manifest-md5.txt'), 1, "create_slub_bagit() $bag: manifest-md5.txt");
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/manifest-sha512.txt', $valid_bag_path . '/manifest-sha512.txt'), 1, "create_slub_bagit() $bag: manifest-sha512.txt");
# is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/tagmanifest-md5.txt', $valid_bag_path . '/tagmanifest-md5.txt'), 1, "create_slub_bagit() $bag: tagmanifest-md5.txt"); # will fail, bacause bag-info.txt checksum
# is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/tagmanifest-sha512.txt', $valid_bag_path . '/tagmanifest-sha512.txt'), 1, "create_slub_bagit() $bag: tagmanifest-sha512.txt"); # will fail, bacause bag-info.txt checksum
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/tagmanifest-md5.txt', $valid_bag_path . '/tagmanifest-md5.txt'), 1, "create_slub_bagit() $bag: tagmanifest-md5.txt"); # workaround
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/tagmanifest-sha512.txt', $valid_bag_path . '/tagmanifest-sha512.txt'), 1, "create_slub_bagit() $bag: tagmanifest-sha512.txt"); # workaround
#
$ie = 'test3';
$bag = 'test3_bag';
$valid_bag = 'valid_test3_bag';
$valid_bag = $system_prefix . 'valid_test3_bag';
$ie_input_path = $input_path . '/' . $ie;
$bag_output_path = $output_path . '/' . $bag;
$data_output_path = $bag_output_path . '/data';
......@@ -792,21 +879,26 @@ File::Copy::Recursive::dircopy($ie_input_path, $new_ie_input_path) or die "Could
ok(SLUB::LZA::SIPBuilderBagIt::buildBagWithMoveOption($ppn, $noppn, $new_ie_input_path, $input_rightsFilePath, \@addMetaFile, \@addBagInfo, $bag_output_path, $data_output_path, $meta_output_path), "buildBagWithMoveOption()");
# workaround bag-info.txt, tagmanifest-md5.txt, tagmanifest-sha512.txt
workaroundBagInfoTXT($bag_output_path . '/bag-info.txt', 'Bagging-Date', 'xxxx-xx-xx');
workaroundTagmanifestMD5($bag_output_path . '/tagmanifest-md5.txt', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'bag-info.txt');
workaroundTagmanifestSHA512($bag_output_path . '/tagmanifest-sha512.txt', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'bag-info.txt');
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/data/img/scans_tif/00000001.tif', $valid_bag_path . '/data/img/scans_tif/00000001.tif'), 1, "create_slub_bagit() $bag: validate data/img/scans_tif/00000001.tif");
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/data/img/scans_tif/00000002.tif', $valid_bag_path . '/data/img/scans_tif/00000002.tif'), 1, "create_slub_bagit() $bag: validate data/img/scans_tif/00000002.tif");
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/data/test.txt', $valid_bag_path . '/data/test.txt'), 1, "create_slub_bagit() $bag: validate data/test.txt");
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/data/test.tiff', $valid_bag_path . '/data/test.tiff'), 1, "create_slub_bagit() $bag: validate data/test.tiff");
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/meta/mods.xml', $valid_bag_path . '/meta/mods.xml'), 1, "create_slub_bagit() $bag: validate meta/mods.xml");
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/meta/rights.xml', $valid_bag_path . '/meta/rights.xml'), 1, "create_slub_bagit() $bag: validate meta/rights.xml");
# is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/bag-info.txt', $valid_bag_path . '/bag-info.txt'), 1, "create_slub_bagit() $bag: validate bag-info.txt"); # will fail, bacause Bagging-Date is auto generated
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/bag-info.txt', $valid_bag_path . '/bag-info.txt'), 1, "create_slub_bagit() $bag: validate bag-info.txt"); # workaround
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/bagit.txt', $valid_bag_path . '/bagit.txt'), 1, "create_slub_bagit() $bag: validate bagit.txt");
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/manifest-md5.txt', $valid_bag_path . '/manifest-md5.txt'), 1, "create_slub_bagit() $bag: manifest-md5.txt");
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/manifest-sha512.txt', $valid_bag_path . '/manifest-sha512.txt'), 1, "create_slub_bagit() $bag: manifest-sha512.txt");
# is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/tagmanifest-md5.txt', $valid_bag_path . '/tagmanifest-md5.txt'), 1, "create_slub_bagit() $bag: tagmanifest-md5.txt"); # will fail, bacause bag-info.txt checksum
# is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/tagmanifest-sha512.txt', $valid_bag_path . '/tagmanifest-sha512.txt'), 1, "create_slub_bagit() $bag: tagmanifest-sha512.txt"); # will fail, bacause bag-info.txt checksum
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/tagmanifest-md5.txt', $valid_bag_path . '/tagmanifest-md5.txt'), 1, "create_slub_bagit() $bag: tagmanifest-md5.txt"); # workaround
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/tagmanifest-sha512.txt', $valid_bag_path . '/tagmanifest-sha512.txt'), 1, "create_slub_bagit() $bag: tagmanifest-sha512.txt"); # workaround
#
$ie = 'test4';
$bag = 'test4_bag';
$valid_bag = 'valid_test4_bag';
$valid_bag = $system_prefix . 'valid_test4_bag';
$ie_input_path = $input_path . '/' . $ie;
$bag_output_path = $output_path . '/' . $bag;
$data_output_path = $bag_output_path . '/data';
......@@ -818,16 +910,21 @@ File::Copy::Recursive::dircopy($ie_input_path, $new_ie_input_path) or die "Could
ok(SLUB::LZA::SIPBuilderBagIt::buildBagWithReplaceOption($ppn, $noppn, $new_ie_input_path, $input_rightsFilePath, \@addMetaFile, \@addBagInfo, $bag_output_path, $data_output_path, $meta_output_path), "buildBagWithReplaceOption()");
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/data/dir_test_äöüÄÖÜß/test2.txt', $valid_bag_path . '/data/dir_test_äöüÄÖÜß/test2.txt'), 1, "create_slub_bagit() $bag: validate data/dir_test_äöüÄÖÜß/test2.txt");
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/data/test_äöüÄÖÜß.txt', $valid_bag_path . '/data/test_äöüÄÖÜß.txt'), 1, "create_slub_bagit() $bag: validate data/test_äöüÄÖÜß.txt");
# workaround bag-info.txt, tagmanifest-md5.txt, tagmanifest-sha512.txt
workaroundBagInfoTXT($bag_output_path . '/bag-info.txt', 'Bagging-Date', 'xxxx-xx-xx');
workaroundTagmanifestMD5($bag_output_path . '/tagmanifest-md5.txt', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'bag-info.txt');
workaroundTagmanifestSHA512($bag_output_path . '/tagmanifest-sha512.txt', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'bag-info.txt');
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/data/dir_test_äöüÄÖÜß/00000001.tif', $valid_bag_path . '/data/dir_test_äöüÄÖÜß/00000001.tif'), 1, "create_slub_bagit() $bag: validate data/dir_test_äöüÄÖÜß/00000001.tif");
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/data/test_äöüÄÖÜß.tiff', $valid_bag_path . '/data/test_äöüÄÖÜß.tiff'), 1, "create_slub_bagit() $bag: validate data/test_äöüÄÖÜß.tiff");
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/meta/mods.xml', $valid_bag_path . '/meta/mods.xml'), 1, "create_slub_bagit() $bag: validate meta/mods.xml");
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/meta/rights.xml', $valid_bag_path . '/meta/rights.xml'), 1, "create_slub_bagit() $bag: validate meta/rights.xml");
# is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/bag-info.txt', $valid_bag_path . '/bag-info.txt'), 1, "create_slub_bagit() $bag: validate bag-info.txt"); # will fail, bacause Bagging-Date is auto generated
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/bag-info.txt', $valid_bag_path . '/bag-info.txt'), 1, "create_slub_bagit() $bag: validate bag-info.txt"); # workaround
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/bagit.txt', $valid_bag_path . '/bagit.txt'), 1, "create_slub_bagit() $bag: validate bagit.txt");
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/manifest-md5.txt', $valid_bag_path . '/manifest-md5.txt'), 1, "create_slub_bagit() $bag: manifest-md5.txt");
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/manifest-sha512.txt', $valid_bag_path . '/manifest-sha512.txt'), 1, "create_slub_bagit() $bag: manifest-sha512.txt");
# is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/tagmanifest-md5.txt', $valid_bag_path . '/tagmanifest-md5.txt'), 1, "create_slub_bagit() $bag: tagmanifest-md5.txt"); # will fail, bacause bag-info.txt checksum
# is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/tagmanifest-sha512.txt', $valid_bag_path . '/tagmanifest-sha512.txt'), 1, "create_slub_bagit() $bag: tagmanifest-sha512.txt"); # will fail, bacause bag-info.txt checksum
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/tagmanifest-md5.txt', $valid_bag_path . '/tagmanifest-md5.txt'), 1, "create_slub_bagit() $bag: tagmanifest-md5.txt"); # workaround
is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/tagmanifest-sha512.txt', $valid_bag_path . '/tagmanifest-sha512.txt'), 1, "create_slub_bagit() $bag: tagmanifest-sha512.txt"); # workaround
#
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment