Skip to content
Browse files

added federations interface

  • Loading branch information...
1 parent d621397 commit ac1064f617ff4d2b4b0d4c2368824ac9f0ac3dea @phifty committed
View
2 lib/allegro_graph.rb
@@ -1,3 +1,5 @@
require File.expand_path(File.join(File.dirname(__FILE__), "allegro_graph", "server"))
require File.expand_path(File.join(File.dirname(__FILE__), "allegro_graph", "catalog"))
require File.expand_path(File.join(File.dirname(__FILE__), "allegro_graph", "repository"))
+require File.expand_path(File.join(File.dirname(__FILE__), "allegro_graph", "session"))
+require File.expand_path(File.join(File.dirname(__FILE__), "allegro_graph", "federation"))
View
69 lib/allegro_graph/federation.rb
@@ -0,0 +1,69 @@
+require File.join(File.dirname(__FILE__), "transport")
+require File.join(File.dirname(__FILE__), "proxy", "statements")
+require File.join(File.dirname(__FILE__), "proxy", "query")
+require File.join(File.dirname(__FILE__), "proxy", "geo")
+
+module AllegroGraph
+
+ class Federation
+
+ attr_reader :server
+ attr_accessor :name
+ attr_accessor :repository_names
+ attr_accessor :repository_urls
+
+ attr_reader :statements
+ attr_reader :query
+ attr_reader :geo
+
+ def initialize(server, name, options = { })
+ @server, @name = server, name
+
+ @repository_names = options[:repository_names]
+ @repository_urls = options[:repository_urls]
+
+ @statements = Proxy::Statements.new self
+ @query = Proxy::Query.new self
+ @geo = Proxy::Geo.new self
+ end
+
+ def ==(other)
+ other.is_a?(self.class) && @server == other.server && @name == other.name
+ end
+
+ def path
+ "/federated/#{@name}"
+ end
+
+ def request(http_method, path, options = { })
+ @server.request http_method, path, options
+ end
+
+ def exists?
+ @server.federations.include? self
+ end
+
+ def create!
+ parameters = { }
+ parameters.merge! :repo => @repository_names if @repository_names
+ parameters.merge! :url => @repository_urls if @repository_urls
+ @server.request :put, self.path, :parameters => parameters, :expected_status_code => 204
+ true
+ end
+
+ def create_if_missing!
+ create! unless exists?
+ end
+
+ def delete!
+ @server.request :delete, self.path, :expected_status_code => 204
+ true
+ end
+
+ def delete_if_exists!
+ delete! if exists?
+ end
+
+ end
+
+end
View
6 lib/allegro_graph/server.rb
@@ -1,5 +1,6 @@
require File.join(File.dirname(__FILE__), "transport")
require File.join(File.dirname(__FILE__), "catalog")
+require File.join(File.dirname(__FILE__), "federation")
module AllegroGraph
@@ -47,6 +48,11 @@ def catalogs
result
end
+ def federations
+ federations = self.request :get, "/federated", :expected_status_code => 200
+ federations.map { |federation| Federation.new self, federation["id"] }
+ end
+
def url
"http://#{@host}:#{@port}"
end
View
27 spec/fake_transport.yml
@@ -54,6 +54,33 @@
:body: ""
-
:http_method: "get"
+ :url: "http://localhost:10035/federated"
+ :response:
+ :code: "200"
+ :body:
+ -
+ "uri": "http://localhost:10035/federated/test_federation"
+ "id": "test_federation"
+ "title": "test_federation"
+ "readable": true
+ "writable": false
+-
+ :http_method: "put"
+ :url: "http://localhost:10035/federated/test_federation"
+ :parameters:
+ :repo: [ "test_repository" ]
+ :url: [ "http://username:password@server:10035/repositories/another" ]
+ :response:
+ :code: "204"
+ :body: ""
+-
+ :http_method: "delete"
+ :url: "http://localhost:10035/federated/test_federation"
+ :response:
+ :code: "204"
+ :body: ""
+-
+ :http_method: "get"
:url: "http://localhost:10035/catalogs/test_catalog/repositories"
:response:
:code: "200"
View
23 spec/integration/basic_spec.rb
@@ -277,4 +277,27 @@
end
+ describe "federations" do
+
+ before :each do
+ @federation = AllegroGraph::Federation.new @server, "test_federation", :repository_names => [ @repository.name ]
+ end
+
+ it "should create a federation" do
+ @federation.delete_if_exists!
+ @federation.create!.should be_true
+ end
+
+ it "should list the federations" do
+ @federation.create_if_missing!
+ @server.federations.should include(@federation)
+ end
+
+ it "should delete a federation" do
+ @federation.create_if_missing!
+ @federation.delete!.should be_true
+ end
+
+ end
+
end
View
113 spec/lib/allegro_graph/federation_spec.rb
@@ -0,0 +1,113 @@
+require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper"))
+require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "lib", "allegro_graph", "federation"))
+
+describe AllegroGraph::Federation do
+
+ before :each do
+ @server = AllegroGraph::Server.new :username => "test", :password => "test"
+ @federation = AllegroGraph::Federation.new @server,
+ "test_federation",
+ :repository_names => [ "test_repository" ],
+ :repository_urls => [ "http://username:password@server:10035/repositories/another" ]
+ end
+
+ describe "==" do
+
+ it "should be true when comparing two equal federations" do
+ other = AllegroGraph::Federation.new @server, "test_federation"
+ @federation.should == other
+ end
+
+ it "should be false when comparing two different federations" do
+ other = AllegroGraph::Federation.new @server, "other_federationy"
+ @federation.should_not == other
+ end
+
+ end
+
+ describe "request" do
+
+ before :each do
+ @server.stub!(:request)
+ end
+
+ it "should call the server's request method" do
+ @server.should_receive(:request).with(:get, "/", { })
+ @federation.request :get, "/"
+ end
+
+ end
+
+ describe "exists?" do
+
+ context "for a federation that already exists" do
+
+ it "should return true" do
+ @federation.exists?.should be_true
+ end
+
+ end
+
+ context "for a federation that not exists" do
+
+ before :each do
+ @federation.name = "not_existing"
+ end
+
+ it "should return false" do
+ @federation.exists?.should be_false
+ end
+
+ end
+
+ end
+
+ describe "create!" do
+
+ it "should return true" do
+ @federation.create!.should be_true
+ end
+
+ end
+
+ describe "create_if_missing!" do
+
+ it "should do nothing if the federation already exists" do
+ @federation.stub!(:exists?).and_return(true)
+ @federation.should_not_receive(:create!)
+ @federation.create_if_missing!
+ end
+
+ it "should call create! if the federation doesn't exists" do
+ @federation.stub!(:exists?).and_return(false)
+ @federation.should_receive(:create!)
+ @federation.create_if_missing!
+ end
+
+ end
+
+ describe "delete!" do
+
+ it "should return true" do
+ @federation.delete!.should be_true
+ end
+
+ end
+
+ describe "delete_if_exists!" do
+
+ it "should call delete! if the federation already exists" do
+ @federation.stub!(:exists?).and_return(true)
+ @federation.should_receive(:delete!)
+ @federation.delete_if_exists!
+ end
+
+ it "should do nothing if the federation doesn't exists" do
+ @federation.stub!(:exists?).and_return(false)
+ @federation.should_not_receive(:delete!)
+ @federation.delete_if_exists!
+ end
+
+ end
+
+end
View
12 spec/lib/allegro_graph/server_spec.rb
@@ -60,4 +60,16 @@
end
+ describe "federations" do
+
+ before :each do
+ @federation = AllegroGraph::Federation.new @server, "test_federation"
+ end
+
+ it "should return the federations of the server" do
+ @server.federations.should include(@federation)
+ end
+
+ end
+
end

0 comments on commit ac1064f

Please sign in to comment.
Something went wrong with that request. Please try again.