talia_core 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +41 -0
- data/bin/talia +33 -0
- data/lib/JXslt/jxslt.rb +60 -0
- data/lib/acts_as_roled.rb +11 -0
- data/lib/core_ext/platform.rb +9 -0
- data/lib/core_ext/string.rb +6 -0
- data/lib/core_ext.rb +1 -0
- data/lib/custom_template.rb +4 -0
- data/lib/loader_helper.rb +62 -0
- data/lib/mysql.rb +1214 -0
- data/lib/progressbar.rb +236 -0
- data/lib/role.rb +12 -0
- data/lib/talia_cl/command_line.rb +39 -0
- data/lib/talia_cl/commands/standalone/cl_options.rb +9 -0
- data/lib/talia_cl/commands/standalone/standalone_generate.rb +75 -0
- data/lib/talia_cl/commands/standalone.rb +25 -0
- data/lib/talia_cl/commands/talia_console/cl_options.rb +55 -0
- data/lib/talia_cl/commands/talia_console/console_commands.rb +37 -0
- data/lib/talia_cl/commands/talia_console/talia_commands.rb +131 -0
- data/lib/talia_cl/commands/talia_console.rb +47 -0
- data/lib/talia_cl/core_commands.rb +11 -0
- data/lib/talia_cl.rb +47 -0
- data/lib/talia_core/active_source.rb +372 -0
- data/lib/talia_core/active_source_parts/class_methods.rb +378 -0
- data/lib/talia_core/active_source_parts/predicate_handler.rb +89 -0
- data/lib/talia_core/active_source_parts/rdf.rb +131 -0
- data/lib/talia_core/active_source_parts/sql_helper.rb +36 -0
- data/lib/talia_core/active_source_parts/xml/base_builder.rb +47 -0
- data/lib/talia_core/active_source_parts/xml/generic_reader.rb +363 -0
- data/lib/talia_core/active_source_parts/xml/rdf_builder.rb +88 -0
- data/lib/talia_core/active_source_parts/xml/source_builder.rb +73 -0
- data/lib/talia_core/active_source_parts/xml/source_reader.rb +20 -0
- data/lib/talia_core/agent.rb +14 -0
- data/lib/talia_core/background_jobs/job.rb +82 -0
- data/lib/talia_core/background_jobs/progress_job.rb +68 -0
- data/lib/talia_core/collection.rb +13 -0
- data/lib/talia_core/data_types/data_loader.rb +92 -0
- data/lib/talia_core/data_types/data_record.rb +105 -0
- data/lib/talia_core/data_types/delayed_copier.rb +76 -0
- data/lib/talia_core/data_types/file_record.rb +59 -0
- data/lib/talia_core/data_types/file_store.rb +306 -0
- data/lib/talia_core/data_types/iip_data.rb +153 -0
- data/lib/talia_core/data_types/iip_loader.rb +127 -0
- data/lib/talia_core/data_types/image_data.rb +32 -0
- data/lib/talia_core/data_types/media_link.rb +19 -0
- data/lib/talia_core/data_types/mime_mapping.rb +45 -0
- data/lib/talia_core/data_types/path_helpers.rb +77 -0
- data/lib/talia_core/data_types/pdf_data.rb +42 -0
- data/lib/talia_core/data_types/simple_text.rb +36 -0
- data/lib/talia_core/data_types/temp_file_handling.rb +85 -0
- data/lib/talia_core/data_types/xml_data.rb +169 -0
- data/lib/talia_core/dc_resource.rb +20 -0
- data/lib/talia_core/dummy_handler.rb +34 -0
- data/lib/talia_core/dummy_source.rb +20 -0
- data/lib/talia_core/errors.rb +25 -0
- data/lib/talia_core/initializer.rb +427 -0
- data/lib/talia_core/ordered_source.rb +228 -0
- data/lib/talia_core/rails_ext/actionpack/action_controller/record_identifier.rb +13 -0
- data/lib/talia_core/rails_ext/actionpack/action_controller.rb +1 -0
- data/lib/talia_core/rails_ext/actionpack.rb +1 -0
- data/lib/talia_core/rails_ext.rb +1 -0
- data/lib/talia_core/rdf_import.rb +90 -0
- data/lib/talia_core/rdf_resource.rb +159 -0
- data/lib/talia_core/semantic_collection_item.rb +93 -0
- data/lib/talia_core/semantic_collection_wrapper.rb +324 -0
- data/lib/talia_core/semantic_property.rb +7 -0
- data/lib/talia_core/semantic_relation.rb +67 -0
- data/lib/talia_core/source.rb +323 -0
- data/lib/talia_core/source_transfer_object.rb +38 -0
- data/lib/talia_core/workflow/base.rb +15 -0
- data/lib/talia_core/workflow/publication_workflow.rb +62 -0
- data/lib/talia_core/workflow.rb +300 -0
- data/lib/talia_core.rb +9 -0
- data/lib/talia_dependencies.rb +12 -0
- data/lib/talia_util/bar_progressor.rb +15 -0
- data/lib/talia_util/configuration/config_file.rb +48 -0
- data/lib/talia_util/configuration/database_config.rb +40 -0
- data/lib/talia_util/configuration/mysql_database_setup.rb +104 -0
- data/lib/talia_util/data_import.rb +91 -0
- data/lib/talia_util/image_conversions.rb +82 -0
- data/lib/talia_util/import_job_helper.rb +132 -0
- data/lib/talia_util/io_helper.rb +54 -0
- data/lib/talia_util/progressable.rb +38 -0
- data/lib/talia_util/progressbar.rb +236 -0
- data/lib/talia_util/rdf_update.rb +80 -0
- data/lib/talia_util/some_sigla.xml +1960 -0
- data/lib/talia_util/test_helpers.rb +151 -0
- data/lib/talia_util/util.rb +226 -0
- data/lib/talia_util/yaml_import.rb +80 -0
- data/lib/talia_util.rb +13 -0
- data/lib/user.rb +116 -0
- data/lib/version.rb +15 -0
- data/test/core_ext/string_test.rb +11 -0
- data/test/custom_template_test.rb +8 -0
- data/test/talia_core/active_source_predicate_test.rb +54 -0
- data/test/talia_core/active_source_rdf_test.rb +89 -0
- data/test/talia_core/active_source_test.rb +631 -0
- data/test/talia_core/data_types/data_loader_test.rb +123 -0
- data/test/talia_core/data_types/data_record_test.rb +40 -0
- data/test/talia_core/data_types/file_record_test.rb +171 -0
- data/test/talia_core/data_types/iip_data_test.rb +130 -0
- data/test/talia_core/data_types/image_data_test.rb +88 -0
- data/test/talia_core/data_types/pdf_data_test.rb +68 -0
- data/test/talia_core/data_types/xml_data_test.rb +134 -0
- data/test/talia_core/generic_xml_test.rb +83 -0
- data/test/talia_core/initializer_test.rb +36 -0
- data/test/talia_core/ordered_source_test.rb +398 -0
- data/test/talia_core/rdf_resource_test.rb +115 -0
- data/test/talia_core/semantic_collection_item_test.rb +129 -0
- data/test/talia_core/source_reader_test.rb +33 -0
- data/test/talia_core/source_test.rb +484 -0
- data/test/talia_core/source_transfer_object_test.rb +24 -0
- data/test/talia_core/workflow/publication_workflow_test.rb +242 -0
- data/test/talia_core/workflow/user_class_for_workflow.rb +35 -0
- data/test/talia_core/workflow/workflow_base_test.rb +21 -0
- data/test/talia_core/workflow_test.rb +19 -0
- data/test/talia_util/import_job_helper_test.rb +46 -0
- data/test/test_helper.rb +68 -0
- metadata +262 -0
@@ -0,0 +1,484 @@
|
|
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
|
+
# class Source
|
9
|
+
# def instantiate_source_or_rdf_object # Need since class may be loaded later
|
10
|
+
# end
|
11
|
+
#
|
12
|
+
# public :instantiate_source_or_rdf_object
|
13
|
+
# end
|
14
|
+
|
15
|
+
# Test the SourceType class
|
16
|
+
class SourceTest < Test::Unit::TestCase
|
17
|
+
|
18
|
+
N::Namespace.shortcut(:meetest, "http://www.meetest.org/me/")
|
19
|
+
N::URI.shortcut(:test_uri, "http://www.testuri.com/bar")
|
20
|
+
N::Predicate.shortcut(:test_predicate, "http://www.meetest.org/my_predicate")
|
21
|
+
N::Namespace.shortcut(:foafx, "http://www.foafx.org/")
|
22
|
+
N::Namespace.shortcut(:foo, "http://foo.com/") unless(N::URI.shortcut_exists?(:foo))
|
23
|
+
|
24
|
+
def setup
|
25
|
+
@predicates_attributes = [
|
26
|
+
{"name"=>"type", "uri"=>"http://www.w3.org/2000/01/rdf-schema#Resource", "namespace"=>"rdf", "titleized"=>"Resource", "should_destroy" => ""},
|
27
|
+
{"name"=>"type", "uri"=>"http://xmlns.com/foaf/0.1/Group", "should_destroy"=>"", "namespace"=>"rdf", "id"=>"Group", "titleized"=>"Group", "should_destroy" => ""}]
|
28
|
+
|
29
|
+
@params = {"uri"=>"#{N::LOCAL}Guinigi_family", "predicates_attributes"=>@predicates_attributes }
|
30
|
+
|
31
|
+
setup_once(:flush) do
|
32
|
+
TaliaUtil::Util.flush_rdf
|
33
|
+
TaliaUtil::Util.flush_db
|
34
|
+
true
|
35
|
+
end
|
36
|
+
|
37
|
+
setup_once(:test_source) do
|
38
|
+
Source.new("http://www.test.org/test/")
|
39
|
+
end
|
40
|
+
|
41
|
+
setup_once(:valid_source) do
|
42
|
+
valid_source = Source.new("http://www.test.org/valid")
|
43
|
+
valid_source.primary_source = false
|
44
|
+
valid_source.save!
|
45
|
+
valid_source
|
46
|
+
end
|
47
|
+
assert(Source::exists?(@valid_source.uri))
|
48
|
+
|
49
|
+
setup_once(:local_source) do
|
50
|
+
local_source = Source.new(N::LOCAL + "home_source")
|
51
|
+
local_source.primary_source = false
|
52
|
+
local_source.save!
|
53
|
+
local_source
|
54
|
+
end
|
55
|
+
|
56
|
+
setup_once(:dummy_sources) do
|
57
|
+
(1..3).each do |n|
|
58
|
+
src = Source.new("http://www.typedthing.com/element#{n}")
|
59
|
+
src.primary_source = false
|
60
|
+
type = ActiveSource.new("http://www.interestingrelations.org/book")
|
61
|
+
type.save!
|
62
|
+
src.types << type
|
63
|
+
src.save!
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
setup_once(:test_type) do
|
68
|
+
type = ActiveSource.new('http://www.type.test/the_type')
|
69
|
+
type.save!
|
70
|
+
type
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
# Check that no .uri method got added to the String class
|
76
|
+
def test_string_sanity
|
77
|
+
assert(!'foo'.respond_to?(:uri), "Someone added an 'uri' method to the String class. This will cause problems.")
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_created_helper
|
81
|
+
assert(Source.exists?("http://www.typedthing.com/element1"))
|
82
|
+
end
|
83
|
+
|
84
|
+
# Test if a source object can be created correctly with no type information
|
85
|
+
def test_create_typeless
|
86
|
+
# rec = SourceRecord.new
|
87
|
+
source = Source.new("http://www.newstuff.org/my_nuff")
|
88
|
+
assert_not_nil(source)
|
89
|
+
assert_equal(0, source.types.size)
|
90
|
+
end
|
91
|
+
|
92
|
+
# Test if a source object can be created correctly
|
93
|
+
def test_types
|
94
|
+
# rec = SourceRecord.new
|
95
|
+
source = make_dummy_source("http://www.newstuff.org/createtypes", N::FOAFX.Person, N::FOAFX.Foe)
|
96
|
+
assert_not_nil(source)
|
97
|
+
assert_equal(2, source.types.size)
|
98
|
+
assert_not_nil(source.types.each { |type| type.to_s == N::FOAFX.Person.to_s} )
|
99
|
+
end
|
100
|
+
|
101
|
+
# test grouping by types
|
102
|
+
def test_grouping
|
103
|
+
make_dummy_source("http://groupme/source1", N::FOAFX.Goat, N::FOAFX.Bee)
|
104
|
+
make_dummy_source("http://groupme/source2", N::FOAFX.Goat)
|
105
|
+
make_dummy_source("http://groupme/source3", N::FOAFX.Bee)
|
106
|
+
results = Source.groups_by_property(:type, [ N::FOAFX.Goat, N::FOAFX.Bee ])
|
107
|
+
assert_equal(2, results.size)
|
108
|
+
assert_equal(2, results[N::FOAFX.Goat].size)
|
109
|
+
assert_equal(2, results[N::FOAFX.Bee].size)
|
110
|
+
end
|
111
|
+
|
112
|
+
# Tests if the ActiveRecord validation works
|
113
|
+
def test_ar_validation
|
114
|
+
source = Source.new("http://www.newstuff.org/my_first")
|
115
|
+
assert(!Source.exists?(source.uri))
|
116
|
+
source.primary_source = false
|
117
|
+
errors = ""
|
118
|
+
assert(source.valid?, source.errors.each_full() { |msg| errors += ":" + msg })
|
119
|
+
|
120
|
+
# Now check if the uri validation works
|
121
|
+
source.uri = "foobar"
|
122
|
+
assert(!source.valid?)
|
123
|
+
source.uri = "foo:bar"
|
124
|
+
assert(source.valid?)
|
125
|
+
end
|
126
|
+
|
127
|
+
# Test load/save for active record
|
128
|
+
def test_save_with_workflow
|
129
|
+
@valid_source.workflow = Workflow::PublicationWorkflow.new
|
130
|
+
@valid_source.save!
|
131
|
+
assert(Source.exists?(@valid_source.uri))
|
132
|
+
assert_kind_of(Workflow::PublicationWorkflow, Source.new(@valid_source.uri).workflow)
|
133
|
+
end
|
134
|
+
|
135
|
+
# Check loading of Elements
|
136
|
+
def test_load
|
137
|
+
@valid_source.save
|
138
|
+
source_loaded = Source.find(@valid_source.uri)
|
139
|
+
assert_kind_of(Source, source_loaded)
|
140
|
+
assert_equal(@valid_source.primary_source, source_loaded.primary_source)
|
141
|
+
assert_equal(@valid_source.uri, source_loaded.uri)
|
142
|
+
end
|
143
|
+
|
144
|
+
# Load change, and save
|
145
|
+
def test_load_save
|
146
|
+
@valid_source.save
|
147
|
+
source_loaded = Source.find(@valid_source.uri)
|
148
|
+
source_loaded['http://loadsavetest/name'] << '4'
|
149
|
+
source_loaded.save
|
150
|
+
|
151
|
+
source_reloaded = Source.find(@valid_source.uri)
|
152
|
+
assert_equal('4', source_reloaded['http://loadsavetest/name'][0])
|
153
|
+
end
|
154
|
+
|
155
|
+
# Check if load failure is raised correctly
|
156
|
+
def test_load_failure
|
157
|
+
# Check for load failure
|
158
|
+
assert_raises(ActiveRecord::RecordNotFound) { Source.find("xxxx") }
|
159
|
+
end
|
160
|
+
|
161
|
+
# Direct RDF property
|
162
|
+
def test_rdf_direct_property
|
163
|
+
@valid_source.default::test_predicate << "moofoo"
|
164
|
+
assert_equal(@valid_source.default::test_predicate[0], "moofoo")
|
165
|
+
assert_equal(1, @valid_source.default::test_predicate.size)
|
166
|
+
end
|
167
|
+
|
168
|
+
# Namespaced RDF property
|
169
|
+
def test_rdf_namespace_property
|
170
|
+
@valid_source.meetest::something << "somefoo"
|
171
|
+
assert_equal(@valid_source.meetest::something[0], "somefoo")
|
172
|
+
end
|
173
|
+
|
174
|
+
# Check disallowed cases for RDF
|
175
|
+
def test_rdf_fail
|
176
|
+
assert_raise(ArgumentError) { @valid_source.test_predicate("foo") }
|
177
|
+
end
|
178
|
+
|
179
|
+
# Relation properties
|
180
|
+
def test_relations
|
181
|
+
@valid_source.default::rel_it << Source.new("http://foobar.com/")
|
182
|
+
assert_kind_of(SemanticCollectionWrapper, @valid_source.default::rel_it)
|
183
|
+
assert_kind_of(Source, @valid_source.default::rel_it[0])
|
184
|
+
assert_equal("http://foobar.com/", @valid_source.default::rel_it[0].uri.to_s)
|
185
|
+
end
|
186
|
+
|
187
|
+
# RDF load and save
|
188
|
+
def test_rdf_save_load
|
189
|
+
@valid_source.default::hero << "napoleon"
|
190
|
+
@valid_source.save
|
191
|
+
loaded = Source.find(@valid_source.uri)
|
192
|
+
assert_equal("napoleon", loaded.default::hero[0])
|
193
|
+
end
|
194
|
+
|
195
|
+
# Test limit
|
196
|
+
def test_find_limit
|
197
|
+
result = Source.find(:all, :limit => 2)
|
198
|
+
assert_equal(2, result.size)
|
199
|
+
end
|
200
|
+
|
201
|
+
def test_find_or_instantiate_by_uri
|
202
|
+
unexistent = Source.find_or_instantiate_by_uri('unexistent', 'Foo Bar')
|
203
|
+
assert unexistent.new_record?
|
204
|
+
assert_equal N::LOCAL.to_s + 'Foo_Bar', unexistent.uri.to_s
|
205
|
+
assert !Source.find_or_instantiate_by_uri(@valid_source.uri.to_s, nil).new_record?
|
206
|
+
end
|
207
|
+
|
208
|
+
def test_should_return_a_list_of_sources_for_given_uri_token
|
209
|
+
assert_not_empty Source.find_by_uri_token('1') # source1 fixture
|
210
|
+
assert_empty Source.find_by_uri_token('org')
|
211
|
+
end
|
212
|
+
|
213
|
+
def test_new_record
|
214
|
+
assert Source.new('nu').new_record?
|
215
|
+
assert_not Source.find(:first).new_record?
|
216
|
+
end
|
217
|
+
|
218
|
+
def test_find_with_local_name
|
219
|
+
assert_nothing_raised ActiveRecord::RecordNotFound do
|
220
|
+
assert Source.find('home_source')
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
# Test the xml create
|
225
|
+
def test_create_xml
|
226
|
+
# TODO: Make a real test when it's worth it
|
227
|
+
source = Source.new("http://www.newstuff.org/my_first")
|
228
|
+
source.types << @test_type
|
229
|
+
source.primary_source = false
|
230
|
+
source.save!
|
231
|
+
source.default::author << "napoleon"
|
232
|
+
source.save!
|
233
|
+
print source.to_xml
|
234
|
+
print source.to_rdf # also check rdf
|
235
|
+
end
|
236
|
+
|
237
|
+
# Test for direct predicates
|
238
|
+
def test_direct_predicates
|
239
|
+
my_source = make_dummy_source("http://direct_predicate_haver/")
|
240
|
+
my_source.default::author << "napoleon"
|
241
|
+
my_source.save!
|
242
|
+
|
243
|
+
# Expected size of direct predicates: One for the predicate set above
|
244
|
+
# and one for the default type
|
245
|
+
assert_equal(2, my_source.direct_predicates.size)
|
246
|
+
assert(my_source.direct_predicates.include?(N::DEFAULT::author))
|
247
|
+
end
|
248
|
+
|
249
|
+
# Test for inverse predicates
|
250
|
+
def test_inverse_predicates
|
251
|
+
source = make_dummy_source("http://predicate_source/")
|
252
|
+
target = make_dummy_source("http://predicate_target/")
|
253
|
+
target.save!
|
254
|
+
source.foo::invtest << target
|
255
|
+
source.save!
|
256
|
+
assert(target.inverse_predicates.size > 0, "No inverse predicates")
|
257
|
+
assert(target.inverse_predicates.include?(N::FOO::invtest), "Inverse predicate not found.")
|
258
|
+
end
|
259
|
+
|
260
|
+
# Test the Array accessor
|
261
|
+
def test_array_accessor
|
262
|
+
@valid_source[N::MEETEST::array_test] << "foo"
|
263
|
+
assert_equal(@valid_source[N::MEETEST::array_test], @valid_source.meetest::array_test)
|
264
|
+
assert_equal("foo", @valid_source[N::MEETEST::array_test][0])
|
265
|
+
end
|
266
|
+
|
267
|
+
def test_grouped_direct_predicates_should_collect_rdf_objects
|
268
|
+
source = make_dummy_source("http://direct_predicate_for_napoleon/")
|
269
|
+
source.default::historical_character << Source.new("#{N::LOCAL}napoleon")
|
270
|
+
source.default::historical_character << "Giuseppe Garibaldi"
|
271
|
+
|
272
|
+
source.save!
|
273
|
+
|
274
|
+
assert_equal(2, source.grouped_direct_predicates.size)
|
275
|
+
predicates = source.grouped_direct_predicates['default']
|
276
|
+
predicates.each do |group, source_list|
|
277
|
+
source_list.flatten.each do |source|
|
278
|
+
assert_kind_of(SourceTransferObject, source)
|
279
|
+
end
|
280
|
+
end
|
281
|
+
assert_included predicates.keys, 'historical_character'
|
282
|
+
end
|
283
|
+
|
284
|
+
def test_predicate_objects
|
285
|
+
source = make_dummy_source("http://star-wars.org/")
|
286
|
+
source.default::jedi_knight << Source.new("http://star-wars.org/luke-skywalker")
|
287
|
+
source.default::jedi_knight << "Obi-Wan Kenobi"
|
288
|
+
|
289
|
+
assert_included source.predicate_objects('default', 'jedi_knight'), "http://star-wars.org/luke-skywalker"
|
290
|
+
assert_included source.predicate_objects('default', 'jedi_knight'), "Obi-Wan Kenobi"
|
291
|
+
end
|
292
|
+
|
293
|
+
def test_associated
|
294
|
+
source = make_dummy_source("http://star-wars.org/")
|
295
|
+
associated_source = Source.new("http://star-wars.org/luke-skywalker")
|
296
|
+
source.default::jedi_knight << associated_source
|
297
|
+
assert(source.associated?('default', 'jedi_knight', associated_source.to_s))
|
298
|
+
end
|
299
|
+
|
300
|
+
def test_predicates_attributes_setter
|
301
|
+
source = make_dummy_source("http://lucca.org/")
|
302
|
+
source.predicates_attributes = @predicates_attributes
|
303
|
+
|
304
|
+
assert_equal("http://www.w3.org/2000/01/rdf-schema#Resource", source.predicates_attributes.first['uri'])
|
305
|
+
assert_equal('rdf', source.predicates_attributes.first['namespace'])
|
306
|
+
assert_equal('Resource', source.predicates_attributes.first['titleized'])
|
307
|
+
assert_kind_of(Source, source.predicates_attributes.first['object'])
|
308
|
+
end
|
309
|
+
|
310
|
+
# def test_save_predicates_attributes
|
311
|
+
# source = create_source('http://star-warz.org/')
|
312
|
+
# @predicates_attributes[1] = @predicates_attributes[1].merge({'should_destroy' => '1'})
|
313
|
+
# @predicates_attributes << {"name"=>"in_epoch", "uri"=> N::LOCAL.to_s, "should_destroy"=>"", "namespace"=>"talia", "id"=>"", "titleized"=>"Paolo Guinigi"}
|
314
|
+
# source.predicates_attributes = @predicates_attributes
|
315
|
+
# source.save_predicates_attributes
|
316
|
+
#
|
317
|
+
# assert_source_exists "#{N::LOCAL}Paolo_Guinigi"
|
318
|
+
# source = create_source('http://star-warz.org/') # force the source reload
|
319
|
+
# # Expected size is equal to 5, because @predicates_attributes
|
320
|
+
# # contains 6 sources, but 1 is marked for destroy.
|
321
|
+
# assert_equal(2, source.direct_predicates_objects.size)
|
322
|
+
# end
|
323
|
+
|
324
|
+
def test_normalize_uri
|
325
|
+
assert_equal("#{N::LOCAL}LocalSource", Source.normalize_uri(N::LOCAL.to_s, 'LocalSource'))
|
326
|
+
assert_equal("#{N::LOCAL}Local_Source", Source.normalize_uri(N::LOCAL.to_s, 'Local Source'))
|
327
|
+
assert_equal("http://star-wars.org/obi-wan-kenobi", Source.normalize_uri('http://star-wars.org/obi-wan-kenobi').to_s)
|
328
|
+
end
|
329
|
+
|
330
|
+
def test_extract_attributes
|
331
|
+
source = make_dummy_source("http://star-wars.org/")
|
332
|
+
attributes, rdf_attributes = source.send(:extract_attributes!, @params)
|
333
|
+
|
334
|
+
assert_equal(%w( uri ), attributes.keys)
|
335
|
+
rdf_attributes['predicates_attributes'].each do |attributes_hash|
|
336
|
+
assert_kind_of Hash, attributes_hash
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
340
|
+
def test_instantiate_source_or_rdf_object
|
341
|
+
source = make_dummy_source("http://springfield.org/")
|
342
|
+
|
343
|
+
attributes = { 'uri' => N::LOCAL.to_s, 'titleized' => 'Homer Simpson', 'source' => 'true' }
|
344
|
+
result = source.send :instantiate_source_or_rdf_object, attributes
|
345
|
+
assert_kind_of(Source, result)
|
346
|
+
assert_equal("#{N::LOCAL}Homer_Simpson", result.to_s)
|
347
|
+
|
348
|
+
attributes.merge!('titleized' => %("Homer Simpson"))
|
349
|
+
result = source.send :instantiate_source_or_rdf_object, attributes
|
350
|
+
assert_equal(%(Homer Simpson), result)
|
351
|
+
|
352
|
+
attributes.merge!('titleized' => "http://springfield.org/Homer_Simpson")
|
353
|
+
result = source.send :instantiate_source_or_rdf_object, attributes
|
354
|
+
assert_kind_of(Source, result)
|
355
|
+
assert_equal("http://springfield.org/Homer_Simpson", result.to_s)
|
356
|
+
|
357
|
+
attributes.merge!('titleized' => "Homer Simpson", 'uri' => nil, 'source' => nil)
|
358
|
+
result = source.send :instantiate_source_or_rdf_object, attributes
|
359
|
+
assert_equal(%(Homer Simpson), result)
|
360
|
+
end
|
361
|
+
|
362
|
+
def test_each_predicate
|
363
|
+
source = make_dummy_source("http://star-wars.org/")
|
364
|
+
source.predicates_attributes = @predicates_attributes
|
365
|
+
|
366
|
+
source.send(:each_predicate) do |namespace, predicate, objects|
|
367
|
+
assert_kind_of(String, namespace)
|
368
|
+
assert_kind_of(String, predicate)
|
369
|
+
assert_not_empty objects
|
370
|
+
objects.each { |object| assert_kind_of(TaliaCore::SourceTransferObject, object) }
|
371
|
+
end
|
372
|
+
end
|
373
|
+
|
374
|
+
# Read an db attribute by symbol
|
375
|
+
def test_read_access_db_symbol
|
376
|
+
source = Source.new('http://localnode.org/something')
|
377
|
+
attribute_value = source[:uri]
|
378
|
+
assert_equal('http://localnode.org/something', attribute_value)
|
379
|
+
end
|
380
|
+
|
381
|
+
# Write an db attribute by symbol
|
382
|
+
def test_write_access_db_symbol
|
383
|
+
source = Source.new('http://localnode.org/something')
|
384
|
+
source[:uri] = "http://somethingelse.com/"
|
385
|
+
assert_equal(source.uri.to_s, "http://somethingelse.com/")
|
386
|
+
end
|
387
|
+
|
388
|
+
# Read the uri
|
389
|
+
def test_access_db_string
|
390
|
+
source = Source.new('http://localnode.org/something')
|
391
|
+
attribute_value = source.uri
|
392
|
+
assert_not_nil(attribute_value)
|
393
|
+
assert_kind_of(N::URI, attribute_value)
|
394
|
+
assert_equal('http://localnode.org/something', attribute_value.to_s)
|
395
|
+
end
|
396
|
+
|
397
|
+
# Write an db attribute by string
|
398
|
+
def test_write_access_db_symbol
|
399
|
+
source = Source.new('http://localnode.org/something')
|
400
|
+
source['uri'] = "http://somethingelse.com/"
|
401
|
+
assert_equal(source.uri.to_s, "http://somethingelse.com/")
|
402
|
+
end
|
403
|
+
|
404
|
+
# Test the predicate accessor
|
405
|
+
def test_predicate_accessor
|
406
|
+
assert(@valid_source.predicate_set(:meetest, "array_test_acc", "bla"))
|
407
|
+
assert_equal(@valid_source.predicate(:meetest, "array_test_acc"), @valid_source.meetest::array_test_acc)
|
408
|
+
assert_equal("bla", @valid_source.predicate(:meetest, "array_test_acc")[0])
|
409
|
+
end
|
410
|
+
|
411
|
+
# Test for non-existing predicates
|
412
|
+
def test_nonexistent_predicate
|
413
|
+
assert_raises(ArgumentError) { @valid_source.predicate(:idontexist, "something") }
|
414
|
+
end
|
415
|
+
|
416
|
+
def test_titleized
|
417
|
+
assert_equal("Home Source", @local_source.titleized)
|
418
|
+
end
|
419
|
+
|
420
|
+
# Test find :first
|
421
|
+
def test_find_first
|
422
|
+
source = Source.find(:first)
|
423
|
+
assert_kind_of(Source, source)
|
424
|
+
end
|
425
|
+
|
426
|
+
# Test the inverse accessor
|
427
|
+
def test_inverse
|
428
|
+
origin = make_dummy_source("http://inversetest.com/originating")
|
429
|
+
origin2 = make_dummy_source("http://inversetest.com/originating2")
|
430
|
+
target = make_dummy_source("http://inversetest.com/target")
|
431
|
+
|
432
|
+
|
433
|
+
origin.foo::my_friend << target
|
434
|
+
origin.foo::coworker << target
|
435
|
+
origin2.foo::my_friend << target
|
436
|
+
|
437
|
+
origin.save!
|
438
|
+
origin2.save!
|
439
|
+
target.save!
|
440
|
+
|
441
|
+
|
442
|
+
inverted = target.inverse[N::FOO::coworker]
|
443
|
+
assert_equal(1, inverted.size)
|
444
|
+
assert_equal(origin.uri, inverted[0].uri)
|
445
|
+
|
446
|
+
# Crosscheck
|
447
|
+
assert_equal(2, target.inverse[N::FOO::my_friend].size)
|
448
|
+
end
|
449
|
+
|
450
|
+
# Test if the save method/db dupes wipes any rdf data
|
451
|
+
def test_rdf_safe
|
452
|
+
safe = make_dummy_source("http://safehaven.com")
|
453
|
+
safe.foo::some_property << "I should be safe!"
|
454
|
+
safe.save!
|
455
|
+
assert_equal("I should be safe!", safe.foo::some_property[0])
|
456
|
+
end
|
457
|
+
|
458
|
+
# Test foreign Source
|
459
|
+
def test_foreign
|
460
|
+
foreign = Source.new("http://www.hypernietzsche.org/ontology/Dossier")
|
461
|
+
assert_kind_of(Source, foreign)
|
462
|
+
assert(!foreign.local)
|
463
|
+
end
|
464
|
+
|
465
|
+
# Test equality
|
466
|
+
def test_equals
|
467
|
+
new_src = Source.new(@test_source.uri)
|
468
|
+
assert_equal(new_src, @test_source)
|
469
|
+
assert_not_same(new_src, @test_source)
|
470
|
+
end
|
471
|
+
|
472
|
+
def test_assign_object
|
473
|
+
assert(!ActiveSource.exists?(uri = 'http://assignobject_source'))
|
474
|
+
src = Source.new(uri)
|
475
|
+
src.rdfs::something << Source.new(uri + '_target')
|
476
|
+
src.save!
|
477
|
+
assert(ActiveSource.exists?(uri))
|
478
|
+
assert(ActiveSource.exists?(uri + '_target'))
|
479
|
+
end
|
480
|
+
|
481
|
+
|
482
|
+
end
|
483
|
+
end
|
484
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
3
|
+
|
4
|
+
module TaliaCore
|
5
|
+
class SourceTransferObjectTest < Test::Unit::TestCase
|
6
|
+
def test_with_uri
|
7
|
+
s = SourceTransferObject.new("#{N::LOCAL}Homer_Simpson")
|
8
|
+
assert_equal('Homer Simpson', s.titleized)
|
9
|
+
assert_equal('Homer_Simpson', s.id)
|
10
|
+
assert_equal("#{N::LOCAL}Homer_Simpson", s.to_s)
|
11
|
+
assert_equal("#{N::LOCAL}Homer_Simpson", s.uri.to_s)
|
12
|
+
assert s.source?
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_with_string
|
16
|
+
s = SourceTransferObject.new('Homer Simpson')
|
17
|
+
assert_equal('Homer Simpson', s.titleized)
|
18
|
+
assert_equal('Homer Simpson', s.to_s)
|
19
|
+
assert_equal('Homer Simpson', s.id)
|
20
|
+
assert_nil(s.uri)
|
21
|
+
assert_not s.source?
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|