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");
}
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"));
}
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"));
}
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"));
}
use of org.neo4j.kernel.impl.annotations.Documented in project neo4j by neo4j.
the class IndexNodeIT method get_or_create_a_node_in_an_unique_index.
@Documented("Get or create unique node (create).\n" + "\n" + "The node is created if it doesn't exist in the unique index already.")
@Test
public void get_or_create_a_node_in_an_unique_index() throws Exception {
final String index = indexes.newInstance(), key = "name", value = "Tobias";
helper.createNodeIndex(index);
ResponseEntity response = gen().expectedStatus(201).payloadType(MediaType.APPLICATION_JSON_TYPE).payload("{\"key\": \"" + key + "\", \"value\": \"" + value + "\", \"properties\": {\"" + key + "\": \"" + value + "\", \"sequence\": 1}}").post(functionalTestHelper.nodeIndexUri() + index + "?uniqueness=get_or_create");
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"));
}
Aggregations