From fdece972d05025f7670abba3286783aee942577c Mon Sep 17 00:00:00 2001 From: Michael Hackstein Date: Fri, 13 Jun 2014 16:41:48 +0200 Subject: [PATCH] Added tests for vertex and edge collection lists in http interface. Added docu for _list in general-graph module --- .../HttpInterface/api-general-graph-spec.rb | 35 +++++++++++++++++++ js/apps/system/gharial/gharial.js | 4 +-- .../modules/org/arangodb/general-graph.js | 15 +++++++- .../modules/org/arangodb/graph-blueprint.js | 2 +- 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/UnitTests/HttpInterface/api-general-graph-spec.rb b/UnitTests/HttpInterface/api-general-graph-spec.rb index 441e78fb76..594de3a18d 100644 --- a/UnitTests/HttpInterface/api-general-graph-spec.rb +++ b/UnitTests/HttpInterface/api-general-graph-spec.rb @@ -28,6 +28,11 @@ def edge_endpoint(graph_name, collection) return URLPREFIX + "/" + graph_name + "/edge/" + collection end +def list_edge_collections (graph_name) + cmd = URLPREFIX + "/" + graph_name + "/edge" + doc = ArangoDB.get(cmd) + return doc +end def additional_edge_definition (graph_name, edge_definitions) cmd = URLPREFIX + "/" + graph_name + "/edge" @@ -47,6 +52,12 @@ def delete_edge_definition (graph_name, definition_name) return doc end +def list_vertex_collections (graph_name) + cmd = URLPREFIX + "/" + graph_name + "/vertex" + doc = ArangoDB.get(cmd) + return doc +end + def additional_vertex_collection (graph_name, collection_name) cmd = URLPREFIX + "/" + graph_name + "/vertex" body = { :collection => collection_name } @@ -286,6 +297,30 @@ describe ArangoDB do doc.parsed_response['error'].should eq("graph already exists") doc.parsed_response['code'].should eq(409) end + + it "can get a list of vertex collections" do + definition = { "collection" => friend_collection, "from" => [user_collection], "to" => [user_collection] } + create_graph(graph_name, [definition]) + additional_vertex_collection(graph_name, product_collection) + + doc = list_vertex_collections(graph_name) + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(200) + doc.parsed_response['collections'].should eq([product_collection, user_collection]) + end + + it "can get a list of edge collections" do + definition1 = { "collection" => friend_collection, "from" => [user_collection], "to" => [user_collection] } + definition2 = { "collection" => bought_collection, "from" => [user_collection], "to" => [product_collection] } + create_graph(graph_name, [definition1, definition2]) + + doc = list_edge_collections(graph_name) + doc.code.should eq(200) + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(200) + doc.parsed_response['collections'].should eq([bought_collection, friend_collection]) + end end context "check vertex operations" do diff --git a/js/apps/system/gharial/gharial.js b/js/apps/system/gharial/gharial.js index 4988071323..647782a0e3 100644 --- a/js/apps/system/gharial/gharial.js +++ b/js/apps/system/gharial/gharial.js @@ -127,7 +127,7 @@ var g = Graph._graph(name); setResponse(res, "collections", _.map(g._vertexCollections(), function(c) { return c.name(); - })); + }).sort()); }) .pathParam("graph", { type: "string", @@ -206,7 +206,7 @@ var g = Graph._graph(name); setResponse(res, "collections", _.map(g._edgeCollections(), function(c) { return c.name(); - })); + }).sort()); }) .pathParam("graph", { type: "string", diff --git a/js/common/modules/org/arangodb/general-graph.js b/js/common/modules/org/arangodb/general-graph.js index 7dfe5e5016..e54313e209 100644 --- a/js/common/modules/org/arangodb/general-graph.js +++ b/js/common/modules/org/arangodb/general-graph.js @@ -1403,7 +1403,20 @@ var _directedRelationDefinition = function ( }; //////////////////////////////////////////////////////////////////////////////// -/// @brief create a list of all graph names +/// @startDocuBlock JSF_general_graph_list +/// +/// `general-graph._list()` +/// *List all graphs.* +/// +/// Lists all graph names stored in this database. +/// +/// @EXAMPLES +/// +/// @EXAMPLE_ARANGOSH_OUTPUT{generalGraphDirectedRelationDefinition} +/// var graph = require("org/arangodb/general-graph"); +/// graph._list(); +/// @END_EXAMPLE_ARANGOSH_OUTPUT +/// @endDocuBlock //////////////////////////////////////////////////////////////////////////////// var _list = function() { diff --git a/js/server/modules/org/arangodb/graph-blueprint.js b/js/server/modules/org/arangodb/graph-blueprint.js index be053a3f2e..dd735f526f 100644 --- a/js/server/modules/org/arangodb/graph-blueprint.js +++ b/js/server/modules/org/arangodb/graph-blueprint.js @@ -370,7 +370,7 @@ Graph.prototype.initialize = function (name, vertices, edges, waitForSync) { if (from.length !== 1 || to.length !== 1 || from[0] !== to[0]) { throw newGraphError; } - } + } vertices = db._collection(edgeDefinitions[0].from[0]);