Skip to content
Snippets Groups Projects
Commit 30e53dd7 authored by Bolkun's avatar Bolkun
Browse files

new tests based on refactoring

parent f2daaaf8
No related branches found
No related tags found
No related merge requests found
...@@ -8,8 +8,9 @@ use Test::Output; ...@@ -8,8 +8,9 @@ use Test::Output;
use Test::Exception; use Test::Exception;
use Test::File; use Test::File;
use Path::Tiny; use Path::Tiny;
use File::Copy::Recursive; # for dircopy() use File::Copy::Recursive qw(dircopy);
use File::Path qw(rmtree); use File::Path qw(rmtree);
use File::Compare;
# *** Read before running tests *** # *** Read before running tests ***
...@@ -29,11 +30,13 @@ my $unpatched_mods=<<'UNPATCHED_MODS'; ...@@ -29,11 +30,13 @@ my $unpatched_mods=<<'UNPATCHED_MODS';
<mods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.loc.gov/mods/v3" version="3.6" xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-6.xsd"><titleInfo><nonSort xml:space="preserve">Der </nonSort><title>Fichtelberg</title><subTitle>Berg der unbekannten Rekorrde</subTitle></titleInfo><name type="personal"><namePart>Schneider, Dirk</namePart><role><roleTerm type="text">FilmemacherIn</roleTerm></role><role><roleTerm authority="marcrelator" type="code">fmk</roleTerm></role><nameIdentifier>(DE-627)1235502279 (DE-576)165502274</nameIdentifier></name><typeOfResource>moving image</typeOfResource><genre authority="rdacontent">zweidimensionales bewegtes Bild</genre><genre authority="gnd-content">Film</genre><originInfo><place><placeTerm type="code" authority="marccountry">xx</placeTerm></place><dateIssued encoding="marc">2014</dateIssued><issuance>monographic</issuance></originInfo><originInfo eventType="publication"><place><placeTerm type="text">[Leipzig]</placeTerm></place><publisher>top ten tv</publisher><dateIssued>[2014]</dateIssued></originInfo><language><languageTerm authority="iso639-2b" type="code">ger</languageTerm></language><physicalDescription><form authority="marccategory">electronic resource</form><form authority="marcsmd">remote</form><extent>1 Online-Ressource (1 Videodatei, 29:49) farbig</extent><form type="media" authority="rdamedia">Computermedien</form><form type="carrier" authority="rdacarrier">Online-Ressource</form></physicalDescription><targetAudience authority="marctarget">juvenile</targetAudience><note type="statement of responsibility" altRepGroup="00">ein Film von Dirk Schneider</note><note>Dokumentarfilm. Deutschland. 2014</note><relatedItem type="series"><titleInfo><title>MDR</title></titleInfo></relatedItem><relatedItem type="series"><titleInfo><title>Der Osten - entdecke wo du lebst</title></titleInfo></relatedItem><identifier type="oclc">946544758</identifier><recordInfo><descriptionStandard>rda</descriptionStandard><recordContentSource authority="marcorg">DE-576</recordContentSource><recordCreationDate encoding="marc">160304</recordCreationDate><recordChangeDate encoding="iso8601">20160510144338.0</recordChangeDate><recordIdentifier source="DE-576">457035137</recordIdentifier><recordOrigin>Converted from MARCXML to MODS version 3.6 using MARC21slim2MODS3-6.xsl <mods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.loc.gov/mods/v3" version="3.6" xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-6.xsd"><titleInfo><nonSort xml:space="preserve">Der </nonSort><title>Fichtelberg</title><subTitle>Berg der unbekannten Rekorrde</subTitle></titleInfo><name type="personal"><namePart>Schneider, Dirk</namePart><role><roleTerm type="text">FilmemacherIn</roleTerm></role><role><roleTerm authority="marcrelator" type="code">fmk</roleTerm></role><nameIdentifier>(DE-627)1235502279 (DE-576)165502274</nameIdentifier></name><typeOfResource>moving image</typeOfResource><genre authority="rdacontent">zweidimensionales bewegtes Bild</genre><genre authority="gnd-content">Film</genre><originInfo><place><placeTerm type="code" authority="marccountry">xx</placeTerm></place><dateIssued encoding="marc">2014</dateIssued><issuance>monographic</issuance></originInfo><originInfo eventType="publication"><place><placeTerm type="text">[Leipzig]</placeTerm></place><publisher>top ten tv</publisher><dateIssued>[2014]</dateIssued></originInfo><language><languageTerm authority="iso639-2b" type="code">ger</languageTerm></language><physicalDescription><form authority="marccategory">electronic resource</form><form authority="marcsmd">remote</form><extent>1 Online-Ressource (1 Videodatei, 29:49) farbig</extent><form type="media" authority="rdamedia">Computermedien</form><form type="carrier" authority="rdacarrier">Online-Ressource</form></physicalDescription><targetAudience authority="marctarget">juvenile</targetAudience><note type="statement of responsibility" altRepGroup="00">ein Film von Dirk Schneider</note><note>Dokumentarfilm. Deutschland. 2014</note><relatedItem type="series"><titleInfo><title>MDR</title></titleInfo></relatedItem><relatedItem type="series"><titleInfo><title>Der Osten - entdecke wo du lebst</title></titleInfo></relatedItem><identifier type="oclc">946544758</identifier><recordInfo><descriptionStandard>rda</descriptionStandard><recordContentSource authority="marcorg">DE-576</recordContentSource><recordCreationDate encoding="marc">160304</recordCreationDate><recordChangeDate encoding="iso8601">20160510144338.0</recordChangeDate><recordIdentifier source="DE-576">457035137</recordIdentifier><recordOrigin>Converted from MARCXML to MODS version 3.6 using MARC21slim2MODS3-6.xsl
(Revision 1.119 2018/06/21)</recordOrigin><languageOfCataloging><languageTerm authority="iso639-2b" type="code">ger</languageTerm></languageOfCataloging></recordInfo></mods> (Revision 1.119 2018/06/21)</recordOrigin><languageOfCataloging><languageTerm authority="iso639-2b" type="code">ger</languageTerm></languageOfCataloging></recordInfo></mods>
UNPATCHED_MODS UNPATCHED_MODS
my $patched_mods=<<'PATCHED_MODS'; my $patched_mods=<<'PATCHED_MODS';
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<mods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.loc.gov/mods/v3" version="3.6" xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-6.xsd"><titleInfo><nonSort xml:space="preserve">Der </nonSort><title>Fichtelberg</title><subTitle>Berg der unbekannten Rekorrde</subTitle></titleInfo><name type="personal"><namePart>Schneider, Dirk</namePart><role><roleTerm type="text">FilmemacherIn</roleTerm></role><role><roleTerm authority="marcrelator" type="code">fmk</roleTerm></role><nameIdentifier>(DE-627)1235502279 (DE-576)165502274</nameIdentifier></name><typeOfResource>moving image</typeOfResource><genre authority="rdacontent">zweidimensionales bewegtes Bild</genre><genre authority="gnd-content">Film</genre><originInfo><place><placeTerm type="code" authority="marccountry">xx</placeTerm></place><dateIssued encoding="marc">2014</dateIssued><issuance>monographic</issuance></originInfo><originInfo eventType="publication"><place><placeTerm type="text">[Leipzig]</placeTerm></place><publisher>top ten tv</publisher><dateIssued>[2014]</dateIssued></originInfo><language><languageTerm authority="iso639-2b" type="code">ger</languageTerm></language><physicalDescription><form authority="marccategory">electronic resource</form><form authority="marcsmd">remote</form><extent>1 Online-Ressource (1 Videodatei, 29:49) farbig</extent><form type="media" authority="rdamedia">Computermedien</form><form type="carrier" authority="rdacarrier">Online-Ressource</form></physicalDescription><targetAudience authority="marctarget">juvenile</targetAudience><note type="statement of responsibility" altRepGroup="00">ein Film von Dirk Schneider</note><note>Dokumentarfilm. Deutschland. 2014</note><relatedItem type="series"><titleInfo><title>MDR</title></titleInfo></relatedItem><relatedItem type="series"><titleInfo><title>Der Osten - entdecke wo du lebst</title></titleInfo></relatedItem><identifier type="oclc">946544758</identifier><recordInfo><descriptionStandard>rda</descriptionStandard><recordContentSource authority="marcorg">DE-576</recordContentSource><recordCreationDate encoding="marc">160304</recordCreationDate><recordChangeDate encoding="iso8601">20160510144338.0</recordChangeDate><recordIdentifier source="DE-576">457035137</recordIdentifier><recordOrigin>Converted from MARCXML to MODS version 3.6 using MARC21slim2MODS3-6.xsl <mods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.loc.gov/mods/v3" version="3.6" xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-6.xsd"><titleInfo><nonSort xml:space="preserve">Der </nonSort><title>Fichtelberg</title><subTitle>Berg der unbekannten Rekorrde</subTitle></titleInfo><name type="personal"><namePart>Schneider, Dirk</namePart><role><roleTerm type="text">FilmemacherIn</roleTerm></role><role><roleTerm authority="marcrelator" type="code">fmk</roleTerm></role><nameIdentifier>(DE-627)1235502279 (DE-576)165502274</nameIdentifier></name><typeOfResource>moving image</typeOfResource><genre authority="rdacontent">zweidimensionales bewegtes Bild</genre><genre authority="gnd-content">Film</genre><originInfo><place><placeTerm type="code" authority="marccountry">xx</placeTerm></place><dateIssued encoding="marc">2014</dateIssued><issuance>monographic</issuance></originInfo><originInfo eventType="publication"><place><placeTerm type="text">[Leipzig]</placeTerm></place><publisher>top ten tv</publisher><dateIssued>[2014]</dateIssued></originInfo><language><languageTerm authority="iso639-2b" type="code">ger</languageTerm></language><physicalDescription><form authority="marccategory">electronic resource</form><form authority="marcsmd">remote</form><extent>1 Online-Ressource (1 Videodatei, 29:49) farbig</extent><form type="media" authority="rdamedia">Computermedien</form><form type="carrier" authority="rdacarrier">Online-Ressource</form></physicalDescription><targetAudience authority="marctarget">juvenile</targetAudience><note type="statement of responsibility" altRepGroup="00">ein Film von Dirk Schneider</note><note>Dokumentarfilm. Deutschland. 2014</note><relatedItem type="series"><titleInfo><title>MDR</title></titleInfo></relatedItem><relatedItem type="series"><titleInfo><title>Der Osten - entdecke wo du lebst</title></titleInfo></relatedItem><identifier type="oclc">946544758</identifier><recordInfo><descriptionStandard>rda</descriptionStandard><recordContentSource authority="marcorg">DE-576</recordContentSource><recordCreationDate encoding="marc">160304</recordCreationDate><recordChangeDate encoding="iso8601">20160510144338.0</recordChangeDate><recordIdentifier source="DE-576">457035137</recordIdentifier><recordOrigin>Converted from MARCXML to MODS version 3.6 using MARC21slim2MODS3-6.xsl
(Revision 1.119 2018/06/21)</recordOrigin><languageOfCataloging><languageTerm authority="iso639-2b" type="code">ger</languageTerm></languageOfCataloging></recordInfo></mods> (Revision 1.119 2018/06/21)</recordOrigin><languageOfCataloging><languageTerm authority="iso639-2b" type="code">ger</languageTerm></languageOfCataloging></recordInfo></mods>
PATCHED_MODS PATCHED_MODS
my $unpatched_mods_obj = XML::LibXML->load_xml(string => $unpatched_mods); my $unpatched_mods_obj = XML::LibXML->load_xml(string => $unpatched_mods);
my $unpatched_marcblob=<<'UNPATCHED_MARCBLOB'; my $unpatched_marcblob=<<'UNPATCHED_MARCBLOB';
...@@ -317,6 +320,7 @@ my $patched_marcblob =<<'PATCHED_MARCBLOB'; ...@@ -317,6 +320,7 @@ my $patched_marcblob =<<'PATCHED_MARCBLOB';
</datafield> </datafield>
</record> </record>
PATCHED_MARCBLOB PATCHED_MARCBLOB
my $unpatched_marcblob_obj = XML::LibXML->load_xml(string => $unpatched_marcblob); my $unpatched_marcblob_obj = XML::LibXML->load_xml(string => $unpatched_marcblob);
my $unpatched_marc21slimutils = <<'UNPATCHED_MARC21SLIMUTIL'; my $unpatched_marc21slimutils = <<'UNPATCHED_MARC21SLIMUTIL';
...@@ -519,53 +523,26 @@ my $noppn_mods_res = "<mods version=\"3.6\" ...@@ -519,53 +523,26 @@ my $noppn_mods_res = "<mods version=\"3.6\"
"; ";
# preparation # preparation
my $xsl_path = path(__FILE__)->parent->parent->child('xsl'); my $exportToArchiveDate = "2020-08-05_10-26-11";
my $ppn = "457035137";
my $noppn = "";
# input # input
my $export_dir_kitodo_path = path(__FILE__)->parent->parent->child('export_dir_kitodo');
if(! -d $export_dir_kitodo_path) { mkdir $export_dir_kitodo_path or die "Error creating directory: $export_dir_kitodo_path"; }
my $input_path = path(__FILE__)->parent->parent->child('export_dir_kitodo')->child('bagit'); my $input_path = path(__FILE__)->parent->parent->child('export_dir_kitodo')->child('bagit');
if(! -d $input_path) { mkdir $input_path or die "Error creating directory: $input_path"; }
# output # output
my $output_path = path(__FILE__)->parent->parent->child('tmp')->child('bagit'); my $output_path = path(__FILE__)->parent->parent->child('tmp')->child('bagit');
rmtree $output_path; # delete tmp/bagit die
if(! -d $output_path->parent) { mkdir $output_path->parent or die "Error creating directory: tmp"; } if(! -d $output_path->parent) { mkdir $output_path->parent or die "Error creating directory: tmp"; }
if(! -d $output_path) { mkdir $output_path or die "Error creating directory: $output_path";} if(! -d $output_path) { mkdir $output_path or die "Error creating directory: tmp/bagit"; }
# create ie
my $ie = 'test';
my @addBagInfo;
push @addBagInfo, {'SLUBArchiv-sipVersion' => 'v2020.1'};
push @addBagInfo, {'Author' => 'Taras Schevchenko'};
my $ie_input_path = $input_path . '/' . $ie;
my $ie_output_path = $output_path . '/' . $ie;
my $file_name = $ie_output_path . '/data/' . 'test.txt';
if(! -d $input_path->child("test")){ mkdir $input_path->child("test") or die "Error creating directory: " . $input_path->child("test"); }
if(! -d $input_path->child("test")->child("data")){ mkdir $input_path->child("test")->child("data") or die "Error creating directory: " . $input_path->child("test")->("data"); }
if(! -f $input_path->child("test")->child("data")->child("test.txt")) {
open(my $fh, '>:encoding(UTF-8)', $input_path->child("test")->child("data")->child("test.txt")) or die "Could not open file " . $input_path->child("test")->child("data")->child("test.txt") . " $!";
print $fh "test file for payload.\n";
close $fh;
}
if(! -d $input_path->child("test")->child("meta")){ mkdir $input_path->child("test")->child("meta") or die "Error creating directory: " . $input_path->child("test")->child("meta"); }
# copy Fallbeispiele-*.xml (as rights.xml) file to output_path/meta
my $rightsXMLPath = path(__FILE__)->parent->realpath->parent->child("export_dir_kitodo")->child("bagit")->child("rights"); # absolute path
File::Copy::Recursive::dircopy($rightsXMLPath, "$ie_input_path/meta") or die "Could not perform dircopy() of $rightsXMLPath to $ie_input_path/meta: $!";
# copy other meta files to output_path/meta
my $otherMetaPath = path(__FILE__)->parent->realpath->parent->child("export_dir_kitodo")->child("bagit")->child("meta"); # absolute path
File::Copy::Recursive::dircopy($otherMetaPath, "$ie_input_path/meta") or die "Could not perform dircopy() of $rightsXMLPath to $ie_input_path/meta: $!";
# delete bagit from last session
rmtree $ie_output_path;
# copy new ie to output_path
File::Copy::Recursive::dircopy($ie_input_path, $ie_output_path) or die "Could not perform dircopy() of $ie_input_path to $ie_output_path: $!";
#~ structure of input output folders for tests #~ structure of input output folders for tests
#~ . #~ .
#~ ├── export_dir_kitodo #~ ├── export_dir_kitodo
#~ │ └─── bagit #~ │ └─── bagit
#~ │ └── test
#~ │ #~ │
#~ └── tmp #~ └── tmp
#~ └── bagit #~ └── bagit
#~ └── test
my $xsl_path = path(__FILE__)->parent->parent->child('xsl');
my $ua = LWP::UserAgent->new; my $ua = LWP::UserAgent->new;
my $request = HTTP::Request->new('GET' => "https://sru.bsz-bw.de/swbf"); my $request = HTTP::Request->new('GET' => "https://sru.bsz-bw.de/swbf");
my $response = $ua->request($request); my $response = $ua->request($request);
...@@ -579,7 +556,9 @@ if($xsl_path->is_dir){ $xsl_path->remove_tree; } ...@@ -579,7 +556,9 @@ if($xsl_path->is_dir){ $xsl_path->remove_tree; }
### tests ### tests
BEGIN { use_ok("SLUB::LZA::SIPBuilderBagIt"); } 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"); 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"); 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"); is(SLUB::LZA::SIPBuilderBagIt::check_xsl_directory(), $xsl_path->absolute, "check_xsl_directory(), return value if exist");
...@@ -587,16 +566,16 @@ ok($xsl_path->is_dir, "check_xsl_directory(), untouched if exist"); ...@@ -587,16 +566,16 @@ ok($xsl_path->is_dir, "check_xsl_directory(), untouched if exist");
# #
SKIP: { SKIP: {
skip "No response from server https://sru.bsz-bw.de/swb", 1 unless ! $response->is_error; 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", "457035137", "pica.swn", "marcxmlvbos"), qr//, "get_mods_from()"); like(SLUB::LZA::SIPBuilderBagIt::get_mods_from("https://sru.bsz-bw.de/swb", $ppn, "pica.swn", "marcxmlvbos"), qr//, "get_mods_from()");
}; };
throws_ok{ SLUB::LZA::SIPBuilderBagIt::get_mods_from("", "457035137", "pica.swn", "marcxmlvbos"); } qr/invalid parameters/, "get_mods_from(), invalid parameters"; 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", "", "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", "457035137", "", "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", "457035137", "pica.swn", ""); } 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, "457035137", "pica.swn", "marcxmlvbos"); } qr/url not defined/, "get_mods_from(\$url, \$ppn, \$key, \$schema), url undef"; 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", 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", "457035137", 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, 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", "457035137", "pica.swn", undef); } qr/schema not defined/, "get_mods_from(\$url, \$ppn, \$key, \$schema), schema 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";
# #
ok(SLUB::LZA::SIPBuilderBagIt::write_file($marc21slimutils_file, $unpatched_marc21slimutils), "write_file()"); 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"; throws_ok{ SLUB::LZA::SIPBuilderBagIt::write_file("", $unpatched_marc21slimutils); } qr/invalid parameters/, "write_file(), invalid parameters";
...@@ -626,7 +605,7 @@ throws_ok{ SLUB::LZA::SIPBuilderBagIt::check_marc21_mods_xsl($xsl_path, undef); ...@@ -626,7 +605,7 @@ throws_ok{ SLUB::LZA::SIPBuilderBagIt::check_marc21_mods_xsl($xsl_path, undef);
# #
SKIP: { SKIP: {
skip "No response from server https://sru.bsz-bw.de/swb", 1 unless ! $response->is_error; 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("457035137"), qr//, "prepare_mods_section_with_ppn()"); 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(""); } 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"; throws_ok{ SLUB::LZA::SIPBuilderBagIt::prepare_mods_section_with_ppn(undef); } qr/ppn not defined/, "prepare_mods_section_with_ppn(\$ppn), ppn undef";
...@@ -634,50 +613,112 @@ throws_ok{ SLUB::LZA::SIPBuilderBagIt::prepare_mods_section_with_ppn(undef); } q ...@@ -634,50 +613,112 @@ throws_ok{ SLUB::LZA::SIPBuilderBagIt::prepare_mods_section_with_ppn(undef); } q
is(SLUB::LZA::SIPBuilderBagIt::prepare_mods_section_with_noppn("string"), $noppn_mods_res, "prepare_mods_section_with_noppn()"); is(SLUB::LZA::SIPBuilderBagIt::prepare_mods_section_with_noppn("string"), $noppn_mods_res, "prepare_mods_section_with_noppn()");
throws_ok{ SLUB::LZA::SIPBuilderBagIt::prepare_mods_section_with_noppn(""); } qr/noppn is empty string!/, "prepare_mods_section_with_noppn(), noppn is empty string!"; throws_ok{ SLUB::LZA::SIPBuilderBagIt::prepare_mods_section_with_noppn(""); } qr/noppn is empty string!/, "prepare_mods_section_with_noppn(), noppn is empty string!";
throws_ok{ SLUB::LZA::SIPBuilderBagIt::prepare_mods_section_with_noppn(undef); } qr/noppn is not defined/, "prepare_mods_section_with_noppn(\$noppn), noppn undef"; throws_ok{ SLUB::LZA::SIPBuilderBagIt::prepare_mods_section_with_noppn(undef); } qr/noppn is not defined/, "prepare_mods_section_with_noppn(\$noppn), noppn undef";
# test new
ok(SLUB::LZA::SIPBuilderBagIt::create_slub_bagit($ie_output_path, \@addBagInfo), "create_slub_bagit()"); # *************************************************************************** test new functions ******************************************************************************************************************
throws_ok{ SLUB::LZA::SIPBuilderBagIt::create_slub_bagit(undef, \@addBagInfo); } qr/ie_path is not defined/, "create_slub_bagit(\$ie_path, \$refAddBagInfo), ie_path undef";
throws_ok{ SLUB::LZA::SIPBuilderBagIt::create_slub_bagit($ie_output_path, undef); } qr/array of hashes not defined for bag-info.txt/, "create_slub_bagit(\$ie_path, \$refAddBagInfo), refAddBagInfo undef"; is(SLUB::LZA::SIPBuilderBagIt::generateBagName($exportToArchiveDate, $ppn, $noppn), "PPN-457035137_2020-08-05_10-26-11", "generateBagName()");
throws_ok{ SLUB::LZA::SIPBuilderBagIt::create_slub_bagit("", \@addBagInfo); } qr/path is not directory/, "create_slub_bagit(), invalid parameters"; #
my $output_dir = $output_path->child("dir");
SLUB::LZA::SIPBuilderBagIt::createDir($output_dir);
is(-d $output_dir, 1, "createDir(\$path) path is directory");
is(-e $output_dir, 1, "createDir(\$path) directory exists in path $output_dir");
# #
is(SLUB::LZA::SIPBuilderBagIt::getBagItName($ie_output_path), $ie, "getBagItName()"); my $output_metaPath = $output_path->child("dir")->child("meta");
throws_ok{ SLUB::LZA::SIPBuilderBagIt::getBagItName(undef); } qr/path for getting bagit name is not defined/, "getBagItName(\$bagit_name), bagit_name undef"; my $output_modsFilePath = $output_metaPath->child("mods.xml"); # auto generated in copyFilesToMeta()
throws_ok{ SLUB::LZA::SIPBuilderBagIt::getBagItName(""); } qr/path is not directory/, "getBagItName(), invalid parameters"; my $output_rightsFilePath = $output_metaPath->child("rights.xml");
my $output_lidoFilePath = $output_metaPath->child("lido.xml");
my $output_bubbleFilePath = $output_metaPath->child("bubble.xml");
my $input_metaPath = path(__FILE__)->parent->parent->child('export_dir_kitodo')->child('bagit')->child("meta");
my $input_rightsFilePath = $input_metaPath->child("rights.xml");
my $input_lidoFilePath = $input_metaPath->child("lido.xml");
my $input_bubbleFilePath = $input_metaPath->child("bubble.xml");
my @input_addMetaFile = ($input_lidoFilePath, $input_bubbleFilePath);
SLUB::LZA::SIPBuilderBagIt::createDir($output_metaPath);
SLUB::LZA::SIPBuilderBagIt::copyFilesToMeta($ppn, $noppn, $output_metaPath, $input_rightsFilePath, \@input_addMetaFile);
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.");
is(-f $output_bubbleFilePath, 1, "copyFilesToMeta() file $output_bubbleFilePath exists.");
is(compare($output_rightsFilePath, $input_rightsFilePath), 0, "copyFilesToMeta() file $input_rightsFilePath is identical to $output_rightsFilePath");
is(compare($output_lidoFilePath, $input_lidoFilePath), 0, "copyFilesToMeta() file $input_lidoFilePath is identical to $output_lidoFilePath");
is(compare($output_bubbleFilePath, $input_bubbleFilePath), 0, "copyFilesToMeta() file $input_bubbleFilePath is identical to $output_bubbleFilePath");
# #
is(SLUB::LZA::SIPBuilderBagIt::getFileName($file_name), "test.txt", "getFileName()"); is(SLUB::LZA::SIPBuilderBagIt::getFileName($input_bubbleFilePath), "bubble.xml", "getFileName()");
throws_ok{ SLUB::LZA::SIPBuilderBagIt::getFileName(undef); } qr/path with file name is not defined/, "getFileName(\$file_name), file_name undef"; throws_ok{ SLUB::LZA::SIPBuilderBagIt::getFileName(undef); } qr/path with file name is not defined/, "getFileName(\$file_name), file_name undef";
throws_ok{ SLUB::LZA::SIPBuilderBagIt::getFileName(""); } qr/invalid parameters/, "getFileName(), invalid parameters"; throws_ok{ SLUB::LZA::SIPBuilderBagIt::getFileName(""); } qr/invalid parameters/, "getFileName(), invalid parameters";
# #
is(SLUB::LZA::SIPBuilderBagIt::save_option("copy", $ie_input_path, $ie_output_path, "ID-10000000_2020-01-01_20-00-00"), $ie_output_path . "/ID-10000000_2020-01-01_20-00-00", "save_option()"); my $rightsName = "rights.xml";
rmtree $ie_output_path . "/ID-10000000_2020-01-01_20-00-00"; my $xsdName = "rights1.xsd";
throws_ok{ SLUB::LZA::SIPBuilderBagIt::save_option(undef, $ie_input_path, $ie_output_path, "ID-10000000_2020-01-01_20-00-00"); } qr/save option not defined/, "save_option(\$save, \$directory, \$output, \$bagNewDir), save undef"; my $input_rights = path(__FILE__)->parent->parent->child('export_dir_kitodo')->child('bagit')->child("rights");
throws_ok{ SLUB::LZA::SIPBuilderBagIt::save_option("copy", undef, $ie_output_path, "ID-10000000_2020-01-01_20-00-00"); } qr/IE directory path not defined/, "save_option(\$save, \$directory, \$output, \$bagNewDir), directory undef"; is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($input_rights, "Fallbeispiel-01.xml", $xsdName), 1, "validateRightsXML() Fallbeispiel-01.xml according to $xsdName");
throws_ok{ SLUB::LZA::SIPBuilderBagIt::save_option("copy", $ie_input_path, undef, "ID-10000000_2020-01-01_20-00-00"); } qr/output path not defined/, "save_option(\$save, \$directory, \$output, \$bagNewDir), for \$save=copy directory undef"; is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($input_rights, "Fallbeispiel-02.xml", $xsdName), 1, "validateRightsXML() Fallbeispiel-02.xml according to $xsdName");
throws_ok{ SLUB::LZA::SIPBuilderBagIt::save_option("move", $ie_input_path, undef, "ID-10000000_2020-01-01_20-00-00"); } qr/output path not defined/, "save_option(\$save, \$directory, \$output, \$bagNewDir), for \$save=move directory undef"; is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($input_rights, "Fallbeispiel-03.xml", $xsdName), 1, "validateRightsXML() Fallbeispiel-03.xml according to $xsdName");
throws_ok{ SLUB::LZA::SIPBuilderBagIt::save_option("copy", $ie_input_path, $ie_output_path, undef); } qr/sip root dir is not defined/, "save_option(\$save, \$directory, \$output, \$bagNewDir), bagNewDir undef"; is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($input_rights, "Fallbeispiel-04.xml", $xsdName), 1, "validateRightsXML() Fallbeispiel-04.xml according to $xsdName");
is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($input_rights, "Fallbeispiel-05.xml", $xsdName), 1, "validateRightsXML() Fallbeispiel-05.xml according to $xsdName");
is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($input_rights, "Fallbeispiel-06.xml", $xsdName), 1, "validateRightsXML() Fallbeispiel-06.xml according to $xsdName");
is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($input_rights, "Fallbeispiel-07.xml", $xsdName), 1, "validateRightsXML() Fallbeispiel-07.xml according to $xsdName");
is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($input_rights, "Fallbeispiel-08a-undef.xml", $xsdName), 1, "validateRightsXML() Fallbeispiel-08a-undef.xml according to $xsdName");
is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($input_rights, "Fallbeispiel-09.xml", $xsdName), 1, "validateRightsXML() Fallbeispiel-09.xml according to $xsdName");
is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($input_rights, "Fallbeispiel-10.xml", $xsdName), 1, "validateRightsXML() Fallbeispiel-10.xml according to $xsdName");
is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($input_rights, "Fallbeispiel-11.xml", $xsdName), 1, "validateRightsXML() Fallbeispiel-11.xml according to $xsdName");
is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($input_rights, "Fallbeispiel-12.xml", $xsdName), 1, "validateRightsXML() Fallbeispiel-12.xml according to $xsdName");
is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($input_rights, "Fallbeispiel-13.xml", $xsdName), 1, "validateRightsXML() Fallbeispiel-13.xml according to $xsdName");
is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($input_rights, "Fallbeispiel-14.xml", $xsdName), 1, "validateRightsXML() Fallbeispiel-14.xml according to $xsdName");
is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($input_rights, "Fallbeispiel-15.xml", $xsdName), 1, "validateRightsXML() Fallbeispiel-15.xml according to $xsdName");
is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($input_rights, "Fallbeispiel-16.xml", $xsdName), 1, "validateRightsXML() Fallbeispiel-16.xml according to $xsdName");
throws_ok{ SLUB::LZA::SIPBuilderBagIt::validateRightsXML(undef, $rightsName, $xsdName); } qr/metaPath to rights.xsd not defined/, "validateRightsXML(\$metaPath, \$rightsName, \$xsdName), metaPath undef";
throws_ok{ SLUB::LZA::SIPBuilderBagIt::validateRightsXML($input_metaPath, undef, $xsdName); } qr/rights name not defined/, "validateRightsXML(\$metaPath, \$rightsName, \$xsdName), rightsName undef";
throws_ok{ SLUB::LZA::SIPBuilderBagIt::validateRightsXML($input_metaPath, $rightsName, undef); } qr/xsd name not defined/, "validateRightsXML(\$metaPath, \$rightsName, \$xsdName), xsdName undef";
throws_ok{ SLUB::LZA::SIPBuilderBagIt::validateRightsXML($input_metaPath, "mods.xml", $xsdName); } qr/failed validation/, "validateRightsXML(\$metaPath, \$rightsName, \$xsdName), rights.xml is not valid according to $xsdName";
# #
is(SLUB::LZA::SIPBuilderBagIt::getPayloadFiles($ie_input_path), 2, "getPayloadFiles()"); # meta, data my $ie = 'test';
throws_ok{ SLUB::LZA::SIPBuilderBagIt::getPayloadFiles(undef); } qr/path is not defined/, "getPayloadFiles(\$import_dir), import_dir undef"; my $bag = 'test_bag';
my $valid_bag = '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;
my $data_output_path = $bag_output_path . '/data';
my $meta_output_path = $bag_output_path . '/meta';
my $valid_bag_path = $input_path . '/' . $valid_bag;
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);
#~ structure of input output folders for tests
#~ .
#~ ├── export_dir_kitodo
#~ │ └─── bagit
#~ │ └── test
#~ │ └── test.txt
#~ │
#~ └── tmp
#~ └── bagit
#~ └── test_bag
#~ ├── data
#~ │ └── test.txt
#~ └── meta
#~ ├── rights.xml
#~ └── mods.xml
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";
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";
# #
is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($ie_input_path, "Fallbeispiel-01.xml"), 1, "validateRightsXML() Fallbeispiel-01.xml");
is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($ie_input_path, "Fallbeispiel-02.xml"), 1, "validateRightsXML() Fallbeispiel-02.xml");
is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($ie_input_path, "Fallbeispiel-03.xml"), 1, "validateRightsXML() Fallbeispiel-03.xml");
is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($ie_input_path, "Fallbeispiel-04.xml"), 1, "validateRightsXML() Fallbeispiel-04.xml");
is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($ie_input_path, "Fallbeispiel-05.xml"), 1, "validateRightsXML() Fallbeispiel-05.xml");
is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($ie_input_path, "Fallbeispiel-06.xml"), 1, "validateRightsXML() Fallbeispiel-06.xml");
is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($ie_input_path, "Fallbeispiel-07.xml"), 1, "validateRightsXML() Fallbeispiel-07.xml");
is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($ie_input_path, "Fallbeispiel-08a-undef.xml"), 1, "validateRightsXML() Fallbeispiel-08a-undef.xml");
is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($ie_input_path, "Fallbeispiel-09.xml"), 1, "validateRightsXML() Fallbeispiel-09.xml");
is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($ie_input_path, "Fallbeispiel-10.xml"), 1, "validateRightsXML() Fallbeispiel-10.xml");
is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($ie_input_path, "Fallbeispiel-11.xml"), 1, "validateRightsXML() Fallbeispiel-11.xml");
is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($ie_input_path, "Fallbeispiel-12.xml"), 1, "validateRightsXML() Fallbeispiel-12.xml");
is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($ie_input_path, "Fallbeispiel-13.xml"), 1, "validateRightsXML() Fallbeispiel-13.xml");
is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($ie_input_path, "Fallbeispiel-14.xml"), 1, "validateRightsXML() Fallbeispiel-14.xml");
is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($ie_input_path, "Fallbeispiel-15.xml"), 1, "validateRightsXML() Fallbeispiel-15.xml");
is(SLUB::LZA::SIPBuilderBagIt::validateRightsXML($ie_input_path, "Fallbeispiel-16.xml"), 1, "validateRightsXML() Fallbeispiel-16.xml");
throws_ok{ SLUB::LZA::SIPBuilderBagIt::validateRightsXML(undef, "rights.xml"); } qr/ie_path to rights.xsd not defined/, "validateRightsXML(\$ie_path, \$rightsName), ie_path undef";
throws_ok{ SLUB::LZA::SIPBuilderBagIt::validateRightsXML($ie_input_path, undef); } qr/file name not defined/, "validateRightsXML(\$ie_path, \$rightsName), rightsName undef";
throws_ok{ SLUB::LZA::SIPBuilderBagIt::validateRightsXML($ie_input_path, "mods.xml"); } qr/failed validation/, "validateRightsXML(\$ie_path, \$rightsName), not valid rights.xml";
1; 1;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment