assembly-objectfile 1.7.1 → 1.7.2

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