Search in sources :

Example 1 with Query

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

the class TableOutputFormatterTest method mockResult.

private Result mockResult(List<String> cols, Object... data) {
    Result result = mock(Result.class);
    Query query = mock(Query.class);
    ResultSummary summary = mock(ResultSummary.class);
    when(summary.query()).thenReturn(query);
    when(result.keys()).thenReturn(cols);
    List<Record> records = new ArrayList<>();
    List<Object> input = asList(data);
    int width = cols.size();
    for (int row = 0; row < input.size() / width; row++) {
        records.add(record(cols, input.subList(row * width, (row + 1) * width)));
    }
    when(result.list()).thenReturn(records);
    when(result.consume()).thenReturn(summary);
    when(result.consume()).thenReturn(summary);
    return result;
}
Also used : Query(org.neo4j.driver.Query) ResultSummary(org.neo4j.driver.summary.ResultSummary) ArrayList(java.util.ArrayList) InternalRecord(org.neo4j.driver.internal.InternalRecord) Record(org.neo4j.driver.Record) Matchers.anyObject(org.mockito.Matchers.anyObject) BoltResult(org.neo4j.shell.state.BoltResult) ListBoltResult(org.neo4j.shell.state.ListBoltResult) Result(org.neo4j.driver.Result)

Example 2 with Query

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

the class OutputFormatterTest method shouldReportTotalDBHits.

@Test
public void shouldReportTotalDBHits() {
    Value labelScan = buildOperator("NodeByLabelScan", 1002L, 1001L, null);
    Value filter = buildOperator("Filter", 1402, 280, labelScan);
    Value planMap = buildOperator("ProduceResults", 0, 280, filter);
    ProfiledPlan plan = PROFILED_PLAN_FROM_VALUE.apply(planMap);
    ResultSummary summary = new InternalResultSummary(new Query("PROFILE MATCH (n:LABEL) WHERE 20 < n.age < 35 return n"), new InternalServerInfo("agent", new BoltServerAddress("localhost:7687"), ServerVersion.vInDev, BoltProtocolV43.VERSION), new InternalDatabaseInfo("neo4j"), QueryType.READ_ONLY, null, plan, plan, Collections.emptyList(), 39, 55);
    // When
    Map<String, Value> info = OutputFormatter.info(summary);
    // Then
    assertThat(info.get("DbHits").asLong(), equalTo(2404L));
}
Also used : ProfiledPlan(org.neo4j.driver.summary.ProfiledPlan) Query(org.neo4j.driver.Query) InternalDatabaseInfo(org.neo4j.driver.internal.summary.InternalDatabaseInfo) MapValue(org.neo4j.driver.internal.value.MapValue) Value(org.neo4j.driver.Value) ListValue(org.neo4j.driver.internal.value.ListValue) InternalResultSummary(org.neo4j.driver.internal.summary.InternalResultSummary) ResultSummary(org.neo4j.driver.summary.ResultSummary) InternalServerInfo(org.neo4j.driver.internal.summary.InternalServerInfo) InternalResultSummary(org.neo4j.driver.internal.summary.InternalResultSummary) BoltServerAddress(org.neo4j.driver.internal.BoltServerAddress) Test(org.junit.Test)

Aggregations

Query (org.neo4j.driver.Query)2 ResultSummary (org.neo4j.driver.summary.ResultSummary)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 Matchers.anyObject (org.mockito.Matchers.anyObject)1 Record (org.neo4j.driver.Record)1 Result (org.neo4j.driver.Result)1 Value (org.neo4j.driver.Value)1 BoltServerAddress (org.neo4j.driver.internal.BoltServerAddress)1 InternalRecord (org.neo4j.driver.internal.InternalRecord)1 InternalDatabaseInfo (org.neo4j.driver.internal.summary.InternalDatabaseInfo)1 InternalResultSummary (org.neo4j.driver.internal.summary.InternalResultSummary)1 InternalServerInfo (org.neo4j.driver.internal.summary.InternalServerInfo)1 ListValue (org.neo4j.driver.internal.value.ListValue)1 MapValue (org.neo4j.driver.internal.value.MapValue)1 ProfiledPlan (org.neo4j.driver.summary.ProfiledPlan)1 BoltResult (org.neo4j.shell.state.BoltResult)1 ListBoltResult (org.neo4j.shell.state.ListBoltResult)1