use of org.neo4j.driver.Driver in project spring-boot by spring-projects.
the class Neo4jHealthIndicatorTests method neo4jIsUpWithOneSessionExpiredException.
@Test
void neo4jIsUpWithOneSessionExpiredException() {
ResultSummary resultSummary = ResultSummaryMock.createResultSummary("My Home", "");
Session session = mock(Session.class);
Result statementResult = mockStatementResult(resultSummary, "4711", "some edition");
AtomicInteger count = new AtomicInteger();
given(session.run(anyString())).will((invocation) -> {
if (count.compareAndSet(0, 1)) {
throw new SessionExpiredException("Session expired");
}
return statementResult;
});
Driver driver = mock(Driver.class);
given(driver.session(any(SessionConfig.class))).willReturn(session);
Neo4jHealthIndicator healthIndicator = new Neo4jHealthIndicator(driver);
Health health = healthIndicator.health();
assertThat(health.getStatus()).isEqualTo(Status.UP);
assertThat(health.getDetails()).containsEntry("server", "4711@My Home");
then(session).should(times(2)).close();
}
use of org.neo4j.driver.Driver in project spring-boot by spring-projects.
the class MockedDriverConfiguration method driver.
@Bean
Driver driver() {
Driver driver = mock(Driver.class);
TypeSystem typeSystem = mock(TypeSystem.class);
Session session = mock(Session.class);
given(driver.defaultTypeSystem()).willReturn(typeSystem);
given(driver.session(ArgumentMatchers.any(SessionConfig.class))).willReturn(session);
return driver;
}
use of org.neo4j.driver.Driver in project spring-boot by spring-projects.
the class Neo4jHealthIndicatorTests method neo4jIsUpWithEmptyDatabaseName.
@Test
void neo4jIsUpWithEmptyDatabaseName() {
ResultSummary resultSummary = ResultSummaryMock.createResultSummary("My Home", "");
Driver driver = mockDriver(resultSummary, "4711", "some edition");
Health health = new Neo4jHealthIndicator(driver).health();
assertThat(health.getStatus()).isEqualTo(Status.UP);
assertThat(health.getDetails()).containsEntry("server", "4711@My Home");
assertThat(health.getDetails()).doesNotContainKey("database");
assertThat(health.getDetails()).containsEntry("edition", "some edition");
}
use of org.neo4j.driver.Driver in project spring-boot by spring-projects.
the class Neo4jHealthIndicatorTests method neo4jIsDown.
@Test
void neo4jIsDown() {
Driver driver = mock(Driver.class);
given(driver.session(any(SessionConfig.class))).willThrow(ServiceUnavailableException.class);
Health health = new Neo4jHealthIndicator(driver).health();
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
assertThat(health.getDetails()).containsKeys("error");
}
use of org.neo4j.driver.Driver in project spring-boot by spring-projects.
the class Neo4jHealthIndicatorTests method neo4jIsUp.
@Test
void neo4jIsUp() {
ResultSummary resultSummary = ResultSummaryMock.createResultSummary("My Home", "test");
Driver driver = mockDriver(resultSummary, "4711", "ultimate collectors edition");
Health health = new Neo4jHealthIndicator(driver).health();
assertThat(health.getStatus()).isEqualTo(Status.UP);
assertThat(health.getDetails()).containsEntry("server", "4711@My Home");
assertThat(health.getDetails()).containsEntry("database", "test");
assertThat(health.getDetails()).containsEntry("edition", "ultimate collectors edition");
}
Aggregations