-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnodez-test.js
109 lines (100 loc) · 3.32 KB
/
nodez-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
var G = require('nodez/nodez.js')
saveNode = function(d) {
var DBROUTE="http://localhost:7474/db/data/cypher/"
cypher={
"query":"create (n:"+d.ExtractNeo4jData().label+" { props } ) return id(n),n",
"params": {
"props": d.ExtractNeo4jData()
}
}
console.log(JSON.stringify(cypher))
options={
url:DBROUTE,
method:"POST",
headers:{'content-type':'application/json'},
body:JSON.stringify(cypher)
}
console.log("Calling Neo4j broker with:"+options)
var request = require('request');
request(options,function(error,response,body) {
if (!error) {
switch (response.statusCode) {
case 200: {
console.log("OK "+response.statusCode+":"+options.url+":Neo4j results="+body)
return body
} // end HTTP 200
default: {
console.log("!OK "+response.statusCode+":"+options.url+":Neo4j results="+body)
// res.status(404)
// res.render('error.jade',data={title:"Not found",msg:body})
break
}
}
}
else {
console.log("!OK "+response.statusCode+":"+options.url+":Neo4j results="+body)
}
})
}
var mac=[]
mac["start"]=[]
mac["start"]["go"]=function () {deleteAll()}
mac["addType"]=[]
mac["addType"]["go"]=function () {
d=G.newTypeNode('Cluster',{template:"{'description':'string','objectives':'string'}"})
e=saveNode(d)
// console.log(typeof d)
// d.cypherSave(d,_CB_nodeSave)
// d=G.newTypeNode('Business Attribute',{template:"{'description':'string','objectives':'string'}"})
// console.log(typeof d)
// d.cypherSave(d,_CB_nodeSave)
}
var _CB_nodeSaved = function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log("OK "+response.statusCode+":"+options.url+":Neo4j results="+body)
}
else {
console.log("!OK "+response.statusCode+":"+options.url+":Neo4j results="+body)
}
}
var _CB_deleteAll = function (error, response, body) {
console.log("back...")
if (!error && response.statusCode == 200) {
console.log("OK "+response.statusCode+":"+options.url+":Neo4j results="+body)
mac["addType"]["go"]()
}
else {
console.log("!OK "+response.statusCode+":"+options.url+":Neo4j results="+body)
}
// callBack(response.statusCode,body)
}
deleteAll = function () {
var DBROUTE="http://localhost:7474/db/data/cypher/"
cypher={
"query":"match (m) optional match (m)-[r]->() delete m,r",
"params": {
}
}
console.log(JSON.stringify(cypher))
options={
url:DBROUTE,
method:"POST",
headers:{'content-type':'application/json'},
body:JSON.stringify(cypher)
}
console.log("Calling Neo4j broker with:"+JSON.stringify(options))
var request = require('request');
console.log('Http async')
request(options,_CB_deleteAll)
}
startTestSequence=function() {
// deleteAll()
mac["start"]["go"]()
}
exports["Save a type"]=function(test) {
// statemac(mac,"start","go")
// startTestSequence()
d=G.newTypeNode('Cluster',{template:"{'description':'string','objectives':'string'}"})
e=saveNode(d)
test.done()
}