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"));
}
use of org.neo4j.kernel.impl.annotations.Documented in project neo4j by neo4j.
the class IndexRelationshipIT method put_relationship_if_absent_only_fail.
@Documented("Add an existing relationship to a unique index (already indexed).")
@Test
public void put_relationship_if_absent_only_fail() throws Exception {
// Given
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();
}
Relationship rel;
try (Transaction tx = graphdb.beginTx()) {
Node node1 = graphdb.createNode();
Node node2 = graphdb.createNode();
rel = node1.createRelationshipTo(node2, MyRelationshipTypes.KNOWS);
tx.success();
}
// When & Then
gen.get().expectedStatus(409).payloadType(MediaType.APPLICATION_JSON_TYPE).payload("{\"key\": \"" + key + "\", \"value\": \"" + value + "\", \"uri\":\"" + functionalTestHelper.relationshipUri(rel.getId()) + "\"}").post(functionalTestHelper.relationshipIndexUri() + index + "?uniqueness=create_or_fail");
}
use of org.neo4j.kernel.impl.annotations.Documented in project neo4j by neo4j.
the class IndexRelationshipIT method create_a_unique_relationship_or_return_fail___create.
@Documented("Create a unique relationship or return fail (create).\n" + "\n" + "Here, in case\n" + "of an already existing relationship, an error should be returned. In this\n" + "example, no existing relationship is found and a new relationship is created.")
@Test
public void create_a_unique_relationship_or_return_fail___create() throws Exception {
final String index = indexes.newInstance(), key = "name", value = "Tobias";
helper.createRelationshipIndex(index);
ResponseEntity response = gen.get().expectedStatus(201).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=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"));
}
use of org.neo4j.kernel.impl.annotations.Documented in project neo4j by neo4j.
the class IndexRelationshipIT method create_a_unique_relationship_or_return_fail___fail.
@Documented("Create a unique relationship or return fail (fail).\n" + "\n" + "Here, in case\n" + "of an already existing relationship, an error should be returned. In this\n" + "example, an existing relationship is found and an error is returned.")
@Test
public void create_a_unique_relationship_or_return_fail___fail() 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(409).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=create_or_fail");
}
use of org.neo4j.kernel.impl.annotations.Documented in project neo4j by neo4j.
the class CypherIT method testProfiling.
@Test
@Title("Profile a query")
@Documented("By passing in an extra parameter, you can ask the cypher executor to return a profile of the " + "query as it is executed. This can help in locating bottlenecks.")
@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 testProfiling() throws Exception {
String script = createScript("MATCH (x)-[r]->(n) WHERE id(x) = %I% RETURN type(r), n.name, n.age");
// WHEN
String response = doCypherRestCall(cypherUri() + "?profile=true", script, Status.OK);
// THEN
Map<String, Object> des = jsonToMap(response);
assertThat(des.get("plan"), instanceOf(Map.class));
@SuppressWarnings("unchecked") Map<String, Object> plan = (Map<String, Object>) des.get("plan");
assertThat(plan.get("name"), instanceOf(String.class));
assertThat(plan.get("children"), instanceOf(Collection.class));
assertThat(plan.get("rows"), instanceOf(Number.class));
assertThat(plan.get("dbHits"), instanceOf(Number.class));
}
Aggregations