Search in sources :

Example 1 with Transaction

use of org.neo4j.driver.Transaction in project neo4j by neo4j.

the class CommunityEditionEndToEndTest method beforeEach.

@BeforeEach
void beforeEach() {
    try (Transaction tx = driver.session().beginTransaction()) {
        tx.run("MATCH (n) DETACH DELETE n");
        tx.run("CREATE (:Person {name: 'Anna', uid: 0, age: 30})").consume();
        tx.run("CREATE (:Person {name: 'Bob',  uid: 1, age: 40})").consume();
        tx.commit();
    }
}
Also used : Transaction(org.neo4j.driver.Transaction) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with Transaction

use of org.neo4j.driver.Transaction in project spring-boot by spring-projects.

the class Neo4jAutoConfigurationIntegrationTests method driverCanHandleRequest.

@Test
void driverCanHandleRequest() {
    try (Session session = this.driver.session();
        Transaction tx = session.beginTransaction()) {
        Result statementResult = tx.run("MATCH (n:Thing) RETURN n LIMIT 1");
        assertThat(statementResult.hasNext()).isFalse();
        tx.commit();
    }
}
Also used : Transaction(org.neo4j.driver.Transaction) Session(org.neo4j.driver.Session) Result(org.neo4j.driver.Result) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with Transaction

use of org.neo4j.driver.Transaction in project neo4j by neo4j.

the class SnapshotExecutionTest method beforeEach.

@BeforeEach
void beforeEach() {
    try (Transaction tx = driver.session().beginTransaction()) {
        tx.run("MATCH (n) DETACH DELETE n");
        tx.run("CREATE (:First {number: 0})").consume();
        tx.run("CREATE (:Second {number: 0})").consume();
        tx.commit();
    }
}
Also used : Transaction(org.neo4j.driver.Transaction) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with Transaction

use of org.neo4j.driver.Transaction in project neo4j by neo4j.

the class BoltStateHandlerTest method whenInTransactionHandlerLetsTransactionDoTheWork.

@Test
public void whenInTransactionHandlerLetsTransactionDoTheWork() throws CommandException {
    Transaction transactionMock = mock(Transaction.class);
    Session sessionMock = mock(Session.class);
    when(sessionMock.beginTransaction()).thenReturn(transactionMock);
    Driver driverMock = stubResultSummaryInAnOpenSession(mock(Result.class), sessionMock, "neo4j-version");
    Result result = mock(Result.class);
    when(transactionMock.run(any(Query.class))).thenReturn(result);
    OfflineBoltStateHandler boltStateHandler = new OfflineBoltStateHandler(driverMock);
    boltStateHandler.connect();
    boltStateHandler.beginTransaction();
    BoltResult boltResult = boltStateHandler.runCypher("UNWIND [1,2] as num RETURN *", Collections.emptyMap()).get();
    assertEquals(result, boltResult.iterate());
    boltStateHandler.commitTransaction();
    assertFalse(boltStateHandler.isTransactionOpen());
}
Also used : Transaction(org.neo4j.driver.Transaction) Query(org.neo4j.driver.Query) Driver(org.neo4j.driver.Driver) FakeDriver(org.neo4j.shell.test.bolt.FakeDriver) Session(org.neo4j.driver.Session) FakeSession(org.neo4j.shell.test.bolt.FakeSession) Result(org.neo4j.driver.Result) Test(org.junit.Test)

Aggregations

Transaction (org.neo4j.driver.Transaction)4 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Result (org.neo4j.driver.Result)2 Session (org.neo4j.driver.Session)2 Test (org.junit.Test)1 Test (org.junit.jupiter.api.Test)1 Driver (org.neo4j.driver.Driver)1 Query (org.neo4j.driver.Query)1 FakeDriver (org.neo4j.shell.test.bolt.FakeDriver)1 FakeSession (org.neo4j.shell.test.bolt.FakeSession)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1