Search in sources :

Example 36 with Documented

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"));
}
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 37 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 38 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 39 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 40 with Documented

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);
}
Also used : ResponseEntity(org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity) HTTP(org.neo4j.test.server.HTTP) 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