pho 0.4.1 → 0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. data/CHANGES +18 -1
  2. data/README +10 -0
  3. data/Rakefile +2 -1
  4. data/doc/rdoc/classes/Pho.html +33 -22
  5. data/doc/rdoc/classes/Pho/DatatypeProperty.html +12 -12
  6. data/doc/rdoc/classes/Pho/{RDF_JSON.html → Enrichment.html} +8 -7
  7. data/doc/rdoc/classes/Pho/Enrichment/ResourceEnricher.html +310 -0
  8. data/doc/rdoc/classes/Pho/Etags.html +42 -42
  9. data/doc/rdoc/classes/Pho/Facet/Results.html +19 -19
  10. data/doc/rdoc/classes/Pho/Facet/Term.html +6 -6
  11. data/doc/rdoc/classes/Pho/FieldPredicateMap.html +110 -105
  12. data/doc/rdoc/classes/Pho/FieldWeighting.html +12 -12
  13. data/doc/rdoc/classes/Pho/FileManagement.html +121 -0
  14. data/doc/rdoc/classes/Pho/FileManagement/AbstractFileManager.html +443 -0
  15. data/doc/rdoc/classes/Pho/FileManagement/FileManager.html +258 -0
  16. data/doc/rdoc/classes/Pho/FileManagement/RDFManager.html +271 -0
  17. data/doc/rdoc/classes/Pho/Job.html +64 -64
  18. data/doc/rdoc/classes/Pho/Jobs.html +60 -60
  19. data/doc/rdoc/classes/Pho/QueryProfile.html +60 -60
  20. data/doc/rdoc/classes/Pho/RDFCollection.html +4 -378
  21. data/doc/rdoc/classes/Pho/ResourceHash.html +123 -0
  22. data/doc/rdoc/classes/Pho/ResourceHash/Converter.html +323 -0
  23. data/doc/rdoc/classes/Pho/{RDF_JSON → ResourceHash}/SetAlgebra.html +18 -18
  24. data/doc/rdoc/classes/Pho/Snapshot.html +35 -35
  25. data/doc/rdoc/classes/Pho/Sparql.html +137 -0
  26. data/doc/rdoc/classes/Pho/Sparql/SparqlClient.html +515 -0
  27. data/doc/rdoc/classes/Pho/Sparql/SparqlHelper.html +575 -0
  28. data/doc/rdoc/classes/Pho/Status.html +26 -26
  29. data/doc/rdoc/classes/Pho/Store.html +271 -241
  30. data/doc/rdoc/classes/Pho/Update/Changeset.html +73 -73
  31. data/doc/rdoc/classes/Pho/Update/ChangesetBuilder.html +34 -34
  32. data/doc/rdoc/classes/Pho/Update/Changesets.html +14 -14
  33. data/doc/rdoc/classes/Pho/Update/LiteralStatement.html +31 -23
  34. data/doc/rdoc/classes/Pho/Update/ResourceStatement.html +45 -21
  35. data/doc/rdoc/classes/Pho/Update/Statement.html +29 -29
  36. data/doc/rdoc/classes/String.html +1 -1
  37. data/doc/rdoc/created.rid +1 -1
  38. data/doc/rdoc/files/CHANGES.html +49 -3
  39. data/doc/rdoc/files/README.html +15 -1
  40. data/doc/rdoc/files/lib/pho/changeset_builder_rb.html +1 -1
  41. data/doc/rdoc/files/lib/pho/changeset_rb.html +1 -1
  42. data/doc/rdoc/files/lib/pho/converter_rb.html +108 -0
  43. data/doc/rdoc/files/lib/pho/enrichment_rb.html +101 -0
  44. data/doc/rdoc/files/lib/pho/etags_rb.html +1 -1
  45. data/doc/rdoc/files/lib/pho/field_predicate_map_rb.html +1 -1
  46. data/doc/rdoc/files/lib/pho/file_management_rb.html +101 -0
  47. data/doc/rdoc/files/lib/pho/file_manager_rb.html +108 -0
  48. data/doc/rdoc/files/lib/pho/rdf_collection_rb.html +1 -1
  49. data/doc/rdoc/files/lib/pho/resource_hash_rb.html +101 -0
  50. data/doc/rdoc/files/lib/pho/{rdf_json_rb.html → sparql_rb.html} +4 -4
  51. data/doc/rdoc/files/lib/pho/store_rb.html +1 -1
  52. data/doc/rdoc/files/lib/pho_rb.html +7 -2
  53. data/doc/rdoc/fr_class_index.html +12 -2
  54. data/doc/rdoc/fr_file_index.html +6 -1
  55. data/doc/rdoc/fr_method_index.html +176 -139
  56. data/examples/sparql_construct_hash.rb +26 -0
  57. data/examples/sparql_select.rb +18 -0
  58. data/lib/pho.rb +6 -1
  59. data/lib/pho/changeset.rb +24 -9
  60. data/lib/pho/changeset_builder.rb +10 -10
  61. data/lib/pho/converter.rb +74 -0
  62. data/lib/pho/enrichment.rb +81 -0
  63. data/lib/pho/etags.rb +1 -0
  64. data/lib/pho/field_predicate_map.rb +6 -1
  65. data/lib/pho/file_management.rb +102 -0
  66. data/lib/pho/file_manager.rb +61 -0
  67. data/lib/pho/rdf_collection.rb +54 -120
  68. data/lib/pho/{rdf_json.rb → resource_hash.rb} +3 -4
  69. data/lib/pho/sparql.rb +332 -0
  70. data/lib/pho/store.rb +20 -14
  71. data/tests/tc_changeset.rb +46 -0
  72. data/tests/tc_changeset_builder.rb +122 -1
  73. data/tests/tc_converter.rb +95 -0
  74. data/tests/tc_enrichment.rb +83 -0
  75. data/tests/tc_file_manager.rb +88 -0
  76. data/tests/tc_rdf_collection.rb +3 -0
  77. data/tests/{tc_rdf_json.rb → tc_resource_hash.rb} +23 -23
  78. data/tests/tc_search.rb +1 -1
  79. data/tests/tc_sparql.rb +131 -6
  80. data/tests/tc_sparql_helper.rb +214 -0
  81. data/tests/ts_pho.rb +6 -2
  82. metadata +47 -8
@@ -170,6 +170,23 @@ module Pho
170
170
  # SERVICES
171
171
  #############
172
172
 
173
+ #Retrieve a SparqlClient object for interacting with the endpoint for this store
174
+ #
175
+ # multisparql:: optional, set to true to retrieve client for multisparql endpoint
176
+ def sparql_client(multisparql=false)
177
+ if multisparql
178
+ u = self.build_uri("/services/multisparql")
179
+ else
180
+ u = self.build_uri("/services/sparql")
181
+ end
182
+
183
+ sparql_client = Pho::Sparql::SparqlClient.new(u, @client)
184
+ sparql_client.supports_rdf_json = true
185
+ sparql_client.supports_sparql_json = true
186
+
187
+ return sparql_client
188
+ end
189
+
173
190
  #Perform a SPARQL DESCRIBE query.
174
191
  #
175
192
  # query:: the SPARQL query
@@ -208,19 +225,7 @@ module Pho
208
225
  # format:: the preferred response format
209
226
  # multisparql:: use default sparql service or multisparql service
210
227
  def sparql(query, format=nil, multisparql=false)
211
- if multisparql
212
- u = self.build_uri("/services/multisparql")
213
- else
214
- u = self.build_uri("/services/sparql")
215
- end
216
-
217
- params = {}
218
- params["query"] = query
219
- headers = {}
220
- if format != nil
221
- headers["Accept"] = format
222
- end
223
- response = @client.get(u, params, headers)
228
+ return sparql_client(multisparql).query(query, format)
224
229
  end
225
230
 
226
231
  # Search the Metabox indexes.
@@ -291,7 +296,7 @@ module Pho
291
296
  # data:: a String containing the RSS feed
292
297
  def augment(data)
293
298
  u = self.build_uri("/services/augment")
294
- response = @client.post(u, data, nil)
299
+ response = @client.post(u, data, {"Content-Type" => "application/rss+xml"})
295
300
  return response
296
301
  end
297
302
 
@@ -330,6 +335,7 @@ module Pho
330
335
  data = f.read()
331
336
  f.close()
332
337
  headers = {"Content-Type" => mimetype}
338
+
333
339
  if uri == nil
334
340
  u = self.build_uri("/items")
335
341
  response = @client.post(u, data, headers)
@@ -167,6 +167,52 @@ class ChangesetTest < Test::Unit::TestCase
167
167
 
168
168
  end
169
169
 
170
+ def test_to_rdf_with_typed_literal
171
+ cs = Pho::Update::Changeset.new("http://www.example.org/my-resource") do |c|
172
+ c.add_addition( Pho::Update::Statement.create_literal("http://www.example.org/my-resource", "http://xmlns.com/foaf/0.1/homePage", "literal",
173
+ nil, "http://www.example.org/type") )
174
+ end
175
+ assert_equal(1, cs.additions.length)
176
+
177
+ cs_el = get_changeset(cs.to_rdf)
178
+
179
+ addition = REXML::XPath.first(cs_el, "cs:addition", Pho::Namespaces::MAPPING)
180
+ assert_not_nil(addition)
181
+ statement = REXML::XPath.first(addition, "rdf:Statement", Pho::Namespaces::MAPPING)
182
+ assert_not_nil(statement)
183
+ el = REXML::XPath.first(statement, "rdf:subject", Pho::Namespaces::MAPPING)
184
+ assert_equal("http://www.example.org/my-resource", el.attributes["rdf:resource"])
185
+ el = REXML::XPath.first(statement, "rdf:predicate", Pho::Namespaces::MAPPING)
186
+ assert_equal("http://xmlns.com/foaf/0.1/homePage", el.attributes["rdf:resource"])
187
+ el = REXML::XPath.first(statement, "rdf:object", Pho::Namespaces::MAPPING)
188
+ assert_equal(nil, el.attributes["rdf:resource"])
189
+ assert_equal("literal", el.text)
190
+ assert_equal( "http://www.example.org/type", el.attributes["rdf:datatype"] )
191
+ assert_equal(nil, el.attributes["xml:lang"])
192
+ end
193
+
194
+ def test_to_rdf_with_language_literal
195
+ cs = Pho::Update::Changeset.new("http://www.example.org/my-resource") do |c|
196
+ c.add_addition( Pho::Update::Statement.create_literal("http://www.example.org/my-resource", "http://xmlns.com/foaf/0.1/homePage", "literal", "fr") )
197
+ end
198
+ assert_equal(1, cs.additions.length)
199
+
200
+ cs_el = get_changeset(cs.to_rdf)
201
+
202
+ addition = REXML::XPath.first(cs_el, "cs:addition", Pho::Namespaces::MAPPING)
203
+ assert_not_nil(addition)
204
+ statement = REXML::XPath.first(addition, "rdf:Statement", Pho::Namespaces::MAPPING)
205
+ assert_not_nil(statement)
206
+ el = REXML::XPath.first(statement, "rdf:subject", Pho::Namespaces::MAPPING)
207
+ assert_equal("http://www.example.org/my-resource", el.attributes["rdf:resource"])
208
+ el = REXML::XPath.first(statement, "rdf:predicate", Pho::Namespaces::MAPPING)
209
+ assert_equal("http://xmlns.com/foaf/0.1/homePage", el.attributes["rdf:resource"])
210
+ el = REXML::XPath.first(statement, "rdf:object", Pho::Namespaces::MAPPING)
211
+ assert_equal(nil, el.attributes["rdf:resource"])
212
+ assert_equal("literal", el.text)
213
+ assert_equal( nil, el.attributes["rdf:datatype"] )
214
+ assert_equal("fr", el.attributes["xml:lang"])
215
+ end
170
216
  def test_to_rdf_with_resource_removal
171
217
  cs = Pho::Update::Changeset.new("http://www.example.org/my-resource") do |c|
172
218
  c.add_removal( Pho::Update::Statement.create_resource("http://www.example.org/my-resource", "http://xmlns.com/foaf/0.1/homePage", "http://www.example.org/page") )
@@ -44,7 +44,109 @@ class ChangesetBuilderTest < Test::Unit::TestCase
44
44
  }
45
45
  EOL
46
46
 
47
+ # COLLECTION = <<-EOL
48
+ # <rdf:RDF xmlns:rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
49
+ # xmlns:ex = "http://www.example.org/ns/">
50
+ #
51
+ # <rdf:Description rdf:about="http://www.example.org">
52
+ # <ex:list rdf:parseType="Collection">
53
+ # <rdf:Description rdf:about="http://www.example.org/first"/>
54
+ # <rdf:Description rdf:about="http://www.example.org/second"/>
55
+ # <rdf:Description rdf:about="http://www.example.org/third"/>
56
+ # </ex:list>
57
+ # </rdf:Description>
58
+ #
59
+ # </rdf:RDF>
60
+ # EOL
61
+ #
62
+ # SHORT_COLLECTION = <<-EOL
63
+ # <rdf:RDF xmlns:rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
64
+ # xmlns:ex = "http://www.example.org/ns/">
65
+ #
66
+ # <rdf:Description rdf:about="http://www.example.org">
67
+ # <ex:list rdf:parseType="List">
68
+ # <rdf:Description rdf:about="http://www.example.org/first"/>
69
+ # <rdf:Description rdf:about="http://www.example.org/second"/>
70
+ # </ex:list>
71
+ # </rdf:Description>
72
+ #
73
+ # </rdf:RDF>
74
+ # EOL
75
+
76
+ COLLECTION = <<-EOL
77
+ <rdf:RDF xmlns:rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
78
+ xmlns:ex = "http://www.example.org/ns/">
79
+
80
+ <rdf:Description rdf:about="http://www.example.org">
81
+ <ex:list rdf:resource="http://www.example.org/list#first"/>
82
+ </rdf:Description>
83
+ <rdf:Description rdf:about="http://www.example.org/list#first">
84
+ <rdf:first rdf:resource="http://www.example.org/first"/>
85
+ <rdf:rest rdf:resource="http://www.example.org/list#second"/>
86
+ </rdf:Description>
87
+ <rdf:Description rdf:about="http://www.example.org/list#second">
88
+ <rdf:first rdf:resource="http://www.example.org/second"/>
89
+ <rdf:rest rdf:resource="http://www.example.org/second"/>
90
+ </rdf:Description>
91
+ <rdf:Description rdf:about="http://www.example.org/list#third">
92
+ <rdf:first rdf:resource="http://www.example.org/third"/>
93
+ <rdf:rest rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"/>
94
+ </rdf:Description>
95
+
96
+ </rdf:RDF>
97
+ EOL
98
+
99
+ SHORT_COLLECTION = <<-EOL
100
+ <rdf:RDF xmlns:rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
101
+ xmlns:ex = "http://www.example.org/ns/">
102
+
103
+ <rdf:Description rdf:about="http://www.example.org">
104
+ <ex:list rdf:resource="http://www.example.org/list#first"/>
105
+ </rdf:Description>
106
+ <rdf:Description rdf:about="http://www.example.org/list#first">
107
+ <rdf:first rdf:resource="http://www.example.org/first"/>
108
+ <rdf:rest rdf:resource="http://www.example.org/list#second"/>
109
+ </rdf:Description>
110
+ <rdf:Description rdf:about="http://www.example.org/list#second">
111
+ <rdf:first rdf:resource="http://www.example.org/second"/>
112
+ <rdf:rest rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"/>
113
+ </rdf:Description>
47
114
 
115
+ </rdf:RDF>
116
+ EOL
117
+
118
+ SEQUENCE = <<-EOL
119
+ <rdf:RDF xmlns:rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
120
+ xmlns:ex = "http://www.example.org/ns/">
121
+
122
+ <rdf:Description rdf:about="http://www.example.org">
123
+ <ex:list>
124
+ <rdf:Seq>
125
+ <rdf:li><rdf:Description rdf:about="http://www.example.org/first"/></rdf:li>
126
+ <rdf:li><rdf:Description rdf:about="http://www.example.org/second"/></rdf:li>
127
+ <rdf:li><rdf:Description rdf:about="http://www.example.org/third"/></rdf:li>
128
+ </rdf:Seq>
129
+ </ex:list>
130
+ </rdf:Description>
131
+
132
+ </rdf:RDF>
133
+ EOL
134
+
135
+ SHORT_SEQUENCE = <<-EOL
136
+ <rdf:RDF xmlns:rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
137
+ xmlns:ex = "http://www.example.org/ns/">
138
+
139
+ <rdf:Description rdf:about="http://www.example.org">
140
+ <ex:list>
141
+ <rdf:Seq>
142
+ <rdf:li><rdf:Description rdf:about="http://www.example.org/first"/></rdf:li>
143
+ <rdf:li><rdf:Description rdf:about="http://www.example.org/second"/></rdf:li>
144
+ </rdf:Seq>
145
+ </ex:list>
146
+ </rdf:Description>
147
+ </rdf:RDF>
148
+ EOL
149
+
48
150
  def test_build_with_single_triple1
49
151
 
50
152
  cs = Pho::Update::ChangesetBuilder.build("http://www.example.org", JSON.parse("{}"), JSON.parse( SINGLE_TRIPLE_RESOURCE ) )
@@ -147,5 +249,24 @@ class ChangesetBuilderTest < Test::Unit::TestCase
147
249
  assert_equal("Bob Bobson", first_uri_changes.creator_name)
148
250
  assert_equal("Because I can", first_uri_changes.change_reason)
149
251
 
150
- end
252
+ end
253
+
254
+ def test_batch_changeset_with_list
255
+ coll_hash = Pho::ResourceHash::Converter.parse_rdfxml(COLLECTION, "http://www.example.com")
256
+ short_coll_hash = Pho::ResourceHash::Converter.parse_rdfxml(SHORT_COLLECTION, "http://www.example.com")
257
+ changesets = Pho::Update::ChangesetBuilder.build_batch(coll_hash, short_coll_hash, "Bob Bobson", "Because I can" )
258
+ #2 because we've updated the head and tail of the list
259
+ assert_equal(2, changesets.length)
260
+
261
+ changesets = Pho::Update::ChangesetBuilder.build_batch(short_coll_hash, coll_hash, "Bob Bobson", "Because I can" )
262
+ #2 because we've updated the head and tail of the list
263
+ assert_equal(2, changesets.length)
264
+ end
265
+
266
+ # def test_batch_changeset_with_sequence
267
+ # hash = Pho::ResourceHash::Converter.parse_rdfxml(SEQUENCE, "http://www.example.com")
268
+ # puts hash.inspect()
269
+ # end
270
+
271
+
151
272
  end
@@ -0,0 +1,95 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
+ require 'pho'
3
+ require 'test/unit'
4
+ require 'rexml/document'
5
+
6
+ class ConverterTest < Test::Unit::TestCase
7
+
8
+ SINGLE_RESOURCE_JSON = <<-EOL
9
+ {
10
+ "http://www.example.org" : {
11
+ "http://www.example.org/ns/resource" : [ { "value" : "http://www.example.org/page", "type" : "uri" } ]
12
+ }
13
+ }
14
+ EOL
15
+
16
+ SINGLE_RESOURCE_RDFXML = <<-EOL
17
+ <rdf:RDF xmlns:rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
18
+ xmlns:ex = "http://www.example.org/ns/">
19
+
20
+ <rdf:Description rdf:about="http://www.example.org">
21
+ <ex:resource rdf:resource="http://www.example.org/page"/>
22
+ </rdf:Description>
23
+
24
+ </rdf:RDF>
25
+
26
+ EOL
27
+
28
+ SINGLE_RESOURCE_NTRIPLES = <<-EOL
29
+ <http://www.example.org> <http://www.example.org/ns/resource> <http://www.example.org/page>.
30
+ EOL
31
+
32
+ SINGLE_RESOURCE_TURTLE = <<-EOL
33
+ <http://www.example.org> <http://www.example.org/ns/resource> <http://www.example.org/page>.
34
+ EOL
35
+
36
+ def test_parse_json
37
+
38
+ hash = Pho::ResourceHash::Converter.parse_json(SINGLE_RESOURCE_JSON)
39
+ assert_not_nil(hash)
40
+ assert_not_nil(hash["http://www.example.org"])
41
+
42
+ end
43
+
44
+ def test_parse_rdfxml
45
+
46
+ hash = Pho::ResourceHash::Converter.parse_rdfxml(SINGLE_RESOURCE_RDFXML, "http://www.example.org")
47
+ assert_not_nil(hash)
48
+ assert_not_nil(hash["http://www.example.org"])
49
+
50
+ predicates = hash["http://www.example.org"]
51
+ assert_equal(1, predicates.size() )
52
+ assert_equal(1, predicates["http://www.example.org/ns/resource"].length)
53
+ assert_equal("http://www.example.org/page", predicates["http://www.example.org/ns/resource"][0]["value"])
54
+ assert_equal("uri", predicates["http://www.example.org/ns/resource"][0]["type"])
55
+ end
56
+
57
+ def test_parse_ntriples
58
+
59
+ hash = Pho::ResourceHash::Converter.parse_ntriples(SINGLE_RESOURCE_NTRIPLES, "http://www.example.org")
60
+ assert_not_nil(hash)
61
+ assert_not_nil(hash["http://www.example.org"])
62
+
63
+ predicates = hash["http://www.example.org"]
64
+ assert_equal(1, predicates.size() )
65
+ assert_equal(1, predicates["http://www.example.org/ns/resource"].length)
66
+ assert_equal("http://www.example.org/page", predicates["http://www.example.org/ns/resource"][0]["value"])
67
+ assert_equal("uri", predicates["http://www.example.org/ns/resource"][0]["type"])
68
+
69
+ end
70
+
71
+ def test_parse_turtle
72
+
73
+ hash = Pho::ResourceHash::Converter.parse_ntriples(SINGLE_RESOURCE_TURTLE, "http://www.example.org")
74
+ assert_not_nil(hash)
75
+ assert_not_nil(hash["http://www.example.org"])
76
+
77
+ predicates = hash["http://www.example.org"]
78
+ assert_equal(1, predicates.size() )
79
+ assert_equal(1, predicates["http://www.example.org/ns/resource"].length)
80
+ assert_equal("http://www.example.org/page", predicates["http://www.example.org/ns/resource"][0]["value"])
81
+ assert_equal("uri", predicates["http://www.example.org/ns/resource"][0]["type"])
82
+
83
+ end
84
+
85
+ def test_serialize_json
86
+ parsed = Pho::ResourceHash::Converter.parse_json(SINGLE_RESOURCE_JSON)
87
+
88
+ serialized = Pho::ResourceHash::Converter.serialize_json(parsed)
89
+ reparsed = Pho::ResourceHash::Converter.parse_json(serialized)
90
+
91
+ assert_equal(parsed, reparsed)
92
+
93
+ end
94
+
95
+ end
@@ -0,0 +1,83 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
+ require 'pho'
3
+ require 'test/unit'
4
+ require 'mocha'
5
+
6
+ class EnrichmentTest < Test::Unit::TestCase
7
+
8
+ RDFXML = <<-EOL
9
+ <rdf:RDF xmlns:rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
10
+ xmlns:ex = "http://www.example.org/ns/">
11
+
12
+ <rdf:Description rdf:about="http://www.example.org">
13
+ <ex:resource rdf:resource="http://www.example.org/page"/>
14
+ </rdf:Description>
15
+
16
+ </rdf:RDF>
17
+ EOL
18
+
19
+ def test_merge()
20
+
21
+ query = "DESCRIBE <http://www.example.org>"
22
+ mock_store = mock()
23
+ mock_store.expects(:store_data).with(RDFXML).returns( HTTP::Message.new_response("OK") )
24
+
25
+ mc = mock()
26
+ mc.expects(:query).with( query, "application/rdf+xml" ).returns( HTTP::Message.new_response(RDFXML) )
27
+
28
+ enricher = Pho::Enrichment::ResourceEnricher.new(mock_store, mc)
29
+ resp = enricher.merge(query)
30
+ assert_not_nil(resp)
31
+
32
+ end
33
+
34
+ def test_merge_with_failed_query()
35
+
36
+ query = "DESCRIBE <http://www.example.org>"
37
+ mock_store = mock()
38
+
39
+ mc = mock()
40
+ msg = HTTP::Message.new_response("Error")
41
+ msg.status = 500
42
+ mc.expects(:query).with( query, "application/rdf+xml" ).returns( msg )
43
+
44
+ enricher = Pho::Enrichment::ResourceEnricher.new(mock_store, mc)
45
+ assert_raises RuntimeError do
46
+ results = enricher.merge(query)
47
+ end
48
+
49
+ end
50
+
51
+ def test_merge_with_failed_store()
52
+
53
+ query = "DESCRIBE <http://www.example.org>"
54
+ mock_store = mock()
55
+ msg = HTTP::Message.new_response("Error")
56
+ msg.status = 500
57
+ mock_store.expects(:store_data).with(RDFXML).returns( msg )
58
+
59
+ mc = mock()
60
+ mc.expects(:query).with( query, "application/rdf+xml" ).returns( HTTP::Message.new_response(RDFXML) )
61
+
62
+ enricher = Pho::Enrichment::ResourceEnricher.new(mock_store, mc)
63
+ resp = enricher.merge(query)
64
+ assert_equal(500, resp.status)
65
+
66
+ end
67
+
68
+ def test_infer()
69
+ query = "CONSTRUCT { ?s ex:foo ?o } WHERE { ?s ex:bar ?o }"
70
+
71
+ mc = mock()
72
+ mc.expects(:query).with( query, "application/rdf+xml" ).returns( HTTP::Message.new_response(RDFXML) )
73
+
74
+ mock_store = mock()
75
+ mock_store.expects(:sparql_client).returns(mc)
76
+ mock_store.expects(:store_data).with(RDFXML).returns( HTTP::Message.new_response("OK") )
77
+
78
+ resp = Pho::Enrichment::ResourceEnricher.infer(mock_store, query)
79
+ assert_not_nil(resp)
80
+
81
+ end
82
+
83
+ end
@@ -0,0 +1,88 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
+ require 'pho'
3
+ require 'test/unit'
4
+ require 'mocha'
5
+
6
+ class FileManagerTest < Test::Unit::TestCase
7
+
8
+ def setup()
9
+ Dir.mkdir("/tmp/pho") unless File.exists?("/tmp/pho")
10
+ 7.times do |i|
11
+ file = File.new( File.join("/tmp/pho", "#{i}.css"), "w" )
12
+ file.write("CSS#{i}")
13
+ file.close()
14
+ end
15
+ 3.times do |i|
16
+ num = i + 7
17
+ file = File.new( File.join("/tmp/pho", "#{num}.js"), "w" )
18
+ file.write("JS#{num}")
19
+ file.close()
20
+ end
21
+ 4.times do |i|
22
+ file = File.new( File.join("/tmp/pho", "#{i}.ok"), "w" )
23
+ file.write("OK")
24
+ file.close()
25
+ end
26
+ 3.times do |i|
27
+ num = 4 + i
28
+ file = File.new( File.join("/tmp/pho", "#{num}.fail"), "w" )
29
+ file.write("FAIL")
30
+ file.close()
31
+ end
32
+ end
33
+
34
+ def teardown()
35
+ Dir.glob("/tmp/pho/*.css") do |file|
36
+ File.delete(file)
37
+ end
38
+ Dir.glob("/tmp/pho/*.js") do |file|
39
+ File.delete(file)
40
+ end
41
+ Dir.glob("/tmp/pho/*.ok") do |file|
42
+ File.delete(file)
43
+ end
44
+ Dir.glob("/tmp/pho/*.fail") do |file|
45
+ File.delete(file)
46
+ end
47
+ end
48
+
49
+ def test_new_files()
50
+ store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass")
51
+ collection = Pho::FileManagement::FileManager.new(store, "/tmp/pho")
52
+
53
+ newfiles = collection.new_files()
54
+ newfiles.sort!
55
+ assert_equal(3, newfiles.size)
56
+ assert_equal("/tmp/pho/7.js", newfiles[0])
57
+ assert_equal("/tmp/pho/8.js", newfiles[1])
58
+ assert_equal("/tmp/pho/9.js", newfiles[2])
59
+
60
+ end
61
+
62
+ def test_store()
63
+ mc = mock()
64
+ mc.expects(:set_auth)
65
+ #mc.stub_everything()
66
+ mc.expects(:post).with("http://api.talis.com/stores/testing/items", "JS7", {"Content-Type" => "application/javascript"}).returns( HTTP::Message.new_response("OK"))
67
+ mc.expects(:post).with("http://api.talis.com/stores/testing/items", "JS8", {"Content-Type" => "application/javascript"}).returns( HTTP::Message.new_response("OK"))
68
+ mc.expects(:post).with("http://api.talis.com/stores/testing/items", "JS9", {"Content-Type" => "application/javascript"}).returns( HTTP::Message.new_response("OK"))
69
+
70
+ store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass", mc)
71
+ collection = Pho::FileManagement::FileManager.new(store, "/tmp/pho")
72
+ collection.store()
73
+
74
+ assert_equal(true, File.exists?("/tmp/pho/7.ok") )
75
+ assert_equal(true, File.exists?("/tmp/pho/8.ok") )
76
+ assert_equal(true, File.exists?("/tmp/pho/9.ok") )
77
+
78
+ end
79
+
80
+ def test_list()
81
+ store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass")
82
+ collection = Pho::FileManagement::FileManager.new(store, "/tmp/pho")
83
+
84
+ files = collection.list()
85
+ assert_equal(10, files.size)
86
+ end
87
+
88
+ end