Search in sources :

Example 16 with Driver

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();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Health(org.springframework.boot.actuate.health.Health) ResultSummary(org.neo4j.driver.summary.ResultSummary) Driver(org.neo4j.driver.Driver) SessionConfig(org.neo4j.driver.SessionConfig) SessionExpiredException(org.neo4j.driver.exceptions.SessionExpiredException) Session(org.neo4j.driver.Session) Result(org.neo4j.driver.Result) Test(org.junit.jupiter.api.Test)

Example 17 with Driver

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;
}
Also used : TypeSystem(org.neo4j.driver.types.TypeSystem) Driver(org.neo4j.driver.Driver) SessionConfig(org.neo4j.driver.SessionConfig) Session(org.neo4j.driver.Session) Bean(org.springframework.context.annotation.Bean)

Example 18 with 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");
}
Also used : Health(org.springframework.boot.actuate.health.Health) ResultSummary(org.neo4j.driver.summary.ResultSummary) Driver(org.neo4j.driver.Driver) Test(org.junit.jupiter.api.Test)

Example 19 with Driver

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");
}
Also used : Health(org.springframework.boot.actuate.health.Health) Driver(org.neo4j.driver.Driver) SessionConfig(org.neo4j.driver.SessionConfig) Test(org.junit.jupiter.api.Test)

Example 20 with Driver

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");
}
Also used : Health(org.springframework.boot.actuate.health.Health) ResultSummary(org.neo4j.driver.summary.ResultSummary) Driver(org.neo4j.driver.Driver) Test(org.junit.jupiter.api.Test)

Aggregations

Driver (org.neo4j.driver.Driver)33 Session (org.neo4j.driver.Session)22 Result (org.neo4j.driver.Result)16 Test (org.junit.Test)15 FakeDriver (org.neo4j.shell.test.bolt.FakeDriver)13 Test (org.junit.jupiter.api.Test)12 SessionConfig (org.neo4j.driver.SessionConfig)11 FakeSession (org.neo4j.shell.test.bolt.FakeSession)11 ResultSummary (org.neo4j.driver.summary.ResultSummary)8 Record (org.neo4j.driver.Record)7 SessionExpiredException (org.neo4j.driver.exceptions.SessionExpiredException)7 ServiceUnavailableException (org.neo4j.driver.exceptions.ServiceUnavailableException)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 BeforeClass (org.junit.BeforeClass)3 Health (org.springframework.boot.actuate.health.Health)3 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 List (java.util.List)2