Search in sources :

Example 1 with SummaryCounters

use of org.neo4j.driver.summary.SummaryCounters in project neo4j by neo4j.

the class PrettyPrinterTest method returnStatisticsForEmptyRecords.

@Test
public void returnStatisticsForEmptyRecords() {
    // given
    ResultSummary resultSummary = mock(ResultSummary.class);
    SummaryCounters summaryCounters = mock(SummaryCounters.class);
    BoltResult result = new ListBoltResult(Collections.emptyList(), resultSummary);
    when(resultSummary.counters()).thenReturn(summaryCounters);
    when(summaryCounters.labelsAdded()).thenReturn(1);
    when(summaryCounters.nodesCreated()).thenReturn(10);
    // when
    String actual = verbosePrinter.format(result);
    // then
    assertThat(actual, containsString("Added 10 nodes, Added 1 labels"));
}
Also used : ListBoltResult(org.neo4j.shell.state.ListBoltResult) ResultSummary(org.neo4j.driver.summary.ResultSummary) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) SummaryCounters(org.neo4j.driver.summary.SummaryCounters) BoltResult(org.neo4j.shell.state.BoltResult) ListBoltResult(org.neo4j.shell.state.ListBoltResult) Test(org.junit.Test)

Example 2 with SummaryCounters

use of org.neo4j.driver.summary.SummaryCounters in project neo4j by neo4j.

the class StatisticsCollector method collectStatistics.

private String collectStatistics(@Nonnull ResultSummary summary) {
    List<String> statistics = new ArrayList<>();
    SummaryCounters counters = summary.counters();
    if (counters == null) {
        return "";
    }
    if (counters.nodesCreated() != 0) {
        statistics.add(String.format("Added %d nodes", counters.nodesCreated()));
    }
    if (counters.nodesDeleted() != 0) {
        statistics.add(String.format("Deleted %d nodes", counters.nodesDeleted()));
    }
    if (counters.relationshipsCreated() != 0) {
        statistics.add(String.format("Created %d relationships", counters.relationshipsCreated()));
    }
    if (counters.relationshipsDeleted() != 0) {
        statistics.add(String.format("Deleted %d relationships", counters.relationshipsDeleted()));
    }
    if (counters.propertiesSet() != 0) {
        statistics.add(String.format("Set %d properties", counters.propertiesSet()));
    }
    if (counters.labelsAdded() != 0) {
        statistics.add(String.format("Added %d labels", counters.labelsAdded()));
    }
    if (counters.labelsRemoved() != 0) {
        statistics.add(String.format("Removed %d labels", counters.labelsRemoved()));
    }
    if (counters.indexesAdded() != 0) {
        statistics.add(String.format("Added %d indexes", counters.indexesAdded()));
    }
    if (counters.indexesRemoved() != 0) {
        statistics.add(String.format("Removed %d indexes", counters.indexesRemoved()));
    }
    if (counters.constraintsAdded() != 0) {
        statistics.add(String.format("Added %d constraints", counters.constraintsAdded()));
    }
    if (counters.constraintsRemoved() != 0) {
        statistics.add(String.format("Removed %d constraints", counters.constraintsRemoved()));
    }
    return statistics.stream().collect(Collectors.joining(", "));
}
Also used : ArrayList(java.util.ArrayList) SummaryCounters(org.neo4j.driver.summary.SummaryCounters)

Example 3 with SummaryCounters

use of org.neo4j.driver.summary.SummaryCounters in project neo4j by neo4j.

the class StatisticsCollectorTest method returnStatisticsForDefaultFormatting.

@Test
public void returnStatisticsForDefaultFormatting() throws Exception {
    // given
    ResultSummary resultSummary = mock(ResultSummary.class);
    SummaryCounters summaryCounters = mock(SummaryCounters.class);
    when(resultSummary.counters()).thenReturn(summaryCounters);
    when(summaryCounters.labelsAdded()).thenReturn(1);
    when(summaryCounters.nodesCreated()).thenReturn(10);
    // when
    String actual = new StatisticsCollector(Format.VERBOSE).collect(resultSummary);
    // then
    assertThat(actual, is("Added 10 nodes, Added 1 labels"));
}
Also used : ResultSummary(org.neo4j.driver.summary.ResultSummary) SummaryCounters(org.neo4j.driver.summary.SummaryCounters) Test(org.junit.Test)

Aggregations

SummaryCounters (org.neo4j.driver.summary.SummaryCounters)3 Test (org.junit.Test)2 ResultSummary (org.neo4j.driver.summary.ResultSummary)2 ArrayList (java.util.ArrayList)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 BoltResult (org.neo4j.shell.state.BoltResult)1 ListBoltResult (org.neo4j.shell.state.ListBoltResult)1