assembly-objectfile 1.10.0 → 1.10.1

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.
@@ -4,6 +4,6 @@
4
4
  module Assembly
5
5
  class ObjectFile
6
6
  # Project version number
7
- VERSION = '1.10.0'
7
+ VERSION = '1.10.1'
8
8
  end
9
9
  end
@@ -8,506 +8,591 @@ RSpec.describe Assembly::ContentMetadata do
8
8
 
9
9
  let(:xml) { Nokogiri::XML(result) }
10
10
 
11
- context 'when using a single tif and jp2 of style=simple_image' do
12
- it 'generates valid content metadata with exif, adding file attributes' do
13
- objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE), Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE)]
14
- result = described_class.create_content_metadata(druid: TEST_DRUID, add_exif: true, add_file_attributes: true, objects: objects)
15
- expect(result.class).to be String
16
- xml = Nokogiri::XML(result)
17
- expect(xml.errors.size).to eq 0
18
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
19
- expect(xml.xpath('//resource').length).to eq 2
20
- expect(xml.xpath('//resource/file').length).to eq 2
21
- expect(xml.xpath('//resource/file/checksum').length).to eq 4
22
- expect(xml.xpath('//resource/file/checksum')[0].text).to eq('8d11fab63089a24c8b17063d29a4b0eac359fb41')
23
- expect(xml.xpath('//resource/file/checksum')[1].text).to eq('a2400500acf21e43f5440d93be894101')
24
- expect(xml.xpath('//resource/file/checksum')[2].text).to eq('b965b5787e0100ec2d43733144120feab327e88c')
25
- expect(xml.xpath('//resource/file/checksum')[3].text).to eq('4eb54050d374291ece622d45e84f014d')
26
- expect(xml.xpath('//label').length).to eq 2
27
- expect(xml.xpath('//label')[0].text).to match(/Image 1/)
28
- expect(xml.xpath('//label')[1].text).to match(/Image 2/)
29
- expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('image')
30
- expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('image')
31
- expect(xml.xpath('//resource/file')[0].attributes['size'].value).to eq('63542')
32
- expect(xml.xpath('//resource/file')[0].attributes['mimetype'].value).to eq('image/tiff')
33
- expect(xml.xpath('//resource/file')[0].attributes['publish'].value).to eq('no')
34
- expect(xml.xpath('//resource/file')[0].attributes['preserve'].value).to eq('yes')
35
- expect(xml.xpath('//resource/file')[0].attributes['shelve'].value).to eq('no')
36
- expect(xml.xpath('//resource/file/imageData')[0].attributes['width'].value).to eq('100')
37
- expect(xml.xpath('//resource/file/imageData')[0].attributes['height'].value).to eq('100')
38
- expect(xml.xpath('//resource/file')[1].attributes['size'].value).to eq('306')
39
- expect(xml.xpath('//resource/file')[1].attributes['mimetype'].value).to eq('image/jp2')
40
- expect(xml.xpath('//resource/file')[1].attributes['publish'].value).to eq('yes')
41
- expect(xml.xpath('//resource/file')[1].attributes['preserve'].value).to eq('no')
42
- expect(xml.xpath('//resource/file')[1].attributes['shelve'].value).to eq('yes')
43
- expect(xml.xpath('//resource/file/imageData')[1].attributes['width'].value).to eq('100')
44
- expect(xml.xpath('//resource/file/imageData')[1].attributes['height'].value).to eq('100')
11
+ context 'when style is 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
45
47
  end
46
- end
47
48
 
48
- context 'when using a single tif and jp2 of style=simple_image' do
49
- it 'generates valid content metadata with no exif adding specific file attributes for 2 objects, and defaults for 1 object' do
50
- obj1 = Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE)
51
- obj2 = Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE)
52
- obj3 = Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE2)
53
- obj1.file_attributes = { publish: 'no', preserve: 'no', shelve: 'no' }
54
- obj2.file_attributes = { publish: 'yes', preserve: 'yes', shelve: 'yes' }
55
- objects = [obj1, obj2, obj3]
56
- result = described_class.create_content_metadata(druid: TEST_DRUID, add_exif: false, add_file_attributes: true, objects: objects)
57
- expect(result.class).to be String
58
- xml = Nokogiri::XML(result)
59
- expect(xml.errors.size).to eq 0
60
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
61
- expect(xml.xpath('//resource').length).to eq 3
62
- expect(xml.xpath('//resource/file').length).to eq 3
63
- expect(xml.xpath('//resource/file/checksum').length).to eq 0
64
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
65
- expect(xml.xpath('//label').length).to eq 3
66
- expect(xml.xpath('//label')[0].text).to match(/Image 1/)
67
- expect(xml.xpath('//label')[1].text).to match(/Image 2/)
68
- expect(xml.xpath('//label')[2].text).to match(/Image 3/)
69
- expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('image')
70
- expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('image')
71
- expect(xml.xpath('//resource')[2].attributes['type'].value).to eq('image')
72
- expect(xml.xpath('//resource/file')[0].attributes['publish'].value).to eq('no') # specificially set in object
73
- expect(xml.xpath('//resource/file')[0].attributes['preserve'].value).to eq('no') # specificially set in object
74
- expect(xml.xpath('//resource/file')[0].attributes['shelve'].value).to eq('no') # specificially set in object
75
- expect(xml.xpath('//resource/file')[1].attributes['publish'].value).to eq('yes') # specificially set in object
76
- expect(xml.xpath('//resource/file')[1].attributes['preserve'].value).to eq('yes') # specificially set in object
77
- expect(xml.xpath('//resource/file')[1].attributes['shelve'].value).to eq('yes') # specificially set in object
78
- expect(xml.xpath('//resource/file')[2].attributes['publish'].value).to eq('yes') # defaults by mimetype
79
- expect(xml.xpath('//resource/file')[2].attributes['preserve'].value).to eq('no') # defaults by mimetype
80
- expect(xml.xpath('//resource/file')[2].attributes['shelve'].value).to eq('yes') # defaults by mimetype
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
81
83
  end
82
- end
83
84
 
84
- context 'when using a single tif and jp2 of style=simple_image' do
85
- it 'generates valid content metadata with exif, overriding file labels' do
86
- objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE, label: 'Sample tif label!'), Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE, label: 'Sample jp2 label!')]
87
- result = described_class.create_content_metadata(druid: TEST_DRUID, add_exif: true, add_file_attributes: true, objects: objects)
88
- expect(result.class).to be String
89
- xml = Nokogiri::XML(result)
90
- expect(xml.errors.size).to eq 0
91
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
92
- expect(xml.xpath('//resource').length).to eq 2
93
- expect(xml.xpath('//resource/file').length).to eq 2
94
- expect(xml.xpath('//resource/file/checksum').length).to eq 4
95
- expect(xml.xpath('//resource/file/checksum')[0].text).to eq('8d11fab63089a24c8b17063d29a4b0eac359fb41')
96
- expect(xml.xpath('//resource/file/checksum')[1].text).to eq('a2400500acf21e43f5440d93be894101')
97
- expect(xml.xpath('//resource/file/checksum')[2].text).to eq('b965b5787e0100ec2d43733144120feab327e88c')
98
- expect(xml.xpath('//resource/file/checksum')[3].text).to eq('4eb54050d374291ece622d45e84f014d')
99
- expect(xml.xpath('//label').length).to eq 2
100
- expect(xml.xpath('//label')[0].text).to match(/Sample tif label!/)
101
- expect(xml.xpath('//label')[1].text).to match(/Sample jp2 label!/)
102
- expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('image')
103
- expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('image')
104
- expect(xml.xpath('//resource/file')[0].attributes['size'].value).to eq('63542')
105
- expect(xml.xpath('//resource/file')[0].attributes['mimetype'].value).to eq('image/tiff')
106
- expect(xml.xpath('//resource/file')[0].attributes['publish'].value).to eq('no')
107
- expect(xml.xpath('//resource/file')[0].attributes['preserve'].value).to eq('yes')
108
- expect(xml.xpath('//resource/file')[0].attributes['shelve'].value).to eq('no')
109
- expect(xml.xpath('//resource/file/imageData')[0].attributes['width'].value).to eq('100')
110
- expect(xml.xpath('//resource/file/imageData')[0].attributes['height'].value).to eq('100')
111
- expect(xml.xpath('//resource/file')[1].attributes['size'].value).to eq('306')
112
- expect(xml.xpath('//resource/file')[1].attributes['mimetype'].value).to eq('image/jp2')
113
- expect(xml.xpath('//resource/file')[1].attributes['publish'].value).to eq('yes')
114
- expect(xml.xpath('//resource/file')[1].attributes['preserve'].value).to eq('no')
115
- expect(xml.xpath('//resource/file')[1].attributes['shelve'].value).to eq('yes')
116
- expect(xml.xpath('//resource/file/imageData')[1].attributes['width'].value).to eq('100')
117
- expect(xml.xpath('//resource/file/imageData')[1].attributes['height'].value).to eq('100')
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
118
120
  end
119
- end
120
121
 
121
- context 'when using a single tif and jp2 of style=simple_image' do
122
- 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
123
- 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: '')]
124
- result = described_class.create_content_metadata(druid: TEST_DRUID, auto_labels: false, add_file_attributes: true, objects: objects)
125
- expect(result.class).to be String
126
- xml = Nokogiri::XML(result)
127
- expect(xml.errors.size).to eq 0
128
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
129
- expect(xml.xpath('//resource').length).to eq 3
130
- expect(xml.xpath('//resource/file').length).to eq 3
131
- expect(xml.xpath('//label').length).to eq 1
132
- expect(xml.xpath('//label')[0].text).to match(/Sample tif label!/)
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
133
135
  end
134
- end
135
136
 
136
- context 'when using a single tif and jp2 of style=simple_image' do
137
- it 'generates valid content metadata with overriding file attributes and no exif data' do
138
- objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE), Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE)]
139
- 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)
140
- expect(result.class).to be String
141
- xml = Nokogiri::XML(result)
142
- expect(xml.errors.size).to eq 0
143
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
144
- expect(xml.xpath('//resource').length).to eq 2
145
- expect(xml.xpath('//resource/file').length).to eq 2
146
- expect(xml.xpath('//label').length).to eq 2
147
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
148
- expect(xml.xpath('//label')[0].text).to match(/Image 1/)
149
- expect(xml.xpath('//label')[1].text).to match(/Image 2/)
150
- expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('image')
151
- expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('image')
152
- expect(xml.xpath('//resource/file')[0].attributes['size']).to be_nil
153
- expect(xml.xpath('//resource/file')[0].attributes['mimetype']).to be_nil
154
- expect(xml.xpath('//resource/file')[0].attributes['role']).to be_nil
155
- expect(xml.xpath('//resource/file')[0].attributes['publish'].value).to eq('no')
156
- expect(xml.xpath('//resource/file')[0].attributes['preserve'].value).to eq('no')
157
- expect(xml.xpath('//resource/file')[0].attributes['shelve'].value).to eq('no')
158
- expect(xml.xpath('//resource/file')[1].attributes['size']).to be_nil
159
- expect(xml.xpath('//resource/file')[1].attributes['mimetype']).to be_nil
160
- expect(xml.xpath('//resource/file')[1].attributes['role']).to be_nil
161
- expect(xml.xpath('//resource/file')[1].attributes['publish'].value).to eq('yes')
162
- expect(xml.xpath('//resource/file')[1].attributes['preserve'].value).to eq('yes')
163
- expect(xml.xpath('//resource/file')[1].attributes['shelve'].value).to eq('yes')
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
164
166
  end
165
- end
166
167
 
167
- context 'when using a single tif and jp2 of style=simple_image' do
168
- it 'generates valid content metadata with overriding file attributes, including a default value, and no exif data' do
169
- objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE), Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE)]
170
- 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)
171
- expect(result.class).to be String
172
- xml = Nokogiri::XML(result)
173
- expect(xml.errors.size).to eq 0
174
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
175
- expect(xml.xpath('//resource/file').length).to eq 2
176
- expect(xml.xpath('//resource/file')[0].attributes['mimetype']).to be_nil
177
- expect(xml.xpath('//resource/file')[0].attributes['publish'].value).to eq('yes')
178
- expect(xml.xpath('//resource/file')[0].attributes['preserve'].value).to eq('no')
179
- expect(xml.xpath('//resource/file')[0].attributes['shelve'].value).to eq('no')
180
- expect(xml.xpath('//resource/file')[1].attributes['mimetype']).to be_nil
181
- expect(xml.xpath('//resource/file')[1].attributes['publish'].value).to eq('yes')
182
- expect(xml.xpath('//resource/file')[1].attributes['preserve'].value).to eq('yes')
183
- expect(xml.xpath('//resource/file')[1].attributes['shelve'].value).to eq('yes')
184
- (0..1).each do |i|
185
- expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 1
186
- expect(xml.xpath('//label')[i].text).to eq("Image #{i + 1}")
187
- expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('image')
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
188
190
  end
189
191
  end
190
- end
191
192
 
192
- context 'when using a single tif and jp2 of style=map' do
193
- it 'generates valid content metadata with overriding file attributes, including a default value, and no exif data' do
194
- objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE), Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE)]
195
- result = described_class.create_content_metadata(style: :map, 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)
196
- expect(result.class).to be String
197
- xml = Nokogiri::XML(result)
198
- expect(xml.errors.size).to eq 0
199
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('map')
200
- expect(xml.xpath('//resource/file').length).to eq 2
201
- expect(xml.xpath('//resource/file')[0].attributes['mimetype']).to be_nil
202
- expect(xml.xpath('//resource/file')[0].attributes['publish'].value).to eq('yes')
203
- expect(xml.xpath('//resource/file')[0].attributes['preserve'].value).to eq('no')
204
- expect(xml.xpath('//resource/file')[0].attributes['shelve'].value).to eq('no')
205
- expect(xml.xpath('//resource/file')[1].attributes['mimetype']).to be_nil
206
- expect(xml.xpath('//resource/file')[1].attributes['publish'].value).to eq('yes')
207
- expect(xml.xpath('//resource/file')[1].attributes['preserve'].value).to eq('yes')
208
- expect(xml.xpath('//resource/file')[1].attributes['shelve'].value).to eq('yes')
209
- (0..1).each do |i|
210
- expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 1
211
- expect(xml.xpath('//label')[i].text).to eq("Image #{i + 1}")
212
- expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('image')
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
213
214
  end
214
215
  end
215
- end
216
216
 
217
- context 'when using two tifs and two associated jp2s of style=simple_image using bundle=filename' do
218
- it 'generates valid content metadata and no exif data' do
219
- 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)]
220
- result = described_class.create_content_metadata(druid: TEST_DRUID, bundle: :filename, objects: objects)
221
- expect(result.class).to be String
222
- xml = Nokogiri::XML(result)
223
- expect(xml.errors.size).to eq 0
224
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
225
- expect(xml.xpath('//resource').length).to eq 2
226
- expect(xml.xpath('//resource/file').length).to eq 4
227
- expect(xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value).to eq('test.tif')
228
- expect(xml.xpath("//resource[@sequence='1']/file")[1].attributes['id'].value).to eq('test.jp2')
229
- expect(xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value).to eq('test2.tif')
230
- expect(xml.xpath("//resource[@sequence='2']/file")[1].attributes['id'].value).to eq('test2.jp2')
231
- expect(xml.xpath('//label').length).to eq 2
232
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
233
- (0..1).each do |i|
234
- expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 2
235
- expect(xml.xpath('//label')[i].text).to eq("Image #{i + 1}")
236
- expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('image')
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
237
242
  end
238
243
  end
239
- end
240
244
 
241
- context 'when using two tifs and two associated jp2s of style=simple_image using bundle=dpg' do
242
- it 'generates valid content metadata and no exif data and no root xml node' do
243
- 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)]
244
- test_druid = TEST_DRUID.to_s
245
- result = described_class.create_content_metadata(druid: test_druid, bundle: :dpg, objects: objects, include_root_xml: false)
246
- expect(result.class).to be String
247
- expect(result.include?('<?xml')).to be false
248
- xml = Nokogiri::XML(result)
249
- expect(xml.errors.size).to eq 0
250
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
251
- expect(test_druid).to eq(TEST_DRUID)
252
- expect(xml.xpath('//contentMetadata')[0].attributes['objectId'].value).to eq(TEST_DRUID.to_s)
253
- expect(xml.xpath('//resource').length).to eq 2
254
- expect(xml.xpath('//resource/file').length).to eq 4
255
- expect(xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value).to eq('00/oo000oo0001_00_001.tif')
256
- expect(xml.xpath("//resource[@sequence='1']/file")[1].attributes['id'].value).to eq('05/oo000oo0001_05_001.jp2')
257
- expect(xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value).to eq('00/oo000oo0001_00_002.tif')
258
- expect(xml.xpath("//resource[@sequence='2']/file")[1].attributes['id'].value).to eq('05/oo000oo0001_05_002.jp2')
259
- expect(xml.xpath('//label').length).to eq 2
260
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
261
- (0..1).each do |i|
262
- expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 2
263
- expect(xml.xpath('//label')[i].text).to eq("Image #{i + 1}")
264
- expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('image')
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
265
266
  end
266
267
  end
267
- end
268
268
 
269
- context 'when using two tifs, two associated jp2s, one combined pdf and one special tif of style=simple_book using bundle=dpg' do
270
- it 'generates valid content metadata and no exif data and no root xml node, flattening folder structure' do
271
- 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)]
272
- result = described_class.create_content_metadata(druid: TEST_DRUID, style: :simple_book, bundle: :dpg, objects: objects, include_root_xml: false, flatten_folder_structure: true)
273
- expect(result.class).to be String
274
- expect(result.include?('<?xml')).to be false
275
- xml = Nokogiri::XML(result)
276
- expect(xml.errors.size).to eq 0
277
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('book')
278
- expect(xml.xpath('//contentMetadata')[0].attributes['objectId'].value).to eq(TEST_DRUID.to_s)
279
- expect(xml.xpath('//resource').length).to eq 4
280
- expect(xml.xpath('//resource/file').length).to eq 6
281
- expect(xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value).to eq('oo000oo0001_00_001.tif')
282
- expect(xml.xpath("//resource[@sequence='1']/file")[1].attributes['id'].value).to eq('oo000oo0001_05_001.jp2')
283
- expect(xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value).to eq('oo000oo0001_00_002.tif')
284
- expect(xml.xpath("//resource[@sequence='2']/file")[1].attributes['id'].value).to eq('oo000oo0001_05_002.jp2')
285
- expect(xml.xpath("//resource[@sequence='3']/file")[0].attributes['id'].value).to eq('oo000oo0001_31_001.pdf')
286
- expect(xml.xpath("//resource[@sequence='4']/file")[0].attributes['id'].value).to eq('oo000oo0001_50_001.tif')
287
- expect(xml.xpath('//label').length).to eq 4
288
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
289
- (0..1).each do |i|
290
- expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 2
291
- expect(xml.xpath('//label')[i].text).to eq("Page #{i + 1}")
292
- expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('page')
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
293
290
  end
294
- expect(xml.xpath("//resource[@sequence='3']/file").length).to eq 1
295
- expect(xml.xpath('//label')[2].text).to eq('Object 1')
296
- expect(xml.xpath('//resource')[2].attributes['type'].value).to eq('object')
297
- expect(xml.xpath("//resource[@sequence='4']/file").length).to eq 1
298
- expect(xml.xpath('//label')[3].text).to eq('Object 2')
299
- expect(xml.xpath('//resource')[3].attributes['type'].value).to eq('object')
300
291
  end
301
- end
302
292
 
303
- context "when item has a 'druid:' prefix. Using two tifs, two associated jp2s, two associated pdfs and one lingering PDF of style=simple_book using bundle=dpg" do
304
- it 'generates valid content metadata with flattening folder structure' do
305
- objects = [Assembly::ObjectFile.new(TEST_DPG_TIF), Assembly::ObjectFile.new(TEST_DPG_JP),
306
- Assembly::ObjectFile.new(TEST_DPG_PDF), Assembly::ObjectFile.new(TEST_DPG_TIF2),
307
- Assembly::ObjectFile.new(TEST_DPG_JP2), Assembly::ObjectFile.new(TEST_DPG_PDF2),
308
- Assembly::ObjectFile.new(TEST_DPG_SPECIAL_PDF1)]
309
- test_druid = "druid:#{TEST_DRUID}"
310
- result = described_class.create_content_metadata(druid: test_druid, bundle: :dpg, objects: objects, style: :simple_book, flatten_folder_structure: true)
311
- expect(result.class).to be String
312
- expect(result.include?('<?xml')).to be true
313
- xml = Nokogiri::XML(result)
314
- expect(xml.errors.size).to eq 0
315
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('book')
316
- expect(xml.xpath('//contentMetadata')[0].attributes['objectId'].value).to eq(test_druid)
317
- expect(test_druid).to eq("druid:#{TEST_DRUID}")
318
- expect(xml.xpath('//resource').length).to eq 3
319
- expect(xml.xpath('//resource/file').length).to be 7
320
-
321
- expect(xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value).to eq('oo000oo0001_00_001.tif')
322
- expect(xml.xpath("//resource[@sequence='1']/file")[1].attributes['id'].value).to eq('oo000oo0001_05_001.jp2')
323
- expect(xml.xpath("//resource[@sequence='1']/file")[2].attributes['id'].value).to eq('oo000oo0001_15_001.pdf')
324
- expect(xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value).to eq('oo000oo0001_00_002.tif')
325
- expect(xml.xpath("//resource[@sequence='2']/file")[1].attributes['id'].value).to eq('oo000oo0001_05_002.jp2')
326
- expect(xml.xpath("//resource[@sequence='2']/file")[2].attributes['id'].value).to eq('oo000oo0001_15_002.pdf')
327
- expect(xml.xpath("//resource[@sequence='3']/file")[0].attributes['id'].value).to eq('oo000oo0001_book.pdf')
328
- expect(xml.xpath('//label').length).to eq 3
329
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
330
- (0..1).each do |i|
331
- expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 3
332
- expect(xml.xpath('//label')[i].text).to eq("Page #{i + 1}")
333
- expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('page')
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
334
332
  end
335
- expect(xml.xpath("//resource[@sequence='3']/file").length).to eq 1
336
- expect(xml.xpath('//label')[2].text).to eq('Object 1')
337
- expect(xml.xpath('//resource')[2].attributes['type'].value).to eq('object')
338
333
  end
339
334
  end
340
335
 
341
- context 'when using two tifs, two associated jp2s, two associated pdfs and one lingering PDF of style=book_with_pdf using bundle=dpg' do
342
- subject(:result) { described_class.create_content_metadata(druid: TEST_DRUID, bundle: :dpg, style: style, objects: objects) }
343
-
344
- let(:objects) do
345
- [
346
- Assembly::ObjectFile.new(TEST_DPG_TIF),
347
- Assembly::ObjectFile.new(TEST_DPG_JP),
348
- Assembly::ObjectFile.new(TEST_DPG_PDF),
349
- Assembly::ObjectFile.new(TEST_DPG_TIF2),
350
- Assembly::ObjectFile.new(TEST_DPG_JP2),
351
- Assembly::ObjectFile.new(TEST_DPG_SPECIAL_PDF1)
352
- ]
353
- end
354
- let(:style) { :book_with_pdf }
355
-
356
- before do
357
- allow(Deprecation).to receive(:warn)
358
- end
359
-
360
- it 'generates valid content metadata' do
361
- expect(xml.errors.size).to eq 0
362
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('book')
363
- expect(xml.xpath('//resource').length).to eq 3
364
- expect(xml.xpath('//resource/file').length).to eq 6
365
- expect(xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value).to eq('00/oo000oo0001_00_001.tif')
366
- expect(xml.xpath("//resource[@sequence='1']/file")[1].attributes['id'].value).to eq('05/oo000oo0001_05_001.jp2')
367
- expect(xml.xpath("//resource[@sequence='1']/file")[2].attributes['id'].value).to eq('15/oo000oo0001_15_001.pdf')
368
- expect(xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value).to eq('00/oo000oo0001_00_002.tif')
369
- expect(xml.xpath("//resource[@sequence='2']/file")[1].attributes['id'].value).to eq('05/oo000oo0001_05_002.jp2')
370
- expect(xml.xpath("//resource[@sequence='3']/file")[0].attributes['id'].value).to eq('oo000oo0001_book.pdf')
371
- expect(xml.xpath('//label').length).to eq 3
372
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
373
- expect(xml.xpath("//resource[@sequence='1']/file").length).to eq 3
374
- expect(xml.xpath('//label')[0].text).to eq('Object 1')
375
- expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('object')
376
- expect(xml.xpath("//resource[@sequence='2']/file").length).to eq 2
377
- expect(xml.xpath('//label')[1].text).to eq('Page 1')
378
- expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('page')
379
- expect(xml.xpath("//resource[@sequence='3']/file").length).to eq 1
380
- expect(xml.xpath('//label')[2].text).to eq('Object 2')
381
- expect(xml.xpath('//resource')[2].attributes['type'].value).to eq('object')
336
+ context 'when style is 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('//resource').length).to eq 1
346
+ expect(xml.xpath('//resource/file').length).to eq 1
347
+ expect(xml.xpath('//resource/file/checksum').length).to eq 2
348
+ expect(xml.xpath('//resource/file/checksum')[0].text).to eq('b965b5787e0100ec2d43733144120feab327e88c')
349
+ expect(xml.xpath('//resource/file/checksum')[1].text).to eq('4eb54050d374291ece622d45e84f014d')
350
+ expect(xml.xpath('//label').length).to eq 1
351
+ expect(xml.xpath('//label')[0].text).to match(/Image 1/)
352
+ expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('image')
353
+ expect(xml.xpath('//resource/file')[0].attributes['size'].value).to eq('306')
354
+ expect(xml.xpath('//resource/file')[0].attributes['mimetype'].value).to eq('image/jp2')
355
+ expect(xml.xpath('//resource/file')[0].attributes['publish'].value).to eq('yes')
356
+ expect(xml.xpath('//resource/file')[0].attributes['preserve'].value).to eq('no')
357
+ expect(xml.xpath('//resource/file')[0].attributes['shelve'].value).to eq('yes')
358
+ expect(xml.xpath('//resource/file/imageData')[0].attributes['width'].value).to eq('100')
359
+ expect(xml.xpath('//resource/file/imageData')[0].attributes['height'].value).to eq('100')
360
+ end
382
361
  end
383
362
  end
384
363
 
385
- context 'when using two tifs and two associated jp2s of style=simple_image using bundle=default' do
386
- it 'generates valid content metadata and no exif data' do
387
- 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)]
388
- result = described_class.create_content_metadata(druid: TEST_DRUID, bundle: :default, objects: objects)
389
- expect(result.class).to be String
390
- xml = Nokogiri::XML(result)
391
- expect(xml.errors.size).to eq 0
392
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
393
- expect(xml.xpath('//resource').length).to eq 4
394
- expect(xml.xpath('//resource/file').length).to eq 4
395
- expect(xml.xpath('//resource/file')[0].attributes['id'].value).to eq('test.tif')
396
- expect(xml.xpath('//resource/file')[1].attributes['id'].value).to eq('test.jp2')
397
- expect(xml.xpath('//resource/file')[2].attributes['id'].value).to eq('test2.tif')
398
- expect(xml.xpath('//resource/file')[3].attributes['id'].value).to eq('test2.jp2')
399
- expect(xml.xpath('//label').length).to eq 4
400
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
401
- (0..3).each do |i|
402
- expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 1
403
- expect(xml.xpath('//label')[i].text).to eq("Image #{i + 1}")
404
- expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('image')
364
+ context 'when style=map' do
365
+ context 'when using a single tif and jp2' do
366
+ it 'generates valid content metadata with overriding file attributes, including a default value, and no exif data' do
367
+ objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE), Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE)]
368
+ result = described_class.create_content_metadata(style: :map,
369
+ druid: TEST_DRUID,
370
+ add_file_attributes: true,
371
+ file_attributes: { 'default' => { publish: 'yes', preserve: 'no', shelve: 'no' },
372
+ 'image/jp2' => { publish: 'yes', preserve: 'yes', shelve: 'yes' } },
373
+ objects: objects)
374
+ expect(result.class).to be String
375
+ xml = Nokogiri::XML(result)
376
+ expect(xml.errors.size).to eq 0
377
+ expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('map')
378
+ expect(xml.xpath('//resource/file').length).to eq 2
379
+ expect(xml.xpath('//resource/file')[0].attributes['mimetype']).to be_nil
380
+ expect(xml.xpath('//resource/file')[0].attributes['publish'].value).to eq('yes')
381
+ expect(xml.xpath('//resource/file')[0].attributes['preserve'].value).to eq('no')
382
+ expect(xml.xpath('//resource/file')[0].attributes['shelve'].value).to eq('no')
383
+ expect(xml.xpath('//resource/file')[1].attributes['mimetype']).to be_nil
384
+ expect(xml.xpath('//resource/file')[1].attributes['publish'].value).to eq('yes')
385
+ expect(xml.xpath('//resource/file')[1].attributes['preserve'].value).to eq('yes')
386
+ expect(xml.xpath('//resource/file')[1].attributes['shelve'].value).to eq('yes')
387
+ (0..1).each do |i|
388
+ expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 1
389
+ expect(xml.xpath('//label')[i].text).to eq("Image #{i + 1}")
390
+ expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('image')
391
+ end
405
392
  end
406
393
  end
407
394
  end
408
395
 
409
- context 'when using two tifs and two associated jp2s of style=simple_image using bundle=default' do
410
- it 'generates valid content metadata and no exif data, preserving full paths' do
411
- 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)]
412
- result = described_class.create_content_metadata(druid: TEST_DRUID, bundle: :default, objects: objects, preserve_common_paths: true)
413
- expect(result.class).to be String
414
- xml = Nokogiri::XML(result)
415
- expect(xml.errors.size).to eq 0
416
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
417
- expect(xml.xpath('//resource').length).to eq 4
418
- expect(xml.xpath('//resource/file').length).to eq 4
419
- expect(xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value).to eq(TEST_TIF_INPUT_FILE)
420
- expect(xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value).to eq(TEST_JP2_INPUT_FILE)
421
- expect(xml.xpath("//resource[@sequence='3']/file")[0].attributes['id'].value).to eq(TEST_TIF_INPUT_FILE2)
422
- expect(xml.xpath("//resource[@sequence='4']/file")[0].attributes['id'].value).to eq(TEST_JP2_INPUT_FILE2)
423
- expect(xml.xpath('//label').length).to eq 4
424
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
425
- (0..3).each do |i|
426
- expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 1
427
- expect(xml.xpath('//label')[i].text).to eq("Image #{i + 1}")
428
- expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('image')
396
+ context 'when style=simple_book' do
397
+ context 'when using two tifs, two associated jp2s, one combined pdf and one special tif using bundle=dpg' do
398
+ it 'generates valid content metadata and no exif data and no root xml node, flattening folder structure' do
399
+ 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)]
400
+ result = described_class.create_content_metadata(druid: TEST_DRUID, style: :simple_book, bundle: :dpg, objects: objects, include_root_xml: false, flatten_folder_structure: true)
401
+ expect(result.class).to be String
402
+ expect(result.include?('<?xml')).to be false
403
+ xml = Nokogiri::XML(result)
404
+ expect(xml.errors.size).to eq 0
405
+ expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('book')
406
+ expect(xml.xpath('//contentMetadata')[0].attributes['objectId'].value).to eq(TEST_DRUID.to_s)
407
+ expect(xml.xpath('//resource').length).to eq 4
408
+ expect(xml.xpath('//resource/file').length).to eq 6
409
+ expect(xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value).to eq('oo000oo0001_00_001.tif')
410
+ expect(xml.xpath("//resource[@sequence='1']/file")[1].attributes['id'].value).to eq('oo000oo0001_05_001.jp2')
411
+ expect(xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value).to eq('oo000oo0001_00_002.tif')
412
+ expect(xml.xpath("//resource[@sequence='2']/file")[1].attributes['id'].value).to eq('oo000oo0001_05_002.jp2')
413
+ expect(xml.xpath("//resource[@sequence='3']/file")[0].attributes['id'].value).to eq('oo000oo0001_31_001.pdf')
414
+ expect(xml.xpath("//resource[@sequence='4']/file")[0].attributes['id'].value).to eq('oo000oo0001_50_001.tif')
415
+ expect(xml.xpath('//label').length).to eq 4
416
+ expect(xml.xpath('//resource/file/imageData').length).to eq 0
417
+ (0..1).each do |i|
418
+ expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 2
419
+ expect(xml.xpath('//label')[i].text).to eq("Page #{i + 1}")
420
+ expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('page')
421
+ end
422
+ expect(xml.xpath("//resource[@sequence='3']/file").length).to eq 1
423
+ expect(xml.xpath('//label')[2].text).to eq('Object 1')
424
+ expect(xml.xpath('//resource')[2].attributes['type'].value).to eq('object')
425
+ expect(xml.xpath("//resource[@sequence='4']/file").length).to eq 1
426
+ expect(xml.xpath('//label')[3].text).to eq('Object 2')
427
+ expect(xml.xpath('//resource')[3].attributes['type'].value).to eq('object')
429
428
  end
430
429
  end
431
- end
432
430
 
433
- context 'when using two tifs and two associated jp2s of style=file' do
434
- it 'generates valid content metadata using specific content metadata paths' do
435
- 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)]
436
- objects[0].relative_path = 'input/test.tif'
437
- objects[1].relative_path = 'input/test.jp2'
438
- objects[2].relative_path = 'input/test2.tif'
439
- objects[3].relative_path = 'input/test2.jp2'
440
- result = described_class.create_content_metadata(druid: TEST_DRUID, style: :file, objects: objects)
441
- expect(result.class).to be String
442
- xml = Nokogiri::XML(result)
443
- expect(xml.errors.size).to eq 0
444
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('file')
445
- expect(xml.xpath('//resource').length).to eq 4
446
- expect(xml.xpath('//resource/file').length).to eq 4
447
- expect(xml.xpath('//label').length).to eq 4
448
- expect(xml.xpath('//resource/file')[0].attributes['id'].value).to eq('input/test.tif')
449
- expect(xml.xpath('//resource/file')[1].attributes['id'].value).to eq('input/test.jp2')
450
- expect(xml.xpath('//resource/file')[2].attributes['id'].value).to eq('input/test2.tif')
451
- expect(xml.xpath('//resource/file')[3].attributes['id'].value).to eq('input/test2.jp2')
452
- (0..3).each do |i|
453
- expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 1
454
- expect(xml.xpath('//label')[i].text).to eq("File #{i + 1}")
455
- expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('file')
431
+ context "when item has a 'druid:' prefix. Using two tifs, two associated jp2s, two associated pdfs and one lingering PDF using bundle=dpg" do
432
+ it 'generates valid content metadata with flattening folder structure' do
433
+ objects = [Assembly::ObjectFile.new(TEST_DPG_TIF), Assembly::ObjectFile.new(TEST_DPG_JP),
434
+ Assembly::ObjectFile.new(TEST_DPG_PDF), Assembly::ObjectFile.new(TEST_DPG_TIF2),
435
+ Assembly::ObjectFile.new(TEST_DPG_JP2), Assembly::ObjectFile.new(TEST_DPG_PDF2),
436
+ Assembly::ObjectFile.new(TEST_DPG_SPECIAL_PDF1)]
437
+ test_druid = "druid:#{TEST_DRUID}"
438
+ result = described_class.create_content_metadata(druid: test_druid, bundle: :dpg, objects: objects, style: :simple_book, flatten_folder_structure: true)
439
+ expect(result.class).to be String
440
+ expect(result.include?('<?xml')).to be true
441
+ xml = Nokogiri::XML(result)
442
+ expect(xml.errors.size).to eq 0
443
+ expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('book')
444
+ expect(xml.xpath('//contentMetadata')[0].attributes['objectId'].value).to eq(test_druid)
445
+ expect(test_druid).to eq("druid:#{TEST_DRUID}")
446
+ expect(xml.xpath('//resource').length).to eq 3
447
+ expect(xml.xpath('//resource/file').length).to be 7
448
+
449
+ expect(xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value).to eq('oo000oo0001_00_001.tif')
450
+ expect(xml.xpath("//resource[@sequence='1']/file")[1].attributes['id'].value).to eq('oo000oo0001_05_001.jp2')
451
+ expect(xml.xpath("//resource[@sequence='1']/file")[2].attributes['id'].value).to eq('oo000oo0001_15_001.pdf')
452
+ expect(xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value).to eq('oo000oo0001_00_002.tif')
453
+ expect(xml.xpath("//resource[@sequence='2']/file")[1].attributes['id'].value).to eq('oo000oo0001_05_002.jp2')
454
+ expect(xml.xpath("//resource[@sequence='2']/file")[2].attributes['id'].value).to eq('oo000oo0001_15_002.pdf')
455
+ expect(xml.xpath("//resource[@sequence='3']/file")[0].attributes['id'].value).to eq('oo000oo0001_book.pdf')
456
+ expect(xml.xpath('//label').length).to eq 3
457
+ expect(xml.xpath('//resource/file/imageData').length).to eq 0
458
+ (0..1).each do |i|
459
+ expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 3
460
+ expect(xml.xpath('//label')[i].text).to eq("Page #{i + 1}")
461
+ expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('page')
462
+ end
463
+ expect(xml.xpath("//resource[@sequence='3']/file").length).to eq 1
464
+ expect(xml.xpath('//label')[2].text).to eq('Object 1')
465
+ expect(xml.xpath('//resource')[2].attributes['type'].value).to eq('object')
456
466
  end
457
467
  end
458
- end
459
468
 
460
- context 'when using two tifs of style=simple_book' do
461
- it 'generates valid content metadata for two tifs of style=simple_book' do
462
- objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE), Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE2)]
463
- result = described_class.create_content_metadata(druid: TEST_DRUID, style: :simple_book, objects: objects)
464
- expect(result.class).to be String
465
- xml = Nokogiri::XML(result)
466
- expect(xml.errors.size).to eq 0
467
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('book')
468
- expect(xml.xpath('//resource').length).to eq 2
469
- expect(xml.xpath('//resource/file').length).to eq 2
470
- expect(xml.xpath('//label').length).to eq 2
471
- expect(xml.xpath('//label')[0].text).to match(/Page 1/)
472
- expect(xml.xpath('//label')[1].text).to match(/Page 2/)
473
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
474
- (0..1).each do |i|
475
- expect(xml.xpath('//resource/file')[i].attributes['size']).to be_nil
476
- expect(xml.xpath('//resource/file')[i].attributes['mimetype']).to be_nil
477
- expect(xml.xpath('//resource/file')[i].attributes['publish']).to be_nil
478
- expect(xml.xpath('//resource/file')[i].attributes['preserve']).to be_nil
479
- expect(xml.xpath('//resource/file')[i].attributes['shelve']).to be_nil
469
+ context 'when using two tifs' do
470
+ it 'generates valid content metadata for two tifs of style=simple_book' do
471
+ objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE), Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE2)]
472
+ result = described_class.create_content_metadata(druid: TEST_DRUID, style: :simple_book, objects: objects)
473
+ expect(result.class).to be String
474
+ xml = Nokogiri::XML(result)
475
+ expect(xml.errors.size).to eq 0
476
+ expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('book')
477
+ expect(xml.xpath('//resource').length).to eq 2
478
+ expect(xml.xpath('//resource/file').length).to eq 2
479
+ expect(xml.xpath('//label').length).to eq 2
480
+ expect(xml.xpath('//label')[0].text).to match(/Page 1/)
481
+ expect(xml.xpath('//label')[1].text).to match(/Page 2/)
482
+ expect(xml.xpath('//resource/file/imageData').length).to eq 0
483
+ (0..1).each do |i|
484
+ expect(xml.xpath('//resource/file')[i].attributes['size']).to be_nil
485
+ expect(xml.xpath('//resource/file')[i].attributes['mimetype']).to be_nil
486
+ expect(xml.xpath('//resource/file')[i].attributes['publish']).to be_nil
487
+ expect(xml.xpath('//resource/file')[i].attributes['preserve']).to be_nil
488
+ expect(xml.xpath('//resource/file')[i].attributes['shelve']).to be_nil
489
+ end
490
+ expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('page')
491
+ expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('page')
480
492
  end
481
- expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('page')
482
- expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('page')
483
493
  end
484
494
  end
485
495
 
486
496
  context 'when using style=book_with_pdf' do
487
- let(:objects) do
488
- [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE),
489
- Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE2),
490
- Assembly::ObjectFile.new(TEST_PDF_FILE)]
497
+ context 'when using two tiffs and a pdf' do
498
+ let(:objects) do
499
+ [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE),
500
+ Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE2),
501
+ Assembly::ObjectFile.new(TEST_PDF_FILE)]
502
+ end
503
+ let(:style) { :book_with_pdf }
504
+
505
+ before do
506
+ allow(Deprecation).to receive(:warn)
507
+ end
508
+
509
+ it 'generates valid content metadata for two tifs' do
510
+ expect(xml.errors.size).to eq 0
511
+ expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('book')
512
+ expect(xml.xpath('//resource').length).to eq 3
513
+ expect(xml.xpath('//resource/file').length).to eq 3
514
+ expect(xml.xpath('//label').length).to eq 3
515
+ expect(xml.xpath('//label')[0].text).to match(/Page 1/)
516
+ expect(xml.xpath('//label')[1].text).to match(/Page 2/)
517
+ expect(xml.xpath('//label')[2].text).to match(/Object 1/)
518
+ expect(xml.xpath('//resource/file/imageData').length).to eq 0
519
+ expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('page')
520
+ expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('page')
521
+ expect(xml.xpath('//resource')[2].attributes['type'].value).to eq('object')
522
+ end
491
523
  end
492
- let(:style) { :book_with_pdf }
493
524
 
494
- before do
495
- allow(Deprecation).to receive(:warn)
525
+ context 'when using two tifs, two associated jp2s, two associated pdfs and one lingering PDF using bundle=dpg' do
526
+ subject(:result) { described_class.create_content_metadata(druid: TEST_DRUID, bundle: :dpg, style: style, objects: objects) }
527
+
528
+ let(:objects) do
529
+ [
530
+ Assembly::ObjectFile.new(TEST_DPG_TIF),
531
+ Assembly::ObjectFile.new(TEST_DPG_JP),
532
+ Assembly::ObjectFile.new(TEST_DPG_PDF),
533
+ Assembly::ObjectFile.new(TEST_DPG_TIF2),
534
+ Assembly::ObjectFile.new(TEST_DPG_JP2),
535
+ Assembly::ObjectFile.new(TEST_DPG_SPECIAL_PDF1)
536
+ ]
537
+ end
538
+ let(:style) { :book_with_pdf }
539
+
540
+ before do
541
+ allow(Deprecation).to receive(:warn)
542
+ end
543
+
544
+ it 'generates valid content metadata' do
545
+ expect(xml.errors.size).to eq 0
546
+ expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('book')
547
+ expect(xml.xpath('//resource').length).to eq 3
548
+ expect(xml.xpath('//resource/file').length).to eq 6
549
+ expect(xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value).to eq('00/oo000oo0001_00_001.tif')
550
+ expect(xml.xpath("//resource[@sequence='1']/file")[1].attributes['id'].value).to eq('05/oo000oo0001_05_001.jp2')
551
+ expect(xml.xpath("//resource[@sequence='1']/file")[2].attributes['id'].value).to eq('15/oo000oo0001_15_001.pdf')
552
+ expect(xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value).to eq('00/oo000oo0001_00_002.tif')
553
+ expect(xml.xpath("//resource[@sequence='2']/file")[1].attributes['id'].value).to eq('05/oo000oo0001_05_002.jp2')
554
+ expect(xml.xpath("//resource[@sequence='3']/file")[0].attributes['id'].value).to eq('oo000oo0001_book.pdf')
555
+ expect(xml.xpath('//label').length).to eq 3
556
+ expect(xml.xpath('//resource/file/imageData').length).to eq 0
557
+ expect(xml.xpath("//resource[@sequence='1']/file").length).to eq 3
558
+ expect(xml.xpath('//label')[0].text).to eq('Object 1')
559
+ expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('object')
560
+ expect(xml.xpath("//resource[@sequence='2']/file").length).to eq 2
561
+ expect(xml.xpath('//label')[1].text).to eq('Page 1')
562
+ expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('page')
563
+ expect(xml.xpath("//resource[@sequence='3']/file").length).to eq 1
564
+ expect(xml.xpath('//label')[2].text).to eq('Object 2')
565
+ expect(xml.xpath('//resource')[2].attributes['type'].value).to eq('object')
566
+ end
496
567
  end
568
+ end
497
569
 
498
- it 'generates valid content metadata for two tifs' do
499
- expect(xml.errors.size).to eq 0
500
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('book')
501
- expect(xml.xpath('//resource').length).to eq 3
502
- expect(xml.xpath('//resource/file').length).to eq 3
503
- expect(xml.xpath('//label').length).to eq 3
504
- expect(xml.xpath('//label')[0].text).to match(/Page 1/)
505
- expect(xml.xpath('//label')[1].text).to match(/Page 2/)
506
- expect(xml.xpath('//label')[2].text).to match(/Object 1/)
507
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
508
- expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('page')
509
- expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('page')
510
- expect(xml.xpath('//resource')[2].attributes['type'].value).to eq('object')
570
+ context 'when style=file' do
571
+ context 'when using two tifs and two associated jp2s' do
572
+ it 'generates valid content metadata using specific content metadata paths' do
573
+ 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)]
574
+ objects[0].relative_path = 'input/test.tif'
575
+ objects[1].relative_path = 'input/test.jp2'
576
+ objects[2].relative_path = 'input/test2.tif'
577
+ objects[3].relative_path = 'input/test2.jp2'
578
+ result = described_class.create_content_metadata(druid: TEST_DRUID, style: :file, objects: objects)
579
+ expect(result.class).to be String
580
+ xml = Nokogiri::XML(result)
581
+ expect(xml.errors.size).to eq 0
582
+ expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('file')
583
+ expect(xml.xpath('//resource').length).to eq 4
584
+ expect(xml.xpath('//resource/file').length).to eq 4
585
+ expect(xml.xpath('//label').length).to eq 4
586
+ expect(xml.xpath('//resource/file')[0].attributes['id'].value).to eq('input/test.tif')
587
+ expect(xml.xpath('//resource/file')[1].attributes['id'].value).to eq('input/test.jp2')
588
+ expect(xml.xpath('//resource/file')[2].attributes['id'].value).to eq('input/test2.tif')
589
+ expect(xml.xpath('//resource/file')[3].attributes['id'].value).to eq('input/test2.jp2')
590
+ (0..3).each do |i|
591
+ expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 1
592
+ expect(xml.xpath('//label')[i].text).to eq("File #{i + 1}")
593
+ expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('file')
594
+ end
595
+ end
511
596
  end
512
597
  end
513
598
 
@@ -643,48 +728,6 @@ RSpec.describe Assembly::ContentMetadata do
643
728
  end
644
729
  end
645
730
 
646
- context 'when style=simple_image using bundle=prebundled' do
647
- it 'generates valid content metadata for images and associated text files and no exif data' do
648
- 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]]
649
- objects = files.collect { |resource| resource.collect { |file| Assembly::ObjectFile.new(file) } }
650
- result = described_class.create_content_metadata(druid: TEST_DRUID, bundle: :prebundled, style: :simple_image, objects: objects)
651
- expect(result.class).to be String
652
- xml = Nokogiri::XML(result)
653
- expect(xml.errors.size).to eq 0
654
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
655
- expect(xml.xpath('//resource').length).to eq 3
656
- expect(xml.xpath('//resource/file').length).to eq 16
657
- expect(xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value).to eq('res1_image1.tif')
658
- expect(xml.xpath("//resource[@sequence='1']/file")[1].attributes['id'].value).to eq('res1_image1.jp2')
659
- expect(xml.xpath("//resource[@sequence='1']/file")[2].attributes['id'].value).to eq('res1_image2.tif')
660
- expect(xml.xpath("//resource[@sequence='1']/file")[3].attributes['id'].value).to eq('res1_image2.jp2')
661
- expect(xml.xpath("//resource[@sequence='1']/file")[4].attributes['id'].value).to eq('res1_teifile.txt')
662
- expect(xml.xpath("//resource[@sequence='1']/file")[5].attributes['id'].value).to eq('res1_textfile.txt')
663
- expect(xml.xpath("//resource[@sequence='1']/file")[6].attributes['id'].value).to eq('res1_transcript.pdf')
664
- expect(xml.xpath("//resource[@sequence='1']/file").length).to be 7
665
-
666
- expect(xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value).to eq('res2_image1.tif')
667
- expect(xml.xpath("//resource[@sequence='2']/file")[1].attributes['id'].value).to eq('res2_image1.jp2')
668
- expect(xml.xpath("//resource[@sequence='2']/file")[2].attributes['id'].value).to eq('res2_image2.tif')
669
- expect(xml.xpath("//resource[@sequence='2']/file")[3].attributes['id'].value).to eq('res2_image2.jp2')
670
- expect(xml.xpath("//resource[@sequence='2']/file")[4].attributes['id'].value).to eq('res2_teifile.txt')
671
- expect(xml.xpath("//resource[@sequence='2']/file")[5].attributes['id'].value).to eq('res2_textfile.txt')
672
- expect(xml.xpath("//resource[@sequence='2']/file").length).to eq 6
673
-
674
- expect(xml.xpath("//resource[@sequence='3']/file")[0].attributes['id'].value).to eq('res3_image1.tif')
675
- expect(xml.xpath("//resource[@sequence='3']/file")[1].attributes['id'].value).to eq('res3_image1.jp2')
676
- expect(xml.xpath("//resource[@sequence='3']/file")[2].attributes['id'].value).to eq('res3_teifile.txt')
677
- expect(xml.xpath("//resource[@sequence='3']/file").length).to eq 3
678
-
679
- expect(xml.xpath('//label').length).to eq 3
680
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
681
- (0..2).each do |i|
682
- expect(xml.xpath('//label')[i].text).to eq("Image #{i + 1}")
683
- expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('image')
684
- end
685
- end
686
- end
687
-
688
731
  context 'when providing file attributes' do
689
732
  it 'generates role attributes for content metadata' do
690
733
  obj1 = Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE)