kasabi 0.0.1 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/kasabi.rb +8 -0
- data/lib/kasabi/api/attribution.rb +21 -0
- data/lib/kasabi/api/augment.rb +2 -2
- data/lib/kasabi/api/base_client.rb +15 -1
- data/lib/kasabi/api/jobs.rb +33 -0
- data/lib/kasabi/api/lookup.rb +4 -2
- data/lib/kasabi/api/reconcile.rb +2 -2
- data/lib/kasabi/api/search.rb +4 -9
- data/lib/kasabi/api/sparql.rb +98 -222
- data/lib/kasabi/api/status.rb +36 -0
- data/lib/kasabi/api/store.rb +63 -0
- data/lib/kasabi/data/dataset.rb +90 -0
- data/tests/api/apollo-6.json +74 -0
- data/tests/api/tc_attribution.rb +31 -0
- data/tests/api/tc_augment.rb +6 -4
- data/tests/api/tc_facet.rb +1 -1
- data/tests/api/tc_jobs.rb +23 -0
- data/tests/api/tc_lookup.rb +9 -4
- data/tests/api/tc_reconcile.rb +5 -4
- data/tests/api/tc_search.rb +2 -2
- data/tests/api/tc_sparql.rb +291 -92
- data/tests/api/tc_status.rb +82 -0
- data/tests/api/tc_store.rb +75 -0
- data/tests/data/dataset.json +65 -0
- data/tests/data/tc_dataset.rb +59 -0
- data/tests/ts_kasabi.rb +3 -1
- metadata +16 -6
- data/lib/kasabi/dataset/dataset.rb +0 -21
- data/tests/api/tc_sparqlhelper.rb +0 -262
@@ -0,0 +1,82 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
2
|
+
require 'kasabi'
|
3
|
+
require 'test/unit'
|
4
|
+
require 'mocha'
|
5
|
+
|
6
|
+
class StatusTest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
STATUS = <<-EOL
|
9
|
+
{
|
10
|
+
"status": "published",
|
11
|
+
"storageMode": "read-write"
|
12
|
+
}
|
13
|
+
EOL
|
14
|
+
|
15
|
+
STATUS_READ_ONLY = <<-EOL
|
16
|
+
{
|
17
|
+
"status": "draft",
|
18
|
+
"storageMode": "read-only"
|
19
|
+
}
|
20
|
+
EOL
|
21
|
+
|
22
|
+
def test_get
|
23
|
+
mc = mock()
|
24
|
+
mc.expects(:get).with("http://api.kasabi.com/api/test-data/status",
|
25
|
+
nil, {"X_KASABI_APIKEY" => "test-key"} ).returns(
|
26
|
+
HTTP::Message.new_response( STATUS ))
|
27
|
+
|
28
|
+
client = Kasabi::Status.new("http://api.kasabi.com/api/test-data/status",
|
29
|
+
:apikey=>"test-key", :client=>mc)
|
30
|
+
|
31
|
+
status = client.get_status
|
32
|
+
assert_not_nil(status)
|
33
|
+
assert_equal("published", status["status"])
|
34
|
+
assert_equal("read-write", status["storageMode"])
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_writeable
|
39
|
+
mc = mock()
|
40
|
+
mc.expects(:get).with("http://api.kasabi.com/api/test-data/status",
|
41
|
+
nil, {"X_KASABI_APIKEY" => "test-key"} ).returns(
|
42
|
+
HTTP::Message.new_response( STATUS ))
|
43
|
+
|
44
|
+
client = Kasabi::Status.new("http://api.kasabi.com/api/test-data/status",
|
45
|
+
:apikey=>"test-key", :client=>mc)
|
46
|
+
|
47
|
+
assert_equal(true, client.writeable?)
|
48
|
+
|
49
|
+
mc = mock()
|
50
|
+
mc.expects(:get).with("http://api.kasabi.com/api/test-data/status",
|
51
|
+
nil, {"X_KASABI_APIKEY" => "test-key"} ).returns(
|
52
|
+
HTTP::Message.new_response( STATUS_READ_ONLY ))
|
53
|
+
|
54
|
+
client = Kasabi::Status.new("http://api.kasabi.com/api/test-data/status",
|
55
|
+
:apikey=>"test-key", :client=>mc)
|
56
|
+
|
57
|
+
assert_equal(false, client.writeable?)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_published
|
61
|
+
mc = mock()
|
62
|
+
mc.expects(:get).with("http://api.kasabi.com/api/test-data/status",
|
63
|
+
nil, {"X_KASABI_APIKEY" => "test-key"} ).returns(
|
64
|
+
HTTP::Message.new_response( STATUS ))
|
65
|
+
|
66
|
+
client = Kasabi::Status.new("http://api.kasabi.com/api/test-data/status",
|
67
|
+
:apikey=>"test-key", :client=>mc)
|
68
|
+
|
69
|
+
assert_equal(true, client.published?)
|
70
|
+
|
71
|
+
mc = mock()
|
72
|
+
mc.expects(:get).with("http://api.kasabi.com/api/test-data/status",
|
73
|
+
nil, {"X_KASABI_APIKEY" => "test-key"} ).returns(
|
74
|
+
HTTP::Message.new_response( STATUS_READ_ONLY ))
|
75
|
+
|
76
|
+
client = Kasabi::Status.new("http://api.kasabi.com/api/test-data/status",
|
77
|
+
:apikey=>"test-key", :client=>mc)
|
78
|
+
|
79
|
+
assert_equal(false, client.published?)
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
2
|
+
require 'kasabi'
|
3
|
+
require 'test/unit'
|
4
|
+
require 'mocha'
|
5
|
+
|
6
|
+
class StoreTest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def test_store_data
|
9
|
+
resp = HTTP::Message.new_response("http://api.kasabi.com/dataset/test-data/changes/1")
|
10
|
+
resp.status = 202
|
11
|
+
mc = mock()
|
12
|
+
mc.expects(:post).with("http://api.kasabi.com/dataset/test-data/store",
|
13
|
+
"data", {"Content-Type" => "application/rdf+xml", "X_KASABI_APIKEY" => "test"} ).returns( resp )
|
14
|
+
dataset = Kasabi::Storage::Client.new("http://api.kasabi.com/dataset/test-data/store", { :apikey => "test", :client => mc })
|
15
|
+
id = dataset.store_data("data")
|
16
|
+
assert_equal("http://api.kasabi.com/dataset/test-data/changes/1", id)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_store_data_as_turtle
|
20
|
+
resp = HTTP::Message.new_response("http://api.kasabi.com/dataset/test-data/changes/1")
|
21
|
+
resp.status = 202
|
22
|
+
mc = mock()
|
23
|
+
mc.expects(:post).with("http://api.kasabi.com/dataset/test-data/store",
|
24
|
+
"data", {"Content-Type" => "text/turtle", "X_KASABI_APIKEY" => "test"} ).returns( resp )
|
25
|
+
dataset = Kasabi::Storage::Client.new("http://api.kasabi.com/dataset/test-data/store", { :apikey => "test", :client => mc })
|
26
|
+
id = dataset.store_data("data", "text/turtle")
|
27
|
+
assert_equal("http://api.kasabi.com/dataset/test-data/changes/1", id)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_apply_changeset
|
31
|
+
resp = HTTP::Message.new_response("http://api.kasabi.com/dataset/test-data/changes/1")
|
32
|
+
resp.status = 202
|
33
|
+
mc = mock()
|
34
|
+
mc.expects(:post).with("http://api.kasabi.com/dataset/test-data/store",
|
35
|
+
"data", {"Content-Type" => "application/vnd.talis.changeset+xml", "X_KASABI_APIKEY" => "test"} ).returns( resp )
|
36
|
+
dataset = Kasabi::Storage::Client.new("http://api.kasabi.com/dataset/test-data/store", { :apikey => "test", :client => mc })
|
37
|
+
id = dataset.apply_changeset("data")
|
38
|
+
assert_equal("http://api.kasabi.com/dataset/test-data/changes/1", id)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_store_file
|
42
|
+
resp = HTTP::Message.new_response("http://api.kasabi.com/dataset/test-data/changes/1")
|
43
|
+
resp.status = 202
|
44
|
+
mc = mock()
|
45
|
+
mc.expects(:post).with("http://api.kasabi.com/dataset/test-data/store",
|
46
|
+
"data", {"Content-Type" => "application/rdf+xml", "X_KASABI_APIKEY" => "test"} ).returns( resp )
|
47
|
+
io = StringIO.new("data")
|
48
|
+
|
49
|
+
dataset = Kasabi::Storage::Client.new("http://api.kasabi.com/dataset/test-data/store", { :apikey => "test", :client => mc })
|
50
|
+
id = dataset.store_file(io)
|
51
|
+
assert_equal("http://api.kasabi.com/dataset/test-data/changes/1", id)
|
52
|
+
assert_equal(true, io.closed?)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_store_uri
|
56
|
+
resp = HTTP::Message.new_response("http://api.kasabi.com/dataset/test-data/changes/1")
|
57
|
+
resp.status = 202
|
58
|
+
mc = mock()
|
59
|
+
mc.expects(:post).with("http://api.kasabi.com/dataset/test-data/store",
|
60
|
+
{"data_uri" => "http://www.example.org"}, {"Content-Type" => "application/rdf+xml", "X_KASABI_APIKEY" => "test"} ).returns( resp )
|
61
|
+
dataset = Kasabi::Storage::Client.new("http://api.kasabi.com/dataset/test-data/store", { :apikey => "test", :client => mc })
|
62
|
+
id = dataset.store_uri("http://www.example.org")
|
63
|
+
assert_equal("http://api.kasabi.com/dataset/test-data/changes/1", id)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_applied?
|
67
|
+
resp = HTTP::Message.new_response("{ \"status\": \"applied\" }")
|
68
|
+
mc = mock()
|
69
|
+
mc.expects(:get).with("http://api.kasabi.com/dataset/test-data/changes/1", nil,
|
70
|
+
{"Content-Type" => "application/json", "X_KASABI_APIKEY" => "test"}).returns(resp)
|
71
|
+
dataset = Kasabi::Storage::Client.new("http://api.kasabi.com/dataset/test-data/store", { :apikey => "test", :client => mc })
|
72
|
+
assert_equal(true, dataset.applied?("http://api.kasabi.com/dataset/test-data/changes/1"))
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
{
|
2
|
+
"http://data.kasabi.com/dataset/test-data": {
|
3
|
+
"http://rdfs.org/ns/void#exampleResource": [
|
4
|
+
{
|
5
|
+
"value": "http://api.kasabi.com/dataset/test-data/person/1",
|
6
|
+
"type": "uri"
|
7
|
+
}
|
8
|
+
],
|
9
|
+
"http://purl.org/dc/terms/title": [
|
10
|
+
{
|
11
|
+
"value": "Test Data",
|
12
|
+
"type": "literal"
|
13
|
+
}
|
14
|
+
],
|
15
|
+
"http://purl.org/dc/terms/description": [
|
16
|
+
{
|
17
|
+
"value": "The Test Data dataset",
|
18
|
+
"type": "literal"
|
19
|
+
}
|
20
|
+
],
|
21
|
+
"http://rdfs.org/ns/void#sparqlEndpoint": [
|
22
|
+
{
|
23
|
+
"value": "http://api.kasabi.com/api/test-sparql",
|
24
|
+
"type": "uri"
|
25
|
+
}
|
26
|
+
],
|
27
|
+
"http://rdfs.org/ns/void#uriLookupEndpoint": [
|
28
|
+
{
|
29
|
+
"value": "http://api.kasabi.com/api/test-lookup",
|
30
|
+
"type": "uri"
|
31
|
+
}
|
32
|
+
],
|
33
|
+
"http://www.w3.org/1999/02/22-rdf-syntax-ns#type": [
|
34
|
+
{
|
35
|
+
"value": "http://rdfs.org/ns/void#Dataset",
|
36
|
+
"type": "uri"
|
37
|
+
}
|
38
|
+
],
|
39
|
+
"http://xmlns.com/foaf/0.1/homepage": [
|
40
|
+
{
|
41
|
+
"value": "http://ldodds.kasabi.com/dataset/test-data",
|
42
|
+
"type": "uri"
|
43
|
+
}
|
44
|
+
],
|
45
|
+
"http://labs.kasabi.com/ns/services#searchEndpoint": [
|
46
|
+
{
|
47
|
+
"value": "http://api.kasabi.com/api/test-search",
|
48
|
+
"type": "uri"
|
49
|
+
}
|
50
|
+
],
|
51
|
+
"http://labs.kasabi.com/ns/services#reconciliationEndpoint": [
|
52
|
+
{
|
53
|
+
"value": "http://api.kasabi.com/api/test-recon",
|
54
|
+
"type": "uri"
|
55
|
+
}
|
56
|
+
],
|
57
|
+
"http://labs.kasabi.com/ns/services#augmentationEndpoint": [
|
58
|
+
{
|
59
|
+
"value": "http://api.kasabi.com/api/test-augment",
|
60
|
+
"type": "uri"
|
61
|
+
}
|
62
|
+
]
|
63
|
+
|
64
|
+
}
|
65
|
+
}
|
@@ -0,0 +1,59 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
2
|
+
require 'kasabi'
|
3
|
+
require 'test/unit'
|
4
|
+
require 'mocha'
|
5
|
+
|
6
|
+
class DatasetTest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@metadata = File.read(File.join(File.dirname(__FILE__), "dataset.json"))
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_constructor
|
13
|
+
dataset = Kasabi::Dataset.new("http://api.kasabi.com/dataset/test-data", { :apikey => "test" })
|
14
|
+
assert_equal("http://api.kasabi.com/dataset/test-data", dataset.endpoint)
|
15
|
+
assert_equal("http://data.kasabi.com/dataset/test-data", dataset.uri)
|
16
|
+
|
17
|
+
dataset = Kasabi::Dataset.new("http://data.kasabi.com/dataset/test-data", { :apikey => "test" })
|
18
|
+
assert_equal("http://api.kasabi.com/dataset/test-data", dataset.endpoint)
|
19
|
+
assert_equal("http://data.kasabi.com/dataset/test-data", dataset.uri)
|
20
|
+
|
21
|
+
dataset = Kasabi::Dataset.new("http://www.kasabi.com/dataset/test-data", { :apikey => "test" })
|
22
|
+
assert_equal("http://api.kasabi.com/dataset/test-data", dataset.endpoint)
|
23
|
+
assert_equal("http://data.kasabi.com/dataset/test-data", dataset.uri)
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_read_metadata
|
28
|
+
mc = mock()
|
29
|
+
mc.expects(:get).with("http://data.kasabi.com/dataset/test-data", nil, {"Accept" => "application/json", "X_KASABI_APIKEY" => "test"} ).returns(
|
30
|
+
HTTP::Message.new_response( @metadata ))
|
31
|
+
|
32
|
+
dataset = Kasabi::Dataset.new("http://api.kasabi.com/dataset/test-data", { :apikey => "test", :client => mc })
|
33
|
+
metadata = dataset.metadata
|
34
|
+
assert_not_nil(metadata)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_read_properties
|
38
|
+
mc = mock()
|
39
|
+
mc.expects(:get).with("http://data.kasabi.com/dataset/test-data",
|
40
|
+
nil, {"Accept" => "application/json", "X_KASABI_APIKEY" => "test"} ).returns(
|
41
|
+
HTTP::Message.new_response( @metadata ))
|
42
|
+
|
43
|
+
dataset = Kasabi::Dataset.new("http://api.kasabi.com/dataset/test-data", { :apikey => "test", :client => mc })
|
44
|
+
assert_equal("Test Data", dataset.title)
|
45
|
+
assert_equal("The Test Data dataset", dataset.description)
|
46
|
+
assert_equal("http://ldodds.kasabi.com/dataset/test-data", dataset.homepage)
|
47
|
+
assert_equal("http://api.kasabi.com/api/test-sparql", dataset.sparql_endpoint)
|
48
|
+
assert_equal("http://api.kasabi.com/api/test-lookup", dataset.lookup_api)
|
49
|
+
assert_equal("http://api.kasabi.com/api/test-search", dataset.search_api)
|
50
|
+
assert_equal("http://api.kasabi.com/api/test-recon", dataset.reconciliation_api)
|
51
|
+
assert_equal("http://api.kasabi.com/api/test-augment", dataset.augmentation_api)
|
52
|
+
|
53
|
+
assert_equal("http://api.kasabi.com/api/test-sparql", dataset.sparql_endpoint_client.endpoint)
|
54
|
+
assert_equal("http://api.kasabi.com/api/test-lookup", dataset.lookup_api_client.endpoint)
|
55
|
+
assert_equal("http://api.kasabi.com/api/test-search", dataset.search_api_client.endpoint)
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
data/tests/ts_kasabi.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kasabi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 0
|
9
8
|
- 1
|
10
|
-
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Leigh Dodds
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-08-22 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -108,22 +108,32 @@ files:
|
|
108
108
|
- README.md
|
109
109
|
- Rakefile
|
110
110
|
- CHANGES
|
111
|
+
- tests/api/tc_jobs.rb
|
112
|
+
- tests/api/tc_store.rb
|
113
|
+
- tests/api/apollo-6.json
|
111
114
|
- tests/api/tc_sparql.rb
|
112
115
|
- tests/api/tc_augment.rb
|
113
116
|
- tests/api/tc_reconcile.rb
|
117
|
+
- tests/api/tc_status.rb
|
114
118
|
- tests/api/tc_facet.rb
|
115
|
-
- tests/api/tc_sparqlhelper.rb
|
116
119
|
- tests/api/tc_lookup.rb
|
120
|
+
- tests/api/tc_attribution.rb
|
117
121
|
- tests/api/tc_search.rb
|
122
|
+
- tests/data/dataset.json
|
123
|
+
- tests/data/tc_dataset.rb
|
118
124
|
- tests/ts_kasabi.rb
|
119
|
-
- lib/kasabi/
|
125
|
+
- lib/kasabi/api/status.rb
|
120
126
|
- lib/kasabi/api/sparql.rb
|
121
127
|
- lib/kasabi/api/lookup.rb
|
122
128
|
- lib/kasabi/api/reconcile.rb
|
129
|
+
- lib/kasabi/api/attribution.rb
|
130
|
+
- lib/kasabi/api/jobs.rb
|
131
|
+
- lib/kasabi/api/store.rb
|
123
132
|
- lib/kasabi/api/augment.rb
|
124
133
|
- lib/kasabi/api/facet.rb
|
125
134
|
- lib/kasabi/api/base_client.rb
|
126
135
|
- lib/kasabi/api/search.rb
|
136
|
+
- lib/kasabi/data/dataset.rb
|
127
137
|
- lib/kasabi.rb
|
128
138
|
has_rdoc: true
|
129
139
|
homepage: http://github.com/kasabi/kasabi.rb
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module Kasabi
|
2
|
-
|
3
|
-
class Dataset
|
4
|
-
|
5
|
-
attr_reader :uri
|
6
|
-
attr_reader :client
|
7
|
-
attr_reader :apikey
|
8
|
-
|
9
|
-
#Initialize the client to work with a specific endpoint
|
10
|
-
#
|
11
|
-
# The _options_ hash can contain the following values:
|
12
|
-
# * *:apikey*: required. apikey authorized to use the API
|
13
|
-
# * *:client*: HTTPClient object instance
|
14
|
-
def initialize(uri, options={})
|
15
|
-
@uri = uri
|
16
|
-
@client = options[:client] || HTTPClient.new()
|
17
|
-
@apikey = options[:apikey] || nil
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
end
|
@@ -1,262 +0,0 @@
|
|
1
|
-
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
2
|
-
require 'kasabi'
|
3
|
-
require 'test/unit'
|
4
|
-
require 'mocha'
|
5
|
-
|
6
|
-
class SparqlHelperTest < Test::Unit::TestCase
|
7
|
-
|
8
|
-
SELECT_QUERY = <<-EOL
|
9
|
-
SELECT ?name WHERE { ?s rdfs:label ?name. }
|
10
|
-
EOL
|
11
|
-
|
12
|
-
ASK_QUERY = <<-EOL
|
13
|
-
ASK WHERE { ?s rdfs:label "Something". }
|
14
|
-
EOL
|
15
|
-
|
16
|
-
DESCRIBE_QUERY = <<-EOL
|
17
|
-
DESCRIBE <http://www.example.org>
|
18
|
-
EOL
|
19
|
-
|
20
|
-
CONSTRUCT_QUERY = <<-EOL
|
21
|
-
CONSTRUCT { ?s ?p ?o. } WHERE { ?s ?p ?o. }
|
22
|
-
EOL
|
23
|
-
|
24
|
-
RESULTS = <<-EOL
|
25
|
-
{
|
26
|
-
"head": { "vars": [ "name" ] } ,
|
27
|
-
|
28
|
-
"results": {
|
29
|
-
"bindings": [
|
30
|
-
{ "name": { "type": "literal" , "value": "Apollo 11 Command and Service Module (CSM)" }
|
31
|
-
} ,
|
32
|
-
{ "name": { "type": "literal" , "value": "Apollo 11 SIVB" }
|
33
|
-
} ,
|
34
|
-
{ "name": { "type": "literal" , "value": "Apollo 11 Lunar Module / EASEP" }
|
35
|
-
}
|
36
|
-
]
|
37
|
-
}
|
38
|
-
}
|
39
|
-
EOL
|
40
|
-
|
41
|
-
RESULTS_NO_BINDING = <<-EOL
|
42
|
-
{
|
43
|
-
"head": { "vars": [ "name" ] } ,
|
44
|
-
|
45
|
-
"results": {
|
46
|
-
"bindings": [
|
47
|
-
{ } ,
|
48
|
-
{ "name": { "type": "literal" , "value": "Apollo 11 SIVB" }
|
49
|
-
}
|
50
|
-
]
|
51
|
-
}
|
52
|
-
}
|
53
|
-
EOL
|
54
|
-
|
55
|
-
ASK_RESULTS = <<-EOL
|
56
|
-
{
|
57
|
-
"head": {},
|
58
|
-
"boolean": "true"
|
59
|
-
}
|
60
|
-
EOL
|
61
|
-
|
62
|
-
RDF_JSON_RESULTS = <<-EOL
|
63
|
-
{
|
64
|
-
"http://www.example.org" : {
|
65
|
-
"http://www.example.org/ns/resource" : [ { "value" : "http://www.example.org/page", "type" : "uri" } ]
|
66
|
-
}
|
67
|
-
}
|
68
|
-
EOL
|
69
|
-
|
70
|
-
RDF_JSON = <<-EOL
|
71
|
-
{
|
72
|
-
"head": { "vars": [ "name" ] } ,
|
73
|
-
|
74
|
-
"results": {
|
75
|
-
"bindings": [
|
76
|
-
{ "name": { "type": "literal" , "value": "Apollo 11 Command and Service Module (CSM)" },
|
77
|
-
"uri": { "type": "uri" , "value": "http://nasa.dataincubator.org/spacecraft/12345" },
|
78
|
-
"mass": { "type": "literal" , "value": "5000.5", "datatype" : "http://www.w3.org/2001/XMLSchema#float" }
|
79
|
-
} ,
|
80
|
-
{ "name": { "type": "literal" , "value": "Apollo 11 SIVB" },
|
81
|
-
"uri": { "type": "uri" , "value": "http://nasa.dataincubator.org/spacecraft/12345" }
|
82
|
-
}
|
83
|
-
]
|
84
|
-
}
|
85
|
-
}
|
86
|
-
EOL
|
87
|
-
|
88
|
-
def test_apply_initial_bindings
|
89
|
-
query = "SELECT ?p ?o WHERE { ?s ?p ?o }"
|
90
|
-
values = { "s" => "<http://www.example.org>" }
|
91
|
-
|
92
|
-
bound = Kasabi::Sparql::SparqlHelper.apply_initial_bindings(query, values)
|
93
|
-
assert_not_nil(bound)
|
94
|
-
assert_equal( "SELECT ?p ?o WHERE { <http://www.example.org> ?p ?o }", bound )
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_apply_initial_bindings_with_dollars
|
98
|
-
query = "SELECT $p $o WHERE { $s $p $o }"
|
99
|
-
values = { "s" => "<http://www.example.org>" }
|
100
|
-
|
101
|
-
bound = Kasabi::Sparql::SparqlHelper.apply_initial_bindings(query, values)
|
102
|
-
assert_not_nil(bound)
|
103
|
-
assert_equal( "SELECT $p $o WHERE { <http://www.example.org> $p $o }", bound )
|
104
|
-
end
|
105
|
-
|
106
|
-
def test_apply_initial_bindings_with_literal
|
107
|
-
query = "SELECT ?s WHERE { ?s ?p ?o }"
|
108
|
-
values = { "o" => "'some value'" }
|
109
|
-
|
110
|
-
bound = Kasabi::Sparql::SparqlHelper.apply_initial_bindings(query, values)
|
111
|
-
assert_not_nil(bound)
|
112
|
-
assert_equal( "SELECT ?s WHERE { ?s ?p 'some value' }", bound )
|
113
|
-
end
|
114
|
-
|
115
|
-
def test_select
|
116
|
-
mc = mock()
|
117
|
-
mc.expects(:select).with(SELECT_QUERY, Kasabi::Sparql::SPARQL_RESULTS_JSON).returns(
|
118
|
-
HTTP::Message.new_response(RESULTS) )
|
119
|
-
json = Kasabi::Sparql::SparqlHelper.select(SELECT_QUERY, mc)
|
120
|
-
assert_not_nil(json)
|
121
|
-
assert_equal("name", json["head"]["vars"][0])
|
122
|
-
end
|
123
|
-
|
124
|
-
def test_failed_select
|
125
|
-
mc = mock()
|
126
|
-
resp = HTTP::Message.new_response("Error")
|
127
|
-
resp.status = 500
|
128
|
-
mc.expects(:select).with(SELECT_QUERY, Kasabi::Sparql::SPARQL_RESULTS_JSON).returns( resp )
|
129
|
-
assert_raises RuntimeError do
|
130
|
-
json = Kasabi::Sparql::SparqlHelper.select(SELECT_QUERY, mc)
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
def test_ask
|
135
|
-
mc = mock()
|
136
|
-
mc.expects(:select).with(ASK_QUERY, Kasabi::Sparql::SPARQL_RESULTS_JSON).returns(
|
137
|
-
HTTP::Message.new_response(ASK_RESULTS) )
|
138
|
-
assert_equal( true, Kasabi::Sparql::SparqlHelper.ask(ASK_QUERY, mc) )
|
139
|
-
end
|
140
|
-
|
141
|
-
def test_select_values
|
142
|
-
mc = mock()
|
143
|
-
mc.expects(:select).with(SELECT_QUERY, Kasabi::Sparql::SPARQL_RESULTS_JSON).returns(
|
144
|
-
HTTP::Message.new_response(RESULTS) )
|
145
|
-
results = Kasabi::Sparql::SparqlHelper.select_values(SELECT_QUERY, mc)
|
146
|
-
assert_not_nil( results )
|
147
|
-
assert_equal( 3, results.length )
|
148
|
-
end
|
149
|
-
|
150
|
-
def test_select_values_with_empty_binding
|
151
|
-
mc = mock()
|
152
|
-
mc.expects(:select).with(SELECT_QUERY, Kasabi::Sparql::SPARQL_RESULTS_JSON).returns(
|
153
|
-
HTTP::Message.new_response(RESULTS_NO_BINDING) )
|
154
|
-
results = Kasabi::Sparql::SparqlHelper.select_values(SELECT_QUERY, mc)
|
155
|
-
assert_not_nil( results )
|
156
|
-
assert_equal( 1 , results.length )
|
157
|
-
end
|
158
|
-
|
159
|
-
def test_select_single_value
|
160
|
-
mc = mock()
|
161
|
-
mc.expects(:select).with(SELECT_QUERY, Kasabi::Sparql::SPARQL_RESULTS_JSON).returns(
|
162
|
-
HTTP::Message.new_response(RESULTS) )
|
163
|
-
result = Kasabi::Sparql::SparqlHelper.select_single_value(SELECT_QUERY, mc)
|
164
|
-
assert_equal( "Apollo 11 Command and Service Module (CSM)", result )
|
165
|
-
end
|
166
|
-
|
167
|
-
def test_describe_to_resource_hash
|
168
|
-
mc = mock()
|
169
|
-
mc.expects(:describe).with(DESCRIBE_QUERY, "application/json").returns( HTTP::Message.new_response(RDF_JSON_RESULTS) )
|
170
|
-
result = Kasabi::Sparql::SparqlHelper.describe_to_resource_hash(DESCRIBE_QUERY, mc)
|
171
|
-
assert_not_nil(result)
|
172
|
-
assert_not_nil(result["http://www.example.org"])
|
173
|
-
end
|
174
|
-
|
175
|
-
def test_failed_describe
|
176
|
-
mc = mock()
|
177
|
-
resp = HTTP::Message.new_response("Error")
|
178
|
-
resp.status = 500
|
179
|
-
mc.expects(:describe).with(DESCRIBE_QUERY, "application/json").returns( resp )
|
180
|
-
assert_raises RuntimeError do
|
181
|
-
Kasabi::Sparql::SparqlHelper.describe_to_resource_hash(DESCRIBE_QUERY, mc)
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
def test_construct_to_resource_hash
|
186
|
-
mc = mock()
|
187
|
-
mc.expects(:construct).with(CONSTRUCT_QUERY, "application/json").returns( HTTP::Message.new_response(RDF_JSON_RESULTS) )
|
188
|
-
result = Kasabi::Sparql::SparqlHelper.construct_to_resource_hash(CONSTRUCT_QUERY, mc)
|
189
|
-
assert_not_nil(result)
|
190
|
-
assert_not_nil(result["http://www.example.org"])
|
191
|
-
end
|
192
|
-
|
193
|
-
def test_failed_construct
|
194
|
-
mc = mock()
|
195
|
-
resp = HTTP::Message.new_response("Error")
|
196
|
-
resp.status = 500
|
197
|
-
mc.expects(:construct).with(CONSTRUCT_QUERY, "application/json").returns( resp )
|
198
|
-
assert_raises RuntimeError do
|
199
|
-
Kasabi::Sparql::SparqlHelper.construct_to_resource_hash(CONSTRUCT_QUERY, mc)
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
def test_multi_describe
|
204
|
-
uris = []
|
205
|
-
uris << "http://www.example.org"
|
206
|
-
uris << "http://www.example.com"
|
207
|
-
mc = mock()
|
208
|
-
mc.expects(:multi_describe).with(uris, "application/json").returns(
|
209
|
-
HTTP::Message.new_response(RDF_JSON_RESULTS) )
|
210
|
-
|
211
|
-
result = Kasabi::Sparql::SparqlHelper.multi_describe(uris, mc)
|
212
|
-
assert_not_nil(result)
|
213
|
-
assert_not_nil(result["http://www.example.org"])
|
214
|
-
end
|
215
|
-
|
216
|
-
def test_binding_to_hash
|
217
|
-
json = JSON.parse(RDF_JSON)
|
218
|
-
binding = json["results"]["bindings"][0]
|
219
|
-
|
220
|
-
hash = Kasabi::Sparql::SparqlHelper.result_to_query_binding(binding)
|
221
|
-
assert_equal(3, hash.size)
|
222
|
-
assert_equal("\"Apollo 11 Command and Service Module (CSM)\"", hash["name"])
|
223
|
-
assert_equal("<http://nasa.dataincubator.org/spacecraft/12345>", hash["uri"])
|
224
|
-
assert_equal("\"5000.5\"^^http://www.w3.org/2001/XMLSchema#float", hash["mass"])
|
225
|
-
end
|
226
|
-
|
227
|
-
def test_results_to_bindings
|
228
|
-
json = JSON.parse(RDF_JSON)
|
229
|
-
bindings = Kasabi::Sparql::SparqlHelper.results_to_query_bindings(json)
|
230
|
-
assert_equal(2, bindings.size)
|
231
|
-
hash = bindings[0]
|
232
|
-
assert_equal("\"Apollo 11 Command and Service Module (CSM)\"", hash["name"])
|
233
|
-
assert_equal("<http://nasa.dataincubator.org/spacecraft/12345>", hash["uri"])
|
234
|
-
assert_equal("\"5000.5\"^^http://www.w3.org/2001/XMLSchema#float", hash["mass"])
|
235
|
-
end
|
236
|
-
|
237
|
-
def test_describe_uri
|
238
|
-
mc = mock()
|
239
|
-
mc.expects(:describe_uri).with("http://www.example.org", "application/json", :cbd).returns( HTTP::Message.new_response(RDF_JSON_RESULTS) )
|
240
|
-
result = Kasabi::Sparql::SparqlHelper.describe_uri("http://www.example.org", mc)
|
241
|
-
assert_not_nil(result)
|
242
|
-
assert_not_nil(result["http://www.example.org"])
|
243
|
-
end
|
244
|
-
|
245
|
-
def test_describe_uri_with_type
|
246
|
-
mc = mock()
|
247
|
-
mc.expects(:describe_uri).with("http://www.example.org", "application/json", :slcbd).returns( HTTP::Message.new_response(RDF_JSON_RESULTS) )
|
248
|
-
result = Kasabi::Sparql::SparqlHelper.describe_uri("http://www.example.org", mc, :slcbd)
|
249
|
-
assert_not_nil(result)
|
250
|
-
assert_not_nil(result["http://www.example.org"])
|
251
|
-
end
|
252
|
-
|
253
|
-
def test_exists
|
254
|
-
mc = mock()
|
255
|
-
mc.expects(:select).with("ASK { <http://www.example.org> ?p ?o }", Kasabi::Sparql::SPARQL_RESULTS_JSON).returns(
|
256
|
-
HTTP::Message.new_response(ASK_RESULTS) )
|
257
|
-
result = Kasabi::Sparql::SparqlHelper.exists("http://www.example.org", mc)
|
258
|
-
assert_equal( true, result )
|
259
|
-
|
260
|
-
end
|
261
|
-
|
262
|
-
end
|