Search in sources :

Example 6 with Title

use of org.neo4j.test.TestData.Title in project neo4j by neo4j.

the class CypherIT method testPropertyColumn.

@Test
@Title("Send a query")
@Documented("A simple query returning all nodes connected to some node, returning the node and the name " + "property, if it exists, otherwise `NULL`:")
@Graph(nodes = { @NODE(name = "I", setNameProperty = true), @NODE(name = "you", setNameProperty = true), @NODE(name = "him", setNameProperty = true, properties = { @PROP(key = "age", value = "25", type = GraphDescription.PropType.INTEGER) }) }, relationships = { @REL(start = "I", end = "him", type = "know", properties = {}), @REL(start = "I", end = "you", type = "know", properties = {}) })
public void testPropertyColumn() throws UnsupportedEncodingException {
    String script = createScript("MATCH (x {name: 'I'})-[r]->(n) RETURN type(r), n.name, n.age");
    String response = cypherRestCall(script, Status.OK);
    assertThat(response, containsString("you"));
    assertThat(response, containsString("him"));
    assertThat(response, containsString("25"));
    assertThat(response, not(containsString("\"x\"")));
}
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 7 with Title

use of org.neo4j.test.TestData.Title in project neo4j by neo4j.

the class CypherIT method send_queries_with_syntax_errors.

@Test
@Title("Syntax errors")
@Documented("Sending a query with syntax errors will give a bad request (HTTP 400) response together with " + "an error message.")
@Graph(value = { "I know you" }, autoIndexNodes = true)
public void send_queries_with_syntax_errors() throws Exception {
    data.get();
    String script = "START x  = node:node_auto_index(name={startName}) MATC path = (x-[r]-friend) WHERE friend" + ".name = {name} RETURN TYPE(r)";
    String response = cypherRestCall(script, Status.BAD_REQUEST, Pair.of("startName", "I"), Pair.of("name", "you"));
    Map<String, Object> output = jsonToMap(response);
    assertTrue(output.containsKey("message"));
    assertTrue(output.containsKey("stackTrace"));
}
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 8 with Title

use of org.neo4j.test.TestData.Title in project neo4j by neo4j.

the class CypherIT method return_paths.

@Test
@Title("Return paths")
@Documented("Paths can be returned just like other return types.")
@Graph("I know you")
public void return_paths() throws Exception {
    String script = "MATCH path = (x {name: 'I'})--(friend) RETURN path, friend.name";
    String response = cypherRestCall(script, Status.OK);
    assertEquals(2, (jsonToMap(response)).size());
    assertThat(response, containsString("data"));
    assertThat(response, containsString("you"));
}
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 9 with Title

use of org.neo4j.test.TestData.Title in project neo4j by neo4j.

the class CypherIT method testQueryStatistics.

@Test
@Title("Retrieve query metadata")
@Documented("By passing in an additional GET parameter when you execute Cypher queries, metadata about the " + "query will be returned, such as how many labels were added or removed by the query.")
@Graph(nodes = { @NODE(name = "I", setNameProperty = true, labels = { @LABEL("Director") }) })
public void testQueryStatistics() throws JsonParseException {
    // Given
    String script = createScript("MATCH (n {name: 'I'}) SET n:Actor REMOVE n:Director RETURN labels(n)");
    // When
    Map<String, Object> output = jsonToMap(doCypherRestCall(cypherUri() + "?includeStats=true", script, Status.OK));
    // Then
    @SuppressWarnings("unchecked") Map<String, Object> stats = (Map<String, Object>) output.get("stats");
    assertThat(stats, isA(Map.class));
    assertThat((Boolean) stats.get("contains_updates"), is(true));
    assertThat((Integer) stats.get("labels_added"), is(1));
    assertThat((Integer) stats.get("labels_removed"), is(1));
    assertThat((Integer) stats.get("nodes_created"), is(0));
    assertThat((Integer) stats.get("nodes_deleted"), is(0));
    assertThat((Integer) stats.get("properties_set"), is(0));
    assertThat((Integer) stats.get("relationships_created"), is(0));
    assertThat((Integer) stats.get("relationship_deleted"), is(0));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Map(java.util.Map) JsonHelper.jsonToMap(org.neo4j.server.rest.domain.JsonHelper.jsonToMap) Graph(org.neo4j.test.GraphDescription.Graph) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test) Title(org.neo4j.test.TestData.Title)

Example 10 with Title

use of org.neo4j.test.TestData.Title 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)

Aggregations

Test (org.junit.Test)21 Title (org.neo4j.test.TestData.Title)21 Documented (org.neo4j.kernel.impl.annotations.Documented)19 Graph (org.neo4j.test.GraphDescription.Graph)18 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)12 Relationship (org.neo4j.graphdb.Relationship)4 FunctionalTestHelper (org.neo4j.server.helpers.FunctionalTestHelper)3 JaxRsResponse (org.neo4j.server.rest.JaxRsResponse)3 Map (java.util.Map)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Node (org.neo4j.graphdb.Node)2 Transaction (org.neo4j.graphdb.Transaction)2 JsonHelper.jsonToMap (org.neo4j.server.rest.domain.JsonHelper.jsonToMap)2 RelationshipRepresentationTest (org.neo4j.server.rest.repr.RelationshipRepresentationTest)2 Collection (java.util.Collection)1