agraph 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,56 @@
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 "mapping" 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
+ @repository.create_if_missing!
12
+ @statements = @repository.statements
13
+ @mapping = @repository.mapping
14
+ end
15
+
16
+ describe "creating a type" do
17
+
18
+ it "should return true" do
19
+ result = @mapping.create "<time>", "<http://www.w3.org/2001/XMLSchema#dateTime>"
20
+ result.should be_true
21
+ end
22
+
23
+ end
24
+
25
+ describe "creating a type" do
26
+
27
+ before :each do
28
+ @mapping.create "<time>", "<http://www.w3.org/2001/XMLSchema#dateTime>"
29
+ end
30
+
31
+ it "should return true" do
32
+ result = @mapping.delete "<time>"
33
+ result.should be_true
34
+ end
35
+
36
+ end
37
+
38
+ describe "using a type for a range query" do
39
+
40
+ before :each do
41
+ @mapping.create "<time>", "<http://www.w3.org/2001/XMLSchema#dateTime>"
42
+ @statements.create "\"event_one\"", "<happened>", "\"2010-03-29T17:00:00\"^^<time>"
43
+ @statements.create "\"event_two\"", "<happened>", "\"2010-03-29T18:00:00\"^^<time>"
44
+ @statements.create "\"event_three\"", "<happened>", "\"2010-03-29T19:00:00\"^^<time>"
45
+ end
46
+
47
+ it "should findthe statements for the given time" do
48
+ result = @statements.find :predicate => "<happened>", :object => [ "\"2010-03-29T16:30:00\"^^<time>", "\"2010-03-29T18:30:00\"^^<time>" ]
49
+ result.should include([ "\"event_one\"", "<happened>", "\"2010-03-29T17:00:00Z\"^^<http://www.w3.org/2001/XMLSchema#dateTime>" ])
50
+ result.should include([ "\"event_two\"", "<happened>", "\"2010-03-29T18:00:00Z\"^^<http://www.w3.org/2001/XMLSchema#dateTime>" ])
51
+ result.should_not include([ "\"event_three\"", "<happened>", "\"2010-03-29T19:00:00Z\"^^<http://www.w3.org/2001/XMLSchema#dateTime>" ])
52
+ end
53
+
54
+ end
55
+
56
+ end
@@ -0,0 +1,47 @@
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 "query" 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
+
12
+ @repository.create_if_missing!
13
+
14
+ statements = @repository.statements
15
+ statements.create "\"test_subject\"", "<http://xmlns.com/foaf/0.1/knows>", "\"test_object\"", "\"test_context\""
16
+ statements.create "\"another_subject\"", "<http://xmlns.com/foaf/0.1/knows>", "\"another_object\"", "\"test_context\""
17
+ end
18
+
19
+ describe "sparql" do
20
+
21
+ before :each do
22
+ @repository.query.language = :sparql
23
+ end
24
+
25
+ it "should respond to queried data" do
26
+ result = @repository.query.perform "SELECT ?subject WHERE { ?subject <http://xmlns.com/foaf/0.1/knows> ?object . }"
27
+ result["names"].should include("subject")
28
+ result["values"].should include([ "\"another_subject\"" ], [ "\"test_subject\"" ])
29
+ end
30
+
31
+ end
32
+
33
+ describe "prolog" do
34
+
35
+ before :each do
36
+ @repository.query.language = :prolog
37
+ end
38
+
39
+ it "should respond to queried data" do
40
+ result = @repository.query.perform "(select (?subject) (q- ?subject !<http://xmlns.com/foaf/0.1/knows> ?object))"
41
+ result["names"].should include("subject")
42
+ result["values"].should include([ "\"another_subject\"" ], [ "\"test_subject\"" ])
43
+ end
44
+
45
+ end
46
+
47
+ end
@@ -0,0 +1,53 @@
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 "repository" 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 "listing" do
14
+
15
+ before :each do
16
+ @repository.create_if_missing!
17
+ end
18
+
19
+ it "should provide a list of repositories" do
20
+ @server.root_catalog.repositories.should == [ @repository ]
21
+ end
22
+
23
+ end
24
+
25
+ describe "creation" do
26
+
27
+ before :each do
28
+ @repository.delete_if_exists!
29
+ end
30
+
31
+ it "should create the repository" do
32
+ lambda do
33
+ @repository.create!
34
+ end.should change(@repository, :exists?).from(false).to(true)
35
+ end
36
+
37
+ end
38
+
39
+ describe "deletion" do
40
+
41
+ before :each do
42
+ @repository.create_if_missing!
43
+ end
44
+
45
+ it "should delete the repository" do
46
+ lambda do
47
+ @repository.delete!
48
+ end.should change(@repository, :exists?).from(true).to(false)
49
+ end
50
+
51
+ end
52
+
53
+ end
@@ -0,0 +1,20 @@
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 "server" do
5
+
6
+ use_real_transport!
7
+
8
+ before :each do
9
+ @server = AllegroGraph::Server.new :username => "test", :password => "test"
10
+ end
11
+
12
+ it "should return the server's version" do
13
+ @server.version.should == {
14
+ :version => "\"4.0.4\"",
15
+ :date => "\"June 10, 2010 17:37:10 GMT-0700\"",
16
+ :revision => "\"[unknown]\""
17
+ }
18
+ end
19
+
20
+ end
@@ -0,0 +1,67 @@
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 "statements" 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
+
12
+ @repository.create_if_missing!
13
+ @statements = @repository.statements
14
+ end
15
+
16
+ describe "creation" do
17
+
18
+ it "should take a statement" do
19
+ result = @statements.create "\"test_subject\"", "\"test_predicate\"", "\"test_object\"", "\"test_context\""
20
+ result.should be_true
21
+ end
22
+
23
+ end
24
+
25
+ describe "finding" do
26
+
27
+ before :each do
28
+ @statements.delete
29
+ @statements.create "\"test_subject\"", "\"test_predicate\"", "\"test_object\"", "\"test_context\""
30
+ @statements.create "\"another_subject\"", "\"test_predicate\"", "\"another_object\"", "\"test_context\""
31
+ end
32
+
33
+ it "should find all statements" do
34
+ statements = @statements.find
35
+ statements.should == [
36
+ [ "\"test_subject\"", "\"test_predicate\"", "\"test_object\"", "\"test_context\"" ],
37
+ [ "\"another_subject\"", "\"test_predicate\"", "\"another_object\"", "\"test_context\"" ]
38
+ ]
39
+ end
40
+
41
+ it "should find statements by filter options" do
42
+ statements = @statements.find :subject => "\"test_subject\""
43
+ statements.should == [
44
+ [ "\"test_subject\"", "\"test_predicate\"", "\"test_object\"", "\"test_context\"" ]
45
+ ]
46
+ end
47
+
48
+ end
49
+
50
+ describe "deletion" do
51
+
52
+ before :each do
53
+ @statements.create "\"test_subject\"", "\"test_predicate\"", "\"test_object\"", "\"test_context\""
54
+ end
55
+
56
+ it "should delete all statements" do
57
+ lambda do
58
+ @statements.delete :subject => "\"test_subject\"",
59
+ :predicate => "\"test_predicate\"",
60
+ :object => "\"test_object\"",
61
+ :context => "\"test_context\""
62
+ end.should change(@repository, :size)
63
+ end
64
+
65
+ end
66
+
67
+ 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"))
3
+
4
+ describe "transactions" 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
+ @repository.statements.delete
12
+ end
13
+
14
+ it "should commit all changes at once" do
15
+ @repository.transaction do
16
+ statements.create "\"test_subject\"", "<http://xmlns.com/foaf/0.1/knows>", "\"test_object\""
17
+ statements.create "\"another_subject\"", "<http://xmlns.com/foaf/0.1/knows>", "\"another_object\""
18
+ end
19
+
20
+ result = @repository.statements.find
21
+ result.should include([ "\"test_subject\"", "<http://xmlns.com/foaf/0.1/knows>", "\"test_object\"" ])
22
+ result.should include([ "\"another_subject\"", "<http://xmlns.com/foaf/0.1/knows>", "\"another_object\"" ])
23
+ end
24
+
25
+ it "should rollback on error" do
26
+ lambda do
27
+ @repository.transaction do
28
+ statements.create "\"test_subject\"", "<http://xmlns.com/foaf/0.1/knows>", "\"test_object\""
29
+ statements.create "\"another_subject\"", "<http://xmlns.com/foaf/0.1/knows>", "\"another_object\""
30
+ invalid
31
+ end
32
+ end.should raise_error(NameError)
33
+
34
+ result = @repository.statements.find
35
+ result.should_not include([ "\"test_subject\"", "<http://xmlns.com/foaf/0.1/knows>", "\"test_object\"" ])
36
+ result.should_not include([ "\"another_subject\"", "<http://xmlns.com/foaf/0.1/knows>", "\"another_object\"" ])
37
+ end
38
+
39
+ end
@@ -0,0 +1,59 @@
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
@@ -0,0 +1,26 @@
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", "resource"))
3
+
4
+ describe AllegroGraph::Resource do
5
+
6
+ before :each do
7
+ @resource = AllegroGraph::Resource.new
8
+ end
9
+
10
+ it "should the statements proxy" do
11
+ @resource.statements.should be_instance_of(AllegroGraph::Proxy::Statements)
12
+ end
13
+
14
+ it "should the query proxy" do
15
+ @resource.query.should be_instance_of(AllegroGraph::Proxy::Query)
16
+ end
17
+
18
+ it "should the geometric proxy" do
19
+ @resource.geometric.should be_instance_of(AllegroGraph::Proxy::Geometric)
20
+ end
21
+
22
+ it "should the mapping proxy" do
23
+ @resource.mapping.should be_instance_of(AllegroGraph::Proxy::Mapping)
24
+ end
25
+
26
+ end
@@ -18,7 +18,7 @@ describe AllegroGraph::Server do
18
18
  other = AllegroGraph::Server.new :host => "other"
19
19
  @server.should_not == other
20
20
  end
21
-
21
+
22
22
  end
23
23
 
24
24
  describe "request" do
@@ -60,16 +60,4 @@ describe AllegroGraph::Server do
60
60
 
61
61
  end
62
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
63
  end
@@ -55,60 +55,3 @@ describe AllegroGraph::Transport do
55
55
  end
56
56
 
57
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("/", { "Accept" => "application/json" }).and_return(@request)
88
- do_request
89
- end
90
-
91
- it "should perform the request" do
92
- Net::HTTP.should_receive(:start).and_return(@response)
93
- do_request
94
- end
95
-
96
- it "should return the parsed response" do
97
- do_request.should == { "test" => "test" }
98
- end
99
-
100
- it "should raise NotImplementedError if the given auth_type is wrong" do
101
- lambda do
102
- do_request :auth_type => :invalid
103
- end.should raise_error(NotImplementedError)
104
- end
105
-
106
- it "should raise UnexpectedStatusCodeError if responded status code is wrong" do
107
- lambda do
108
- do_request :expected_status_code => 201
109
- end.should raise_error(AllegroGraph::ExtendedTransport::UnexpectedStatusCodeError)
110
- end
111
-
112
- end
113
-
114
- end