Search in sources :

Example 76 with Graph

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

the class AutoIndexDocIT method autoindexed_relationships_cannot_be_removed_manually.

/**
 * It is not allowed to remove entries manually from automatic indexes.
 */
@Test
@Graph(nodes = { @NODE(name = "I"), @NODE(name = "you") }, relationships = { @REL(start = "I", end = "you", type = "know", properties = { @PROP(key = "since", value = "today") }) }, autoIndexRelationships = true)
public void autoindexed_relationships_cannot_be_removed_manually() {
    try (Transaction tx = graphdb().beginTx()) {
        data.get();
        tx.success();
    }
    try (Transaction tx = graphdb().beginTx()) {
        long id = data.get().get("I").getRelationships().iterator().next().getId();
        String indexName = graphdb().index().getRelationshipAutoIndexer().getAutoIndex().getName();
        gen.get().noGraph().expectedStatus(405).delete(getDataUri() + "index/relationship/" + indexName + "/since/today/" + id).entity();
        gen.get().noGraph().expectedStatus(405).delete(getDataUri() + "index/relationship/" + indexName + "/since/" + id).entity();
        gen.get().noGraph().expectedStatus(405).delete(getDataUri() + "index/relationship/" + indexName + "/" + id).entity();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Graph(org.neo4j.test.GraphDescription.Graph) Test(org.junit.Test)

Example 77 with Graph

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

the class BatchOperationDocIT method shouldHandleEscapedStrings.

@Test
@Graph("Peter likes Jazz")
public void shouldHandleEscapedStrings() throws ClientHandlerException, UniformInterfaceException, JSONException, JsonParseException {
    String string = "Jazz";
    Node gnode = getNode(string);
    assertThat(gnode, inTx(graphdb(), hasProperty("name").withValue(string)));
    String name = "string\\ and \"test\"";
    String jsonString = new PrettyJSON().array().object().key("method").value("PUT").key("to").value("/node/" + gnode.getId() + "/properties").key("body").object().key("name").value(name).endObject().endObject().endArray().toString();
    gen.get().expectedStatus(200).payload(jsonString).post(batchUri()).entity();
    jsonString = new PrettyJSON().array().object().key("method").value("GET").key("to").value("/node/" + gnode.getId() + "/properties/name").endObject().endArray().toString();
    String entity = gen.get().expectedStatus(200).payload(jsonString).post(batchUri()).entity();
    List<Map<String, Object>> results = JsonHelper.jsonToList(entity);
    assertEquals(results.get(0).get("body"), name);
}
Also used : JsonNode(org.codehaus.jackson.JsonNode) Node(org.neo4j.graphdb.Node) Map(java.util.Map) Graph(org.neo4j.test.GraphDescription.Graph) Test(org.junit.Test)

Example 78 with Graph

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

the class CreateRelationshipDocIT 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).description(startGraph("create relationship")).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) Title(org.neo4j.test.TestData.Title)

Example 79 with Graph

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

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

Example 80 with Graph

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

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

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