agraph 0.1.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +137 -0
- data/Rakefile +48 -0
- data/lib/allegro_graph.rb +5 -0
- data/lib/allegro_graph/catalog.rb +39 -0
- data/lib/allegro_graph/federation.rb +72 -0
- data/lib/allegro_graph/proxy/geo.rb +117 -0
- data/lib/allegro_graph/proxy/mapping.rb +34 -0
- data/lib/allegro_graph/proxy/query.rb +37 -0
- data/lib/allegro_graph/proxy/statements.rb +59 -0
- data/lib/allegro_graph/repository.rb +89 -0
- data/lib/allegro_graph/server.rb +68 -0
- data/lib/allegro_graph/session.rb +64 -0
- data/lib/allegro_graph/transport.rb +169 -0
- data/lib/code_smells.reek +3 -0
- data/spec/fake_transport.yml +287 -0
- data/spec/fake_transport_helper.rb +38 -0
- data/spec/integration/basic_spec.rb +364 -0
- data/spec/lib/allegro_graph/catalog_spec.rb +85 -0
- data/spec/lib/allegro_graph/federation_spec.rb +113 -0
- data/spec/lib/allegro_graph/proxy/geo_spec.rb +89 -0
- data/spec/lib/allegro_graph/proxy/mapping_spec.rb +39 -0
- data/spec/lib/allegro_graph/proxy/query_spec.rb +62 -0
- data/spec/lib/allegro_graph/proxy/statements_spec.rb +58 -0
- data/spec/lib/allegro_graph/repository_spec.rb +224 -0
- data/spec/lib/allegro_graph/server_spec.rb +75 -0
- data/spec/lib/allegro_graph/session_spec.rb +76 -0
- data/spec/lib/allegro_graph/transport_spec.rb +116 -0
- data/spec/spec_helper.rb +26 -0
- metadata +92 -0
@@ -0,0 +1,287 @@
|
|
1
|
+
-
|
2
|
+
:http_method: "post"
|
3
|
+
:url: "http://session:5555/commit"
|
4
|
+
:response:
|
5
|
+
:code: "204"
|
6
|
+
:body: ""
|
7
|
+
-
|
8
|
+
:http_method: "post"
|
9
|
+
:url: "http://session:5555/rollback"
|
10
|
+
:response:
|
11
|
+
:code: "204"
|
12
|
+
:body: ""
|
13
|
+
-
|
14
|
+
:http_method: "get"
|
15
|
+
:url: "http://localhost:10035/version"
|
16
|
+
:response:
|
17
|
+
:code: "200"
|
18
|
+
:body: "4.0.1a"
|
19
|
+
-
|
20
|
+
:http_method: "get"
|
21
|
+
:url: "http://localhost:10035/version/date"
|
22
|
+
:response:
|
23
|
+
:code: "200"
|
24
|
+
:body: "March 10, 2010 10:23:52 GMT-0800"
|
25
|
+
-
|
26
|
+
:http_method: "get"
|
27
|
+
:url: "http://localhost:10035/version/revision"
|
28
|
+
:response:
|
29
|
+
:code: "200"
|
30
|
+
:body: "[unknown]"
|
31
|
+
-
|
32
|
+
:http_method: "get"
|
33
|
+
:url: "http://localhost:10035/catalogs"
|
34
|
+
:response:
|
35
|
+
:code: "200"
|
36
|
+
:body:
|
37
|
+
-
|
38
|
+
"id": "/"
|
39
|
+
"uri": "http://localhost:10035"
|
40
|
+
-
|
41
|
+
"id": "/test_catalog"
|
42
|
+
"uri": "http://localhost:10035/test_catalog"
|
43
|
+
-
|
44
|
+
:http_method: "put"
|
45
|
+
:url: "http://localhost:10035/catalogs/test_catalog"
|
46
|
+
:response:
|
47
|
+
:code: "400"
|
48
|
+
:body: ""
|
49
|
+
-
|
50
|
+
:http_method: "put"
|
51
|
+
:url: "http://localhost:10035/catalogs/not_existing"
|
52
|
+
:response:
|
53
|
+
:code: "201"
|
54
|
+
:body: ""
|
55
|
+
-
|
56
|
+
:http_method: "get"
|
57
|
+
:url: "http://localhost:10035/federated"
|
58
|
+
:response:
|
59
|
+
:code: "200"
|
60
|
+
:body:
|
61
|
+
-
|
62
|
+
"uri": "http://localhost:10035/federated/test_federation"
|
63
|
+
"id": "test_federation"
|
64
|
+
"title": "test_federation"
|
65
|
+
"readable": true
|
66
|
+
"writable": false
|
67
|
+
-
|
68
|
+
:http_method: "put"
|
69
|
+
:url: "http://localhost:10035/federated/test_federation"
|
70
|
+
:parameters:
|
71
|
+
:repo: [ "test_repository" ]
|
72
|
+
:url: [ "http://username:password@server:10035/repositories/another" ]
|
73
|
+
:response:
|
74
|
+
:code: "204"
|
75
|
+
:body: ""
|
76
|
+
-
|
77
|
+
:http_method: "delete"
|
78
|
+
:url: "http://localhost:10035/federated/test_federation"
|
79
|
+
:response:
|
80
|
+
:code: "204"
|
81
|
+
:body: ""
|
82
|
+
-
|
83
|
+
:http_method: "get"
|
84
|
+
:url: "http://localhost:10035/catalogs/test_catalog/repositories"
|
85
|
+
:response:
|
86
|
+
:code: "200"
|
87
|
+
:body:
|
88
|
+
-
|
89
|
+
"uri": "http://localhost:10035/repositories/test_repository"
|
90
|
+
"id": "test_repository"
|
91
|
+
"title": "test_repository"
|
92
|
+
"readable": true
|
93
|
+
"writable": true
|
94
|
+
-
|
95
|
+
:http_method: "put"
|
96
|
+
:url: "http://localhost:10035/catalogs/test_catalog/repositories/test_repository"
|
97
|
+
:response:
|
98
|
+
:code: "400"
|
99
|
+
:body: ""
|
100
|
+
-
|
101
|
+
:http_method: "delete"
|
102
|
+
:url: "http://localhost:10035/catalogs/test_catalog/repositories/test_repository"
|
103
|
+
:response:
|
104
|
+
:code: "200"
|
105
|
+
:body: ""
|
106
|
+
-
|
107
|
+
:http_method: "put"
|
108
|
+
:url: "http://localhost:10035/catalogs/test_catalog/repositories/not_existing"
|
109
|
+
:response:
|
110
|
+
:code: "204"
|
111
|
+
:body: ""
|
112
|
+
-
|
113
|
+
:http_method: "delete"
|
114
|
+
:url: "http://localhost:10035/catalogs/test_catalog/repositories/not_existing"
|
115
|
+
:response:
|
116
|
+
:code: "400"
|
117
|
+
:body: ""
|
118
|
+
-
|
119
|
+
:http_method: "get"
|
120
|
+
:url: "http://localhost:10035/catalogs/test_catalog/repositories/test_repository/size"
|
121
|
+
:response:
|
122
|
+
:code: "200"
|
123
|
+
:body: "3"
|
124
|
+
-
|
125
|
+
:http_method: "post"
|
126
|
+
:url: "http://localhost:10035/catalogs/test_catalog/repositories/test_repository/statements"
|
127
|
+
:response:
|
128
|
+
:code: "204"
|
129
|
+
:body: "1"
|
130
|
+
-
|
131
|
+
:http_method: "get"
|
132
|
+
:url: "http://localhost:10035/catalogs/test_catalog/repositories/test_repository/statements"
|
133
|
+
:response:
|
134
|
+
:code: "200"
|
135
|
+
:body:
|
136
|
+
- [ "\"test_subject\"", "\"test_predicate\"", "\"test_object\"", "\"test_context\"" ]
|
137
|
+
- [ "\"another_subject\"", "\"test_predicate\"", "\"another_object\"", "\"test_context\"" ]
|
138
|
+
-
|
139
|
+
:http_method: "get"
|
140
|
+
:url: "http://localhost:10035/catalogs/test_catalog/repositories/test_repository/statements"
|
141
|
+
:parameters:
|
142
|
+
:subj: "test_subject"
|
143
|
+
:response:
|
144
|
+
:code: "200"
|
145
|
+
:body:
|
146
|
+
- [ "\"test_subject\"", "\"test_predicate\"", "\"test_object\"", "\"test_context\"" ]
|
147
|
+
-
|
148
|
+
:http_method: "delete"
|
149
|
+
:url: "http://localhost:10035/catalogs/test_catalog/repositories/test_repository/statements"
|
150
|
+
:parameters:
|
151
|
+
:subj: "test_subject"
|
152
|
+
:response:
|
153
|
+
:code: "200"
|
154
|
+
:body: ""
|
155
|
+
-
|
156
|
+
:http_method: "get"
|
157
|
+
:url: "http://localhost:10035/catalogs/test_catalog/repositories/test_repository"
|
158
|
+
:parameters:
|
159
|
+
:query: "SELECT ?subject WHERE { ?subject <http://xmlns.com/foaf/0.1/knows> ?object . }"
|
160
|
+
:queryLn: "sparql"
|
161
|
+
:response:
|
162
|
+
:code: "200"
|
163
|
+
:body:
|
164
|
+
"names": [ "subject" ]
|
165
|
+
"values":
|
166
|
+
- [ "\"another_subject\"" ]
|
167
|
+
- [ "\"test_subject\"" ]
|
168
|
+
-
|
169
|
+
:http_method: "get"
|
170
|
+
:url: "http://localhost:10035/catalogs/test_catalog/repositories/test_repository"
|
171
|
+
:parameters:
|
172
|
+
:query: "(select (?subject) (q- ?subject !<http://xmlns.com/foaf/0.1/knows> ?object))"
|
173
|
+
:queryLn: "prolog"
|
174
|
+
:response:
|
175
|
+
:code: "200"
|
176
|
+
:body:
|
177
|
+
"names": [ "subject" ]
|
178
|
+
"values":
|
179
|
+
- [ "\"another_subject\"" ]
|
180
|
+
- [ "\"test_subject\"" ]
|
181
|
+
-
|
182
|
+
:http_method: "post"
|
183
|
+
:url: "http://localhost:10035/catalogs/test_catalog/repositories/test_repository/geo/types/cartesian"
|
184
|
+
:parameters:
|
185
|
+
:stripWidth: "1.0"
|
186
|
+
:xmin: "2.0"
|
187
|
+
:xmax: "20.0"
|
188
|
+
:ymin: "2.0"
|
189
|
+
:ymax: "20.0"
|
190
|
+
:response:
|
191
|
+
:code: "200"
|
192
|
+
:body: "\"<http://franz.com/ns/allegrograph/3.0/geospatial/cartesian/2.0/20.0/2.0/20.0/1.0>\""
|
193
|
+
-
|
194
|
+
:http_method: "post"
|
195
|
+
:url: "http://localhost:10035/catalogs/test_catalog/repositories/test_repository/geo/types/spherical"
|
196
|
+
:parameters:
|
197
|
+
:stripWidth: "1.0"
|
198
|
+
:unit: "degree"
|
199
|
+
:latmin: "2.0"
|
200
|
+
:latmax: "20.0"
|
201
|
+
:longmin: "2.0"
|
202
|
+
:longmax: "20.0"
|
203
|
+
:response:
|
204
|
+
:code: "200"
|
205
|
+
:body: "\"<http://franz.com/ns/allegrograph/3.0/geospatial/spherical/degrees/2.0/20.0/2.0/20.0/1.0>\""
|
206
|
+
-
|
207
|
+
:http_method: "put"
|
208
|
+
:url: "http://localhost:10035/catalogs/test_catalog/repositories/test_repository/geo/polygon"
|
209
|
+
:parameters:
|
210
|
+
:resource: "\"test_polygon\""
|
211
|
+
:point:
|
212
|
+
- "\"+2+2\"^^<http://franz.com/ns/allegrograph/3.0/geospatial/cartesian/2.0/20.0/2.0/20.0/1.0>"
|
213
|
+
- "\"+10+2\"^^<http://franz.com/ns/allegrograph/3.0/geospatial/cartesian/2.0/20.0/2.0/20.0/1.0>"
|
214
|
+
- "\"+10+10\"^^<http://franz.com/ns/allegrograph/3.0/geospatial/cartesian/2.0/20.0/2.0/20.0/1.0>"
|
215
|
+
- "\"+2+10\"^^<http://franz.com/ns/allegrograph/3.0/geospatial/cartesian/2.0/20.0/2.0/20.0/1.0>"
|
216
|
+
:response:
|
217
|
+
:code: "204"
|
218
|
+
:body: ""
|
219
|
+
-
|
220
|
+
:http_method: "get"
|
221
|
+
:url: "http://localhost:10035/catalogs/test_catalog/repositories/test_repository/geo/box"
|
222
|
+
:parameters:
|
223
|
+
:type: "<http://franz.com/ns/allegrograph/3.0/geospatial/cartesian/2.0/20.0/2.0/20.0/1.0>"
|
224
|
+
:predicate: "\"at\""
|
225
|
+
:xmin: "8.0"
|
226
|
+
:ymin: "8.0"
|
227
|
+
:xmax: "11.0"
|
228
|
+
:ymax: "11.0"
|
229
|
+
:response:
|
230
|
+
:code: "200"
|
231
|
+
:body:
|
232
|
+
- [ "\"test_subject\"", "\"at\"", "\"+10.000000000931323+10.000000000931323\"^^<http://franz.com/ns/allegrograph/3.0/geospatial/cartesian/2.0/20.0/2.0/20.0/1.0>" ]
|
233
|
+
-
|
234
|
+
:http_method: "get"
|
235
|
+
:url: "http://localhost:10035/catalogs/test_catalog/repositories/test_repository/geo/circle"
|
236
|
+
:parameters:
|
237
|
+
:type: "<http://franz.com/ns/allegrograph/3.0/geospatial/cartesian/2.0/20.0/2.0/20.0/1.0>"
|
238
|
+
:predicate: "\"at\""
|
239
|
+
:x: "9.0"
|
240
|
+
:y: "9.0"
|
241
|
+
:radius: "2.0"
|
242
|
+
:response:
|
243
|
+
:code: "200"
|
244
|
+
:body:
|
245
|
+
- [ "\"test_subject\"", "\"at\"", "\"+10.000000000931323+10.000000000931323\"^^<http://franz.com/ns/allegrograph/3.0/geospatial/cartesian/2.0/20.0/2.0/20.0/1.0>" ]
|
246
|
+
-
|
247
|
+
:http_method: "get"
|
248
|
+
:url: "http://localhost:10035/catalogs/test_catalog/repositories/test_repository/geo/haversine"
|
249
|
+
:parameters:
|
250
|
+
:type: "<http://franz.com/ns/allegrograph/3.0/geospatial/cartesian/2.0/20.0/2.0/20.0/1.0>"
|
251
|
+
:predicate: "\"at\""
|
252
|
+
:lat: "+09.0000000"
|
253
|
+
:long: "+009.0000000"
|
254
|
+
:radius: "200.0"
|
255
|
+
:unit: "km"
|
256
|
+
:response:
|
257
|
+
:code: "200"
|
258
|
+
:body:
|
259
|
+
- [ "\"test_subject\"", "\"at\"", "\"+100000+0100000\"^^<http://franz.com/ns/allegrograph/3.0/geospatial/spherical/degrees/2.0/20.0/2.0/20.0/1.0>" ]
|
260
|
+
-
|
261
|
+
:http_method: "get"
|
262
|
+
:url: "http://localhost:10035/catalogs/test_catalog/repositories/test_repository/geo/polygon"
|
263
|
+
:parameters:
|
264
|
+
:type: "<http://franz.com/ns/allegrograph/3.0/geospatial/cartesian/2.0/20.0/2.0/20.0/1.0>"
|
265
|
+
:predicate: "\"at\""
|
266
|
+
:polygon: "\"test_polygon\""
|
267
|
+
:response:
|
268
|
+
:code: "200"
|
269
|
+
:body:
|
270
|
+
- [ "\"test_subject\"", "\"at\"", "\"+10.000000000931323+10.000000000931323\"^^<http://franz.com/ns/allegrograph/3.0/geospatial/cartesian/2.0/20.0/2.0/20.0/1.0>" ]
|
271
|
+
-
|
272
|
+
:http_method: "put"
|
273
|
+
:url: "http://localhost:10035/catalogs/test_catalog/repositories/test_repository/mapping/type"
|
274
|
+
:parameters:
|
275
|
+
:type: "<time>"
|
276
|
+
:encoding: "<http://www.w3.org/2001/XMLSchema#dateTime>"
|
277
|
+
:response:
|
278
|
+
:code: "204"
|
279
|
+
:body: ""
|
280
|
+
-
|
281
|
+
:http_method: "delete"
|
282
|
+
:url: "http://localhost:10035/catalogs/test_catalog/repositories/test_repository/mapping/type"
|
283
|
+
:parameters:
|
284
|
+
:type: "<time>"
|
285
|
+
:response:
|
286
|
+
:code: "204"
|
287
|
+
:body: ""
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module FakeTransport
|
4
|
+
|
5
|
+
def self.enable!
|
6
|
+
@enabled = true
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.disable!
|
10
|
+
@enabled = false
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.transport_class
|
14
|
+
AllegroGraph::ExtendedTransport
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.fake!
|
18
|
+
return unless @enabled
|
19
|
+
@@fake ||= YAML::load_file File.join(File.dirname(__FILE__), "fake_transport.yml")
|
20
|
+
transport_class.stub!(:request).and_return do |http_method, url, options|
|
21
|
+
options ||= { }
|
22
|
+
parameters = options[:parameters]
|
23
|
+
headers = options[:headers]
|
24
|
+
expected_status_code = options[:expected_status_code]
|
25
|
+
|
26
|
+
request = @@fake.detect do |hash|
|
27
|
+
hash[:http_method].to_s == http_method.to_s &&
|
28
|
+
hash[:url].to_s == url.to_s &&
|
29
|
+
hash[:parameters] == parameters &&
|
30
|
+
hash[:headers] == headers
|
31
|
+
end
|
32
|
+
raise StandardError, "no fake request found for [#{http_method} #{url} #{parameters.inspect} #{headers.inspect}]" unless request
|
33
|
+
raise transport_class::UnexpectedStatusCodeError.new(request[:response][:code].to_i, request[:response][:body]) if expected_status_code && expected_status_code.to_s != request[:response][:code]
|
34
|
+
request[:response][:body].dup
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,364 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper"))
|
2
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "lib", "allegro_graph"))
|
3
|
+
|
4
|
+
describe "integration" do
|
5
|
+
|
6
|
+
use_real_transport!
|
7
|
+
|
8
|
+
before :each do
|
9
|
+
@server = AllegroGraph::Server.new :username => "test", :password => "test"
|
10
|
+
@repository = AllegroGraph::Repository.new @server, "test_repository"
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "basic server functions" do
|
14
|
+
|
15
|
+
before :each do
|
16
|
+
@server = AllegroGraph::Server.new :username => "test", :password => "test"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should return the server's version" do
|
20
|
+
@server.version.should == {
|
21
|
+
:version => "\"4.0.1a\"",
|
22
|
+
:date => "\"March 10, 2010 10:23:52 GMT-0800\"",
|
23
|
+
:revision => "\"[unknown]\""
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "repository listing" do
|
30
|
+
|
31
|
+
before :each do
|
32
|
+
@repository.create_if_missing!
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should provide a list of repositories" do
|
36
|
+
@server.root_catalog.repositories.should == [ @repository ]
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "repository creation" do
|
42
|
+
|
43
|
+
before :each do
|
44
|
+
@repository.delete_if_exists!
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should create the repository" do
|
48
|
+
lambda do
|
49
|
+
@repository.create!
|
50
|
+
end.should change(@repository, :exists?).from(false).to(true)
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "repository deletion" do
|
56
|
+
|
57
|
+
before :each do
|
58
|
+
@repository.create_if_missing!
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should delete the repository" do
|
62
|
+
lambda do
|
63
|
+
@repository.delete!
|
64
|
+
end.should change(@repository, :exists?).from(true).to(false)
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "statements" do
|
70
|
+
|
71
|
+
before :each do
|
72
|
+
@repository.create_if_missing!
|
73
|
+
@statements = @repository.statements
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "creation" do
|
77
|
+
|
78
|
+
it "should take a statement" do
|
79
|
+
result = @statements.create "\"test_subject\"", "\"test_predicate\"", "\"test_object\"", "\"test_context\""
|
80
|
+
result.should be_true
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "finding" do
|
86
|
+
|
87
|
+
before :each do
|
88
|
+
@statements.delete
|
89
|
+
@statements.create "\"test_subject\"", "\"test_predicate\"", "\"test_object\"", "\"test_context\""
|
90
|
+
@statements.create "\"another_subject\"", "\"test_predicate\"", "\"another_object\"", "\"test_context\""
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should find all statements" do
|
94
|
+
statements = @statements.find
|
95
|
+
statements.should == [
|
96
|
+
[ "\"test_subject\"", "\"test_predicate\"", "\"test_object\"", "\"test_context\"" ],
|
97
|
+
[ "\"another_subject\"", "\"test_predicate\"", "\"another_object\"", "\"test_context\"" ]
|
98
|
+
]
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should find statements by filter options" do
|
102
|
+
statements = @statements.find :subject => "\"test_subject\""
|
103
|
+
statements.should == [
|
104
|
+
[ "\"test_subject\"", "\"test_predicate\"", "\"test_object\"", "\"test_context\"" ]
|
105
|
+
]
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "deletion" do
|
111
|
+
|
112
|
+
before :each do
|
113
|
+
@statements.create "\"test_subject\"", "\"test_predicate\"", "\"test_object\"", "\"test_context\""
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should delete all statements" do
|
117
|
+
lambda do
|
118
|
+
@statements.delete :subject => "\"test_subject\"",
|
119
|
+
:predicate => "\"test_predicate\"",
|
120
|
+
:object => "\"test_object\"",
|
121
|
+
:context => "\"test_context\""
|
122
|
+
end.should change(@repository, :size)
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
describe "query bypass" do
|
130
|
+
|
131
|
+
before :each do
|
132
|
+
@repository.create_if_missing!
|
133
|
+
|
134
|
+
statements = @repository.statements
|
135
|
+
statements.create "\"test_subject\"", "<http://xmlns.com/foaf/0.1/knows>", "\"test_object\"", "\"test_context\""
|
136
|
+
statements.create "\"another_subject\"", "<http://xmlns.com/foaf/0.1/knows>", "\"another_object\"", "\"test_context\""
|
137
|
+
end
|
138
|
+
|
139
|
+
context "sparql" do
|
140
|
+
|
141
|
+
before :each do
|
142
|
+
@repository.query.language = :sparql
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should respond to queried data" do
|
146
|
+
result = @repository.query.perform "SELECT ?subject WHERE { ?subject <http://xmlns.com/foaf/0.1/knows> ?object . }"
|
147
|
+
result["names"].should include("subject")
|
148
|
+
result["values"].should include([ "\"another_subject\"" ], [ "\"test_subject\"" ])
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
context "prolog" do
|
154
|
+
|
155
|
+
before :each do
|
156
|
+
@repository.query.language = :prolog
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should respond to queried data" do
|
160
|
+
result = @repository.query.perform "(select (?subject) (q- ?subject !<http://xmlns.com/foaf/0.1/knows> ?object))"
|
161
|
+
result["names"].should include("subject")
|
162
|
+
result["values"].should include([ "\"another_subject\"" ], [ "\"test_subject\"" ])
|
163
|
+
end
|
164
|
+
|
165
|
+
end
|
166
|
+
|
167
|
+
end
|
168
|
+
|
169
|
+
describe "geo" do
|
170
|
+
|
171
|
+
before :each do
|
172
|
+
@repository.create_if_missing!
|
173
|
+
@geo = @repository.geo
|
174
|
+
end
|
175
|
+
|
176
|
+
describe "types" do
|
177
|
+
|
178
|
+
it "should provide a cartesian type" do
|
179
|
+
result = @geo.cartesian_type 1.0, 2.0, 2.0, 20.0, 20.0
|
180
|
+
result.should == "<http://franz.com/ns/allegrograph/3.0/geospatial/cartesian/2.0/20.0/2.0/20.0/1.0>"
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should provide a spherical type" do
|
184
|
+
result = @geo.spherical_type 1.0, :degree, 2.0, 2.0, 20.0, 20.0
|
185
|
+
result.should == "<http://franz.com/ns/allegrograph/3.0/geospatial/spherical/degrees/2.0/20.0/2.0/20.0/1.0>"
|
186
|
+
end
|
187
|
+
|
188
|
+
end
|
189
|
+
|
190
|
+
describe "creating polygon" do
|
191
|
+
|
192
|
+
before :each do
|
193
|
+
@type = @geo.cartesian_type 1.0, 2.0, 2.0, 20.0, 20.0
|
194
|
+
@polygon = [ [ 2.0, 2.0 ], [ 11.0, 2.0 ], [ 11.0, 11.0 ], [ 2.0, 11.0 ] ]
|
195
|
+
end
|
196
|
+
|
197
|
+
it "should return true" do
|
198
|
+
result = @geo.create_polygon "test_polygon", @type, @polygon
|
199
|
+
result.should be_true
|
200
|
+
end
|
201
|
+
|
202
|
+
end
|
203
|
+
|
204
|
+
context "in a cartesian system" do
|
205
|
+
|
206
|
+
before :each do
|
207
|
+
@type = @geo.cartesian_type 1.0, 2.0, 2.0, 20.0, 20.0
|
208
|
+
@repository.statements.create "\"test_subject\"", "\"at\"", "\"+10+10\"^^#{@type}"
|
209
|
+
@repository.statements.create "\"another_subject\"", "\"at\"", "\"+15+15\"^^#{@type}"
|
210
|
+
end
|
211
|
+
|
212
|
+
it "should find objects inside a box" do
|
213
|
+
result = @geo.inside_box @type, "\"at\"", 8.0, 8.0, 11.0, 11.0
|
214
|
+
result.should include([ "\"test_subject\"", "\"at\"", "\"+10.000000000931323+10.000000000931323\"^^#{@type}"])
|
215
|
+
result.should_not include([ "\"another_subject\"", "\"at\"", "\"+15.000000000465661+15.000000000465661\"^^#{@type}"])
|
216
|
+
end
|
217
|
+
|
218
|
+
it "should find objects inside a circle" do
|
219
|
+
result = @geo.inside_circle @type, "\"at\"", 9.0, 9.0, 2.0
|
220
|
+
result.should include([ "\"test_subject\"", "\"at\"", "\"+10.000000000931323+10.000000000931323\"^^#{@type}"])
|
221
|
+
result.should_not include([ "\"another_subject\"", "\"at\"", "\"+15.000000000465661+15.000000000465661\"^^#{@type}"])
|
222
|
+
end
|
223
|
+
|
224
|
+
context "with a defined polygon" do
|
225
|
+
|
226
|
+
before :each do
|
227
|
+
@type = @geo.cartesian_type 1, -100, -100, 100, 100
|
228
|
+
@repository.statements.create "\"test_subject\"", "\"at\"", "\"+1+1\"^^#{@type}"
|
229
|
+
@geo.create_polygon "test_polygon", @type, [ [ 0, -100 ], [ 0, 100 ], [ 100, 100 ], [ 100, -100 ] ]
|
230
|
+
end
|
231
|
+
|
232
|
+
it "should find objects inside that polygon" do
|
233
|
+
pending
|
234
|
+
result = @geo.inside_polygon @type, "\"at\"", "test_polygon"
|
235
|
+
result.should include([ "\"test_subject\"", "\"at\"", "\"+1+1\"^^<http://franz.com/ns/allegrograph/3.0/geospatial/cartesian/2.0/20.0/2.0/20.0/1.0>"])
|
236
|
+
end
|
237
|
+
|
238
|
+
end
|
239
|
+
|
240
|
+
end
|
241
|
+
|
242
|
+
context "in a spherical system" do
|
243
|
+
|
244
|
+
before :each do
|
245
|
+
@type = @geo.spherical_type 1.0, :degree, 2.0, 2.0, 20.0, 20.0
|
246
|
+
@repository.statements.create "\"test_subject\"", "\"at\"", "\"+10.00+010.00\"^^#{@type}"
|
247
|
+
end
|
248
|
+
|
249
|
+
it "should find objects inside a haversine" do
|
250
|
+
result = @geo.inside_haversine @type, "\"at\"", 9.0, 9.0, 200.0, :km
|
251
|
+
result.should include([ "\"test_subject\"", "\"at\"", "\"+100000+0100000\"^^<http://franz.com/ns/allegrograph/3.0/geospatial/spherical/degrees/2.0/20.0/2.0/20.0/1.0>"])
|
252
|
+
end
|
253
|
+
|
254
|
+
end
|
255
|
+
|
256
|
+
end
|
257
|
+
|
258
|
+
describe "transactions" do
|
259
|
+
|
260
|
+
before :each do
|
261
|
+
@repository.statements.delete
|
262
|
+
end
|
263
|
+
|
264
|
+
it "should commit all changes at once" do
|
265
|
+
@repository.transaction do
|
266
|
+
statements.create "\"test_subject\"", "<http://xmlns.com/foaf/0.1/knows>", "\"test_object\""
|
267
|
+
statements.create "\"another_subject\"", "<http://xmlns.com/foaf/0.1/knows>", "\"another_object\""
|
268
|
+
end
|
269
|
+
|
270
|
+
result = @repository.statements.find
|
271
|
+
result.should include([ "\"test_subject\"", "<http://xmlns.com/foaf/0.1/knows>", "\"test_object\"" ])
|
272
|
+
result.should include([ "\"another_subject\"", "<http://xmlns.com/foaf/0.1/knows>", "\"another_object\"" ])
|
273
|
+
end
|
274
|
+
|
275
|
+
it "should rollback on error" do
|
276
|
+
lambda do
|
277
|
+
@repository.transaction do
|
278
|
+
statements.create "\"test_subject\"", "<http://xmlns.com/foaf/0.1/knows>", "\"test_object\""
|
279
|
+
statements.create "\"another_subject\"", "<http://xmlns.com/foaf/0.1/knows>", "\"another_object\""
|
280
|
+
invalid
|
281
|
+
end
|
282
|
+
end.should raise_error(NameError)
|
283
|
+
|
284
|
+
result = @repository.statements.find
|
285
|
+
result.should_not include([ "\"test_subject\"", "<http://xmlns.com/foaf/0.1/knows>", "\"test_object\"" ])
|
286
|
+
result.should_not include([ "\"another_subject\"", "<http://xmlns.com/foaf/0.1/knows>", "\"another_object\"" ])
|
287
|
+
end
|
288
|
+
|
289
|
+
end
|
290
|
+
|
291
|
+
describe "federations" do
|
292
|
+
|
293
|
+
before :each do
|
294
|
+
@federation = AllegroGraph::Federation.new @server, "test_federation", :repository_names => [ @repository.name ]
|
295
|
+
end
|
296
|
+
|
297
|
+
it "should create a federation" do
|
298
|
+
@federation.delete_if_exists!
|
299
|
+
@federation.create!.should be_true
|
300
|
+
end
|
301
|
+
|
302
|
+
it "should list the federations" do
|
303
|
+
@federation.create_if_missing!
|
304
|
+
@server.federations.should include(@federation)
|
305
|
+
end
|
306
|
+
|
307
|
+
it "should delete a federation" do
|
308
|
+
@federation.create_if_missing!
|
309
|
+
@federation.delete!.should be_true
|
310
|
+
end
|
311
|
+
|
312
|
+
end
|
313
|
+
|
314
|
+
describe "type mapping" do
|
315
|
+
|
316
|
+
before :each do
|
317
|
+
@repository.create_if_missing!
|
318
|
+
@statements = @repository.statements
|
319
|
+
@mapping = @repository.mapping
|
320
|
+
end
|
321
|
+
|
322
|
+
describe "creating a type" do
|
323
|
+
|
324
|
+
it "should return true" do
|
325
|
+
result = @mapping.create "<time>", "<http://www.w3.org/2001/XMLSchema#dateTime>"
|
326
|
+
result.should be_true
|
327
|
+
end
|
328
|
+
|
329
|
+
end
|
330
|
+
|
331
|
+
describe "creating a type" do
|
332
|
+
|
333
|
+
before :each do
|
334
|
+
@mapping.create "<time>", "<http://www.w3.org/2001/XMLSchema#dateTime>"
|
335
|
+
end
|
336
|
+
|
337
|
+
it "should return true" do
|
338
|
+
result = @mapping.delete "<time>"
|
339
|
+
result.should be_true
|
340
|
+
end
|
341
|
+
|
342
|
+
end
|
343
|
+
|
344
|
+
describe "using a type for a range query" do
|
345
|
+
|
346
|
+
before :each do
|
347
|
+
@mapping.create "<time>", "<http://www.w3.org/2001/XMLSchema#dateTime>"
|
348
|
+
@statements.create "\"event_one\"", "<happened>", "\"2010-03-29T17:00:00\"^^<time>"
|
349
|
+
@statements.create "\"event_two\"", "<happened>", "\"2010-03-29T18:00:00\"^^<time>"
|
350
|
+
@statements.create "\"event_three\"", "<happened>", "\"2010-03-29T19:00:00\"^^<time>"
|
351
|
+
end
|
352
|
+
|
353
|
+
it "should findthe statements for the given time" do
|
354
|
+
result = @statements.find :predicate => "<happened>", :object => [ "\"2010-03-29T16:30:00\"^^<time>", "\"2010-03-29T18:30:00\"^^<time>" ]
|
355
|
+
result.should include([ "\"event_one\"", "<happened>", "\"2010-03-29T17:00:00Z\"^^<http://www.w3.org/2001/XMLSchema#dateTime>" ])
|
356
|
+
result.should include([ "\"event_two\"", "<happened>", "\"2010-03-29T18:00:00Z\"^^<http://www.w3.org/2001/XMLSchema#dateTime>" ])
|
357
|
+
result.should_not include([ "\"event_three\"", "<happened>", "\"2010-03-29T19:00:00Z\"^^<http://www.w3.org/2001/XMLSchema#dateTime>" ])
|
358
|
+
end
|
359
|
+
|
360
|
+
end
|
361
|
+
|
362
|
+
end
|
363
|
+
|
364
|
+
end
|