Search in sources :

Example 11 with Result

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

the class Neo4jHealthIndicatorTests method mockStatementResult.

private Result mockStatementResult(ResultSummary resultSummary, String version, String edition) {
    Record record = mock(Record.class);
    given(record.get("edition")).willReturn(Values.value(edition));
    given(record.get("version")).willReturn(Values.value(version));
    Result statementResult = mock(Result.class);
    given(statementResult.single()).willReturn(record);
    given(statementResult.consume()).willReturn(resultSummary);
    return statementResult;
}
Also used : Record(org.neo4j.driver.Record) Result(org.neo4j.driver.Result)

Example 12 with Result

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

the class Neo4jHealthIndicatorTests method mockDriver.

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

Example 13 with Result

use of org.neo4j.driver.Result 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 14 with Result

use of org.neo4j.driver.Result in project zeppelin by apache.

the class Neo4jConnectionManager method execute.

public List<Record> execute(String cypherQuery, InterpreterContext interpreterContext) {
    Map<String, Object> params = new HashMap<>();
    if (interpreterContext != null) {
        ResourcePool resourcePool = interpreterContext.getResourcePool();
        Set<String> keys = extractParams(cypherQuery, PROPERTY_PATTERN, REPLACE_CURLY_BRACKETS);
        keys.addAll(extractParams(cypherQuery, $_PATTERN, REPLACE_$));
        for (String key : keys) {
            Resource resource = resourcePool.get(key);
            if (resource != null) {
                params.put(key, resource.get());
            }
        }
    }
    LOGGER.debug("Executing cypher query {} with params {}", cypherQuery, params);
    try (Session session = getSession()) {
        final Result result = params.isEmpty() ? session.run(cypherQuery) : session.run(cypherQuery, params);
        return result.list();
    }
}
Also used : HashMap(java.util.HashMap) Resource(org.apache.zeppelin.resource.Resource) ResourcePool(org.apache.zeppelin.resource.ResourcePool) Session(org.neo4j.driver.Session) Result(org.neo4j.driver.Result)

Example 15 with Result

use of org.neo4j.driver.Result 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();
    }
}
Also used : Transaction(org.neo4j.driver.Transaction) Session(org.neo4j.driver.Session) Result(org.neo4j.driver.Result) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Result (org.neo4j.driver.Result)29 Test (org.junit.Test)19 Session (org.neo4j.driver.Session)16 Driver (org.neo4j.driver.Driver)13 StringContains.containsString (org.hamcrest.core.StringContains.containsString)8 BoltResult (org.neo4j.shell.state.BoltResult)8 ListBoltResult (org.neo4j.shell.state.ListBoltResult)8 FakeDriver (org.neo4j.shell.test.bolt.FakeDriver)8 FakeSession (org.neo4j.shell.test.bolt.FakeSession)8 Record (org.neo4j.driver.Record)7 SessionConfig (org.neo4j.driver.SessionConfig)5 ClientException (org.neo4j.driver.exceptions.ClientException)5 SessionExpiredException (org.neo4j.driver.exceptions.SessionExpiredException)5 Query (org.neo4j.driver.Query)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Test (org.junit.jupiter.api.Test)3 Value (org.neo4j.driver.Value)3 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2