Skip to content

Commit

Permalink
bump assembly-objectfile and add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
peetucket committed Mar 16, 2021
1 parent a7f2b2e commit 838ec92
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ gem 'uglifier' # compressor for JavaScript assets

# Stanford gems
gem 'assembly-image', '~> 1.7'
gem 'assembly-objectfile', '~> 1.10'
gem 'assembly-objectfile', '~> 1.10', '>= 1.10.1' # webarchive-seed is supported in 1.10.1 and better
gem 'dor-services-client', '~> 6.27'
gem 'dor-workflow-client'
gem 'druid-tools'
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ GEM
assembly-image (1.7.7)
assembly-objectfile (>= 1.6.4)
mini_exiftool (>= 1.6, < 3)
assembly-objectfile (1.10.0)
assembly-objectfile (1.10.1)
activesupport (>= 5.2.0)
deprecation
dry-struct (~> 1.0)
Expand Down Expand Up @@ -469,7 +469,7 @@ PLATFORMS

DEPENDENCIES
assembly-image (~> 1.7)
assembly-objectfile (~> 1.10)
assembly-objectfile (~> 1.10, >= 1.10.1)
bootstrap (~> 4.3, >= 4.3.1)
capistrano-bundler
capistrano-passenger
Expand Down
104 changes: 104 additions & 0 deletions spec/lib/pre_assembly/digital_object_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,110 @@ def add_object_files(extension = 'tif', all_files_public: false)
end
end

describe 'map content metadata' do
let(:exp_xml) do
noko_doc <<-XML
<contentMetadata type="map" objectId="gn330dv6119">
<resource type="image" id="gn330dv6119_1" sequence="1">
<label>Image 1</label>
<file id="image1.jp2">
<checksum type="md5">1111</checksum>
</file>
</resource>
<resource type="image" id="gn330dv6119_2" sequence="2">
<label>Image 2</label>
<file id="image2.jp2">
<checksum type="md5">2222</checksum>
</file>
</resource>
</contentMetadata>
XML
end

let(:assembly_directory) { PreAssembly::AssemblyDirectory.new(druid_id: druid.id) }

before do
allow(object).to receive(:druid).and_return(druid)
allow(object).to receive(:object_type).and_return('')
allow(bc).to receive(:content_structure).and_return('map')
add_object_files('jp2')
allow(object).to receive(:assembly_directory).and_return(assembly_directory)
end

around do |example|
RSpec::Mocks.with_temporary_scope do
Dir.mktmpdir(*tmp_dir_args) do |tmp_area|
allow(assembly_directory).to receive(:druid_tree_dir).and_return(tmp_area)
example.run
end
end
end

it 'generates the expected xml text' do
expect(noko_doc(object.send(:create_content_metadata, false))).to be_equivalent_to exp_xml
end

it 'is able to write the content_metadata XML to a file' do
assembly_directory.create_object_directories
file_name = object.send(:assembly_directory).content_metadata_file
expect(File.exist?(file_name)).to eq(false)
object.send(:generate_content_metadata, false)
expect(noko_doc(File.read(file_name))).to be_equivalent_to exp_xml
end
end

describe 'webarchive-seed content metadata' do
let(:exp_xml) do
noko_doc <<-XML
<contentMetadata type="webarchive-seed" objectId="gn330dv6119">
<resource type="image" id="gn330dv6119_1" sequence="1">
<label>Image 1</label>
<file id="image1.jp2">
<checksum type="md5">1111</checksum>
</file>
</resource>
<resource type="image" id="gn330dv6119_2" sequence="2">
<label>Image 2</label>
<file id="image2.jp2">
<checksum type="md5">2222</checksum>
</file>
</resource>
</contentMetadata>
XML
end

let(:assembly_directory) { PreAssembly::AssemblyDirectory.new(druid_id: druid.id) }

before do
allow(object).to receive(:druid).and_return(druid)
allow(object).to receive(:object_type).and_return('')
allow(bc).to receive(:content_structure).and_return('webarchive-seed')
add_object_files('jp2')
allow(object).to receive(:assembly_directory).and_return(assembly_directory)
end

around do |example|
RSpec::Mocks.with_temporary_scope do
Dir.mktmpdir(*tmp_dir_args) do |tmp_area|
allow(assembly_directory).to receive(:druid_tree_dir).and_return(tmp_area)
example.run
end
end
end

it 'generates the expected xml text' do
expect(noko_doc(object.send(:create_content_metadata, false))).to be_equivalent_to exp_xml
end

it 'is able to write the content_metadata XML to a file' do
assembly_directory.create_object_directories
file_name = object.send(:assembly_directory).content_metadata_file
expect(File.exist?(file_name)).to eq(false)
object.send(:generate_content_metadata, false)
expect(noko_doc(File.read(file_name))).to be_equivalent_to exp_xml
end
end

describe 'grouped by filename, simple book content metadata without file attributes' do
let(:exp_xml) do
noko_doc <<-XML
Expand Down

0 comments on commit 838ec92

Please sign in to comment.