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,631 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
+
3
+ module TaliaCore
4
+
5
+ class SingularAccessorTest < ActiveSource
6
+ singular_property :siglum, N::RDFS.siglum
7
+ has_rdf_type N::TALIA.foo
8
+ end
9
+
10
+ # Test the ActiveSource
11
+ class ActiveSourceTest < Test::Unit::TestCase
12
+ fixtures :active_sources, :semantic_properties, :semantic_relations
13
+
14
+ N::Namespace.shortcut(:as_test_preds, 'http://testvalue.org/')
15
+
16
+ def setup
17
+ setup_once(:flush) do
18
+ TaliaUtil::Util.flush_rdf
19
+ true
20
+ end
21
+
22
+ setup_once(:data_source) do
23
+ data_source = ActiveSource.new("http://www.test.org/source_with_data")
24
+ text = DataTypes::SimpleText.new
25
+ text.location = "text.txt"
26
+ image = DataTypes::ImageData.new
27
+ image.location = "image.jpg"
28
+ data_source.data_records << text
29
+ data_source.data_records << image
30
+ data_source.save!
31
+ data_source
32
+ end
33
+
34
+ end
35
+
36
+ def test_has_type
37
+ facs = ActiveSource.new('http://facsimile/has_type_test')
38
+ facs.types << N::HYPER.testtype
39
+ assert(facs.has_type?(N::HYPER.testtype))
40
+ end
41
+
42
+
43
+ def test_exists
44
+ assert_not_nil(ActiveSource.find(:first))
45
+ end
46
+
47
+ def test_create_existing
48
+ src = ActiveSource.new(active_sources(:testy).uri)
49
+ assert_equal(src, active_sources(:testy))
50
+ assert(!src.new_record?)
51
+ end
52
+
53
+ def test_create_new
54
+ src_uri = 'http://foobarxxx.com/imallnew'
55
+ src = ActiveSource.new(src_uri)
56
+ assert_equal(src_uri, src.uri)
57
+ assert(src.new_record?)
58
+ end
59
+
60
+ def test_create_vanilla
61
+ src = ActiveSource.new
62
+ # Somehow this gives different results for JRuby/Ruby
63
+ assert(src.uri == nil || src.uri == '')
64
+ assert(src.new_record?)
65
+ end
66
+
67
+ def test_accessor
68
+ assert_equal(3, active_sources(:multirel)['http://testvalue.org/multirel'].size)
69
+ assert_equal(1, active_sources(:multirel)['http://testvalue.org/multi_b'].size)
70
+ end
71
+
72
+ def test_delete
73
+ del = active_sources(:deltest)
74
+ assert_equal(2, del['http://testvalue.org/delete_test'].size)
75
+ del["http://testvalue.org/delete_test"].remove("Delete Me!")
76
+ del.save!
77
+ assert_equal(1, active_sources(:deltest)["http://testvalue.org/delete_test"].size)
78
+ end
79
+
80
+ def test_delete_relation
81
+ del = active_sources(:deltest_rel)
82
+ assert_equal(2, del['http://testvalue.org/delete_test'].size)
83
+ del['http://testvalue.org/delete_test'].remove(active_sources(:deltest_rel_target1))
84
+ del.save
85
+ assert_equal(1, active_sources(:deltest_rel)["http://testvalue.org/delete_test"].size)
86
+ end
87
+
88
+ def test_accessor_tripledup
89
+ assert_equal(2, active_sources(:duplicator)['http://testvalue.org/dup_rel'].size)
90
+ end
91
+
92
+ def test_accessor_tripledup_delete
93
+ dupey = active_sources(:dup_for_delete)
94
+ dupdouble = TaliaCore::ActiveSource.find(dupey.uri)
95
+ assert_equal(2, dupey['http://testvalue.org/dup_rel'].size)
96
+ dupey['http://testvalue.org/dup_rel'].remove(active_sources(:testy))
97
+ assert_equal(1, dupey['http://testvalue.org/dup_rel'].size)
98
+ dupey.save!
99
+ assert_equal(1, dupdouble['http://testvalue.org/dup_rel'].size)
100
+ assert_equal(1, dupey['http://testvalue.org/dup_rel'].size)
101
+ dupey['http://testvalue.org/dup_rel'].remove(active_sources(:testy))
102
+ assert_equal(0, active_sources(:dup_for_delete)['http://testvalue.org/dup_rel'].size)
103
+ dupey.save!
104
+ assert_equal(0, active_sources(:dup_for_delete)['http://testvalue.org/dup_rel'].size)
105
+ end
106
+
107
+ def test_uri
108
+ assert_equal("http://testy.com/testme/hard", active_sources(:testy).uri)
109
+ end
110
+
111
+ def test_to_s
112
+ assert_equal active_sources(:testy).uri, active_sources(:testy).to_s
113
+ end
114
+
115
+ def test_create
116
+ src = ActiveSource.new
117
+ src.uri = "http://www.testy.org/create_test"
118
+ src.save!
119
+ assert_equal(1, ActiveSource.find(:all, :conditions => { :uri => "http://www.testy.org/create_test" } ).size)
120
+ end
121
+
122
+ def test_associate
123
+ test_src = active_sources(:assoc_test)
124
+ test_src["http://foo/assoc_test"] << active_sources(:assoc_test_target)
125
+ test_src["http://bar/assoc_test_prop"] << 'Test Value'
126
+ test_src.save!
127
+ assert_equal(1, test_src["http://foo/assoc_test"].size)
128
+ assert_equal(1, active_sources(:assoc_test)["http://foo/assoc_test"].size)
129
+ assert_equal(1, active_sources(:assoc_test)["http://bar/assoc_test_prop"].size)
130
+ active_sources(:assoc_test).save!
131
+ assert_equal(1, active_sources(:assoc_test)["http://foo/assoc_test"].size)
132
+ assert_equal(1, active_sources(:assoc_test)["http://bar/assoc_test_prop"].size)
133
+ assert_equal('TaliaCore::ActiveSource', SemanticRelation.find(:first,
134
+ :conditions => {
135
+ :subject_id => test_src.id,
136
+ :predicate_uri => 'http://foo/assoc_test',
137
+ :object_id => active_sources(:assoc_test_target)
138
+ }).object_type)
139
+ end
140
+
141
+ def test_create_validate
142
+ src = ActiveSource.new
143
+ assert_raise(ActiveRecord::RecordInvalid) { src.save! }
144
+ end
145
+
146
+ def test_create_validate_format
147
+ src = ActiveSource.new
148
+ src.uri = "invalid"
149
+ assert_raise(ActiveRecord::RecordInvalid) { src.save! }
150
+ end
151
+
152
+ def test_create_validate_unique
153
+ src = ActiveSource.new
154
+ src.uri = active_sources(:testy).uri
155
+ assert_raise(ActiveRecord::RecordInvalid) { src.save! }
156
+ end
157
+
158
+ def test_validate_uri
159
+ source = ActiveSource.new(:uri => N::LOCAL.to_s)
160
+ assert !source.valid?
161
+
162
+ source = ActiveSource.new(:uri => "#{N::LOCAL}#{source}")
163
+ assert source.valid?
164
+ end
165
+
166
+ def test_inverse
167
+ assert_equal(2, active_sources(:assoc_inverse_start).inverse['http://testvalue.org/inverse_test'].size)
168
+ second_rel = active_sources(:assoc_inverse_start).inverse['http://testvalue.org/inverse_test_rel2']
169
+ assert_equal(1, second_rel.size)
170
+ assert_kind_of(TaliaCore::ActiveSource, second_rel[0])
171
+ assert_equal('http://testy.com/testme/inverse_end_c', second_rel[0].uri)
172
+ end
173
+
174
+ def test_predicate_access
175
+ assert_equal('The test value', active_sources(:testy).predicate(:as_test_preds, :the_rel1)[0])
176
+ end
177
+
178
+ def test_predicate_assign_string
179
+ src = active_sources(:assoc_predicate_test)
180
+ src.predicate_set(:as_test_preds, :test, "Foo")
181
+ src.save!
182
+ src_chng = TaliaCore::ActiveSource.find(src.id)
183
+ assert_equal('Foo', src_chng[N::AS_TEST_PREDS.test][0])
184
+ end
185
+
186
+ def test_predicate_assign_rel
187
+ src = active_sources(:assoc_predicate_test)
188
+ src.predicate_set(:as_test_preds, :test_rel, src)
189
+ src.save!
190
+ assert_equal(src.uri, active_sources(:assoc_predicate_test)[N::AS_TEST_PREDS.test_rel][0].uri)
191
+ end
192
+
193
+ def test_semantic_build_success
194
+ src = TaliaCore::ActiveSource.new('http://buildsuccesstest/source')
195
+ src.predicate_set(:hyper, 'buildsucc', 'test')
196
+ src['http://buildsucc'] << 'test'
197
+ assert_equal(1, src['http://buildsucc'].size)
198
+ assert_equal(1, src[N::HYPER.buildsucc].size)
199
+ src.save!
200
+ assert_equal(1, ActiveSource.find(src.uri)['http://buildsucc'].size)
201
+ end
202
+
203
+ def test_predicate_set_uniq
204
+ src = active_sources(:assoc_predicate_test)
205
+ src.predicate_set_uniq(:as_test_preds, :test_uniq, "foo")
206
+ assert_property(src.predicate(:as_test_preds, :test_uniq), "foo")
207
+ src.predicate_set_uniq(:as_test_preds, :test_uniq, "bar")
208
+ src.predicate_set_uniq(:as_test_preds, :test_uniq, "foo")
209
+ src.save!
210
+ assert_property(src.predicate(:as_test_preds, :test_uniq), "foo", "bar")
211
+ end
212
+
213
+ def test_predicate_replace
214
+ src = active_sources(:assoc_predicate_test)
215
+ src.predicate_set(:as_test_preds, :test_replace, "foo")
216
+ src.predicate_replace(:as_test_preds, :test_replace, "bar")
217
+ src.save!
218
+ assert_property(src.predicate(:as_test_preds, :test_replace), "bar")
219
+ end
220
+
221
+ def test_direct_predicates
222
+ preds = active_sources(:predicate_search_a).direct_predicates
223
+ assert_equal(4, preds.size)
224
+ assert(preds.include?('http://testvalue.org/pred_b'), "#{preds} does not include the expected value")
225
+ end
226
+
227
+ def tes_predicates_prefetch
228
+ uri = active_sources(:testy)
229
+ src = TaliaCore::ActiveSource.find(uri, :prefetch_relations => true)
230
+ assert_equal('The test value', src.predicate(:as_test_preds, :the_rel1)[0])
231
+ end
232
+
233
+ def test_inverse_predicates
234
+ preds = active_sources(:predicate_search_b).inverse_predicates
235
+ assert_equal(4, preds.size)
236
+ assert(preds.include?('http://testvalue.org/pred_b'), "#{preds} does not include the expected value")
237
+ assert_equal(0, active_sources(:predicate_search_b).direct_predicates.size)
238
+ end
239
+
240
+ def test_types
241
+ src = ActiveSource.new
242
+ src.uri = 'http://testy.com/testme/type_test'
243
+ src.save!
244
+ src.types << N::SourceClass.new(active_sources(:type_a).uri)
245
+ src.types << N::SourceClass.new(active_sources(:type_b).uri)
246
+ src.save!
247
+ assert_equal(2, src.types.size)
248
+ assert_kind_of(N::SourceClass, src.types[0])
249
+ assert(src.types.include?(active_sources(:type_b).uri))
250
+ end
251
+
252
+ def test_sti_simple # Single table inheritance
253
+ assert_kind_of(TaliaCore::OrderedSource, ActiveSource.find(:first, :conditions => { :uri => active_sources(:sti_source).uri } ))
254
+ assert_kind_of(TaliaCore::OrderedSource, active_sources(:sti_source))
255
+ end
256
+
257
+ def test_sti_relation_create
258
+ src = active_sources(:sti_source_reltest)
259
+ src['http://reltest_test'] << active_sources(:sti_source_reltest_b)
260
+ src['http://reltest_test_b'] << active_sources(:sti_source_reltest_c)
261
+ src.save!
262
+ assert_equal(1, src['http://reltest_test'].size)
263
+ assert_equal(1, src['http://reltest_test_b'].size)
264
+ assert_equal(TaliaCore::OrderedSource, src['http://reltest_test'][0].class)
265
+ assert_equal(TaliaCore::ActiveSource, src['http://reltest_test_b'][0].class)
266
+ end
267
+
268
+ def test_sti_relation_inverse
269
+ assert_equal(1, active_sources(:sti_source_b).subjects.size)
270
+ assert_equal(TaliaCore::OrderedSource, active_sources(:sti_source_b).subjects[0].class)
271
+ assert_equal(TaliaCore::OrderedSource, active_sources(:sti_source_b).inverse['http://testvalue.org/sti_test'][0].class)
272
+ assert_equal(active_sources(:sti_source).uri, active_sources(:sti_source_b).inverse['http://testvalue.org/sti_test'][0].uri)
273
+ end
274
+
275
+ def test_attach_large_and_strange_text
276
+ src = active_sources(:strange_attach)
277
+ src['http://strangeattach_prop'] << "Nous présentons un commentaire de l'aphorisme 103 du Voyageur et son ombre, que Nietzsche a intitulé \" Lessing \" et où l'oeuvre de cet écrivain est jugée du du point de vue du style. On ne comprend vraiment le problème que si on inscrit l'aphorisme dans le cadre de la réception par Nietzsche, dès ses années d'études, des oeuvres de Lessing. Il résulte de notre analyse que Nietzsche définit le style de Lessing en le comparant à ce que Nietzsche lui-même appelle l'école française. À l'époque du Voyageur, le concept de sérénité (Heiterkeit) dont Montaigne est le modèle, est central pour juger un style. La question est de savoir à quelle école française Lessing a appartenu. La réponse de Nietzsche est apparemment assez ambiguë : Lessing est rapproché non seulement de Bayle, de Voltaire, de Diderot et de Montaigne, mais aussi de Marivaux, de Corneille et de Racine."
278
+ src.save!
279
+ assert_equal(src['http://strangeattach_prop'][0],"Nous présentons un commentaire de l'aphorisme 103 du Voyageur et son ombre, que Nietzsche a intitulé \" Lessing \" et où l'oeuvre de cet écrivain est jugée du du point de vue du style. On ne comprend vraiment le problème que si on inscrit l'aphorisme dans le cadre de la réception par Nietzsche, dès ses années d'études, des oeuvres de Lessing. Il résulte de notre analyse que Nietzsche définit le style de Lessing en le comparant à ce que Nietzsche lui-même appelle l'école française. À l'époque du Voyageur, le concept de sérénité (Heiterkeit) dont Montaigne est le modèle, est central pour juger un style. La question est de savoir à quelle école française Lessing a appartenu. La réponse de Nietzsche est apparemment assez ambiguë : Lessing est rapproché non seulement de Bayle, de Voltaire, de Diderot et de Montaigne, mais aussi de Marivaux, de Corneille et de Racine.")
280
+ end
281
+
282
+ def test_attach_large_and_strange_text_fresh
283
+ src = ActiveSource.new('http://freshstrangeattach.xml')
284
+ src['http://strangeattach_prop'] << "Nous présentons un commentaire de l'aphorisme 103 du Voyageur et son ombre, que Nietzsche a intitulé \" Lessing \" et où l'oeuvre de cet écrivain est jugée du du point de vue du style.\nOn ne comprend vraiment le problème que si on inscrit l'aphorisme dans le cadre de la réception par Nietzsche, dès ses années d'études, des oeuvres de Lessing. Il résulte de notre analyse que Nietzsche définit le style de Lessing en le comparant à ce que Nietzsche lui-même appelle l'école française. À l'époque du Voyageur, le concept de sérénité (Heiterkeit) dont Montaigne est le modèle, est central pour juger un style. La question est de savoir à quelle école française Lessing a appartenu. La réponse de Nietzsche est apparemment assez ambiguë : Lessing est rapproché non seulement de Bayle, de Voltaire, de Diderot et de Montaigne, mais aussi de Marivaux, de Corneille et de Racine."
285
+ src.save!
286
+ assert_equal(src['http://strangeattach_prop'][0],"Nous présentons un commentaire de l'aphorisme 103 du Voyageur et son ombre, que Nietzsche a intitulé \" Lessing \" et où l'oeuvre de cet écrivain est jugée du du point de vue du style.\nOn ne comprend vraiment le problème que si on inscrit l'aphorisme dans le cadre de la réception par Nietzsche, dès ses années d'études, des oeuvres de Lessing. Il résulte de notre analyse que Nietzsche définit le style de Lessing en le comparant à ce que Nietzsche lui-même appelle l'école française. À l'époque du Voyageur, le concept de sérénité (Heiterkeit) dont Montaigne est le modèle, est central pour juger un style. La question est de savoir à quelle école française Lessing a appartenu. La réponse de Nietzsche est apparemment assez ambiguë : Lessing est rapproché non seulement de Bayle, de Voltaire, de Diderot et de Montaigne, mais aussi de Marivaux, de Corneille et de Racine.")
287
+ end
288
+
289
+ def test_destroy_from_predicate
290
+ src = active_sources(:pred_destroy_test)
291
+ assert_equal(2, src.direct_predicates.size)
292
+ src['http://testvalue.org/pred_destroy_a'].remove
293
+ src.save!
294
+ assert_equal(1, active_sources(:pred_destroy_test).direct_predicates.size)
295
+ end
296
+
297
+ def test_create_local
298
+ src = ActiveSource.new('testlocalthing')
299
+ assert_equal(N::LOCAL.testlocalthing, src.uri)
300
+ end
301
+
302
+ def test_assign_and_save
303
+ src = ActiveSource.new('http://testassignandsave/')
304
+ src[N::LOCAL.something] << ActiveSource.new('http://types_test/assign_and_save_a')
305
+ src.save!
306
+ assert(ActiveSource.exists?(src.uri))
307
+ end
308
+
309
+ def test_assign_nil_fail
310
+ src = ActiveSource.new('http://testassignandsave_nil/')
311
+ assert_raise(ArgumentError) { src['rdfs:something'] << nil }
312
+ end
313
+
314
+ def test_find_through
315
+ result = ActiveSource.find(:all, :find_through => ['http://testvalue.org/pred_find_through', active_sources(:find_through_target).uri])
316
+ assert_equal(1, result.size)
317
+ assert_equal(active_sources(:find_through_test), result[0])
318
+ end
319
+
320
+ def test_find_through_props
321
+ result = ActiveSource.find(:all, :find_through => ['http://testvalue.org/pred_find_through', 'the_value'])
322
+ assert_equal(1, result.size)
323
+ assert_equal(active_sources(:find_through_test), result[0])
324
+ end
325
+
326
+ def test_find_through_fail
327
+ assert_raise(ArgumentError) { ActiveSource.find(:all, :find_through => ['foo:bar', 'bar'], :joins => "LEFT JOIN something") }
328
+ assert_raise(ArgumentError) { ActiveSource.find(:all, :find_through => ['foo:bar', 'bar'], :conditions => ["x = ?", 'bar']) }
329
+ end
330
+
331
+ def test_find_through_inv
332
+ result = ActiveSource.find(:all, :find_through_inv => ['http://testvalue.org/pred_find_through', active_sources(:find_through_test).uri])
333
+ assert_equal(1, result.size)
334
+ assert_equal(active_sources(:find_through_target), result[0])
335
+ end
336
+
337
+ def test_find_through_type
338
+ result = ActiveSource.find(:all, :type => active_sources(:find_through_type).uri)
339
+ assert_equal(1, result.size)
340
+ assert_equal(active_sources(:find_through_test), result[0])
341
+ end
342
+
343
+ def test_singular_accessor
344
+ src = SingularAccessorTest.new('http://testvalue.org/singular_acc_test')
345
+ assert_equal(nil, src.siglum)
346
+ src.siglum = 'foo'
347
+ src.save!
348
+ assert_equal('foo', src.siglum)
349
+ src.siglum = 'bar'
350
+ assert_equal('bar', src.siglum)
351
+ end
352
+
353
+ def test_singular_accessor_finder
354
+ src = SingularAccessorTest.new('http://testvalue.org/singular_find_test')
355
+ src.siglum = 'foo'
356
+ src.save!
357
+ src2 = SingularAccessorTest.new('http://testvalue.org/singular_find_test2')
358
+ src2.siglum = 'bar'
359
+ src2.save!
360
+ assert_equal(SingularAccessorTest.find_by_siglum('foo'), [ src ])
361
+ end
362
+
363
+ def test_autosave_rdf
364
+ src = ActiveSource.new('http://testautosaverdf/')
365
+ assert(src.autosave_rdf?)
366
+ src.autosave_rdf = false
367
+ assert(src.autosave_rdf? == false)
368
+ end
369
+
370
+ def test_write_predicate
371
+ src = ActiveSource.new('http://activesourcetest/testwritepredicate')
372
+ src['http://activesourcetest/write_predicate'] << 'foo'
373
+ src.save!
374
+ assert_equal(['foo'], src['http://activesourcetest/write_predicate'].values)
375
+ end
376
+
377
+ def test_write_predicate_direct
378
+ src = ActiveSource.new('http://activesourcetest/testwritepredicate')
379
+ src.write_predicate_direct('http://activesourcetest/write_predicate', 'foo')
380
+ assert_equal(['foo'], src['http://activesourcetest/write_predicate'].values)
381
+ assert_equal(['foo'], src.my_rdf['http://activesourcetest/write_predicate'])
382
+ end
383
+
384
+ def test_write_direct_new_source
385
+ src = ActiveSource.new('http://activesourcetest/testwritepredicatenewsrc')
386
+ src2 = ActiveSource.new('http://activesourcetest/testwritepredicatenewsrctarg')
387
+ src.write_predicate_direct('http://activesourcetest/write_predicate', src2)
388
+ assert_equal([src2], src['http://activesourcetest/write_predicate'].values)
389
+ assert_equal([src2], src.my_rdf['http://activesourcetest/write_predicate'])
390
+ end
391
+
392
+
393
+ def test_write_predicate_multi
394
+ src = ActiveSource.new('http://activesourcetest/testwritepredicatemulti')
395
+ src[N::HYPER.multipred] << ['target1', 'target2']
396
+ assert_equal(['target1', 'target2'], src[N::HYPER.multipred].values)
397
+ src.save!
398
+ assert_equal(['target1', 'target2'], src[N::HYPER.multipred].values)
399
+ end
400
+
401
+ def test_write_predicate_advanced
402
+ src = ActiveSource.new('http://activesourcetest/testwritepredicateadv')
403
+ target1 = ActiveSource.new('http://activesourcetest/testwritepredtarget1')
404
+ target2 = ActiveSource.new('http://activesourcetest/testwritepredtarget2')
405
+ src[N::HYPER.write_pred] << [target1, target2]
406
+ assert_equal([target1, target2], src[N::HYPER.write_pred].values)
407
+ src.save!
408
+ assert_equal([target1, target2], src[N::HYPER.write_pred].values)
409
+ end
410
+
411
+ def test_assign_predicate
412
+ src = ActiveSource.new('http://activesourcetest/testclearpred')
413
+ src['http://activesourcetest/write_predicate'] << 'foo'
414
+ src['http://activesourcetest/write_predicate'] << 'bar'
415
+ src['http://activesourcetest/write_predicate2'] << 'bar'
416
+ src.save!
417
+ assert_equal(2, src['http://activesourcetest/write_predicate'].size)
418
+ end
419
+
420
+ def test_double_add_new_source
421
+ src = ActiveSource.new('http://activesourcetest/doubletest')
422
+ src2 = ActiveSource.new('http://activesourcetest/doubletest2')
423
+ src3 = ActiveSource.new('http://activesourcetest/doubletest2')
424
+ src[N::HYPER.bar] << src2
425
+ src[N::HYPER.bar] << src3
426
+ src.save!
427
+ assert_equal([src2, src2], src[N::HYPER.bar].values)
428
+ end
429
+
430
+ def test_double_add
431
+ src = ActiveSource.new('http://activesourcetest/doubleadd/test')
432
+ src[N::HYPER.bar] << 'foo'
433
+ src.save!
434
+ src2 = ActiveSource.find(src.uri)
435
+ src2[N::HYPER.bar] << 'bar'
436
+ src2.save!
437
+ assert_property(ActiveSource.find(src.uri)[N::HYPER.bar], 'foo', 'bar')
438
+ end
439
+
440
+ def test_double_add_and_reset
441
+ src = ActiveSource.new('http://activesourcetest/doubleaddload/test')
442
+ src[N::HYPER.bar] << 'foo'
443
+ src.save!
444
+ src2 = ActiveSource.find(src.uri)
445
+ src2[N::HYPER.bar] << 'bar'
446
+ src2.save!
447
+ src.reset!
448
+ assert_property(src[N::HYPER.bar], 'foo', 'bar')
449
+ end
450
+
451
+ def test_db_attributes
452
+ assert(ActiveSource.db_attr?(:type))
453
+ assert(ActiveSource.db_attr?('type'))
454
+ assert(!ActiveSource.db_attr?('footype'))
455
+ assert(!ActiveSource.db_attr?('http://www.foobar.org/'))
456
+ end
457
+
458
+ def test_expand_uri
459
+ assert_equal(N::LOCAL.foo.to_s, ActiveSource.expand_uri(':foo'))
460
+ assert_equal(N::LOCAL.foo.to_s, ActiveSource.expand_uri('foo'))
461
+ assert_equal(N::LOCAL.foo.to_s, ActiveSource.expand_uri('local:foo'))
462
+ assert_equal(N::RDF.foo.to_s, ActiveSource.expand_uri('rdf:foo'))
463
+ assert_equal('http://barf.org/foo', ActiveSource.expand_uri('http://barf.org/foo'))
464
+ end
465
+
466
+ def test_update_attributes_on_saved
467
+ src = ActiveSource.new('http://as_test/test_update_attributes_on_saved')
468
+ src.save!
469
+ src.update_attributes(:uri => 'http://as_test/test_update_attributes_on_2', 'rdf:foo' => 'value', N::LOCAL.relatit.to_s => "<#{N::LOCAL + 'attr_on_save_test_dummy'}>" )
470
+ src = ActiveSource.find('http://as_test/test_update_attributes_on_2')
471
+ assert_kind_of(DummySource, src[N::LOCAL.relatit].first)
472
+ assert_equal(N::LOCAL + 'attr_on_save_test_dummy', src[N::LOCAL.relatit].first.uri)
473
+ assert_equal('value', src[N::RDF.foo].first)
474
+ end
475
+
476
+ def test_update_attributes_lists
477
+ src = ActiveSource.new('http://as_test/test_update_attributes_on_saved_lists')
478
+ src.update_attributes(N::LOCAL.relatit.to_s => ["<#{N::LOCAL + 'attr_update_test_dummy'}>" , "<:another_attribute_save_dummy>"])
479
+ assert_property(src[N::LOCAL.relatit], N::LOCAL.attr_update_test_dummy, N::LOCAL.another_attribute_save_dummy)
480
+ end
481
+
482
+ def test_update_adding
483
+ src = ActiveSource.new('http://as_test/test_update_adding')
484
+ src[N::RDF.something] << 'value1'
485
+ src.update_attributes!('rdf:something' => ['value2', 'value3'])
486
+ assert_property(src[N::RDF.something], 'value1', 'value2', 'value3')
487
+ end
488
+
489
+ def test_rewrite
490
+ src = ActiveSource.new('http://as_test/test_update_rewrite')
491
+ src[N::RDF.something] << 'value1'
492
+ src.rewrite_attributes!('rdf:something' => ['value2', 'value3'])
493
+ assert_property(src[N::RDF.something], 'value2', 'value3')
494
+ end
495
+
496
+ def test_rewrite_type
497
+ src = ActiveSource.new('http://as_test/test_update_rewrite_type')
498
+ src.rewrite_attributes!({}) { |src| src.type = 'SingularAccessorTest' }
499
+ assert_kind_of(SingularAccessorTest, ActiveSource.find(src.uri))
500
+ end
501
+
502
+ def test_rewrite_type
503
+ src = ActiveSource.new('http://as_test/test_update_type')
504
+ src.update_attributes!({}) { |src| src.type = 'SingularAccessorTest' }
505
+ assert_kind_of(SingularAccessorTest, ActiveSource.find(src.uri))
506
+ end
507
+
508
+ def test_update_static
509
+ src = ActiveSource.new('http://as_test/test_update_static')
510
+ src[N::RDF.something] << 'value1'
511
+ src.save!
512
+ ActiveSource.update(src.uri, 'rdf:something' => ['value2', 'value3'])
513
+ src = ActiveSource.find(src.uri)
514
+ assert_property(src[N::RDF.something], 'value1', 'value2', 'value3')
515
+ end
516
+
517
+ def test_rewrite_static
518
+ src = ActiveSource.new('http://as_test/test_update_rewrite')
519
+ src[N::RDF.something] << 'value1'
520
+ src.save!
521
+ ActiveSource.rewrite(src.id, 'rdf:something' => ['value2', 'value3'])
522
+ src = ActiveSource.find(src.id)
523
+ assert_property(src[N::RDF.something], 'value2', 'value3')
524
+ end
525
+
526
+ def test_create_with_attributes
527
+ src = ActiveSource.new(:uri => 'http://as_test/create_with_attributes', ':localthi' => 'value', 'rdf:relatit' => ["<:as_create_attr_dummy_1>", "<:as_create_attr_dummy_1>"])
528
+ assert_equal('http://as_test/create_with_attributes', src.uri)
529
+ assert_equal('value', src[N::LOCAL.localthi].first)
530
+ assert_property(src[N::RDF.relatit], N::LOCAL.as_create_attr_dummy_1, N::LOCAL.as_create_attr_dummy_1)
531
+ end
532
+
533
+ def test_create_source
534
+ src = ActiveSource.create_source(:uri => 'http://as_test/create_with_type', ':localthi' => 'value', 'rdf:relatit' => ["<:as_create_attr_dummy_1>", "<:as_create_attr_dummy_1>"], 'type' => 'SingularAccessorTest')
535
+ assert_kind_of(SingularAccessorTest, src)
536
+ assert_equal('value', src[N::LOCAL.localthi].first)
537
+ assert_property(src[N::RDF.relatit], N::LOCAL.as_create_attr_dummy_1, N::LOCAL.as_create_attr_dummy_1)
538
+ assert_property(src.types, N::TALIA.foo)
539
+ end
540
+
541
+ def test_create_for_existing
542
+ src = ActiveSource.create_source(:uri => 'http://as_test/create_forth_and_existing', ':localthi' => 'valueFOOOO', 'rdf:relatit' => ["<:as_create_attr_dummy_1>", "<:as_create_attr_dummy_1>"], 'type' => 'SingularAccessorTest')
543
+ src.save!
544
+ assert_equal('valueFOOOO', src[N::LOCAL.localthi].first)
545
+ xml = src.to_xml
546
+ # Quickly change something inside, but leave the URL
547
+ xml.gsub!('valueFOOOO', 'valorz')
548
+ new_src = ActiveSource.create_from_xml(xml)
549
+ # Now test as above
550
+ assert_equal(src.uri.to_s, new_src.uri.to_s)
551
+ assert_equal('valorz', new_src[N::LOCAL.localthi].first)
552
+ assert_property(new_src[N::RDF.relatit], N::LOCAL.as_create_attr_dummy_1, N::LOCAL.as_create_attr_dummy_1)
553
+ assert_property(new_src.types, N::TALIA.foo)
554
+ end
555
+
556
+ def test_create_multi
557
+ src_attribs = [
558
+ { :uri => N::LOCAL.test_create_multi_stuff, 'rdf:relatit' => [ "<#{N::LOCAL.test_create_multi_stuff_two}>" ], 'type' => 'SingularAccessorTest' },
559
+ { :uri => N::LOCAL.test_create_multi_stuff_two, ':localthi' => 'valueFOOOO', 'rdf:relatit' => ["<#{N::LOCAL.test_create_multi_stuff}>"], 'type' => 'SingularAccessorTest' }
560
+ ]
561
+ ActiveSource.create_multi_from(src_attribs)
562
+ src = TaliaCore::ActiveSource.find(N::LOCAL.test_create_multi_stuff)
563
+ src_two = TaliaCore::ActiveSource.find(N::LOCAL.test_create_multi_stuff_two)
564
+ assert(src && src_two)
565
+ assert_kind_of(SingularAccessorTest, src)
566
+ assert_kind_of(SingularAccessorTest, src_two)
567
+ assert_property(src_two[N::RDF.relatit], N::LOCAL.test_create_multi_stuff)
568
+ assert_property(src[N::RDF.relatit], N::LOCAL.test_create_multi_stuff_two)
569
+ assert_property(src_two[N::LOCAL.localthi], 'valueFOOOO')
570
+ end
571
+
572
+
573
+ def test_xml_forth_and_back
574
+ src = ActiveSource.create_source(:uri => 'http://as_test/create_forth_and_back', ':localthi' => 'value', 'rdf:relatit' => ["<:as_create_attr_dummy_1>", "<:as_create_attr_dummy_1>"], 'type' => 'DummySource')
575
+ xml = src.to_xml
576
+ assert_kind_of(TaliaCore::DummySource, src)
577
+ # Quickly change the URI for the new thing
578
+ xml.gsub!(src.uri.to_s, 'http://as_test/create_forth_and_forth')
579
+ xml.gsub!('DummySource', 'SingularAccessorTest')
580
+ new_src = ActiveSource.create_from_xml(xml)
581
+ assert_kind_of(TaliaCore::SingularAccessorTest, new_src)
582
+ # Now test as above
583
+ assert_equal('http://as_test/create_forth_and_forth', new_src.uri.to_s)
584
+ assert_equal('value', new_src[N::LOCAL.localthi].first)
585
+ assert_property(new_src[N::RDF.relatit], N::LOCAL.as_create_attr_dummy_1, N::LOCAL.as_create_attr_dummy_1)
586
+ assert_property(new_src.types, N::TALIA.foo)
587
+ end
588
+
589
+ def test_create_with_file
590
+ test_file = File.join(Test::Unit::TestCase.fixture_path, 'generic_test.xml')
591
+ src = ActiveSource.create_source(:uri => 'http://as_test/create_forth_and_back', 'type' => 'Source', 'files' => {'url' => test_file })
592
+ assert_equal(1, src.data_records.size)
593
+ src.save!
594
+ assert(!src.data_records.first.new_record?)
595
+ assert_kind_of(DataTypes::XmlData, src.data_records.first)
596
+ File.open(test_file) do |io|
597
+ assert_equal(src.data_records.first.all_text, io.read)
598
+ end
599
+ end
600
+
601
+ # Test if accessing the data on a Source works
602
+ def test_data_access
603
+ data = @data_source.data
604
+ assert_equal(2, data.size)
605
+ end
606
+
607
+ # Test if accessing the data on a Source works
608
+ def test_data_access_by_type
609
+ data = @data_source.data("SimpleText")
610
+ assert_equal(1, data.size)
611
+ assert_kind_of(DataTypes::SimpleText, data.first)
612
+ end
613
+
614
+ # Test if accessing the data on a Source works
615
+ def test_data_access_by_type_and_location
616
+ data = @data_source.data("ImageData", "image.jpg")
617
+ assert_kind_of(DataTypes::ImageData, data)
618
+ end
619
+
620
+ # Test accessing inexistent data
621
+ def test_data_access_inexistent
622
+ data = @data_source.data("Foo")
623
+ assert_equal(0, data.size)
624
+ data = @data_source.data("SimpleText", "noop.txt")
625
+ assert_nil(data)
626
+ end
627
+
628
+
629
+ end
630
+
631
+ end