agraph 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +22 -21
- data/lib/allegro_graph.rb +1 -2
- data/lib/allegro_graph/catalog.rb +2 -2
- data/lib/allegro_graph/proxy/geometric.rb +3 -3
- data/lib/allegro_graph/proxy/mapping.rb +2 -2
- data/lib/allegro_graph/proxy/query.rb +1 -1
- data/lib/allegro_graph/proxy/statements.rb +8 -8
- data/lib/allegro_graph/repository.rb +12 -8
- data/lib/allegro_graph/server.rb +11 -6
- data/lib/allegro_graph/session.rb +11 -8
- data/spec/integration/geo_spatial_spec.rb +16 -24
- data/spec/integration/mapping_spec.rb +3 -5
- data/spec/integration/query_spec.rb +0 -2
- data/spec/integration/server_spec.rb +3 -3
- data/spec/integration/statements_spec.rb +1 -1
- data/spec/integration/transactions_spec.rb +2 -0
- data/spec/lib/allegro_graph/catalog_spec.rb +2 -1
- data/spec/lib/allegro_graph/proxy/geometric_spec.rb +1 -0
- data/spec/lib/allegro_graph/proxy/mapping_spec.rb +2 -1
- data/spec/lib/allegro_graph/proxy/query_spec.rb +2 -1
- data/spec/lib/allegro_graph/proxy/statements_spec.rb +2 -1
- data/spec/lib/allegro_graph/repository_spec.rb +25 -6
- data/spec/lib/allegro_graph/server_spec.rb +21 -5
- data/spec/lib/allegro_graph/session_spec.rb +27 -13
- data/spec/spec_helper.rb +3 -5
- metadata +51 -12
- data/lib/allegro_graph/extended_transport.rb +0 -84
- data/lib/allegro_graph/transport.rb +0 -100
- data/spec/lib/allegro_graph/extended_transport_spec.rb +0 -59
- data/spec/lib/allegro_graph/transport_spec.rb +0 -57
data/Rakefile
CHANGED
@@ -1,37 +1,38 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
|
2
|
+
|
3
|
+
gem 'rspec'
|
3
4
|
require 'rspec'
|
4
|
-
require "rake/rdoctask"
|
5
|
-
require 'rake/gempackagetask'
|
6
5
|
require 'rspec/core/rake_task'
|
7
6
|
|
7
|
+
gem 'reek'
|
8
|
+
require 'reek/rake/task'
|
9
|
+
|
10
|
+
require 'rake/rdoctask'
|
11
|
+
|
8
12
|
task :default => :spec
|
9
13
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
specification.extra_rdoc_files = [ "README.rdoc" ]
|
23
|
-
specification.require_path = "lib"
|
14
|
+
namespace :gem do
|
15
|
+
|
16
|
+
desc "Builds the gem"
|
17
|
+
task :build do
|
18
|
+
system "gem build *.gemspec && mkdir -p pkg/ && mv *.gem pkg/"
|
19
|
+
end
|
20
|
+
|
21
|
+
desc "Builds and installs the gem"
|
22
|
+
task :install => :build do
|
23
|
+
system "gem install pkg/"
|
24
|
+
end
|
25
|
+
|
24
26
|
end
|
25
27
|
|
26
|
-
Rake::
|
27
|
-
|
28
|
+
Reek::Rake::Task.new do |task|
|
29
|
+
task.fail_on_error = true
|
28
30
|
end
|
29
31
|
|
30
32
|
desc "Generate the rdoc"
|
31
33
|
Rake::RDocTask.new do |rdoc|
|
32
34
|
rdoc.rdoc_files.add [ "README.rdoc", "lib/**/*.rb" ]
|
33
|
-
rdoc.main
|
34
|
-
rdoc.title = "Client for the AllegroGraph 4.x graph database."
|
35
|
+
rdoc.main = "README.rdoc"
|
35
36
|
end
|
36
37
|
|
37
38
|
desc "Run all specs in spec directory"
|
data/lib/allegro_graph.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
+
require 'transport'
|
1
2
|
|
2
3
|
module AllegroGraph
|
3
4
|
|
4
|
-
autoload :Transport, File.join(File.dirname(__FILE__), "allegro_graph", "transport")
|
5
|
-
autoload :ExtendedTransport, File.join(File.dirname(__FILE__), "allegro_graph", "extended_transport")
|
6
5
|
autoload :Server, File.join(File.dirname(__FILE__), "allegro_graph", "server")
|
7
6
|
autoload :Catalog, File.join(File.dirname(__FILE__), "allegro_graph", "catalog")
|
8
7
|
autoload :Resource, File.join(File.dirname(__FILE__), "allegro_graph", "resource")
|
@@ -31,10 +31,10 @@ module AllegroGraph
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def repositories
|
34
|
-
repositories = @server.
|
34
|
+
repositories = @server.request_json :get, self.path + "/repositories", :expected_status_code => 200
|
35
35
|
repositories.map { |repository| Repository.new self, repository["id"] }
|
36
36
|
end
|
37
37
|
|
38
38
|
end
|
39
39
|
|
40
|
-
end
|
40
|
+
end
|
@@ -19,7 +19,7 @@ module AllegroGraph
|
|
19
19
|
|
20
20
|
def cartesian_type(parameters = { })
|
21
21
|
parameters = Utility::ParameterMapper.map parameters, :cartesian_type
|
22
|
-
type = @resource.
|
22
|
+
type = @resource.request_http :post, self.path + "/types/cartesian", :parameters => parameters, :expected_status_code => 200
|
23
23
|
type.sub! /^.*</, "<"
|
24
24
|
type.sub! />.*$/, ">"
|
25
25
|
type
|
@@ -27,7 +27,7 @@ module AllegroGraph
|
|
27
27
|
|
28
28
|
def spherical_type(parameters = { })
|
29
29
|
parameters = Utility::ParameterMapper.map parameters, :spherical_type
|
30
|
-
type = @resource.
|
30
|
+
type = @resource.request_http :post, self.path + "/types/spherical", :parameters => parameters, :expected_status_code => 200
|
31
31
|
type.sub! /^.*</, "<"
|
32
32
|
type.sub! />.*$/, ">"
|
33
33
|
type
|
@@ -40,7 +40,7 @@ module AllegroGraph
|
|
40
40
|
raise ArgumentError, "at least three points has to defined" unless points.is_a?(Array) && points.size >= 3
|
41
41
|
parameters[:point] = points.map{ |point| "\"%+g%+g\"^^%s" % [ point[0], point[1], type ] }
|
42
42
|
|
43
|
-
@resource.
|
43
|
+
@resource.request_json :put, self.path + "/polygon", :parameters => parameters, :expected_status_code => 204
|
44
44
|
true
|
45
45
|
end
|
46
46
|
|
@@ -18,13 +18,13 @@ module AllegroGraph
|
|
18
18
|
|
19
19
|
def create(type, encoding)
|
20
20
|
parameters = { :type => type, :encoding => encoding }
|
21
|
-
@resource.
|
21
|
+
@resource.request_http :put, self.path + "/type", :parameters => parameters, :expected_status_code => 204
|
22
22
|
true
|
23
23
|
end
|
24
24
|
|
25
25
|
def delete(type)
|
26
26
|
parameters = { :type => type }
|
27
|
-
@resource.
|
27
|
+
@resource.request_http :delete, self.path + "/type", :parameters => parameters, :expected_status_code => 204
|
28
28
|
true
|
29
29
|
end
|
30
30
|
|
@@ -29,7 +29,7 @@ module AllegroGraph
|
|
29
29
|
|
30
30
|
def perform(query)
|
31
31
|
parameters = { :query => query, :queryLn => @language.to_s }
|
32
|
-
@resource.
|
32
|
+
@resource.request_json :get, self.path, :parameters => parameters, :expected_status_code => 200
|
33
33
|
end
|
34
34
|
|
35
35
|
end
|
@@ -20,7 +20,7 @@ module AllegroGraph
|
|
20
20
|
def create(subject, predicate, object, context = nil)
|
21
21
|
statement = [ subject, predicate, object ]
|
22
22
|
statement << context if context
|
23
|
-
@resource.
|
23
|
+
@resource.request_json :post, self.path + "/statements", :body => [ statement ], :expected_status_code => 204
|
24
24
|
true
|
25
25
|
end
|
26
26
|
|
@@ -32,7 +32,7 @@ module AllegroGraph
|
|
32
32
|
parameters.merge! parameter_key => value if value
|
33
33
|
end
|
34
34
|
|
35
|
-
@resource.
|
35
|
+
@resource.request_http :delete, self.path + "/statements", :parameters => parameters, :expected_status_code => 200
|
36
36
|
end
|
37
37
|
|
38
38
|
def find(options = { })
|
@@ -51,31 +51,31 @@ module AllegroGraph
|
|
51
51
|
|
52
52
|
parameters = nil if parameters.empty?
|
53
53
|
|
54
|
-
@resource.
|
54
|
+
@resource.request_json :get, self.path + "/statements", :parameters => parameters, :expected_status_code => 200
|
55
55
|
end
|
56
56
|
|
57
57
|
def find_inside_box(parameters = { })
|
58
58
|
parameters = Utility::ParameterMapper.map parameters, :find_inside_box
|
59
|
-
@resource.
|
59
|
+
@resource.request_json :get, self.path + "/geo/box", :parameters => parameters, :expected_status_code => 200
|
60
60
|
end
|
61
61
|
|
62
62
|
def find_inside_circle(parameters = { })
|
63
63
|
parameters = Utility::ParameterMapper.map parameters, :find_inside_circle
|
64
|
-
@resource.
|
64
|
+
@resource.request_json :get, self.path + "/geo/circle", :parameters => parameters, :expected_status_code => 200
|
65
65
|
end
|
66
66
|
|
67
67
|
def find_inside_haversine(parameters = { })
|
68
68
|
parameters = Utility::ParameterMapper.map parameters, :find_inside_haversine
|
69
|
-
@resource.
|
69
|
+
@resource.request_json :get, self.path + "/geo/haversine", :parameters => parameters, :expected_status_code => 200
|
70
70
|
end
|
71
71
|
|
72
72
|
def find_inside_polygon(parameters = { })
|
73
73
|
parameters = Utility::ParameterMapper.map parameters, :find_inside_polygon
|
74
|
-
@resource.
|
74
|
+
@resource.request_json :get, self.path + "/geo/polygon", :parameters => parameters, :expected_status_code => 200
|
75
75
|
end
|
76
76
|
|
77
77
|
end
|
78
78
|
|
79
79
|
end
|
80
80
|
|
81
|
-
end
|
81
|
+
end
|
@@ -24,8 +24,12 @@ module AllegroGraph
|
|
24
24
|
"#{@catalog.path}/repositories/#{@name}"
|
25
25
|
end
|
26
26
|
|
27
|
-
def
|
28
|
-
@server.
|
27
|
+
def request_http(*arguments)
|
28
|
+
@server.request_http *arguments
|
29
|
+
end
|
30
|
+
|
31
|
+
def request_json(*arguments)
|
32
|
+
@server.request_json *arguments
|
29
33
|
end
|
30
34
|
|
31
35
|
def exists?
|
@@ -33,9 +37,9 @@ module AllegroGraph
|
|
33
37
|
end
|
34
38
|
|
35
39
|
def create!
|
36
|
-
@server.
|
40
|
+
@server.request_http :put, self.path, :expected_status_code => 204
|
37
41
|
true
|
38
|
-
rescue
|
42
|
+
rescue ::Transport::UnexpectedStatusCodeError => error
|
39
43
|
return false if error.status_code == 400
|
40
44
|
raise error
|
41
45
|
end
|
@@ -45,9 +49,9 @@ module AllegroGraph
|
|
45
49
|
end
|
46
50
|
|
47
51
|
def delete!
|
48
|
-
@server.
|
52
|
+
@server.request_http :delete, self.path, :expected_status_code => 200
|
49
53
|
true
|
50
|
-
rescue
|
54
|
+
rescue ::Transport::UnexpectedStatusCodeError => error
|
51
55
|
return false if error.status_code == 400
|
52
56
|
raise error
|
53
57
|
end
|
@@ -57,7 +61,7 @@ module AllegroGraph
|
|
57
61
|
end
|
58
62
|
|
59
63
|
def size
|
60
|
-
response = @server.
|
64
|
+
response = @server.request_http :get, self.path + "/size", :type => :text, :expected_status_code => 200
|
61
65
|
response.to_i
|
62
66
|
end
|
63
67
|
|
@@ -73,7 +77,7 @@ module AllegroGraph
|
|
73
77
|
session.rollback
|
74
78
|
raise error
|
75
79
|
end
|
76
|
-
session.commit
|
80
|
+
session.commit
|
77
81
|
end
|
78
82
|
|
79
83
|
end
|
data/lib/allegro_graph/server.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'logger'
|
1
2
|
|
2
3
|
module AllegroGraph
|
3
4
|
|
@@ -23,21 +24,25 @@ module AllegroGraph
|
|
23
24
|
other.is_a?(self.class) && @host == other.host && @port == other.port
|
24
25
|
end
|
25
26
|
|
26
|
-
def
|
27
|
-
|
27
|
+
def request_http(http_method, path, options = { })
|
28
|
+
::Transport::HTTP.request http_method, (self.url + path), credentials.merge(options)
|
29
|
+
end
|
30
|
+
|
31
|
+
def request_json(http_method, path, options = { })
|
32
|
+
::Transport::JSON.request http_method, self.url + path, credentials.merge(options).merge(:logger => Logger.new(STDOUT))
|
28
33
|
end
|
29
34
|
|
30
35
|
def version
|
31
36
|
{
|
32
|
-
:version => self.
|
33
|
-
:date => self.
|
34
|
-
:revision => self.
|
37
|
+
:version => self.request_http(:get, "/version", :expected_status_code => 200),
|
38
|
+
:date => self.request_http(:get, "/version/date", :expected_status_code => 200),
|
39
|
+
:revision => self.request_http(:get, "/version/revision", :expected_status_code => 200)
|
35
40
|
}
|
36
41
|
end
|
37
42
|
|
38
43
|
def catalogs
|
39
44
|
result = [ @root_catalog ]
|
40
|
-
catalogs = self.
|
45
|
+
catalogs = self.request_json :get, "/catalogs", :expected_status_code => 200
|
41
46
|
catalogs.each do |catalog|
|
42
47
|
id = catalog["id"]
|
43
48
|
result << Catalog.new(self, id.sub(/^\//, "")) unless id == "/"
|
@@ -19,24 +19,27 @@ module AllegroGraph
|
|
19
19
|
""
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
23
|
-
|
22
|
+
def request_http(http_method, path, options = { })
|
23
|
+
::Transport::HTTP.request http_method, self.url + path, credentials.merge(options)
|
24
|
+
end
|
25
|
+
|
26
|
+
def request_json(http_method, path, options = { })
|
27
|
+
::Transport::JSON.request http_method, self.url + path, credentials.merge(options)
|
24
28
|
end
|
25
29
|
|
26
30
|
def commit
|
27
|
-
self.
|
31
|
+
self.request_http :post, "/commit", :expected_status_code => 204
|
28
32
|
true
|
29
33
|
end
|
30
34
|
|
31
35
|
def rollback
|
32
|
-
self.
|
36
|
+
self.request_http :post, "/rollback", :expected_status_code => 204
|
33
37
|
true
|
34
38
|
end
|
35
39
|
|
36
40
|
def self.create(repository)
|
37
|
-
|
38
|
-
url.sub
|
39
|
-
url.sub! /"$/, ""
|
41
|
+
response = repository.request_http :post, repository.path + "/session", :expected_status_code => 200
|
42
|
+
url = response.sub(/^"/, "").sub(/"$/, "")
|
40
43
|
server = repository.server
|
41
44
|
new :url => url, :username => server.username, :password => server.password
|
42
45
|
end
|
@@ -46,7 +49,7 @@ module AllegroGraph
|
|
46
49
|
def credentials
|
47
50
|
{ :auth_type => :basic, :username => @username, :password => @password }
|
48
51
|
end
|
49
|
-
|
52
|
+
|
50
53
|
end
|
51
54
|
|
52
55
|
end
|
@@ -62,7 +62,10 @@ describe "geo-spatial data" do
|
|
62
62
|
:x_max => 20.0,
|
63
63
|
:y_max => 20.0
|
64
64
|
@statements.create "\"test_subject\"", "\"at\"", "\"+10+10\"^^#{@type}"
|
65
|
+
@statement_one = [ "\"test_subject\"", "\"at\"", "\"+10.000000000931323+10.000000000931323\"^^#{@type}"]
|
66
|
+
|
65
67
|
@statements.create "\"another_subject\"", "\"at\"", "\"+15+15\"^^#{@type}"
|
68
|
+
@statement_two = [ "\"another_subject\"", "\"at\"", "\"+15.000000000465661+15.000000000465661\"^^#{@type}"]
|
66
69
|
end
|
67
70
|
|
68
71
|
it "should find objects inside a box" do
|
@@ -72,8 +75,8 @@ describe "geo-spatial data" do
|
|
72
75
|
:y_min => 8.0,
|
73
76
|
:x_max => 11.0,
|
74
77
|
:y_max => 11.0
|
75
|
-
result.should include(
|
76
|
-
result.should_not include(
|
78
|
+
result.should include(@statement_one)
|
79
|
+
result.should_not include(@statement_two)
|
77
80
|
end
|
78
81
|
|
79
82
|
it "should find objects inside a circle" do
|
@@ -82,31 +85,20 @@ describe "geo-spatial data" do
|
|
82
85
|
:x => 9.0,
|
83
86
|
:y => 9.0,
|
84
87
|
:radius => 2.0
|
85
|
-
result.should include(
|
86
|
-
result.should_not include(
|
88
|
+
result.should include(@statement_one)
|
89
|
+
result.should_not include(@statement_two)
|
87
90
|
end
|
88
91
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
:x_min => -100,
|
94
|
-
:y_min => -100,
|
95
|
-
:x_max => 100,
|
96
|
-
:y_max => 100
|
97
|
-
@statements.create "\"test_subject\"", "\"at\"", "\"+1+1\"^^#{@type}"
|
98
|
-
@geometric.create_polygon [ [ 0, -100 ], [ 0, 100 ], [ 100, 100 ], [ 100, -100 ] ],
|
99
|
-
:name => "test_polygon",
|
100
|
-
:type => @type
|
101
|
-
end
|
102
|
-
|
103
|
-
it "should find objects inside that polygon" do
|
104
|
-
result = @statements.find_inside_polygon :type => @type,
|
105
|
-
:predicate => "\"at\"",
|
106
|
-
:polygon_name => "test_polygon"
|
107
|
-
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>"])
|
108
|
-
end
|
92
|
+
it "should find objects inside that polygon" do
|
93
|
+
@geometric.create_polygon [ [ 5.0, 5.0 ], [ 5.0, 12.0 ], [ 12.0, 12.0 ], [ 12.0, 5.0 ] ],
|
94
|
+
:name => "test_polygon",
|
95
|
+
:type => @type
|
109
96
|
|
97
|
+
result = @statements.find_inside_polygon :type => @type,
|
98
|
+
:predicate => "\"at\"",
|
99
|
+
:polygon_name => "test_polygon"
|
100
|
+
result.should include(@statement_one)
|
101
|
+
result.should_not include(@statement_two)
|
110
102
|
end
|
111
103
|
|
112
104
|
end
|
@@ -3,11 +3,9 @@ require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "lib", "a
|
|
3
3
|
|
4
4
|
describe "mapping" do
|
5
5
|
|
6
|
-
use_real_transport!
|
7
|
-
|
8
6
|
before :each do
|
9
7
|
@server = AllegroGraph::Server.new :username => "test", :password => "test"
|
10
|
-
@repository = AllegroGraph::Repository.new @server, "test_repository"
|
8
|
+
@repository = AllegroGraph::Repository.new @server, "test_repository"
|
11
9
|
@repository.create_if_missing!
|
12
10
|
@statements = @repository.statements
|
13
11
|
@mapping = @repository.mapping
|
@@ -16,7 +14,7 @@ describe "mapping" do
|
|
16
14
|
describe "creating a type" do
|
17
15
|
|
18
16
|
it "should return true" do
|
19
|
-
result = @mapping.create "<time>", "<http://www.w3.org/2001/XMLSchema#dateTime>"
|
17
|
+
result = @mapping.create "<http://test.com/time>", "<http://www.w3.org/2001/XMLSchema#dateTime>"
|
20
18
|
result.should be_true
|
21
19
|
end
|
22
20
|
|
@@ -44,7 +42,7 @@ describe "mapping" do
|
|
44
42
|
@statements.create "\"event_three\"", "<happened>", "\"2010-03-29T19:00:00\"^^<time>"
|
45
43
|
end
|
46
44
|
|
47
|
-
it "should
|
45
|
+
it "should find the statements for the given time" do
|
48
46
|
result = @statements.find :predicate => "<happened>", :object => [ "\"2010-03-29T16:30:00\"^^<time>", "\"2010-03-29T18:30:00\"^^<time>" ]
|
49
47
|
result.should include([ "\"event_one\"", "<happened>", "\"2010-03-29T17:00:00Z\"^^<http://www.w3.org/2001/XMLSchema#dateTime>" ])
|
50
48
|
result.should include([ "\"event_two\"", "<happened>", "\"2010-03-29T18:00:00Z\"^^<http://www.w3.org/2001/XMLSchema#dateTime>" ])
|
@@ -3,8 +3,6 @@ require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "lib", "a
|
|
3
3
|
|
4
4
|
describe "query" do
|
5
5
|
|
6
|
-
use_real_transport!
|
7
|
-
|
8
6
|
before :each do
|
9
7
|
@server = AllegroGraph::Server.new :username => "test", :password => "test"
|
10
8
|
@repository = AllegroGraph::Repository.new @server, "test_repository"
|
@@ -11,9 +11,9 @@ describe "server" do
|
|
11
11
|
|
12
12
|
it "should return the server's version" do
|
13
13
|
@server.version.should == {
|
14
|
-
:version => "
|
15
|
-
:date => "
|
16
|
-
:revision => "
|
14
|
+
:version => "4.1.1",
|
15
|
+
:date => "October 23, 2010 16:25:51 GMT-0700",
|
16
|
+
:revision => "internal reversion unknown"
|
17
17
|
}
|
18
18
|
end
|
19
19
|
|
@@ -8,8 +8,8 @@ describe "statements" do
|
|
8
8
|
before :each do
|
9
9
|
@server = AllegroGraph::Server.new :username => "test", :password => "test"
|
10
10
|
@repository = AllegroGraph::Repository.new @server, "test_repository"
|
11
|
-
|
12
11
|
@repository.create_if_missing!
|
12
|
+
|
13
13
|
@statements = @repository.statements
|
14
14
|
end
|
15
15
|
|
@@ -8,6 +8,8 @@ describe "transactions" do
|
|
8
8
|
before :each do
|
9
9
|
@server = AllegroGraph::Server.new :username => "test", :password => "test"
|
10
10
|
@repository = AllegroGraph::Repository.new @server, "test_repository"
|
11
|
+
@repository.create_if_missing!
|
12
|
+
|
11
13
|
@repository.statements.delete
|
12
14
|
end
|
13
15
|
|
@@ -4,6 +4,7 @@ require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "li
|
|
4
4
|
describe AllegroGraph::Catalog do
|
5
5
|
|
6
6
|
before :each do
|
7
|
+
fake_transport!
|
7
8
|
@server = AllegroGraph::Server.new :username => "test", :password => "test"
|
8
9
|
@catalog = AllegroGraph::Catalog.new @server, "test_catalog"
|
9
10
|
end
|
@@ -79,7 +80,7 @@ describe AllegroGraph::Catalog do
|
|
79
80
|
it "should return the catalog's repositories" do
|
80
81
|
@catalog.repositories.should == [ @repository ]
|
81
82
|
end
|
82
|
-
|
83
|
+
|
83
84
|
end
|
84
85
|
|
85
86
|
end
|
@@ -4,6 +4,7 @@ require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "..
|
|
4
4
|
describe AllegroGraph::Proxy::Geometric do
|
5
5
|
|
6
6
|
before :each do
|
7
|
+
fake_transport!
|
7
8
|
@server = AllegroGraph::Server.new :username => "test", :password => "test"
|
8
9
|
@catalog = AllegroGraph::Catalog.new @server, "test_catalog"
|
9
10
|
@repository = AllegroGraph::Repository.new @catalog, "test_repository"
|
@@ -4,6 +4,7 @@ require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "..
|
|
4
4
|
describe AllegroGraph::Proxy::Geometric do
|
5
5
|
|
6
6
|
before :each do
|
7
|
+
fake_transport!
|
7
8
|
@server = AllegroGraph::Server.new :username => "test", :password => "test"
|
8
9
|
@catalog = AllegroGraph::Catalog.new @server, "test_catalog"
|
9
10
|
@repository = AllegroGraph::Repository.new @catalog, "test_repository"
|
@@ -24,7 +25,7 @@ describe AllegroGraph::Proxy::Geometric do
|
|
24
25
|
result = @mapping.create "<time>", "<http://www.w3.org/2001/XMLSchema#dateTime>"
|
25
26
|
result.should be_true
|
26
27
|
end
|
27
|
-
|
28
|
+
|
28
29
|
end
|
29
30
|
|
30
31
|
describe "delete" do
|
@@ -4,6 +4,7 @@ require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "..
|
|
4
4
|
describe AllegroGraph::Proxy::Query do
|
5
5
|
|
6
6
|
before :each do
|
7
|
+
fake_transport!
|
7
8
|
@server = AllegroGraph::Server.new :username => "test", :password => "test"
|
8
9
|
@catalog = AllegroGraph::Catalog.new @server, "test_catalog"
|
9
10
|
@repository = AllegroGraph::Repository.new @catalog, "test_repository"
|
@@ -48,7 +49,7 @@ describe AllegroGraph::Proxy::Query do
|
|
48
49
|
}
|
49
50
|
end
|
50
51
|
|
51
|
-
it "should return the query result" do
|
52
|
+
it "should return the prolog query result" do
|
52
53
|
@query.language = :prolog
|
53
54
|
result = @query.perform "(select (?subject) (q- ?subject !<http://xmlns.com/foaf/0.1/knows> ?object))"
|
54
55
|
result.should == {
|
@@ -4,6 +4,7 @@ require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "..
|
|
4
4
|
describe AllegroGraph::Proxy::Statements do
|
5
5
|
|
6
6
|
before :each do
|
7
|
+
fake_transport!
|
7
8
|
@server = AllegroGraph::Server.new :username => "test", :password => "test"
|
8
9
|
@catalog = AllegroGraph::Catalog.new @server, "test_catalog"
|
9
10
|
@repository = AllegroGraph::Repository.new @catalog, "test_repository"
|
@@ -20,7 +21,7 @@ describe AllegroGraph::Proxy::Statements do
|
|
20
21
|
it "should return the correct path" do
|
21
22
|
@statements.path.should == @repository.path
|
22
23
|
end
|
23
|
-
|
24
|
+
|
24
25
|
end
|
25
26
|
|
26
27
|
describe "create" do
|
@@ -4,9 +4,10 @@ require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "li
|
|
4
4
|
describe AllegroGraph::Repository do
|
5
5
|
|
6
6
|
before :each do
|
7
|
+
fake_transport!
|
7
8
|
@server = AllegroGraph::Server.new :username => "test", :password => "test"
|
8
9
|
@catalog = AllegroGraph::Catalog.new @server, "test_catalog"
|
9
|
-
@repository = AllegroGraph::Repository.new @catalog, "test_repository"
|
10
|
+
@repository = AllegroGraph::Repository.new @catalog, "test_repository"
|
10
11
|
end
|
11
12
|
|
12
13
|
describe "==" do
|
@@ -31,15 +32,28 @@ describe AllegroGraph::Repository do
|
|
31
32
|
|
32
33
|
end
|
33
34
|
|
34
|
-
describe "
|
35
|
+
describe "request_http" do
|
35
36
|
|
36
37
|
before :each do
|
37
|
-
@server.stub
|
38
|
+
@server.stub(:request_http)
|
38
39
|
end
|
39
40
|
|
40
41
|
it "should call the server's request method" do
|
41
|
-
@server.should_receive(:
|
42
|
-
@repository.
|
42
|
+
@server.should_receive(:request_http).with(:get, "/", { })
|
43
|
+
@repository.request_http :get, "/", { }
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "request_json" do
|
49
|
+
|
50
|
+
before :each do
|
51
|
+
@server.stub(:request_json)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should call the server's request method" do
|
55
|
+
@server.should_receive(:request_json).with(:get, "/", { })
|
56
|
+
@repository.request_json :get, "/", { }
|
43
57
|
end
|
44
58
|
|
45
59
|
end
|
@@ -130,6 +144,11 @@ describe AllegroGraph::Repository do
|
|
130
144
|
@repository.delete!.should be_true
|
131
145
|
end
|
132
146
|
|
147
|
+
it "should return true even if a #{Transport::JSON::ParserError} is raised" do
|
148
|
+
@server.stub(:request).and_raise(Transport::JSON::ParserError)
|
149
|
+
@repository.delete!.should be_true
|
150
|
+
end
|
151
|
+
|
133
152
|
end
|
134
153
|
|
135
154
|
context "for a repository that not exists" do
|
@@ -181,7 +200,7 @@ describe AllegroGraph::Repository do
|
|
181
200
|
it "should return the number of statements" do
|
182
201
|
@repository.size.should == 3
|
183
202
|
end
|
184
|
-
|
203
|
+
|
185
204
|
end
|
186
205
|
|
187
206
|
describe "transaction" do
|
@@ -4,6 +4,7 @@ require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "li
|
|
4
4
|
describe AllegroGraph::Server do
|
5
5
|
|
6
6
|
before :each do
|
7
|
+
fake_transport!
|
7
8
|
@server = AllegroGraph::Server.new :username => "test", :password => "test"
|
8
9
|
end
|
9
10
|
|
@@ -21,17 +22,32 @@ describe AllegroGraph::Server do
|
|
21
22
|
|
22
23
|
end
|
23
24
|
|
24
|
-
describe "
|
25
|
+
describe "request_http" do
|
25
26
|
|
26
27
|
before :each do
|
27
|
-
|
28
|
+
Transport::HTTP.stub(:request)
|
28
29
|
end
|
29
30
|
|
30
|
-
it "should perform
|
31
|
-
|
31
|
+
it "should perform a http request" do
|
32
|
+
Transport::HTTP.should_receive(:request).with(
|
32
33
|
:get, "http://localhost:10035/", hash_including(:expected_status_code => 200)
|
33
34
|
).and_return("test" => "test")
|
34
|
-
@server.
|
35
|
+
@server.request_http(:get, "/", :expected_status_code => 200).should == { "test" => "test" }
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "request_json" do
|
41
|
+
|
42
|
+
before :each do
|
43
|
+
Transport::JSON.stub(:request)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should perform a json request" do
|
47
|
+
Transport::JSON.should_receive(:request).with(
|
48
|
+
:get, "http://localhost:10035/", hash_including(:expected_status_code => 200)
|
49
|
+
).and_return("test" => "test")
|
50
|
+
@server.request_json(:get, "/", :expected_status_code => 200).should == { "test" => "test" }
|
35
51
|
end
|
36
52
|
|
37
53
|
end
|
@@ -4,20 +4,36 @@ require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "li
|
|
4
4
|
describe AllegroGraph::Session do
|
5
5
|
|
6
6
|
before :each do
|
7
|
+
fake_transport!
|
7
8
|
@session = AllegroGraph::Session.new :url => "http://session:5555", :username => "test", :password => "test"
|
8
9
|
end
|
9
10
|
|
10
|
-
describe "
|
11
|
+
describe "request_http" do
|
11
12
|
|
12
13
|
before :each do
|
13
|
-
|
14
|
+
Transport::HTTP.stub(:request)
|
14
15
|
end
|
15
16
|
|
16
|
-
it "should perform
|
17
|
-
|
17
|
+
it "should perform a http request" do
|
18
|
+
Transport::HTTP.should_receive(:request).with(
|
18
19
|
:get, "http://session:5555/", hash_including(:expected_status_code => 200)
|
19
20
|
).and_return("test" => "test")
|
20
|
-
@session.
|
21
|
+
@session.request_http(:get, "/", :expected_status_code => 200).should == { "test" => "test" }
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "request_json" do
|
27
|
+
|
28
|
+
before :each do
|
29
|
+
Transport::JSON.stub(:request)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should perform a json request" do
|
33
|
+
Transport::JSON.should_receive(:request).with(
|
34
|
+
:get, "http://session:5555/", hash_including(:expected_status_code => 200)
|
35
|
+
).and_return("test" => "test")
|
36
|
+
@session.request_json(:get, "/", :expected_status_code => 200).should == { "test" => "test" }
|
21
37
|
end
|
22
38
|
|
23
39
|
end
|
@@ -43,17 +59,15 @@ describe AllegroGraph::Session do
|
|
43
59
|
describe "create" do
|
44
60
|
|
45
61
|
before :each do
|
46
|
-
@server =
|
47
|
-
@
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
@repository.stub!(:request).and_return("http://session:5555")
|
52
|
-
@repository.stub!(:server).and_return(@server)
|
62
|
+
@server = mock AllegroGraph::Server, :username => "test", :password => "test"
|
63
|
+
@repository = mock AllegroGraph::Repository,
|
64
|
+
:path => "/repositories/test_repository",
|
65
|
+
:request_http => "http://session:5555",
|
66
|
+
:server => @server
|
53
67
|
end
|
54
68
|
|
55
69
|
it "should request a session" do
|
56
|
-
@repository.should_receive(:
|
70
|
+
@repository.should_receive(:request_http).with(
|
57
71
|
:post, "/repositories/test_repository/session", :expected_status_code => 200
|
58
72
|
).and_return("http://session:5555")
|
59
73
|
AllegroGraph::Session.create @repository
|
data/spec/spec_helper.rb
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
gem 'rspec', '>= 2'
|
3
3
|
require 'rspec'
|
4
|
+
require 'transport/spec'
|
4
5
|
|
5
6
|
require File.join(File.dirname(__FILE__), "..", "lib", "allegro_graph")
|
6
7
|
require File.join(File.dirname(__FILE__), "fake_transport_helper")
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
configuration.before :each do
|
11
|
-
FakeTransport.fake!
|
12
|
-
end
|
9
|
+
def fake_transport!
|
10
|
+
Transport::Spec::Faker.fake! File.join(File.dirname(__FILE__), "fake_transport.yml")
|
13
11
|
end
|
14
12
|
|
15
13
|
def use_real_transport!
|
metadata
CHANGED
@@ -5,19 +5,60 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 3
|
9
|
+
version: 0.1.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
|
-
- Philipp
|
12
|
+
- "Philipp Br\xC3\xBCll"
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-11-
|
17
|
+
date: 2010-11-29 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
|
-
dependencies:
|
20
|
-
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: transport
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 1
|
30
|
+
- 0
|
31
|
+
- 0
|
32
|
+
version: 1.0.0
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rspec
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
segments:
|
44
|
+
- 2
|
45
|
+
version: "2"
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: reek
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
segments:
|
57
|
+
- 1
|
58
|
+
- 2
|
59
|
+
version: "1.2"
|
60
|
+
type: :development
|
61
|
+
version_requirements: *id003
|
21
62
|
description: The gem provides a client for the AllegroGraph 4.x RDF graph database. Features like searching geo-spatial data, type mapping and transactions are supported.
|
22
63
|
email: b.phifty@gmail.com
|
23
64
|
executables: []
|
@@ -36,9 +77,7 @@ files:
|
|
36
77
|
- lib/allegro_graph/catalog.rb
|
37
78
|
- lib/allegro_graph/resource.rb
|
38
79
|
- lib/allegro_graph/utility.rb
|
39
|
-
- lib/allegro_graph/extended_transport.rb
|
40
80
|
- lib/allegro_graph/utility/parameter_mapper.rb
|
41
|
-
- lib/allegro_graph/transport.rb
|
42
81
|
- lib/allegro_graph/session.rb
|
43
82
|
- lib/allegro_graph/proxy.rb
|
44
83
|
- lib/allegro_graph/proxy/query.rb
|
@@ -56,10 +95,8 @@ files:
|
|
56
95
|
- spec/lib/allegro_graph/catalog_spec.rb
|
57
96
|
- spec/lib/allegro_graph/resource_spec.rb
|
58
97
|
- spec/lib/allegro_graph/session_spec.rb
|
59
|
-
- spec/lib/allegro_graph/transport_spec.rb
|
60
98
|
- spec/lib/allegro_graph/utility/parameter_mapper_spec.rb
|
61
99
|
- spec/lib/allegro_graph/repository_spec.rb
|
62
|
-
- spec/lib/allegro_graph/extended_transport_spec.rb
|
63
100
|
- spec/lib/allegro_graph/proxy/mapping_spec.rb
|
64
101
|
- spec/lib/allegro_graph/proxy/query_spec.rb
|
65
102
|
- spec/lib/allegro_graph/proxy/geometric_spec.rb
|
@@ -83,8 +120,10 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
83
120
|
- - ">="
|
84
121
|
- !ruby/object:Gem::Version
|
85
122
|
segments:
|
86
|
-
-
|
87
|
-
|
123
|
+
- 1
|
124
|
+
- 8
|
125
|
+
- 7
|
126
|
+
version: 1.8.7
|
88
127
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
128
|
none: false
|
90
129
|
requirements:
|
@@ -1,84 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
|
3
|
-
module AllegroGraph
|
4
|
-
|
5
|
-
# Extended transport layer for http transfers. Basic authorization and JSON transfers are supported.
|
6
|
-
class ExtendedTransport < Transport
|
7
|
-
|
8
|
-
# The UnexpectedStatusCodeError is raised if the :expected_status_code option is given to
|
9
|
-
# the :request method and the responded status code is different from the expected one.
|
10
|
-
class UnexpectedStatusCodeError < StandardError
|
11
|
-
|
12
|
-
attr_reader :status_code
|
13
|
-
attr_reader :message
|
14
|
-
|
15
|
-
def initialize(status_code, message)
|
16
|
-
@status_code, @message = status_code, message
|
17
|
-
end
|
18
|
-
|
19
|
-
def to_s
|
20
|
-
"#{super} received status code #{self.status_code}" + (@message ? " [#{@message}]" : "")
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
attr_reader :expected_status_code
|
26
|
-
attr_reader :auth_type
|
27
|
-
attr_reader :username
|
28
|
-
attr_reader :password
|
29
|
-
|
30
|
-
def initialize(http_method, url, options = { })
|
31
|
-
super http_method, url, options
|
32
|
-
@expected_status_code = options[:expected_status_code]
|
33
|
-
@auth_type = options[:auth_type]
|
34
|
-
@username = options[:username]
|
35
|
-
@password = options[:password]
|
36
|
-
end
|
37
|
-
|
38
|
-
def perform
|
39
|
-
initialize_headers
|
40
|
-
super
|
41
|
-
check_status_code
|
42
|
-
parse_response
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
|
47
|
-
def initialize_headers
|
48
|
-
@headers["Accept"] = "application/json"
|
49
|
-
end
|
50
|
-
|
51
|
-
def initialize_request
|
52
|
-
super
|
53
|
-
if @auth_type == :basic
|
54
|
-
@request.basic_auth @username, @password
|
55
|
-
elsif !@auth_type.nil?
|
56
|
-
raise NotImplementedError, "the given auth_type [#{@auth_type}] is not implemented"
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def initialize_request_body
|
61
|
-
super
|
62
|
-
if @body
|
63
|
-
@request.body = @body.to_json
|
64
|
-
@request["Content-Type"] = "application/json"
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def check_status_code
|
69
|
-
return unless @expected_status_code
|
70
|
-
response_code = @response.code
|
71
|
-
response_body = @response.body
|
72
|
-
raise UnexpectedStatusCodeError.new(response_code.to_i, response_body) if @expected_status_code.to_s != response_code
|
73
|
-
end
|
74
|
-
|
75
|
-
def parse_response
|
76
|
-
body = @response.body
|
77
|
-
@response = body.nil? ? nil : JSON.parse(body)
|
78
|
-
rescue JSON::ParserError
|
79
|
-
@response = body.to_s
|
80
|
-
end
|
81
|
-
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
@@ -1,100 +0,0 @@
|
|
1
|
-
require 'uri'
|
2
|
-
require 'cgi'
|
3
|
-
require 'net/http'
|
4
|
-
|
5
|
-
module AllegroGraph
|
6
|
-
|
7
|
-
# Common transport layer for http transfers.
|
8
|
-
class Transport
|
9
|
-
|
10
|
-
attr_reader :http_method
|
11
|
-
attr_reader :url
|
12
|
-
attr_reader :options
|
13
|
-
attr_reader :headers
|
14
|
-
attr_reader :parameters
|
15
|
-
attr_reader :body
|
16
|
-
attr_reader :response
|
17
|
-
|
18
|
-
def initialize(http_method, url, options = { })
|
19
|
-
@http_method = http_method
|
20
|
-
@uri = URI.parse url
|
21
|
-
@headers = options[:headers] || { }
|
22
|
-
@parameters = options[:parameters] || { }
|
23
|
-
@body = options[:body]
|
24
|
-
end
|
25
|
-
|
26
|
-
def perform
|
27
|
-
initialize_request_class
|
28
|
-
initialize_request_path
|
29
|
-
initialize_request
|
30
|
-
initialize_request_body
|
31
|
-
perform_request
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
def initialize_request_class
|
37
|
-
request_class_name = @http_method.to_s.capitalize
|
38
|
-
raise NotImplementedError, "the request method #{http_method} is not implemented" unless Net::HTTP.const_defined?(request_class_name)
|
39
|
-
@request_class = Net::HTTP.const_get request_class_name
|
40
|
-
end
|
41
|
-
|
42
|
-
def initialize_request_path
|
43
|
-
@request_path = @uri.path # + (@uri.query ? "?" + @uri.query : "")
|
44
|
-
unless parameter_body?
|
45
|
-
serialize_parameters
|
46
|
-
@request_path += @serialized_parameters
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def serialize_parameters
|
51
|
-
quote_parameters
|
52
|
-
@serialized_parameters = if @parameters.nil? || @parameters.empty?
|
53
|
-
""
|
54
|
-
else
|
55
|
-
"?" + @quoted_parameters.collect do |key, value|
|
56
|
-
value.is_a?(Array) ?
|
57
|
-
value.map{ |element| "#{key}=#{element}" }.join("&") :
|
58
|
-
"#{key}=#{value}"
|
59
|
-
end.join("&")
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def quote_parameters
|
64
|
-
@quoted_parameters = { }
|
65
|
-
@parameters.each do |key, value|
|
66
|
-
quoted_key = CGI.escape(key.to_s)
|
67
|
-
@quoted_parameters[quoted_key] = value.is_a?(Array) ? value.map{ |element| CGI.escape element } : CGI.escape(value)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def initialize_request
|
72
|
-
@request = @request_class.new @request_path, @headers
|
73
|
-
end
|
74
|
-
|
75
|
-
def initialize_request_body
|
76
|
-
if parameter_body?
|
77
|
-
serialize_parameters
|
78
|
-
@request.body = @body ? @body : @serialized_parameters.sub(/^\?/, "")
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def perform_request
|
83
|
-
@response = Net::HTTP.start(@uri.host, @uri.port) do |connection|
|
84
|
-
connection.request @request
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def parameter_body?
|
89
|
-
[ :post, :put ].include? @http_method.to_sym
|
90
|
-
end
|
91
|
-
|
92
|
-
def self.request(http_method, url, options = { })
|
93
|
-
transport = new http_method, url, options
|
94
|
-
transport.perform
|
95
|
-
transport.response
|
96
|
-
end
|
97
|
-
|
98
|
-
end
|
99
|
-
|
100
|
-
end
|
@@ -1,59 +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", "extended_transport"))
|
3
|
-
|
4
|
-
describe AllegroGraph::ExtendedTransport 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
|
-
:auth_type => :basic,
|
15
|
-
:username => "test",
|
16
|
-
:password => "test",
|
17
|
-
:expected_status_code => 200
|
18
|
-
}
|
19
|
-
|
20
|
-
@request = Net::HTTP::Get.new "/", { }
|
21
|
-
@response = Object.new
|
22
|
-
@response.stub!(:code).and_return("200")
|
23
|
-
@response.stub!(:body).and_return("{\"test\":\"test\"}")
|
24
|
-
Net::HTTP.stub!(:start).and_return(@response)
|
25
|
-
end
|
26
|
-
|
27
|
-
def do_request(options = { })
|
28
|
-
AllegroGraph::ExtendedTransport.request @http_method, @url, @options.merge(options)
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should initialize the correct request object" do
|
32
|
-
Net::HTTP::Get.should_receive(:new).with("/", { "Accept" => "application/json" }).and_return(@request)
|
33
|
-
do_request
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should perform the request" do
|
37
|
-
Net::HTTP.should_receive(:start).and_return(@response)
|
38
|
-
do_request
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should return the parsed response" do
|
42
|
-
do_request.should == { "test" => "test" }
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should raise NotImplementedError if the given auth_type is wrong" do
|
46
|
-
lambda do
|
47
|
-
do_request :auth_type => :invalid
|
48
|
-
end.should raise_error(NotImplementedError)
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should raise UnexpectedStatusCodeError if responded status code is wrong" do
|
52
|
-
lambda do
|
53
|
-
do_request :expected_status_code => 201
|
54
|
-
end.should raise_error(AllegroGraph::ExtendedTransport::UnexpectedStatusCodeError)
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
@@ -1,57 +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", "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
|