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,224 @@
|
|
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", "repository"))
|
3
|
+
|
4
|
+
describe AllegroGraph::Repository 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
|
+
end
|
11
|
+
|
12
|
+
describe "==" do
|
13
|
+
|
14
|
+
it "should be true when comparing two equal repositories" do
|
15
|
+
other = AllegroGraph::Repository.new @catalog, "test_repository"
|
16
|
+
@repository.should == other
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should be false when comparing two different repositories" do
|
20
|
+
other = AllegroGraph::Repository.new @catalog, "other_repository"
|
21
|
+
@repository.should_not == other
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "path" do
|
27
|
+
|
28
|
+
it "should return the repository path" do
|
29
|
+
@repository.path.should == "#{@catalog.path}/repositories/test_repository"
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "request" do
|
35
|
+
|
36
|
+
before :each do
|
37
|
+
@server.stub!(:request)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should call the server's request method" do
|
41
|
+
@server.should_receive(:request).with(:get, "/", { })
|
42
|
+
@repository.request :get, "/"
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "exists?" do
|
48
|
+
|
49
|
+
context "for a repository that already exists" do
|
50
|
+
|
51
|
+
it "should return true" do
|
52
|
+
@repository.exists?.should be_true
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
context "for a repository that not exists" do
|
58
|
+
|
59
|
+
before :each do
|
60
|
+
@repository.name = "not_existing"
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should return false" do
|
64
|
+
@repository.exists?.should be_false
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "create!" do
|
72
|
+
|
73
|
+
context "for a repository that already exists" do
|
74
|
+
|
75
|
+
it "should return false" do
|
76
|
+
@repository.create!.should be_false
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
context "for a repository that not exists" do
|
82
|
+
|
83
|
+
before :each do
|
84
|
+
@repository.name = "not_existing"
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should return true" do
|
88
|
+
@repository.create!.should be_true
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "create_if_missing!" do
|
96
|
+
|
97
|
+
context "for a repository that already exists" do
|
98
|
+
|
99
|
+
before :each do
|
100
|
+
@repository.stub!(:exists?).and_return(true)
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should do nothing" do
|
104
|
+
@repository.should_not_receive(:create!)
|
105
|
+
@repository.create_if_missing!
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
context "for a repository that not exists" do
|
111
|
+
|
112
|
+
before :each do
|
113
|
+
@repository.stub!(:exists?).and_return(false)
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should call create!" do
|
117
|
+
@repository.should_receive(:create!)
|
118
|
+
@repository.create_if_missing!
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
describe "delete!" do
|
126
|
+
|
127
|
+
context "for a repository that already exists" do
|
128
|
+
|
129
|
+
it "should return true" do
|
130
|
+
@repository.delete!.should be_true
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
context "for a repository that not exists" do
|
136
|
+
|
137
|
+
before :each do
|
138
|
+
@repository.name = "not_existing"
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should return false" do
|
142
|
+
@repository.delete!.should be_false
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
describe "delete_if_exists!" do
|
150
|
+
|
151
|
+
context "for a repository that already exists" do
|
152
|
+
|
153
|
+
before :each do
|
154
|
+
@repository.stub!(:exists?).and_return(true)
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should call delete!" do
|
158
|
+
@repository.should_receive(:delete!)
|
159
|
+
@repository.delete_if_exists!
|
160
|
+
end
|
161
|
+
|
162
|
+
end
|
163
|
+
|
164
|
+
context "for a repository that not exists" do
|
165
|
+
|
166
|
+
before :each do
|
167
|
+
@repository.stub!(:exists?).and_return(false)
|
168
|
+
end
|
169
|
+
|
170
|
+
it "should do nothing" do
|
171
|
+
@repository.should_not_receive(:delete!)
|
172
|
+
@repository.delete_if_exists!
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
176
|
+
|
177
|
+
end
|
178
|
+
|
179
|
+
describe "size" do
|
180
|
+
|
181
|
+
it "should return the number of statements" do
|
182
|
+
@repository.size.should == 3
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
186
|
+
|
187
|
+
describe "transaction" do
|
188
|
+
|
189
|
+
before :each do
|
190
|
+
@session = AllegroGraph::Session.new :url => "http://session:5555", :username => "test", :password => "test"
|
191
|
+
AllegroGraph::Session.stub!(:create).and_return(@session)
|
192
|
+
|
193
|
+
@session.statements.stub!(:create)
|
194
|
+
end
|
195
|
+
|
196
|
+
it "should use the session proxies" do
|
197
|
+
@session.statements.should_receive(:create)
|
198
|
+
@repository.transaction do
|
199
|
+
statements.create
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
it "should commit the session after block execution" do
|
204
|
+
@session.statements.should_receive(:create).ordered
|
205
|
+
@session.should_receive(:commit).ordered
|
206
|
+
@repository.transaction do
|
207
|
+
statements.create
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
it "should rollback the session on error" do
|
212
|
+
@session.statements.should_receive(:create).ordered
|
213
|
+
@session.should_receive(:rollback).ordered
|
214
|
+
lambda do
|
215
|
+
@repository.transaction do
|
216
|
+
statements.create
|
217
|
+
invalid
|
218
|
+
end
|
219
|
+
end.should raise_error(NameError)
|
220
|
+
end
|
221
|
+
|
222
|
+
end
|
223
|
+
|
224
|
+
end
|
@@ -0,0 +1,75 @@
|
|
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", "server"))
|
3
|
+
|
4
|
+
describe AllegroGraph::Server do
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
@server = AllegroGraph::Server.new :username => "test", :password => "test"
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "==" do
|
11
|
+
|
12
|
+
it "should be true when comparing two equal servers" do
|
13
|
+
other = AllegroGraph::Server.new
|
14
|
+
@server.should == other
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should be false when comparing two different servers" do
|
18
|
+
other = AllegroGraph::Server.new :host => "other"
|
19
|
+
@server.should_not == other
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "request" do
|
25
|
+
|
26
|
+
before :each do
|
27
|
+
AllegroGraph::ExtendedTransport.stub!(:request)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should perform an extended request" do
|
31
|
+
AllegroGraph::ExtendedTransport.should_receive(:request).with(
|
32
|
+
:get, "http://localhost:10035/", hash_including(:expected_status_code => 200)
|
33
|
+
).and_return("test" => "test")
|
34
|
+
@server.request(:get, "/", :expected_status_code => 200).should == { "test" => "test" }
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "version" do
|
40
|
+
|
41
|
+
it "should return the server's version" do
|
42
|
+
@server.version.should == {
|
43
|
+
:version => "4.0.1a",
|
44
|
+
:date => "March 10, 2010 10:23:52 GMT-0800",
|
45
|
+
:revision => "[unknown]"
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "catalogs" do
|
52
|
+
|
53
|
+
before :each do
|
54
|
+
@catalog = AllegroGraph::Catalog.new @server, "test_catalog"
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should return the catalogs of the server" do
|
58
|
+
@server.catalogs.should == [ @server.root_catalog, @catalog ]
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "federations" do
|
64
|
+
|
65
|
+
before :each do
|
66
|
+
@federation = AllegroGraph::Federation.new @server, "test_federation"
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should return the federations of the server" do
|
70
|
+
@server.federations.should include(@federation)
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
@@ -0,0 +1,76 @@
|
|
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", "session"))
|
3
|
+
|
4
|
+
describe AllegroGraph::Session do
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
@session = AllegroGraph::Session.new :url => "http://session:5555", :username => "test", :password => "test"
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "request" do
|
11
|
+
|
12
|
+
before :each do
|
13
|
+
AllegroGraph::ExtendedTransport.stub!(:request)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should perform an extended request" do
|
17
|
+
AllegroGraph::ExtendedTransport.should_receive(:request).with(
|
18
|
+
:get, "http://session:5555/", hash_including(:expected_status_code => 200)
|
19
|
+
).and_return("test" => "test")
|
20
|
+
@session.request(:get, "/", :expected_status_code => 200).should == { "test" => "test" }
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "commit" do
|
26
|
+
|
27
|
+
it "should return true" do
|
28
|
+
result = @session.commit
|
29
|
+
result.should be_true
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "rollback" do
|
35
|
+
|
36
|
+
it "should return true" do
|
37
|
+
result = @session.rollback
|
38
|
+
result.should be_true
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "create" do
|
44
|
+
|
45
|
+
before :each do
|
46
|
+
@server = Object.new
|
47
|
+
@server.stub!(:username).and_return("test")
|
48
|
+
@server.stub!(:password).and_return("test")
|
49
|
+
@repository = Object.new
|
50
|
+
@repository.stub!(:path).and_return("/repositories/test_repository")
|
51
|
+
@repository.stub!(:request).and_return("http://session:5555")
|
52
|
+
@repository.stub!(:server).and_return(@server)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should request a session" do
|
56
|
+
@repository.should_receive(:request).with(
|
57
|
+
:post, "/repositories/test_repository/session", :expected_status_code => 200
|
58
|
+
).and_return("http://session:5555")
|
59
|
+
AllegroGraph::Session.create @repository
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should return a session" do
|
63
|
+
result = AllegroGraph::Session.create @repository
|
64
|
+
result.should be_instance_of(AllegroGraph::Session)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should set the correct values" do
|
68
|
+
result = AllegroGraph::Session.create @repository
|
69
|
+
result.url.should == "http://session:5555"
|
70
|
+
result.username.should == "test"
|
71
|
+
result.password.should == "test"
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
@@ -0,0 +1,116 @@
|
|
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", "transport"))
|
3
|
+
|
4
|
+
describe AllegroGraph::Transport do
|
5
|
+
|
6
|
+
use_real_transport!
|
7
|
+
|
8
|
+
describe "request" do
|
9
|
+
|
10
|
+
before :each do
|
11
|
+
@http_method = :get
|
12
|
+
@url = "http://localhost:5984/"
|
13
|
+
@options = { }
|
14
|
+
|
15
|
+
@request = Net::HTTP::Get.new "/", { }
|
16
|
+
@response = Object.new
|
17
|
+
@response.stub!(:code).and_return("200")
|
18
|
+
@response.stub!(:body).and_return("test")
|
19
|
+
Net::HTTP.stub!(:start).and_return(@response)
|
20
|
+
end
|
21
|
+
|
22
|
+
def do_request(options = { })
|
23
|
+
AllegroGraph::Transport.request @http_method, @url, @options.merge(options)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should initialize the correct request object" do
|
27
|
+
Net::HTTP::Get.should_receive(:new).with("/", { }).and_return(@request)
|
28
|
+
do_request
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should perform the request" do
|
32
|
+
Net::HTTP.should_receive(:start).and_return(@response)
|
33
|
+
do_request
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should return the response" do
|
37
|
+
do_request.body.should == "test"
|
38
|
+
end
|
39
|
+
|
40
|
+
context "with parameters" do
|
41
|
+
|
42
|
+
before :each do
|
43
|
+
@options.merge! :parameters => { :foo => "bar", :test => [ "value1", "value2" ] }
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should initialize the correct request object" do
|
47
|
+
Net::HTTP::Get.should_receive(:new).with(
|
48
|
+
"/?foo=bar&test=value1&test=value2", { }
|
49
|
+
).and_return(@request)
|
50
|
+
do_request
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
describe AllegroGraph::ExtendedTransport do
|
60
|
+
|
61
|
+
use_real_transport!
|
62
|
+
|
63
|
+
describe "request" do
|
64
|
+
|
65
|
+
before :each do
|
66
|
+
@http_method = :get
|
67
|
+
@url = "http://localhost:5984/"
|
68
|
+
@options = {
|
69
|
+
:auth_type => :basic,
|
70
|
+
:username => "test",
|
71
|
+
:password => "test",
|
72
|
+
:expected_status_code => 200
|
73
|
+
}
|
74
|
+
|
75
|
+
@request = Net::HTTP::Get.new "/", { }
|
76
|
+
@response = Object.new
|
77
|
+
@response.stub!(:code).and_return("200")
|
78
|
+
@response.stub!(:body).and_return("{\"test\":\"test\"}")
|
79
|
+
Net::HTTP.stub!(:start).and_return(@response)
|
80
|
+
end
|
81
|
+
|
82
|
+
def do_request(options = { })
|
83
|
+
AllegroGraph::ExtendedTransport.request @http_method, @url, @options.merge(options)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should initialize the correct request object" do
|
87
|
+
Net::HTTP::Get.should_receive(:new).with(
|
88
|
+
"/", { "Authorization" => "Basic dGVzdDp0ZXN0\n", "Accept" => "application/json" }
|
89
|
+
).and_return(@request)
|
90
|
+
do_request
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should perform the request" do
|
94
|
+
Net::HTTP.should_receive(:start).and_return(@response)
|
95
|
+
do_request
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should return the parsed response" do
|
99
|
+
do_request.should == { "test" => "test" }
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should raise NotImplementedError if the given auth_type is wrong" do
|
103
|
+
lambda do
|
104
|
+
do_request :auth_type => :invalid
|
105
|
+
end.should raise_error(NotImplementedError)
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should raise UnexpectedStatusCodeError if responded status code is wrong" do
|
109
|
+
lambda do
|
110
|
+
do_request :expected_status_code => 201
|
111
|
+
end.should raise_error(AllegroGraph::ExtendedTransport::UnexpectedStatusCodeError)
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|