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));
}
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"));
}
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\"]")));
}
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"));
}
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));
}
Aggregations