diff --git a/Documentation/Examples/api-blueprints-change-edge b/Documentation/Examples/api-blueprints-change-edge new file mode 100644 index 0000000000..4f13b762c1 --- /dev/null +++ b/Documentation/Examples/api-blueprints-change-edge @@ -0,0 +1,21 @@ +> curl --data @- -X PUT --dump - http://localhost:8529/_api/blueprints/edge/edge1?graph=graph1 +{"optional2" : "val2"} + +HTTP/1.1 200 OK +content-type: application/json; charset=utf-8 + +{ + "edge": { + "_id": "82564582/85317094", + "_rev": 85906918, + "_key": "85317094", + "_bidirectional": false, + "_from": "81778150/84989414", + "_to": "81778150/84792806", + "$label": null, + "$id": "edge1", + "optional2": "val2" + }, + "error": false, + "code": 200 +} diff --git a/Documentation/Examples/api-blueprints-change-vertex b/Documentation/Examples/api-blueprints-change-vertex new file mode 100644 index 0000000000..e6a65f6e63 --- /dev/null +++ b/Documentation/Examples/api-blueprints-change-vertex @@ -0,0 +1,17 @@ +> curl --data @- -X PUT --dump - http://localhost:8529/_api/blueprints/vertex/v1?graph=graph1 +{"optional1" : "val2"} + +HTTP/1.1 200 OK +content-type: application/json; charset=utf-8 + +{ + "vertex": { + "_id": "39572966/42653158", + "_rev": 42849766, + "_key": "42653158", + "$id": "v1", + "optional1": "val2" + }, + "error": false, + "code": 200 +} diff --git a/Documentation/Examples/api-blueprints-create-edge b/Documentation/Examples/api-blueprints-create-edge new file mode 100644 index 0000000000..3fa55f2b28 --- /dev/null +++ b/Documentation/Examples/api-blueprints-create-edge @@ -0,0 +1,21 @@ +> curl --data @- -X POST --dump - http://localhost:8529/_api/blueprints/edge?graph=graph1 +{"$id" : "edge1", "_from" : "vert2", "_to" : "vert1", "optional1" : "val1"} + +HTTP/1.1 200 OK +content-type: application/json; charset=utf-8 + +{ + "edge": { + "_id": "54842854/57595366", + "_rev": 57595366, + "_key": "57595366", + "_bidirectional": false, + "_from": "54056422/57267686", + "_to": "54056422/57071078", + "$label": null, + "$id": "edge1", + "optional1": "val1" + }, + "error": false, + "code": 200 +} diff --git a/Documentation/Examples/api-blueprints-create-graph b/Documentation/Examples/api-blueprints-create-graph new file mode 100644 index 0000000000..d6d9736d45 --- /dev/null +++ b/Documentation/Examples/api-blueprints-create-graph @@ -0,0 +1,20 @@ +> curl --data @- -X POST --dump - http://localhost:8529/_api/blueprints/graph +{"name" : "graph1", "verticesName" : "v", "edgesName" : "e"} + +HTTP/1.1 200 OK +content-type: application/json; charset=utf-8 + +{ + "graph": { + "_id": "1849955/7686033", + "_rev": 7686033, + "_key": "7686033", + "vertices": 5523345, + "edges": 6309777, + "name": "graph1", + "verticesName": "v", + "edgesName": "e" + }, + "error": false, + "code": 200 +} diff --git a/Documentation/Examples/api-blueprints-create-vertex b/Documentation/Examples/api-blueprints-create-vertex new file mode 100644 index 0000000000..9cd8e82d8e --- /dev/null +++ b/Documentation/Examples/api-blueprints-create-vertex @@ -0,0 +1,18 @@ +> curl --data @- -X POST --dump - http://localhost:8529/_api/blueprints/vertex?graph=graph1 +{"$id" : "v1", "optional1" : "val1", "optional2" : "val2"} + +HTTP/1.1 200 OK +content-type: application/json; charset=utf-8 + +{ + "vertex": { + "_id": "21186449/24332177", + "_rev": 24332177, + "_key": "24332177", + "$id": "v1", + "optional1": "val1", + "optional2": "val2" + }, + "error": false, + "code": 200 +} diff --git a/Documentation/Examples/api-blueprints-delete-edge b/Documentation/Examples/api-blueprints-delete-edge new file mode 100644 index 0000000000..5b85984b7e --- /dev/null +++ b/Documentation/Examples/api-blueprints-delete-edge @@ -0,0 +1,10 @@ +> curl -X DELETE --dump - http://localhost:8529/_api/blueprints/edge/edge1?graph=graph1 + +HTTP/1.1 200 OK +content-type: application/json; charset=utf-8 + +{ + "deleted": true, + "error": false, + "code": 200 +} diff --git a/Documentation/Examples/api-blueprints-delete-graph b/Documentation/Examples/api-blueprints-delete-graph new file mode 100644 index 0000000000..66de0e9652 --- /dev/null +++ b/Documentation/Examples/api-blueprints-delete-graph @@ -0,0 +1,10 @@ +> curl -X DELETE --dump - http://localhost:8529/_api/blueprints/graph/graph1 + +HTTP/1.1 200 OK +content-type: application/json; charset=utf-8 + +{ + "deleted": true, + "error": false, + "code": 200 +} diff --git a/Documentation/Examples/api-blueprints-delete-vertex b/Documentation/Examples/api-blueprints-delete-vertex new file mode 100644 index 0000000000..e8051499b9 --- /dev/null +++ b/Documentation/Examples/api-blueprints-delete-vertex @@ -0,0 +1,10 @@ +> curl -X DELETE --dump - http://localhost:8529/_api/blueprints/vertex/46519782/49599974?graph=graph1 + +HTTP/1.1 200 OK +content-type: application/json; charset=utf-8 + +{ + "deleted": true, + "error": false, + "code": 200 +} diff --git a/Documentation/Examples/api-blueprints-get-edge b/Documentation/Examples/api-blueprints-get-edge new file mode 100644 index 0000000000..8708affd06 --- /dev/null +++ b/Documentation/Examples/api-blueprints-get-edge @@ -0,0 +1,20 @@ +> curl -X GET --dump - http://localhost:8529/_api/blueprints/edge/edge1?graph=graph1 + +HTTP/1.1 200 OK +content-type: application/json; charset=utf-8 + +{ + "edge": { + "_id": "74569190/77321702", + "_rev": 77321702, + "_key": "77321702", + "_bidirectional": false, + "_from": "73782758/76994022", + "_to": "73782758/76797414", + "$label": null, + "$id": "edge1", + "optional1": "val1" + }, + "error": false, + "code": 200 +} diff --git a/Documentation/Examples/api-blueprints-get-edges b/Documentation/Examples/api-blueprints-get-edges new file mode 100644 index 0000000000..6eea62e8b1 --- /dev/null +++ b/Documentation/Examples/api-blueprints-get-edges @@ -0,0 +1,33 @@ +> curl -X GET --dump - http://localhost:8529/_api/blueprints/edges?graph=graph1 + +HTTP/1.1 200 OK +content-type: application/json; charset=utf-8 + +{ + "edges": [ + { + "_id": "94950886/97834470", + "_rev": 97834470, + "_key": "97834470", + "_bidirectional": false, + "_from": "94164454/97310182", + "_to": "94164454/97506790", + "$label": null, + "$id": "edge1", + "optional1": "val1a" + }, + { + "_id": "94950886/98227686", + "_rev": 98227686, + "_key": "98227686", + "_bidirectional": false, + "_from": "94164454/97506790", + "_to": "94164454/97572326", + "$label": null, + "$id": "edge2", + "optional1": "val1b" + } + ], + "error": false, + "code": 200 +} diff --git a/Documentation/Examples/api-blueprints-get-edges-by-vertex b/Documentation/Examples/api-blueprints-get-edges-by-vertex new file mode 100644 index 0000000000..54fc5fd9fe --- /dev/null +++ b/Documentation/Examples/api-blueprints-get-edges-by-vertex @@ -0,0 +1,22 @@ +> curl -X GET --dump - http://localhost:8529/_api/blueprints/edges?graph=graph1&vertex=id1 + +HTTP/1.1 200 OK +content-type: application/json; charset=utf-8 + +{ + "edges": [ + { + "_id": "99145190/102028774", + "_rev": 102028774, + "_key": "102028774", + "_bidirectional": false, + "_from": "98358758/101504486", + "_to": "98358758/101701094", + "$label": null, + "$id": "edge1", + "optional1": "val1a" + } + ], + "error": false, + "code": 200 +} diff --git a/Documentation/Examples/api-blueprints-get-graph b/Documentation/Examples/api-blueprints-get-graph new file mode 100644 index 0000000000..536bea3d49 --- /dev/null +++ b/Documentation/Examples/api-blueprints-get-graph @@ -0,0 +1,19 @@ +> curl -X GET --dump - http://localhost:8529/_api/blueprints/graph/graph1 + +HTTP/1.1 200 OK +content-type: application/json; charset=utf-8 + +{ + "graph": { + "_id": "1849955/16992145", + "_rev": 16992145, + "_key": "16992145", + "vertices": 15157137, + "edges": 15943569, + "name": "graph1", + "verticesName": "v", + "edgesName": "e" + }, + "error": false, + "code": 200 +} diff --git a/Documentation/Examples/api-blueprints-get-graph-by-id b/Documentation/Examples/api-blueprints-get-graph-by-id new file mode 100644 index 0000000000..6aad3db9e8 --- /dev/null +++ b/Documentation/Examples/api-blueprints-get-graph-by-id @@ -0,0 +1,19 @@ +> curl -X GET --dump - http://localhost:8529/_api/blueprints/graph/1849955/16992145 + +HTTP/1.1 200 OK +content-type: application/json; charset=utf-8 + +{ + "graph": { + "_id": "1849955/16992145", + "_rev": 16992145, + "_key": "16992145", + "vertices": 15157137, + "edges": 15943569, + "name": "graph1", + "verticesName": "v", + "edgesName": "e" + }, + "error": false, + "code": 200 +} diff --git a/Documentation/Examples/api-blueprints-get-in-edges-by-vertex b/Documentation/Examples/api-blueprints-get-in-edges-by-vertex new file mode 100644 index 0000000000..66e5d36b46 --- /dev/null +++ b/Documentation/Examples/api-blueprints-get-in-edges-by-vertex @@ -0,0 +1,22 @@ +> curl -X GET --dump - http://localhost:8529/_api/blueprints/edges?graph=graph1&vertex=id2&type=in + +HTTP/1.1 200 OK +content-type: application/json; charset=utf-8 + +{ + "edges": [ + { + "_id": "103339494/106223078", + "_rev": 106223078, + "_key": "106223078", + "_bidirectional": false, + "_from": "102553062/105698790", + "_to": "102553062/105895398", + "$label": null, + "$id": "edge1", + "optional1": "val1a" + } + ], + "error": false, + "code": 200 +} diff --git a/Documentation/Examples/api-blueprints-get-out-edges-by-vertex b/Documentation/Examples/api-blueprints-get-out-edges-by-vertex new file mode 100644 index 0000000000..002531623d --- /dev/null +++ b/Documentation/Examples/api-blueprints-get-out-edges-by-vertex @@ -0,0 +1,22 @@ +> curl -X GET --dump - http://localhost:8529/_api/blueprints/edges?graph=graph1&vertex=id2&type=out + +HTTP/1.1 200 OK +content-type: application/json; charset=utf-8 + +{ + "edges": [ + { + "_id": "107533798/110810598", + "_rev": 110810598, + "_key": "110810598", + "_bidirectional": false, + "_from": "106747366/110089702", + "_to": "106747366/110155238", + "$label": null, + "$id": "edge2", + "optional1": "val1b" + } + ], + "error": false, + "code": 200 +} diff --git a/Documentation/Examples/api-blueprints-get-vertex b/Documentation/Examples/api-blueprints-get-vertex new file mode 100644 index 0000000000..eb98ca89af --- /dev/null +++ b/Documentation/Examples/api-blueprints-get-vertex @@ -0,0 +1,17 @@ +> curl -X GET --dump - http://localhost:8529/_api/blueprints/vertex/v1?graph=graph1 + +HTTP/1.1 200 OK +content-type: application/json; charset=utf-8 + +{ + "vertex": { + "_id": "28133265/31278993", + "_rev": 31278993, + "_key": "31278993", + "$id": "v1", + "optional1": "val1", + "optional2": "val2" + }, + "error": false, + "code": 200 +} diff --git a/Documentation/Examples/api-blueprints-get-vertex-by-id b/Documentation/Examples/api-blueprints-get-vertex-by-id new file mode 100644 index 0000000000..d8c9a4a4cf --- /dev/null +++ b/Documentation/Examples/api-blueprints-get-vertex-by-id @@ -0,0 +1,17 @@ +> curl -X GET --dump - http://localhost:8529/_api/blueprints/vertex/28133265/31278993?graph=graph1 + +HTTP/1.1 200 OK +content-type: application/json; charset=utf-8 + +{ + "vertex": { + "_id": "28133265/31278993", + "_rev": 31278993, + "_key": "31278993", + "$id": "v1", + "optional1": "val1", + "optional2": "val2" + }, + "error": false, + "code": 200 +} diff --git a/Documentation/Examples/api-blueprints-get-vertices b/Documentation/Examples/api-blueprints-get-vertices new file mode 100644 index 0000000000..cb4267400c --- /dev/null +++ b/Documentation/Examples/api-blueprints-get-vertices @@ -0,0 +1,50 @@ +> curl -X GET --dump - http://localhost:8529/_api/blueprints/vertices?graph=graph1 + +HTTP/1.1 200 OK +content-type: application/json; charset=utf-8 + +{ + "vertices": [ + { + "_id": "49927654/53401062", + "_rev": 53401062, + "_key": "53401062", + "$id": null, + "optional1": "val1", + "optional2": "val2" + }, + { + "_id": "49927654/53073382", + "_rev": 53073382, + "_key": "53073382", + "$id": null, + "optional1": "val1", + "optional2": "val2" + }, + { + "_id": "49927654/53335526", + "_rev": 53335526, + "_key": "53335526", + "$id": null, + "optional1": "val1", + "optional2": "val2" + }, + { + "_id": "49927654/53269990", + "_rev": 53269990, + "_key": "53269990", + "$id": null, + "optional1": "val1", + "optional2": "val2" + }, + { + "_id": "49927654/53532134", + "_rev": 53532134, + "_key": "53532134", + "$id": "id1", + "optional2": "val2" + } + ], + "error": false, + "code": 200 +} diff --git a/Documentation/Makefile.files b/Documentation/Makefile.files index 90f70da2ab..2b54393064 100644 --- a/Documentation/Makefile.files +++ b/Documentation/Makefile.files @@ -10,6 +10,7 @@ DOXYGEN = \ Doxygen/js/actions/system/api-collection.c \ + Doxygen/js/actions/system/api-blueprints.c \ Doxygen/js/actions/system/api-cursor.c \ Doxygen/js/actions/system/api-edges.c \ Doxygen/js/actions/system/api-explain.c \ @@ -46,6 +47,7 @@ WIKI = \ Graphs \ Home \ HttpBatch \ + HttpBlueprints \ HttpCollection \ HttpCursor \ HttpImport \ diff --git a/UnitTests/HttpInterface/api-blueprints-spec.rb b/UnitTests/HttpInterface/api-blueprints-spec.rb new file mode 100644 index 0000000000..641760a069 --- /dev/null +++ b/UnitTests/HttpInterface/api-blueprints-spec.rb @@ -0,0 +1,646 @@ +# coding: utf-8 + +require 'rspec' +require './arangodb.rb' + + +describe ArangoDB do + prefix = "api-blueprints" + + vertex_collection = "v" + edge_collection = "e" + graph_name = "graph1" + + context "testing blueprints methods:" do + + def truncate_collection (prefix, name) + cmd = "/_api/collection/#{name}/truncate" + ArangoDB.log_put("#{prefix}", cmd) + end + +################################################################################ +## checking graph responses +################################################################################ + + context "checks blueprints graph requests" do + before do + #ArangoDB.create_collection( edge_collection , 0, 3) + #ArangoDB.create_collection( vertex_collection , 0, 2) + truncate_collection(prefix, "_graphs") + end + + after do + truncate_collection(prefix, "_graphs") + ArangoDB.drop_collection( vertex_collection ) + ArangoDB.drop_collection( edge_collection ) + end + + it "checks create graph" do + cmd = "/_api/blueprints/graph" + body = "{\"name\" : \"#{graph_name}\", \"verticesName\" : \"#{vertex_collection}\", \"edgesName\" : \"#{edge_collection}\"}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(200) + doc.parsed_response['graph']['name'].should eq("#{graph_name}") + end + + it "checks create graph with wrong edges collection" do + ArangoDB.create_collection( edge_collection , 0, 2) + + cmd = "/_api/blueprints/graph" + body = "{\"name\" : \"#{graph_name}\", \"verticesName\" : \"#{vertex_collection}\", \"edgesName\" : \"#{edge_collection}\"}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + + doc.code.should eq(400) + doc.parsed_response['error'].should eq(true) + doc.parsed_response['code'].should eq(400) + doc.parsed_response['errorNum'].should eq(1902) + end + + it "checks (re)create graph" do + cmd = "/_api/blueprints/graph" + body = "{\"name\" : \"#{graph_name}\", \"verticesName\" : \"#{vertex_collection}\", \"edgesName\" : \"#{edge_collection}\"}" + doc1 = ArangoDB.log_post("#{prefix}", cmd, :body => body) + + doc1.code.should eq(200) + + doc2 = ArangoDB.log_post("#{prefix}", cmd, :body => body) + + doc2.code.should eq(200) + + doc1.parsed_response['graph']['_id'].should eq(doc2.parsed_response['graph']['_id']) + end + + it "checks create and get graph" do + cmd = "/_api/blueprints/graph" + body = "{\"name\" : \"#{graph_name}\", \"verticesName\" : \"#{vertex_collection}\", \"edgesName\" : \"#{edge_collection}\"}" + doc1 = ArangoDB.log_post("#{prefix}", cmd, :body => body) + g_id = doc1.parsed_response['graph']['_id'] + + doc1.code.should eq(200) + + cmd = "/_api/blueprints/graph/#{graph_name}" + doc2 = ArangoDB.log_get("#{prefix}", cmd) + + doc2.code.should eq(200) + doc2.parsed_response['graph']['_id'].should eq(g_id) + + cmd = "/_api/blueprints/graph/#{g_id}" + doc3 = ArangoDB.log_get("#{prefix}", cmd) + + doc3.code.should eq(200) + doc3.parsed_response['graph']['_id'].should eq(g_id) + end + + it "checks create and delete graph" do + # create + cmd = "/_api/blueprints/graph" + body = "{\"name\" : \"#{graph_name}\", \"verticesName\" : \"#{vertex_collection}\", \"edgesName\" : \"#{edge_collection}\"}" + doc1 = ArangoDB.log_post("#{prefix}", cmd, :body => body) + doc1.code.should eq(200) + + # delete + cmd = "/_api/blueprints/graph/#{graph_name}" + doc2 = ArangoDB.log_delete("#{prefix}", cmd) + doc2.code.should eq(200) + doc2.parsed_response['deleted'].should eq(true) + + # check + doc3 = ArangoDB.log_get("#{prefix}", cmd) + doc3.code.should eq(400) + end + + end + +################################################################################ +## checking vertex responses +################################################################################ + + context "checks blueprints vertex requests" do + before do + truncate_collection(prefix, "_graphs") + cmd = "/_api/blueprints/graph" + body = "{\"name\" : \"#{graph_name}\", \"verticesName\" : \"#{vertex_collection}\", \"edgesName\" : \"#{edge_collection}\"}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + end + + after do + truncate_collection(prefix, "_graphs") + ArangoDB.drop_collection( vertex_collection ) + ArangoDB.drop_collection( edge_collection ) + end + + it "checks create vertex with \$id" do + cmd = "/_api/blueprints/vertex?graph=#{graph_name}" + body = "{\"\$id\" : \"v1\", \"optional1\" : \"val1\", \"optional2\" : \"val2\"}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(200) + doc.parsed_response['vertex']['$id'].should eq("v1") + doc.parsed_response['vertex']['optional1'].should eq("val1") + end + + it "checks create second vertex with \$id" do + cmd = "/_api/blueprints/vertex?graph=#{graph_name}" + body = "{\"\$id\" : \"double_id\", \"optional1\" : \"val1\", \"optional2\" : \"val2\"}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(200) + + doc2 = ArangoDB.log_post("#{prefix}", cmd, :body => body) + doc2.code.should eq(400) + doc2.parsed_response['error'].should eq(true) + doc2.parsed_response['code'].should eq(400) + end + + it "checks get vertex by \$id" do + cmd = "/_api/blueprints/vertex?graph=#{graph_name}" + body = "{\"\$id\" : \"v1\", \"optional1\" : \"val1\", \"optional2\" : \"val2\"}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(200) + doc.parsed_response['vertex']['$id'].should eq("v1") + doc.parsed_response['vertex']['optional1'].should eq("val1") + + cmd = "/_api/blueprints/vertex/v1?graph=#{graph_name}" + doc2 = ArangoDB.log_get("#{prefix}", cmd) + doc2.code.should eq(200) + doc2.parsed_response['error'].should eq(false) + doc2.parsed_response['code'].should eq(200) + doc2.parsed_response['vertex']['optional1'].should eq(doc.parsed_response['vertex']['optional1']) + + _id = doc2.parsed_response['vertex']['_id']; + cmd = "/_api/blueprints/vertex/#{_id}?graph=#{graph_name}" + doc3 = ArangoDB.log_get("#{prefix}", cmd) + doc3.code.should eq(200) + doc3.parsed_response['error'].should eq(false) + doc3.parsed_response['code'].should eq(200) + doc3.parsed_response['vertex']['optional1'].should eq(doc.parsed_response['vertex']['optional1']) + end + + it "checks get vertex by wrong \$id" do + cmd = "/_api/blueprints/vertex/vv11?graph=#{graph_name}" + doc = ArangoDB.log_get("#{prefix}", cmd) + doc.code.should eq(400) + doc.parsed_response['error'].should eq(true) + doc.parsed_response['code'].should eq(400) + end + + it "checks update vertex by \$id" do + cmd = "/_api/blueprints/vertex?graph=#{graph_name}" + body = "{\"\$id\" : \"v1\", \"optional1\" : \"val1\"}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(200) + doc.parsed_response['vertex']['$id'].should eq("v1") + doc.parsed_response['vertex']['optional1'].should eq("val1") + + cmd = "/_api/blueprints/vertex/v1?graph=#{graph_name}" + doc2 = ArangoDB.log_get("#{prefix}", cmd) + doc2.code.should eq(200) + doc2.parsed_response['error'].should eq(false) + doc2.parsed_response['code'].should eq(200) + doc2.parsed_response['vertex']['optional1'].should eq(doc.parsed_response['vertex']['optional1']) + + _id = doc2.parsed_response['vertex']['_id']; + cmd = "/_api/blueprints/vertex/#{_id}?graph=#{graph_name}" + body = "{\"\$id\" : \"v1\", \"optional1\" : \"val2\"}" + doc3 = ArangoDB.log_put("#{prefix}", cmd, :body => body) + doc3.code.should eq(200) + doc3.parsed_response['error'].should eq(false) + doc3.parsed_response['code'].should eq(200) + doc3.parsed_response['vertex']['optional1'].should eq("val2") + + cmd = "/_api/blueprints/vertex/v1?graph=#{graph_name}" + doc2 = ArangoDB.log_get("#{prefix}", cmd) + doc2.code.should eq(200) + doc2.parsed_response['error'].should eq(false) + doc2.parsed_response['code'].should eq(200) + doc2.parsed_response['vertex']['optional1'].should eq("val2") + end + + it "checks update vertex" do + cmd = "/_api/blueprints/vertex?graph=#{graph_name}" + body = "{\"optional1\" : \"val1\", \"optional2\" : \"val2\"}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(200) + doc.parsed_response['vertex']['$id'].should eq(nil) + doc.parsed_response['vertex']['optional1'].should eq("val1") + doc.parsed_response['vertex']['optional2'].should eq("val2") + _id = doc.parsed_response['vertex']['_id']; + + cmd = "/_api/blueprints/vertex/#{_id}?graph=#{graph_name}" + doc2 = ArangoDB.log_get("#{prefix}", cmd) + doc2.code.should eq(200) + doc2.parsed_response['error'].should eq(false) + doc2.parsed_response['code'].should eq(200) + doc2.parsed_response['vertex']['optional1'].should eq(doc.parsed_response['vertex']['optional1']) + + cmd = "/_api/blueprints/vertex/#{_id}?graph=#{graph_name}" + body = "{\"optional1\" : \"val2\"}" + doc3 = ArangoDB.log_put("#{prefix}", cmd, :body => body) + doc3.code.should eq(200) + doc3.parsed_response['error'].should eq(false) + doc3.parsed_response['code'].should eq(200) + doc3.parsed_response['vertex']['optional1'].should eq("val2") + doc3.parsed_response['vertex']['optional2'].should eq(nil) + + cmd = "/_api/blueprints/vertex/#{_id}?graph=#{graph_name}" + doc4 = ArangoDB.log_get("#{prefix}", cmd) + doc4.code.should eq(200) + doc4.parsed_response['error'].should eq(false) + doc4.parsed_response['code'].should eq(200) + doc4.parsed_response['vertex']['optional1'].should eq("val2") + doc4.parsed_response['vertex']['optional2'].should eq(nil) + end + + it "checks delete vertex" do + cmd = "/_api/blueprints/vertex?graph=#{graph_name}" + body = "{\"optional1\" : \"val1\"}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(200) + doc.parsed_response['vertex']['$id'].should eq(nil) + doc.parsed_response['vertex']['optional1'].should eq("val1") + _id = doc.parsed_response['vertex']['_id']; + + cmd = "/_api/blueprints/vertex/#{_id}?graph=#{graph_name}" + doc2 = ArangoDB.log_delete("#{prefix}", cmd) + doc2.code.should eq(200) + doc2.parsed_response['error'].should eq(false) + doc2.parsed_response['code'].should eq(200) + doc2.parsed_response['deleted'].should eq(true) + + cmd = "/_api/blueprints/vertex/#{_id}?graph=#{graph_name}" + doc3 = ArangoDB.log_get("#{prefix}", cmd) + doc3.code.should eq(400) + doc3.parsed_response['error'].should eq(true) + doc3.parsed_response['code'].should eq(400) + end + + end + +################################################################################ +## checking vertices responses +################################################################################ + + context "checks blueprints vertices requests" do + before do + truncate_collection(prefix, "_graphs") + cmd = "/_api/blueprints/graph" + body = "{\"name\" : \"#{graph_name}\", \"verticesName\" : \"#{vertex_collection}\", \"edgesName\" : \"#{edge_collection}\"}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + end + + after do + truncate_collection(prefix, "_graphs") + ArangoDB.drop_collection( vertex_collection ) + ArangoDB.drop_collection( edge_collection ) + end + + it "checks list of vertices" do + cmd = "/_api/blueprints/vertex?graph=#{graph_name}" + body = "{\"optional1\" : \"val1\", \"optional2\" : \"val2\"}" + ArangoDB.log_post("#{prefix}", cmd, :body => body) + ArangoDB.log_post("#{prefix}", cmd, :body => body) + ArangoDB.log_post("#{prefix}", cmd, :body => body) + ArangoDB.log_post("#{prefix}", cmd, :body => body) + + body = "{\"$id\" : \"id1\", \"optional2\" : \"val2\"}" + ArangoDB.log_post("#{prefix}", cmd, :body => body) + ArangoDB.log_post("#{prefix}", cmd, :body => body) + ArangoDB.log_post("#{prefix}", cmd, :body => body) + ArangoDB.log_post("#{prefix}", cmd, :body => body) + + cmd = "/_api/blueprints/vertices?graph=#{graph_name}" + doc = ArangoDB.log_get("#{prefix}", cmd) + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(200) + doc.parsed_response['vertices'].count.should eq(5) + end + + end + +################################################################################ +## checking edge responses +################################################################################ + + context "checks blueprints edge requests" do + before do + truncate_collection(prefix, "_graphs") + cmd = "/_api/blueprints/graph" + body = "{\"name\" : \"#{graph_name}\", \"verticesName\" : \"#{vertex_collection}\", \"edgesName\" : \"#{edge_collection}\"}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + + cmd = "/_api/blueprints/vertex?graph=#{graph_name}" + body = "{\"$id\" : \"vert1\"}" + ArangoDB.log_post("#{prefix}", cmd, :body => body) + body = "{\"$id\" : \"vert2\"}" + ArangoDB.log_post("#{prefix}", cmd, :body => body) + body = "{\"$id\" : \"vert3\"}" + ArangoDB.log_post("#{prefix}", cmd, :body => body) + + end + + after do + truncate_collection(prefix, "_graphs") + ArangoDB.drop_collection( vertex_collection ) + ArangoDB.drop_collection( edge_collection ) + end + + it "checks create edge" do + cmd = "/_api/blueprints/edge?graph=#{graph_name}" + body = "{\"$id\" : \"edge1\", \"_from\" : \"vert2\", \"_to\" : \"vert1\", \"optional1\" : \"val1\"}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(200) + doc.parsed_response['edge']['$id'].should eq("edge1") + doc.parsed_response['edge']['optional1'].should eq("val1") + doc.parsed_response['edge']['$label'].should eq(nil) + end + + it "checks create second edge with same \$id" do + cmd = "/_api/blueprints/edge?graph=#{graph_name}" + body = "{\"$id\" : \"edge1\", \"_from\" : \"vert2\", \"_to\" : \"vert1\", \"optional1\" : \"val1\"}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(200) + doc.parsed_response['edge']['$id'].should eq("edge1") + doc.parsed_response['edge']['optional1'].should eq("val1") + doc.parsed_response['edge']['$label'].should eq(nil) + + cmd = "/_api/blueprints/edge?graph=#{graph_name}" + body = "{\"$id\" : \"edge1\", \"_from\" : \"vert2\", \"_to\" : \"vert1\", \"optional1\" : \"val1\"}" + doc1 = ArangoDB.log_post("#{prefix}", cmd, :body => body) + + doc1.code.should eq(400) + doc1.parsed_response['error'].should eq(true) + doc1.parsed_response['code'].should eq(400) + end + + it "checks create edge with unknown vertex" do + cmd = "/_api/blueprints/edge?graph=#{graph_name}" + body = "{\"$id\" : \"edge1\", \"_from\" : \"unknown\", \"_to\" : \"vert1\", \"optional1\" : \"val1\"}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + + doc.code.should eq(400) + doc.parsed_response['error'].should eq(true) + doc.parsed_response['code'].should eq(400) + end + + it "checks create edge with \$label" do + cmd = "/_api/blueprints/edge?graph=#{graph_name}" + body = "{\"$id\" : \"edge1\", \"_from\" : \"vert2\", \"_to\" : \"vert1\", \"$label\" : \"label1\", \"optional1\" : \"val1\"}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(200) + doc.parsed_response['edge']['$id'].should eq("edge1") + doc.parsed_response['edge']['optional1'].should eq("val1") + doc.parsed_response['edge']['$label'].should eq("label1") + end + + it "checks create edge with _id of vertex" do + cmd = "/_api/blueprints/vertex?graph=#{graph_name}" + body = "{}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + v_id1 = doc.parsed_response['vertex']['_id'] + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + v_id2 = doc.parsed_response['vertex']['_id'] + + cmd = "/_api/blueprints/edge?graph=#{graph_name}" + body = "{\"$id\" : \"edge1\", \"_from\" : \"#{v_id1}\", \"_to\" : \"#{v_id2}\", \"$label\" : \"label1\", \"optional1\" : \"val1\"}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(200) + doc.parsed_response['edge']['$id'].should eq("edge1") + doc.parsed_response['edge']['optional1'].should eq("val1") + doc.parsed_response['edge']['_from'].should eq(v_id1) + doc.parsed_response['edge']['_to'].should eq(v_id2) + end + + it "checks get edge by $id" do + cmd = "/_api/blueprints/edge?graph=#{graph_name}" + body = "{\"$id\" : \"edge1\", \"_from\" : \"vert2\", \"_to\" : \"vert1\", \"optional1\" : \"val1\"}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + eid = doc.parsed_response['edge']['$id'] + e_id = doc.parsed_response['edge']['_id'] + + + cmd = "/_api/blueprints/edge/#{eid}?graph=#{graph_name}" + doc1 = ArangoDB.log_get("#{prefix}", cmd) + + doc1.code.should eq(200) + doc1.parsed_response['error'].should eq(false) + doc1.parsed_response['code'].should eq(200) + doc1.parsed_response['edge']['$id'].should eq(eid) + doc1.parsed_response['edge']['_id'].should eq(e_id) + doc1.parsed_response['edge']['optional1'].should eq("val1") + doc1.parsed_response['edge']['$label'].should eq(nil) + end + + it "checks get edge by _id" do + cmd = "/_api/blueprints/edge?graph=#{graph_name}" + body = "{\"$id\" : \"edge1\", \"_from\" : \"vert2\", \"_to\" : \"vert1\", \"optional1\" : \"val1\"}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + eid = doc.parsed_response['edge']['$id'] + e_id = doc.parsed_response['edge']['_id'] + + + cmd = "/_api/blueprints/edge/#{e_id}?graph=#{graph_name}" + doc1 = ArangoDB.log_get("#{prefix}", cmd) + + doc1.code.should eq(200) + doc1.parsed_response['error'].should eq(false) + doc1.parsed_response['code'].should eq(200) + doc1.parsed_response['edge']['$id'].should eq(eid) + doc1.parsed_response['edge']['_id'].should eq(e_id) + doc1.parsed_response['edge']['optional1'].should eq("val1") + doc1.parsed_response['edge']['$label'].should eq(nil) + end + + it "checks replace edge properties by _id" do + cmd = "/_api/blueprints/edge?graph=#{graph_name}" + body = "{\"$id\" : \"edge1\", \"_from\" : \"vert2\", \"_to\" : \"vert1\", \"optional1\" : \"val1\"}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(200) + doc.parsed_response['edge']['optional1'].should eq("val1") + doc.parsed_response['edge']['optional2'].should eq(nil) + doc.parsed_response['edge']['$label'].should eq(nil) + eid = doc.parsed_response['edge']['$id'] + e_id = doc.parsed_response['edge']['_id'] + e_to = doc.parsed_response['edge']['_to'] + + + cmd = "/_api/blueprints/edge/#{e_id}?graph=#{graph_name}" + body = "{\"$id\" : \"edge4711\", \"optional2\" : \"val2\", \"label\" : \"label1\", \"_to\" : \"to\"}" + doc1 = ArangoDB.log_put("#{prefix}", cmd, :body => body) + doc1.code.should eq(200) + doc1.parsed_response['error'].should eq(false) + doc1.parsed_response['code'].should eq(200) + doc1.parsed_response['edge']['$id'].should eq(eid) + doc1.parsed_response['edge']['_id'].should eq(e_id) + doc1.parsed_response['edge']['_to'].should eq(e_to) + doc1.parsed_response['edge']['nameEdges'].should eq(nil) + doc1.parsed_response['edge']['optional1'].should eq(nil) + doc1.parsed_response['edge']['optional2'].should eq("val2") + doc1.parsed_response['edge']['$label'].should eq(nil) + end + + it "checks delete edge by $id" do + cmd = "/_api/blueprints/edge?graph=#{graph_name}" + body = "{\"$id\" : \"edge1\", \"_from\" : \"vert2\", \"_to\" : \"vert1\", \"optional1\" : \"val1\"}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + eid = doc.parsed_response['edge']['$id'] + e_id = doc.parsed_response['edge']['_id'] + + + cmd = "/_api/blueprints/edge/#{eid}?graph=#{graph_name}" + doc1 = ArangoDB.log_delete("#{prefix}", cmd) + doc1.code.should eq(200) + doc1.parsed_response['error'].should eq(false) + doc1.parsed_response['code'].should eq(200) + + cmd = "/_api/blueprints/edge/#{eid}?graph=#{graph_name}" + doc2 = ArangoDB.log_get("#{prefix}", cmd) + doc2.code.should eq(400) + doc2.parsed_response['error'].should eq(true) + doc2.parsed_response['code'].should eq(400) + end + + it "checks delete edge by _id" do + cmd = "/_api/blueprints/edge?graph=#{graph_name}" + body = "{\"$id\" : \"edge1\", \"_from\" : \"vert2\", \"_to\" : \"vert1\", \"optional1\" : \"val1\"}" + doc = ArangoDB.log_post("#{prefix}", cmd, :body => body) + eid = doc.parsed_response['edge']['$id'] + e_id = doc.parsed_response['edge']['_id'] + + cmd = "/_api/blueprints/edge/#{e_id}?graph=#{graph_name}" + doc1 = ArangoDB.log_delete("#{prefix}", cmd) + doc1.code.should eq(200) + doc1.parsed_response['error'].should eq(false) + doc1.parsed_response['code'].should eq(200) + + cmd = "/_api/blueprints/edge/#{eid}?graph=#{graph_name}" + doc2 = ArangoDB.log_get("#{prefix}", cmd) + doc2.code.should eq(400) + doc2.parsed_response['error'].should eq(true) + doc2.parsed_response['code'].should eq(400) + end + + end + +################################################################################ +## checking edges responses +################################################################################ + + context "checks blueprints edges requests" do + before do + truncate_collection(prefix, "_graphs") + cmd = "/_api/blueprints/graph" + body = "{\"name\" : \"#{graph_name}\", \"verticesName\" : \"#{vertex_collection}\", \"edgesName\" : \"#{edge_collection}\"}" + ArangoDB.post(cmd, :body => body) + + cmd = "/_api/blueprints/vertex?graph=#{graph_name}" + body = "{\"$id\" : \"id1\", \"optional1\" : \"val1a\", \"optional2\" : \"val2a\"}" + ArangoDB.post(cmd, :body => body) + body = "{\"$id\" : \"id2\", \"optional1\" : \"val1b\", \"optional2\" : \"val2b\"}" + ArangoDB.post(cmd, :body => body) + body = "{\"$id\" : \"id3\", \"optional1\" : \"val1c\", \"optional2\" : \"val2c\"}" + ArangoDB.post(cmd, :body => body) + + cmd = "/_api/blueprints/edge?graph=#{graph_name}" + body1 = "{\"$id\" : \"edge1\", \"_from\" : \"id1\", \"_to\" : \"id2\", \"optional1\" : \"val1a\"}" + ArangoDB.post(cmd, :body => body1) + + body2 = "{\"$id\" : \"edge2\", \"_from\" : \"id2\", \"_to\" : \"id3\", \"optional1\" : \"val1b\"}" + ArangoDB.post(cmd, :body => body2) + end + + after do + truncate_collection(prefix, "_graphs") + ArangoDB.drop_collection( vertex_collection ) + ArangoDB.drop_collection( edge_collection ) + end + + it "checks list of all edges" do + cmd = "/_api/blueprints/edges?graph=#{graph_name}" + doc = ArangoDB.log_get("#{prefix}", cmd) + + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(200) + doc.parsed_response['edges'].count.should eq(2) + end + + it "checks list of all edges of one vertex" do + cmd = "/_api/blueprints/edges?graph=#{graph_name}&vertex=id1" + doc = ArangoDB.log_get("#{prefix}", cmd) + + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(200) + doc.parsed_response['edges'].count.should eq(1) + doc.parsed_response['edges'][0]['$id'].should eq("edge1") + + cmd = "/_api/blueprints/edges?graph=#{graph_name}&vertex=id2" + doc2 = ArangoDB.log_get("#{prefix}", cmd) + + doc2.code.should eq(200) + doc2.parsed_response['error'].should eq(false) + doc2.parsed_response['code'].should eq(200) + doc2.parsed_response['edges'].count.should eq(2) + end + + it "checks list of all in edges of one vertex" do + cmd = "/_api/blueprints/edges?graph=#{graph_name}&vertex=id2&type=in" + doc = ArangoDB.log_get("#{prefix}", cmd) + + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(200) + doc.parsed_response['edges'].count.should eq(1) + doc.parsed_response['edges'][0]['$id'].should eq("edge1") + end + + it "checks list of all out edges of one vertex" do + cmd = "/_api/blueprints/edges?graph=#{graph_name}&vertex=id2&type=out" + doc = ArangoDB.log_get("#{prefix}", cmd) + + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(200) + doc.parsed_response['edges'].count.should eq(1) + doc.parsed_response['edges'][0]['$id'].should eq("edge2") + end + + end + + end + +end diff --git a/UnitTests/HttpInterface/run-tests b/UnitTests/HttpInterface/run-tests index 6e3036802b..6c6be73c8e 100755 --- a/UnitTests/HttpInterface/run-tests +++ b/UnitTests/HttpInterface/run-tests @@ -4,6 +4,7 @@ test -d logs || mkdir logs rspec --format d \ api-http-spec.rb \ api-batch-spec.rb \ + api-blueprints-spec.rb \ api-collection-spec.rb \ rest-create-document-spec.rb \ rest-read-document-spec.rb \ diff --git a/arangod/Documentation/api-blueprints.dox b/arangod/Documentation/api-blueprints.dox new file mode 100644 index 0000000000..e330ba30c5 --- /dev/null +++ b/arangod/Documentation/api-blueprints.dox @@ -0,0 +1,92 @@ +//////////////////////////////////////////////////////////////////////////////// +/// @brief over the wire protocol +/// +/// @file +/// +/// DISCLAIMER +/// +/// Copyright 2012 triagens GmbH, Cologne, Germany +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// +/// Copyright holder is triAGENS GmbH, Cologne, Germany +/// +/// @author Jan Steemann +/// @author Copyright 2012, triAGENS GmbH, Cologne, Germany +//////////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////////// +/// @page HttpBlueprints HTTP Interface for Blueprints implementations +/// +/// Blueprints is a property graph model interface with provided implementations. +/// Databases that implement the Blueprints interfaces automatically support +/// Blueprints-enabled applications. (http://tinkerpop.com/) +/// +/// @anchor A_JSF_POST_blueprints_graph +/// @copydetails JSF_POST_blueprints_graph +/// +/// @anchor A_JSF_GET_blueprints_graph +/// @copydetails JSF_GET_blueprints_graph +/// +/// @anchor A_JSF_DELETE_blueprints_graph +/// @copydetails JSF_DELETE_blueprints_graph +/// +/// +/// +/// +/// @anchor A_JSF_POST_blueprints_vertex +/// @copydetails JSF_POST_blueprints_vertex +/// +/// @anchor A_JSF_GET_blueprints_vertex +/// @copydetails JSF_GET_blueprints_vertex +/// +/// @anchor A_JSF_PUT_blueprints_vertex +/// @copydetails JSF_PUT_blueprints_vertex +/// +/// @anchor A_JSF_DELETE_blueprints_vertex +/// @copydetails JSF_DELETE_blueprints_vertex +/// +/// +/// +/// +/// @anchor A_JSF_GET_blueprints_vertices +/// @copydetails JSF_GET_blueprints_vertices +/// +/// +/// +/// +/// @anchor A_JSF_POST_blueprints_edge +/// @copydetails JSF_POST_blueprints_edge +/// +/// @anchor A_JSF_GET_blueprints_edge +/// @copydetails JSF_GET_blueprints_edge +/// +/// @anchor A_JSF_PUT_blueprints_edge +/// @copydetails JSF_PUT_blueprints_edge +/// +/// @anchor A_JSF_DELETE_blueprints_edge +/// @copydetails JSF_DELETE_blueprints_edge +/// +/// +/// +/// +/// @anchor A_JSF_GET_blueprints_edges +/// @copydetails JSF_GET_blueprints_edges +/// +////////////////////////////////////////////////////// + +// Local Variables: +// mode: c++ +// mode: outline-minor +// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @page\\|/// @\\}\\)" +// End: diff --git a/arangod/Documentation/implementor-manual.dox b/arangod/Documentation/implementor-manual.dox index f2147762b2..a3f0a788d4 100644 --- a/arangod/Documentation/implementor-manual.dox +++ b/arangod/Documentation/implementor-manual.dox @@ -95,6 +95,25 @@ /// /// /// +///