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();
}
}
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);
}
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));
}
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));
}
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"));
}
Aggregations