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();
}
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());
}
}
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"));
}
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));
}
}
Aggregations