Search in sources :

Example 36 with Graph

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

the class CreateRelationshipTest method create_relationship.

@Test
@Documented("Upon successful creation of a relationship, the new relationship is returned.")
@Title("Create relationship")
@Graph("Joe knows Sara")
public void create_relationship() throws Exception {
    String jsonString = "{\"to\" : \"" + getDataUri() + "node/" + getNode("Sara").getId() + "\", \"type\" : \"LOVES\"}";
    Node i = getNode("Joe");
    String entity = gen.get().expectedStatus(Status.CREATED.getStatusCode()).payload(jsonString).post(getNodeUri(i) + "/relationships").entity();
    try (Transaction tx = graphdb().beginTx()) {
        assertTrue(i.hasRelationship(RelationshipType.withName("LOVES")));
    }
    assertProperRelationshipRepresentation(JsonHelper.jsonToMap(entity));
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Graph(org.neo4j.test.GraphDescription.Graph) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test) RelationshipRepresentationTest(org.neo4j.server.rest.repr.RelationshipRepresentationTest) Title(org.neo4j.test.TestData.Title)

Example 37 with Graph

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

the class CreateRelationshipTest method create_a_relationship_with_properties.

@Test
@Graph("Joe knows Sara")
@Documented("Upon successful creation of a relationship, the new relationship is returned.")
@Title("Create a relationship with properties")
public void create_a_relationship_with_properties() throws Exception {
    String jsonString = "{\"to\" : \"" + getDataUri() + "node/" + getNode("Sara").getId() + "\", \"type\" : \"LOVES\", \"data\" : {\"foo\" : \"bar\"}}";
    Node i = getNode("Joe");
    gen.get().expectedStatus(Status.CREATED.getStatusCode()).payload(jsonString).post(getNodeUri(i) + "/relationships");
    try (Transaction tx = graphdb().beginTx()) {
        assertTrue(i.hasRelationship(RelationshipType.withName("LOVES")));
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Graph(org.neo4j.test.GraphDescription.Graph) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test) RelationshipRepresentationTest(org.neo4j.server.rest.repr.RelationshipRepresentationTest) Title(org.neo4j.test.TestData.Title)

Example 38 with Graph

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

the class CypherIT method send_queries_with_errors.

@Test
@Title("Send queries with errors")
@Documented("This example shows what happens if you misspell an identifier.")
@Graph(value = { "I know you" }, autoIndexNodes = true)
public void send_queries_with_errors() throws Exception {
    data.get();
    String script = "START x = node:node_auto_index(name={startName}) MATCH path = (x)-[r]-(friend) WHERE frien" + ".name = {name} RETURN type(r)";
    String response = cypherRestCall(script, Status.BAD_REQUEST, Pair.of("startName", "I"), Pair.of("name", "you"));
    Map<String, Object> responseMap = jsonToMap(response);
    assertThat(responseMap.keySet(), containsInAnyOrder("message", "exception", "fullname", "stackTrace", "cause", "errors"));
    assertThat(response, containsString("message"));
    assertThat((String) responseMap.get("message"), containsString("Variable `frien` not defined"));
}
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 39 with Graph

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

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

Example 40 with Graph

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

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

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