Search in sources :

Example 41 with Documented

use of org.neo4j.kernel.impl.annotations.Documented in project neo4j by neo4j.

the class TransactionTest method begin_a_transaction.

@Test
@Documented("Begin a transaction\n" + "\n" + "You begin a new transaction by posting zero or more Cypher statements\n" + "to the transaction endpoint. The server will respond with the result of\n" + "your statements, as well as the location of your open transaction.")
public void begin_a_transaction() throws JsonParseException {
    // Document
    ResponseEntity response = gen.get().expectedStatus(201).payload(quotedJson("{ 'statements': [ { 'statement': 'CREATE (n {props}) RETURN n', " + "'parameters': { 'props': { 'name': 'My Node' } } } ] }")).post(getDataUri() + "transaction");
    // Then
    Map<String, Object> result = jsonToMap(response.entity());
    assertNoErrors(result);
    Map<String, Object> node = resultCell(result, 0, 0);
    assertThat((String) node.get("name"), equalTo("My Node"));
}
Also used : ResponseEntity(org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Example 42 with Documented

use of org.neo4j.kernel.impl.annotations.Documented in project neo4j by neo4j.

the class TransactionTest method begin_and_commit_a_transaction_in_one_request.

@Test
@Documented("Begin and commit a transaction in one request\n" + "\n" + "If there is no need to keep a transaction open across multiple HTTP requests, you can begin a transaction,\n" + "execute statements, and commit with just a single HTTP request.")
public void begin_and_commit_a_transaction_in_one_request() throws JsonParseException {
    // Document
    ResponseEntity response = gen.get().expectedStatus(200).payload(quotedJson("{ 'statements': [ { 'statement': 'CREATE (n) RETURN id(n)' } ] }")).post(getDataUri() + "transaction/commit");
    // Then
    Map<String, Object> result = jsonToMap(response.entity());
    assertNoErrors(result);
    Integer id = resultCell(result, 0, 0);
    assertThat(GET(getNodeUri(id)).status(), is(200));
}
Also used : ResponseEntity(org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Example 43 with Documented

use of org.neo4j.kernel.impl.annotations.Documented in project neo4j by neo4j.

the class TransactionTest 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(getDataUri() + "transaction").location();
    // Document
    ResponseEntity response = gen.get().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);
    assertThat(GET(getNodeUri(id)).status(), is(200));
}
Also used : ResponseEntity(org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Example 44 with Documented

use of org.neo4j.kernel.impl.annotations.Documented in project neo4j by neo4j.

the class TransactionTest 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(getDataUri() + "transaction").location();
    // Document
    ResponseEntity response = gen.get().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);
}
Also used : ResponseEntity(org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity) ArrayList(java.util.ArrayList) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Example 45 with Documented

use of org.neo4j.kernel.impl.annotations.Documented in project neo4j by neo4j.

the class TestData method apply.

@Override
public Statement apply(final Statement base, final Description description) {
    final Title title = description.getAnnotation(Title.class);
    final Documented doc = description.getAnnotation(Documented.class);
    GraphDescription.Graph g = description.getAnnotation(GraphDescription.Graph.class);
    if (g == null) {
        g = description.getTestClass().getAnnotation(GraphDescription.Graph.class);
    }
    final GraphDescription graph = GraphDescription.create(g);
    return new Statement() {

        @Override
        public void evaluate() throws Throwable {
            product.set(create(graph, title == null ? null : title.value(), doc == null ? null : doc.value(), description.getMethodName()));
            try {
                try {
                    base.evaluate();
                } catch (Throwable err) {
                    try {
                        destroy(get(false), false);
                    } catch (Throwable sub) {
                        List<Throwable> failures = new ArrayList<Throwable>();
                        if (err instanceof MultipleFailureException) {
                            failures.addAll(((MultipleFailureException) err).getFailures());
                        } else {
                            failures.add(err);
                        }
                        failures.add(sub);
                        throw new MultipleFailureException(failures);
                    }
                    throw err;
                }
                destroy(get(false), false);
            } finally {
                product.set(null);
            }
        }
    };
}
Also used : Documented(org.neo4j.kernel.impl.annotations.Documented) MultipleFailureException(org.junit.runners.model.MultipleFailureException) Statement(org.junit.runners.model.Statement) ArrayList(java.util.ArrayList)

Aggregations

Documented (org.neo4j.kernel.impl.annotations.Documented)71 Test (org.junit.Test)70 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)26 Graph (org.neo4j.test.GraphDescription.Graph)21 ResponseEntity (org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity)20 Title (org.neo4j.test.TestData.Title)19 Node (org.neo4j.graphdb.Node)14 Matchers.containsString (org.hamcrest.Matchers.containsString)11 Transaction (org.neo4j.graphdb.Transaction)8 RelationshipRepresentationTest (org.neo4j.server.rest.repr.RelationshipRepresentationTest)7 JsonNode (org.codehaus.jackson.JsonNode)6 JaxRsResponse (org.neo4j.server.rest.JaxRsResponse)6 RESTRequestGenerator (org.neo4j.server.rest.RESTRequestGenerator)6 ArrayList (java.util.ArrayList)5 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)5 Relationship (org.neo4j.graphdb.Relationship)5 Map (java.util.Map)4 URI (java.net.URI)3 FunctionalTestHelper (org.neo4j.server.helpers.FunctionalTestHelper)3 RestRequest (org.neo4j.server.rest.RestRequest)3