Search in sources :

Example 21 with Driver

use of org.neo4j.driver.Driver in project spring-boot by spring-projects.

the class Neo4jAutoConfigurationTests method uriWithAdvancedSchemesAreDetected.

@ParameterizedTest
@ValueSource(strings = { "bolt+s", "bolt+ssc", "neo4j+s", "neo4j+ssc" })
void uriWithAdvancedSchemesAreDetected(String scheme) {
    this.contextRunner.withPropertyValues("spring.neo4j.uri=" + scheme + "://localhost:4711").run((ctx) -> {
        assertThat(ctx).hasSingleBean(Driver.class);
        Driver driver = ctx.getBean(Driver.class);
        assertThat(driver.isEncrypted()).isTrue();
    });
}
Also used : Driver(org.neo4j.driver.Driver) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 22 with Driver

use of org.neo4j.driver.Driver in project spring-boot by spring-projects.

the class Neo4jReactiveHealthIndicatorTests method neo4jIsUpWithOneSessionExpiredException.

@Test
void neo4jIsUpWithOneSessionExpiredException() {
    ResultSummary resultSummary = ResultSummaryMock.createResultSummary("My Home", "");
    RxSession session = mock(RxSession.class);
    RxResult 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.rxSession(any(SessionConfig.class))).willReturn(session);
    Neo4jReactiveHealthIndicator healthIndicator = new Neo4jReactiveHealthIndicator(driver);
    healthIndicator.health().as(StepVerifier::create).consumeNextWith((health) -> {
        assertThat(health.getStatus()).isEqualTo(Status.UP);
        assertThat(health.getDetails()).containsEntry("server", "4711@My Home");
        assertThat(health.getDetails()).containsEntry("edition", "some edition");
    }).verifyComplete();
    then(session).should(times(2)).close();
}
Also used : Status(org.springframework.boot.actuate.health.Status) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Driver(org.neo4j.driver.Driver) StepVerifier(reactor.test.StepVerifier) RxSession(org.neo4j.driver.reactive.RxSession) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SessionExpiredException(org.neo4j.driver.exceptions.SessionExpiredException) BDDMockito.then(org.mockito.BDDMockito.then) Mono(reactor.core.publisher.Mono) Mockito.times(org.mockito.Mockito.times) RxResult(org.neo4j.driver.reactive.RxResult) Test(org.junit.jupiter.api.Test) Values(org.neo4j.driver.Values) SessionConfig(org.neo4j.driver.SessionConfig) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BDDMockito.given(org.mockito.BDDMockito.given) ServiceUnavailableException(org.neo4j.driver.exceptions.ServiceUnavailableException) ResultSummary(org.neo4j.driver.summary.ResultSummary) Record(org.neo4j.driver.Record) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) RxSession(org.neo4j.driver.reactive.RxSession) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ResultSummary(org.neo4j.driver.summary.ResultSummary) Driver(org.neo4j.driver.Driver) SessionConfig(org.neo4j.driver.SessionConfig) SessionExpiredException(org.neo4j.driver.exceptions.SessionExpiredException) StepVerifier(reactor.test.StepVerifier) RxResult(org.neo4j.driver.reactive.RxResult) Test(org.junit.jupiter.api.Test)

Example 23 with Driver

use of org.neo4j.driver.Driver in project spring-boot by spring-projects.

the class Neo4jReactiveHealthIndicatorTests method mockDriver.

private Driver mockDriver(ResultSummary resultSummary, String version, String edition) {
    RxResult statementResult = mockStatementResult(resultSummary, version, edition);
    RxSession session = mock(RxSession.class);
    given(session.run(anyString())).willReturn(statementResult);
    Driver driver = mock(Driver.class);
    given(driver.rxSession(any(SessionConfig.class))).willReturn(session);
    return driver;
}
Also used : RxSession(org.neo4j.driver.reactive.RxSession) Driver(org.neo4j.driver.Driver) SessionConfig(org.neo4j.driver.SessionConfig) RxResult(org.neo4j.driver.reactive.RxResult)

Example 24 with Driver

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

the class BoltStateHandlerTest method serverVersionIsNotEmptyAfterConnect.

@Test
public void serverVersionIsNotEmptyAfterConnect() throws CommandException {
    Driver fakeDriver = new FakeDriver();
    BoltStateHandler handler = new BoltStateHandler((s, authToken, config) -> fakeDriver, false);
    handler.connect(config);
    assertEquals("4.3.0", handler.getServerVersion());
}
Also used : Driver(org.neo4j.driver.Driver) FakeDriver(org.neo4j.shell.test.bolt.FakeDriver) FakeDriver(org.neo4j.shell.test.bolt.FakeDriver) Test(org.junit.Test)

Example 25 with Driver

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

the class BoltStateHandlerTest method stubResultSummaryInAnOpenSession.

private Driver stubResultSummaryInAnOpenSession(Result resultMock, Session sessionMock, String protocolVersion, String databaseName) {
    Driver driverMock = mock(Driver.class);
    ResultSummary resultSummary = mock(ResultSummary.class);
    ServerInfo serverInfo = mock(ServerInfo.class);
    DatabaseInfo databaseInfo = mock(DatabaseInfo.class);
    when(resultSummary.server()).thenReturn(serverInfo);
    when(serverInfo.protocolVersion()).thenReturn(protocolVersion);
    when(resultMock.consume()).thenReturn(resultSummary);
    when(resultSummary.database()).thenReturn(databaseInfo);
    when(databaseInfo.name()).thenReturn(databaseName);
    when(sessionMock.isOpen()).thenReturn(true);
    when(sessionMock.run("CALL db.ping()")).thenReturn(resultMock);
    when(sessionMock.run(anyString(), any(Value.class))).thenReturn(resultMock);
    when(driverMock.session(any())).thenReturn(sessionMock);
    return driverMock;
}
Also used : DatabaseInfo(org.neo4j.driver.summary.DatabaseInfo) ServerInfo(org.neo4j.driver.summary.ServerInfo) ResultSummary(org.neo4j.driver.summary.ResultSummary) Value(org.neo4j.driver.Value) Driver(org.neo4j.driver.Driver) FakeDriver(org.neo4j.shell.test.bolt.FakeDriver)

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