Search in sources :

Example 21 with Documented

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

the class SetNodePropertiesIT method shouldReturn204WhenPropertiesAreUpdated.

@Graph("jim knows joe")
@Documented("Update node properties.\n" + "\n" + "This will replace all existing properties on the node with the new set\n" + "of attributes.")
@Test
public void shouldReturn204WhenPropertiesAreUpdated() throws JsonParseException {
    Node jim = data.get().get("jim");
    assertThat(jim, inTx(graphdb(), not(hasProperty("age"))));
    gen.get().payload(JsonHelper.createJsonFrom(MapUtil.map("age", "18"))).expectedStatus(204).put(getPropertiesUri(jim));
    assertThat(jim, inTx(graphdb(), hasProperty("age").withValue("18")));
}
Also used : Node(org.neo4j.graphdb.Node) Graph(org.neo4j.test.GraphDescription.Graph) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Example 22 with Documented

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

the class GetNodePropertiesIT method shouldGet200ForProperties.

@Documented("Get properties for node.")
@Test
public void shouldGet200ForProperties() throws JsonParseException {
    String entity = JsonHelper.createJsonFrom(Collections.singletonMap("foo", "bar"));
    JaxRsResponse createResponse = req.post(functionalTestHelper.dataUri() + "node/", entity);
    gen.get().expectedStatus(200).get(createResponse.getLocation().toString() + "/properties");
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Example 23 with Documented

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

the class IndexNodeIT method create_a_unique_node_or_fail_create.

@Documented("Create a unique node or return fail (create).\n" + "\n" + "Here, in case\n" + "of an already existing node, an error should be returned. In this\n" + "example, no existing indexed node is found and a new node is created.")
@Test
public void create_a_unique_node_or_fail_create() throws Exception {
    final String index = indexes.newInstance(), key = "name", value = "Tobias";
    helper.createNodeIndex(index);
    ResponseEntity response = gen.get().expectedStatus(201).payloadType(MediaType.APPLICATION_JSON_TYPE).payload("{\"key\": \"" + key + "\", \"value\": \"" + value + "\", \"properties\": {\"" + key + "\": \"" + value + "\", \"sequence\": 1}}").post(functionalTestHelper.nodeIndexUri() + index + "?uniqueness=create_or_fail" + "");
    MultivaluedMap<String, String> headers = response.response().getHeaders();
    Map<String, Object> result = JsonHelper.jsonToMap(response.entity());
    assertEquals(result.get("indexed"), headers.getFirst("Location"));
    Map<String, Object> data = assertCast(Map.class, result.get("data"));
    assertEquals(value, data.get(key));
    assertEquals(1, data.get("sequence"));
}
Also used : ResponseEntity(org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Example 24 with Documented

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

the class IndexNodeIT method get_or_create_unique_node_if_already_existing.

@Documented("Get or create unique node (existing).\n" + "\n" + "Here,\n" + "a node is not created but the existing unique node returned, since another node\n" + "is indexed with the same data already. The node data returned is then that of the\n" + "already existing node.")
@Test
public void get_or_create_unique_node_if_already_existing() throws Exception {
    final String index = indexes.newInstance(), key = "name", value = "Peter";
    GraphDatabaseService graphdb = graphdb();
    try (Transaction tx = graphdb().beginTx()) {
        Node peter = graphdb.createNode();
        peter.setProperty(key, value);
        peter.setProperty("sequence", 1);
        graphdb.index().forNodes(index).add(peter, key, value);
        tx.success();
    }
    helper.createNodeIndex(index);
    ResponseEntity response = gen().expectedStatus(200).payloadType(MediaType.APPLICATION_JSON_TYPE).payload("{\"key\": \"" + key + "\", \"value\": \"" + value + "\", \"properties\": {\"" + key + "\": \"" + value + "\", \"sequence\": 2}}").post(functionalTestHelper.nodeIndexUri() + index + "?uniqueness=get_or_create");
    Map<String, Object> result = JsonHelper.jsonToMap(response.entity());
    Map<String, Object> data = assertCast(Map.class, result.get("data"));
    assertEquals(value, data.get(key));
    assertEquals(1, data.get("sequence"));
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) ResponseEntity(org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Example 25 with Documented

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

the class IndexNodeIT method create_a_unique_node_or_return_fail___fail.

@Documented("Create a unique node or return fail (fail).\n" + "\n" + "Here, in case\n" + "of an already existing node, an error should be returned. In this\n" + "example, an existing node indexed with the same data\n" + "is found and an error is returned.")
@Test
public void create_a_unique_node_or_return_fail___fail() throws Exception {
    final String index = indexes.newInstance(), key = "name", value = "Peter";
    GraphDatabaseService graphdb = graphdb();
    helper.createNodeIndex(index);
    try (Transaction tx = graphdb.beginTx()) {
        Node peter = graphdb.createNode();
        peter.setProperty(key, value);
        peter.setProperty("sequence", 1);
        graphdb.index().forNodes(index).add(peter, key, value);
        tx.success();
    }
    RestRequest.req();
    ResponseEntity response = gen.get().expectedStatus(409).payloadType(MediaType.APPLICATION_JSON_TYPE).payload("{\"key\": \"" + key + "\", \"value\": \"" + value + "\", \"properties\": {\"" + key + "\": \"" + value + "\", \"sequence\": 2}}").post(functionalTestHelper.nodeIndexUri() + index + "?uniqueness=create_or_fail");
    Map<String, Object> result = JsonHelper.jsonToMap(response.entity());
    Map<String, Object> data = assertCast(Map.class, result.get("data"));
    assertEquals(value, data.get(key));
    assertEquals(1, data.get("sequence"));
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) ResponseEntity(org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

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