Search in sources :

Example 31 with ResponseEntity

use of org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity in project neo4j by neo4j.

the class TransactionTestIT method execute_multiple_statements.

@Test
@Documented("Execute multiple statements\n" + "\n" + "You can send multiple Cypher statements in the same request.\n" + "The response will contain the result of each statement.")
public void execute_multiple_statements() throws JsonParseException {
    // Document
    ResponseEntity response = gen.get().expectedStatus(200).payload(quotedJson("{ 'statements': [ { 'statement': 'CREATE (n) RETURN id(n)' }, " + "{ 'statement': 'CREATE (n $props) RETURN n', " + "'parameters': { 'props': { 'name': 'My Node' } } } ] }")).post(txCommitUri());
    // Then
    Map<String, Object> result = jsonToMap(response.entity());
    assertNoErrors(result);
    Integer id = resultCell(result, 0, 0);
    verifyNodeExists(id);
    assertThat(response.entity()).contains("My Node");
}
Also used : ResponseEntity(org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity) Documented(org.neo4j.annotations.documented.Documented) Test(org.junit.jupiter.api.Test)

Example 32 with ResponseEntity

use of org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity in project neo4j by neo4j.

the class TransactionTestIT method return_results_in_graph_format.

@Test
@Documented("Return results in graph format\n" + "\n" + "If you want to understand the graph structure of nodes and relationships returned by your query,\n" + "you can specify the \"graph\" results data format. For example, this is useful when you want to visualise the\n" + "graph structure. The format collates all the nodes and relationships from all columns of the result,\n" + "and also flattens collections of nodes and relationships, including paths.")
public void return_results_in_graph_format() throws JsonParseException {
    // Document
    ResponseEntity response = gen.get().expectedStatus(200).payload(quotedJson("{'statements':[{'statement':" + "'CREATE ( bike:Bike { weight: 10 } ) " + "CREATE ( frontWheel:Wheel { spokes: 3 } ) " + "CREATE ( backWheel:Wheel { spokes: 32 } ) " + "CREATE p1 = (bike)-[:HAS { position: 1 } ]->(frontWheel) " + "CREATE p2 = (bike)-[:HAS { position: 2 } ]->(backWheel) " + "RETURN bike, p1, p2', " + "'resultDataContents': ['row','graph']}] }")).post(txCommitUri());
    // Then
    Map<String, Object> result = jsonToMap(response.entity());
    assertNoErrors(result);
    Map<String, List<Object>> row = graphRow(result, 0);
    assertEquals(3, row.get("nodes").size());
    assertEquals(2, row.get("relationships").size());
}
Also used : ResponseEntity(org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity) ArrayList(java.util.ArrayList) List(java.util.List) Documented(org.neo4j.annotations.documented.Documented) Test(org.junit.jupiter.api.Test)

Example 33 with ResponseEntity

use of org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity in project neo4j by neo4j.

the class TransactionTestIT method execute_statements_in_an_open_transaction.

@Test
@Documented("Execute statements in an open transaction\n" + "\n" + "Given that you have an open transaction, you can make a number of requests, each of which executes additional\n" + "statements, and keeps the transaction open by resetting the transaction timeout.")
public void execute_statements_in_an_open_transaction() throws JsonParseException {
    // Given
    String location = POST(txUri()).location();
    // Document
    ResponseEntity response = gen.get().expectedStatus(200).payload(quotedJson("{ 'statements': [ { 'statement': 'CREATE (n) RETURN n' } ] }")).post(location);
    // Then
    Map<String, Object> result = jsonToMap(response.entity());
    assertThat(result).containsKey("transaction");
    assertNoErrors(result);
}
Also used : ResponseEntity(org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity) Documented(org.neo4j.annotations.documented.Documented) Test(org.junit.jupiter.api.Test)

Example 34 with ResponseEntity

use of org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity in project neo4j by neo4j.

the class TransactionTestIT method begin_a_transaction.

@Test
@Documented("Begin a transaction\n" + "\n" + "You begin a new transaction by posting zero or more Cypher statements\n" + "to the transaction endpoint. The server will respond with the result of\n" + "your statements, as well as the location of your open transaction.")
public void begin_a_transaction() throws JsonParseException {
    // Document
    ResponseEntity response = gen.get().expectedStatus(201).payload(quotedJson("{ 'statements': [ { 'statement': 'CREATE (n $props) RETURN n', " + "'parameters': { 'props': { 'name': 'My Node' } } } ] }")).post(txUri());
    // Then
    Map<String, Object> result = jsonToMap(response.entity());
    assertNoErrors(result);
    Map<String, Object> node = resultCell(result, 0, 0);
    assertThat(node.get("name")).isEqualTo("My Node");
}
Also used : ResponseEntity(org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity) Documented(org.neo4j.annotations.documented.Documented) Test(org.junit.jupiter.api.Test)

Example 35 with ResponseEntity

use of org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity in project neo4j by neo4j.

the class TransactionTestIT method begin_and_commit_a_transaction_in_one_request.

@Test
@Documented("Begin and commit a transaction in one request\n" + "\n" + "If there is no need to keep a transaction open across multiple HTTP requests, you can begin a transaction,\n" + "execute statements, and commit with just a single HTTP request.")
public void begin_and_commit_a_transaction_in_one_request() throws JsonParseException {
    // Document
    ResponseEntity response = gen.get().expectedStatus(200).payload(quotedJson("{ 'statements': [ { 'statement': 'CREATE (n) RETURN id(n)' } ] }")).post(txCommitUri());
    // Then
    Map<String, Object> result = jsonToMap(response.entity());
    assertNoErrors(result);
    Integer id = resultCell(result, 0, 0);
    verifyNodeExists(id);
}
Also used : ResponseEntity(org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity) Documented(org.neo4j.annotations.documented.Documented) Test(org.junit.jupiter.api.Test)

Aggregations

ResponseEntity (org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity)36 Test (org.junit.Test)22 Documented (org.neo4j.kernel.impl.annotations.Documented)20 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)12 Test (org.junit.jupiter.api.Test)12 Documented (org.neo4j.annotations.documented.Documented)12 ArrayList (java.util.ArrayList)6 List (java.util.List)5 HTTP (org.neo4j.test.server.HTTP)4 Node (org.neo4j.graphdb.Node)3 Transaction (org.neo4j.graphdb.Transaction)3 Map (java.util.Map)2 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)2 JsonHelper.jsonToMap (org.neo4j.server.rest.domain.JsonHelper.jsonToMap)2 Matchers.containsString (org.hamcrest.Matchers.containsString)1