use of org.neo4j.doc.server.rest.RESTDocsGenerator.ResponseEntity in project neo4j-documentation by neo4j.
the class GetOnRootDocIT method streaming.
@Documented("All responses from the REST API can be transmitted as JSON streams, resulting in\n" + "better performance and lower memory overhead on the server side. To use\n" + "streaming, supply the header `X-Stream: true` with each request.")
@Test
public void streaming() throws Exception {
data.get();
ResponseEntity responseEntity = gen().docHeadingLevel(2).noGraph().withHeader(StreamingFormat.STREAM_HEADER, "true").expectedType(APPLICATION_JSON_TYPE).expectedStatus(200).get(getDataUri());
JaxRsResponse response = responseEntity.response();
// this gets the full media type, including things like
// ; stream=true at the end
String foundMediaType = response.getType().toString();
String expectedMediaType = StreamingFormat.MEDIA_TYPE.toString();
assertEquals(expectedMediaType, foundMediaType);
String body = responseEntity.entity();
Map<String, Object> map = JsonHelper.jsonToMap(body);
assertEquals(getDataUri() + "node", map.get("node"));
}
use of org.neo4j.doc.server.rest.RESTDocsGenerator.ResponseEntity in project neo4j-documentation by neo4j.
the class IndexNodeDocIT 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().noGraph().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.doc.server.rest.RESTDocsGenerator.ResponseEntity in project neo4j-documentation by neo4j.
the class IndexNodeDocIT 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().noGraph().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.doc.server.rest.RESTDocsGenerator.ResponseEntity in project neo4j-documentation by neo4j.
the class TransactionDocIT method execute_statements_in_an_open_transaction.
@Test
@Documented("Execute statements in an open transaction\n" + "\n" + "Given that you have an open transaction, you can make a number of requests, each of which executes additional\n" + "statements, and keeps the transaction open by resetting the transaction timeout.")
public void execute_statements_in_an_open_transaction() throws JsonParseException {
// Given
String location = POST(txUri()).location();
// Document
ResponseEntity response = gen.get().noGraph().expectedStatus(200).payload(quotedJson("{ 'statements': [ { 'statement': 'CREATE (n) RETURN n' } ] }")).post(location);
// Then
Map<String, Object> result = jsonToMap(response.entity());
assertThat(result, hasKey("transaction"));
assertNoErrors(result);
}
use of org.neo4j.doc.server.rest.RESTDocsGenerator.ResponseEntity in project neo4j-documentation by neo4j.
the class TransactionDocIT method execute_statements_in_an_open_transaction_using_REST.
@Test
@Documented("Execute statements in an open transaction in REST format for the return.\n" + "\n" + "Given that you have an open transaction, you can make a number of requests, each of which executes additional\n" + "statements, and keeps the transaction open by resetting the transaction timeout. Specifying the `REST` format will\n" + "give back full Neo4j Rest API representations of the Neo4j Nodes, Relationships and Paths, if returned.")
public void execute_statements_in_an_open_transaction_using_REST() throws JsonParseException {
// Given
String location = POST(txUri()).location();
// Document
ResponseEntity response = gen.get().noGraph().expectedStatus(200).payload(quotedJson("{ 'statements': [ { 'statement': 'CREATE (n) RETURN n','resultDataContents':['REST'] } ] }")).post(location);
// Then
Map<String, Object> result = jsonToMap(response.entity());
ArrayList rest = (ArrayList) ((Map) ((ArrayList) ((Map) ((ArrayList) result.get("results")).get(0)).get("data")).get(0)).get("rest");
String selfUri = ((String) ((Map) rest.get(0)).get("self"));
assertTrue(selfUri.startsWith(getDatabaseUri()));
assertNoErrors(result);
}
Aggregations