use of org.neo4j.annotations.documented.Documented in project neo4j-documentation by neo4j.
the class TransactionDocIT method errors_in_open_transaction.
@Test
@Documented("Handling errors in an open transaction\n" + "\n" + "Whenever there is an error in a request the server will rollback the transaction.\n" + "By inspecting the response for the presence/absence of the `transaction` key you can tell if the " + "transaction is still open")
public void errors_in_open_transaction() throws JsonParseException {
// Given
String location = POST(txUri()).location();
// Document
ResponseEntity response = gen.get().noGraph().expectedStatus(200).payload(quotedJson("{ 'statements': [ { 'statement': 'This is not a valid Cypher Statement.' } ] }")).post(location);
// Then
Map<String, Object> result = jsonToMap(response.entity());
assertThat(result, not(hasKey("transaction")));
}
use of org.neo4j.annotations.documented.Documented in project neo4j-documentation by neo4j.
the class TransactionDocIT method execute_multiple_statements.
@Test
@Documented("Execute multiple statements\n" + "\n" + "You can send multiple Cypher statements in the same request.\n" + "The response will contain the result of each statement.")
public void execute_multiple_statements() throws JsonParseException {
// Document
ResponseEntity response = gen.get().noGraph().expectedStatus(200).payload(quotedJson("{ 'statements': [ { 'statement': 'CREATE (n) RETURN id(n)' }, " + "{ 'statement': 'CREATE (n $props) RETURN n', " + "'parameters': { 'props': { 'name': 'My Node' } } } ] }")).post(txCommitUri());
// Then
Map<String, Object> result = jsonToMap(response.entity());
assertNoErrors(result);
Integer id = resultCell(result, 0, 0);
verifyNodeExists(id);
assertThat(response.entity(), containsString("My Node"));
}
use of org.neo4j.annotations.documented.Documented in project neo4j-documentation by neo4j.
the class TransactionDocIT method commit_an_open_transaction.
@Test
@Documented("Commit an open transaction\n" + "\n" + "Given you have an open transaction, you can send a commit request. Optionally, you submit additional statements\n" + "along with the request that will be executed before committing the transaction.")
public void commit_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 id(n)' } ] }")).post(location + "/commit");
// Then
Map<String, Object> result = jsonToMap(response.entity());
assertNoErrors(result);
Integer id = resultCell(result, 0, 0);
verifyNodeExists(id);
}
use of org.neo4j.annotations.documented.Documented in project neo4j-documentation by neo4j.
the class TransactionDocIT method return_results_in_graph_format.
@Test
@Documented("Return results in graph format\n" + "\n" + "If you want to understand the graph structure of nodes and relationships returned by your query,\n" + "you can specify the \"graph\" results data format. For example, this is useful when you want to visualise the\n" + "graph structure. The format collates all the nodes and relationships from all columns of the result,\n" + "and also flattens collections of nodes and relationships, including paths.")
public void return_results_in_graph_format() throws JsonParseException {
// Document
ResponseEntity response = gen.get().noGraph().expectedStatus(200).payload(quotedJson("{'statements':[{'statement':" + "'CREATE ( bike:Bike { weight: 10 } ) " + "CREATE ( frontWheel:Wheel { spokes: 3 } ) " + "CREATE ( backWheel:Wheel { spokes: 32 } ) " + "CREATE p1 = (bike)-[:HAS { position: 1 } ]->(frontWheel) " + "CREATE p2 = (bike)-[:HAS { position: 2 } ]->(backWheel) " + "RETURN bike, p1, p2', " + "'resultDataContents': ['row','graph']}] }")).post(txCommitUri());
// Then
Map<String, Object> result = jsonToMap(response.entity());
assertNoErrors(result);
Map<String, List<Object>> row = graphRow(result, 0);
assertEquals(3, row.get("nodes").size());
assertEquals(2, row.get("relationships").size());
}
use of org.neo4j.annotations.documented.Documented in project neo4j-documentation by neo4j.
the class TestJavaTestDocsGenerator method can_create_docs_from_method_name.
@Documented(value = "Title1.\n\nhej\n@@snippet1\n\nmore docs\n@@snippet_2-1\n@@snippet12\n.")
@Test
@Graph("I know you")
public void can_create_docs_from_method_name() throws Exception {
data.get();
JavaTestDocsGenerator doc = gen.get();
doc.setGraph(graphdb);
assertNotNull(data.get().get("I"));
String snippet1 = "snippet1-value";
String snippet12 = "snippet12-value";
String snippet2 = "snippet2-value";
doc.addSnippet("snippet1", snippet1);
doc.addSnippet("snippet12", snippet12);
doc.addSnippet("snippet_2-1", snippet2);
doc.document(directory.toAbsolutePath().toString(), sectionName);
String result = readFileAsString(sectionDirectory.resolve("title1.asciidoc"));
assertTrue(result.contains("include::includes/title1-snippet1.asciidoc[]"));
assertTrue(result.contains("include::includes/title1-snippet_2-1.asciidoc[]"));
assertTrue(result.contains("include::includes/title1-snippet12.asciidoc[]"));
Path includes = sectionDirectory.resolve("includes");
result = readFileAsString(includes.resolve("title1-snippet1.asciidoc"));
assertTrue(result.contains(snippet1));
result = readFileAsString(includes.resolve("title1-snippet_2-1.asciidoc"));
assertTrue(result.contains(snippet2));
result = readFileAsString(includes.resolve("title1-snippet12.asciidoc"));
assertTrue(result.contains(snippet12));
}
Aggregations