From aa85295697a09517e88574412f290d6bde76f54e Mon Sep 17 00:00:00 2001 From: Frank Celler Date: Mon, 23 Apr 2012 10:38:57 +0200 Subject: [PATCH] edges --- .../rest_edge-read-edges-any | 31 +++++++++ .../rest_edge-read-edges-in | 18 ++++++ .../rest_edge-read-edges-out | 24 +++++++ UnitTests/HttpInterface/rest_edge_spec.rb | 64 ++++++++++++++++++- UnitTests/HttpInterface/run_tests | 3 +- js/actions/system/api-edges.js | 42 ++++++++---- 6 files changed, 167 insertions(+), 15 deletions(-) create mode 100644 Doxygen/Examples.AvocadoDB/rest_edge-read-edges-any create mode 100644 Doxygen/Examples.AvocadoDB/rest_edge-read-edges-in create mode 100644 Doxygen/Examples.AvocadoDB/rest_edge-read-edges-out diff --git a/Doxygen/Examples.AvocadoDB/rest_edge-read-edges-any b/Doxygen/Examples.AvocadoDB/rest_edge-read-edges-any new file mode 100644 index 0000000000..33e946af55 --- /dev/null +++ b/Doxygen/Examples.AvocadoDB/rest_edge-read-edges-any @@ -0,0 +1,31 @@ +> curl -X GET --dump - http://localhost:8529/edges/17501660?vertex=17501660/18419164 + +HTTP/1.1 200 OK +content-type: application/json + +{ + "edges": [ + { + "_from": "17501660/18419164", + "_rev": 19140060, + "_to": "17501660/19008988", + "_id": "17501660/19140060" + }, + { + "_from": "17501660/18419164", + "_rev": 19336668, + "_to": "17501660/19008988", + "_id": "17501660/19336668", + "e": 1 + }, + { + "_from": "17501660/19008988", + "_rev": 19402204, + "_to": "17501660/18419164", + "_id": "17501660/19402204", + "e": 2 + } + ], + "code": 200, + "error": false +} diff --git a/Doxygen/Examples.AvocadoDB/rest_edge-read-edges-in b/Doxygen/Examples.AvocadoDB/rest_edge-read-edges-in new file mode 100644 index 0000000000..79b2ba2f6f --- /dev/null +++ b/Doxygen/Examples.AvocadoDB/rest_edge-read-edges-in @@ -0,0 +1,18 @@ +> curl -X GET --dump - http://localhost:8529/edges/17501660?vertex=17501660/18419164&direction=in + +HTTP/1.1 200 OK +content-type: application/json + +{ + "edges": [ + { + "_from": "17501660/19008988", + "_rev": 19402204, + "_to": "17501660/18419164", + "_id": "17501660/19402204", + "e": 2 + } + ], + "code": 200, + "error": false +} diff --git a/Doxygen/Examples.AvocadoDB/rest_edge-read-edges-out b/Doxygen/Examples.AvocadoDB/rest_edge-read-edges-out new file mode 100644 index 0000000000..28cf5687b4 --- /dev/null +++ b/Doxygen/Examples.AvocadoDB/rest_edge-read-edges-out @@ -0,0 +1,24 @@ +> curl -X GET --dump - http://localhost:8529/edges/17501660?vertex=17501660/18419164&direction=out + +HTTP/1.1 200 OK +content-type: application/json + +{ + "edges": [ + { + "_from": "17501660/18419164", + "_rev": 19336668, + "_to": "17501660/19008988", + "_id": "17501660/19336668", + "e": 1 + }, + { + "_from": "17501660/18419164", + "_rev": 19140060, + "_to": "17501660/19008988", + "_id": "17501660/19140060" + } + ], + "code": 200, + "error": false +} diff --git a/UnitTests/HttpInterface/rest_edge_spec.rb b/UnitTests/HttpInterface/rest_edge_spec.rb index 86598f2a81..25ff1d5664 100644 --- a/UnitTests/HttpInterface/rest_edge_spec.rb +++ b/UnitTests/HttpInterface/rest_edge_spec.rb @@ -36,12 +36,26 @@ describe AvocadoDB do doc.code.should eq(400) doc.parsed_response['error'].should eq(true) - doc.parsed_response['errorNum'].should eq(400) + doc.parsed_response['errorNum'].should eq(1205) doc.parsed_response['code'].should eq(400) doc.headers['content-type'].should eq("application/json; charset=utf-8") AvocadoDB.drop_collection(cn) end + + it "returns an error if vertex-handle is missing" do + cn = "UnitTestsCollectionEdge" + cmd = "/edges/#{@cid}?vertex=" + doc = AvocadoDB.log_get("#{prefix}-missing-handle", cmd) + + doc.code.should eq(400) + doc.parsed_response['error'].should eq(true) + doc.parsed_response['errorNum'].should eq(400) + doc.parsed_response['code'].should eq(400) + doc.headers['content-type'].should eq("application/json") + + AvocadoDB.drop_collection(cn) + end end ################################################################################ @@ -93,7 +107,6 @@ describe AvocadoDB do id3 = doc.parsed_response['_id'] # check edge - cmd = "/edge/#{id3}" doc = AvocadoDB.log_get("#{prefix}-read-edge", cmd) @@ -115,7 +128,6 @@ describe AvocadoDB do id4 = doc.parsed_response['_id'] # check edge - cmd = "/edge/#{id4}" doc = AvocadoDB.log_get("#{prefix}-read-edge", cmd) @@ -125,6 +137,52 @@ describe AvocadoDB do doc.parsed_response['_to'].should eq(id2) doc.parsed_response['e'].should eq(1) doc.headers['content-type'].should eq("application/json; charset=utf-8") + + # create third edge + cmd = "/edge?collection=#{@cid}&from=#{id2}&to=#{id1}" + body = "{ \"e\" : 2 }" + doc = AvocadoDB.log_post("#{prefix}-create-edge", cmd, :body => body) + + doc.code.should eq(201) + doc.parsed_response['_id'].should be_kind_of(String) + doc.headers['content-type'].should eq("application/json; charset=utf-8") + + id5 = doc.parsed_response['_id'] + + # check edge + cmd = "/edge/#{id5}" + doc = AvocadoDB.log_get("#{prefix}-read-edge", cmd) + + doc.code.should eq(200) + doc.parsed_response['_id'].should eq(id5) + doc.parsed_response['_from'].should eq(id2) + doc.parsed_response['_to'].should eq(id1) + doc.parsed_response['e'].should eq(2) + doc.headers['content-type'].should eq("application/json; charset=utf-8") + + # check ANY edges + cmd = "/edges/#{@cid}?vertex=#{id1}" + doc = AvocadoDB.log_get("#{prefix}-read-edges-any", cmd); + + doc.code.should eq(200) + doc.parsed_response['edges'].should be_kind_of(Array) + doc.parsed_response['edges'].length.should be(3) + + # check IN edges + cmd = "/edges/#{@cid}?vertex=#{id1}&direction=in" + doc = AvocadoDB.log_get("#{prefix}-read-edges-in", cmd); + + doc.code.should eq(200) + doc.parsed_response['edges'].should be_kind_of(Array) + doc.parsed_response['edges'].length.should be(1) + + # check OUT edges + cmd = "/edges/#{@cid}?vertex=#{id1}&direction=out" + doc = AvocadoDB.log_get("#{prefix}-read-edges-out", cmd); + + doc.code.should eq(200) + doc.parsed_response['edges'].should be_kind_of(Array) + doc.parsed_response['edges'].length.should be(2) end end diff --git a/UnitTests/HttpInterface/run_tests b/UnitTests/HttpInterface/run_tests index ff480f7e80..7117622ada 100755 --- a/UnitTests/HttpInterface/run_tests +++ b/UnitTests/HttpInterface/run_tests @@ -7,4 +7,5 @@ rspec --format d \ rest_create-document_spec.rb \ rest_read-document_spec.rb \ rest_update-document_spec.rb \ - rest_delete-document_spec.rb + rest_delete-document_spec.rb \ + rest_edge_spec.rb diff --git a/js/actions/system/api-edges.js b/js/actions/system/api-edges.js index 4fc0a7ef86..816e553d2c 100644 --- a/js/actions/system/api-edges.js +++ b/js/actions/system/api-edges.js @@ -50,6 +50,20 @@ var API = "edges"; /// /// Returns the list of edges starting in the vertex identified by /// @FA{vertex-handle}. +/// +/// @EXAMPLES +/// +/// Any direction +/// +/// @verbinclude rest_edge-read-edges-any +/// +/// In edges +/// +/// @verbinclude rest_edge-read-edges-in +/// +/// Out edges +/// +/// @verbinclude rest_edge-read-edges-out //////////////////////////////////////////////////////////////////////////////// function GET_edges (req, res) { @@ -72,18 +86,24 @@ function GET_edges (req, res) { var direction = req.parameters['direction']; var e; - if (direction == null || direction == "" || direction == "any") { - e = collection.edges(vertex); + try { + if (direction == null || direction == "" || direction == "any") { + e = collection.edges(vertex); + } + else if (direction == "in") { + e = collection.inEdges(vertex); + } + else if (direction == "out") { + e = collection.outEdges(vertex); + } + else { + actions.resultBad(req, res, actions.ERROR_HTTP_BAD_PARAMETER, + " must be any, in, or out, not: " + JSON.stringify(direction)); + return; + } } - else if (direction == "in") { - e = collection.inEdges(vertex); - } - else if (direction == "out") { - e = collection.outEdges(vertex); - } - else { - actions.resultBad(req, res, actions.ERROR_HTTP_BAD_PARAMETER, - " must be any, in, or out, not: " + JSON.stringify(direction)); + catch (err) { + actions.resultException(req, res, err); return; }