Search in sources :

Example 46 with Documented

use of org.neo4j.kernel.impl.annotations.Documented in project neo4j by neo4j.

the class IndexNodeIT method addExistingNodeToUniqueIndexExisting.

@Documented("Add an existing node to unique index (already indexed).\n" + "\n" + "In this case, the node already exists in the index, and thus we get a `HTTP 409` status response,\n" + "as we have set the uniqueness to `create_or_fail`.")
@Test
public void addExistingNodeToUniqueIndexExisting() throws Exception {
    final String indexName = indexes.newInstance();
    final String key = "some-key";
    final String value = "some value";
    try (Transaction tx = graphdb().beginTx()) {
        Node peter = graphdb().createNode();
        peter.setProperty(key, value);
        graphdb().index().forNodes(indexName).add(peter, key, value);
        tx.success();
    }
    gen().expectedStatus(409).payload(JsonHelper.createJsonFrom(generateNodeIndexCreationPayload(key, value, functionalTestHelper.nodeUri(createNode())))).post(functionalTestHelper.indexNodeUri(indexName) + "?uniqueness=create_or_fail");
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Example 47 with Documented

use of org.neo4j.kernel.impl.annotations.Documented in project neo4j by neo4j.

the class IndexRelationshipIT method get_or_create_unique_relationship_existing.

@Documented("Get or create unique relationship (existing).\n" + "\n" + "Here, in case\n" + "of an already existing relationship, the sent data is ignored and the\n" + "existing relationship returned.")
@Test
public void get_or_create_unique_relationship_existing() throws Exception {
    final String index = indexes.newInstance(), key = "name", value = "Peter";
    GraphDatabaseService graphdb = graphdb();
    helper.createRelationshipIndex(index);
    try (Transaction tx = graphdb.beginTx()) {
        Node node1 = graphdb.createNode();
        Node node2 = graphdb.createNode();
        Relationship rel = node1.createRelationshipTo(node2, MyRelationshipTypes.KNOWS);
        graphdb.index().forRelationships(index).add(rel, key, value);
        tx.success();
    }
    gen.get().expectedStatus(200).payloadType(MediaType.APPLICATION_JSON_TYPE).payload("{\"key\": \"" + key + "\", \"value\": \"" + value + "\", \"start\": \"" + functionalTestHelper.nodeUri(helper.createNode()) + "\", \"end\": \"" + functionalTestHelper.nodeUri(helper.createNode()) + "\", \"type\":\"" + MyRelationshipTypes.KNOWS + "\"}").post(functionalTestHelper.relationshipIndexUri() + index + "?uniqueness=get_or_create");
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Example 48 with Documented

use of org.neo4j.kernel.impl.annotations.Documented 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 49 with Documented

use of org.neo4j.kernel.impl.annotations.Documented 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 50 with Documented

use of org.neo4j.kernel.impl.annotations.Documented 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)

Aggregations

Documented (org.neo4j.kernel.impl.annotations.Documented)71 Test (org.junit.Test)70 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)26 Graph (org.neo4j.test.GraphDescription.Graph)21 ResponseEntity (org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity)20 Title (org.neo4j.test.TestData.Title)19 Node (org.neo4j.graphdb.Node)14 Matchers.containsString (org.hamcrest.Matchers.containsString)11 Transaction (org.neo4j.graphdb.Transaction)8 RelationshipRepresentationTest (org.neo4j.server.rest.repr.RelationshipRepresentationTest)7 JsonNode (org.codehaus.jackson.JsonNode)6 JaxRsResponse (org.neo4j.server.rest.JaxRsResponse)6 RESTRequestGenerator (org.neo4j.server.rest.RESTRequestGenerator)6 ArrayList (java.util.ArrayList)5 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)5 Relationship (org.neo4j.graphdb.Relationship)5 Map (java.util.Map)4 URI (java.net.URI)3 FunctionalTestHelper (org.neo4j.server.helpers.FunctionalTestHelper)3 RestRequest (org.neo4j.server.rest.RestRequest)3