activerdf_net7 1.6.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (190) hide show
  1. data/CHANGELOG +79 -0
  2. data/LICENSE +504 -0
  3. data/README.rdoc +34 -0
  4. data/activerdf-jena/CHANGELOG +14 -0
  5. data/activerdf-jena/LICENSE +504 -0
  6. data/activerdf-jena/README +57 -0
  7. data/activerdf-jena/Rakefile +87 -0
  8. data/activerdf-jena/TODO +18 -0
  9. data/activerdf-jena/VERSION +1 -0
  10. data/activerdf-jena/ext/antlr-2.7.5.jar +0 -0
  11. data/activerdf-jena/ext/arq-extra.jar +0 -0
  12. data/activerdf-jena/ext/arq.jar +0 -0
  13. data/activerdf-jena/ext/aterm-java-1.6.jar +0 -0
  14. data/activerdf-jena/ext/commons-logging-1.1.jar +0 -0
  15. data/activerdf-jena/ext/concurrent.jar +0 -0
  16. data/activerdf-jena/ext/icu4j_3_4.jar +0 -0
  17. data/activerdf-jena/ext/iri.jar +0 -0
  18. data/activerdf-jena/ext/jena.jar +0 -0
  19. data/activerdf-jena/ext/jenatest.jar +0 -0
  20. data/activerdf-jena/ext/json.jar +0 -0
  21. data/activerdf-jena/ext/junit.jar +0 -0
  22. data/activerdf-jena/ext/log4j-1.2.12.jar +0 -0
  23. data/activerdf-jena/ext/lucene-core-2.0.0.jar +0 -0
  24. data/activerdf-jena/ext/ng4j.jar +0 -0
  25. data/activerdf-jena/ext/pellet.jar +0 -0
  26. data/activerdf-jena/ext/relaxngDatatype.jar +0 -0
  27. data/activerdf-jena/ext/stax-api-1.0.jar +0 -0
  28. data/activerdf-jena/ext/wstx-asl-3.0.0.jar +0 -0
  29. data/activerdf-jena/ext/xercesImpl.jar +0 -0
  30. data/activerdf-jena/ext/xml-apis.jar +0 -0
  31. data/activerdf-jena/ext/xsdlib.jar +0 -0
  32. data/activerdf-jena/lib/activerdf_jena/init.rb +26 -0
  33. data/activerdf-jena/lib/activerdf_jena/jena.rb +59 -0
  34. data/activerdf-jena/lib/activerdf_jena/jena_adapter.rb +515 -0
  35. data/activerdf-jena/lib/activerdf_jena/lucene.rb +22 -0
  36. data/activerdf-jena/lib/activerdf_jena/ng4j.rb +50 -0
  37. data/activerdf-jena/lib/activerdf_jena/ng4j_adapter.rb +379 -0
  38. data/activerdf-jena/lib/activerdf_jena/pellet.rb +25 -0
  39. data/activerdf-jena/test/bnode_org_rss.rdf +793 -0
  40. data/activerdf-jena/test/eyal-foaf.nt +39 -0
  41. data/activerdf-jena/test/fun_with_bnodes.nt +2 -0
  42. data/activerdf-jena/test/s1.n3 +18 -0
  43. data/activerdf-jena/test/test_data.nt +32 -0
  44. data/activerdf-jena/test/test_jena_adapter.rb +451 -0
  45. data/activerdf-jena/test/test_ng4j_adapter.rb +354 -0
  46. data/activerdf-rdflite/CHANGELOG +31 -0
  47. data/activerdf-rdflite/LICENSE +504 -0
  48. data/activerdf-rdflite/README +16 -0
  49. data/activerdf-rdflite/Rakefile +73 -0
  50. data/activerdf-rdflite/VERSION +1 -0
  51. data/activerdf-rdflite/lib/activerdf_rdflite/fetching.rb +34 -0
  52. data/activerdf-rdflite/lib/activerdf_rdflite/init.rb +13 -0
  53. data/activerdf-rdflite/lib/activerdf_rdflite/rdflite.rb +582 -0
  54. data/activerdf-rdflite/lib/activerdf_rdflite/suggesting.rb +87 -0
  55. data/activerdf-rdflite/test/test_bnode_data.nt +5 -0
  56. data/activerdf-rdflite/test/test_data.nt +32 -0
  57. data/activerdf-rdflite/test/test_escaped_data.nt +2 -0
  58. data/activerdf-rdflite/test/test_fetching.rb +33 -0
  59. data/activerdf-rdflite/test/test_rdflite.rb +277 -0
  60. data/activerdf-redland/CHANGELOG +12 -0
  61. data/activerdf-redland/LICENSE +504 -0
  62. data/activerdf-redland/README +9 -0
  63. data/activerdf-redland/Rakefile +72 -0
  64. data/activerdf-redland/VERSION +1 -0
  65. data/activerdf-redland/lib/activerdf_redland/init.rb +10 -0
  66. data/activerdf-redland/lib/activerdf_redland/redland.rb +362 -0
  67. data/activerdf-redland/test/test_person_data.nt +42 -0
  68. data/activerdf-redland/test/test_redland_adapter.rb +242 -0
  69. data/activerdf-sesame/CHANGELOG +6 -0
  70. data/activerdf-sesame/LICENSE +10 -0
  71. data/activerdf-sesame/LICENSE-aduna +10 -0
  72. data/activerdf-sesame/LICENSE-lgpl +504 -0
  73. data/activerdf-sesame/README +33 -0
  74. data/activerdf-sesame/Rakefile +77 -0
  75. data/activerdf-sesame/VERSION +1 -0
  76. data/activerdf-sesame/ext/commons-codec-1.3.jar +0 -0
  77. data/activerdf-sesame/ext/commons-dbcp-1.2.2.jar +0 -0
  78. data/activerdf-sesame/ext/commons-httpclient-3.1.jar +0 -0
  79. data/activerdf-sesame/ext/commons-logging-1.1.1.jar +0 -0
  80. data/activerdf-sesame/ext/commons-pool-1.3.jar +0 -0
  81. data/activerdf-sesame/ext/commons-pool-1.5.2.jar +0 -0
  82. data/activerdf-sesame/ext/junit-3.8.2.jar +0 -0
  83. data/activerdf-sesame/ext/openrdf-sesame-2.0-onejar.jar +0 -0
  84. data/activerdf-sesame/ext/openrdf-sesame-2.3-pr1-onejar.jar +0 -0
  85. data/activerdf-sesame/ext/slf4j-api-1.4.3.jar +0 -0
  86. data/activerdf-sesame/ext/slf4j-nop-1.4.3.jar +0 -0
  87. data/activerdf-sesame/ext/wrapper-sesame2.jar +0 -0
  88. data/activerdf-sesame/java/build.number +3 -0
  89. data/activerdf-sesame/java/build.xml +313 -0
  90. data/activerdf-sesame/java/javadoc/allclasses-frame.html +31 -0
  91. data/activerdf-sesame/java/javadoc/allclasses-noframe.html +31 -0
  92. data/activerdf-sesame/java/javadoc/constant-values.html +146 -0
  93. data/activerdf-sesame/java/javadoc/deprecated-list.html +146 -0
  94. data/activerdf-sesame/java/javadoc/help-doc.html +223 -0
  95. data/activerdf-sesame/java/javadoc/index-files/index-1.html +150 -0
  96. data/activerdf-sesame/java/javadoc/index-files/index-10.html +145 -0
  97. data/activerdf-sesame/java/javadoc/index-files/index-2.html +157 -0
  98. data/activerdf-sesame/java/javadoc/index-files/index-3.html +146 -0
  99. data/activerdf-sesame/java/javadoc/index-files/index-4.html +145 -0
  100. data/activerdf-sesame/java/javadoc/index-files/index-5.html +145 -0
  101. data/activerdf-sesame/java/javadoc/index-files/index-6.html +142 -0
  102. data/activerdf-sesame/java/javadoc/index-files/index-7.html +145 -0
  103. data/activerdf-sesame/java/javadoc/index-files/index-8.html +152 -0
  104. data/activerdf-sesame/java/javadoc/index-files/index-9.html +146 -0
  105. data/activerdf-sesame/java/javadoc/index.html +36 -0
  106. data/activerdf-sesame/java/javadoc/org/activerdf/wrapper/sesame2/WrapperForSesame2.html +665 -0
  107. data/activerdf-sesame/java/javadoc/org/activerdf/wrapper/sesame2/class-use/WrapperForSesame2.html +144 -0
  108. data/activerdf-sesame/java/javadoc/org/activerdf/wrapper/sesame2/package-frame.html +32 -0
  109. data/activerdf-sesame/java/javadoc/org/activerdf/wrapper/sesame2/package-summary.html +157 -0
  110. data/activerdf-sesame/java/javadoc/org/activerdf/wrapper/sesame2/package-tree.html +150 -0
  111. data/activerdf-sesame/java/javadoc/org/activerdf/wrapper/sesame2/package-use.html +144 -0
  112. data/activerdf-sesame/java/javadoc/overview-summary.html +156 -0
  113. data/activerdf-sesame/java/javadoc/overview-tree.html +152 -0
  114. data/activerdf-sesame/java/javadoc/package-list +1 -0
  115. data/activerdf-sesame/java/javadoc/resources/inherit.gif +0 -0
  116. data/activerdf-sesame/java/javadoc/stylesheet.css +29 -0
  117. data/activerdf-sesame/java/lib/commons-codec-1.3.jar +0 -0
  118. data/activerdf-sesame/java/lib/commons-dbcp-1.2.2.jar +0 -0
  119. data/activerdf-sesame/java/lib/commons-httpclient-3.1.jar +0 -0
  120. data/activerdf-sesame/java/lib/commons-logging-1.1.1.jar +0 -0
  121. data/activerdf-sesame/java/lib/commons-pool-1.3.jar +0 -0
  122. data/activerdf-sesame/java/lib/commons-pool-1.5.2.jar +0 -0
  123. data/activerdf-sesame/java/lib/junit-3.8.2.jar +0 -0
  124. data/activerdf-sesame/java/lib/openrdf-sesame-2.0-onejar.jar +0 -0
  125. data/activerdf-sesame/java/lib/openrdf-sesame-2.3-pr1-onejar.jar +0 -0
  126. data/activerdf-sesame/java/lib/slf4j-api-1.4.3.jar +0 -0
  127. data/activerdf-sesame/java/lib/slf4j-nop-1.4.3.jar +0 -0
  128. data/activerdf-sesame/java/manifest.mf +3 -0
  129. data/activerdf-sesame/java/settings.xml +135 -0
  130. data/activerdf-sesame/java/src/org/activerdf/wrapper/sesame2/WrapperForSesame2.java +145 -0
  131. data/activerdf-sesame/java/test-src/org/activerdf/wrapper/sesame2/TestWrapperForSesame2.java +41 -0
  132. data/activerdf-sesame/lib/activerdf_sesame/init.rb +11 -0
  133. data/activerdf-sesame/lib/activerdf_sesame/sesame.rb +400 -0
  134. data/activerdf-sesame/test/eyal-foaf.nt +39 -0
  135. data/activerdf-sesame/test/eyal-foaf.rdf +65 -0
  136. data/activerdf-sesame/test/test_sesame_adapter.rb +341 -0
  137. data/activerdf-sparql/CHANGELOG +35 -0
  138. data/activerdf-sparql/LICENSE +504 -0
  139. data/activerdf-sparql/README +10 -0
  140. data/activerdf-sparql/Rakefile +78 -0
  141. data/activerdf-sparql/VERSION +1 -0
  142. data/activerdf-sparql/lib/activerdf_sparql/init.rb +10 -0
  143. data/activerdf-sparql/lib/activerdf_sparql/sparql.rb +212 -0
  144. data/activerdf-sparql/lib/activerdf_sparql/sparql_result_parser.rb +55 -0
  145. data/activerdf-sparql/test/test_sparql_adapter.rb +108 -0
  146. data/activerdf-yars/LICENSE +504 -0
  147. data/activerdf-yars/README +10 -0
  148. data/activerdf-yars/Rakefile +38 -0
  149. data/activerdf-yars/lib/activerdf_yars/init.rb +10 -0
  150. data/activerdf-yars/lib/activerdf_yars/jars2.rb +119 -0
  151. data/lib/active_rdf.rb +85 -0
  152. data/lib/active_rdf/directaccess/direct_access.rb +49 -0
  153. data/lib/active_rdf/federation/active_rdf_adapter.rb +47 -0
  154. data/lib/active_rdf/federation/connection_pool.rb +156 -0
  155. data/lib/active_rdf/federation/federation_manager.rb +112 -0
  156. data/lib/active_rdf/instance_exec.rb +13 -0
  157. data/lib/active_rdf/objectmanager/bnode.rb +7 -0
  158. data/lib/active_rdf/objectmanager/literal.rb +71 -0
  159. data/lib/active_rdf/objectmanager/namespace.rb +106 -0
  160. data/lib/active_rdf/objectmanager/object_manager.rb +119 -0
  161. data/lib/active_rdf/objectmanager/ordered_set.rb +116 -0
  162. data/lib/active_rdf/objectmanager/property_list.rb +76 -0
  163. data/lib/active_rdf/objectmanager/resource.rb +609 -0
  164. data/lib/active_rdf/objectmanager/resource_like.rb +28 -0
  165. data/lib/active_rdf/queryengine/ntriples_parser.rb +90 -0
  166. data/lib/active_rdf/queryengine/query.rb +245 -0
  167. data/lib/active_rdf/queryengine/query2jars2.rb +22 -0
  168. data/lib/active_rdf/queryengine/query2sparql.rb +139 -0
  169. data/lib/active_rdf_helpers.rb +30 -0
  170. data/lib/active_rdf_log.rb +100 -0
  171. data/test/common.rb +119 -0
  172. data/test/directaccess/test_direct_access.rb +64 -0
  173. data/test/federation/test_connection_pool.rb +86 -0
  174. data/test/federation/test_federation_manager.rb +145 -0
  175. data/test/objectmanager/test_literal.rb +52 -0
  176. data/test/objectmanager/test_namespace.rb +83 -0
  177. data/test/objectmanager/test_object_manager.rb +96 -0
  178. data/test/objectmanager/test_ordered_set.rb +110 -0
  179. data/test/objectmanager/test_resource_reading.rb +150 -0
  180. data/test/objectmanager/test_resource_writing.rb +39 -0
  181. data/test/objectmanager/test_talia_syntax.rb +68 -0
  182. data/test/queryengine/my_external_resource.rb +24 -0
  183. data/test/queryengine/test_external_resource_class.rb +49 -0
  184. data/test/queryengine/test_ntriples_parser.rb +71 -0
  185. data/test/queryengine/test_query.rb +55 -0
  186. data/test/queryengine/test_query2jars2.rb +51 -0
  187. data/test/queryengine/test_query2sparql.rb +76 -0
  188. data/test/queryengine/test_query_engine.rb +52 -0
  189. data/test/test_adapters.rb +58 -0
  190. metadata +266 -0
@@ -0,0 +1,30 @@
1
+ # Default ActiveRDF error
2
+ class ActiveRdfError < StandardError
3
+ end
4
+
5
+ class Module
6
+ # Adds boolean accessor to a class (e.g. person.male?)
7
+ def bool_accessor *syms
8
+ attr_accessor(*syms)
9
+ syms.each { |sym| alias_method "#{sym}?", sym }
10
+ remove_method(*syms)
11
+ end
12
+ end
13
+
14
+ module ActiveRdfBenchmark
15
+ # Benchmarking for ActiveRecord. You may pass a message with additional
16
+ # information - there's a little hack that the "real" benchmark will pass
17
+ # the message to the block, while the "non-benchmark" call will pass nil.
18
+ # This allows you to build the message in the block only if you need it.
19
+ def benchmark(title, log_level = Logger::DEBUG, message = '')
20
+ if(ActiveRdfLogger.logger.level <= log_level)
21
+ result = nil
22
+ seconds = Benchmark.realtime { result = yield(message) }
23
+ ActiveRdfLogger.log_add("\033[31m\033[1m#{title}\033[0m (#{'%.5f' % seconds}) -- \033[34m#{message}\033[0m", log_level, self)
24
+ result
25
+ else
26
+ yield(nil)
27
+ end
28
+ end
29
+
30
+ end
@@ -0,0 +1,100 @@
1
+ require 'logger'
2
+
3
+
4
+ class ActiveRdfLogger
5
+
6
+ # Create log methods for each level
7
+ %w(debug info warn error fatal).each do |level|
8
+ module_eval <<-"end_eval"
9
+ def self.log_#{level}(message_or_context, context = nil)
10
+ message_or_context, context = nil, message_or_context if(block_given?)
11
+ log_add(message_or_context, Logger::#{level.upcase}, context) do
12
+ yield if(block_given?)
13
+ end
14
+ end
15
+ end_eval
16
+ end
17
+
18
+ class << self
19
+
20
+ # Get the logger for the ActiveRDF library. This will default to the Rails
21
+ # logger if that is active. Otherwise it will use the configured logger
22
+ # for ActiveRDF. (Note that some messages may go to the configured logger
23
+ # if ActiveRDF is initialized before Rails).
24
+ def logger
25
+ @logger ||= get_active_rdf_logger
26
+ end
27
+
28
+ # Assign a new logger
29
+ def logger=(logger)
30
+ @logger = logger
31
+ @native_logger = false
32
+ end
33
+
34
+ # Logs a message of the given severity. The context may identify the class/
35
+ # object that logged the message
36
+ def log_add(message = nil, severity = Logger::DEBUG, context = nil)
37
+ logger.add(severity, nil, "ActiveRDF") do
38
+ message = yield if(!message && block_given?)
39
+ log_message(message, context)
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def log_message(message, context = nil)
46
+ message = ("\033[32m\033[4m\033[1m#{context_string(context)}\033[0m ") << message if(context)
47
+ return message if(@native_logger)
48
+ "\033[35m\033[4m\033[1mActiveRDF\033[0m " << message
49
+ end
50
+
51
+ def context_string(context)
52
+ return context if(context.is_a?(String))
53
+ context = context.class unless(context.is_a?(Class))
54
+ context.name
55
+ end
56
+
57
+ def get_active_rdf_logger
58
+ if(defined?(RAILS_DEFAULT_LOGGER) && RAILS_DEFAULT_LOGGER)
59
+ RAILS_DEFAULT_LOGGER
60
+ else
61
+ @native_logger = true
62
+
63
+ # use either $ACTIVE_RDF_LOG for logging or current directory
64
+ location = ENV['ACTIVE_RDF_LOG'] || $stdout # "#{Dir.pwd}/activerdf.log"
65
+ location = $stdout if(location == "STDOUT")
66
+ logger = Logger.new(location, 1, 100*1024)
67
+
68
+ # if user has specified loglevel we use that, otherwise we use default level
69
+ # in the environment variable ACTIVE_RDF_LOG_LEVEL we expect numbers, which we
70
+ # have to convert
71
+ if ENV['ACTIVE_RDF_LOG_LEVEL'].nil?
72
+ logger.level = Logger::WARN
73
+ else
74
+ logger.level = ENV['ACTIVE_RDF_LOG_LEVEL'].to_i
75
+ end
76
+
77
+ logger
78
+ end
79
+ end
80
+
81
+ end
82
+ end
83
+
84
+ class Logger
85
+ def debug_pp(message, variable)
86
+ if variable.respond_to?(:join)
87
+ if variable.empty?
88
+ debug(sprintf(message, "empty"))
89
+ else
90
+ debug(sprintf(message, variable.join(', ')))
91
+ end
92
+ else
93
+ if variable.nil?
94
+ debug(sprintf(message, 'empty'))
95
+ else
96
+ debug(sprintf(message, variable))
97
+ end
98
+ end
99
+ end
100
+ end
data/test/common.rb ADDED
@@ -0,0 +1,119 @@
1
+ def get_adapter
2
+ types = ConnectionPool.adapter_types
3
+ if types.include?(:rdflite)
4
+ get_rdflite
5
+ elsif types.include?(:redland)
6
+ get_redland
7
+ elsif types.include?(:sparql)
8
+ get_sparql
9
+ elsif types.include?(:yars)
10
+ get_yars
11
+ elsif types.include?(:jars2)
12
+ get_jars2
13
+ else
14
+ raise ActiveRdfError, "no suitable adapter found for test"
15
+ end
16
+ end
17
+
18
+ def get_read_only_adapter
19
+ if ConnectionPool.adapter_types.include?(:sparql)
20
+ get_sparql
21
+ else
22
+ raise ActiveRdfError, "no suitable read-only adapter found for test"
23
+ end
24
+ end
25
+
26
+ # TODO make this work with a list of existing adapters, not only one
27
+ def get_different_adapter(existing_adapter)
28
+ types = ConnectionPool.adapter_types
29
+ if types.include?(:rdflite)
30
+ if existing_adapter.class == RDFLite
31
+ ConnectionPool.add :type => :rdflite, :unique => true
32
+ else
33
+ get_rdflite
34
+ end
35
+ elsif types.include?(:redland) and existing_adapter.class != RedlandAdapter
36
+ get_rdflite
37
+ elsif types.include?(:sparql) and existing_adapter.class != SparqlAdapter
38
+ get_sparql
39
+ elsif types.include?(:yars) and existing_adapter.class != YarsAdapter
40
+ get_yars
41
+ elsif types.include?(:jars2) and existing_adapter.class != Jars2Adapter
42
+ get_jars2
43
+ else
44
+ raise ActiveRdfError, "only one adapter on this system, or no suitable adapter found for test"
45
+ end
46
+ end
47
+
48
+ def get_all_read_adapters
49
+ types = ConnectionPool.adapter_types
50
+ adapters = types.collect {|type| self.send("get_#{type}") }
51
+ adapters.select {|adapter| adapter.reads?}
52
+ end
53
+
54
+ def get_all_write_adapters
55
+ types = ConnectionPool.adapter_types
56
+ adapters = types.collect {|type| self.send("get_#{type}") }
57
+ adapters.select {|adapter| adapter.writes?}
58
+ end
59
+
60
+ def get_write_adapter
61
+ types = ConnectionPool.adapter_types
62
+ if types.include?(:rdflite)
63
+ get_rdflite
64
+ elsif types.include?(:redland)
65
+ get_redland
66
+ elsif types.include?(:yars)
67
+ get_yars
68
+ elsif types.include?(:jars2)
69
+ get_jars2
70
+ else
71
+ raise ActiveRdfError, "no suitable adapter found for test"
72
+ end
73
+ end
74
+
75
+ # TODO use a list of exisiting adapters not only one
76
+ def get_different_write_adapter(existing_adapter)
77
+ types = ConnectionPool.adapter_types
78
+ if types.include?(:rdflite)
79
+ if existing_adapter.class == RDFLite
80
+ ConnectionPool.add :type => :rdflite, :unique => true
81
+ else
82
+ get_rdflite
83
+ end
84
+ elsif types.include?(:redland) and existing_adapter.class != RedlandAdapter
85
+ get_redland
86
+ elsif types.include?(:yars) and existing_adapter.class != YarsAdapter
87
+ get_yars
88
+ else
89
+ raise ActiveRdfError, "only one write adapter on this system, or no suitable write adapter found for test"
90
+ end
91
+ end
92
+
93
+ # get all adapters used in Talia
94
+ def get_talia_adapters
95
+ types = ConnectionPool.adapter_types
96
+ ConnectionPool.add :type => :rdflite if types.include?(:rdflite)
97
+ ConnectionPool.add :type => :fetching if types.include?(:fetching)
98
+ ConnectionPool.add :type => :suggesting if types.include?(:suggesting)
99
+ ConnectionPool.add :type => :redland if types.include?(:redland)
100
+ ConnectionPool.add :type => :sesame if types.include?(:sesame)
101
+ if ConnectionPool.adapters.size > 0
102
+ return ConnectionPool.adapters
103
+ else
104
+ raise ActiveRdfError, "No adapter for Talia found on this system, or no suitable write adapter found for Talia test"
105
+ end
106
+ end
107
+
108
+ private
109
+ def get_sparql
110
+ ConnectionPool.add(:type => :sparql, :url => "http://sparql.org/books",
111
+ :engine => :joseki, :results => :sparql_xml)
112
+ end
113
+
114
+ def get_fetching; ConnectionPool.add(:type => :fetching); end
115
+ def get_suggesting; ConnectionPool.add(:type => :suggesting); end
116
+ def get_rdflite; ConnectionPool.add(:type => :rdflite); end
117
+ def get_redland; ConnectionPool.add(:type => :redland); end
118
+ def get_yars; ConnectionPool.add(:type => :yars); end
119
+ def get_jars2; ConnectionPool.add(:type => :jars2); end
@@ -0,0 +1,64 @@
1
+ $:.unshift File.join(File.dirname(__FILE__),'..', '..','lib', 'active_rdf')
2
+
3
+ require 'test/unit'
4
+ require 'directaccess/direct_access'
5
+
6
+ class TestDirectAccess < Test::Unit::TestCase
7
+
8
+ def setup
9
+ # load Redland Adapter
10
+ #ConnectionPool.clear
11
+ #adapter = load_adapter(:redland)
12
+ #adapter.load("#{File.dirname(__FILE__)}/../test_person_data.nt") if !adapter.nil?
13
+ end
14
+
15
+ @@eyal = "<http://activerdf.org/test/eyal>"
16
+ @@age = "<http://activerdf.org/test/age>"
17
+ @@age_number = "18"
18
+
19
+
20
+ def test_query
21
+ ConnectionPool.clear
22
+ adapter = load_adapter(:redland)
23
+ if !adapter.nil?
24
+ adapter.load("#{File.dirname(__FILE__)}/../test_person_data.nt")
25
+ # test SELECT query
26
+ assert_not_equal nil, DirectAccess.sparql_query("SELECT ?p ?o WHERE {#{@@eyal} ?p ?o}")
27
+ assert_not_equal nil, DirectAccess.sparql_query("SELECT ?o WHERE {#{@@eyal} #{@@age} ?o}")
28
+ assert_raise(ActiveRdfError) {DirectAccess.sparql_query(nil)}
29
+ assert_raise(ActiveRdfError) {DirectAccess.sparql_query(123)}
30
+
31
+ # test return value
32
+ assert_equal Array, DirectAccess.sparql_query("SELECT ?o WHERE {#{@@eyal} #{@@age} ?o}",:array).class
33
+ assert_equal String, DirectAccess.sparql_query("SELECT ?p WHERE {#{@@eyal} ?p '27'}")[0].class
34
+ end
35
+ end
36
+
37
+ def test_propertylist
38
+ ConnectionPool.clear
39
+ adapter = load_adapter(:redland)
40
+ if !adapter.nil?
41
+ # test creation
42
+ assert_equal PropertyList, DirectAccess.find_all_by_subject_and_predicate(@@eyal, @@age).class
43
+ assert_raise(ActiveRdfError) {DirectAccess.find_all_by_subject_and_predicate(nil, nil)}
44
+
45
+ # test add
46
+ pl = DirectAccess.find_all_by_subject_and_predicate(@@eyal, @@age)
47
+ assert_kind_of(PropertyList, pl)
48
+ assert_equal false, pl.include?(@@age_number)
49
+ assert_equal true, (pl << @@age_number)
50
+ assert_equal true, pl.include?(@@age_number)
51
+
52
+ # test remove
53
+ assert_equal true, (pl.remove(@@age_number))
54
+ assert_equal false, pl.include?(@@age_number)
55
+ assert_equal true, (pl.remove)
56
+ assert_equal 0, pl.size
57
+ assert_equal 0, DirectAccess.find_all_by_subject_and_predicate(@@eyal, @@age).size
58
+
59
+ # test replace
60
+ pl << "123"
61
+ assert_equal true, pl.replace("123", @@age_number)
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,86 @@
1
+ # Author:: Benjamin Heitmann
2
+ # Copyright:: (c) 2005-2006
3
+ # License:: LGPL
4
+
5
+ require 'test/unit'
6
+ require 'active_rdf'
7
+ require 'federation/connection_pool'
8
+ require "#{File.dirname(__FILE__)}/../common"
9
+
10
+ class TestConnectionPool < Test::Unit::TestCase
11
+ def setup
12
+ ConnectionPool.clear
13
+ end
14
+
15
+ def teardown
16
+ ConnectionPool.clear
17
+ end
18
+
19
+ def test_class_add_data_source
20
+ # test for successfull adding of an adapter
21
+ adapter = get_adapter
22
+ assert_kind_of ActiveRdfAdapter, adapter
23
+ assert ConnectionPool.adapter_pool.include?(adapter)
24
+
25
+ # now check that we get the same adapter if we supply the same parameters
26
+ adapter2 = get_adapter
27
+ assert_equal adapter, adapter2
28
+ # test same object_id
29
+ end
30
+
31
+ def test_class_adapter_pool
32
+ #ConnectionPool.clear
33
+ assert_equal 0, ConnectionPool.adapter_pool.size
34
+ adapter = get_adapter
35
+ assert_equal 1, ConnectionPool.adapter_pool.size
36
+ end
37
+
38
+ def test_class_register_adapter
39
+ ConnectionPool.register_adapter(:funkytype, ActiveRdfAdapter)
40
+ assert ConnectionPool.adapter_types.include?(:funkytype)
41
+ # unregister test adapter
42
+ ConnectionPool.unregister_adapter(:funkytype)
43
+ assert !ConnectionPool.adapter_types.include?(:funkytype)
44
+ end
45
+
46
+ def test_class_auto_flush_equals
47
+ # assert auto flushing by default
48
+ assert ConnectionPool.auto_flush?
49
+ ConnectionPool.auto_flush = false
50
+ assert !ConnectionPool.auto_flush?
51
+ end
52
+
53
+ def test_class_clear
54
+ ConnectionPool.clear
55
+ assert ConnectionPool.adapter_pool.empty?
56
+ assert_nil ConnectionPool.write_adapter
57
+ end
58
+
59
+ def test_class_write_adapter
60
+ adapter = get_write_adapter
61
+ assert_kind_of ActiveRdfAdapter, adapter
62
+ end
63
+
64
+ def test_class_write_adapter_equals
65
+ # get 2 adapter
66
+ adapter1 = get_write_adapter
67
+
68
+ # if another write adapter is present
69
+ adapter2 = get_different_write_adapter(adapter1)
70
+ # check if the selected write adapter is the second
71
+ assert_equal adapter2, ConnectionPool.write_adapter if !adapter2.nil?
72
+
73
+ # change write adatper
74
+ ConnectionPool.write_adapter = adapter1
75
+ #check if the selected write adapter is the first
76
+ assert_equal adapter1, ConnectionPool.write_adapter
77
+ end
78
+ end
79
+
80
+ # need access to connectionpool.adapter_pool in tests
81
+ class ConnectionPool
82
+ def self.adapter_pool
83
+ @@adapter_pool
84
+ end
85
+ end
86
+
@@ -0,0 +1,145 @@
1
+ # Author:: Eyal Oren
2
+ # Copyright:: (c) 2005-2006
3
+ # License:: LGPL
4
+
5
+ require 'test/unit'
6
+ require 'active_rdf'
7
+ require 'federation/federation_manager'
8
+ require "#{File.dirname(__FILE__)}/../common"
9
+
10
+ class TestFederationManager < Test::Unit::TestCase
11
+ def setup
12
+ ConnectionPool.clear
13
+ end
14
+
15
+ def teardown
16
+ end
17
+
18
+ @@eyal = RDFS::Resource.new("http://activerdf.org/test/eyal")
19
+ @@age = RDFS::Resource.new("http://activerdf.org/test/age")
20
+ @@age_number = RDFS::Resource.new("27")
21
+ @@eye = RDFS::Resource.new("http://activerdf.org/test/eye")
22
+ @@eye_value = RDFS::Resource.new("blue")
23
+ @@type = RDFS::Resource.new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")
24
+ @@person = RDFS::Resource.new("http://www.w3.org/2000/01/rdf-schema#Resource")
25
+ @@resource = RDFS::Resource.new("http://activerdf.org/test/Person")
26
+
27
+
28
+ def test_single_pool
29
+ a1 = get_adapter
30
+ a2 = get_adapter
31
+ assert_equal a1, a2
32
+ assert_equal a1.object_id, a2.object_id
33
+ end
34
+
35
+ def test_class_add
36
+ write1 = get_write_adapter
37
+ FederationManager.add(@@eyal, @@age, @@age_number)
38
+
39
+ age_result = Query.new.select(:o).where(@@eyal, @@age, :o).execute
40
+ assert "27", age_result
41
+ end
42
+
43
+ def test_class_add_no_write_adapter
44
+ # zero write, one read -> must raise error
45
+ adapter = get_read_only_adapter
46
+ assert (not adapter.writes?)
47
+ assert_raises(ActiveRdfError) { FederationManager.add(@@eyal, @@age, @@age_number) }
48
+ end
49
+
50
+ def test_class_add_one_write_one_read
51
+ # one write, one read
52
+
53
+ write1 = get_write_adapter
54
+ read1 = get_read_only_adapter
55
+ assert_not_equal write1,read1
56
+ assert_not_equal write1.object_id, read1.object_id
57
+
58
+ FederationManager.add(@@eyal, @@age, @@age_number)
59
+
60
+ age_result = Query.new.select(:o).where(@@eyal, @@age, :o).execute
61
+ assert "27", age_result
62
+ end
63
+
64
+ def test_get_different_read_and_write_adapters
65
+ r1 = get_adapter
66
+ r2 = get_different_adapter(r1)
67
+ assert_not_equal r1,r2
68
+ assert_not_equal r1.object_id, r2.object_id
69
+
70
+ w1 = get_write_adapter
71
+ w2 = get_different_write_adapter(w1)
72
+ assert_not_equal w1,w2
73
+ assert_not_equal w1.object_id, w2.object_id
74
+ end
75
+
76
+ def test_class_add_two_write
77
+ # two write, one read, no switching
78
+ # we need to different write adapters for this
79
+ #
80
+
81
+ write1 = get_write_adapter
82
+ write2 = get_different_write_adapter(write1)
83
+
84
+ read1 = get_read_only_adapter
85
+
86
+ FederationManager.add(@@eyal, @@age, @@age_number)
87
+
88
+ age_result = Query.new.select(:o).where(@@eyal, @@age, :o).execute
89
+ assert "27", age_result
90
+ end
91
+
92
+ def test_class_add_two_write_switching
93
+ # two write, one read, with switching
94
+
95
+ write1 = get_write_adapter
96
+ write2 = get_different_write_adapter(write1)
97
+
98
+ read1 = get_read_only_adapter
99
+
100
+ FederationManager.add(@@eyal, @@age, @@age_number)
101
+ age_result = Query.new.select(:o).where(@@eyal, @@age, :o).execute
102
+ assert "27", age_result
103
+
104
+ ConnectionPool.write_adapter = write2
105
+
106
+ FederationManager.add(@@eyal, @@eye, @@eye_value)
107
+ age_result = Query.new.select(:o).where(@@eyal, @@eye, :o).execute
108
+ assert "blue", age_result
109
+
110
+ second_result = write2.query(Query.new.select(:o).where(@@eyal, @@eye, :o))
111
+ assert "blue", second_result
112
+ end
113
+
114
+ # this test makes no sense without two different data sources
115
+ def test_federated_query
116
+ first_adapter = get_write_adapter
117
+ first_adapter.load("#{File.dirname(__FILE__)}/../test_person_data.nt")
118
+ first = Query.new.select(:s,:p,:o).where(:s,:p,:o).execute
119
+
120
+ # results should not be empty, because then the test succeeds trivially
121
+ assert_not_nil first
122
+ assert first != []
123
+
124
+ ConnectionPool.clear
125
+ second_adapter = get_different_write_adapter(first_adapter)
126
+ second_adapter.load("#{File.dirname(__FILE__)}/../test_person_data.nt")
127
+ second = Query.new.select(:s,:p,:o).where(:s,:p,:o).execute
128
+
129
+ # now we query both adapters in parallel
130
+ ConnectionPool.clear
131
+ first_adapter = get_write_adapter
132
+ first_adapter.load("#{File.dirname(__FILE__)}/../test_person_data.nt")
133
+ second_adapter = get_different_write_adapter(first_adapter)
134
+ second_adapter.load("#{File.dirname(__FILE__)}/../test_person_data.nt")
135
+ both = Query.new.select(:s,:p,:o).where(:s,:p,:o).execute
136
+ # assert both together contain twice the sum of the separate sources
137
+ assert_equal first + second, both
138
+
139
+ # since both sources contain the same data, we check that querying (both!)
140
+ # in parallel for distinct data, actually gives same results as querying
141
+ # only the one set
142
+ uniq = Query.new.distinct(:s,:p,:o).where(:s,:p,:o).execute
143
+ assert_equal first.sort, uniq.sort
144
+ end
145
+ end