assembly-objectfile 1.11.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +14 -0
  3. data/.github/pull_request_template.md +3 -5
  4. data/.gitignore +0 -1
  5. data/.rubocop.yml +87 -15
  6. data/.rubocop_todo.yml +19 -74
  7. data/Gemfile +2 -0
  8. data/Gemfile.lock +106 -0
  9. data/README.md +1 -1
  10. data/assembly-objectfile.gemspec +5 -6
  11. data/lib/assembly-objectfile/object_file.rb +253 -3
  12. data/lib/assembly-objectfile/version.rb +2 -2
  13. data/lib/assembly-objectfile.rb +0 -5
  14. data/spec/object_file_spec.rb +411 -167
  15. data/spec/spec_helper.rb +3 -31
  16. data/spec/test_data/empty.txt +0 -0
  17. metadata +35 -121
  18. data/.travis.yml +0 -20
  19. data/lib/assembly-objectfile/content_metadata/config.rb +0 -26
  20. data/lib/assembly-objectfile/content_metadata/file.rb +0 -63
  21. data/lib/assembly-objectfile/content_metadata/file_set.rb +0 -73
  22. data/lib/assembly-objectfile/content_metadata/file_set_builder.rb +0 -65
  23. data/lib/assembly-objectfile/content_metadata/nokogiri_builder.rb +0 -57
  24. data/lib/assembly-objectfile/content_metadata.rb +0 -117
  25. data/lib/assembly-objectfile/object_fileable.rb +0 -278
  26. data/spec/content_metadata_spec.rb +0 -791
  27. data/spec/test_data/input/oo000oo0001/00/oo000oo0001_00_001.tif +0 -0
  28. data/spec/test_data/input/oo000oo0001/00/oo000oo0001_00_002.tif +0 -0
  29. data/spec/test_data/input/oo000oo0001/05/oo000oo0001_05_001.jp2 +0 -0
  30. data/spec/test_data/input/oo000oo0001/05/oo000oo0001_05_002.jp2 +0 -0
  31. data/spec/test_data/input/oo000oo0001/15/oo000oo0001_15_001.pdf +0 -1
  32. data/spec/test_data/input/oo000oo0001/15/oo000oo0001_15_002.pdf +0 -1
  33. data/spec/test_data/input/oo000oo0001/31/oo000oo0001_31_001.pdf +0 -1
  34. data/spec/test_data/input/oo000oo0001/50/oo000oo0001_50_001.tif +0 -0
  35. data/spec/test_data/input/oo000oo0001/oo000oo0001_book.pdf +0 -1
  36. data/spec/test_data/input/res1_image1.jp2 +0 -0
  37. data/spec/test_data/input/res1_image2.jp2 +0 -0
  38. data/spec/test_data/input/res1_image2.tif +0 -0
  39. data/spec/test_data/input/res1_teifile.txt +0 -1
  40. data/spec/test_data/input/res2_image1.jp2 +0 -0
  41. data/spec/test_data/input/res2_image1.tif +0 -0
  42. data/spec/test_data/input/res2_image2.jp2 +0 -0
  43. data/spec/test_data/input/res2_image2.tif +0 -0
  44. data/spec/test_data/input/res2_teifile.txt +0 -1
  45. data/spec/test_data/input/res2_textfile.txt +0 -1
  46. data/spec/test_data/input/res3_image1.jp2 +0 -0
  47. data/spec/test_data/input/res3_image1.tif +0 -0
  48. data/spec/test_data/input/res3_teifile.txt +0 -1
  49. data/spec/test_data/input/test.pdf +0 -1
  50. data/spec/test_data/input/test2.jp2 +0 -0
  51. data/spec/test_data/input/test2.tif +0 -0
@@ -1,791 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe Assembly::ContentMetadata do
6
- describe '#create_content_metadata' do
7
- subject(:result) { described_class.create_content_metadata(druid: TEST_DRUID, style: style, objects: objects) }
8
-
9
- let(:xml) { Nokogiri::XML(result) }
10
-
11
- context 'when style=simple_image' do
12
- context 'when using a single tif and jp2' do
13
- it 'generates valid content metadata with exif, adding file attributes' do
14
- objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE), Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE)]
15
- result = described_class.create_content_metadata(druid: TEST_DRUID, add_exif: true, add_file_attributes: true, objects: objects)
16
- expect(result.class).to be String
17
- xml = Nokogiri::XML(result)
18
- expect(xml.errors.size).to eq 0
19
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
20
- expect(xml.xpath('//resource').length).to eq 2
21
- expect(xml.xpath('//resource/file').length).to eq 2
22
- expect(xml.xpath('//resource/file/checksum').length).to eq 4
23
- expect(xml.xpath('//resource/file/checksum')[0].text).to eq('8d11fab63089a24c8b17063d29a4b0eac359fb41')
24
- expect(xml.xpath('//resource/file/checksum')[1].text).to eq('a2400500acf21e43f5440d93be894101')
25
- expect(xml.xpath('//resource/file/checksum')[2].text).to eq('b965b5787e0100ec2d43733144120feab327e88c')
26
- expect(xml.xpath('//resource/file/checksum')[3].text).to eq('4eb54050d374291ece622d45e84f014d')
27
- expect(xml.xpath('//label').length).to eq 2
28
- expect(xml.xpath('//label')[0].text).to match(/Image 1/)
29
- expect(xml.xpath('//label')[1].text).to match(/Image 2/)
30
- expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('image')
31
- expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('image')
32
- expect(xml.xpath('//resource/file')[0].attributes['size'].value).to eq('63542')
33
- expect(xml.xpath('//resource/file')[0].attributes['mimetype'].value).to eq('image/tiff')
34
- expect(xml.xpath('//resource/file')[0].attributes['publish'].value).to eq('no')
35
- expect(xml.xpath('//resource/file')[0].attributes['preserve'].value).to eq('yes')
36
- expect(xml.xpath('//resource/file')[0].attributes['shelve'].value).to eq('no')
37
- expect(xml.xpath('//resource/file/imageData')[0].attributes['width'].value).to eq('100')
38
- expect(xml.xpath('//resource/file/imageData')[0].attributes['height'].value).to eq('100')
39
- expect(xml.xpath('//resource/file')[1].attributes['size'].value).to eq('306')
40
- expect(xml.xpath('//resource/file')[1].attributes['mimetype'].value).to eq('image/jp2')
41
- expect(xml.xpath('//resource/file')[1].attributes['publish'].value).to eq('yes')
42
- expect(xml.xpath('//resource/file')[1].attributes['preserve'].value).to eq('no')
43
- expect(xml.xpath('//resource/file')[1].attributes['shelve'].value).to eq('yes')
44
- expect(xml.xpath('//resource/file/imageData')[1].attributes['width'].value).to eq('100')
45
- expect(xml.xpath('//resource/file/imageData')[1].attributes['height'].value).to eq('100')
46
- end
47
- end
48
-
49
- context 'when using a single tif and jp2' do
50
- it 'generates valid content metadata with no exif adding specific file attributes for 2 objects, and defaults for 1 object' do
51
- obj1 = Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE)
52
- obj2 = Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE)
53
- obj3 = Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE2)
54
- obj1.file_attributes = { publish: 'no', preserve: 'no', shelve: 'no' }
55
- obj2.file_attributes = { publish: 'yes', preserve: 'yes', shelve: 'yes' }
56
- objects = [obj1, obj2, obj3]
57
- result = described_class.create_content_metadata(druid: TEST_DRUID, add_exif: false, add_file_attributes: true, objects: objects)
58
- expect(result.class).to be String
59
- xml = Nokogiri::XML(result)
60
- expect(xml.errors.size).to eq 0
61
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
62
- expect(xml.xpath('//resource').length).to eq 3
63
- expect(xml.xpath('//resource/file').length).to eq 3
64
- expect(xml.xpath('//resource/file/checksum').length).to eq 0
65
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
66
- expect(xml.xpath('//label').length).to eq 3
67
- expect(xml.xpath('//label')[0].text).to match(/Image 1/)
68
- expect(xml.xpath('//label')[1].text).to match(/Image 2/)
69
- expect(xml.xpath('//label')[2].text).to match(/Image 3/)
70
- expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('image')
71
- expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('image')
72
- expect(xml.xpath('//resource')[2].attributes['type'].value).to eq('image')
73
- expect(xml.xpath('//resource/file')[0].attributes['publish'].value).to eq('no') # specificially set in object
74
- expect(xml.xpath('//resource/file')[0].attributes['preserve'].value).to eq('no') # specificially set in object
75
- expect(xml.xpath('//resource/file')[0].attributes['shelve'].value).to eq('no') # specificially set in object
76
- expect(xml.xpath('//resource/file')[1].attributes['publish'].value).to eq('yes') # specificially set in object
77
- expect(xml.xpath('//resource/file')[1].attributes['preserve'].value).to eq('yes') # specificially set in object
78
- expect(xml.xpath('//resource/file')[1].attributes['shelve'].value).to eq('yes') # specificially set in object
79
- expect(xml.xpath('//resource/file')[2].attributes['publish'].value).to eq('yes') # defaults by mimetype
80
- expect(xml.xpath('//resource/file')[2].attributes['preserve'].value).to eq('no') # defaults by mimetype
81
- expect(xml.xpath('//resource/file')[2].attributes['shelve'].value).to eq('yes') # defaults by mimetype
82
- end
83
- end
84
-
85
- context 'when using a single tif and jp2' do
86
- it 'generates valid content metadata with exif, overriding file labels' do
87
- objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE, label: 'Sample tif label!'), Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE, label: 'Sample jp2 label!')]
88
- result = described_class.create_content_metadata(druid: TEST_DRUID, add_exif: true, add_file_attributes: true, objects: objects)
89
- expect(result.class).to be String
90
- xml = Nokogiri::XML(result)
91
- expect(xml.errors.size).to eq 0
92
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
93
- expect(xml.xpath('//resource').length).to eq 2
94
- expect(xml.xpath('//resource/file').length).to eq 2
95
- expect(xml.xpath('//resource/file/checksum').length).to eq 4
96
- expect(xml.xpath('//resource/file/checksum')[0].text).to eq('8d11fab63089a24c8b17063d29a4b0eac359fb41')
97
- expect(xml.xpath('//resource/file/checksum')[1].text).to eq('a2400500acf21e43f5440d93be894101')
98
- expect(xml.xpath('//resource/file/checksum')[2].text).to eq('b965b5787e0100ec2d43733144120feab327e88c')
99
- expect(xml.xpath('//resource/file/checksum')[3].text).to eq('4eb54050d374291ece622d45e84f014d')
100
- expect(xml.xpath('//label').length).to eq 2
101
- expect(xml.xpath('//label')[0].text).to match(/Sample tif label!/)
102
- expect(xml.xpath('//label')[1].text).to match(/Sample jp2 label!/)
103
- expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('image')
104
- expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('image')
105
- expect(xml.xpath('//resource/file')[0].attributes['size'].value).to eq('63542')
106
- expect(xml.xpath('//resource/file')[0].attributes['mimetype'].value).to eq('image/tiff')
107
- expect(xml.xpath('//resource/file')[0].attributes['publish'].value).to eq('no')
108
- expect(xml.xpath('//resource/file')[0].attributes['preserve'].value).to eq('yes')
109
- expect(xml.xpath('//resource/file')[0].attributes['shelve'].value).to eq('no')
110
- expect(xml.xpath('//resource/file/imageData')[0].attributes['width'].value).to eq('100')
111
- expect(xml.xpath('//resource/file/imageData')[0].attributes['height'].value).to eq('100')
112
- expect(xml.xpath('//resource/file')[1].attributes['size'].value).to eq('306')
113
- expect(xml.xpath('//resource/file')[1].attributes['mimetype'].value).to eq('image/jp2')
114
- expect(xml.xpath('//resource/file')[1].attributes['publish'].value).to eq('yes')
115
- expect(xml.xpath('//resource/file')[1].attributes['preserve'].value).to eq('no')
116
- expect(xml.xpath('//resource/file')[1].attributes['shelve'].value).to eq('yes')
117
- expect(xml.xpath('//resource/file/imageData')[1].attributes['width'].value).to eq('100')
118
- expect(xml.xpath('//resource/file/imageData')[1].attributes['height'].value).to eq('100')
119
- end
120
- end
121
-
122
- context 'when using a single tif and jp2' do
123
- it 'generates valid content metadata with exif, overriding file labels for one, and skipping auto labels for the others or for where the label is set but is blank' do
124
- objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE, label: 'Sample tif label!'), Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE), Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE, label: '')]
125
- result = described_class.create_content_metadata(druid: TEST_DRUID, auto_labels: false, add_file_attributes: true, objects: objects)
126
- expect(result.class).to be String
127
- xml = Nokogiri::XML(result)
128
- expect(xml.errors.size).to eq 0
129
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
130
- expect(xml.xpath('//resource').length).to eq 3
131
- expect(xml.xpath('//resource/file').length).to eq 3
132
- expect(xml.xpath('//label').length).to eq 1
133
- expect(xml.xpath('//label')[0].text).to match(/Sample tif label!/)
134
- end
135
- end
136
-
137
- context 'when using a single tif and jp2' do
138
- it 'generates valid content metadata with overriding file attributes and no exif data' do
139
- objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE), Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE)]
140
- result = described_class.create_content_metadata(druid: TEST_DRUID, add_file_attributes: true, file_attributes: { 'image/tiff' => { publish: 'no', preserve: 'no', shelve: 'no' }, 'image/jp2' => { publish: 'yes', preserve: 'yes', shelve: 'yes' } }, objects: objects)
141
- expect(result.class).to be String
142
- xml = Nokogiri::XML(result)
143
- expect(xml.errors.size).to eq 0
144
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
145
- expect(xml.xpath('//resource').length).to eq 2
146
- expect(xml.xpath('//resource/file').length).to eq 2
147
- expect(xml.xpath('//label').length).to eq 2
148
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
149
- expect(xml.xpath('//label')[0].text).to match(/Image 1/)
150
- expect(xml.xpath('//label')[1].text).to match(/Image 2/)
151
- expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('image')
152
- expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('image')
153
- expect(xml.xpath('//resource/file')[0].attributes['size']).to be_nil
154
- expect(xml.xpath('//resource/file')[0].attributes['mimetype']).to be_nil
155
- expect(xml.xpath('//resource/file')[0].attributes['role']).to be_nil
156
- expect(xml.xpath('//resource/file')[0].attributes['publish'].value).to eq('no')
157
- expect(xml.xpath('//resource/file')[0].attributes['preserve'].value).to eq('no')
158
- expect(xml.xpath('//resource/file')[0].attributes['shelve'].value).to eq('no')
159
- expect(xml.xpath('//resource/file')[1].attributes['size']).to be_nil
160
- expect(xml.xpath('//resource/file')[1].attributes['mimetype']).to be_nil
161
- expect(xml.xpath('//resource/file')[1].attributes['role']).to be_nil
162
- expect(xml.xpath('//resource/file')[1].attributes['publish'].value).to eq('yes')
163
- expect(xml.xpath('//resource/file')[1].attributes['preserve'].value).to eq('yes')
164
- expect(xml.xpath('//resource/file')[1].attributes['shelve'].value).to eq('yes')
165
- end
166
- end
167
-
168
- context 'when using a single tif and jp2' do
169
- it 'generates valid content metadata with overriding file attributes, including a default value, and no exif data' do
170
- objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE), Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE)]
171
- result = described_class.create_content_metadata(druid: TEST_DRUID, add_file_attributes: true, file_attributes: { 'default' => { publish: 'yes', preserve: 'no', shelve: 'no' }, 'image/jp2' => { publish: 'yes', preserve: 'yes', shelve: 'yes' } }, objects: objects)
172
- expect(result.class).to be String
173
- xml = Nokogiri::XML(result)
174
- expect(xml.errors.size).to eq 0
175
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
176
- expect(xml.xpath('//resource/file').length).to eq 2
177
- expect(xml.xpath('//resource/file')[0].attributes['mimetype']).to be_nil
178
- expect(xml.xpath('//resource/file')[0].attributes['publish'].value).to eq('yes')
179
- expect(xml.xpath('//resource/file')[0].attributes['preserve'].value).to eq('no')
180
- expect(xml.xpath('//resource/file')[0].attributes['shelve'].value).to eq('no')
181
- expect(xml.xpath('//resource/file')[1].attributes['mimetype']).to be_nil
182
- expect(xml.xpath('//resource/file')[1].attributes['publish'].value).to eq('yes')
183
- expect(xml.xpath('//resource/file')[1].attributes['preserve'].value).to eq('yes')
184
- expect(xml.xpath('//resource/file')[1].attributes['shelve'].value).to eq('yes')
185
- (0..1).each do |i|
186
- expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 1
187
- expect(xml.xpath('//label')[i].text).to eq("Image #{i + 1}")
188
- expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('image')
189
- end
190
- end
191
- end
192
-
193
- context 'when using two tifs and two associated jp2s using bundle=filename' do
194
- it 'generates valid content metadata and no exif data' do
195
- objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE), Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE), Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE2), Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE2)]
196
- result = described_class.create_content_metadata(druid: TEST_DRUID, bundle: :filename, objects: objects)
197
- expect(result.class).to be String
198
- xml = Nokogiri::XML(result)
199
- expect(xml.errors.size).to eq 0
200
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
201
- expect(xml.xpath('//resource').length).to eq 2
202
- expect(xml.xpath('//resource/file').length).to eq 4
203
- expect(xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value).to eq('test.tif')
204
- expect(xml.xpath("//resource[@sequence='1']/file")[1].attributes['id'].value).to eq('test.jp2')
205
- expect(xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value).to eq('test2.tif')
206
- expect(xml.xpath("//resource[@sequence='2']/file")[1].attributes['id'].value).to eq('test2.jp2')
207
- expect(xml.xpath('//label').length).to eq 2
208
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
209
- (0..1).each do |i|
210
- expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 2
211
- expect(xml.xpath('//label')[i].text).to eq("Image #{i + 1}")
212
- expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('image')
213
- end
214
- end
215
- end
216
-
217
- context 'when using two tifs and two associated jp2s using bundle=dpg' do
218
- it 'generates valid content metadata and no exif data and no root xml node' do
219
- objects = [Assembly::ObjectFile.new(TEST_DPG_TIF), Assembly::ObjectFile.new(TEST_DPG_JP), Assembly::ObjectFile.new(TEST_DPG_TIF2), Assembly::ObjectFile.new(TEST_DPG_JP2)]
220
- test_druid = TEST_DRUID.to_s
221
- result = described_class.create_content_metadata(druid: test_druid, bundle: :dpg, objects: objects, include_root_xml: false)
222
- expect(result.class).to be String
223
- expect(result.include?('<?xml')).to be false
224
- xml = Nokogiri::XML(result)
225
- expect(xml.errors.size).to eq 0
226
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
227
- expect(test_druid).to eq(TEST_DRUID)
228
- expect(xml.xpath('//contentMetadata')[0].attributes['objectId'].value).to eq(TEST_DRUID.to_s)
229
- expect(xml.xpath('//resource').length).to eq 2
230
- expect(xml.xpath('//resource/file').length).to eq 4
231
- expect(xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value).to eq('00/oo000oo0001_00_001.tif')
232
- expect(xml.xpath("//resource[@sequence='1']/file")[1].attributes['id'].value).to eq('05/oo000oo0001_05_001.jp2')
233
- expect(xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value).to eq('00/oo000oo0001_00_002.tif')
234
- expect(xml.xpath("//resource[@sequence='2']/file")[1].attributes['id'].value).to eq('05/oo000oo0001_05_002.jp2')
235
- expect(xml.xpath('//label').length).to eq 2
236
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
237
- (0..1).each do |i|
238
- expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 2
239
- expect(xml.xpath('//label')[i].text).to eq("Image #{i + 1}")
240
- expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('image')
241
- end
242
- end
243
- end
244
-
245
- context 'when using two tifs and two associated jp2s using bundle=default' do
246
- it 'generates valid content metadata and no exif data' do
247
- objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE), Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE), Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE2), Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE2)]
248
- result = described_class.create_content_metadata(druid: TEST_DRUID, bundle: :default, objects: objects)
249
- expect(result.class).to be String
250
- xml = Nokogiri::XML(result)
251
- expect(xml.errors.size).to eq 0
252
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
253
- expect(xml.xpath('//resource').length).to eq 4
254
- expect(xml.xpath('//resource/file').length).to eq 4
255
- expect(xml.xpath('//resource/file')[0].attributes['id'].value).to eq('test.tif')
256
- expect(xml.xpath('//resource/file')[1].attributes['id'].value).to eq('test.jp2')
257
- expect(xml.xpath('//resource/file')[2].attributes['id'].value).to eq('test2.tif')
258
- expect(xml.xpath('//resource/file')[3].attributes['id'].value).to eq('test2.jp2')
259
- expect(xml.xpath('//label').length).to eq 4
260
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
261
- (0..3).each do |i|
262
- expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 1
263
- expect(xml.xpath('//label')[i].text).to eq("Image #{i + 1}")
264
- expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('image')
265
- end
266
- end
267
- end
268
-
269
- context 'when using two tifs and two associated jp2s using bundle=default' do
270
- it 'generates valid content metadata and no exif data, preserving full paths' do
271
- objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE), Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE), Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE2), Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE2)]
272
- result = described_class.create_content_metadata(druid: TEST_DRUID, bundle: :default, objects: objects, preserve_common_paths: true)
273
- expect(result.class).to be String
274
- xml = Nokogiri::XML(result)
275
- expect(xml.errors.size).to eq 0
276
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
277
- expect(xml.xpath('//resource').length).to eq 4
278
- expect(xml.xpath('//resource/file').length).to eq 4
279
- expect(xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value).to eq(TEST_TIF_INPUT_FILE)
280
- expect(xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value).to eq(TEST_JP2_INPUT_FILE)
281
- expect(xml.xpath("//resource[@sequence='3']/file")[0].attributes['id'].value).to eq(TEST_TIF_INPUT_FILE2)
282
- expect(xml.xpath("//resource[@sequence='4']/file")[0].attributes['id'].value).to eq(TEST_JP2_INPUT_FILE2)
283
- expect(xml.xpath('//label').length).to eq 4
284
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
285
- (0..3).each do |i|
286
- expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 1
287
- expect(xml.xpath('//label')[i].text).to eq("Image #{i + 1}")
288
- expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('image')
289
- end
290
- end
291
- end
292
-
293
- context 'when using bundle=prebundled' do
294
- it 'generates valid content metadata for images and associated text files and no exif data' do
295
- files = [[TEST_RES1_TIF1, TEST_RES1_JP1, TEST_RES1_TIF2, TEST_RES1_JP2, TEST_RES1_TEI, TEST_RES1_TEXT, TEST_RES1_PDF], [TEST_RES2_TIF1, TEST_RES2_JP1, TEST_RES2_TIF2, TEST_RES2_JP2, TEST_RES2_TEI, TEST_RES2_TEXT], [TEST_RES3_TIF1, TEST_RES3_JP1, TEST_RES3_TEI]]
296
- objects = files.collect { |resource| resource.collect { |file| Assembly::ObjectFile.new(file) } }
297
- result = described_class.create_content_metadata(druid: TEST_DRUID, bundle: :prebundled, style: :simple_image, objects: objects)
298
- expect(result.class).to be String
299
- xml = Nokogiri::XML(result)
300
- expect(xml.errors.size).to eq 0
301
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
302
- expect(xml.xpath('//resource').length).to eq 3
303
- expect(xml.xpath('//resource/file').length).to eq 16
304
- expect(xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value).to eq('res1_image1.tif')
305
- expect(xml.xpath("//resource[@sequence='1']/file")[1].attributes['id'].value).to eq('res1_image1.jp2')
306
- expect(xml.xpath("//resource[@sequence='1']/file")[2].attributes['id'].value).to eq('res1_image2.tif')
307
- expect(xml.xpath("//resource[@sequence='1']/file")[3].attributes['id'].value).to eq('res1_image2.jp2')
308
- expect(xml.xpath("//resource[@sequence='1']/file")[4].attributes['id'].value).to eq('res1_teifile.txt')
309
- expect(xml.xpath("//resource[@sequence='1']/file")[5].attributes['id'].value).to eq('res1_textfile.txt')
310
- expect(xml.xpath("//resource[@sequence='1']/file")[6].attributes['id'].value).to eq('res1_transcript.pdf')
311
- expect(xml.xpath("//resource[@sequence='1']/file").length).to be 7
312
-
313
- expect(xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value).to eq('res2_image1.tif')
314
- expect(xml.xpath("//resource[@sequence='2']/file")[1].attributes['id'].value).to eq('res2_image1.jp2')
315
- expect(xml.xpath("//resource[@sequence='2']/file")[2].attributes['id'].value).to eq('res2_image2.tif')
316
- expect(xml.xpath("//resource[@sequence='2']/file")[3].attributes['id'].value).to eq('res2_image2.jp2')
317
- expect(xml.xpath("//resource[@sequence='2']/file")[4].attributes['id'].value).to eq('res2_teifile.txt')
318
- expect(xml.xpath("//resource[@sequence='2']/file")[5].attributes['id'].value).to eq('res2_textfile.txt')
319
- expect(xml.xpath("//resource[@sequence='2']/file").length).to eq 6
320
-
321
- expect(xml.xpath("//resource[@sequence='3']/file")[0].attributes['id'].value).to eq('res3_image1.tif')
322
- expect(xml.xpath("//resource[@sequence='3']/file")[1].attributes['id'].value).to eq('res3_image1.jp2')
323
- expect(xml.xpath("//resource[@sequence='3']/file")[2].attributes['id'].value).to eq('res3_teifile.txt')
324
- expect(xml.xpath("//resource[@sequence='3']/file").length).to eq 3
325
-
326
- expect(xml.xpath('//label').length).to eq 3
327
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
328
- (0..2).each do |i|
329
- expect(xml.xpath('//label')[i].text).to eq("Image #{i + 1}")
330
- expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('image')
331
- end
332
- end
333
- end
334
- end
335
-
336
- context 'when style=webarchive-seed' do
337
- context 'when using a jp2' do
338
- it 'generates valid content metadata with exif, adding file attributes' do
339
- objects = [Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE)]
340
- result = described_class.create_content_metadata(style: :'webarchive-seed', druid: TEST_DRUID, add_exif: true, add_file_attributes: true, objects: objects)
341
- expect(result.class).to be String
342
- xml = Nokogiri::XML(result)
343
- expect(xml.errors.size).to eq 0
344
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('webarchive-seed')
345
- expect(xml.xpath('//bookData').length).to eq 0
346
- expect(xml.xpath('//resource').length).to eq 1
347
- expect(xml.xpath('//resource/file').length).to eq 1
348
- expect(xml.xpath('//resource/file/checksum').length).to eq 2
349
- expect(xml.xpath('//resource/file/checksum')[0].text).to eq('b965b5787e0100ec2d43733144120feab327e88c')
350
- expect(xml.xpath('//resource/file/checksum')[1].text).to eq('4eb54050d374291ece622d45e84f014d')
351
- expect(xml.xpath('//label').length).to eq 1
352
- expect(xml.xpath('//label')[0].text).to match(/Image 1/)
353
- expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('image')
354
- expect(xml.xpath('//resource/file')[0].attributes['size'].value).to eq('306')
355
- expect(xml.xpath('//resource/file')[0].attributes['mimetype'].value).to eq('image/jp2')
356
- expect(xml.xpath('//resource/file')[0].attributes['publish'].value).to eq('yes')
357
- expect(xml.xpath('//resource/file')[0].attributes['preserve'].value).to eq('no')
358
- expect(xml.xpath('//resource/file')[0].attributes['shelve'].value).to eq('yes')
359
- expect(xml.xpath('//resource/file/imageData')[0].attributes['width'].value).to eq('100')
360
- expect(xml.xpath('//resource/file/imageData')[0].attributes['height'].value).to eq('100')
361
- end
362
- end
363
- end
364
-
365
- context 'when style=map' do
366
- context 'when using a single tif and jp2' do
367
- it 'generates valid content metadata with overriding file attributes, including a default value, and no exif data' do
368
- objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE), Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE)]
369
- result = described_class.create_content_metadata(style: :map,
370
- druid: TEST_DRUID,
371
- add_file_attributes: true,
372
- file_attributes: { 'default' => { publish: 'yes', preserve: 'no', shelve: 'no' },
373
- 'image/jp2' => { publish: 'yes', preserve: 'yes', shelve: 'yes' } },
374
- objects: objects)
375
- expect(result.class).to be String
376
- xml = Nokogiri::XML(result)
377
- expect(xml.errors.size).to eq 0
378
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('map')
379
- expect(xml.xpath('//bookData').length).to eq 0
380
- expect(xml.xpath('//resource/file').length).to eq 2
381
- expect(xml.xpath('//resource/file')[0].attributes['mimetype']).to be_nil
382
- expect(xml.xpath('//resource/file')[0].attributes['publish'].value).to eq('yes')
383
- expect(xml.xpath('//resource/file')[0].attributes['preserve'].value).to eq('no')
384
- expect(xml.xpath('//resource/file')[0].attributes['shelve'].value).to eq('no')
385
- expect(xml.xpath('//resource/file')[1].attributes['mimetype']).to be_nil
386
- expect(xml.xpath('//resource/file')[1].attributes['publish'].value).to eq('yes')
387
- expect(xml.xpath('//resource/file')[1].attributes['preserve'].value).to eq('yes')
388
- expect(xml.xpath('//resource/file')[1].attributes['shelve'].value).to eq('yes')
389
- (0..1).each do |i|
390
- expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 1
391
- expect(xml.xpath('//label')[i].text).to eq("Image #{i + 1}")
392
- expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('image')
393
- end
394
- end
395
- end
396
- end
397
-
398
- context 'when style=simple_book' do
399
- context 'when using two tifs, two associated jp2s, one combined pdf and one special tif using bundle=dpg' do
400
- it 'generates valid content metadata and no exif data and no root xml node, flattening folder structure' do
401
- objects = [Assembly::ObjectFile.new(TEST_DPG_SPECIAL_PDF2), Assembly::ObjectFile.new(TEST_DPG_SPECIAL_TIF), Assembly::ObjectFile.new(TEST_DPG_TIF), Assembly::ObjectFile.new(TEST_DPG_JP), Assembly::ObjectFile.new(TEST_DPG_TIF2), Assembly::ObjectFile.new(TEST_DPG_JP2)]
402
- result = described_class.create_content_metadata(druid: TEST_DRUID, style: :simple_book, bundle: :dpg, objects: objects, include_root_xml: false, flatten_folder_structure: true)
403
- expect(result.class).to be String
404
- expect(result.include?('<?xml')).to be false
405
- xml = Nokogiri::XML(result)
406
- expect(xml.errors.size).to eq 0
407
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('book')
408
- expect(xml.xpath('//contentMetadata')[0].attributes['objectId'].value).to eq(TEST_DRUID.to_s)
409
- expect(xml.xpath('//bookData')[0].attributes['readingOrder'].value).to eq('ltr')
410
- expect(xml.xpath('//resource').length).to eq 4
411
- expect(xml.xpath('//resource/file').length).to eq 6
412
- expect(xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value).to eq('oo000oo0001_00_001.tif')
413
- expect(xml.xpath("//resource[@sequence='1']/file")[1].attributes['id'].value).to eq('oo000oo0001_05_001.jp2')
414
- expect(xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value).to eq('oo000oo0001_00_002.tif')
415
- expect(xml.xpath("//resource[@sequence='2']/file")[1].attributes['id'].value).to eq('oo000oo0001_05_002.jp2')
416
- expect(xml.xpath("//resource[@sequence='3']/file")[0].attributes['id'].value).to eq('oo000oo0001_31_001.pdf')
417
- expect(xml.xpath("//resource[@sequence='4']/file")[0].attributes['id'].value).to eq('oo000oo0001_50_001.tif')
418
- expect(xml.xpath('//label').length).to eq 4
419
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
420
- (0..1).each do |i|
421
- expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 2
422
- expect(xml.xpath('//label')[i].text).to eq("Page #{i + 1}")
423
- expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('page')
424
- end
425
- expect(xml.xpath("//resource[@sequence='3']/file").length).to eq 1
426
- expect(xml.xpath('//label')[2].text).to eq('Object 1')
427
- expect(xml.xpath('//resource')[2].attributes['type'].value).to eq('object')
428
- expect(xml.xpath("//resource[@sequence='4']/file").length).to eq 1
429
- expect(xml.xpath('//label')[3].text).to eq('Object 2')
430
- expect(xml.xpath('//resource')[3].attributes['type'].value).to eq('object')
431
- end
432
- end
433
-
434
- context "when item has a 'druid:' prefix and specified book order. Using two tifs, two associated jp2s, two associated pdfs and one lingering PDF using bundle=dpg" do
435
- it 'generates valid content metadata with flattening folder structure' do
436
- objects = [Assembly::ObjectFile.new(TEST_DPG_TIF), Assembly::ObjectFile.new(TEST_DPG_JP),
437
- Assembly::ObjectFile.new(TEST_DPG_PDF), Assembly::ObjectFile.new(TEST_DPG_TIF2),
438
- Assembly::ObjectFile.new(TEST_DPG_JP2), Assembly::ObjectFile.new(TEST_DPG_PDF2),
439
- Assembly::ObjectFile.new(TEST_DPG_SPECIAL_PDF1)]
440
- test_druid = "druid:#{TEST_DRUID}"
441
- result = described_class.create_content_metadata(druid: test_druid, bundle: :dpg, objects: objects, style: :simple_book, flatten_folder_structure: true, reading_order: 'rtl')
442
- expect(result.class).to be String
443
- expect(result.include?('<?xml')).to be true
444
- xml = Nokogiri::XML(result)
445
- expect(xml.errors.size).to eq 0
446
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('book')
447
- expect(xml.xpath('//contentMetadata')[0].attributes['objectId'].value).to eq(test_druid)
448
- expect(xml.xpath('//bookData')[0].attributes['readingOrder'].value).to eq('rtl')
449
- expect(test_druid).to eq("druid:#{TEST_DRUID}")
450
- expect(xml.xpath('//resource').length).to eq 3
451
- expect(xml.xpath('//resource/file').length).to be 7
452
-
453
- expect(xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value).to eq('oo000oo0001_00_001.tif')
454
- expect(xml.xpath("//resource[@sequence='1']/file")[1].attributes['id'].value).to eq('oo000oo0001_05_001.jp2')
455
- expect(xml.xpath("//resource[@sequence='1']/file")[2].attributes['id'].value).to eq('oo000oo0001_15_001.pdf')
456
- expect(xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value).to eq('oo000oo0001_00_002.tif')
457
- expect(xml.xpath("//resource[@sequence='2']/file")[1].attributes['id'].value).to eq('oo000oo0001_05_002.jp2')
458
- expect(xml.xpath("//resource[@sequence='2']/file")[2].attributes['id'].value).to eq('oo000oo0001_15_002.pdf')
459
- expect(xml.xpath("//resource[@sequence='3']/file")[0].attributes['id'].value).to eq('oo000oo0001_book.pdf')
460
- expect(xml.xpath('//label').length).to eq 3
461
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
462
- (0..1).each do |i|
463
- expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 3
464
- expect(xml.xpath('//label')[i].text).to eq("Page #{i + 1}")
465
- expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('page')
466
- end
467
- expect(xml.xpath("//resource[@sequence='3']/file").length).to eq 1
468
- expect(xml.xpath('//label')[2].text).to eq('Object 1')
469
- expect(xml.xpath('//resource')[2].attributes['type'].value).to eq('object')
470
- end
471
- end
472
-
473
- context 'throws an error with invalid reading order' do
474
- subject(:result) { described_class.create_content_metadata(druid: "druid:#{TEST_DRUID}", bundle: :dpg, objects: [], style: :simple_book, flatten_folder_structure: true, reading_order: 'bogus') }
475
-
476
- it 'generates valid content metadata with flattening folder structure' do
477
- expect { result }.to raise_error(Dry::Struct::Error)
478
- end
479
- end
480
-
481
- context 'when using two tifs' do
482
- it 'generates valid content metadata for two tifs of style=simple_book' do
483
- objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE), Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE2)]
484
- result = described_class.create_content_metadata(druid: TEST_DRUID, style: :simple_book, objects: objects)
485
- expect(result.class).to be String
486
- xml = Nokogiri::XML(result)
487
- expect(xml.errors.size).to eq 0
488
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('book')
489
- expect(xml.xpath('//resource').length).to eq 2
490
- expect(xml.xpath('//resource/file').length).to eq 2
491
- expect(xml.xpath('//label').length).to eq 2
492
- expect(xml.xpath('//label')[0].text).to match(/Page 1/)
493
- expect(xml.xpath('//label')[1].text).to match(/Page 2/)
494
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
495
- (0..1).each do |i|
496
- expect(xml.xpath('//resource/file')[i].attributes['size']).to be_nil
497
- expect(xml.xpath('//resource/file')[i].attributes['mimetype']).to be_nil
498
- expect(xml.xpath('//resource/file')[i].attributes['publish']).to be_nil
499
- expect(xml.xpath('//resource/file')[i].attributes['preserve']).to be_nil
500
- expect(xml.xpath('//resource/file')[i].attributes['shelve']).to be_nil
501
- end
502
- expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('page')
503
- expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('page')
504
- end
505
- end
506
- end
507
-
508
- context 'when style=book_with_pdf' do
509
- context 'when using two tiffs and a pdf' do
510
- let(:objects) do
511
- [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE),
512
- Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE2),
513
- Assembly::ObjectFile.new(TEST_PDF_FILE)]
514
- end
515
- let(:style) { :book_with_pdf }
516
-
517
- before do
518
- allow(Deprecation).to receive(:warn)
519
- end
520
-
521
- it 'generates valid content metadata for two tifs' do
522
- expect(xml.errors.size).to eq 0
523
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('book')
524
- expect(xml.xpath('//resource').length).to eq 3
525
- expect(xml.xpath('//resource/file').length).to eq 3
526
- expect(xml.xpath('//label').length).to eq 3
527
- expect(xml.xpath('//label')[0].text).to match(/Page 1/)
528
- expect(xml.xpath('//label')[1].text).to match(/Page 2/)
529
- expect(xml.xpath('//label')[2].text).to match(/Object 1/)
530
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
531
- expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('page')
532
- expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('page')
533
- expect(xml.xpath('//resource')[2].attributes['type'].value).to eq('object')
534
- end
535
- end
536
-
537
- context 'when using two tifs, two associated jp2s, two associated pdfs and one lingering PDF using bundle=dpg' do
538
- subject(:result) { described_class.create_content_metadata(druid: TEST_DRUID, bundle: :dpg, style: style, objects: objects) }
539
-
540
- let(:objects) do
541
- [
542
- Assembly::ObjectFile.new(TEST_DPG_TIF),
543
- Assembly::ObjectFile.new(TEST_DPG_JP),
544
- Assembly::ObjectFile.new(TEST_DPG_PDF),
545
- Assembly::ObjectFile.new(TEST_DPG_TIF2),
546
- Assembly::ObjectFile.new(TEST_DPG_JP2),
547
- Assembly::ObjectFile.new(TEST_DPG_SPECIAL_PDF1)
548
- ]
549
- end
550
- let(:style) { :book_with_pdf }
551
-
552
- before do
553
- allow(Deprecation).to receive(:warn)
554
- end
555
-
556
- it 'generates valid content metadata' do
557
- expect(xml.errors.size).to eq 0
558
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('book')
559
- expect(xml.xpath('//resource').length).to eq 3
560
- expect(xml.xpath('//resource/file').length).to eq 6
561
- expect(xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value).to eq('00/oo000oo0001_00_001.tif')
562
- expect(xml.xpath("//resource[@sequence='1']/file")[1].attributes['id'].value).to eq('05/oo000oo0001_05_001.jp2')
563
- expect(xml.xpath("//resource[@sequence='1']/file")[2].attributes['id'].value).to eq('15/oo000oo0001_15_001.pdf')
564
- expect(xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value).to eq('00/oo000oo0001_00_002.tif')
565
- expect(xml.xpath("//resource[@sequence='2']/file")[1].attributes['id'].value).to eq('05/oo000oo0001_05_002.jp2')
566
- expect(xml.xpath("//resource[@sequence='3']/file")[0].attributes['id'].value).to eq('oo000oo0001_book.pdf')
567
- expect(xml.xpath('//label').length).to eq 3
568
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
569
- expect(xml.xpath("//resource[@sequence='1']/file").length).to eq 3
570
- expect(xml.xpath('//label')[0].text).to eq('Object 1')
571
- expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('object')
572
- expect(xml.xpath("//resource[@sequence='2']/file").length).to eq 2
573
- expect(xml.xpath('//label')[1].text).to eq('Page 1')
574
- expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('page')
575
- expect(xml.xpath("//resource[@sequence='3']/file").length).to eq 1
576
- expect(xml.xpath('//label')[2].text).to eq('Object 2')
577
- expect(xml.xpath('//resource')[2].attributes['type'].value).to eq('object')
578
- end
579
- end
580
- end
581
-
582
- context 'when style=file' do
583
- context 'when using two tifs and two associated jp2s' do
584
- it 'generates valid content metadata using specific content metadata paths' do
585
- objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE), Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE), Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE2), Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE2)]
586
- objects[0].relative_path = 'input/test.tif'
587
- objects[1].relative_path = 'input/test.jp2'
588
- objects[2].relative_path = 'input/test2.tif'
589
- objects[3].relative_path = 'input/test2.jp2'
590
- result = described_class.create_content_metadata(druid: TEST_DRUID, style: :file, objects: objects)
591
- expect(result.class).to be String
592
- xml = Nokogiri::XML(result)
593
- expect(xml.errors.size).to eq 0
594
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('file')
595
- expect(xml.xpath('//bookData').length).to eq 0
596
- expect(xml.xpath('//resource').length).to eq 4
597
- expect(xml.xpath('//resource/file').length).to eq 4
598
- expect(xml.xpath('//label').length).to eq 4
599
- expect(xml.xpath('//resource/file')[0].attributes['id'].value).to eq('input/test.tif')
600
- expect(xml.xpath('//resource/file')[1].attributes['id'].value).to eq('input/test.jp2')
601
- expect(xml.xpath('//resource/file')[2].attributes['id'].value).to eq('input/test2.tif')
602
- expect(xml.xpath('//resource/file')[3].attributes['id'].value).to eq('input/test2.jp2')
603
- (0..3).each do |i|
604
- expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 1
605
- expect(xml.xpath('//label')[i].text).to eq("File #{i + 1}")
606
- expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('file')
607
- end
608
- end
609
- end
610
- end
611
-
612
- context 'when using style=book_as_image' do
613
- let(:objects) do
614
- [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE),
615
- Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE2)]
616
- end
617
-
618
- let(:style) { :book_as_image }
619
-
620
- before do
621
- allow(Deprecation).to receive(:warn)
622
- end
623
-
624
- it 'generates valid content metadata for two tifs' do
625
- expect(xml.errors.size).to eq 0
626
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('book')
627
- expect(xml.xpath('//bookData').length).to eq 1
628
- expect(xml.xpath('//resource').length).to eq 2
629
- expect(xml.xpath('//resource/file').length).to eq 2
630
- expect(xml.xpath('//label').length).to eq 2
631
- expect(xml.xpath('//label')[0].text).to match(/Image 1/)
632
- expect(xml.xpath('//label')[1].text).to match(/Image 2/)
633
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
634
- (0..1).each do |i|
635
- file = xml.xpath('//resource/file')[i]
636
-
637
- expect(file.attributes['size']).to be_nil
638
- expect(file.attributes['mimetype']).to be_nil
639
- expect(file.attributes['publish']).to be_nil
640
- expect(file.attributes['preserve']).to be_nil
641
- expect(file.attributes['shelve']).to be_nil
642
- end
643
- expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('image')
644
- expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('image')
645
- end
646
- end
647
-
648
- context 'when using style=document' do
649
- let(:objects) do
650
- [Assembly::ObjectFile.new(TEST_PDF_FILE)]
651
- end
652
-
653
- let(:style) { :document }
654
-
655
- it 'generates valid content metadata' do
656
- expect(xml.errors.size).to eq 0
657
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('document')
658
- expect(xml.xpath('//bookData').length).to eq 0
659
- expect(xml.xpath('//resource').length).to eq 1
660
- expect(xml.xpath('//resource/file').length).to eq 1
661
- expect(xml.xpath('//label').length).to eq 1
662
- expect(xml.xpath('//label')[0].text).to match(/Document 1/)
663
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
664
- file = xml.xpath('//resource/file').first
665
- expect(file.attributes['size']).to be_nil
666
- expect(file.attributes['mimetype']).to be_nil
667
- expect(file.attributes['publish']).to be_nil
668
- expect(file.attributes['preserve']).to be_nil
669
- expect(file.attributes['shelve']).to be_nil
670
- expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('document')
671
- end
672
- end
673
-
674
- context 'when using user supplied checksums for two tifs and style=simple_book' do
675
- it 'generates valid content metadata with no exif' do
676
- obj1 = Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE)
677
- obj1.provider_md5 = '123456789'
678
- obj1.provider_sha1 = 'abcdefgh'
679
- obj2 = Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE2)
680
- obj2.provider_md5 = 'qwerty'
681
- objects = [obj1, obj2]
682
- result = described_class.create_content_metadata(druid: TEST_DRUID, style: :simple_book, objects: objects)
683
- expect(result.class).to be String
684
- xml = Nokogiri::XML(result)
685
- expect(xml.errors.size).to eq 0
686
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('book')
687
- expect(xml.xpath('//resource').length).to eq 2
688
- expect(xml.xpath('//resource/file').length).to eq 2
689
- expect(xml.xpath('//resource/file/checksum').length).to eq 3
690
- expect(xml.xpath('//label').length).to eq 2
691
- expect(xml.xpath('//label')[0].text).to match(/Page 1/)
692
- expect(xml.xpath('//label')[1].text).to match(/Page 2/)
693
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
694
- expect(xml.xpath('//resource/file/checksum')[0].text).to eq('abcdefgh')
695
- expect(xml.xpath('//resource/file/checksum')[1].text).to eq('123456789')
696
- expect(xml.xpath('//resource/file/checksum')[2].text).to eq('qwerty')
697
- (0..1).each do |i|
698
- expect(xml.xpath('//resource/file')[i].attributes['size']).to be_nil
699
- expect(xml.xpath('//resource/file')[i].attributes['mimetype']).to be_nil
700
- expect(xml.xpath('//resource/file')[i].attributes['publish']).to be_nil
701
- expect(xml.xpath('//resource/file')[i].attributes['preserve']).to be_nil
702
- expect(xml.xpath('//resource/file')[i].attributes['shelve']).to be_nil
703
- end
704
- expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('page')
705
- expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('page')
706
- end
707
- end
708
-
709
- context 'when not all input files exist' do
710
- it 'does not generate valid content metadata' do
711
- expect(File.exist?(TEST_TIF_INPUT_FILE)).to be true
712
- junk_file = '/tmp/flim_flam_floom.jp2'
713
- expect(File.exist?(junk_file)).to be false
714
- objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE), Assembly::ObjectFile.new(junk_file)]
715
- expect { described_class.create_content_metadata(druid: TEST_DRUID, objects: objects) }.to raise_error(RuntimeError, "File '#{junk_file}' not found")
716
- end
717
- end
718
-
719
- context 'when using a 3d object with one 3d type files and three other supporting files (where one supporting file is a non-viewable but downloadable 3d file)' do
720
- let(:objects) do
721
- [Assembly::ObjectFile.new(TEST_OBJ_FILE),
722
- Assembly::ObjectFile.new(TEST_PLY_FILE),
723
- Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE),
724
- Assembly::ObjectFile.new(TEST_PDF_FILE)]
725
- end
726
- let(:style) { :'3d' }
727
-
728
- it 'generates valid content metadata' do
729
- expect(xml.errors.size).to eq 0
730
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('3d')
731
- expect(xml.xpath('//bookData').length).to eq 0
732
- expect(xml.xpath('//resource').length).to eq 4
733
- expect(xml.xpath('//resource/file').length).to eq 4
734
- expect(xml.xpath('//label').length).to eq 4
735
- expect(xml.xpath('//label')[0].text).to match(/3d 1/)
736
- expect(xml.xpath('//label')[1].text).to match(/File 1/)
737
- expect(xml.xpath('//label')[2].text).to match(/File 2/)
738
- expect(xml.xpath('//label')[3].text).to match(/File 3/)
739
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
740
- expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('3d')
741
- expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('file')
742
- expect(xml.xpath('//resource')[2].attributes['type'].value).to eq('file')
743
- expect(xml.xpath('//resource')[3].attributes['type'].value).to eq('file')
744
- end
745
- end
746
-
747
- context 'when providing file attributes' do
748
- it 'generates role attributes for content metadata' do
749
- obj1 = Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE)
750
- obj1.file_attributes = { publish: 'no', preserve: 'no', shelve: 'no', role: 'master-role' }
751
- objects = [obj1]
752
- result = described_class.create_content_metadata(druid: TEST_DRUID, add_exif: false, add_file_attributes: true, objects: objects)
753
- expect(result.class).to be String
754
- xml = Nokogiri::XML(result)
755
- expect(xml.errors.size).to eq 0
756
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
757
- expect(xml.xpath('//resource').length).to eq 1
758
- expect(xml.xpath('//resource/file').length).to eq 1
759
- expect(xml.xpath('//resource/file').length).to eq 1
760
- expect(xml.xpath('//resource/file')[0].attributes['role'].value).to eq('master-role')
761
- end
762
- end
763
-
764
- context 'when no objects are passed in' do
765
- subject(:result) { described_class.create_content_metadata(druid: TEST_DRUID, bundle: :prebundled, style: style, objects: objects) }
766
-
767
- let(:objects) { [] }
768
-
769
- let(:style) { :file }
770
-
771
- it 'generates content metadata even when no objects are passed in' do
772
- expect(xml.errors.size).to eq 0
773
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('file')
774
- expect(xml.xpath('//resource').length).to eq 0
775
- expect(xml.xpath('//resource/file').length).to eq 0
776
- end
777
- end
778
-
779
- context 'when an unknown style is passed in' do
780
- subject(:result) { described_class.create_content_metadata(druid: TEST_DRUID, bundle: :prebundled, style: style, objects: objects) }
781
-
782
- let(:objects) { [] }
783
-
784
- let(:style) { :borked }
785
-
786
- it 'generates an error message' do
787
- expect { result }.to raise_error 'Supplied style (borked) not valid'
788
- end
789
- end
790
- end
791
- end