agraph 0.1.0.beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,85 @@
|
|
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", "catalog"))
|
3
|
+
|
4
|
+
describe AllegroGraph::Catalog do
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
@server = AllegroGraph::Server.new :username => "test", :password => "test"
|
8
|
+
@catalog = AllegroGraph::Catalog.new @server, "test_catalog"
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "==" do
|
12
|
+
|
13
|
+
it "should be true when comparing two equal catalogs" do
|
14
|
+
other = AllegroGraph::Catalog.new @server, "test_catalog"
|
15
|
+
@catalog.should == other
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should be false when comparing two different catalog" do
|
19
|
+
other = AllegroGraph::Catalog.new @server, "other_catalog"
|
20
|
+
@catalog.should_not == other
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "path" do
|
26
|
+
|
27
|
+
context "for root catalog" do
|
28
|
+
|
29
|
+
before :each do
|
30
|
+
@catalog.stub!(:root?).and_return(true)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should the root catalog url" do
|
34
|
+
@catalog.path.should == ""
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
context "for named catalog" do
|
40
|
+
|
41
|
+
it "should the named catalog url" do
|
42
|
+
@catalog.path.should == "/catalogs/test_catalog"
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "exists?" do
|
50
|
+
|
51
|
+
context "for a catalog that already exists" do
|
52
|
+
|
53
|
+
it "should return true" do
|
54
|
+
@catalog.exists?.should be_true
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
context "for a catalog that not exists" do
|
60
|
+
|
61
|
+
before :each do
|
62
|
+
@catalog.name = "not_existing"
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should return false" do
|
66
|
+
@catalog.exists?.should be_false
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "repositories" do
|
74
|
+
|
75
|
+
before :each do
|
76
|
+
@repository = AllegroGraph::Repository.new @catalog, "test_repository"
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should return the catalog's repositories" do
|
80
|
+
@catalog.repositories.should == [ @repository ]
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
@@ -0,0 +1,113 @@
|
|
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", "federation"))
|
3
|
+
|
4
|
+
describe AllegroGraph::Federation do
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
@server = AllegroGraph::Server.new :username => "test", :password => "test"
|
8
|
+
@federation = AllegroGraph::Federation.new @server,
|
9
|
+
"test_federation",
|
10
|
+
:repository_names => [ "test_repository" ],
|
11
|
+
:repository_urls => [ "http://username:password@server:10035/repositories/another" ]
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "==" do
|
15
|
+
|
16
|
+
it "should be true when comparing two equal federations" do
|
17
|
+
other = AllegroGraph::Federation.new @server, "test_federation"
|
18
|
+
@federation.should == other
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should be false when comparing two different federations" do
|
22
|
+
other = AllegroGraph::Federation.new @server, "other_federationy"
|
23
|
+
@federation.should_not == other
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "request" do
|
29
|
+
|
30
|
+
before :each do
|
31
|
+
@server.stub!(:request)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should call the server's request method" do
|
35
|
+
@server.should_receive(:request).with(:get, "/", { })
|
36
|
+
@federation.request :get, "/"
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "exists?" do
|
42
|
+
|
43
|
+
context "for a federation that already exists" do
|
44
|
+
|
45
|
+
it "should return true" do
|
46
|
+
@federation.exists?.should be_true
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
context "for a federation that not exists" do
|
52
|
+
|
53
|
+
before :each do
|
54
|
+
@federation.name = "not_existing"
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should return false" do
|
58
|
+
@federation.exists?.should be_false
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "create!" do
|
66
|
+
|
67
|
+
it "should return true" do
|
68
|
+
@federation.create!.should be_true
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "create_if_missing!" do
|
74
|
+
|
75
|
+
it "should do nothing if the federation already exists" do
|
76
|
+
@federation.stub!(:exists?).and_return(true)
|
77
|
+
@federation.should_not_receive(:create!)
|
78
|
+
@federation.create_if_missing!
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should call create! if the federation doesn't exists" do
|
82
|
+
@federation.stub!(:exists?).and_return(false)
|
83
|
+
@federation.should_receive(:create!)
|
84
|
+
@federation.create_if_missing!
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "delete!" do
|
90
|
+
|
91
|
+
it "should return true" do
|
92
|
+
@federation.delete!.should be_true
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "delete_if_exists!" do
|
98
|
+
|
99
|
+
it "should call delete! if the federation already exists" do
|
100
|
+
@federation.stub!(:exists?).and_return(true)
|
101
|
+
@federation.should_receive(:delete!)
|
102
|
+
@federation.delete_if_exists!
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should do nothing if the federation doesn't exists" do
|
106
|
+
@federation.stub!(:exists?).and_return(false)
|
107
|
+
@federation.should_not_receive(:delete!)
|
108
|
+
@federation.delete_if_exists!
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
@@ -0,0 +1,89 @@
|
|
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", "proxy", "geo"))
|
3
|
+
|
4
|
+
describe AllegroGraph::Proxy::Geo do
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
@server = AllegroGraph::Server.new :username => "test", :password => "test"
|
8
|
+
@catalog = AllegroGraph::Catalog.new @server, "test_catalog"
|
9
|
+
@repository = AllegroGraph::Repository.new @catalog, "test_repository"
|
10
|
+
@geo = AllegroGraph::Proxy::Geo.new @repository
|
11
|
+
@type = @geo.cartesian_type 1.0, 2.0, 2.0, 20.0, 20.0
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "path" do
|
15
|
+
|
16
|
+
it "should return the correct path" do
|
17
|
+
@geo.path.should == "#{@repository.path}/geo"
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "cartesian_type" do
|
23
|
+
|
24
|
+
it "should provide a cartesian type" do
|
25
|
+
result = @geo.cartesian_type 1.0, 2.0, 2.0, 20.0, 20.0
|
26
|
+
result.should == "<http://franz.com/ns/allegrograph/3.0/geospatial/cartesian/2.0/20.0/2.0/20.0/1.0>"
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "spherical_type" do
|
32
|
+
|
33
|
+
it "should provide a spherical type" do
|
34
|
+
result = @geo.spherical_type 1.0, :degree, 2.0, 2.0, 20.0, 20.0
|
35
|
+
result.should == "<http://franz.com/ns/allegrograph/3.0/geospatial/spherical/degrees/2.0/20.0/2.0/20.0/1.0>"
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "create_polygon" do
|
41
|
+
|
42
|
+
before :each do
|
43
|
+
@polygon = [ [ 2.0, 2.0 ], [ 10.0, 2.0 ], [ 10.0, 10.0 ], [ 2.0, 10.0 ] ]
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should create a polygon" do
|
47
|
+
result = @geo.create_polygon "test_polygon", @type, @polygon
|
48
|
+
result.should be_true
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "inside_box" do
|
54
|
+
|
55
|
+
it "should find objects inside a box" do
|
56
|
+
result = @geo.inside_box @type, "\"at\"", 8.0, 8.0, 11.0, 11.0
|
57
|
+
result.should include([ "\"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>"])
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "inside_circle" do
|
63
|
+
|
64
|
+
it "should find objects inside a circle" do
|
65
|
+
result = @geo.inside_circle @type, "\"at\"", 9.0, 9.0, 2.0
|
66
|
+
result.should include([ "\"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>"])
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "inside_haversine" do
|
72
|
+
|
73
|
+
it "should find objects inside a haversine" do
|
74
|
+
result = @geo.inside_haversine @type, "\"at\"", 9.0, 9.0, 200.0, :km
|
75
|
+
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>"])
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "inside_polygon" do
|
81
|
+
|
82
|
+
it "should find objects inside a polygon" do
|
83
|
+
result = @geo.inside_polygon @type, "\"at\"", "test_polygon"
|
84
|
+
result.should include([ "\"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>"])
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
@@ -0,0 +1,39 @@
|
|
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", "proxy", "mapping"))
|
3
|
+
|
4
|
+
describe AllegroGraph::Proxy::Geo do
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
@server = AllegroGraph::Server.new :username => "test", :password => "test"
|
8
|
+
@catalog = AllegroGraph::Catalog.new @server, "test_catalog"
|
9
|
+
@repository = AllegroGraph::Repository.new @catalog, "test_repository"
|
10
|
+
@mapping = AllegroGraph::Proxy::Mapping.new @repository
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "path" do
|
14
|
+
|
15
|
+
it "should return the correct path" do
|
16
|
+
@mapping.path.should == "#{@repository.path}/mapping"
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "create" do
|
22
|
+
|
23
|
+
it "should return true" do
|
24
|
+
result = @mapping.create "<time>", "<http://www.w3.org/2001/XMLSchema#dateTime>"
|
25
|
+
result.should be_true
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "delete" do
|
31
|
+
|
32
|
+
it "should return true" do
|
33
|
+
result = @mapping.delete "<time>"
|
34
|
+
result.should be_true
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,62 @@
|
|
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", "proxy", "query"))
|
3
|
+
|
4
|
+
describe AllegroGraph::Proxy::Query do
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
@server = AllegroGraph::Server.new :username => "test", :password => "test"
|
8
|
+
@catalog = AllegroGraph::Catalog.new @server, "test_catalog"
|
9
|
+
@repository = AllegroGraph::Repository.new @catalog, "test_repository"
|
10
|
+
@query = AllegroGraph::Proxy::Query.new @repository
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "path" do
|
14
|
+
|
15
|
+
it "should return the correct path" do
|
16
|
+
@query.path.should == @repository.path
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "language=" do
|
22
|
+
|
23
|
+
it "should take :sparql" do
|
24
|
+
@query.language = :sparql
|
25
|
+
@query.language.should == :sparql
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should take :prolog" do
|
29
|
+
@query.language = :prolog
|
30
|
+
@query.language.should == :prolog
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should raise a NotImplementedError on invalid language" do
|
34
|
+
lambda do
|
35
|
+
@query.language = :invalid
|
36
|
+
end.should raise_error(NotImplementedError)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "perform" do
|
42
|
+
|
43
|
+
it "should return the sparql query result" do
|
44
|
+
result = @query.perform "SELECT ?subject WHERE { ?subject <http://xmlns.com/foaf/0.1/knows> ?object . }"
|
45
|
+
result.should == {
|
46
|
+
"names" => [ "subject" ],
|
47
|
+
"values" => [ [ "\"another_subject\"" ], [ "\"test_subject\"" ] ]
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should return the query result" do
|
52
|
+
@query.language = :prolog
|
53
|
+
result = @query.perform "(select (?subject) (q- ?subject !<http://xmlns.com/foaf/0.1/knows> ?object))"
|
54
|
+
result.should == {
|
55
|
+
"names" => [ "subject" ],
|
56
|
+
"values" => [ [ "\"another_subject\"" ], [ "\"test_subject\"" ] ]
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,58 @@
|
|
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", "proxy", "statements"))
|
3
|
+
|
4
|
+
describe AllegroGraph::Proxy::Statements do
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
@server = AllegroGraph::Server.new :username => "test", :password => "test"
|
8
|
+
@catalog = AllegroGraph::Catalog.new @server, "test_catalog"
|
9
|
+
@repository = AllegroGraph::Repository.new @catalog, "test_repository"
|
10
|
+
@statements = AllegroGraph::Proxy::Statements.new @repository
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "path" do
|
14
|
+
|
15
|
+
it "should return the correct path" do
|
16
|
+
@statements.path.should == "#{@repository.path}/statements"
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "create" do
|
22
|
+
|
23
|
+
it "should create a statement" do
|
24
|
+
result = @statements.create "\"test_subject\"", "\"test_predicate\"", "\"test_object\"", "\"test_context\""
|
25
|
+
result.should be_true
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "find" do
|
31
|
+
|
32
|
+
it "should find all statements" do
|
33
|
+
result = @statements.find
|
34
|
+
result.should == [
|
35
|
+
[ "\"test_subject\"", "\"test_predicate\"", "\"test_object\"", "\"test_context\"" ],
|
36
|
+
[ "\"another_subject\"", "\"test_predicate\"", "\"another_object\"", "\"test_context\"" ]
|
37
|
+
]
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should find statements by filter options" do
|
41
|
+
result = @statements.find :subject => "test_subject"
|
42
|
+
result.should == [
|
43
|
+
[ "\"test_subject\"", "\"test_predicate\"", "\"test_object\"", "\"test_context\"" ]
|
44
|
+
]
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "delete" do
|
50
|
+
|
51
|
+
it "should delete all statements" do
|
52
|
+
result = @statements.delete :subject => "test_subject"
|
53
|
+
result.should be_true
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|