Search in sources :

Example 16 with Documented

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"));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Graph(org.neo4j.test.GraphDescription.Graph) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test) Title(org.neo4j.test.TestData.Title)

Example 17 with Documented

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\"")));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Graph(org.neo4j.test.GraphDescription.Graph) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Example 18 with Documented

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"));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Graph(org.neo4j.test.GraphDescription.Graph) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test) Title(org.neo4j.test.TestData.Title)

Example 19 with Documented

use of org.neo4j.kernel.impl.annotations.Documented in project neo4j by neo4j.

the class TransactionTest 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(getDataUri() + "transaction").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, hasKey("transaction"));
    assertNoErrors(result);
}
Also used : ResponseEntity(org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Example 20 with Documented

use of org.neo4j.kernel.impl.annotations.Documented in project neo4j by neo4j.

the class TransactionTest method handling_errors.

@Test
@Documented("Handling errors\n" + "\n" + "The result of any request against the transaction endpoint is streamed back to the client.\n" + "Therefore the server does not know whether the request will be successful or not when it sends the HTTP status\n" + "code.\n" + "\n" + "Because of this, all requests against the transactional endpoint will return 200 or 201 status code, regardless\n" + "of whether statements were successfully executed. At the end of the response payload, the server includes a list\n" + "of errors that occurred while executing statements. If this list is empty, the request completed successfully.\n" + "\n" + "If any errors occur while executing statements, the server will roll back the transaction.\n" + "\n" + "In this example, we send the server an invalid statement to demonstrate error handling.\n" + " \n" + "For more information on the status codes, see <<status-codes>>.")
public void handling_errors() throws JsonParseException {
    // Given
    String location = POST(getDataUri() + "transaction").location();
    // Document
    ResponseEntity response = gen.get().expectedStatus(200).payload(quotedJson("{ 'statements': [ { 'statement': 'This is not a valid Cypher Statement.' } ] }")).post(location + "/commit");
    // Then
    Map<String, Object> result = jsonToMap(response.entity());
    assertErrors(result, Status.Statement.SyntaxError);
}
Also used : ResponseEntity(org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Aggregations

Documented (org.neo4j.kernel.impl.annotations.Documented)71 Test (org.junit.Test)70 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)26 Graph (org.neo4j.test.GraphDescription.Graph)21 ResponseEntity (org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity)20 Title (org.neo4j.test.TestData.Title)19 Node (org.neo4j.graphdb.Node)14 Matchers.containsString (org.hamcrest.Matchers.containsString)11 Transaction (org.neo4j.graphdb.Transaction)8 RelationshipRepresentationTest (org.neo4j.server.rest.repr.RelationshipRepresentationTest)7 JsonNode (org.codehaus.jackson.JsonNode)6 JaxRsResponse (org.neo4j.server.rest.JaxRsResponse)6 RESTRequestGenerator (org.neo4j.server.rest.RESTRequestGenerator)6 ArrayList (java.util.ArrayList)5 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)5 Relationship (org.neo4j.graphdb.Relationship)5 Map (java.util.Map)4 URI (java.net.URI)3 FunctionalTestHelper (org.neo4j.server.helpers.FunctionalTestHelper)3 RestRequest (org.neo4j.server.rest.RestRequest)3