contracts: change the contract syntax
[nit.git] / tests / test_neo4j.nit
index f8cbd4b..d240047 100644 (file)
 
 import neo4j
 
-var key = get_time
-
-var srv = new Neo4jServer
-srv.start_quiet
+# key used to loosely assume unicity and prevent conflicting db accesses
+var key = "NIT_TESTING_ID".environ.to_i
 
 print "# Test local\n"
 
-var client = new Neo4jClient("http://localhost:7474")
+var client = new Neo4jClient("http://neo4j:7474")
 assert client.is_ok
 
+# Clear the previous objects, if any
+client.cypher(
+       new CypherQuery.from_string(
+               "MATCH (n) WHERE n.key = \{key\} OPTIONAL MATCH n-[r]-() DELETE r, n"
+       ).set("key", key)
+)
+
 var andres = new NeoNode
 andres.labels.add_all(["PERSON", "MALE"])
 andres["name"] = "Andres"
@@ -43,7 +48,7 @@ assert res1.is_linked
 print res1["name"].to_s
 print res1["age"].to_s
 print res1["status"].to_s
-print res1["groups"].to_s
+print res1["groups"].to_json
 print res1.labels.join(" ")
 assert res1.out_edges.is_empty
 
@@ -83,7 +88,7 @@ print "{kate["name"].to_s} IS LOVED BY {kate.in_nodes("LOVES").first["name"].to_
 
 print "\n# Test lazy\n"
 
-client = new Neo4jClient("http://localhost:7474")
+client = new Neo4jClient("http://neo4j:7474/")
 assert client.is_ok
 
 # Read Andres
@@ -92,7 +97,7 @@ assert res4.is_linked
 print res4["name"].to_s
 print res4["age"].to_s
 print res4["status"].to_s
-print res4["groups"].to_s
+print res4["groups"].to_json
 print res4.labels.join(" ")
 assert res4.in_edges.is_empty
 assert not res4.out_edges.is_empty
@@ -119,8 +124,9 @@ print "{res5["name"].to_s} IS LOVED BY {res5.in_nodes("LOVES").first["name"].to_
 var query = (new CypherQuery).
        nmatch("(n: MALE)-[r: LOVES]->(m)").
        nwhere("n.name = 'Andres'").
-       nand("n.key = {key}").
-       nreturn("n, r, m")
+       nand("n.key = \{key\}").
+       nreturn("n, r, m").
+       set("key", key)
 var res7 = client.cypher(query)
-assert not res7.as(JsonObject)["data"].as(JsonArray).is_empty
+assert res7.as(JsonObject)["data"].as(JsonArray).length == 1