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,134 @@
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 XmlDataTest < Test::Unit::TestCase
10
+
11
+ fixtures :active_sources, :data_records
12
+
13
+ def setup
14
+ # Sets the file that is used by one test
15
+ setup_once(:tmp_file) { File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'data_for_test', 'XmlData', 'temp0.xhtml')) }
16
+ setup_once(:flush) do
17
+ # If the temp file already exists, it must be deleted
18
+ File.delete(@tmp_file) if(File.exist?(@tmp_file))
19
+ true
20
+ end
21
+ @test_records = DataTypes::DataRecord.find_data_records(Fixtures.identify(:something))
22
+ end
23
+
24
+ # test not nil and records numbers
25
+ def test_records_numbers
26
+ assert_not_equal [], @test_records
27
+ assert_equal 15, @test_records.size
28
+ end
29
+
30
+ # test class type and mime_type and subtype
31
+ def test_mime_types
32
+ assert_kind_of(DataTypes::XmlData, @test_records[2])
33
+ assert_kind_of(DataTypes::XmlData, @test_records[3])
34
+ assert_kind_of(DataTypes::XmlData, @test_records[4])
35
+ assert_kind_of(DataTypes::XmlData, @test_records[5])
36
+ assert_kind_of(DataTypes::XmlData, @test_records[6])
37
+ assert_equal("text/xml", @test_records[2].mime_type)
38
+ assert_equal("xml", @test_records[2].mime_subtype)
39
+ assert_equal("text/html", @test_records[3].mime_type)
40
+ assert_equal("html", @test_records[3].mime_subtype)
41
+ assert_equal("text/hnml", @test_records[4].mime_type)
42
+ assert_equal("hnml", @test_records[4].mime_subtype)
43
+ assert_equal("text/html", @test_records[5].mime_type)
44
+ assert_equal("html", @test_records[5].mime_subtype)
45
+ assert_equal("text/html", @test_records[6].mime_type)
46
+ assert_equal("html", @test_records[6].mime_subtype)
47
+ end
48
+
49
+ # test data directory
50
+ def test_data_directory
51
+ dir_for_test = File.expand_path(@test_records[2].data_directory)
52
+ assert_equal(base_dir_name(@test_records[2].id), dir_for_test)
53
+ assert(File.exists?(dir_for_test))
54
+ assert_equal(File.join(base_dir_name(@test_records[2].id), 'temp1.xml'), File.join(dir_for_test, @test_records[2].location))
55
+ assert( File.exists?(File.join(dir_for_test, @test_records[2].id.to_s)), "#{File.join(dir_for_test, @test_records[2].id.to_s)} does not exist" )
56
+ end
57
+
58
+ # test file size
59
+ def test_file_size
60
+ assert_equal(300, @test_records[2].size)
61
+ end
62
+
63
+ # test binary access
64
+ def test_binary_access
65
+ # Check initial position
66
+ assert_equal(0, @test_records[2].position)
67
+
68
+ # Try to read all bytes
69
+ bytes = @test_records[2].all_bytes
70
+ assert_equal(300, bytes.size)
71
+ assert_equal(false, @test_records[2].is_file_open?)
72
+
73
+
74
+ # Re-check position (it should be 0)
75
+ assert_equal(0, @test_records[2].position)
76
+
77
+ # Read only one bytes and check position
78
+ byte = @test_records[2].get_byte
79
+ # check byte by code (60 == '<')
80
+ assert_equal(60, byte)
81
+ # Re-check position (it should be 1)
82
+ assert_equal(1, @test_records[2].position)
83
+ end
84
+
85
+ # test for specific classes methods
86
+ def test_specific_classes_methods
87
+ # test content value
88
+ xml_content = @test_records[2].get_content
89
+ xhtml_content = @test_records[3].get_content
90
+ hnml_content = @test_records[4].get_content
91
+
92
+ assert_kind_of REXML::Elements, xml_content
93
+ assert_not_equal nil, xml_content.nil?
94
+
95
+ assert_kind_of REXML::Elements, xhtml_content
96
+ assert_not_equal nil, xhtml_content.nil?
97
+
98
+ assert_kind_of REXML::Elements, hnml_content
99
+ assert_not_equal nil, hnml_content.nil?
100
+
101
+ # test Tidy parsing
102
+ new_record = DataTypes::XmlData.new
103
+ new_record.source_id = TaliaCore::Source.find(:first).id
104
+ new_record.create_from_data('test_file.xhtml', @test_records[5].all_text, {:tidy => true})
105
+ new_record.save!
106
+ # read data from file
107
+ string_tidy = new_record.all_text
108
+ # if tidy is enabled, check tidy output
109
+ if !ENV['TIDYLIB'].nil?
110
+ assert_equal string_tidy, @test_records[6].all_text
111
+ end
112
+ end
113
+
114
+ def test_attach
115
+ test_uri = 'http://testy.com/xml_attach'
116
+ src = Source.new(test_uri)
117
+ data_record = DataTypes::XmlData.new do |dr|
118
+ dr.location = 'my_file.xml'
119
+ end
120
+ src.data_records << data_record
121
+ src.save!
122
+ rel = Source.find(src.id)
123
+ assert_equal(1, rel.data_records.size)
124
+ assert_kind_of(DataTypes::XmlData, rel.data_records[0])
125
+ end
126
+
127
+ private
128
+ def base_dir_name(id=nil)
129
+ @data_path_test ||= File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'data_for_test', 'XmlData', ("00" + id.to_s)[-3..-1]))
130
+ end
131
+ end
132
+
133
+ end
134
+
@@ -0,0 +1,83 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
+
3
+ module TaliaCore
4
+
5
+ class GenericImporterTest < ActiveSourceParts::Xml::GenericReader
6
+ element :test_a do
7
+ add :type, TaliaCore::ActiveSource
8
+ add :uri, from_attribute(:url)
9
+ add N::TALIA.some_value, from_element(:valuator)
10
+ add_rel N::TALIA.some_reference, from_element(:refigator)
11
+ end
12
+
13
+ plain_element :dummything do
14
+ add_source :test_b do
15
+ add :uri, from_element(:url)
16
+ add :type, from_attribute(:type)
17
+ add_part :test_a
18
+ add_part :test_c do
19
+ add :uri, from_attribute(:url)
20
+ add :type, TaliaCore::ActiveSource
21
+ end
22
+ end
23
+ end
24
+
25
+ end
26
+
27
+ # Test the Generic Xml Import
28
+ class GenericXmlTest < Test::Unit::TestCase
29
+
30
+ def setup
31
+ setup_once(:flush) do
32
+ TaliaUtil::Util.flush_rdf
33
+ true
34
+ end
35
+
36
+ setup_once(:test_xml) do
37
+ File.open(TestHelper.fixture_file('generic_test.xml')) { |io| io.read }
38
+ end
39
+ setup_once(:imported) do
40
+ import = GenericImporterTest.sources_from(@test_xml)
41
+ import
42
+ end
43
+ setup_once(:sources) do
44
+ sources = {}
45
+ @imported.each do |el|
46
+ assert(el['uri'])
47
+ sources[el['uri']] = el
48
+ end
49
+ sources
50
+ end
51
+ # setup_once(:source_objects) do
52
+ # ActiveSource.create_from_xml(@test_xml, "TaliaCore::GenericImporterTest")
53
+ # end
54
+ end
55
+
56
+ def test_import_success
57
+ assert(@imported)
58
+ assert_equal(@imported.size, @sources.size)
59
+ end
60
+
61
+ def test_uris
62
+ expected = ['http://fooobar.com', 'http://www.otherfoo.com/', 'http://first_sub/X', 'http://first_sub/Y']
63
+ assert_equal(expected.sort, @sources.keys.sort)
64
+ end
65
+
66
+ def test_simple_reference
67
+ assert_equal(['<http://www.refthing.com/>'], @sources['http://fooobar.com'][N::TALIA.some_reference.to_s] )
68
+ end
69
+
70
+ def test_type
71
+ assert_equal('TaliaCore::Source', @sources['http://www.otherfoo.com/']['type'])
72
+ end
73
+
74
+ def test_part
75
+ assert_equal(['<http://www.otherfoo.com/>'], @sources['http://first_sub/Y'][N::TALIA.part_of.to_s])
76
+ end
77
+
78
+ # def test_create
79
+ # assert(@source_objects)
80
+ # end
81
+
82
+ end
83
+ end
@@ -0,0 +1,36 @@
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
+ # Just test if the initializer has works correctly. These tests will fail if you
9
+ # don't use the configuration file supplied with Talia
10
+ class InitializerTest < Test::Unit::TestCase
11
+
12
+ fixtures :active_sources
13
+
14
+ # Test it
15
+ def test_initialized
16
+ assert(TaliaCore::Initializer.initialized)
17
+ end
18
+
19
+ # Test namespaces
20
+ def test_namespaces
21
+ assert(N::LOCAL.to_s, "http://localnode.org/")
22
+ assert_equal(N::DEFAULT.to_s, "http://default.talia.eu/")
23
+ assert_equal(N::FOO.to_s, "http://foo.com/")
24
+ assert_kind_of(N::Namespace, N::FOO)
25
+ end
26
+
27
+ # Test the datase connection
28
+ def test_db_connection
29
+ assert(Source.exists?(N::LOCAL.something))
30
+ end
31
+
32
+ def test_core_ext_loading
33
+ assert 'string'.respond_to?(:to_permalink)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,398 @@
1
+ # Load the helper class
2
+ require File.join(File.dirname(__FILE__), '..', 'test_helper')
3
+
4
+ module TaliaCore
5
+
6
+ # Test the ActiveSource
7
+ class OrderedSourceTest < Test::Unit::TestCase
8
+
9
+ # fixtures :active_sources, :semantic_properties, :semantic_relations
10
+
11
+ def setup
12
+ setup_once(:flush) do
13
+ TaliaUtil::Util.flush_db
14
+ TaliaUtil::Util.flush_rdf
15
+ true
16
+ end
17
+ end
18
+
19
+ def test_resource_type
20
+ ordered_source = OrderedSource.new('http://testvalue.org/ordered_set/type')
21
+ # check class
22
+ assert_kind_of OrderedSource, ordered_source
23
+ # check type
24
+ # assert_equal 'http://www.w3.org/1999/02/22-rdf-syntax-ns#Seq', ordered_source.types.to_s
25
+ end
26
+
27
+ def test_elements
28
+ # create new OrderedSource
29
+ ordered_source = OrderedSource.new('http://testvalue.org/ordered_set/elenments')
30
+ ordered_source.save!
31
+
32
+ # create 3 items
33
+ item_1 = ActiveSource.new('http://testvalue.org/item_1')
34
+ item_2 = ActiveSource.new('http://testvalue.org/item_2')
35
+ item_3 = ActiveSource.new('http://testvalue.org/item_3')
36
+
37
+ # add items to OrderedSource
38
+ ordered_source[(RDF::_000001).uri].add_with_order(item_1, 1)
39
+ ordered_source[(RDF::_000002).uri].add_with_order(item_2, 2)
40
+ ordered_source[(RDF::_000003).uri].add_with_order(item_3, 3)
41
+ ordered_source.save!
42
+
43
+ # check if all items are inserted
44
+ assert_equal 3, ordered_source.elements.size
45
+ assert_equal item_1.uri, ordered_source.elements[0].uri
46
+ assert_equal item_2.uri, ordered_source.elements[1].uri
47
+ assert_equal item_3.uri, ordered_source.elements[2].uri
48
+ end
49
+
50
+ def test_add
51
+ # create new OrderedSource
52
+ ordered_source = OrderedSource.new('http://testvalue.org/ordered_set')
53
+ ordered_source.save!
54
+ assert ordered_source.elements.empty?
55
+
56
+ # create 3 items
57
+ item_1 = ActiveSource.new('http://testvalue.org/item_1')
58
+ item_2 = ActiveSource.new('http://testvalue.org/item_2')
59
+
60
+ # add item to ordered source
61
+ ordered_source.add item_1
62
+ ordered_source.save!
63
+
64
+ # check if all items are inserted
65
+ assert_equal 1, ordered_source.elements.size
66
+ assert_equal item_1.uri, ordered_source.elements[0].uri
67
+
68
+ ordered_source.add item_2
69
+ ordered_source.save!
70
+
71
+ # check if all items are inserted
72
+ assert_equal 2, ordered_source.elements.size
73
+ assert_equal item_1.uri, ordered_source.elements[0].uri
74
+ assert_equal item_2.uri, ordered_source.elements[1].uri
75
+ end
76
+
77
+ def test_remove
78
+ # create new OrderedSource
79
+ ordered_source = OrderedSource.new('http://testvalue.org/ordered_set_remove')
80
+ ordered_source.save!
81
+ assert ordered_source.elements.empty?
82
+
83
+ # create 3 items
84
+ item_1 = ActiveSource.new('http://testvalue.org/item_1')
85
+ item_2 = ActiveSource.new('http://testvalue.org/item_2')
86
+
87
+ # add items to ordered source
88
+ ordered_source.add item_1
89
+ ordered_source.add item_2
90
+
91
+ # check if all items are inserted
92
+ assert_equal 2, ordered_source.elements.size
93
+ assert_equal item_1.uri, ordered_source.elements[0].uri
94
+ assert_equal item_2.uri, ordered_source.elements[1].uri
95
+
96
+ # test delete item 1
97
+ ordered_source.delete 1
98
+
99
+ # check if item1 is been deleted
100
+ assert_equal 1, ordered_source.elements.size
101
+ assert_equal item_2.uri, ordered_source.elements[0].uri
102
+
103
+ # test delete item 1
104
+ ordered_source.delete 1
105
+ ordered_source.save!
106
+
107
+ # check if item1 is been deleted
108
+ assert_equal 0, ordered_source.elements.size
109
+
110
+ # add items to ordered source
111
+ ordered_source.add item_1
112
+ ordered_source.add item_2
113
+
114
+ # delete all item
115
+ ordered_source.delete_all
116
+
117
+ # check if all items are been deleted
118
+ assert_equal 0, ordered_source.elements.size
119
+ assert ordered_source.elements.empty?
120
+ end
121
+
122
+
123
+ def test_replace
124
+ # create new OrderedSource
125
+ ordered_source = OrderedSource.new('http://testvalue.org/ordered_set/replace')
126
+ ordered_source.save!
127
+ assert ordered_source.elements.empty?
128
+
129
+ # create 3 items
130
+ item_1 = ActiveSource.new('http://testvalue.org/item_1')
131
+ item_2 = ActiveSource.new('http://testvalue.org/item_2')
132
+ item_3 = ActiveSource.new('http://testvalue.org/item_3')
133
+
134
+ # add items to ordered source
135
+ ordered_source.add item_1
136
+ ordered_source.add item_2
137
+
138
+ # check if all items are inserted
139
+ assert_equal 2, ordered_source.elements.size
140
+ assert_equal item_1.uri, ordered_source.elements[0].uri
141
+ assert_equal item_2.uri, ordered_source.elements[1].uri
142
+
143
+ # test delete item 1
144
+ ordered_source.replace 1,item_3
145
+
146
+ # check if item1 is been replaced
147
+ assert_equal 2, ordered_source.elements.size
148
+ assert_not_equal item_1.uri, ordered_source.elements[0].uri
149
+ assert_equal item_3.uri, ordered_source.elements[0].uri
150
+ assert_equal item_2.uri, ordered_source.elements[1].uri
151
+ end
152
+
153
+ def test_size
154
+ # create new OrderedSource
155
+ ordered_source = OrderedSource.new('http://testvalue.org/ordered_set/size')
156
+ ordered_source.save!
157
+ assert ordered_source.elements.empty?
158
+
159
+ # the size must be 0
160
+ assert_equal 0, ordered_source.size
161
+
162
+ # create 3 items
163
+ item_1 = ActiveSource.new('http://testvalue.org/item_1')
164
+ item_2 = ActiveSource.new('http://testvalue.org/item_2')
165
+ item_3 = ActiveSource.new('http://testvalue.org/item_3')
166
+
167
+ # add items to OrderedSource
168
+ ordered_source.insert_at(101, item_1)
169
+ ordered_source.insert_at(103, item_3)
170
+ ordered_source.insert_at(102, item_2)
171
+
172
+ # the size must be 104 (counting the 0-element
173
+ assert_equal 104, ordered_source.size
174
+ end
175
+
176
+ def test_at
177
+ # create new OrderedSource
178
+ ordered_source = OrderedSource.new('http://testvalue.org/ordered_set/at')
179
+ ordered_source.save!
180
+ assert ordered_source.elements.empty?
181
+
182
+ # the size must be 0
183
+ assert_equal 0, ordered_source.size
184
+
185
+ # create 3 items
186
+ item_1 = ActiveSource.new('http://testvalue.org/item_1')
187
+ item_2 = ActiveSource.new('http://testvalue.org/item_2')
188
+ item_3 = ActiveSource.new('http://testvalue.org/item_3')
189
+
190
+ # add items to OrderedSource
191
+ ordered_source.add item_1
192
+ ordered_source.add item_2
193
+ ordered_source.add item_3
194
+
195
+ # check at method
196
+ assert_kind_of TaliaCore::ActiveSource, ordered_source.at(1)
197
+ assert_equal item_1.uri, ordered_source.at(1).uri
198
+ assert_kind_of TaliaCore::ActiveSource, ordered_source.at(2)
199
+ assert_equal item_2.uri, ordered_source.at(2).uri
200
+ assert_kind_of TaliaCore::ActiveSource, ordered_source.at(3)
201
+ assert_equal item_3.uri, ordered_source.at(3).uri
202
+ end
203
+
204
+ def test_add_more_then_10_items
205
+ # create new OrderedSource
206
+ ordered_source = OrderedSource.new('http://testvalue.org/ordered_set/tenit')
207
+ ordered_source.save!
208
+ assert_equal 0, ordered_source.elements.size, "#{ordered_source.elements.collect { |el| el.uri }}"
209
+
210
+ # the size must be 0
211
+ assert_equal 0, ordered_source.size
212
+
213
+ # create 3 items
214
+ item_1 = ActiveSource.new('http://testvalue.org/item_1')
215
+ item_2 = ActiveSource.new('http://testvalue.org/item_2')
216
+ item_3 = ActiveSource.new('http://testvalue.org/item_3')
217
+ item_4 = ActiveSource.new('http://testvalue.org/item_4')
218
+ item_5 = ActiveSource.new('http://testvalue.org/item_5')
219
+ item_6 = ActiveSource.new('http://testvalue.org/item_6')
220
+ item_7 = ActiveSource.new('http://testvalue.org/item_7')
221
+ item_8 = ActiveSource.new('http://testvalue.org/item_8')
222
+ item_9 = ActiveSource.new('http://testvalue.org/item_9')
223
+ item_10 = ActiveSource.new('http://testvalue.org/item_10')
224
+ item_11 = ActiveSource.new('http://testvalue.org/item_11')
225
+ item_12 = ActiveSource.new('http://testvalue.org/item_12')
226
+
227
+ # add items to OrderedSource
228
+ ordered_source.add item_1
229
+ ordered_source.add item_2
230
+ ordered_source.add item_3
231
+ ordered_source.add item_4
232
+ ordered_source.add item_5
233
+ ordered_source.add item_6
234
+ ordered_source.add item_7
235
+ ordered_source.add item_8
236
+ ordered_source.add item_9
237
+ ordered_source.add item_10
238
+ ordered_source.add item_11
239
+ ordered_source.add item_12
240
+
241
+ # check at method
242
+ assert_kind_of TaliaCore::ActiveSource, ordered_source.at(1)
243
+ assert_equal item_1.uri, ordered_source.at(1).uri
244
+ assert_kind_of TaliaCore::ActiveSource, ordered_source.at(2)
245
+ assert_equal item_2.uri, ordered_source.at(2).uri
246
+ assert_kind_of TaliaCore::ActiveSource, ordered_source.at(3)
247
+ assert_equal item_3.uri, ordered_source.at(3).uri
248
+ assert_kind_of TaliaCore::ActiveSource, ordered_source.at(4)
249
+ assert_equal item_4.uri, ordered_source.at(4).uri
250
+ assert_kind_of TaliaCore::ActiveSource, ordered_source.at(5)
251
+ assert_equal item_5.uri, ordered_source.at(5).uri
252
+ assert_kind_of TaliaCore::ActiveSource, ordered_source.at(6)
253
+ assert_equal item_6.uri, ordered_source.at(6).uri
254
+ assert_kind_of TaliaCore::ActiveSource, ordered_source.at(7)
255
+ assert_equal item_7.uri, ordered_source.at(7).uri
256
+ assert_kind_of TaliaCore::ActiveSource, ordered_source.at(8)
257
+ assert_equal item_8.uri, ordered_source.at(8).uri
258
+ assert_kind_of TaliaCore::ActiveSource, ordered_source.at(9)
259
+ assert_equal item_9.uri, ordered_source.at(9).uri
260
+ assert_kind_of TaliaCore::ActiveSource, ordered_source.at(10)
261
+ assert_equal item_10.uri, ordered_source.at(10).uri
262
+ assert_kind_of TaliaCore::ActiveSource, ordered_source.at(11)
263
+ assert_equal item_11.uri, ordered_source.at(11).uri
264
+ assert_kind_of TaliaCore::ActiveSource, ordered_source.at(12)
265
+ assert_equal item_12.uri, ordered_source.at(12).uri
266
+
267
+ # test order
268
+ elements = ordered_source.elements.collect { |el| el.uri }
269
+ elements_array = []
270
+ elements_array << 'http://testvalue.org/item_1'
271
+ elements_array << 'http://testvalue.org/item_2'
272
+ elements_array << 'http://testvalue.org/item_3'
273
+ elements_array << 'http://testvalue.org/item_4'
274
+ elements_array << 'http://testvalue.org/item_5'
275
+ elements_array << 'http://testvalue.org/item_6'
276
+ elements_array << 'http://testvalue.org/item_7'
277
+ elements_array << 'http://testvalue.org/item_8'
278
+ elements_array << 'http://testvalue.org/item_9'
279
+ elements_array << 'http://testvalue.org/item_10'
280
+ elements_array << 'http://testvalue.org/item_11'
281
+ elements_array << 'http://testvalue.org/item_12'
282
+ assert_equal elements_array, elements
283
+ end
284
+
285
+ def test_next_and_previous
286
+ # create new OrderedSource
287
+ ordered_source = OrderedSource.new('http://testvalue.org/ordered_set/nextprev')
288
+ ordered_source.save!
289
+ assert ordered_source.elements.empty?
290
+
291
+ # the size must be 0
292
+ assert_equal 0, ordered_source.size
293
+
294
+ # create 3 items
295
+ item_1 = ActiveSource.new('http://testvalue.org/item_1')
296
+ item_2 = ActiveSource.new('http://testvalue.org/item_2')
297
+ item_3 = ActiveSource.new('http://testvalue.org/item_3')
298
+
299
+ # add items to OrderedSource
300
+ ordered_source.add item_1
301
+ ordered_source.add item_2
302
+ ordered_source.add item_3
303
+
304
+ # test next method
305
+ item = ordered_source.at(2)
306
+ assert_kind_of TaliaCore::ActiveSource, ordered_source.at(2)
307
+ assert_equal item_2.uri, ordered_source.at(2).uri
308
+ assert_equal 2, ordered_source.current_index
309
+
310
+ @next = ordered_source.next
311
+ assert_kind_of TaliaCore::ActiveSource, @next
312
+ assert_equal item_3.uri, @next.uri
313
+ assert_equal 3, ordered_source.current_index
314
+
315
+ assert_raise(RuntimeError) {ordered_source.next}
316
+ assert_equal 3, ordered_source.current_index
317
+
318
+ # test previous method
319
+ item = ordered_source.at(2)
320
+ assert_kind_of TaliaCore::ActiveSource, ordered_source.at(2)
321
+ assert_equal item_2.uri, ordered_source.at(2).uri
322
+ assert_equal 2, ordered_source.current_index
323
+
324
+ @previous = ordered_source.previous
325
+ assert_kind_of TaliaCore::ActiveSource, @previous
326
+ assert_equal item_1.uri, @previous.uri
327
+ assert_equal 1, ordered_source.current_index
328
+
329
+ assert_raise(RuntimeError) {ordered_source.previous}
330
+ assert_equal 1, ordered_source.current_index
331
+
332
+ # test next with index
333
+ @next = ordered_source.next(2)
334
+ assert_kind_of TaliaCore::ActiveSource, @next
335
+ assert_equal item_3.uri, @next.uri
336
+ assert_equal 3, ordered_source.current_index
337
+
338
+ assert_raise(RuntimeError) {ordered_source.next(3)}
339
+ assert_equal 3, ordered_source.current_index
340
+
341
+ # test next with element
342
+ @next = ordered_source.next(item_2)
343
+ assert_kind_of TaliaCore::ActiveSource, @next
344
+ assert_equal item_3.uri, @next.uri
345
+ assert_equal 3, ordered_source.current_index
346
+
347
+ # test previous with index
348
+ @previous = ordered_source.previous(2)
349
+ assert_kind_of TaliaCore::ActiveSource, @previous
350
+ assert_equal item_1.uri, @previous.uri
351
+ assert_equal 1, ordered_source.current_index
352
+
353
+ assert_raise(RuntimeError) {ordered_source.previous(1)}
354
+ assert_equal 1, ordered_source.current_index
355
+
356
+ # test previous with element
357
+ @previous = ordered_source.previous(item_2)
358
+ assert_kind_of TaliaCore::ActiveSource, @previous
359
+ assert_equal item_1.uri, @previous.uri
360
+ assert_equal 1, ordered_source.current_index
361
+
362
+ end
363
+
364
+ def test_find_ordered_source
365
+ # create new OrderedSource
366
+ ordered_source = OrderedSource.new('http://testvalue.org/ordered_set/find')
367
+ ordered_source.save!
368
+ assert ordered_source.elements.empty?
369
+
370
+ # the size must be 0
371
+ assert_equal 0, ordered_source.size
372
+
373
+ # create 3 items
374
+ item_1 = ActiveSource.new('http://testvalue.org/item_1')
375
+ item_2 = ActiveSource.new('http://testvalue.org/item_2')
376
+ item_3 = ActiveSource.new('http://testvalue.org/item_3')
377
+
378
+ # add items to OrderedSource
379
+ ordered_source.add item_1
380
+ ordered_source.add item_2
381
+ ordered_source.add item_3
382
+
383
+ # test find method
384
+ assert_equal 2, ordered_source.find_position_by_object(item_2)
385
+ end
386
+
387
+ def test_save_reload
388
+ ordered = OrderedSource.new('http://orderedsource_save_and_load')
389
+ item_1 = ActiveSource.new('http://orderedsource_save_and_load/item')
390
+ ordered.insert_at(15, item_1)
391
+ assert_equal(item_1, ordered.at(15))
392
+ ordered.save!
393
+ reload = OrderedSource.find(ordered.id)
394
+ assert_equal(item_1, reload.at(15))
395
+ end
396
+
397
+ end
398
+ end