assembly-objectfile 1.9.0 → 1.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 04ee4aa95c21e1ef894bc760f83bf38bc4ce18cb18ca543451fc9645ee43f20b
4
- data.tar.gz: e6e6f2a9a6d9e075470f412bcd299d4da9dbeb3e5aa673c6b371e3d20c3e06fc
3
+ metadata.gz: ab94538c86ddec92361ad8be34b75f30d5c5c2991ddbb25e3375593e6c079b94
4
+ data.tar.gz: b03077ed3ae19b4c77615ce407e600b8cacdaa190cded54e98edc5461d360af8
5
5
  SHA512:
6
- metadata.gz: 23c5882333d2c6b95eb107672c374986c8b048d9844ed40c8716cae9f1d8ad4a1904c187f0bdc308ac97262010a0e386eaae833524100fd4de7d8f9dcf672c23
7
- data.tar.gz: 15114a44a00b614f41d6cb8467c1fbaf16986dc570ed7e4decc574eebfdc1fe52321fc8c87cce37ba45199347860b47044ea8fde6467e4399569ac6c84eafe77
6
+ metadata.gz: e77fd23ee31f26f9d9cd4502b760670381e5e97ade348274e52f9b70e318b4d8dd54bd45fe7529535a8912f60c822dfb616f71306f8381f6923bffa37c631993
7
+ data.tar.gz: 8d92581381a3464cc0cfb44bf0e7dabd3222edf70acf477c293d79c7b1791ca5c626bf2458d1faebe05a1ef5f4606d53e1a7a1266ff18e68257dbfe1f66ddfcd
@@ -13,3 +13,28 @@ RSpec/MessageSpies:
13
13
 
14
14
  RSpec/NestedGroups:
15
15
  Max: 4 # default: 3
16
+
17
+ Metrics/BlockLength:
18
+ Exclude:
19
+ - spec/**/*_spec.rb
20
+
21
+ Layout/SpaceAroundMethodCallOperator:
22
+ Enabled: true
23
+
24
+ Lint/RaiseException:
25
+ Enabled: true
26
+
27
+ Lint/StructNewOverride:
28
+ Enabled: true
29
+
30
+ Style/ExponentialNotation:
31
+ Enabled: true
32
+
33
+ Style/HashEachMethods:
34
+ Enabled: true
35
+
36
+ Style/HashTransformKeys:
37
+ Enabled: true
38
+
39
+ Style/HashTransformValues:
40
+ Enabled: true
@@ -1,36 +1,33 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2019-10-17 23:28:35 -0500 using RuboCop version 0.75.1.
3
+ # on 2020-04-23 10:59:56 -0500 using RuboCop version 0.82.0.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 1
10
- Lint/AmbiguousBlockAssociation:
11
- Exclude:
12
- - 'spec/content_metadata_spec.rb'
13
-
14
9
  # Offense count: 1
15
10
  Lint/UselessAssignment:
16
11
  Exclude:
17
12
  - 'config/boot.rb'
18
13
 
19
14
  # Offense count: 3
15
+ # Configuration parameters: IgnoredMethods.
20
16
  Metrics/AbcSize:
21
17
  Max: 51
22
18
 
23
- # Offense count: 11
19
+ # Offense count: 2
24
20
  # Configuration parameters: CountComments, ExcludedMethods.
25
21
  # ExcludedMethods: refine
26
22
  Metrics/BlockLength:
27
- Max: 577
23
+ Max: 27
28
24
 
29
- # Offense count: 3
25
+ # Offense count: 2
26
+ # Configuration parameters: IgnoredMethods.
30
27
  Metrics/CyclomaticComplexity:
31
28
  Max: 14
32
29
 
33
- # Offense count: 5
30
+ # Offense count: 4
34
31
  # Configuration parameters: CountComments, ExcludedMethods.
35
32
  Metrics/MethodLength:
36
33
  Max: 30
@@ -46,6 +43,7 @@ Metrics/ParameterLists:
46
43
  Max: 11
47
44
 
48
45
  # Offense count: 2
46
+ # Configuration parameters: IgnoredMethods.
49
47
  Metrics/PerceivedComplexity:
50
48
  Max: 12
51
49
 
@@ -57,10 +55,10 @@ Naming/FileName:
57
55
  - 'lib/assembly-objectfile.rb'
58
56
 
59
57
  # Offense count: 1
60
- # Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist, MethodDefinitionMacros.
58
+ # Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros.
61
59
  # NamePrefix: is_, has_, have_
62
- # NamePrefixBlacklist: is_, has_, have_
63
- # NameWhitelist: is_a?
60
+ # ForbiddenPrefixes: is_, has_, have_
61
+ # AllowedMethods: is_a?
64
62
  # MethodDefinitionMacros: define_method, define_singleton_method
65
63
  Naming/PredicateName:
66
64
  Exclude:
@@ -80,7 +78,7 @@ RSpec/FilePath:
80
78
  - 'spec/content_metadata_spec.rb'
81
79
  - 'spec/object_file_spec.rb'
82
80
 
83
- # Offense count: 67
81
+ # Offense count: 71
84
82
  # Configuration parameters: AssignmentOnly.
85
83
  RSpec/InstanceVariable:
86
84
  Exclude:
@@ -101,20 +99,19 @@ RSpec/RepeatedExample:
101
99
  Exclude:
102
100
  - 'spec/object_file_spec.rb'
103
101
 
102
+ # Offense count: 8
103
+ RSpec/RepeatedExampleGroupDescription:
104
+ Exclude:
105
+ - 'spec/content_metadata_spec.rb'
106
+
104
107
  # Offense count: 2
105
108
  Style/CommentedKeyword:
106
109
  Exclude:
107
110
  - 'lib/assembly-objectfile/content_metadata.rb'
108
111
 
109
- # Offense count: 1
110
- # Configuration parameters: MinBodyLength.
111
- Style/GuardClause:
112
- Exclude:
113
- - 'lib/assembly-objectfile/object_file.rb'
114
-
115
- # Offense count: 346
112
+ # Offense count: 409
116
113
  # Cop supports --auto-correct.
117
114
  # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
118
115
  # URISchemes: http, https
119
- Metrics/LineLength:
120
- Max: 304
116
+ Layout/LineLength:
117
+ Max: 284
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
21
21
  s.require_paths = ['lib']
22
22
 
23
23
  s.add_dependency 'activesupport', '>= 5.2.0'
24
+ s.add_dependency 'deprecation'
24
25
  s.add_dependency 'dry-struct', '~> 1.0'
25
26
  s.add_dependency 'dry-types', '~> 1.1'
26
27
  s.add_dependency 'mime-types', '> 3'
@@ -14,26 +14,6 @@ module Assembly
14
14
  # by the file command, then a check will be made to see if exif data exists...if so, the mimetype returned by the exif data will be used
15
15
  # if no exif data exists, then the mimetype returned by the unix file command will be used
16
16
  TRUSTED_MIMETYPES = ['text/plain', 'plain/text', 'application/pdf', 'text/html', 'application/xml'].freeze
17
-
18
- # default publish/preserve/shelve attributes used in content metadata
19
- # if no mimetype specific attributes are specified for a given file, define some defaults, and override for specific mimetypes below
20
- FILE_ATTRIBUTES = {
21
- 'default' => { preserve: 'yes', shelve: 'no', publish: 'no' },
22
- 'image/tif' => { preserve: 'yes', shelve: 'no', publish: 'no' },
23
- 'image/tiff' => { preserve: 'yes', shelve: 'no', publish: 'no' },
24
- 'image/jp2' => { preserve: 'no', shelve: 'yes', publish: 'yes' },
25
- 'image/jpeg' => { preserve: 'yes', shelve: 'no', publish: 'no' },
26
- 'audio/wav' => { preserve: 'yes', shelve: 'no', publish: 'no' },
27
- 'audio/x-wav' => { preserve: 'yes', shelve: 'no', publish: 'no' },
28
- 'audio/mp3' => { preserve: 'no', shelve: 'yes', publish: 'yes' },
29
- 'audio/mpeg' => { preserve: 'no', shelve: 'yes', publish: 'yes' },
30
- 'application/pdf' => { preserve: 'yes', shelve: 'yes', publish: 'yes' },
31
- 'plain/text' => { preserve: 'yes', shelve: 'yes', publish: 'yes' },
32
- 'text/plain' => { preserve: 'yes', shelve: 'yes', publish: 'yes' },
33
- 'image/png' => { preserve: 'yes', shelve: 'yes', publish: 'no' },
34
- 'application/zip' => { preserve: 'yes', shelve: 'no', publish: 'no' },
35
- 'application/json' => { preserve: 'yes', shelve: 'yes', publish: 'yes' }
36
- }.freeze
37
17
  end
38
18
 
39
19
  require 'assembly-objectfile/content_metadata'
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'nokogiri'
4
+ require 'deprecation'
4
5
  require 'active_support'
5
6
  require 'assembly-objectfile/content_metadata/file'
6
7
  require 'assembly-objectfile/content_metadata/file_set'
@@ -13,6 +14,7 @@ module Assembly
13
14
  # these are used when :bundle=>:dpg only
14
15
 
15
16
  DEPRECATED_STYLES = %i[book_with_pdf book_as_image].freeze
17
+ VALID_STYLES = %i[simple_image simple_book file map document 3d].freeze
16
18
 
17
19
  # This class generates content metadata for image files
18
20
  class ContentMetadata
@@ -60,7 +62,6 @@ module Assembly
60
62
  common_path = find_common_path(objects) unless preserve_common_paths # find common paths to all files provided if needed
61
63
 
62
64
  filesets = FileSetBuilder.build(bundle: bundle, objects: objects, style: style)
63
-
64
65
  config = Config.new(auto_labels: auto_labels,
65
66
  flatten_folder_structure: flatten_folder_structure,
66
67
  add_file_attributes: add_file_attributes,
@@ -98,21 +99,16 @@ module Assembly
98
99
  private_class_method :find_common_path
99
100
 
100
101
  def self.object_level_type(style)
101
- puts "WARNING - the style #{style} is now deprecated and should not be used." if DEPRECATED_STYLES.include? style
102
+ Deprecation.warn(self, "the style #{style} is now deprecated and should not be used. This will be removed in assembly-objectfile 2.0") if DEPRECATED_STYLES.include? style
103
+ raise "Supplied style (#{style}) not valid" unless (VALID_STYLES + DEPRECATED_STYLES).include? style
102
104
 
103
105
  case style
104
106
  when :simple_image
105
107
  'image'
106
- when :file
107
- 'file'
108
108
  when :simple_book, :book_with_pdf, :book_as_image
109
109
  'book'
110
- when :map
111
- 'map'
112
- when :'3d'
113
- '3d'
114
110
  else
115
- raise "Supplied style (#{style}) not valid"
111
+ style.to_s
116
112
  end
117
113
  end
118
114
  end # class
@@ -12,7 +12,7 @@ module Assembly
12
12
 
13
13
  # Represents a configuration for generating the content metadata
14
14
  class Config < Dry::Struct
15
- STYLES = %w[image file book map 3d].freeze
15
+ STYLES = %w[image file book map 3d document].freeze
16
16
  attribute :auto_labels, Types::Strict::Bool.default(true)
17
17
  attribute :flatten_folder_structure, Types::Strict::Bool.default(false)
18
18
  attribute :add_file_attributes, Types::Strict::Bool.default(false)
@@ -6,6 +6,26 @@ module Assembly
6
6
  class ContentMetadata
7
7
  # Represents a single File
8
8
  class File
9
+ # default publish/preserve/shelve attributes used in content metadata
10
+ # if no mimetype specific attributes are specified for a given file, define some defaults, and override for specific mimetypes below
11
+ ATTRIBUTES_FOR_TYPE = {
12
+ 'default' => { preserve: 'yes', shelve: 'no', publish: 'no' },
13
+ 'image/tif' => { preserve: 'yes', shelve: 'no', publish: 'no' },
14
+ 'image/tiff' => { preserve: 'yes', shelve: 'no', publish: 'no' },
15
+ 'image/jp2' => { preserve: 'no', shelve: 'yes', publish: 'yes' },
16
+ 'image/jpeg' => { preserve: 'yes', shelve: 'no', publish: 'no' },
17
+ 'audio/wav' => { preserve: 'yes', shelve: 'no', publish: 'no' },
18
+ 'audio/x-wav' => { preserve: 'yes', shelve: 'no', publish: 'no' },
19
+ 'audio/mp3' => { preserve: 'no', shelve: 'yes', publish: 'yes' },
20
+ 'audio/mpeg' => { preserve: 'no', shelve: 'yes', publish: 'yes' },
21
+ 'application/pdf' => { preserve: 'yes', shelve: 'yes', publish: 'yes' },
22
+ 'plain/text' => { preserve: 'yes', shelve: 'yes', publish: 'yes' },
23
+ 'text/plain' => { preserve: 'yes', shelve: 'yes', publish: 'yes' },
24
+ 'image/png' => { preserve: 'yes', shelve: 'yes', publish: 'no' },
25
+ 'application/zip' => { preserve: 'yes', shelve: 'no', publish: 'no' },
26
+ 'application/json' => { preserve: 'yes', shelve: 'yes', publish: 'yes' }
27
+ }.freeze
28
+
9
29
  # @param [Symbol] bundle
10
30
  # @param [Assembly::ObjectFile] file
11
31
  # @param style
@@ -28,7 +48,7 @@ module Assembly
28
48
  end
29
49
 
30
50
  def file_attributes(provided_file_attributes)
31
- file.file_attributes || provided_file_attributes[mimetype] || provided_file_attributes['default'] || Assembly::FILE_ATTRIBUTES[mimetype] || Assembly::FILE_ATTRIBUTES['default']
51
+ file.file_attributes || provided_file_attributes[mimetype] || provided_file_attributes['default'] || ATTRIBUTES_FOR_TYPE[mimetype] || ATTRIBUTES_FOR_TYPE['default']
32
52
  end
33
53
 
34
54
  def image_data
@@ -39,6 +39,7 @@ module Assembly
39
39
  resource_files.collect { |obj| ContentMetadata.special_dpg_folder?(obj.dpg_folder) }.include?(true)
40
40
  end
41
41
 
42
+ # rubocop:disable Metrics/CyclomaticComplexity
42
43
  def resource_type_descriptions
43
44
  # grab all of the file types within a resource into an array so we can decide what the resource type should be
44
45
  resource_file_types = resource_files.collect(&:object_type)
@@ -57,6 +58,8 @@ module Assembly
57
58
  resource_has_non_images ? 'object' : 'page'
58
59
  when :map
59
60
  'image'
61
+ when :document
62
+ 'document'
60
63
  when :'3d'
61
64
  resource_extensions = resource_files.collect(&:ext)
62
65
  if (resource_extensions & VALID_THREE_DIMENSION_EXTENTIONS).empty? # if this resource contains no known 3D file extensions, the resource type is file
@@ -66,6 +69,7 @@ module Assembly
66
69
  end
67
70
  end
68
71
  end
72
+ # rubocop:enable Metrics/CyclomaticComplexity
69
73
  end
70
74
  end
71
75
  end
@@ -4,6 +4,6 @@
4
4
  module Assembly
5
5
  class ObjectFile
6
6
  # Project version number
7
- VERSION = '1.9.0'
7
+ VERSION = '1.10.0'
8
8
  end
9
9
  end
@@ -2,610 +2,731 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Assembly::ContentMetadata do
6
- it 'generates valid content metadata with exif for a single tif and jp2 of style=simple_image, adding file attributes' do
7
- objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE), Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE)]
8
- result = described_class.create_content_metadata(druid: TEST_DRUID, add_exif: true, add_file_attributes: true, objects: objects)
9
- expect(result.class).to be String
10
- xml = Nokogiri::XML(result)
11
- expect(xml.errors.size).to be 0
12
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
13
- expect(xml.xpath('//resource').length).to be 2
14
- expect(xml.xpath('//resource/file').length).to be 2
15
- expect(xml.xpath('//resource/file/checksum').length).to be 4
16
- expect(xml.xpath('//resource/file/checksum')[0].text).to eq('8d11fab63089a24c8b17063d29a4b0eac359fb41')
17
- expect(xml.xpath('//resource/file/checksum')[1].text).to eq('a2400500acf21e43f5440d93be894101')
18
- expect(xml.xpath('//resource/file/checksum')[2].text).to eq('b965b5787e0100ec2d43733144120feab327e88c')
19
- expect(xml.xpath('//resource/file/checksum')[3].text).to eq('4eb54050d374291ece622d45e84f014d')
20
- expect(xml.xpath('//label').length).to be 2
21
- expect(xml.xpath('//label')[0].text).to match(/Image 1/)
22
- expect(xml.xpath('//label')[1].text).to match(/Image 2/)
23
- expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('image')
24
- expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('image')
25
- expect(xml.xpath('//resource/file')[0].attributes['size'].value).to eq('63542')
26
- expect(xml.xpath('//resource/file')[0].attributes['mimetype'].value).to eq('image/tiff')
27
- expect(xml.xpath('//resource/file')[0].attributes['publish'].value).to eq('no')
28
- expect(xml.xpath('//resource/file')[0].attributes['preserve'].value).to eq('yes')
29
- expect(xml.xpath('//resource/file')[0].attributes['shelve'].value).to eq('no')
30
- expect(xml.xpath('//resource/file/imageData')[0].attributes['width'].value).to eq('100')
31
- expect(xml.xpath('//resource/file/imageData')[0].attributes['height'].value).to eq('100')
32
- expect(xml.xpath('//resource/file')[1].attributes['size'].value).to eq('306')
33
- expect(xml.xpath('//resource/file')[1].attributes['mimetype'].value).to eq('image/jp2')
34
- expect(xml.xpath('//resource/file')[1].attributes['publish'].value).to eq('yes')
35
- expect(xml.xpath('//resource/file')[1].attributes['preserve'].value).to eq('no')
36
- expect(xml.xpath('//resource/file')[1].attributes['shelve'].value).to eq('yes')
37
- expect(xml.xpath('//resource/file/imageData')[1].attributes['width'].value).to eq('100')
38
- expect(xml.xpath('//resource/file/imageData')[1].attributes['height'].value).to eq('100')
39
- end
5
+ RSpec.describe Assembly::ContentMetadata do
6
+ describe '#create_content_metadata' do
7
+ subject(:result) { described_class.create_content_metadata(druid: TEST_DRUID, style: style, objects: objects) }
40
8
 
41
- 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
42
- obj1 = Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE)
43
- obj2 = Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE)
44
- obj3 = Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE2)
45
- obj1.file_attributes = { publish: 'no', preserve: 'no', shelve: 'no' }
46
- obj2.file_attributes = { publish: 'yes', preserve: 'yes', shelve: 'yes' }
47
- objects = [obj1, obj2, obj3]
48
- result = described_class.create_content_metadata(druid: TEST_DRUID, add_exif: false, add_file_attributes: true, objects: objects)
49
- expect(result.class).to be String
50
- xml = Nokogiri::XML(result)
51
- expect(xml.errors.size).to be 0
52
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
53
- expect(xml.xpath('//resource').length).to be 3
54
- expect(xml.xpath('//resource/file').length).to be 3
55
- expect(xml.xpath('//resource/file/checksum').length).to be 0
56
- expect(xml.xpath('//resource/file/imageData').length).to be 0
57
- expect(xml.xpath('//label').length).to be 3
58
- expect(xml.xpath('//label')[0].text).to match(/Image 1/)
59
- expect(xml.xpath('//label')[1].text).to match(/Image 2/)
60
- expect(xml.xpath('//label')[2].text).to match(/Image 3/)
61
- expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('image')
62
- expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('image')
63
- expect(xml.xpath('//resource')[2].attributes['type'].value).to eq('image')
64
- expect(xml.xpath('//resource/file')[0].attributes['publish'].value).to eq('no') # specificially set in object
65
- expect(xml.xpath('//resource/file')[0].attributes['preserve'].value).to eq('no') # specificially set in object
66
- expect(xml.xpath('//resource/file')[0].attributes['shelve'].value).to eq('no') # specificially set in object
67
- expect(xml.xpath('//resource/file')[1].attributes['publish'].value).to eq('yes') # specificially set in object
68
- expect(xml.xpath('//resource/file')[1].attributes['preserve'].value).to eq('yes') # specificially set in object
69
- expect(xml.xpath('//resource/file')[1].attributes['shelve'].value).to eq('yes') # specificially set in object
70
- expect(xml.xpath('//resource/file')[2].attributes['publish'].value).to eq('yes') # defaults by mimetype
71
- expect(xml.xpath('//resource/file')[2].attributes['preserve'].value).to eq('no') # defaults by mimetype
72
- expect(xml.xpath('//resource/file')[2].attributes['shelve'].value).to eq('yes') # defaults by mimetype
73
- end
9
+ let(:xml) { Nokogiri::XML(result) }
74
10
 
75
- it 'generates 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 = described_class.create_content_metadata(druid: TEST_DRUID, add_exif: true, add_file_attributes: true, objects: objects)
78
- expect(result.class).to be String
79
- xml = Nokogiri::XML(result)
80
- 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')
108
- end
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')
45
+ end
46
+ end
109
47
 
110
- 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
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 = described_class.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!/)
121
- end
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
81
+ end
82
+ end
122
83
 
123
- it 'generates 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 = 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
- expect(result.class).to be String
127
- xml = Nokogiri::XML(result)
128
- 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')
150
- end
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')
118
+ end
119
+ end
151
120
 
152
- 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
153
- objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE), Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE)]
154
- 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
- expect(result.class).to be String
156
- xml = Nokogiri::XML(result)
157
- 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
- (0..1).each do |i|
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')
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!/)
133
+ end
172
134
  end
173
- end
174
135
 
175
- 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
176
- objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE), Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE)]
177
- 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
- expect(result.class).to be String
179
- xml = Nokogiri::XML(result)
180
- 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
- (0..1).each do |i|
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')
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')
164
+ end
195
165
  end
196
- end
197
166
 
198
- it 'generates 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 = described_class.create_content_metadata(druid: TEST_DRUID, bundle: :filename, objects: objects)
201
- expect(result.class).to be String
202
- xml = Nokogiri::XML(result)
203
- 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
207
- expect(xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value).to eq('test.tif')
208
- expect(xml.xpath("//resource[@sequence='1']/file")[1].attributes['id'].value).to eq('test.jp2')
209
- expect(xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value).to eq('test2.tif')
210
- 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
- (0..1).each do |i|
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')
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')
188
+ end
189
+ end
217
190
  end
218
- end
219
191
 
220
- 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
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.to_s
223
- result = described_class.create_content_metadata(druid: test_druid, bundle: :dpg, objects: objects, include_root_xml: false)
224
- expect(result.class).to be String
225
- expect(result.include?('<?xml')).to be false
226
- xml = Nokogiri::XML(result)
227
- expect(xml.errors.size).to be 0
228
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
229
- expect(test_druid).to eq(TEST_DRUID)
230
- expect(xml.xpath('//contentMetadata')[0].attributes['objectId'].value).to eq(TEST_DRUID.to_s)
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
- (0..1).each do |i|
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')
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')
213
+ end
214
+ end
243
215
  end
244
- end
245
216
 
246
- 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
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 = described_class.create_content_metadata(druid: TEST_DRUID, style: :simple_book, bundle: :dpg, objects: objects, include_root_xml: false, flatten_folder_structure: true)
249
- expect(result.class).to be String
250
- expect(result.include?('<?xml')).to be false
251
- xml = Nokogiri::XML(result)
252
- 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.to_s)
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
- (0..1).each do |i|
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')
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')
237
+ end
238
+ end
269
239
  end
270
- 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')
273
- 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')
276
- end
277
240
 
278
- 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
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 = described_class.create_content_metadata(druid: test_druid, bundle: :dpg, objects: objects, style: :simple_book, flatten_folder_structure: true)
282
- expect(result.class).to be String
283
- expect(result.include?('<?xml')).to be true
284
- xml = Nokogiri::XML(result)
285
- 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)
288
- 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
- (0..1).each do |i|
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')
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')
265
+ end
266
+ end
305
267
  end
306
- 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')
309
- end
310
268
 
311
- 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
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 = described_class.create_content_metadata(druid: TEST_DRUID, bundle: :dpg, objects: objects, style: :book_with_pdf)
314
- expect(result.class).to be String
315
- xml = Nokogiri::XML(result)
316
- 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
328
- 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')
331
- 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')
334
- 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')
337
- end
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')
293
+ 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
+ end
301
+ end
338
302
 
339
- it 'generates 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 = described_class.create_content_metadata(druid: TEST_DRUID, bundle: :default, objects: objects)
342
- expect(result.class).to be String
343
- xml = Nokogiri::XML(result)
344
- 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
- (0..3).each do |i|
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')
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')
334
+ 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
+ end
358
339
  end
359
- end
360
340
 
361
- 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
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 = described_class.create_content_metadata(druid: TEST_DRUID, bundle: :default, objects: objects, preserve_common_paths: true)
364
- expect(result.class).to be String
365
- xml = Nokogiri::XML(result)
366
- 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
370
- expect(xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value).to eq(TEST_TIF_INPUT_FILE)
371
- expect(xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value).to eq(TEST_JP2_INPUT_FILE)
372
- 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
- (0..3).each do |i|
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')
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')
382
+ end
380
383
  end
381
- end
382
384
 
383
- it 'generates 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 = described_class.create_content_metadata(druid: TEST_DRUID, style: :file, objects: objects)
390
- expect(result.class).to be String
391
- xml = Nokogiri::XML(result)
392
- 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
- (0..3).each do |i|
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')
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')
405
+ end
406
+ end
405
407
  end
406
- end
407
408
 
408
- it 'generates 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 = described_class.create_content_metadata(druid: TEST_DRUID, style: :simple_book, objects: objects)
411
- expect(result.class).to be String
412
- xml = Nokogiri::XML(result)
413
- 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
- (0..1).each do |i|
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
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')
429
+ end
430
+ end
427
431
  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')
430
- end
431
432
 
432
- it 'generates 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 = described_class.create_content_metadata(druid: TEST_DRUID, style: :book_with_pdf, objects: objects)
435
- expect(result.class).to be String
436
- xml = Nokogiri::XML(result)
437
- 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')
449
- end
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')
456
+ end
457
+ end
458
+ end
450
459
 
451
- it 'generates 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 = described_class.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
- (0..1).each do |i|
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
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
480
+ 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
+ end
470
484
  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
485
 
475
- it 'generates 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 = described_class.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
- (0..1).each do |i|
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
486
+ 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)]
491
+ end
492
+ let(:style) { :book_with_pdf }
493
+
494
+ before do
495
+ allow(Deprecation).to receive(:warn)
496
+ end
497
+
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')
511
+ end
503
512
  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
513
 
508
- it 'does not generate valid content metadata if not all input files exist' do
509
- expect(File.exist?(TEST_TIF_INPUT_FILE)).to be true
510
- junk_file = '/tmp/flim_flam_floom.jp2'
511
- expect(File.exist?(junk_file)).to be false
512
- objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE), Assembly::ObjectFile.new(junk_file)]
513
- expect { described_class.create_content_metadata(druid: TEST_DRUID, objects: objects) }.to raise_error(RuntimeError, "File '#{junk_file}' not found")
514
- end
514
+ context 'when using style=book_as_image' do
515
+ let(:objects) do
516
+ [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE),
517
+ Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE2)]
518
+ end
515
519
 
516
- it 'generates valid content metadata for a 3d object with one 3d type files and three other supporting files (where one supporting file is a non-viewable but downloadable 3d file)' do
517
- 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)]
518
- result = described_class.create_content_metadata(druid: TEST_DRUID, style: :'3d', objects: objects)
519
- expect(result.class).to be String
520
- xml = Nokogiri::XML(result)
521
- expect(xml.errors.size).to be 0
522
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('3d')
523
- expect(xml.xpath('//resource').length).to be 4
524
- expect(xml.xpath('//resource/file').length).to be 4
525
- expect(xml.xpath('//label').length).to be 4
526
- expect(xml.xpath('//label')[0].text).to match(/3d 1/)
527
- expect(xml.xpath('//label')[1].text).to match(/File 1/)
528
- expect(xml.xpath('//label')[2].text).to match(/File 2/)
529
- expect(xml.xpath('//label')[3].text).to match(/File 3/)
530
- expect(xml.xpath('//resource/file/imageData').length).to be 0
531
- expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('3d')
532
- expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('file')
533
- expect(xml.xpath('//resource')[2].attributes['type'].value).to eq('file')
534
- expect(xml.xpath('//resource')[3].attributes['type'].value).to eq('file')
535
- end
520
+ let(:style) { :book_as_image }
521
+
522
+ before do
523
+ allow(Deprecation).to receive(:warn)
524
+ end
536
525
 
537
- it 'generates valid content metadata for images and associated text files, of style=simple_image using bundle=prebundled, and no exif data' do
538
- 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]]
539
- objects = files.collect { |resource| resource.collect { |file| Assembly::ObjectFile.new(file) } }
540
- result = described_class.create_content_metadata(druid: TEST_DRUID, bundle: :prebundled, style: :simple_image, objects: objects)
541
- expect(result.class).to be String
542
- xml = Nokogiri::XML(result)
543
- expect(xml.errors.size).to be 0
544
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
545
- expect(xml.xpath('//resource').length).to be 3
546
- expect(xml.xpath('//resource/file').length).to be 16
547
- expect(xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value).to eq('res1_image1.tif')
548
- expect(xml.xpath("//resource[@sequence='1']/file")[1].attributes['id'].value).to eq('res1_image1.jp2')
549
- expect(xml.xpath("//resource[@sequence='1']/file")[2].attributes['id'].value).to eq('res1_image2.tif')
550
- expect(xml.xpath("//resource[@sequence='1']/file")[3].attributes['id'].value).to eq('res1_image2.jp2')
551
- expect(xml.xpath("//resource[@sequence='1']/file")[4].attributes['id'].value).to eq('res1_teifile.txt')
552
- expect(xml.xpath("//resource[@sequence='1']/file")[5].attributes['id'].value).to eq('res1_textfile.txt')
553
- expect(xml.xpath("//resource[@sequence='1']/file")[6].attributes['id'].value).to eq('res1_transcript.pdf')
554
- expect(xml.xpath("//resource[@sequence='1']/file").length).to be 7
555
-
556
- expect(xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value).to eq('res2_image1.tif')
557
- expect(xml.xpath("//resource[@sequence='2']/file")[1].attributes['id'].value).to eq('res2_image1.jp2')
558
- expect(xml.xpath("//resource[@sequence='2']/file")[2].attributes['id'].value).to eq('res2_image2.tif')
559
- expect(xml.xpath("//resource[@sequence='2']/file")[3].attributes['id'].value).to eq('res2_image2.jp2')
560
- expect(xml.xpath("//resource[@sequence='2']/file")[4].attributes['id'].value).to eq('res2_teifile.txt')
561
- expect(xml.xpath("//resource[@sequence='2']/file")[5].attributes['id'].value).to eq('res2_textfile.txt')
562
- expect(xml.xpath("//resource[@sequence='2']/file").length).to be 6
563
-
564
- expect(xml.xpath("//resource[@sequence='3']/file")[0].attributes['id'].value).to eq('res3_image1.tif')
565
- expect(xml.xpath("//resource[@sequence='3']/file")[1].attributes['id'].value).to eq('res3_image1.jp2')
566
- expect(xml.xpath("//resource[@sequence='3']/file")[2].attributes['id'].value).to eq('res3_teifile.txt')
567
- expect(xml.xpath("//resource[@sequence='3']/file").length).to be 3
568
-
569
- expect(xml.xpath('//label').length).to be 3
570
- expect(xml.xpath('//resource/file/imageData').length).to be 0
571
- (0..2).each do |i|
572
- expect(xml.xpath('//label')[i].text).to eq("Image #{i + 1}")
573
- expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('image')
526
+ it 'generates valid content metadata for two tifs' do
527
+ expect(xml.errors.size).to eq 0
528
+ expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('book')
529
+ expect(xml.xpath('//resource').length).to eq 2
530
+ expect(xml.xpath('//resource/file').length).to eq 2
531
+ expect(xml.xpath('//label').length).to eq 2
532
+ expect(xml.xpath('//label')[0].text).to match(/Image 1/)
533
+ expect(xml.xpath('//label')[1].text).to match(/Image 2/)
534
+ expect(xml.xpath('//resource/file/imageData').length).to eq 0
535
+ (0..1).each do |i|
536
+ file = xml.xpath('//resource/file')[i]
537
+
538
+ expect(file.attributes['size']).to be_nil
539
+ expect(file.attributes['mimetype']).to be_nil
540
+ expect(file.attributes['publish']).to be_nil
541
+ expect(file.attributes['preserve']).to be_nil
542
+ expect(file.attributes['shelve']).to be_nil
543
+ end
544
+ expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('image')
545
+ expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('image')
546
+ end
574
547
  end
575
- end
576
548
 
577
- it 'generates role attributes for content metadata for a tif' do
578
- obj1 = Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE)
579
- obj1.file_attributes = { publish: 'no', preserve: 'no', shelve: 'no', role: 'master-role' }
580
- objects = [obj1]
581
- result = described_class.create_content_metadata(druid: TEST_DRUID, add_exif: false, add_file_attributes: true, objects: objects)
582
- expect(result.class).to be String
583
- xml = Nokogiri::XML(result)
584
- expect(xml.errors.size).to be 0
585
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
586
- expect(xml.xpath('//resource').length).to be 1
587
- expect(xml.xpath('//resource/file').length).to be 1
588
- expect(xml.xpath('//resource/file').length).to be 1
589
- expect(xml.xpath('//resource/file')[0].attributes['role'].value).to eq('master-role')
590
- end
549
+ context 'when using style=document' do
550
+ let(:objects) do
551
+ [Assembly::ObjectFile.new(TEST_PDF_FILE)]
552
+ end
591
553
 
592
- it 'generates content metadata even when no objects are passed in' do
593
- objects = []
594
- result = described_class.create_content_metadata(druid: TEST_DRUID, bundle: :prebundled, style: :file, objects: objects)
595
- expect(result.class).to be String
596
- xml = Nokogiri::XML(result)
597
- expect(xml.errors.size).to be 0
598
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('file')
599
- expect(xml.xpath('//resource').length).to be 0
600
- expect(xml.xpath('//resource/file').length).to be 0
601
- end
554
+ let(:style) { :document }
555
+
556
+ it 'generates valid content metadata' do
557
+ expect(xml.errors.size).to eq 0
558
+ expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('document')
559
+ expect(xml.xpath('//resource').length).to eq 1
560
+ expect(xml.xpath('//resource/file').length).to eq 1
561
+ expect(xml.xpath('//label').length).to eq 1
562
+ expect(xml.xpath('//label')[0].text).to match(/Document 1/)
563
+ expect(xml.xpath('//resource/file/imageData').length).to eq 0
564
+ file = xml.xpath('//resource/file').first
565
+ expect(file.attributes['size']).to be_nil
566
+ expect(file.attributes['mimetype']).to be_nil
567
+ expect(file.attributes['publish']).to be_nil
568
+ expect(file.attributes['preserve']).to be_nil
569
+ expect(file.attributes['shelve']).to be_nil
570
+ expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('document')
571
+ end
572
+ end
573
+
574
+ context 'when using user supplied checksums for two tifs and style=simple_book' do
575
+ it 'generates valid content metadata with no exif' do
576
+ obj1 = Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE)
577
+ obj1.provider_md5 = '123456789'
578
+ obj1.provider_sha1 = 'abcdefgh'
579
+ obj2 = Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE2)
580
+ obj2.provider_md5 = 'qwerty'
581
+ objects = [obj1, obj2]
582
+ result = described_class.create_content_metadata(druid: TEST_DRUID, style: :simple_book, objects: objects)
583
+ expect(result.class).to be String
584
+ xml = Nokogiri::XML(result)
585
+ expect(xml.errors.size).to eq 0
586
+ expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('book')
587
+ expect(xml.xpath('//resource').length).to eq 2
588
+ expect(xml.xpath('//resource/file').length).to eq 2
589
+ expect(xml.xpath('//resource/file/checksum').length).to eq 3
590
+ expect(xml.xpath('//label').length).to eq 2
591
+ expect(xml.xpath('//label')[0].text).to match(/Page 1/)
592
+ expect(xml.xpath('//label')[1].text).to match(/Page 2/)
593
+ expect(xml.xpath('//resource/file/imageData').length).to eq 0
594
+ expect(xml.xpath('//resource/file/checksum')[0].text).to eq('abcdefgh')
595
+ expect(xml.xpath('//resource/file/checksum')[1].text).to eq('123456789')
596
+ expect(xml.xpath('//resource/file/checksum')[2].text).to eq('qwerty')
597
+ (0..1).each do |i|
598
+ expect(xml.xpath('//resource/file')[i].attributes['size']).to be_nil
599
+ expect(xml.xpath('//resource/file')[i].attributes['mimetype']).to be_nil
600
+ expect(xml.xpath('//resource/file')[i].attributes['publish']).to be_nil
601
+ expect(xml.xpath('//resource/file')[i].attributes['preserve']).to be_nil
602
+ expect(xml.xpath('//resource/file')[i].attributes['shelve']).to be_nil
603
+ end
604
+ expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('page')
605
+ expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('page')
606
+ end
607
+ end
608
+
609
+ context 'when not all input files exist' do
610
+ it 'does not generate valid content metadata' do
611
+ expect(File.exist?(TEST_TIF_INPUT_FILE)).to be true
612
+ junk_file = '/tmp/flim_flam_floom.jp2'
613
+ expect(File.exist?(junk_file)).to be false
614
+ objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE), Assembly::ObjectFile.new(junk_file)]
615
+ expect { described_class.create_content_metadata(druid: TEST_DRUID, objects: objects) }.to raise_error(RuntimeError, "File '#{junk_file}' not found")
616
+ end
617
+ end
618
+
619
+ context 'when using a 3d object with one 3d type files and three other supporting files (where one supporting file is a non-viewable but downloadable 3d file)' do
620
+ let(:objects) do
621
+ [Assembly::ObjectFile.new(TEST_OBJ_FILE),
622
+ Assembly::ObjectFile.new(TEST_PLY_FILE),
623
+ Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE),
624
+ Assembly::ObjectFile.new(TEST_PDF_FILE)]
625
+ end
626
+ let(:style) { :'3d' }
627
+
628
+ it 'generates valid content metadata' do
629
+ expect(xml.errors.size).to eq 0
630
+ expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('3d')
631
+ expect(xml.xpath('//resource').length).to eq 4
632
+ expect(xml.xpath('//resource/file').length).to eq 4
633
+ expect(xml.xpath('//label').length).to eq 4
634
+ expect(xml.xpath('//label')[0].text).to match(/3d 1/)
635
+ expect(xml.xpath('//label')[1].text).to match(/File 1/)
636
+ expect(xml.xpath('//label')[2].text).to match(/File 2/)
637
+ expect(xml.xpath('//label')[3].text).to match(/File 3/)
638
+ expect(xml.xpath('//resource/file/imageData').length).to eq 0
639
+ expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('3d')
640
+ expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('file')
641
+ expect(xml.xpath('//resource')[2].attributes['type'].value).to eq('file')
642
+ expect(xml.xpath('//resource')[3].attributes['type'].value).to eq('file')
643
+ end
644
+ end
645
+
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
602
665
 
603
- it 'generates an error message when an unknown style is passed in' do
604
- objects = []
605
- expect do
606
- described_class.create_content_metadata(druid: TEST_DRUID, bundle: :prebundled, style: :borked, objects: objects)
607
- end.to raise_error { |error|
608
- expect(error.message).to eq('Supplied style (borked) not valid')
609
- }
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
+ context 'when providing file attributes' do
689
+ it 'generates role attributes for content metadata' do
690
+ obj1 = Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE)
691
+ obj1.file_attributes = { publish: 'no', preserve: 'no', shelve: 'no', role: 'master-role' }
692
+ objects = [obj1]
693
+ result = described_class.create_content_metadata(druid: TEST_DRUID, add_exif: false, add_file_attributes: true, objects: objects)
694
+ expect(result.class).to be String
695
+ xml = Nokogiri::XML(result)
696
+ expect(xml.errors.size).to eq 0
697
+ expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
698
+ expect(xml.xpath('//resource').length).to eq 1
699
+ expect(xml.xpath('//resource/file').length).to eq 1
700
+ expect(xml.xpath('//resource/file').length).to eq 1
701
+ expect(xml.xpath('//resource/file')[0].attributes['role'].value).to eq('master-role')
702
+ end
703
+ end
704
+
705
+ context 'when no objects are passed in' do
706
+ subject(:result) { described_class.create_content_metadata(druid: TEST_DRUID, bundle: :prebundled, style: style, objects: objects) }
707
+
708
+ let(:objects) { [] }
709
+
710
+ let(:style) { :file }
711
+
712
+ it 'generates content metadata even when no objects are passed in' do
713
+ expect(xml.errors.size).to eq 0
714
+ expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('file')
715
+ expect(xml.xpath('//resource').length).to eq 0
716
+ expect(xml.xpath('//resource/file').length).to eq 0
717
+ end
718
+ end
719
+
720
+ context 'when an unknown style is passed in' do
721
+ subject(:result) { described_class.create_content_metadata(druid: TEST_DRUID, bundle: :prebundled, style: style, objects: objects) }
722
+
723
+ let(:objects) { [] }
724
+
725
+ let(:style) { :borked }
726
+
727
+ it 'generates an error message' do
728
+ expect { result }.to raise_error 'Supplied style (borked) not valid'
729
+ end
730
+ end
610
731
  end
611
732
  end