use of org.neo4j.driver.Session 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();
}
}
use of org.neo4j.driver.Session in project spring-boot by spring-projects.
the class Neo4jHealthIndicator method runHealthCheckQuery.
private void runHealthCheckQuery(Health.Builder builder) {
// all possible workloads
try (Session session = this.driver.session(DEFAULT_SESSION_CONFIG)) {
Result result = session.run(CYPHER);
Record record = result.single();
ResultSummary resultSummary = result.consume();
this.healthDetailsHandler.addHealthDetails(builder, new Neo4jHealthDetails(record, resultSummary));
}
}
use of org.neo4j.driver.Session in project neo4j by neo4j.
the class BoltStateHandlerTest method silentDisconnectCleansUp.
@Test
public void silentDisconnectCleansUp() throws Exception {
// given
boltStateHandler.connect();
Session session = boltStateHandler.session;
assertNotNull(session);
assertNotNull(boltStateHandler.driver);
assertTrue(boltStateHandler.session.isOpen());
// when
boltStateHandler.silentDisconnect();
// then
assertFalse(session.isOpen());
}
use of org.neo4j.driver.Session 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());
}
use of org.neo4j.driver.Session in project neo4j by neo4j.
the class BoltStateHandlerTest method shouldRunCypherQuery.
@Test
public void shouldRunCypherQuery() throws CommandException {
Session sessionMock = mock(Session.class);
Result resultMock = mock(Result.class);
Record recordMock = mock(Record.class);
Value valueMock = mock(Value.class);
Driver driverMock = stubResultSummaryInAnOpenSession(resultMock, sessionMock, "neo4j-version");
when(resultMock.list()).thenReturn(singletonList(recordMock));
when(valueMock.toString()).thenReturn("999");
when(recordMock.get(0)).thenReturn(valueMock);
when(sessionMock.run(any(Query.class))).thenReturn(resultMock);
OfflineBoltStateHandler boltStateHandler = new OfflineBoltStateHandler(driverMock);
boltStateHandler.connect();
BoltResult boltResult = boltStateHandler.runCypher("RETURN 999", new HashMap<>()).get();
verify(sessionMock).run(any(Query.class));
assertEquals("999", boltResult.getRecords().get(0).get(0).toString());
}
Aggregations