Search in sources :

Example 81 with Graph

use of org.neo4j.test.GraphDescription.Graph in project neo4j-documentation by neo4j.

the class CypherDocIT method testProfiling.

@Test
@Title("Profile a query")
@Documented("By passing in an extra parameter, you can ask the cypher executor to return a profile of the " + "query as it is executed. This can help in locating bottlenecks.")
@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 testProfiling() throws Exception {
    String script = createScript("MATCH (x)-[r]->(n) WHERE id(x) = %I% RETURN type(r), n.name, n.age");
    // WHEN
    String response = doCypherRestCall(cypherUri() + "?profile=true", script, Status.OK);
    // THEN
    Map<String, Object> des = jsonToMap(response);
    assertThat(des.get("plan"), instanceOf(Map.class));
    @SuppressWarnings("unchecked") Map<String, Object> plan = (Map<String, Object>) des.get("plan");
    assertThat(plan.get("name"), instanceOf(String.class));
    assertThat(plan.get("children"), instanceOf(Collection.class));
    assertThat(plan.get("rows"), instanceOf(Number.class));
    assertThat(plan.get("dbHits"), instanceOf(Number.class));
}
Also used : Collection(java.util.Collection) 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 82 with Graph

use of org.neo4j.test.GraphDescription.Graph in project neo4j-documentation by neo4j.

the class CypherDocIT method send_query_to_create_a_node.

@Test
@Documented("Create a node with a label and a property using Cypher. See the request for the parameter " + "sent with the query.")
@Title("Create a node")
@Graph
public void send_query_to_create_a_node() throws Exception {
    data.get();
    String script = "CREATE (n:Person { name : {name} }) RETURN n";
    String response = cypherRestCall(script, Status.OK, Pair.of("name", "Andres"));
    assertTrue(response.contains("name"));
    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 83 with Graph

use of org.neo4j.test.GraphDescription.Graph in project neo4j-documentation by neo4j.

the class CypherDocIT method array_property.

@Test
@Graph(value = { "I know you" }, autoIndexNodes = false)
public void array_property() throws Exception {
    setProperty("I", "array1", new int[] { 1, 2, 3 });
    setProperty("I", "array2", new String[] { "a", "b", "c" });
    String script = "MATCH (n) WHERE id(n) = %I% RETURN n.array1, n.array2";
    String response = cypherRestCall(script, Status.OK);
    assertThat(response, anyOf(containsString("[ 1, 2, 3 ]"), containsString("[1,2,3]")));
    assertThat(response, anyOf(containsString("[ \"a\", \"b\", \"c\" ]"), containsString("[\"a\",\"b\",\"c\"]")));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Graph(org.neo4j.test.GraphDescription.Graph) Test(org.junit.Test)

Example 84 with Graph

use of org.neo4j.test.GraphDescription.Graph in project neo4j-documentation by neo4j.

the class CypherDocIT method nodes_are_represented_as_nodes.

@Test
@Graph(nodes = { @NODE(name = "I", properties = { @PROP(key = "prop", value = "Hello", type = GraphDescription.PropType.STRING) }), @NODE(name = "you") }, relationships = { @REL(start = "I", end = "him", type = "know", properties = { @PROP(key = "prop", value = "World", type = GraphDescription.PropType.STRING) }) })
public void nodes_are_represented_as_nodes() throws Exception {
    data.get();
    String script = "MATCH (n)-[r]->() WHERE id(n) = %I% RETURN n, r";
    String response = cypherRestCall(script, Status.OK);
    assertThat(response, containsString("Hello"));
    assertThat(response, containsString("World"));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Graph(org.neo4j.test.GraphDescription.Graph) Test(org.junit.Test)

Example 85 with Graph

use of org.neo4j.test.GraphDescription.Graph in project neo4j-documentation by neo4j.

the class CypherDocIT method testDataColumnOrder.

/**
 * Ensure that order of data and column is ok.
 */
@Test
@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 testDataColumnOrder() throws UnsupportedEncodingException {
    String script = createScript("MATCH (x)-[r]->(n) WHERE id(x) = %I% RETURN type(r), n.name, n.age");
    String response = cypherRestCall(script, Status.OK);
    assertThat(response.indexOf("columns") < response.indexOf("data"), is(true));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Graph(org.neo4j.test.GraphDescription.Graph) Test(org.junit.Test)

Aggregations

Graph (org.neo4j.test.GraphDescription.Graph)96 Test (org.junit.Test)92 Documented (org.neo4j.kernel.impl.annotations.Documented)48 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)37 Title (org.neo4j.test.TestData.Title)36 Node (org.neo4j.graphdb.Node)35 Relationship (org.neo4j.graphdb.Relationship)21 Transaction (org.neo4j.graphdb.Transaction)21 Map (java.util.Map)19 ArrayList (java.util.ArrayList)5 Matchers.containsString (org.hamcrest.Matchers.containsString)4 JsonHelper.jsonToMap (org.neo4j.server.rest.domain.JsonHelper.jsonToMap)4 HashSet (java.util.HashSet)3 Test (org.junit.jupiter.api.Test)3 RelationshipRepresentationTest (org.neo4j.server.rest.repr.RelationshipRepresentationTest)3 Collection (java.util.Collection)2 List (java.util.List)2 JsonNode (org.codehaus.jackson.JsonNode)2 PrettyJSON (org.neo4j.doc.server.rest.PrettyJSON)2 PrettyJSON (org.neo4j.server.rest.PrettyJSON)2