diff --git a/t/slubsipbuilderbagit.t b/t/slubsipbuilderbagit.t index 9d90cf29635cc3abbf96df48fc001ad307ee39f5..6081349f7cd86d156da16e2f56418a3d86a973c5 100644 --- a/t/slubsipbuilderbagit.t +++ b/t/slubsipbuilderbagit.t @@ -24,7 +24,7 @@ use strict; use warnings; use diagnostics; -use Test::More tests => 120; +use Test::More tests => 138; use Test::Output; use Test::Exception; use Test::File; @@ -100,14 +100,14 @@ sub equalFilesByIgnoringCRLF_LF($$){ open(my $fh2, '<', $file_path2) or die $!; # changing the CRLF to LF - while (<$fh1>) { + while (<$fh1>) { s/\r?\n\z//; # print "$_\n"; $content1 .= "$_\n"; } - + # changing the CRLF to LF - while (<$fh2>) { + while (<$fh2>) { s/\r?\n\z//; # print "$_\n"; $content2 .= "$_\n"; @@ -628,6 +628,18 @@ my $noppn_mods_res = "<mods version=\"3.6\" my $exportToArchiveDate = "2020-08-05_10-26-11"; my $ppn = "457035137"; my $noppn = ""; +my $marc21; +my $mods; +my @addBagInfo = ( + {'SLUBArchiv-sipVersion' => 'v2020.1'}, + {'SLUBArchiv-externalWorkflow' => 'kitodo'}, + {'SLUBArchiv-externalId' => '10008'}, + {'SLUBArchiv-externalIsilId' => 'DE-14'}, + {'SLUBArchiv-exportToArchiveDate' => '2020-08-05T10:26:11'}, + {'SLUBArchiv-hasConservationReason' => 'false'}, + {'SLUBArchiv-archivalValueDescription' => 'Gesetzlicher Auftrag'}, + {'SLUBArchiv-rightsVersion' => '1.0'} +); # input my $input_path = path(__FILE__)->parent->parent->child('export_dir_kitodo')->child('bagit'); # output @@ -664,7 +676,7 @@ if($xsl_path->is_dir){ $xsl_path->remove_tree; } BEGIN { use_ok("SLUB::LZA::SIPBuilderBagIt"); } # *************************************************************************** test old functions ****************************************************************************************************************** - +# is(SLUB::LZA::SIPBuilderBagIt::check_xsl_directory(), $xsl_path->absolute, "check_xsl_directory(), return value if not exist"); ok($xsl_path->is_dir, "check_xsl_directory(), created if not exist"); is(SLUB::LZA::SIPBuilderBagIt::check_xsl_directory(), $xsl_path->absolute, "check_xsl_directory(), return value if exist"); @@ -672,16 +684,16 @@ ok($xsl_path->is_dir, "check_xsl_directory(), untouched if exist"); # SKIP: { skip "No response from server https://sru.bsz-bw.de/swb", 1 unless ! $response->is_error; - like(SLUB::LZA::SIPBuilderBagIt::get_mods_from("https://sru.bsz-bw.de/swb", $ppn, "pica.swn", "marcxmlvbos"), qr//, "get_mods_from()"); + like(SLUB::LZA::SIPBuilderBagIt::get_marc21_from("https://sru.bsz-bw.de/swb", $ppn, "pica.swn", "marcxmlvbos"), qr//, "get_marc21_from()"); }; -throws_ok{ SLUB::LZA::SIPBuilderBagIt::get_mods_from("", $ppn, "pica.swn", "marcxmlvbos"); } qr/invalid parameters/, "get_mods_from(), invalid parameters"; -throws_ok{ SLUB::LZA::SIPBuilderBagIt::get_mods_from("https://sru.bsz-bw.de/swb", "", "pica.swn", "marcxmlvbos"); } qr/invalid parameters/, "get_mods_from(), invalid parameters"; -throws_ok{ SLUB::LZA::SIPBuilderBagIt::get_mods_from("https://sru.bsz-bw.de/swb", $ppn, "", "marcxmlvbos"); } qr/invalid parameters/, "get_mods_from(), invalid parameters"; -throws_ok{ SLUB::LZA::SIPBuilderBagIt::get_mods_from("https://sru.bsz-bw.de/swb", $ppn, "pica.swn", ""); } qr/invalid parameters/, "get_mods_from(), invalid parameters"; -throws_ok{ SLUB::LZA::SIPBuilderBagIt::get_mods_from(undef, $ppn, "pica.swn", "marcxmlvbos"); } qr/url not defined/, "get_mods_from(\$url, \$ppn, \$key, \$schema), url undef"; -throws_ok{ SLUB::LZA::SIPBuilderBagIt::get_mods_from("https://sru.bsz-bw.de/swb", undef, "pica.swn", "marcxmlvbos"); } qr/ppn not defined/, "get_mods_from(\$url, \$ppn, \$key, \$schema), ppn undef"; -throws_ok{ SLUB::LZA::SIPBuilderBagIt::get_mods_from("https://sru.bsz-bw.de/swb", $ppn, undef, "marcxmlvbos"); } qr/key not defined/, "get_mods_from(\$url, \$ppn, \$key, \$schema), key undef"; -throws_ok{ SLUB::LZA::SIPBuilderBagIt::get_mods_from("https://sru.bsz-bw.de/swb", $ppn, "pica.swn", undef); } qr/schema not defined/, "get_mods_from(\$url, \$ppn, \$key, \$schema), schema undef"; +throws_ok{ SLUB::LZA::SIPBuilderBagIt::get_marc21_from("", $ppn, "pica.swn", "marcxmlvbos"); } qr/invalid parameters/, "get_marc21_from(), invalid parameters"; +throws_ok{ SLUB::LZA::SIPBuilderBagIt::get_marc21_from("https://sru.bsz-bw.de/swb", "", "pica.swn", "marcxmlvbos"); } qr/invalid parameters/, "get_marc21_from(), invalid parameters"; +throws_ok{ SLUB::LZA::SIPBuilderBagIt::get_marc21_from("https://sru.bsz-bw.de/swb", $ppn, "", "marcxmlvbos"); } qr/invalid parameters/, "get_marc21_from(), invalid parameters"; +throws_ok{ SLUB::LZA::SIPBuilderBagIt::get_marc21_from("https://sru.bsz-bw.de/swb", $ppn, "pica.swn", ""); } qr/invalid parameters/, "get_marc21_from(), invalid parameters"; +throws_ok{ SLUB::LZA::SIPBuilderBagIt::get_marc21_from(undef, $ppn, "pica.swn", "marcxmlvbos"); } qr/url not defined/, "get_marc21_from(\$url, \$ppn, \$key, \$schema), url undef"; +throws_ok{ SLUB::LZA::SIPBuilderBagIt::get_marc21_from("https://sru.bsz-bw.de/swb", undef, "pica.swn", "marcxmlvbos"); } qr/ppn not defined/, "get_marc21_from(\$url, \$ppn, \$key, \$schema), ppn undef"; +throws_ok{ SLUB::LZA::SIPBuilderBagIt::get_marc21_from("https://sru.bsz-bw.de/swb", $ppn, undef, "marcxmlvbos"); } qr/key not defined/, "get_marc21_from(\$url, \$ppn, \$key, \$schema), key undef"; +throws_ok{ SLUB::LZA::SIPBuilderBagIt::get_marc21_from("https://sru.bsz-bw.de/swb", $ppn, "pica.swn", undef); } qr/schema not defined/, "get_marc21_from(\$url, \$ppn, \$key, \$schema), schema undef"; # ok(SLUB::LZA::SIPBuilderBagIt::write_file($marc21slimutils_file, $unpatched_marc21slimutils), "write_file()"); throws_ok{ SLUB::LZA::SIPBuilderBagIt::write_file("", $unpatched_marc21slimutils); } qr/invalid parameters/, "write_file(), invalid parameters"; @@ -709,15 +721,41 @@ throws_ok{ SLUB::LZA::SIPBuilderBagIt::check_marc21_mods_xsl($xsl_path, ""); } q throws_ok{ SLUB::LZA::SIPBuilderBagIt::check_marc21_mods_xsl(undef, $useragent_obj); } qr/xsl directory not defined/, "check_marc21_mods_xsl(\$xsl_dir, \$useragent), xsl_dir undef"; throws_ok{ SLUB::LZA::SIPBuilderBagIt::check_marc21_mods_xsl($xsl_path, undef); } qr/user agent not defined/, "check_marc21_mods_xsl(\$xsl_dir, \$useragent), useragent undef"; # -SKIP: { - skip "No response from server https://sru.bsz-bw.de/swb", 1 unless ! $response->is_error; - like(SLUB::LZA::SIPBuilderBagIt::prepare_mods_section_with_ppn($ppn), qr//, "prepare_mods_section_with_ppn()"); -}; -throws_ok{ SLUB::LZA::SIPBuilderBagIt::prepare_mods_section_with_ppn(""); } qr/invalid parameters/, "prepare_mods_section_with_ppn(), invalid parameters"; -throws_ok{ SLUB::LZA::SIPBuilderBagIt::prepare_mods_section_with_ppn(undef); } qr/ppn not defined/, "prepare_mods_section_with_ppn(\$ppn), ppn undef"; +ok( $marc21 = SLUB::LZA::SIPBuilderBagIt::get_marc21_from_catalogue($ppn), "get_marc21_from_catalogue(), valid"); +like( $marc21, qr/<datafield tag="/, "get_marc21_from_catalogue(), valid"); +throws_ok{ SLUB::LZA::SIPBuilderBagIt::get_marc21_from_catalogue(""); } qr/ppn not defined/, "get_marc21_from_catalogue(), invalid"; +throws_ok{ SLUB::LZA::SIPBuilderBagIt::get_marc21_from_catalogue(undef); } qr/ppn not defined/, "get_marc21_from_catalogue(), invalid"; +# +is( SLUB::LZA::SIPBuilderBagIt::get_marc21_text_node($marc21, { tag => "245", code => "a", key => "Title" }), "Der Fichtelberg", "get_marc21_text_node(), valid"); +throws_ok{ SLUB::LZA::SIPBuilderBagIt::get_marc21_text_node("", { tag => "245", code => "a", key => "Title" }); } qr/empty marc21/, "get_marc21_text_node(), invalid"; +throws_ok{ SLUB::LZA::SIPBuilderBagIt::get_marc21_text_node(undef, { tag => "245", code => "a", key => "Title" }); } qr/empty marc21/, "get_marc21_text_node(), invalid"; +throws_ok{ SLUB::LZA::SIPBuilderBagIt::get_marc21_text_node($marc21, "" ); } qr/not a mapping hash/, "get_marc21_text_node(), invalid"; +throws_ok{ SLUB::LZA::SIPBuilderBagIt::get_marc21_text_node($marc21, undef); } qr/not a mapping hash/, "get_marc21_text_node(), invalid"; +# +ok( $mods = SLUB::LZA::SIPBuilderBagIt::get_mods_from_marc21($marc21), "get_mods_from_marc21(), valid"); +like( $mods, qr/<mods.*xmlns="http:\/\/www\.loc\.gov\/mods\/v3\"/, "get_mods_from_marc21(), valid"); +throws_ok{ SLUB::LZA::SIPBuilderBagIt::get_mods_from_marc21(""); } qr/marc21 empty/, "get_mods_from_marc21(), invalid"; +throws_ok{ SLUB::LZA::SIPBuilderBagIt::get_mods_from_marc21(undef); } qr/marc21 empty/, "get_mods_from_marc21(), invalid"; +# +my @baginfo_got = @addBagInfo; +my @baginfo_expected = @addBagInfo; +push @baginfo_expected, ( + { "External-Identifier" => "PPN:457035137" }, + { "Title" => "Der Fichtelberg" }, + { "Title" => "Berg der unbekannten Rekorde" }, + { "Title" => "ein Film von Dirk Schneider" }, + { "Title" => "Der Osten - entdecke wo du lebst" } +); +ok( SLUB::LZA::SIPBuilderBagIt::add_metadata(\@baginfo_got, $ppn, $noppn, $marc21), "add_metadata(), valid"); +is_deeply( \@baginfo_got, \@baginfo_expected, "add_metadata(), valid"); +throws_ok{ SLUB::LZA::SIPBuilderBagIt::add_metadata("" , $ppn, $noppn, $marc21); } qr/not defined/, "add_metadata(), invalid"; +throws_ok{ SLUB::LZA::SIPBuilderBagIt::add_metadata(undef, $ppn, $noppn, $marc21); } qr/not defined/, "add_metadata(), invalid"; +# +is( SLUB::LZA::SIPBuilderBagIt::checkForTitle(\@baginfo_expected), 1, "checkForTitle(), valid"); +is( SLUB::LZA::SIPBuilderBagIt::checkForTitle(\@addBagInfo), 0, "checkForTitle(), valid"); # no 'Title' +throws_ok{ SLUB::LZA::SIPBuilderBagIt::checkForTitle(""); } qr/no array/, "checkForTitle(), invalid"; +throws_ok{ SLUB::LZA::SIPBuilderBagIt::checkForTitle(undef); } qr/no array/, "checkForTitle(), invalid"; # -# *************************************************************************** test new functions ****************************************************************************************************************** - is(SLUB::LZA::SIPBuilderBagIt::generateBagName($exportToArchiveDate, $ppn, $noppn), "PPN-457035137_2020-08-05_10-26-11", "generateBagName()"); # my $output_dir = $output_path->child("dir"); @@ -732,7 +770,6 @@ my $output_lidoFilePath = $output_metaPath->child("lido.xml"); my $output_bubbleFilePath = $output_metaPath->child("bubble.xml"); my $output_sameModsFilePath = $output_metaPath->child("1.xml"); my $output_sameRightsFilePath = $output_metaPath->child("2.xml"); - my $input_metaPath = path(__FILE__)->parent->parent->child('export_dir_kitodo')->child('bagit')->child("meta"); my $input_modsFilePath = $input_metaPath->child("mods.xml"); my $input_rightsFilePath = $input_metaPath->child("rights.xml"); @@ -740,7 +777,7 @@ my $input_lidoFilePath = $input_metaPath->child("lido.xml"); my $input_bubbleFilePath = $input_metaPath->child("bubble.xml"); my @input_addMetaFile = ($input_lidoFilePath, $input_bubbleFilePath, $input_modsFilePath, $input_rightsFilePath); SLUB::LZA::SIPBuilderBagIt::createDir($output_metaPath); -SLUB::LZA::SIPBuilderBagIt::copyFilesToMeta($ppn, $noppn, $output_metaPath, $input_rightsFilePath, \@input_addMetaFile); +SLUB::LZA::SIPBuilderBagIt::copyFilesToMeta($ppn, $noppn, $output_metaPath, $input_rightsFilePath, \@input_addMetaFile, $mods); is(-f $output_modsFilePath, 1, "copyFilesToMeta() file $output_modsFilePath exists."); is(-f $output_rightsFilePath, 1, "copyFilesToMeta() file $output_rightsFilePath exists."); is(-f $output_lidoFilePath, 1, "copyFilesToMeta() file $output_lidoFilePath exists."); @@ -781,15 +818,6 @@ if($^O eq 'MSWin32'){ $system_prefix = 'win_'; } my $ie = 'test'; my $bag = 'test_bag'; my $valid_bag = $system_prefix . 'valid_test_bag'; -my @addBagInfo; -push @addBagInfo, {'SLUBArchiv-sipVersion' => 'v2020.1'}; -push @addBagInfo, {'SLUBArchiv-externalWorkflow' => 'kitodo'}; -push @addBagInfo, {'SLUBArchiv-externalId' => '10008'}; -push @addBagInfo, {'SLUBArchiv-externalIsilId' => 'DE-14'}; -push @addBagInfo, {'SLUBArchiv-exportToArchiveDate' => '2020-08-05T10:26:11'}; -push @addBagInfo, {'SLUBArchiv-hasConservationReason' => 'false'}; -push @addBagInfo, {'SLUBArchiv-archivalValueDescription' => 'Gesetzlicher Auftrag'}; -push @addBagInfo, {'SLUBArchiv-rightsVersion' => '1.0'}; my @addMetaFile = (); my $ie_input_path = $input_path . '/' . $ie; my $bag_output_path = $output_path . '/' . $bag; @@ -801,7 +829,7 @@ SLUB::LZA::SIPBuilderBagIt::createDir($bag_output_path); SLUB::LZA::SIPBuilderBagIt::createDir($data_output_path); File::Copy::Recursive::dircopy($ie_input_path, $data_output_path) or die "Could not perform dircopy() of $ie_input_path to autogenerated $data_output_path: $!"; SLUB::LZA::SIPBuilderBagIt::createDir($meta_output_path); -SLUB::LZA::SIPBuilderBagIt::copyFilesToMeta($ppn, $noppn, $meta_output_path, $input_rightsFilePath, \@addMetaFile); +SLUB::LZA::SIPBuilderBagIt::copyFilesToMeta($ppn, $noppn, $meta_output_path, $input_rightsFilePath, \@addMetaFile, $mods); ok(SLUB::LZA::SIPBuilderBagIt::create_slub_bagit($bag_output_path, \@addBagInfo), "create_slub_bagit()"); throws_ok{ SLUB::LZA::SIPBuilderBagIt::create_slub_bagit(undef, \@addBagInfo); } qr/bagPath is not defined/, "create_slub_bagit(\$bagPath, \$refAddBagInfo), bagPath undef"; @@ -911,7 +939,5 @@ is(equalFilesByIgnoringCRLF_LF($bag_output_path . '/manifest-md5.txt', $valid_ba 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"); # 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 -# - 1;