agraph 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/spec/spec_helper.rb CHANGED
@@ -2,6 +2,7 @@ require 'rubygems'
2
2
  gem 'rspec', '1.3.0'
3
3
  require 'spec'
4
4
 
5
+ require File.join(File.dirname(__FILE__), "..", "lib", "allegro_graph")
5
6
  require File.join(File.dirname(__FILE__), "fake_transport_helper")
6
7
 
7
8
  FakeTransport.enable!
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Philipp Bruell
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-05 00:00:00 +02:00
17
+ date: 2010-07-05 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -29,22 +29,26 @@ extra_rdoc_files:
29
29
  files:
30
30
  - README.rdoc
31
31
  - Rakefile
32
- - lib/allegro_graph/federation.rb
32
+ - lib/allegro_graph/utility.rb
33
33
  - lib/allegro_graph/catalog.rb
34
+ - lib/allegro_graph/proxy.rb
34
35
  - lib/allegro_graph/proxy/geometric.rb
35
36
  - lib/allegro_graph/proxy/mapping.rb
36
37
  - lib/allegro_graph/proxy/query.rb
37
38
  - lib/allegro_graph/proxy/statements.rb
38
39
  - lib/allegro_graph/session.rb
39
40
  - lib/allegro_graph/server.rb
41
+ - lib/allegro_graph/extended_transport.rb
40
42
  - lib/allegro_graph/repository.rb
41
43
  - lib/allegro_graph/transport.rb
42
44
  - lib/allegro_graph/utility/parameter_mapper.rb
45
+ - lib/allegro_graph/resource.rb
43
46
  - lib/allegro_graph.rb
44
47
  - lib/agraph.rb
45
48
  - lib/code_smells.reek
46
49
  - spec/spec_helper.rb
47
50
  - spec/lib/allegro_graph/server_spec.rb
51
+ - spec/lib/allegro_graph/resource_spec.rb
48
52
  - spec/lib/allegro_graph/transport_spec.rb
49
53
  - spec/lib/allegro_graph/proxy/query_spec.rb
50
54
  - spec/lib/allegro_graph/proxy/geometric_spec.rb
@@ -52,11 +56,17 @@ files:
52
56
  - spec/lib/allegro_graph/proxy/mapping_spec.rb
53
57
  - spec/lib/allegro_graph/catalog_spec.rb
54
58
  - spec/lib/allegro_graph/session_spec.rb
59
+ - spec/lib/allegro_graph/extended_transport_spec.rb
55
60
  - spec/lib/allegro_graph/repository_spec.rb
56
- - spec/lib/allegro_graph/federation_spec.rb
57
61
  - spec/lib/allegro_graph/utility/parameter_mapper_spec.rb
58
62
  - spec/fake_transport_helper.rb
59
- - spec/integration/basic_spec.rb
63
+ - spec/integration/query_spec.rb
64
+ - spec/integration/server_spec.rb
65
+ - spec/integration/statements_spec.rb
66
+ - spec/integration/mapping_spec.rb
67
+ - spec/integration/geo_spatial_spec.rb
68
+ - spec/integration/transactions_spec.rb
69
+ - spec/integration/repository_spec.rb
60
70
  - spec/fake_transport.yml
61
71
  has_rdoc: true
62
72
  homepage: http://github.com/phifty/agraph
@@ -1,74 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "transport")
2
- require File.join(File.dirname(__FILE__), "proxy", "statements")
3
- require File.join(File.dirname(__FILE__), "proxy", "query")
4
- require File.join(File.dirname(__FILE__), "proxy", "geometric")
5
- require File.join(File.dirname(__FILE__), "proxy", "mapping")
6
-
7
- module AllegroGraph
8
-
9
- # The Federation class wrap the corresponding resource on the AllegroGraph server. A federation is a collection
10
- # of many repositories that acts like a single one. Only read access is allowed.
11
- class Federation
12
-
13
- attr_reader :server
14
- attr_accessor :name
15
- attr_accessor :repository_names
16
- attr_accessor :repository_urls
17
-
18
- attr_reader :statements
19
- attr_reader :query
20
- attr_reader :geometric
21
- attr_reader :mapping
22
-
23
- def initialize(server, name, options = { })
24
- @server, @name = server, name
25
-
26
- @repository_names = options[:repository_names]
27
- @repository_urls = options[:repository_urls]
28
-
29
- @statements = Proxy::Statements.new self
30
- @query = Proxy::Query.new self
31
- @geometric = Proxy::Geometric.new self
32
- @mapping = Proxy::Mapping.new self
33
- end
34
-
35
- def ==(other)
36
- other.is_a?(self.class) && @server == other.server && @name == other.name
37
- end
38
-
39
- def path
40
- "/federated/#{@name}"
41
- end
42
-
43
- def request(http_method, path, options = { })
44
- @server.request http_method, path, options
45
- end
46
-
47
- def exists?
48
- @server.federations.include? self
49
- end
50
-
51
- def create!
52
- parameters = { }
53
- parameters.merge! :repo => @repository_names if @repository_names
54
- parameters.merge! :url => @repository_urls if @repository_urls
55
- @server.request :put, self.path, :parameters => parameters, :expected_status_code => 204
56
- true
57
- end
58
-
59
- def create_if_missing!
60
- create! unless exists?
61
- end
62
-
63
- def delete!
64
- @server.request :delete, self.path, :expected_status_code => 204
65
- true
66
- end
67
-
68
- def delete_if_exists!
69
- delete! if exists?
70
- end
71
-
72
- end
73
-
74
- end
@@ -1,406 +0,0 @@
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-spatial data" do
170
-
171
- before :each do
172
- @repository.create_if_missing!
173
- @geometric = @repository.geometric
174
- @statements = @repository.statements
175
- end
176
-
177
- describe "types" do
178
-
179
- it "should provide a cartesian type" do
180
- result = @geometric.cartesian_type :strip_width => 1.0,
181
- :x_min => 2.0,
182
- :y_min => 2.0,
183
- :x_max => 20.0,
184
- :y_max => 20.0
185
- result.should == "<http://franz.com/ns/allegrograph/3.0/geospatial/cartesian/2.0/20.0/2.0/20.0/1.0>"
186
- end
187
-
188
- it "should provide a spherical type" do
189
- result = @geometric.spherical_type :strip_width => 1.0,
190
- :latitude_min => 2.0,
191
- :longitude_min => 2.0,
192
- :latitude_max => 20.0,
193
- :longitude_max => 20.0
194
- result.should == "<http://franz.com/ns/allegrograph/3.0/geospatial/spherical/degrees/2.0/20.0/2.0/20.0/1.0>"
195
- end
196
-
197
- end
198
-
199
- describe "creating polygon" do
200
-
201
- before :each do
202
- @type = @geometric.cartesian_type :strip_width => 1.0,
203
- :x_min => 2.0,
204
- :y_min => 2.0,
205
- :x_max => 20.0,
206
- :y_max => 20.0
207
- @polygon = [ [ 2.0, 2.0 ], [ 11.0, 2.0 ], [ 11.0, 11.0 ], [ 2.0, 11.0 ] ]
208
- end
209
-
210
- it "should return true" do
211
- result = @geometric.create_polygon @polygon, :name => "test_polygon", :type => @type
212
- result.should be_true
213
- end
214
-
215
- end
216
-
217
- context "in a cartesian system" do
218
-
219
- before :each do
220
- @type = @geometric.cartesian_type :strip_width => 1.0,
221
- :x_min => 2.0,
222
- :y_min => 2.0,
223
- :x_max => 20.0,
224
- :y_max => 20.0
225
- @statements.create "\"test_subject\"", "\"at\"", "\"+10+10\"^^#{@type}"
226
- @statements.create "\"another_subject\"", "\"at\"", "\"+15+15\"^^#{@type}"
227
- end
228
-
229
- it "should find objects inside a box" do
230
- result = @statements.find_inside_box :type => @type,
231
- :predicate => "\"at\"",
232
- :x_min => 8.0,
233
- :y_min => 8.0,
234
- :x_max => 11.0,
235
- :y_max => 11.0
236
- result.should include([ "\"test_subject\"", "\"at\"", "\"+10.000000000931323+10.000000000931323\"^^#{@type}"])
237
- result.should_not include([ "\"another_subject\"", "\"at\"", "\"+15.000000000465661+15.000000000465661\"^^#{@type}"])
238
- end
239
-
240
- it "should find objects inside a circle" do
241
- result = @statements.find_inside_circle :type => @type,
242
- :predicate => "\"at\"",
243
- :x => 9.0,
244
- :y => 9.0,
245
- :radius => 2.0
246
- result.should include([ "\"test_subject\"", "\"at\"", "\"+10.000000000931323+10.000000000931323\"^^#{@type}"])
247
- result.should_not include([ "\"another_subject\"", "\"at\"", "\"+15.000000000465661+15.000000000465661\"^^#{@type}"])
248
- end
249
-
250
- context "with a defined polygon" do
251
-
252
- before :each do
253
- @type = @geometric.cartesian_type :strip_width => 1,
254
- :x_min => -100,
255
- :y_min => -100,
256
- :x_max => 100,
257
- :y_max => 100
258
- @statements.create "\"test_subject\"", "\"at\"", "\"+1+1\"^^#{@type}"
259
- @geometric.create_polygon [ [ 0, -100 ], [ 0, 100 ], [ 100, 100 ], [ 100, -100 ] ],
260
- :name => "test_polygon",
261
- :type => @type
262
- end
263
-
264
- it "should find objects inside that polygon" do
265
- result = @statements.find_inside_polygon :type => @type,
266
- :predicate => "\"at\"",
267
- :polygon_name => "test_polygon"
268
- result.should include([ "\"test_subject\"", "\"at\"", "\"+0.9999999776482582+0.9999999776482582\"^^<http://franz.com/ns/allegrograph/3.0/geospatial/cartesian/-100.0/100.0/-100.0/100.0/1.0>"])
269
- end
270
-
271
- end
272
-
273
- end
274
-
275
- context "in a spherical system" do
276
-
277
- before :each do
278
- @type = @geometric.spherical_type :strip_width => 1.0,
279
- :latitude_min => 2.0,
280
- :longitude_min => 2.0,
281
- :latitude_max => 20.0,
282
- :longitude_max => 20.0
283
- @statements.create "\"test_subject\"", "\"at\"", "\"+10.00+010.00\"^^#{@type}"
284
- end
285
-
286
- it "should find objects inside a haversine" do
287
- result = @statements.find_inside_haversine :type => @type,
288
- :predicate => "\"at\"",
289
- :latitude => 9.0,
290
- :longitude => 9.0,
291
- :radius => 200.0,
292
- :unit => :km
293
- 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>"])
294
- end
295
-
296
- end
297
-
298
- end
299
-
300
- describe "transactions" do
301
-
302
- before :each do
303
- @repository.statements.delete
304
- end
305
-
306
- it "should commit all changes at once" do
307
- @repository.transaction do
308
- statements.create "\"test_subject\"", "<http://xmlns.com/foaf/0.1/knows>", "\"test_object\""
309
- statements.create "\"another_subject\"", "<http://xmlns.com/foaf/0.1/knows>", "\"another_object\""
310
- end
311
-
312
- result = @repository.statements.find
313
- result.should include([ "\"test_subject\"", "<http://xmlns.com/foaf/0.1/knows>", "\"test_object\"" ])
314
- result.should include([ "\"another_subject\"", "<http://xmlns.com/foaf/0.1/knows>", "\"another_object\"" ])
315
- end
316
-
317
- it "should rollback on error" do
318
- lambda do
319
- @repository.transaction do
320
- statements.create "\"test_subject\"", "<http://xmlns.com/foaf/0.1/knows>", "\"test_object\""
321
- statements.create "\"another_subject\"", "<http://xmlns.com/foaf/0.1/knows>", "\"another_object\""
322
- invalid
323
- end
324
- end.should raise_error(NameError)
325
-
326
- result = @repository.statements.find
327
- result.should_not include([ "\"test_subject\"", "<http://xmlns.com/foaf/0.1/knows>", "\"test_object\"" ])
328
- result.should_not include([ "\"another_subject\"", "<http://xmlns.com/foaf/0.1/knows>", "\"another_object\"" ])
329
- end
330
-
331
- end
332
-
333
- describe "federations" do
334
-
335
- before :each do
336
- @federation = AllegroGraph::Federation.new @server, "test_federation", :repository_names => [ @repository.name ]
337
- end
338
-
339
- it "should create a federation" do
340
- @federation.delete_if_exists!
341
- @federation.create!.should be_true
342
- end
343
-
344
- it "should list the federations" do
345
- @federation.create_if_missing!
346
- @server.federations.should include(@federation)
347
- end
348
-
349
- it "should delete a federation" do
350
- @federation.create_if_missing!
351
- @federation.delete!.should be_true
352
- end
353
-
354
- end
355
-
356
- describe "type mapping" do
357
-
358
- before :each do
359
- @repository.create_if_missing!
360
- @statements = @repository.statements
361
- @mapping = @repository.mapping
362
- end
363
-
364
- describe "creating a type" do
365
-
366
- it "should return true" do
367
- result = @mapping.create "<time>", "<http://www.w3.org/2001/XMLSchema#dateTime>"
368
- result.should be_true
369
- end
370
-
371
- end
372
-
373
- describe "creating a type" do
374
-
375
- before :each do
376
- @mapping.create "<time>", "<http://www.w3.org/2001/XMLSchema#dateTime>"
377
- end
378
-
379
- it "should return true" do
380
- result = @mapping.delete "<time>"
381
- result.should be_true
382
- end
383
-
384
- end
385
-
386
- describe "using a type for a range query" do
387
-
388
- before :each do
389
- @mapping.create "<time>", "<http://www.w3.org/2001/XMLSchema#dateTime>"
390
- @statements.create "\"event_one\"", "<happened>", "\"2010-03-29T17:00:00\"^^<time>"
391
- @statements.create "\"event_two\"", "<happened>", "\"2010-03-29T18:00:00\"^^<time>"
392
- @statements.create "\"event_three\"", "<happened>", "\"2010-03-29T19:00:00\"^^<time>"
393
- end
394
-
395
- it "should findthe statements for the given time" do
396
- result = @statements.find :predicate => "<happened>", :object => [ "\"2010-03-29T16:30:00\"^^<time>", "\"2010-03-29T18:30:00\"^^<time>" ]
397
- result.should include([ "\"event_one\"", "<happened>", "\"2010-03-29T17:00:00Z\"^^<http://www.w3.org/2001/XMLSchema#dateTime>" ])
398
- result.should include([ "\"event_two\"", "<happened>", "\"2010-03-29T18:00:00Z\"^^<http://www.w3.org/2001/XMLSchema#dateTime>" ])
399
- result.should_not include([ "\"event_three\"", "<happened>", "\"2010-03-29T19:00:00Z\"^^<http://www.w3.org/2001/XMLSchema#dateTime>" ])
400
- end
401
-
402
- end
403
-
404
- end
405
-
406
- end