use of org.neo4j.kernel.impl.annotations.Documented in project neo4j by neo4j.
the class CypherIT method send_query_to_create_multipe_nodes_from_a_map.
@Test
@Documented("Create multiple nodes with properties using Cypher. See the request for the parameter sent " + "with the query.")
@Title("Create multiple nodes with properties")
@Graph
public void send_query_to_create_multipe_nodes_from_a_map() throws Exception {
data.get();
String script = "UNWIND {props} AS properties CREATE (n:Person) SET n = properties RETURN n";
String params = "\"props\" : [ { \"name\" : \"Andres\", \"position\" : \"Developer\" }, { \"name\" : \"Michael\", \"position\" : \"Developer\" } ]";
String response = cypherRestCall(script, Status.OK, params);
assertTrue(response.contains("name"));
assertTrue(response.contains("Michael"));
assertTrue(response.contains("Andres"));
}
use of org.neo4j.kernel.impl.annotations.Documented in project neo4j by neo4j.
the class CypherIT method send_queries_with_parameters.
@Test
@Title("Use parameters")
@Documented("Cypher supports queries with parameters which are submitted as JSON.")
@Graph(value = { "I know you" }, autoIndexNodes = true)
public void send_queries_with_parameters() throws Exception {
data.get();
String script = "MATCH (x {name: {startName}})-[r]-(friend) WHERE friend" + ".name = {name} RETURN TYPE(r)";
String response = cypherRestCall(script, Status.OK, Pair.of("startName", "I"), Pair.of("name", "you"));
assertEquals(2, (jsonToMap(response)).size());
assertTrue(response.contains("know"));
assertTrue(response.contains("data"));
}
use of org.neo4j.kernel.impl.annotations.Documented in project neo4j by neo4j.
the class CypherIT method nested_results.
@Test
@Documented("When sending queries that\n" + "return nested results like list and maps,\n" + "these will get serialized into nested JSON representations\n" + "according to their types.")
@Graph(value = { "I know you" }, autoIndexNodes = true)
public void nested_results() throws Exception {
data.get();
String script = "MATCH (n) WHERE n.name in ['I', 'you'] RETURN collect(n.name)";
String response = cypherRestCall(script, Status.OK);
System.out.println();
Map<String, Object> resultMap = jsonToMap(response);
assertEquals(2, resultMap.size());
assertThat(response, anyOf(containsString("\"I\",\"you\""), containsString("\"you\",\"I\""), containsString("\"I\", \"you\""), containsString("\"you\", \"I\"")));
}
use of org.neo4j.kernel.impl.annotations.Documented in project neo4j by neo4j.
the class CypherIT method setAllPropertiesUsingMap.
@Test
@Title("Set all properties on a node using Cypher")
@Documented("Set all properties on a node.")
@Graph
public void setAllPropertiesUsingMap() throws Exception {
data.get();
String script = "CREATE (n:Person { name: 'this property is to be deleted' } ) SET n = { props } RETURN n";
String params = "\"props\" : { \"position\" : \"Developer\", \"firstName\" : \"Michael\", \"awesome\" : true, \"children\" : 3 }";
String response = cypherRestCall(script, Status.OK, params);
assertTrue(response.contains("firstName"));
assertTrue(response.contains("Michael"));
assertTrue(!response.contains("name"));
assertTrue(!response.contains("deleted"));
}
use of org.neo4j.kernel.impl.annotations.Documented in project neo4j by neo4j.
the class TransactionTest method reset_transaction_timeout_of_an_open_transaction.
@Test
@Documented("Reset transaction timeout of an open transaction\n" + "\n" + "Every orphaned transaction is automatically expired after a period of inactivity. This may be prevented\n" + "by resetting the transaction timeout.\n" + "\n" + "The timeout may be reset by sending a keep-alive request to the server that executes an empty list of statements.\n" + "This request will reset the transaction timeout and return the new time at which the transaction will\n" + "expire as an RFC1123 formatted timestamp value in the ``transaction'' section of the response.")
public void reset_transaction_timeout_of_an_open_transaction() throws JsonParseException, ParseException, InterruptedException {
// Given
HTTP.Response initialResponse = POST(getDataUri() + "transaction");
String location = initialResponse.location();
long initialExpirationTime = expirationTime(jsonToMap(initialResponse.rawContent()));
// This generous wait time is necessary to compensate for limited resolution of RFC 1123 timestamps
// and the fact that the system clock is allowed to run "backwards" between threads
// (cf. http://stackoverflow.com/questions/2978598)
//
Thread.sleep(3000);
// Document
ResponseEntity response = gen.get().expectedStatus(200).payload(quotedJson("{ 'statements': [ ] }")).post(location);
// Then
Map<String, Object> result = jsonToMap(response.entity());
assertNoErrors(result);
long newExpirationTime = expirationTime(result);
assertTrue("Expiration time was not increased", newExpirationTime > initialExpirationTime);
}
Aggregations