talia_core 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. data/README.rdoc +41 -0
  2. data/bin/talia +33 -0
  3. data/lib/JXslt/jxslt.rb +60 -0
  4. data/lib/acts_as_roled.rb +11 -0
  5. data/lib/core_ext/platform.rb +9 -0
  6. data/lib/core_ext/string.rb +6 -0
  7. data/lib/core_ext.rb +1 -0
  8. data/lib/custom_template.rb +4 -0
  9. data/lib/loader_helper.rb +62 -0
  10. data/lib/mysql.rb +1214 -0
  11. data/lib/progressbar.rb +236 -0
  12. data/lib/role.rb +12 -0
  13. data/lib/talia_cl/command_line.rb +39 -0
  14. data/lib/talia_cl/commands/standalone/cl_options.rb +9 -0
  15. data/lib/talia_cl/commands/standalone/standalone_generate.rb +75 -0
  16. data/lib/talia_cl/commands/standalone.rb +25 -0
  17. data/lib/talia_cl/commands/talia_console/cl_options.rb +55 -0
  18. data/lib/talia_cl/commands/talia_console/console_commands.rb +37 -0
  19. data/lib/talia_cl/commands/talia_console/talia_commands.rb +131 -0
  20. data/lib/talia_cl/commands/talia_console.rb +47 -0
  21. data/lib/talia_cl/core_commands.rb +11 -0
  22. data/lib/talia_cl.rb +47 -0
  23. data/lib/talia_core/active_source.rb +372 -0
  24. data/lib/talia_core/active_source_parts/class_methods.rb +378 -0
  25. data/lib/talia_core/active_source_parts/predicate_handler.rb +89 -0
  26. data/lib/talia_core/active_source_parts/rdf.rb +131 -0
  27. data/lib/talia_core/active_source_parts/sql_helper.rb +36 -0
  28. data/lib/talia_core/active_source_parts/xml/base_builder.rb +47 -0
  29. data/lib/talia_core/active_source_parts/xml/generic_reader.rb +363 -0
  30. data/lib/talia_core/active_source_parts/xml/rdf_builder.rb +88 -0
  31. data/lib/talia_core/active_source_parts/xml/source_builder.rb +73 -0
  32. data/lib/talia_core/active_source_parts/xml/source_reader.rb +20 -0
  33. data/lib/talia_core/agent.rb +14 -0
  34. data/lib/talia_core/background_jobs/job.rb +82 -0
  35. data/lib/talia_core/background_jobs/progress_job.rb +68 -0
  36. data/lib/talia_core/collection.rb +13 -0
  37. data/lib/talia_core/data_types/data_loader.rb +92 -0
  38. data/lib/talia_core/data_types/data_record.rb +105 -0
  39. data/lib/talia_core/data_types/delayed_copier.rb +76 -0
  40. data/lib/talia_core/data_types/file_record.rb +59 -0
  41. data/lib/talia_core/data_types/file_store.rb +306 -0
  42. data/lib/talia_core/data_types/iip_data.rb +153 -0
  43. data/lib/talia_core/data_types/iip_loader.rb +127 -0
  44. data/lib/talia_core/data_types/image_data.rb +32 -0
  45. data/lib/talia_core/data_types/media_link.rb +19 -0
  46. data/lib/talia_core/data_types/mime_mapping.rb +45 -0
  47. data/lib/talia_core/data_types/path_helpers.rb +77 -0
  48. data/lib/talia_core/data_types/pdf_data.rb +42 -0
  49. data/lib/talia_core/data_types/simple_text.rb +36 -0
  50. data/lib/talia_core/data_types/temp_file_handling.rb +85 -0
  51. data/lib/talia_core/data_types/xml_data.rb +169 -0
  52. data/lib/talia_core/dc_resource.rb +20 -0
  53. data/lib/talia_core/dummy_handler.rb +34 -0
  54. data/lib/talia_core/dummy_source.rb +20 -0
  55. data/lib/talia_core/errors.rb +25 -0
  56. data/lib/talia_core/initializer.rb +427 -0
  57. data/lib/talia_core/ordered_source.rb +228 -0
  58. data/lib/talia_core/rails_ext/actionpack/action_controller/record_identifier.rb +13 -0
  59. data/lib/talia_core/rails_ext/actionpack/action_controller.rb +1 -0
  60. data/lib/talia_core/rails_ext/actionpack.rb +1 -0
  61. data/lib/talia_core/rails_ext.rb +1 -0
  62. data/lib/talia_core/rdf_import.rb +90 -0
  63. data/lib/talia_core/rdf_resource.rb +159 -0
  64. data/lib/talia_core/semantic_collection_item.rb +93 -0
  65. data/lib/talia_core/semantic_collection_wrapper.rb +324 -0
  66. data/lib/talia_core/semantic_property.rb +7 -0
  67. data/lib/talia_core/semantic_relation.rb +67 -0
  68. data/lib/talia_core/source.rb +323 -0
  69. data/lib/talia_core/source_transfer_object.rb +38 -0
  70. data/lib/talia_core/workflow/base.rb +15 -0
  71. data/lib/talia_core/workflow/publication_workflow.rb +62 -0
  72. data/lib/talia_core/workflow.rb +300 -0
  73. data/lib/talia_core.rb +9 -0
  74. data/lib/talia_dependencies.rb +12 -0
  75. data/lib/talia_util/bar_progressor.rb +15 -0
  76. data/lib/talia_util/configuration/config_file.rb +48 -0
  77. data/lib/talia_util/configuration/database_config.rb +40 -0
  78. data/lib/talia_util/configuration/mysql_database_setup.rb +104 -0
  79. data/lib/talia_util/data_import.rb +91 -0
  80. data/lib/talia_util/image_conversions.rb +82 -0
  81. data/lib/talia_util/import_job_helper.rb +132 -0
  82. data/lib/talia_util/io_helper.rb +54 -0
  83. data/lib/talia_util/progressable.rb +38 -0
  84. data/lib/talia_util/progressbar.rb +236 -0
  85. data/lib/talia_util/rdf_update.rb +80 -0
  86. data/lib/talia_util/some_sigla.xml +1960 -0
  87. data/lib/talia_util/test_helpers.rb +151 -0
  88. data/lib/talia_util/util.rb +226 -0
  89. data/lib/talia_util/yaml_import.rb +80 -0
  90. data/lib/talia_util.rb +13 -0
  91. data/lib/user.rb +116 -0
  92. data/lib/version.rb +15 -0
  93. data/test/core_ext/string_test.rb +11 -0
  94. data/test/custom_template_test.rb +8 -0
  95. data/test/talia_core/active_source_predicate_test.rb +54 -0
  96. data/test/talia_core/active_source_rdf_test.rb +89 -0
  97. data/test/talia_core/active_source_test.rb +631 -0
  98. data/test/talia_core/data_types/data_loader_test.rb +123 -0
  99. data/test/talia_core/data_types/data_record_test.rb +40 -0
  100. data/test/talia_core/data_types/file_record_test.rb +171 -0
  101. data/test/talia_core/data_types/iip_data_test.rb +130 -0
  102. data/test/talia_core/data_types/image_data_test.rb +88 -0
  103. data/test/talia_core/data_types/pdf_data_test.rb +68 -0
  104. data/test/talia_core/data_types/xml_data_test.rb +134 -0
  105. data/test/talia_core/generic_xml_test.rb +83 -0
  106. data/test/talia_core/initializer_test.rb +36 -0
  107. data/test/talia_core/ordered_source_test.rb +398 -0
  108. data/test/talia_core/rdf_resource_test.rb +115 -0
  109. data/test/talia_core/semantic_collection_item_test.rb +129 -0
  110. data/test/talia_core/source_reader_test.rb +33 -0
  111. data/test/talia_core/source_test.rb +484 -0
  112. data/test/talia_core/source_transfer_object_test.rb +24 -0
  113. data/test/talia_core/workflow/publication_workflow_test.rb +242 -0
  114. data/test/talia_core/workflow/user_class_for_workflow.rb +35 -0
  115. data/test/talia_core/workflow/workflow_base_test.rb +21 -0
  116. data/test/talia_core/workflow_test.rb +19 -0
  117. data/test/talia_util/import_job_helper_test.rb +46 -0
  118. data/test/test_helper.rb +68 -0
  119. metadata +262 -0
@@ -0,0 +1,123 @@
1
+ # Load the helper class
2
+ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
3
+
4
+ module TaliaCore
5
+ # Test the DataRecord storage class
6
+ class DataLoaderTest < Test::Unit::TestCase
7
+
8
+ fixtures :active_sources, :data_records
9
+
10
+ WEB_TEST_URL = 'http://net7sviluppo.com/talia_test_files/'
11
+
12
+ def setup
13
+ setup_once(:web_test) do
14
+ web_test_good = false
15
+ begin
16
+ open(WEB_TEST_URL + 'generic_test.xml') do |io|
17
+ io.read
18
+ end
19
+ web_test_good = true
20
+ rescue
21
+ puts "*** Cannot find: #{WEB_TEST_URL + 'generic_test.xml'}, web loading test will be disabled!"
22
+ end
23
+ web_test_good
24
+ end
25
+ end
26
+
27
+ def test_create_from_file
28
+ loaded = DataTypes::FileRecord.create_from_url(fixture_file('generic_test.xml'))
29
+ assert_equal(1, loaded.size)
30
+ assert_kind_of(DataTypes::XmlData, loaded.first)
31
+ end
32
+
33
+ def test_options
34
+ loaded = DataTypes::FileRecord.create_from_url(fixture_file('generic_test.xml'), :location => 'foo.xml', :mime_type => 'application/pdf')
35
+ assert_equal(1, loaded.size)
36
+ assert_equal('foo.xml', loaded.first.location)
37
+ assert_equal('application/pdf', loaded.first.mime)
38
+ end
39
+
40
+ def test_data_loaded
41
+ loaded = DataTypes::FileRecord.create_from_url(fixture_file('generic_test.xml')).first
42
+ loaded.source = active_sources(:something)
43
+ loaded.save!
44
+ File.open(fixture_file('generic_test.xml')) do |io|
45
+ assert_equal(io.read, loaded.all_text)
46
+ end
47
+ end
48
+
49
+ def test_create_from_web
50
+ return unless(@web_test)
51
+ loaded = DataTypes::FileRecord.create_from_url(WEB_TEST_URL + 'generic_test.xml')
52
+ assert_equal(1, loaded.size)
53
+ loaded = loaded.first
54
+ loaded.source = active_sources(:something)
55
+ loaded.save!
56
+ File.open(fixture_file('generic_test.xml')) do |io|
57
+ assert_equal(io.read, loaded.all_text)
58
+ end
59
+ end
60
+
61
+ def test_create_from_image
62
+ loaded = DataTypes::FileRecord.create_from_url(fixture_file('tiny.jpg'))
63
+ assert_equal(2, loaded.size)
64
+ assert_equal([DataTypes::IipData, DataTypes::ImageData], loaded.collect { |t| t.class })
65
+ assert_equal('tiny.jpg', loaded.last.location)
66
+ end
67
+
68
+ def test_web_create_from_image
69
+ return unless(@web_test)
70
+ loaded = DataTypes::FileRecord.create_from_url(WEB_TEST_URL + 'tiny.jpg')
71
+ assert_equal(2, loaded.size)
72
+ assert_equal([DataTypes::IipData, DataTypes::ImageData], loaded.collect { |t| t.class })
73
+ assert_equal('tiny.jpg', loaded.last.location)
74
+ end
75
+
76
+ def test_image_creation
77
+ loaded = DataTypes::FileRecord.create_from_url(fixture_file('tiny.jpg')).last
78
+ loaded.source = active_sources(:something)
79
+ loaded.save!
80
+ assert_equal(loaded.all_bytes, File.open(fixture_file('tiny.jpg')) { |io| io.read.unpack("C*") } )
81
+ end
82
+
83
+ def test_web_image_creation
84
+ return unless(@web_test)
85
+ loaded = DataTypes::FileRecord.create_from_url(WEB_TEST_URL + 'tiny.jpg').last
86
+ loaded.source = active_sources(:something)
87
+ loaded.save!
88
+ assert_equal(loaded.all_bytes, File.open(fixture_file('tiny.jpg')) { |io| io.read.unpack("C*") } )
89
+ end
90
+
91
+ def test_create_from_image_and_convert
92
+ loaded = DataTypes::FileRecord.create_from_url(fixture_file('tiny.gif'))
93
+ assert_equal(2, loaded.size)
94
+ assert_equal([DataTypes::IipData, DataTypes::ImageData], loaded.collect { |t| t.class })
95
+ loaded.each { |element| element.source = active_sources(:something) ; element.save! }
96
+ assert_equal('image/png', loaded.last.mime)
97
+ assert_equal('tiny.png', loaded.last.location)
98
+ end
99
+
100
+ def test_web_create_from_image_and_convert
101
+ return unless(@web_test)
102
+ loaded = DataTypes::FileRecord.create_from_url(WEB_TEST_URL + 'tiny.gif')
103
+ assert_equal(2, loaded.size)
104
+ assert_equal([DataTypes::IipData, DataTypes::ImageData], loaded.collect { |t| t.class })
105
+ loaded.each { |element| element.source = active_sources(:something) ; element.save! }
106
+ assert_equal('image/png', loaded.last.mime)
107
+ assert_equal('tiny.png', loaded.last.location)
108
+ end
109
+
110
+ def test_convert_original_method
111
+ assert(DataTypes::FileRecord.convert_original?(Mime::Type.lookup('image/tiff')))
112
+ assert(!DataTypes::FileRecord.convert_original?(Mime::Type.lookup('image/jpeg')))
113
+ assert(!DataTypes::FileRecord.convert_original?(:jpeg))
114
+ end
115
+
116
+ private
117
+
118
+ def fixture_file(name)
119
+ @fixture_files = File.join(Test::Unit::TestCase.fixture_path, name)
120
+ end
121
+
122
+ end
123
+ end
@@ -0,0 +1,40 @@
1
+ # Load the helper class
2
+ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
3
+
4
+ module TaliaCore
5
+ # Test the DataRecord storage class
6
+ class DataRecordTest < Test::Unit::TestCase
7
+
8
+ fixtures :active_sources, :data_records
9
+
10
+ def setup
11
+ @test_records = DataTypes::DataRecord.find_data_records(Fixtures.identify(:something))
12
+
13
+ @image_mime_types = ['image/gif', 'image/jpeg', 'image/png', 'image/tiff', 'image/bmp']
14
+ end
15
+
16
+ # test not nil and records numbers
17
+ def test_records_numbers
18
+ assert_not_equal [], @test_records
19
+ assert_equal 15, @test_records.size
20
+ end
21
+
22
+ # test class type and mime_type
23
+ def test_mime_types
24
+ assert_kind_of(DataTypes::SimpleText, @test_records[0])
25
+ assert_kind_of(DataTypes::SimpleText, @test_records[1])
26
+ assert_equal("text/plain", @test_records[0].mime_type)
27
+ assert_equal("text/plain", @test_records[1].mime_type)
28
+ end
29
+
30
+
31
+
32
+ # test for specific classes methods
33
+ def test_specific_classes_methods
34
+ # Get a line
35
+ line = "LINE1: This is a simple text to check the DataRecords class\n"
36
+ assert_equal(line, @test_records[0].get_line)
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,171 @@
1
+ require 'test/unit'
2
+ require 'fileutils'
3
+
4
+ # Load the helper class
5
+ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
6
+
7
+ class UploadedFile < File
8
+ include ActionController::UploadedFile
9
+ attr_accessor_with_default(:content_type) { 'text/plain' }
10
+ alias_method :original_path, :path
11
+
12
+ def size
13
+ self.class.size(original_path)
14
+ end
15
+ end
16
+
17
+ module TaliaCore
18
+
19
+ # Test the DataRecord storage class
20
+ class FileRecordTest < Test::Unit::TestCase
21
+
22
+ fixtures :active_sources, :data_records
23
+
24
+ def setup
25
+ @test_records = DataTypes::DataRecord.find_data_records(Fixtures.identify(:something))
26
+ end
27
+
28
+ def test_create_from_data
29
+ create_from do |record|
30
+ record.create_from_data('loc', 'abc')
31
+ end
32
+ end
33
+
34
+ def test_create_from_file_and_delete
35
+ from_file = File.join(File.dirname(__FILE__), '..', '..', 'data_for_test', 'test_source_file')
36
+ tmp_file = File.join(File.dirname(__FILE__), '..', '..', 'data_for_test', 'test_source_file_copy')
37
+ FileUtils.copy(from_file, tmp_file)
38
+ assert(File.exist?(tmp_file))
39
+ create_from do |record|
40
+ record.create_from_file('loc', tmp_file, true)
41
+ end
42
+ assert(!File.exist?(tmp_file))
43
+ end
44
+
45
+ def test_create_from_file
46
+ create_from do |record|
47
+ from_file = File.join(File.dirname(__FILE__), '..', '..', 'data_for_test', 'test_source_file')
48
+ record.create_from_file('loc', from_file)
49
+ end
50
+ end
51
+
52
+ def test_extract_filename
53
+ assert_equal('1', DataTypes::FileRecord.extract_filename(file))
54
+ end
55
+
56
+ def test_file_should_always_return_nil
57
+ assert_nil(DataTypes::FileRecord.new.file)
58
+ end
59
+
60
+ def test_full_filename
61
+ data_record = DataTypes::FileRecord.new do |dr|
62
+ dr.source_id = 1
63
+ dr.location = 'image.jpg'
64
+ dr.assign_type 'image/jpeg'
65
+ end
66
+ data_record.save
67
+ expected = File.expand_path(File.join(File.dirname(__FILE__), '..','..', 'data_for_test', 'FileRecord', ("00" + data_record.id.to_s)[-3..-1], data_record.id.to_s)) #File.join(DataTypes::DataRecord.data_path, data_record.type, data_record.location)
68
+ assert_equal(expected, data_record.send(:full_filename))
69
+ end
70
+
71
+
72
+ def test_paths
73
+ tempfile_path = File.join(TALIA_ROOT, 'tmp', 'data_records')
74
+ data_path = File.join(TALIA_ROOT, 'data')
75
+ assert_equal(tempfile_path, DataTypes::FileRecord.tempfile_path)
76
+ assert_equal(tempfile_path, DataTypes::FileRecord.new.send(:tempfile_path))
77
+ assert_equal(data_path, DataTypes::FileRecord.data_path)
78
+ assert_equal(data_path, DataTypes::FileRecord.new.send(:data_path))
79
+ end
80
+
81
+ # test binary access
82
+ def test_binary_access
83
+ # Check initial position
84
+ assert_equal(0, @test_records[0].position)
85
+
86
+ # Try to read all bytes
87
+ bytes = @test_records[0].all_bytes
88
+ assert_equal(180, bytes.size)
89
+ assert_equal(false, @test_records[0].is_file_open?)
90
+
91
+ # Re-check position (it should be 0)
92
+ assert_equal(0, @test_records[0].position)
93
+
94
+ # Read only one bytes and check position
95
+ byte = @test_records[0].get_byte
96
+ # check byte by code (76 == 'L')
97
+ assert_equal(76, byte)
98
+ # Re-check position (it should be 1)
99
+ assert_equal(1, @test_records[0].position)
100
+ end
101
+
102
+ # test data directory
103
+ def test_data_directory
104
+ dir_for_test = File.expand_path(@test_records[0].data_directory)
105
+ assert_equal(data_path_test(@test_records[0].id), dir_for_test)
106
+ assert( File.exists?(dir_for_test) )
107
+ assert_equal('temp1.txt', @test_records[0].location)
108
+ assert( File.exists?(File.join(data_path_test(@test_records[0]),@test_records[0].id.to_s)), "#{File.join(data_path_test(@test_records[0]), @test_records[0].id.to_s)} does not exist" )
109
+ end
110
+
111
+ def test_should_find_or_create_and_assign_file
112
+ # FIXME: I use #file and #source_id instead of fixtures,
113
+ # due to unpredictable ids assignment.
114
+ # Because test process doesn't drop tables, but just empty and re-fill them.
115
+ params = {:file => file, :source_id => source_id}
116
+ assert(DataTypes::FileRecord.find_or_create_and_assign_file(params))
117
+ end
118
+
119
+ # test file size
120
+ def test_file_size
121
+ assert_equal(180, @test_records[0].size)
122
+ end
123
+
124
+
125
+ def test_should_save_attachment
126
+ assert(!DataTypes::FileRecord.new.send(:save_attachment?))
127
+ data_record = DataTypes::FileRecord.new do |dr|
128
+ dr.file = file
129
+ end
130
+ assert(data_record.send(:save_attachment?))
131
+ end
132
+
133
+ private
134
+ def data_path_test(id=nil)
135
+ @data_path_test ||= File.expand_path(File.join(File.dirname(__FILE__), '..','..', 'data_for_test', 'SimpleText', ("00" + id.to_s)[-3..-1]))
136
+ end
137
+
138
+ def file
139
+ UploadedFile.new(File.join(data_path_test(DataTypes::DataRecord.find(:first).id), DataTypes::DataRecord.find(:first).id.to_s))
140
+ end
141
+
142
+
143
+ def source_id
144
+ Source.find(:first)[:id]
145
+ end
146
+
147
+ def create_from(expected_content = 'abc')
148
+ data_record = DataTypes::FileRecord.new
149
+ yield(data_record)
150
+ data_record.source = TaliaCore::Source.find(:first)
151
+ data_record.save!
152
+ new_rec = DataTypes::DataRecord.find(data_record.id)
153
+ assert_equal(expected_content, new_rec.content_string)
154
+ end
155
+
156
+ def test_class_type_from
157
+ ['text/plain'].each do |mime|
158
+ assert_equal('SimpleText', DataTypes::FileRecord.class_type_from(mime))
159
+ end
160
+
161
+ @image_mime_types.each { |mime| assert_equal('ImageData', DataTypes::FileRecord.class_type_from(mime)) }
162
+
163
+ ['text/xml', 'application/xml'].each do |mime|
164
+ assert_equal('XmlData', DataTypes::FileRecord.class_type_from(mime))
165
+ end
166
+
167
+ assert_equal('DataRecord', DataTypes::FileRecord.class_type_from('application/rtf'))
168
+ end
169
+
170
+ end
171
+ end
@@ -0,0 +1,130 @@
1
+ require 'test/unit'
2
+
3
+ # Load the helper class
4
+ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
5
+
6
+ module TaliaCore
7
+ module DataType
8
+
9
+ # Test the DataRecord storage class
10
+ class IipDataTest < Test::Unit::TestCase
11
+
12
+ fixtures :active_sources, :data_records
13
+
14
+ def setup
15
+ # Sets the file that is used by one test
16
+ @test_record = data_records(:fifteen)
17
+ end
18
+
19
+ def teardown
20
+ # remove all subdirectory of iip root
21
+ Dir.foreach(TaliaCore::CONFIG["iip_root_directory_location"]) do |entry|
22
+ path = File.join(TaliaCore::CONFIG["iip_root_directory_location"], entry)
23
+ if(!['.', '..', '.svn'].include?(entry) && File.exist?(path))
24
+ FileUtils.remove_dir(path)
25
+ end
26
+ end
27
+ end
28
+
29
+ def test_get_static_path
30
+ TaliaCore::CONFIG['static_data_prefix'] = nil
31
+ assert_nil(@test_record.static_path)
32
+ TaliaCore::CONFIG['static_data_prefix'] = 'preef'
33
+ assert_equal((N::LOCAL + 'preef/IipData/015/15').to_s, @test_record.static_path)
34
+ end
35
+
36
+ # test class type and mime_type and subtype
37
+ def test_mime_types
38
+ assert_kind_of DataTypes::IipData, @test_record
39
+ assert_equal 'image/tiff', @test_record.mime_type
40
+ end
41
+
42
+ # test data directory
43
+ def test_data_directory
44
+ dir_for_test = File.expand_path(@test_record.data_directory)
45
+ assert_equal(base_dir_name(@test_record.id), dir_for_test)
46
+ assert(File.exists?(dir_for_test))
47
+ assert_equal('PATH/TO/IIPSERVER', @test_record.location)
48
+ assert_equal('PATH/TO/IIPSERVER', @test_record.iip_server_path)
49
+ assert(File.exists?(File.join(dir_for_test, @test_record.id.to_s)), "#{File.join(dir_for_test, @test_record.id.to_s)} does not exist" )
50
+ end
51
+
52
+ # test file size
53
+ def test_file_size
54
+ assert_equal(711, @test_record.size)
55
+ end
56
+
57
+ # test binary access
58
+ def test_binary_access
59
+ # Check initial position
60
+ assert_equal(0, @test_record.position)
61
+
62
+ # Try to read all bytes
63
+ bytes = @test_record.all_bytes
64
+ assert_equal(711, bytes.size)
65
+ assert_equal(false, @test_record.is_file_open?)
66
+
67
+ # Try to read all bytes by alias method
68
+ bytes = @test_record.get_thumbnail
69
+ assert_equal(711, bytes.size)
70
+ assert_equal(false, @test_record.is_file_open?)
71
+
72
+ # Re-check position (it should be 0)
73
+ assert_equal(0, @test_record.position)
74
+ end
75
+
76
+ # test create from data method
77
+ def test_create_from_data
78
+ data = @test_record.all_text
79
+
80
+ creation_test do |record|
81
+ record.create_from_data('', data)
82
+ end
83
+ end
84
+
85
+ def test_create_from_file
86
+ creation_test do |record|
87
+ data_file = File.join(File.dirname(__FILE__), '..', '..', 'data_for_test', 'test.jpg')
88
+ record.create_from_file('', data_file)
89
+ end
90
+ end
91
+
92
+ def test_create_from_existing
93
+ creation_test do |record|
94
+ data_file = File.join(File.dirname(__FILE__), '..', '..', 'data_for_test', 'test.jpg')
95
+ data_file = File.expand_path(data_file)
96
+ record.create_from_existing(data_file, data_file)
97
+ end
98
+ end
99
+
100
+ private
101
+ def base_dir_name(id=nil)
102
+ @data_path_test ||= File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'data_for_test', 'IipData', ("00" + id.to_s)[-3..-1]))
103
+ end
104
+
105
+ def creation_test
106
+ new_record = DataTypes::IipData.new
107
+ new_record.location = ''
108
+ new_record.source_id = "something"
109
+ yield(new_record)
110
+ new_record.save!
111
+
112
+ # Try to read all bytes by alias method
113
+ bytes = new_record.get_thumbnail
114
+ assert(bytes.size > 100)
115
+ assert_equal(false, new_record.is_file_open?)
116
+ # Check if the mime was written correctly
117
+ assert_equal('image/gif', DataTypes::IipData.find(new_record.id).mime_type)
118
+
119
+ assert(File.exists?(new_record.file_path))
120
+
121
+ # delete record and file
122
+ File.delete(new_record.file_path)
123
+ Dir.delete new_record.data_directory
124
+ DataTypes::IipData.delete new_record.id
125
+ end
126
+
127
+ end
128
+
129
+ end
130
+ end
@@ -0,0 +1,88 @@
1
+ require 'test/unit'
2
+
3
+ # Load the helper class
4
+ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
5
+
6
+ module TaliaCore
7
+
8
+ # Test the DataRecord storage class
9
+ class ImageDataTest < Test::Unit::TestCase
10
+
11
+ fixtures :active_sources, :data_records
12
+
13
+ def setup
14
+ @test_records = DataTypes::DataRecord.find_data_records(Fixtures.identify(:something))
15
+ end
16
+
17
+ # test not nil and records numbers
18
+ def test_records_numbers
19
+ assert_not_equal [], @test_records
20
+ assert_equal 15, @test_records.size
21
+ end
22
+
23
+ # test class type and mime_type and subtype
24
+ def test_mime_types
25
+ assert_kind_of(DataTypes::ImageData, @test_records[7])
26
+ assert_kind_of(DataTypes::ImageData, @test_records[8])
27
+ assert_kind_of(DataTypes::ImageData, @test_records[9])
28
+ assert_kind_of(DataTypes::ImageData, @test_records[10])
29
+ assert_kind_of(DataTypes::ImageData, @test_records[11])
30
+ assert_kind_of(DataTypes::ImageData, @test_records[12])
31
+ assert_equal("image/bmp", @test_records[7].mime_type)
32
+ assert_equal("image/fits", @test_records[8].mime_type)
33
+ assert_equal("image/gif", @test_records[9].mime_type)
34
+ assert_equal("image/jpeg", @test_records[10].mime_type)
35
+ assert_equal("image/png", @test_records[11].mime_type)
36
+ assert_equal("image/tiff", @test_records[12].mime_type)
37
+ end
38
+
39
+ # test data directory
40
+ def test_data_directory
41
+ #base_dir_name = File.expand_path(File.join(File.dirname(__FILE__), '..', '..' , 'data_for_test', 'ImageData'))
42
+ dir_for_test = File.expand_path(@test_records[7].data_directory)
43
+ assert_equal(base_dir_name(@test_records[7].id), dir_for_test)
44
+ assert(File.exists?(dir_for_test))
45
+ assert_equal(File.join(base_dir_name(@test_records[7].id), 'temp1.bmp'), File.join(dir_for_test, @test_records[7].location))
46
+ assert( File.exists?(File.join(dir_for_test, @test_records[7].id.to_s)), "#{File.join(dir_for_test, @test_records[7].id.to_s)} does not exist" )
47
+ end
48
+
49
+ # test file size
50
+ def test_file_size
51
+ assert_equal(1254, @test_records[7].size)
52
+ end
53
+
54
+ # test binary access
55
+ def test_binary_access
56
+ # Check initial position
57
+ assert_equal(0, @test_records[7].position)
58
+
59
+ # Try to read all bytes
60
+ bytes = @test_records[7].all_bytes
61
+ assert_equal(1254, bytes.size)
62
+ assert_equal(false, @test_records[7].is_file_open?)
63
+
64
+
65
+ # Re-check position (it should be 0)
66
+ assert_equal(0, @test_records[7].position)
67
+ end
68
+
69
+ def test_attach_image
70
+ test_uri = 'http://testy.com/image_attach'
71
+ src = Source.new(test_uri)
72
+ data_record = DataTypes::ImageData.new do |dr|
73
+ dr.location = 'my_file.jpg'
74
+ end
75
+ src.data_records << data_record
76
+ src.save!
77
+ rel = Source.find(src.id)
78
+ assert_equal(1, rel.data_records.size)
79
+ assert_kind_of(DataTypes::ImageData, rel.data_records[0])
80
+ end
81
+
82
+ private
83
+ def base_dir_name(id=nil)
84
+ @data_path_test ||= File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'data_for_test', 'ImageData', ("00" + id.to_s)[-3..-1]))
85
+ end
86
+ end
87
+ end
88
+
@@ -0,0 +1,68 @@
1
+ require 'test/unit'
2
+
3
+ # Load the helper class
4
+ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
5
+
6
+ module TaliaCore
7
+ module DataType
8
+
9
+ # Test the DataRecord storage class
10
+ class PdfDataTest < Test::Unit::TestCase
11
+
12
+ fixtures :active_sources, :data_records
13
+
14
+ def setup
15
+ # Sets the file that is used by one test
16
+ @test_records = DataTypes::DataRecord.find_data_records(Fixtures.identify(:something))
17
+ end
18
+
19
+ # test not nil and records numbers
20
+ def test_records_numbers
21
+ assert_not_equal [], @test_records
22
+ assert_equal 15, @test_records.size
23
+ end
24
+
25
+ # test class type and mime_type and subtype
26
+ def test_mime_types
27
+ assert_kind_of DataTypes::PdfData, @test_records[13]
28
+ assert_equal 'application/pdf', @test_records[13].mime_type
29
+ end
30
+
31
+ # test data directory
32
+ def test_data_directory
33
+ dir_for_test = File.expand_path(@test_records[13].data_directory)
34
+ assert_equal(base_dir_name(@test_records[13].id), dir_for_test)
35
+ assert(File.exists?(dir_for_test))
36
+ assert_equal(File.join(base_dir_name(@test_records[13].id), 'temp1.pdf'), File.join(dir_for_test, @test_records[13].location))
37
+ assert( File.exists?(File.join(dir_for_test, @test_records[13].id.to_s)), "#{File.join(dir_for_test, @test_records[13].id.to_s)} does not exist" )
38
+ end
39
+
40
+ # test file size
41
+ def test_file_size
42
+ assert_equal(104463, @test_records[13].size)
43
+ end
44
+
45
+ # test binary access
46
+ def test_binary_access
47
+ # Check initial position
48
+ assert_equal(0, @test_records[13].position)
49
+
50
+ # Try to read all bytes
51
+ bytes = @test_records[13].all_bytes
52
+ assert_equal(104463, bytes.size)
53
+ assert_equal(false, @test_records[13].is_file_open?)
54
+
55
+
56
+ # Re-check position (it should be 0)
57
+ assert_equal(0, @test_records[13].position)
58
+ end
59
+
60
+ private
61
+ def base_dir_name(id=nil)
62
+ @data_path_test ||= File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'data_for_test', 'PdfData', ("00" + id.to_s)[-3..-1]))
63
+ end
64
+
65
+ end
66
+
67
+ end
68
+ end