Search in sources :

Example 26 with Documented

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")));
}
Also used : ResponseEntity(org.neo4j.doc.server.rest.RESTDocsGenerator.ResponseEntity) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Documented(org.neo4j.annotations.documented.Documented) Test(org.junit.Test)

Example 27 with Documented

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"));
}
Also used : ResponseEntity(org.neo4j.doc.server.rest.RESTDocsGenerator.ResponseEntity) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Documented(org.neo4j.annotations.documented.Documented) Test(org.junit.Test)

Example 28 with Documented

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);
}
Also used : ResponseEntity(org.neo4j.doc.server.rest.RESTDocsGenerator.ResponseEntity) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Documented(org.neo4j.annotations.documented.Documented) Test(org.junit.Test)

Example 29 with Documented

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());
}
Also used : ResponseEntity(org.neo4j.doc.server.rest.RESTDocsGenerator.ResponseEntity) ArrayList(java.util.ArrayList) List(java.util.List) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Documented(org.neo4j.annotations.documented.Documented) Test(org.junit.Test)

Example 30 with Documented

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));
}
Also used : Path(java.nio.file.Path) JavaTestDocsGenerator(org.neo4j.doc.tools.JavaTestDocsGenerator) Graph(org.neo4j.doc.test.GraphDescription.Graph) Documented(org.neo4j.annotations.documented.Documented) Test(org.junit.Test)

Aggregations

Documented (org.neo4j.annotations.documented.Documented)43 Test (org.junit.Test)23 Test (org.junit.jupiter.api.Test)15 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)13 ResponseEntity (org.neo4j.doc.server.rest.RESTDocsGenerator.ResponseEntity)13 ResponseEntity (org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity)12 Graph (org.neo4j.doc.test.GraphDescription.Graph)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 ArrayList (java.util.ArrayList)6 List (java.util.List)5 Transaction (org.neo4j.graphdb.Transaction)4 Map (java.util.Map)3 HTTP (org.neo4j.doc.server.HTTP)3 JavaTestDocsGenerator (org.neo4j.doc.tools.JavaTestDocsGenerator)3 Node (org.neo4j.graphdb.Node)3 TraversalDescription (org.neo4j.graphdb.traversal.TraversalDescription)3 JsonHelper.jsonToMap (org.neo4j.server.rest.domain.JsonHelper.jsonToMap)3 HTTP (org.neo4j.test.server.HTTP)3 Statement (org.junit.runners.model.Statement)2 RESTDocsGenerator (org.neo4j.doc.server.rest.RESTDocsGenerator)2