Search in sources :

Example 21 with Session

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

the class BoltStateHandlerTest method resetSessionOnReset.

@Test
public void resetSessionOnReset() throws Exception {
    // given
    Session sessionMock = mock(Session.class);
    Driver driverMock = stubResultSummaryInAnOpenSession(mock(Result.class), sessionMock, "neo4j-version");
    OfflineBoltStateHandler boltStateHandler = new OfflineBoltStateHandler(driverMock);
    boltStateHandler.connect();
    boltStateHandler.beginTransaction();
    // when
    boltStateHandler.reset();
    // then
    verify(sessionMock).reset();
}
Also used : 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)

Example 22 with Session

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

the class BoltStateHandlerTest method exceptionFromRunQueryDoesNotResetActualDatabaseNameToUnresolved.

@Test
public void exceptionFromRunQueryDoesNotResetActualDatabaseNameToUnresolved() throws CommandException {
    Session sessionMock = mock(Session.class);
    Result resultMock = mock(Result.class);
    Driver driverMock = stubResultSummaryInAnOpenSession(resultMock, sessionMock, "9.4.1-ALPHA", "my_default_db");
    ClientException databaseNotFound = new ClientException("Neo.ClientError.Database.DatabaseNotFound", "blah");
    when(sessionMock.run(any(Query.class))).thenThrow(databaseNotFound).thenReturn(resultMock);
    BoltStateHandler handler = new BoltStateHandler((s, authToken, config) -> driverMock, false);
    handler.connect(config);
    try {
        handler.runCypher("RETURN \"hello\"", Collections.emptyMap());
        fail("should fail on runCypher");
    } catch (Exception e) {
        assertThat(e, is(databaseNotFound));
        assertEquals("my_default_db", handler.getActualDatabaseAsReportedByServer());
    }
}
Also used : Driver(org.neo4j.driver.Driver) FakeDriver(org.neo4j.shell.test.bolt.FakeDriver) ClientException(org.neo4j.driver.exceptions.ClientException) SessionExpiredException(org.neo4j.driver.exceptions.SessionExpiredException) CommandException(org.neo4j.shell.exception.CommandException) ServiceUnavailableException(org.neo4j.driver.exceptions.ServiceUnavailableException) ClientException(org.neo4j.driver.exceptions.ClientException) Session(org.neo4j.driver.Session) FakeSession(org.neo4j.shell.test.bolt.FakeSession) Result(org.neo4j.driver.Result) Test(org.junit.Test)

Example 23 with Session

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

the class CypherShellTest method executeShouldPrintResult.

@Test
public void executeShouldPrintResult() throws CommandException {
    Driver mockedDriver = mock(Driver.class);
    Session session = mock(Session.class);
    BoltResult result = mock(ListBoltResult.class);
    BoltStateHandler boltStateHandler = mock(BoltStateHandler.class);
    when(boltStateHandler.isConnected()).thenReturn(true);
    when(boltStateHandler.runCypher(anyString(), anyMap())).thenReturn(Optional.of(result));
    doAnswer(a -> {
        ((LinePrinter) a.getArguments()[1]).printOut("999");
        return null;
    }).when(mockedPrettyPrinter).format(any(BoltResult.class), anyObject());
    when(mockedDriver.session()).thenReturn(session);
    OfflineTestShell shell = new OfflineTestShell(logger, boltStateHandler, mockedPrettyPrinter);
    shell.execute("RETURN 999");
    verify(logger).printOut(contains("999"));
}
Also used : BoltStateHandler(org.neo4j.shell.state.BoltStateHandler) Driver(org.neo4j.driver.Driver) BoltResult(org.neo4j.shell.state.BoltResult) ListBoltResult(org.neo4j.shell.state.ListBoltResult) Session(org.neo4j.driver.Session) LinePrinter(org.neo4j.shell.prettyprint.LinePrinter) Test(org.junit.Test)

Example 24 with Session

use of org.neo4j.driver.Session in project zeppelin by apache.

the class Neo4jCypherInterpreterTest method setUpNeo4jServer.

@BeforeClass
public static void setUpNeo4jServer() {
    try (Driver driver = GraphDatabase.driver(neo4jContainer.getBoltUrl());
        Session session = driver.session()) {
        session.run(String.format(CYPHER_FOREACH, LABEL_PERSON, "x % 10"));
        session.run(String.format(CHPHER_UNWIND, REL_KNOWS));
    }
}
Also used : Driver(org.neo4j.driver.Driver) Session(org.neo4j.driver.Session) BeforeClass(org.junit.BeforeClass)

Aggregations

Session (org.neo4j.driver.Session)24 Driver (org.neo4j.driver.Driver)20 Result (org.neo4j.driver.Result)17 Test (org.junit.Test)13 FakeSession (org.neo4j.shell.test.bolt.FakeSession)10 FakeDriver (org.neo4j.shell.test.bolt.FakeDriver)9 Test (org.junit.jupiter.api.Test)6 SessionConfig (org.neo4j.driver.SessionConfig)6 Record (org.neo4j.driver.Record)5 SessionExpiredException (org.neo4j.driver.exceptions.SessionExpiredException)4 HashMap (java.util.HashMap)3 BeforeClass (org.junit.BeforeClass)3 ClientException (org.neo4j.driver.exceptions.ClientException)3 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 List (java.util.List)2 Map (java.util.Map)2 PipelineResult (org.apache.beam.sdk.PipelineResult)2 SerializableCoder (org.apache.beam.sdk.coders.SerializableCoder)2