mirror of https://gitee.com/bigwinds/arangodb
Merge branch 'devel' of https://github.com/triAGENS/ArangoDB into mjmh
This commit is contained in:
commit
59aa16de0e
|
@ -703,10 +703,12 @@ TRI_associative_pointer_t* TRI_CreateFunctionsAql (void) {
|
|||
|
||||
// graph functions
|
||||
REGISTER_FUNCTION("PATHS", "GRAPH_PATHS", false, false, "c,h|s,b", &OptimisePaths);
|
||||
REGISTER_FUNCTION("GRAPH_PATHS", "GENERAL_GRAPH_PATHS", false, false, "s|s,b,n,n", &OptimisePaths);
|
||||
REGISTER_FUNCTION("SHORTEST_PATH", "GRAPH_SHORTEST_PATH", false, false, "h,h,s,s,s|a", NULL);
|
||||
REGISTER_FUNCTION("TRAVERSAL", "GRAPH_TRAVERSAL", false, false, "h,h,s,s|a", NULL);
|
||||
REGISTER_FUNCTION("TRAVERSAL_TREE", "GRAPH_TRAVERSAL_TREE", false, false, "h,h,s,s,s|a", NULL);
|
||||
REGISTER_FUNCTION("EDGES", "GRAPH_EDGES", false, false, "h,s,s|l", NULL);
|
||||
REGISTER_FUNCTION("EDGES", "GRAPH_EDGES", false, false, "h,s,s|l,l", NULL);
|
||||
REGISTER_FUNCTION("GRAPH_EDGES", "GENERAL_GRAPH_EDGES", false, false, "s,s,s|l,l", NULL);
|
||||
REGISTER_FUNCTION("NEIGHBORS", "GRAPH_NEIGHBORS", false, false, "h,h,s,s|l", NULL);
|
||||
|
||||
// date functions
|
||||
|
|
|
@ -101,20 +101,20 @@ var findOrCreateCollectionByName = function (name, type, noCreate) {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var findOrCreateCollectionsByEdgeDefinitions = function (edgeDefinitions, noCreate) {
|
||||
var vertexCollections = {},
|
||||
edgeCollections = {};
|
||||
edgeDefinitions.forEach(function (e) {
|
||||
e.from.concat(e.to).forEach(function (v) {
|
||||
findOrCreateCollectionByName(v, ArangoCollection.TYPE_DOCUMENT, noCreate);
|
||||
vertexCollections[v] = db[v];
|
||||
});
|
||||
findOrCreateCollectionByName(e.collection, ArangoCollection.TYPE_EDGE, noCreate);
|
||||
edgeCollections[e.collection] = db[e.collection];
|
||||
});
|
||||
return [
|
||||
vertexCollections,
|
||||
edgeCollections
|
||||
];
|
||||
var vertexCollections = {},
|
||||
edgeCollections = {};
|
||||
edgeDefinitions.forEach(function (e) {
|
||||
e.from.concat(e.to).forEach(function (v) {
|
||||
findOrCreateCollectionByName(v, ArangoCollection.TYPE_DOCUMENT, noCreate);
|
||||
vertexCollections[v] = db[v];
|
||||
});
|
||||
findOrCreateCollectionByName(e.collection, ArangoCollection.TYPE_EDGE, noCreate);
|
||||
edgeCollections[e.collection] = db[e.collection];
|
||||
});
|
||||
return [
|
||||
vertexCollections,
|
||||
edgeCollections
|
||||
];
|
||||
};
|
||||
|
||||
|
||||
|
@ -316,7 +316,7 @@ var _create = function (graphName, edgeDefinitions) {
|
|||
var gdb = db._graphs,
|
||||
g,
|
||||
graphAlreadyExists = true,
|
||||
collections;
|
||||
collections;
|
||||
|
||||
if (gdb === null) {
|
||||
throw "_graphs collection does not exist.";
|
||||
|
@ -340,7 +340,7 @@ var _create = function (graphName, edgeDefinitions) {
|
|||
throw "graph " + graphName + " already exists.";
|
||||
}
|
||||
|
||||
collections = findOrCreateCollectionsByEdgeDefinitions(edgeDefinitions, false);
|
||||
collections = findOrCreateCollectionsByEdgeDefinitions(edgeDefinitions, false);
|
||||
|
||||
gdb.save({
|
||||
'edgeDefinitions' : edgeDefinitions,
|
||||
|
@ -370,6 +370,22 @@ var Graph = function(graphName, edgeDefinitions, vertexCollections, edgeCollecti
|
|||
|
||||
_.each(edgeCollections, function(obj, key) {
|
||||
self[key] = obj;
|
||||
var old_save = obj.save.bind(obj);
|
||||
obj.save = function(from, to, data) {
|
||||
edgeDefinitions.forEach(
|
||||
function(edgeDefinition) {
|
||||
if (edgeDefinition.collection === key) {
|
||||
var fromCollection = from.split("/")[0];
|
||||
var toCollection = to.split("/")[0];
|
||||
if (! _.contains(edgeDefinition.from, fromCollection)
|
||||
|| ! _.contains(edgeDefinition.to, toCollection)) {
|
||||
throw "Edge is not allowed between " + from + " and " + to + ".";
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
return old_save(from, to, data);
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -382,7 +398,7 @@ var Graph = function(graphName, edgeDefinitions, vertexCollections, edgeCollecti
|
|||
var _graph = function(graphName) {
|
||||
|
||||
var gdb = db._graphs,
|
||||
g, collections;
|
||||
g, collections;
|
||||
|
||||
if (gdb === null) {
|
||||
throw "_graphs collection does not exist.";
|
||||
|
@ -391,15 +407,15 @@ var _graph = function(graphName) {
|
|||
try {
|
||||
g = gdb.document(graphName);
|
||||
} catch (e) {
|
||||
if (e.errorNum !== 1202) {
|
||||
throw e;
|
||||
}
|
||||
throw "graph " + graphName + " does not exists.";
|
||||
}
|
||||
if (e.errorNum !== 1202) {
|
||||
throw e;
|
||||
}
|
||||
throw "graph " + graphName + " does not exists.";
|
||||
}
|
||||
|
||||
collections = findOrCreateCollectionsByEdgeDefinitions(g.edgeDefinitions, true);
|
||||
collections = findOrCreateCollectionsByEdgeDefinitions(g.edgeDefinitions, true);
|
||||
|
||||
return new Graph(graphName, g.edgeDefinitions, collections[0], collections[1]);
|
||||
return new Graph(graphName, g.edgeDefinitions, collections[0], collections[1]);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -57,7 +57,7 @@ function GeneralGraphCreationSuite() {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
test_undirectedRelationDefinition : function () {
|
||||
var r;
|
||||
var r;
|
||||
|
||||
try {
|
||||
r = graph._undirectedRelationDefinition("relationName", ["vertexC1", "vertexC2"]);
|
||||
|
@ -66,348 +66,348 @@ function GeneralGraphCreationSuite() {
|
|||
}
|
||||
|
||||
assertEqual(r, {
|
||||
collection: "relationName",
|
||||
from: ["vertexC1", "vertexC2"],
|
||||
to: ["vertexC1", "vertexC2"]
|
||||
collection: "relationName",
|
||||
from: ["vertexC1", "vertexC2"],
|
||||
to: ["vertexC1", "vertexC2"]
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
test_undirectedRelationDefinitionWithSingleCollection : function () {
|
||||
var r;
|
||||
test_undirectedRelationDefinitionWithSingleCollection : function () {
|
||||
var r;
|
||||
|
||||
try {
|
||||
r = graph._undirectedRelationDefinition("relationName", "vertexC1");
|
||||
}
|
||||
catch (err) {
|
||||
}
|
||||
try {
|
||||
r = graph._undirectedRelationDefinition("relationName", "vertexC1");
|
||||
}
|
||||
catch (err) {
|
||||
}
|
||||
|
||||
assertEqual(r, {
|
||||
collection: "relationName",
|
||||
from: ["vertexC1"],
|
||||
to: ["vertexC1"]
|
||||
});
|
||||
assertEqual(r, {
|
||||
collection: "relationName",
|
||||
from: ["vertexC1"],
|
||||
to: ["vertexC1"]
|
||||
});
|
||||
|
||||
},
|
||||
},
|
||||
|
||||
test_undirectedRelationDefinitionWithMissingName : function () {
|
||||
var r, exception;
|
||||
try {
|
||||
r = graph._undirectedRelationDefinition("", ["vertexC1", "vertexC2"]);
|
||||
}
|
||||
catch (err) {
|
||||
exception = err;
|
||||
}
|
||||
test_undirectedRelationDefinitionWithMissingName : function () {
|
||||
var r, exception;
|
||||
try {
|
||||
r = graph._undirectedRelationDefinition("", ["vertexC1", "vertexC2"]);
|
||||
}
|
||||
catch (err) {
|
||||
exception = err;
|
||||
}
|
||||
|
||||
assertEqual(exception, "<relationName> must be a not empty string");
|
||||
assertEqual(exception, "<relationName> must be a not empty string");
|
||||
|
||||
},
|
||||
},
|
||||
|
||||
test_undirectedRelationDefinitionWithTooFewArgs : function () {
|
||||
var r, exception;
|
||||
try {
|
||||
r = graph._undirectedRelationDefinition(["vertexC1", "vertexC2"]);
|
||||
}
|
||||
catch (err) {
|
||||
exception = err;
|
||||
}
|
||||
test_undirectedRelationDefinitionWithTooFewArgs : function () {
|
||||
var r, exception;
|
||||
try {
|
||||
r = graph._undirectedRelationDefinition(["vertexC1", "vertexC2"]);
|
||||
}
|
||||
catch (err) {
|
||||
exception = err;
|
||||
}
|
||||
|
||||
assertEqual(exception, "method _undirectedRelationDefinition expects 2 arguments");
|
||||
assertEqual(exception, "method _undirectedRelationDefinition expects 2 arguments");
|
||||
|
||||
},
|
||||
},
|
||||
|
||||
test_undirectedRelationDefinitionWithInvalidSecondArg : function () {
|
||||
var r, exception;
|
||||
try {
|
||||
r = graph._undirectedRelationDefinition("name", {"vertexC1" : "vertexC2"});
|
||||
}
|
||||
catch (err) {
|
||||
exception = err;
|
||||
}
|
||||
test_undirectedRelationDefinitionWithInvalidSecondArg : function () {
|
||||
var r, exception;
|
||||
try {
|
||||
r = graph._undirectedRelationDefinition("name", {"vertexC1" : "vertexC2"});
|
||||
}
|
||||
catch (err) {
|
||||
exception = err;
|
||||
}
|
||||
|
||||
assertEqual(exception, "<vertexCollections> must be a not empty string or array");
|
||||
assertEqual(exception, "<vertexCollections> must be a not empty string or array");
|
||||
|
||||
},
|
||||
},
|
||||
|
||||
test_directedRelationDefinition : function () {
|
||||
var r;
|
||||
test_directedRelationDefinition : function () {
|
||||
var r;
|
||||
|
||||
try {
|
||||
r = graph._directedRelationDefinition("relationName",
|
||||
["vertexC1", "vertexC2"], ["vertexC3", "vertexC4"]);
|
||||
}
|
||||
catch (err) {
|
||||
}
|
||||
try {
|
||||
r = graph._directedRelationDefinition("relationName",
|
||||
["vertexC1", "vertexC2"], ["vertexC3", "vertexC4"]);
|
||||
}
|
||||
catch (err) {
|
||||
}
|
||||
|
||||
assertEqual(r, {
|
||||
collection: "relationName",
|
||||
from: ["vertexC1", "vertexC2"],
|
||||
to: ["vertexC3", "vertexC4"]
|
||||
});
|
||||
assertEqual(r, {
|
||||
collection: "relationName",
|
||||
from: ["vertexC1", "vertexC2"],
|
||||
to: ["vertexC3", "vertexC4"]
|
||||
});
|
||||
|
||||
},
|
||||
},
|
||||
|
||||
test_directedRelationDefinitionWithMissingName : function () {
|
||||
var r, exception;
|
||||
try {
|
||||
r = graph._directedRelationDefinition("",
|
||||
["vertexC1", "vertexC2"], ["vertexC3", "vertexC4"]);
|
||||
}
|
||||
catch (err) {
|
||||
exception = err;
|
||||
}
|
||||
test_directedRelationDefinitionWithMissingName : function () {
|
||||
var r, exception;
|
||||
try {
|
||||
r = graph._directedRelationDefinition("",
|
||||
["vertexC1", "vertexC2"], ["vertexC3", "vertexC4"]);
|
||||
}
|
||||
catch (err) {
|
||||
exception = err;
|
||||
}
|
||||
|
||||
assertEqual(exception, "<relationName> must be a not empty string");
|
||||
assertEqual(exception, "<relationName> must be a not empty string");
|
||||
|
||||
},
|
||||
},
|
||||
|
||||
test_directedRelationDefinitionWithTooFewArgs : function () {
|
||||
var r, exception;
|
||||
try {
|
||||
r = graph._directedRelationDefinition(["vertexC1", "vertexC2"], ["vertexC3", "vertexC4"]);
|
||||
}
|
||||
catch (err) {
|
||||
exception = err;
|
||||
}
|
||||
test_directedRelationDefinitionWithTooFewArgs : function () {
|
||||
var r, exception;
|
||||
try {
|
||||
r = graph._directedRelationDefinition(["vertexC1", "vertexC2"], ["vertexC3", "vertexC4"]);
|
||||
}
|
||||
catch (err) {
|
||||
exception = err;
|
||||
}
|
||||
|
||||
assertEqual(exception, "method _undirectedRelationDefinition expects 3 arguments");
|
||||
assertEqual(exception, "method _undirectedRelationDefinition expects 3 arguments");
|
||||
|
||||
},
|
||||
},
|
||||
|
||||
test_directedRelationDefinitionWithInvalidSecondArg : function () {
|
||||
var r, exception;
|
||||
try {
|
||||
r = graph._directedRelationDefinition("name", {"vertexC1" : "vertexC2"}, "");
|
||||
}
|
||||
catch (err) {
|
||||
exception = err;
|
||||
}
|
||||
test_directedRelationDefinitionWithInvalidSecondArg : function () {
|
||||
var r, exception;
|
||||
try {
|
||||
r = graph._directedRelationDefinition("name", {"vertexC1" : "vertexC2"}, "");
|
||||
}
|
||||
catch (err) {
|
||||
exception = err;
|
||||
}
|
||||
|
||||
assertEqual(exception, "<fromVertexCollections> must be a not empty string or array");
|
||||
assertEqual(exception, "<fromVertexCollections> must be a not empty string or array");
|
||||
|
||||
},
|
||||
},
|
||||
|
||||
test_directedRelationDefinitionWithInvalidThirdArg : function () {
|
||||
var r, exception;
|
||||
try {
|
||||
r = graph._directedRelationDefinition("name", ["vertexC1", "vertexC2"], []);
|
||||
}
|
||||
catch (err) {
|
||||
exception = err;
|
||||
}
|
||||
test_directedRelationDefinitionWithInvalidThirdArg : function () {
|
||||
var r, exception;
|
||||
try {
|
||||
r = graph._directedRelationDefinition("name", ["vertexC1", "vertexC2"], []);
|
||||
}
|
||||
catch (err) {
|
||||
exception = err;
|
||||
}
|
||||
|
||||
assertEqual(exception, "<toVertexCollections> must be a not empty string or array");
|
||||
assertEqual(exception, "<toVertexCollections> must be a not empty string or array");
|
||||
|
||||
},
|
||||
},
|
||||
|
||||
testEdgeDefinitions : function () {
|
||||
testEdgeDefinitions : function () {
|
||||
|
||||
|
||||
//with empty args
|
||||
assertEqual(graph.edgeDefinitions(), []);
|
||||
//with empty args
|
||||
assertEqual(graph.edgeDefinitions(), []);
|
||||
|
||||
//with args
|
||||
assertEqual(graph.edgeDefinitions(
|
||||
graph._undirectedRelationDefinition("relationName", "vertexC1"),
|
||||
graph._directedRelationDefinition("relationName",
|
||||
["vertexC1", "vertexC2"], ["vertexC3", "vertexC4"])
|
||||
), [
|
||||
{
|
||||
collection: "relationName",
|
||||
from: ["vertexC1"],
|
||||
to: ["vertexC1"]
|
||||
},
|
||||
{
|
||||
collection: "relationName",
|
||||
from: ["vertexC1", "vertexC2"],
|
||||
to: ["vertexC3", "vertexC4"]
|
||||
}
|
||||
]);
|
||||
//with args
|
||||
assertEqual(graph.edgeDefinitions(
|
||||
graph._undirectedRelationDefinition("relationName", "vertexC1"),
|
||||
graph._directedRelationDefinition("relationName",
|
||||
["vertexC1", "vertexC2"], ["vertexC3", "vertexC4"])
|
||||
), [
|
||||
{
|
||||
collection: "relationName",
|
||||
from: ["vertexC1"],
|
||||
to: ["vertexC1"]
|
||||
},
|
||||
{
|
||||
collection: "relationName",
|
||||
from: ["vertexC1", "vertexC2"],
|
||||
to: ["vertexC3", "vertexC4"]
|
||||
}
|
||||
]);
|
||||
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
test_create : function () {
|
||||
try {
|
||||
arangodb.db._collection("_graphs").remove("_graphs/bla3")
|
||||
} catch (err) {
|
||||
}
|
||||
var a = graph._create(
|
||||
"bla3",
|
||||
graph.edgeDefinitions(
|
||||
graph._undirectedRelationDefinition("relationName", "vertexC1"),
|
||||
graph._directedRelationDefinition("relationName2",
|
||||
["vertexC1", "vertexC2"], ["vertexC3", "vertexC4"]
|
||||
)
|
||||
)
|
||||
);
|
||||
assertTrue(a.__vertexCollections.hasOwnProperty('vertexC1'));
|
||||
assertTrue(a.__vertexCollections.hasOwnProperty('vertexC2'));
|
||||
assertTrue(a.__vertexCollections.hasOwnProperty('vertexC3'));
|
||||
assertTrue(a.__vertexCollections.hasOwnProperty('vertexC4'));
|
||||
assertTrue(a.__edgeCollections.hasOwnProperty('relationName'));
|
||||
assertTrue(a.__edgeCollections.hasOwnProperty('relationName2'));
|
||||
assertEqual(a.__edgeDefinitions, [
|
||||
{
|
||||
"collection" : "relationName",
|
||||
"from" : [
|
||||
"vertexC1"
|
||||
],
|
||||
"to" : [
|
||||
"vertexC1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"collection" : "relationName2",
|
||||
"from" : [
|
||||
"vertexC1",
|
||||
"vertexC2"
|
||||
],
|
||||
"to" : [
|
||||
"vertexC3",
|
||||
"vertexC4"
|
||||
]
|
||||
}
|
||||
]
|
||||
);
|
||||
},
|
||||
test_create : function () {
|
||||
try {
|
||||
arangodb.db._collection("_graphs").remove("_graphs/bla3")
|
||||
} catch (err) {
|
||||
}
|
||||
var a = graph._create(
|
||||
"bla3",
|
||||
graph.edgeDefinitions(
|
||||
graph._undirectedRelationDefinition("relationName", "vertexC1"),
|
||||
graph._directedRelationDefinition("relationName2",
|
||||
["vertexC1", "vertexC2"], ["vertexC3", "vertexC4"]
|
||||
)
|
||||
)
|
||||
);
|
||||
assertTrue(a.__vertexCollections.hasOwnProperty('vertexC1'));
|
||||
assertTrue(a.__vertexCollections.hasOwnProperty('vertexC2'));
|
||||
assertTrue(a.__vertexCollections.hasOwnProperty('vertexC3'));
|
||||
assertTrue(a.__vertexCollections.hasOwnProperty('vertexC4'));
|
||||
assertTrue(a.__edgeCollections.hasOwnProperty('relationName'));
|
||||
assertTrue(a.__edgeCollections.hasOwnProperty('relationName2'));
|
||||
assertEqual(a.__edgeDefinitions, [
|
||||
{
|
||||
"collection" : "relationName",
|
||||
"from" : [
|
||||
"vertexC1"
|
||||
],
|
||||
"to" : [
|
||||
"vertexC1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"collection" : "relationName2",
|
||||
"from" : [
|
||||
"vertexC1",
|
||||
"vertexC2"
|
||||
],
|
||||
"to" : [
|
||||
"vertexC3",
|
||||
"vertexC4"
|
||||
]
|
||||
}
|
||||
]
|
||||
);
|
||||
},
|
||||
|
||||
test_create_WithOut_EdgeDefiniton : function () {
|
||||
var msg;
|
||||
try {
|
||||
arangodb.db._collection("_graphs").remove("_graphs/bla3")
|
||||
} catch (err) {
|
||||
}
|
||||
test_create_WithOut_EdgeDefiniton : function () {
|
||||
var msg;
|
||||
try {
|
||||
arangodb.db._collection("_graphs").remove("_graphs/bla3")
|
||||
} catch (err) {
|
||||
}
|
||||
|
||||
try {
|
||||
var a = graph._create(
|
||||
"bla3",
|
||||
[]
|
||||
);
|
||||
} catch (err) {
|
||||
msg = err;
|
||||
}
|
||||
try {
|
||||
var a = graph._create(
|
||||
"bla3",
|
||||
[]
|
||||
);
|
||||
} catch (err) {
|
||||
msg = err;
|
||||
}
|
||||
|
||||
assertEqual(msg, "at least one edge definition is required to create a graph.");
|
||||
assertEqual(msg, "at least one edge definition is required to create a graph.");
|
||||
|
||||
},
|
||||
},
|
||||
|
||||
test_create_WithOut_Name : function () {
|
||||
var msg;
|
||||
try {
|
||||
arangodb.db._collection("_graphs").remove("_graphs/bla3")
|
||||
} catch (err) {
|
||||
}
|
||||
test_create_WithOut_Name : function () {
|
||||
var msg;
|
||||
try {
|
||||
arangodb.db._collection("_graphs").remove("_graphs/bla3")
|
||||
} catch (err) {
|
||||
}
|
||||
|
||||
try {
|
||||
var a = graph._create(
|
||||
"",
|
||||
graph.edgeDefinitions(
|
||||
graph._undirectedRelationDefinition("relationName", "vertexC1"),
|
||||
graph._directedRelationDefinition("relationName2",
|
||||
["vertexC1", "vertexC2"], ["vertexC3", "vertexC4"]
|
||||
)
|
||||
)
|
||||
);
|
||||
} catch (err) {
|
||||
msg = err;
|
||||
}
|
||||
try {
|
||||
var a = graph._create(
|
||||
"",
|
||||
graph.edgeDefinitions(
|
||||
graph._undirectedRelationDefinition("relationName", "vertexC1"),
|
||||
graph._directedRelationDefinition("relationName2",
|
||||
["vertexC1", "vertexC2"], ["vertexC3", "vertexC4"]
|
||||
)
|
||||
)
|
||||
);
|
||||
} catch (err) {
|
||||
msg = err;
|
||||
}
|
||||
|
||||
assertEqual(msg, "a graph name is required to create a graph.");
|
||||
assertEqual(msg, "a graph name is required to create a graph.");
|
||||
|
||||
},
|
||||
},
|
||||
|
||||
test_create_With_Already_Existing_Graph : function () {
|
||||
try {
|
||||
arangodb.db._collection("_graphs").remove("_graphs/bla3")
|
||||
} catch (err) {
|
||||
}
|
||||
graph._create(
|
||||
"bla3",
|
||||
graph.edgeDefinitions(
|
||||
graph._undirectedRelationDefinition("relationName", "vertexC1"),
|
||||
graph._directedRelationDefinition("relationName2",
|
||||
["vertexC1", "vertexC2"], ["vertexC3", "vertexC4"]
|
||||
)
|
||||
)
|
||||
);
|
||||
var msg;
|
||||
try {
|
||||
var a = graph._create(
|
||||
"bla3",
|
||||
graph.edgeDefinitions(
|
||||
graph._undirectedRelationDefinition("relationName", "vertexC1"),
|
||||
graph._directedRelationDefinition("relationName2",
|
||||
["vertexC1", "vertexC2"], ["vertexC3", "vertexC4"]
|
||||
)
|
||||
)
|
||||
);
|
||||
} catch (err) {
|
||||
msg = err;
|
||||
}
|
||||
test_create_With_Already_Existing_Graph : function () {
|
||||
try {
|
||||
arangodb.db._collection("_graphs").remove("_graphs/bla3")
|
||||
} catch (err) {
|
||||
}
|
||||
graph._create(
|
||||
"bla3",
|
||||
graph.edgeDefinitions(
|
||||
graph._undirectedRelationDefinition("relationName", "vertexC1"),
|
||||
graph._directedRelationDefinition("relationName2",
|
||||
["vertexC1", "vertexC2"], ["vertexC3", "vertexC4"]
|
||||
)
|
||||
)
|
||||
);
|
||||
var msg;
|
||||
try {
|
||||
var a = graph._create(
|
||||
"bla3",
|
||||
graph.edgeDefinitions(
|
||||
graph._undirectedRelationDefinition("relationName", "vertexC1"),
|
||||
graph._directedRelationDefinition("relationName2",
|
||||
["vertexC1", "vertexC2"], ["vertexC3", "vertexC4"]
|
||||
)
|
||||
)
|
||||
);
|
||||
} catch (err) {
|
||||
msg = err;
|
||||
}
|
||||
|
||||
assertEqual(msg, "graph bla3 already exists.");
|
||||
assertEqual(msg, "graph bla3 already exists.");
|
||||
|
||||
},
|
||||
},
|
||||
|
||||
test_get_graph : function () {
|
||||
test_get_graph : function () {
|
||||
|
||||
try {
|
||||
arangodb.db._collection("_graphs").remove("_graphs/bla3")
|
||||
} catch (err) {
|
||||
}
|
||||
graph._create(
|
||||
"bla3",
|
||||
graph.edgeDefinitions(
|
||||
graph._undirectedRelationDefinition("relationName", "vertexC1"),
|
||||
graph._directedRelationDefinition("relationName2",
|
||||
["vertexC1", "vertexC2"], ["vertexC3", "vertexC4"]
|
||||
)
|
||||
)
|
||||
);
|
||||
try {
|
||||
arangodb.db._collection("_graphs").remove("_graphs/bla3")
|
||||
} catch (err) {
|
||||
}
|
||||
graph._create(
|
||||
"bla3",
|
||||
graph.edgeDefinitions(
|
||||
graph._undirectedRelationDefinition("relationName", "vertexC1"),
|
||||
graph._directedRelationDefinition("relationName2",
|
||||
["vertexC1", "vertexC2"], ["vertexC3", "vertexC4"]
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
var a = graph._graph("bla3");
|
||||
var a = graph._graph("bla3");
|
||||
|
||||
assertTrue(a.__vertexCollections.hasOwnProperty('vertexC1'));
|
||||
assertTrue(a.__vertexCollections.hasOwnProperty('vertexC2'));
|
||||
assertTrue(a.__vertexCollections.hasOwnProperty('vertexC3'));
|
||||
assertTrue(a.__vertexCollections.hasOwnProperty('vertexC4'));
|
||||
assertTrue(a.__edgeCollections.hasOwnProperty('relationName'));
|
||||
assertTrue(a.__edgeCollections.hasOwnProperty('relationName2'));
|
||||
assertEqual(a.__edgeDefinitions, [
|
||||
{
|
||||
"collection" : "relationName",
|
||||
"from" : [
|
||||
"vertexC1"
|
||||
],
|
||||
"to" : [
|
||||
"vertexC1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"collection" : "relationName2",
|
||||
"from" : [
|
||||
"vertexC1",
|
||||
"vertexC2"
|
||||
],
|
||||
"to" : [
|
||||
"vertexC3",
|
||||
"vertexC4"
|
||||
]
|
||||
}
|
||||
]
|
||||
);
|
||||
},
|
||||
assertTrue(a.__vertexCollections.hasOwnProperty('vertexC1'));
|
||||
assertTrue(a.__vertexCollections.hasOwnProperty('vertexC2'));
|
||||
assertTrue(a.__vertexCollections.hasOwnProperty('vertexC3'));
|
||||
assertTrue(a.__vertexCollections.hasOwnProperty('vertexC4'));
|
||||
assertTrue(a.__edgeCollections.hasOwnProperty('relationName'));
|
||||
assertTrue(a.__edgeCollections.hasOwnProperty('relationName2'));
|
||||
assertEqual(a.__edgeDefinitions, [
|
||||
{
|
||||
"collection" : "relationName",
|
||||
"from" : [
|
||||
"vertexC1"
|
||||
],
|
||||
"to" : [
|
||||
"vertexC1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"collection" : "relationName2",
|
||||
"from" : [
|
||||
"vertexC1",
|
||||
"vertexC2"
|
||||
],
|
||||
"to" : [
|
||||
"vertexC3",
|
||||
"vertexC4"
|
||||
]
|
||||
}
|
||||
]
|
||||
);
|
||||
},
|
||||
|
||||
test_get_graph_without_hit : function () {
|
||||
var msg;
|
||||
try {
|
||||
var a = graph._graph("bla4");
|
||||
} catch (e) {
|
||||
msg = e;
|
||||
}
|
||||
assertEqual(msg, "graph bla4 does not exists.");
|
||||
}
|
||||
test_get_graph_without_hit : function () {
|
||||
var msg;
|
||||
try {
|
||||
var a = graph._graph("bla4");
|
||||
} catch (e) {
|
||||
msg = e;
|
||||
}
|
||||
assertEqual(msg, "graph bla4 does not exists.");
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
@ -676,7 +676,147 @@ function GeneralGraphAQLQueriesSuite() {
|
|||
|
||||
}
|
||||
|
||||
function EdgesAndVerticesSuite() {
|
||||
|
||||
try {
|
||||
arangodb.db._collection("_graphs").remove("_graphs/blubGraph")
|
||||
} catch (err) {
|
||||
}
|
||||
var g = graph._create(
|
||||
"blubGraph",
|
||||
graph.edgeDefinitions(
|
||||
graph._undirectedRelationDefinition("edgeCollection1", "vertexCollection1"),
|
||||
graph._directedRelationDefinition("edgeCollection2",
|
||||
["vertexCollection1", "vertexCollection2"], ["vertexCollection3", "vertexCollection4"]
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
var vertexIds = [];
|
||||
var vertexId1, vertexId2;
|
||||
var edgeId1, edgeId2;
|
||||
|
||||
return {
|
||||
|
||||
test_edgeCollections : function () {
|
||||
|
||||
var edgeCollections = g._edgeCollections();
|
||||
assertEqual(edgeCollections[0].name(), 'edgeCollection1');
|
||||
assertEqual(edgeCollections[1].name(), 'edgeCollection2');
|
||||
},
|
||||
|
||||
test_vertexCollections : function () {
|
||||
|
||||
var vertexCollections = g._vertexCollections();
|
||||
assertEqual(vertexCollections[0].name(), 'vertexCollection1');
|
||||
assertEqual(vertexCollections[1].name(), 'vertexCollection2');
|
||||
assertEqual(vertexCollections[2].name(), 'vertexCollection3');
|
||||
assertEqual(vertexCollections[3].name(), 'vertexCollection4');
|
||||
},
|
||||
|
||||
test_vC_save : function () {
|
||||
var vertex = g.vertexCollection1.save({first_name: "Tom"});
|
||||
assertFalse(vertex.error);
|
||||
vertexId1 = vertex._id;
|
||||
var vertexObj = g.vertexCollection1.document(vertexId1);
|
||||
assertEqual(vertexObj.first_name, "Tom");
|
||||
},
|
||||
|
||||
test_vC_replace : function () {
|
||||
var vertex = g.vertexCollection1.replace(vertexId1, {first_name: "Tim"});
|
||||
assertFalse(vertex.error);
|
||||
var vertexObj = g.vertexCollection1.document(vertexId1);
|
||||
assertEqual(vertexObj.first_name, "Tim");
|
||||
},
|
||||
|
||||
test_vC_update : function () {
|
||||
var vertex = g.vertexCollection1.update(vertexId1, {age: 42});
|
||||
assertFalse(vertex.error);
|
||||
var vertexObj = g.vertexCollection1.document(vertexId1);
|
||||
assertEqual(vertexObj.first_name, "Tim");
|
||||
assertEqual(vertexObj.age, 42);
|
||||
},
|
||||
|
||||
test_vC_remove : function () {
|
||||
var vertex = g.vertexCollection1.remove(vertexId1);
|
||||
assertTrue(vertex);
|
||||
},
|
||||
|
||||
test_eC_save_undirected : function() {
|
||||
var vertex1 = g.vertexCollection1.save({first_name: "Tom"});
|
||||
vertexId1 = vertex1._id;
|
||||
var vertex2 = g.vertexCollection1.save({first_name: "Tim"});
|
||||
vertexId2 = vertex2._id;
|
||||
var edge = g.edgeCollection1.save(vertexId1, vertexId2, {});
|
||||
assertFalse(edge.error);
|
||||
edgeId1 = edge._id;
|
||||
g.vertexCollection1.remove(vertexId1);
|
||||
g.vertexCollection1.remove(vertexId2);
|
||||
},
|
||||
|
||||
test_eC_save_directed : function() {
|
||||
var vertex1 = g.vertexCollection2.save({first_name: "Tom"});
|
||||
vertexId1 = vertex1._id;
|
||||
var vertex2 = g.vertexCollection4.save({first_name: "Tim"});
|
||||
vertexId2 = vertex2._id;
|
||||
var edge = g.edgeCollection2.save(vertexId1, vertexId2, {});
|
||||
assertFalse(edge.error);
|
||||
edgeId2 = edge._id;
|
||||
g.vertexCollection2.remove(vertexId1);
|
||||
g.vertexCollection4.remove(vertexId2);
|
||||
},
|
||||
|
||||
test_eC_save_withError : function() {
|
||||
var vertex1 = g.vertexCollection1.save({first_name: "Tom"});
|
||||
vertexId1 = vertex1._id;
|
||||
var vertex2 = g.vertexCollection2.save({first_name: "Tim"});
|
||||
vertexId2 = vertex2._id;
|
||||
try {
|
||||
var edge = g.edgeCollection1.save(vertexId1, vertexId2, {});
|
||||
} catch (e) {
|
||||
assertEqual(e, "Edge is not allowed between " + vertexId1 + " and " + vertexId2 + ".")
|
||||
}
|
||||
g.vertexCollection1.remove(vertexId1);
|
||||
g.vertexCollection2.remove(vertexId2);
|
||||
},
|
||||
|
||||
test_eC_replace : function() {
|
||||
var edge = g.edgeCollection1.replace(edgeId1, {label: "knows"});
|
||||
assertFalse(edge.error);
|
||||
var edgeObj = g.edgeCollection1.document(edgeId1);
|
||||
assertEqual(edgeObj.label, "knows");
|
||||
assertEqual(edgeObj._id, edgeId1);
|
||||
},
|
||||
|
||||
test_eC_update : function () {
|
||||
var edge = g.edgeCollection1.update(edgeId1, {blub: "blub"});
|
||||
assertFalse(edge.error);
|
||||
var edgeObj = g.edgeCollection1.document(edgeId1);
|
||||
assertEqual(edgeObj.label, "knows");
|
||||
assertEqual(edgeObj.blub, "blub");
|
||||
assertEqual(edgeObj._id, edgeId1);
|
||||
},
|
||||
|
||||
test_eC_remove : function () {
|
||||
var edge = g.edgeCollection1.remove(edgeId1);
|
||||
assertTrue(edge);
|
||||
edge = g.edgeCollection2.remove(edgeId2);
|
||||
assertTrue(edge);
|
||||
},
|
||||
|
||||
|
||||
|
||||
dump : function() {
|
||||
db.vertexCollection1.drop();
|
||||
db.vertexCollection2.drop();
|
||||
db.vertexCollection3.drop();
|
||||
db.vertexCollection4.drop();
|
||||
db.edgeCollection1.drop();
|
||||
db.edgeCollection2.drop();
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- main
|
||||
|
@ -686,6 +826,7 @@ function GeneralGraphAQLQueriesSuite() {
|
|||
/// @brief executes the test suites
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
jsunity.run(EdgesAndVerticesSuite);
|
||||
jsunity.run(GeneralGraphCreationSuite);
|
||||
jsunity.run(GeneralGraphAQLQueriesSuite);
|
||||
|
||||
|
|
|
@ -184,7 +184,8 @@ function FILTER (list, examples) {
|
|||
|
||||
var result = [ ], i;
|
||||
|
||||
if (examples === undefined || examples === null) {
|
||||
if (examples === undefined || examples === null ||
|
||||
(Array.isArray(examples) && examples.length === 0)) {
|
||||
return list;
|
||||
}
|
||||
|
||||
|
@ -4116,6 +4117,85 @@ function GRAPH_PATHS (vertices, edgeCollection, direction, followCycles, minLeng
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief find all paths through a graph
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function GENERAL_GRAPH_PATHS (graphname, direction, followCycles, minLength, maxLength) {
|
||||
"use strict";
|
||||
|
||||
/*var searchDirection;
|
||||
direction = direction || "outbound";
|
||||
followCycles = followCycles || false;
|
||||
minLength = minLength || 0;
|
||||
maxLength = maxLength !== undefined ? maxLength : 10;
|
||||
|
||||
|
||||
var graph = DOCUMENT_HANDLE("_graph" + graphname);
|
||||
if (!graph) {
|
||||
THROW(INTERNAL.errors.ERROR_ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, "GRAPH_PATHS");
|
||||
}
|
||||
|
||||
var vertexCollections = [];
|
||||
|
||||
// validate arguments
|
||||
if (direction === "outbound") {
|
||||
searchDirection = 1;
|
||||
graph.__edgeDefinitions.forEach(function (def) {
|
||||
vertexCollections.concat(def.from);
|
||||
});
|
||||
}
|
||||
else if (direction === "inbound") {
|
||||
graph.__edgeDefinitions.forEach(function (def) {
|
||||
vertexCollections.concat(def.to);
|
||||
});
|
||||
searchDirection = 2;
|
||||
}
|
||||
else if (direction === "any") {
|
||||
graph.__edgeDefinitions.forEach(function (def) {
|
||||
vertexCollections.concat(def.to);
|
||||
vertexCollections.concat(def.from);
|
||||
});
|
||||
searchDirection = 3;
|
||||
}
|
||||
else {
|
||||
THROW(INTERNAL.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, "GRAPH_PATHS");
|
||||
}
|
||||
|
||||
if (minLength < 0 || maxLength < 0 || minLength > maxLength) {
|
||||
THROW(INTERNAL.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, "GRAPH_PATHS");
|
||||
}
|
||||
|
||||
|
||||
|
||||
var searchAttributes = {
|
||||
//edgeCollection : COLLECTION(edgeCollection),
|
||||
minLength : minLength,
|
||||
maxLength : maxLength,
|
||||
direction : searchDirection,
|
||||
followCycles : followCycles
|
||||
};
|
||||
|
||||
var result = [ ];
|
||||
var n = vertices.length, i, j;
|
||||
for (i = 0; i < n; ++i) {
|
||||
var vertex = vertices[i];
|
||||
var visited = { };
|
||||
|
||||
visited[vertex._id] = true;
|
||||
//GRAPH_SUBNODES (searchAttributes, vertexId, visited, edges, vertices, level) {
|
||||
var connected = GRAPH_SUBNODES(searchAttributes, vertex._id, visited, [ ], [ vertex ], 0);
|
||||
for (j = 0; j < connected.length; ++j) {
|
||||
result.push(connected[j]);
|
||||
}
|
||||
}
|
||||
|
||||
return result;*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief visitor callback function for traversal
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -4474,7 +4554,97 @@ function GRAPH_EDGES (edgeCollection,
|
|||
}
|
||||
|
||||
return FILTER(result, examples);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief return connected edges
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function GENERAL_GRAPH_EDGES (graphname,
|
||||
startvertex,
|
||||
direction,
|
||||
edgeexamples,
|
||||
collectionRestrictions) {
|
||||
"use strict";
|
||||
|
||||
|
||||
//check graph exists and load edgeDefintions
|
||||
var graph = DOCUMENT_HANDLE("_graphs/" + graphname);
|
||||
if (!graph) {
|
||||
THROW(INTERNAL.errors.ERROR_GRAPH_INVALID_GRAPH, "EDGES");
|
||||
}
|
||||
|
||||
//check startvertex exists and parse identifier
|
||||
var start = DOCUMENT_HANDLE(startvertex);
|
||||
if (!start) {
|
||||
THROW(INTERNAL.errors.ERROR_ARANGO_DOCUMENT_NOT_FOUND, "EDGES");
|
||||
}
|
||||
var startCollection = startvertex.split("/")[0];
|
||||
|
||||
var edgeCollections = [];
|
||||
|
||||
// validate direction and create edgeCollection array.
|
||||
if (direction === "outbound") {
|
||||
graph.edgeDefinitions.forEach(function (def) {
|
||||
if (def.from.indexOf(startCollection) !== -1 &&
|
||||
edgeCollections.indexOf(def.collection) === -1) {
|
||||
edgeCollections.push(def.collection);
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (direction === "inbound") {
|
||||
graph.edgeDefinitions.forEach(function (def) {
|
||||
if (def.to.indexOf(startCollection) !== -1 &&
|
||||
edgeCollections.indexOf(def.collection) === -1) {
|
||||
edgeCollections.push(def.collection);
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (direction === "any") {
|
||||
graph.edgeDefinitions.forEach(function (def) {
|
||||
if ((def.from.indexOf(startCollection) !== -1 ||
|
||||
def.to.indexOf(startCollection) !== -1) &&
|
||||
edgeCollections.indexOf(def.collection) === -1) {
|
||||
edgeCollections.push(def.collection);
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
THROW(INTERNAL.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, "EDGES");
|
||||
}
|
||||
|
||||
if (collectionRestrictions) {
|
||||
if (typeof collectionRestrictions === "string") {
|
||||
collectionRestrictions = [collectionRestrictions];
|
||||
}
|
||||
edgeCollections.forEach(function (e) {
|
||||
if (collectionRestrictions.indexOf(e) === -1) {
|
||||
edgeCollections.splice(edgeCollections.indexOf(e));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//Now get the result.
|
||||
|
||||
var result = [];
|
||||
|
||||
edgeCollections.forEach(function (c) {
|
||||
c = COLLECTION(c);
|
||||
if (direction === "outbound") {
|
||||
result = result.concat(c.outEdges(startvertex));
|
||||
}
|
||||
else if (direction === "inbound") {
|
||||
result = result.concat(c.inEdges(startvertex));
|
||||
}
|
||||
else if (direction === "any") {
|
||||
result = result.concat(c.edges(startvertex));
|
||||
}
|
||||
});
|
||||
|
||||
return FILTER(result, edgeexamples);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief return connected neighbors
|
||||
|
@ -4639,6 +4809,7 @@ exports.GRAPH_SHORTEST_PATH = GRAPH_SHORTEST_PATH;
|
|||
exports.GRAPH_TRAVERSAL = GRAPH_TRAVERSAL;
|
||||
exports.GRAPH_TRAVERSAL_TREE = GRAPH_TRAVERSAL_TREE;
|
||||
exports.GRAPH_EDGES = GRAPH_EDGES;
|
||||
exports.GENERAL_GRAPH_EDGES = GENERAL_GRAPH_EDGES;
|
||||
exports.GRAPH_NEIGHBORS = GRAPH_NEIGHBORS;
|
||||
exports.NOT_NULL = NOT_NULL;
|
||||
exports.FIRST_LIST = FIRST_LIST;
|
||||
|
|
|
@ -0,0 +1,211 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief tests for query language, graph functions
|
||||
///
|
||||
/// @file
|
||||
///
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2010-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
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var jsunity = require("jsunity");
|
||||
var db = require("org/arangodb").db;
|
||||
var graph = require("org/arangodb/general-graph");
|
||||
var errors = require("internal").errors;
|
||||
var helper = require("org/arangodb/aql-helper");
|
||||
var getQueryResults = helper.getQueryResults;
|
||||
var assertQueryError = helper.assertQueryError;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test suite for EDGES() function
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function ahuacatlQueryGeneralEdgesTestSuite () {
|
||||
var vertex = null;
|
||||
var edge = null;
|
||||
|
||||
return {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief set up
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
setUp : function () {
|
||||
db._drop("UnitTestsAhuacatlVertex1");
|
||||
db._drop("UnitTestsAhuacatlVertex2");
|
||||
db._drop("UnitTestsAhuacatlVertex3");
|
||||
db._drop("UnitTestsAhuacatlVertex4");
|
||||
db._drop("UnitTestsAhuacatlEdge1");
|
||||
db._drop("UnitTestsAhuacatlEdge2");
|
||||
|
||||
vertex1 = db._create("UnitTestsAhuacatlVertex1");
|
||||
vertex2 = db._create("UnitTestsAhuacatlVertex2");
|
||||
vertex3 = db._create("UnitTestsAhuacatlVertex3");
|
||||
vertex4 = db._create("UnitTestsAhuacatlVertex4");
|
||||
edge1 = db._createEdgeCollection("UnitTestsAhuacatlEdge1");
|
||||
edge2 = db._createEdgeCollection("UnitTestsAhuacatlEdge2");
|
||||
|
||||
vertex1.save({ _key: "v1" });
|
||||
vertex1.save({ _key: "v2" });
|
||||
vertex2.save({ _key: "v3" });
|
||||
vertex2.save({ _key: "v4" });
|
||||
vertex3.save({ _key: "v5" });
|
||||
vertex3.save({ _key: "v6" });
|
||||
vertex4.save({ _key: "v7" });
|
||||
|
||||
function makeEdge (from, to, collection) {
|
||||
collection.save(from, to, { what: from.split("/")[1] + "->" + to.split("/")[1] });
|
||||
}
|
||||
|
||||
makeEdge("UnitTestsAhuacatlVertex1/v1", "UnitTestsAhuacatlVertex1/v2", edge1);
|
||||
makeEdge("UnitTestsAhuacatlVertex1/v2", "UnitTestsAhuacatlVertex1/v1", edge1);
|
||||
makeEdge("UnitTestsAhuacatlVertex1/v1", "UnitTestsAhuacatlVertex3/v5", edge2);
|
||||
makeEdge("UnitTestsAhuacatlVertex1/v2", "UnitTestsAhuacatlVertex3/v5", edge2);
|
||||
makeEdge("UnitTestsAhuacatlVertex2/v3", "UnitTestsAhuacatlVertex3/v6", edge2);
|
||||
makeEdge("UnitTestsAhuacatlVertex2/v4", "UnitTestsAhuacatlVertex4/v7", edge2);
|
||||
makeEdge("UnitTestsAhuacatlVertex2/v3", "UnitTestsAhuacatlVertex3/v5", edge2);
|
||||
|
||||
try {
|
||||
db._collection("_graphs").remove("_graphs/bla3")
|
||||
} catch (err) {
|
||||
}
|
||||
graph._create(
|
||||
"bla3",
|
||||
graph.edgeDefinitions(
|
||||
graph._undirectedRelationDefinition("UnitTestsAhuacatlEdge1", "UnitTestsAhuacatlVertex1"),
|
||||
graph._directedRelationDefinition("UnitTestsAhuacatlEdge2",
|
||||
["UnitTestsAhuacatlVertex1", "UnitTestsAhuacatlVertex2"],
|
||||
["UnitTestsAhuacatlVertex3", "UnitTestsAhuacatlVertex4"]
|
||||
)
|
||||
)
|
||||
);
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief tear down
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
tearDown : function () {
|
||||
db._drop("UnitTestsAhuacatlVertex1");
|
||||
db._drop("UnitTestsAhuacatlVertex2");
|
||||
db._drop("UnitTestsAhuacatlVertex3");
|
||||
db._drop("UnitTestsAhuacatlVertex4");
|
||||
db._drop("UnitTestsAhuacatlEdge1");
|
||||
db._drop("UnitTestsAhuacatlEdge2");
|
||||
db._collection("_graphs").remove("_graphs/bla3");
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief checks EDGES()
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//graphname,
|
||||
//startvertex,
|
||||
//direction,
|
||||
//edgeexamples,
|
||||
//collectionRestrictions
|
||||
|
||||
|
||||
testEdgesAny : function () {
|
||||
var actual;
|
||||
|
||||
actual = getQueryResults("FOR e IN GRAPH_EDGES('bla3', 'UnitTestsAhuacatlVertex1/v1', 'any') SORT e.what RETURN e.what");
|
||||
assertEqual(actual, [ "v1->v2", "v1->v5", "v2->v1" ]);
|
||||
|
||||
actual = getQueryResults("FOR e IN GRAPH_EDGES('bla3', 'UnitTestsAhuacatlVertex1/v1', 'any' , [] , ['UnitTestsAhuacatlEdge1']) SORT e.what RETURN e.what");
|
||||
assertEqual(actual, [ "v1->v2", "v2->v1" ]);
|
||||
|
||||
actual = getQueryResults("FOR e IN GRAPH_EDGES('bla3', 'UnitTestsAhuacatlVertex1/v1', 'any' , [{'what' : 'v2->v1'}]) SORT e.what RETURN e.what");
|
||||
assertEqual(actual, [ "v2->v1" ]);
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief checks EDGES()
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/*testEdgesIn : function () {
|
||||
var actual;
|
||||
|
||||
actual = getQueryResults("FOR e IN GRAPH_EDGES(UnitTestsAhuacatlEdge, 'UnitTestsAhuacatlVertex/v1', 'inbound') SORT e.what RETURN e.what");
|
||||
assertEqual(actual, [ ]);
|
||||
|
||||
actual = getQueryResults("FOR e IN GRAPH_EDGES(UnitTestsAhuacatlEdge, 'UnitTestsAhuacatlVertex/v2', 'inbound') SORT e.what RETURN e.what");
|
||||
assertEqual(actual, [ "v1->v2", "v4->v2" ]);
|
||||
|
||||
actual = getQueryResults("FOR e IN GRAPH_EDGES(UnitTestsAhuacatlEdge, 'UnitTestsAhuacatlVertex/v3', 'inbound') SORT e.what RETURN e.what");
|
||||
assertEqual(actual, [ "v1->v3", "v2->v3", "v6->v3", "v7->v3" ]);
|
||||
|
||||
actual = getQueryResults("FOR e IN GRAPH_EDGES(UnitTestsAhuacatlEdge, 'UnitTestsAhuacatlVertex/v3', 'inbound') SORT e.what RETURN e.what");
|
||||
assertEqual(actual, [ "v1->v3", "v2->v3", "v6->v3", "v7->v3" ]);
|
||||
|
||||
actual = getQueryResults("FOR e IN GRAPH_EDGES(UnitTestsAhuacatlEdge, 'UnitTestsAhuacatlVertex/v8', 'inbound') SORT e.what RETURN e.what");
|
||||
assertEqual(actual, [ ]);
|
||||
|
||||
actual = getQueryResults("FOR e IN GRAPH_EDGES(UnitTestsAhuacatlEdge, 'UnitTestsAhuacatlVertex/thefox', 'inbound') SORT e.what RETURN e.what");
|
||||
assertEqual(actual, [ ]);
|
||||
|
||||
assertQueryError(errors.ERROR_ARANGO_COLLECTION_NOT_FOUND.code, "FOR e IN GRAPH_EDGES(UnitTestsAhuacatlEdge, 'thefox/thefox', 'inbound') SORT e.what RETURN e.what");
|
||||
},
|
||||
*/
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief checks EDGES()
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/*testEdgesOut : function () {
|
||||
var actual;
|
||||
|
||||
actual = getQueryResults("FOR e IN GRAPH_EDGES(UnitTestsAhuacatlEdge, 'UnitTestsAhuacatlVertex/v1', 'outbound') SORT e.what RETURN e.what");
|
||||
assertEqual(actual, [ "v1->v2", "v1->v3" ]);
|
||||
|
||||
actual = getQueryResults("FOR e IN GRAPH_EDGES(UnitTestsAhuacatlEdge, 'UnitTestsAhuacatlVertex/v2', 'outbound') SORT e.what RETURN e.what");
|
||||
assertEqual(actual, [ "v2->v3" ]);
|
||||
|
||||
actual = getQueryResults("FOR e IN GRAPH_EDGES(UnitTestsAhuacatlEdge, 'UnitTestsAhuacatlVertex/v3', 'outbound') SORT e.what RETURN e.what");
|
||||
assertEqual(actual, [ "v3->v4", "v3->v6", "v3->v7" ]);
|
||||
|
||||
actual = getQueryResults("FOR e IN GRAPH_EDGES(UnitTestsAhuacatlEdge, 'UnitTestsAhuacatlVertex/v8', 'outbound') SORT e.what RETURN e.what");
|
||||
assertEqual(actual, [ ]);
|
||||
|
||||
actual = getQueryResults("FOR e IN GRAPH_EDGES(UnitTestsAhuacatlEdge, 'UnitTestsAhuacatlVertex/v5', 'outbound') SORT e.what RETURN e.what");
|
||||
assertEqual(actual, [ ]);
|
||||
|
||||
actual = getQueryResults("FOR e IN GRAPH_EDGES(UnitTestsAhuacatlEdge, 'UnitTestsAhuacatlVertex/thefox', 'outbound') SORT e.what RETURN e.what");
|
||||
assertEqual(actual, [ ]);
|
||||
|
||||
assertQueryError(errors.ERROR_ARANGO_COLLECTION_NOT_FOUND.code, "FOR e IN GRAPH_EDGES(UnitTestsAhuacatlEdge, 'thefox/thefox', 'outbound') SORT e.what RETURN e.what");
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief executes the test suite
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
jsunity.run(ahuacatlQueryGeneralEdgesTestSuite);
|
||||
|
||||
return jsunity.done();
|
||||
|
||||
// Local Variables:
|
||||
// mode: outline-minor
|
||||
// outline-regexp: "^\\(/// @brief\\|/// @addtogroup\\|// --SECTION--\\|/// @page\\|/// @}\\)"
|
||||
// End:
|
Loading…
Reference in New Issue