Search in sources :

Example 11 with Graph

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

the class CreateRelationshipTest method creating_a_loop_relationship.

@Test
@Graph("Joe knows Sara")
public void creating_a_loop_relationship() throws Exception {
    Node joe = getNode("Joe");
    String jsonString = "{\"to\" : \"" + getNodeUri(joe) + "\", \"type\" : \"LOVES\"}";
    String entity = gen.get().expectedStatus(Status.CREATED.getStatusCode()).payload(jsonString).post(getNodeUri(getNode("Joe")) + "/relationships").entity();
    assertProperRelationshipRepresentation(JsonHelper.jsonToMap(entity));
}
Also used : Node(org.neo4j.graphdb.Node) Graph(org.neo4j.test.GraphDescription.Graph) Test(org.junit.Test) RelationshipRepresentationTest(org.neo4j.server.rest.repr.RelationshipRepresentationTest)

Example 12 with Graph

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

the class CypherIT 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 13 with Graph

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

the class CypherIT method error_gets_returned_as_json.

@Test
@Title("Errors")
@Documented("Errors on the server will be reported as a JSON-formatted message, exception name and stacktrace.")
@Graph("I know you")
public void error_gets_returned_as_json() throws Exception {
    String response = cypherRestCall("MATCH (x {name: 'I'}) RETURN x.dummy/0", Status.BAD_REQUEST);
    Map<String, Object> output = jsonToMap(response);
    assertTrue(output.toString(), output.containsKey("message"));
    assertTrue(output.containsKey("exception"));
    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 14 with Graph

use of org.neo4j.test.GraphDescription.Graph 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 15 with Graph

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

the class CypherIT 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)

Aggregations

Graph (org.neo4j.test.GraphDescription.Graph)48 Test (org.junit.Test)47 Documented (org.neo4j.kernel.impl.annotations.Documented)21 Title (org.neo4j.test.TestData.Title)18 Node (org.neo4j.graphdb.Node)17 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)16 Transaction (org.neo4j.graphdb.Transaction)13 Relationship (org.neo4j.graphdb.Relationship)11 Map (java.util.Map)7 ArrayList (java.util.ArrayList)3 RelationshipRepresentationTest (org.neo4j.server.rest.repr.RelationshipRepresentationTest)3 HashSet (java.util.HashSet)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 PrettyJSON (org.neo4j.server.rest.PrettyJSON)2 JsonHelper.jsonToMap (org.neo4j.server.rest.domain.JsonHelper.jsonToMap)2 Collection (java.util.Collection)1 List (java.util.List)1 JsonNode (org.codehaus.jackson.JsonNode)1 PathExpander (org.neo4j.graphdb.PathExpander)1