1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
19 var srv
= new Neo4jServer
22 print
"# Test local\n"
24 var client
= new Neo4jClient("http://localhost:7474")
27 var andres
= new NeoNode
28 andres
.labels
.add_all
(["PERSON", "MALE"])
29 andres
["name"] = "Andres"
31 andres
["status"] = true
32 andres
["groups"] = new JsonArray.from
([1, 2, 3])
36 client
.save_node
(andres
)
37 assert andres
.is_linked
38 var andres_url
= andres
.url
.to_s
41 var res1
= client
.load_node
(andres_url
)
43 print res1
["name"].to_s
44 print res1
["age"].to_s
45 print res1
["status"].to_s
46 print res1
["groups"].to_json
47 print res1
.labels
.join
(" ")
48 assert res1
.out_edges
.is_empty
50 # Create a second node
51 var kate
= new NeoNode
52 kate
.labels
.add_all
(["PERSON", "FEMALE"])
55 kate
["status"] = false
56 client
.save_node
(kate
)
58 var kate_url
= kate
.url
.to_s
59 var res2
= client
.load_node
(kate_url
)
62 var loves
= new NeoEdge(andres
, "LOVES", kate
)
64 client
.save_edge
(loves
)
65 assert loves
.is_linked
66 var loves_url
= loves
.url
.to_s
69 assert loves
.from
== andres
70 assert loves
.from
== res1
71 assert loves
.to
== kate
72 assert loves
.to
== res2
75 var res3
= client
.load_edge
(loves_url
)
77 print res3
.rel_type
.to_s
78 print res3
["since"].to_s
81 print
"{andres["name"].to_s} LOVES {andres.out_nodes("LOVES").first["name"].to_s}"
82 print
"{kate["name"].to_s} IS LOVED BY {kate.in_nodes("LOVES").first["name"].to_s}"
84 print
"\n# Test lazy\n"
86 client
= new Neo4jClient("http://localhost:7474/")
90 var res4
= client
.load_node
(andres_url
)
92 print res4
["name"].to_s
93 print res4
["age"].to_s
94 print res4
["status"].to_s
95 print res4
["groups"].to_json
96 print res4
.labels
.join
(" ")
97 assert res4
.in_edges
.is_empty
98 assert not res4
.out_edges
.is_empty
101 var res5
= client
.load_node
(kate_url
)
102 assert res5
.is_linked
103 print res5
["name"].to_s
104 print res5
["age"].to_s
105 print res5
["status"].to_s
106 print res5
.labels
.join
(" ")
107 assert not res5
.in_edges
.is_empty
108 assert res5
.out_edges
.is_empty
111 var res6
= client
.load_edge
(loves_url
)
112 assert res6
.is_linked
113 print res6
.rel_type
.to_s
114 print res6
["since"].to_s
115 print
"{res4["name"].to_s} LOVES {res4.out_nodes("LOVES").first["name"].to_s}"
116 print
"{res5["name"].to_s} IS LOVED BY {res5.in_nodes("LOVES").first["name"].to_s}"
119 var query
= (new CypherQuery).
120 nmatch
("(n: MALE)-[r: LOVES]->(m)").
121 nwhere
("n.name = 'Andres'").
122 nand
("n.key = {key}").
124 var res7
= client
.cypher
(query
)
125 assert not res7
.as(JsonObject)["data"].as(JsonArray).is_empty