@Test
  public void testIfAggregatedStatisticsAreSavedToDb() {
    // given
    final Date date1 =
        new DateTime()
            .withYear(2011)
            .withMonthOfYear(10)
            .withDayOfMonth(15)
            .withHourOfDay(12)
            .withMinuteOfHour(20)
            .toDate();
    final Date date2 =
        new DateTime()
            .withYear(2011)
            .withMonthOfYear(10)
            .withDayOfMonth(15)
            .withHourOfDay(12)
            .withMinuteOfHour(45)
            .toDate();
    final Date date3 =
        new DateTime()
            .withYear(2011)
            .withMonthOfYear(11)
            .withDayOfMonth(19)
            .withHourOfDay(12)
            .withMinuteOfHour(45)
            .toDate();
    final List<AggregatedSearchQueryInfo> aggrResults = new ArrayList<AggregatedSearchQueryInfo>();
    aggrResults.add(new AggregatedSearchQueryInfo(SOLR_CONFIG_NAME, "monitor", "en", 5, date1));
    aggrResults.add(new AggregatedSearchQueryInfo(SOLR_CONFIG_NAME, "monitor lcd", "en", 3, date2));
    aggrResults.add(new AggregatedSearchQueryInfo(SOLR_CONFIG_NAME, "canon", "en", 2, date3));

    Mockito.when(mockSolrQueryStatisticsAggregator.aggregate()).thenReturn(aggrResults);

    solrQueryStatisticsCollectorJob.setSolrQueryStatisticsAggregator(
        mockSolrQueryStatisticsAggregator);

    // when
    final PerformResult perform = solrQueryStatisticsCollectorJob.perform(null);

    // then
    org.fest.assertions.Assertions.assertThat(perform.getResult()).isEqualTo(CronJobResult.SUCCESS);
    org.fest.assertions.Assertions.assertThat(perform.getStatus())
        .isEqualTo(CronJobStatus.FINISHED);

    final SearchResult<SolrQueryAggregatedStatsModel> result =
        flexibleSearchService.search("SELECT {PK} FROM {SolrQueryAggregatedStats}");
    org.fest.assertions.Assertions.assertThat(result.getResult()).hasSize(3);
  }
  @Test
  public void testDisableCollectingStatistics() {
    // given
    solrQueryStatisticsCollectorJob.setEnableCollectingStatistics(false);

    // when
    final PerformResult perform = solrQueryStatisticsCollectorJob.perform(null);

    // then
    org.fest.assertions.Assertions.assertThat(perform.getResult()).isEqualTo(CronJobResult.SUCCESS);
    org.fest.assertions.Assertions.assertThat(perform.getStatus())
        .isEqualTo(CronJobStatus.FINISHED);

    final SearchResult<SolrQueryAggregatedStatsModel> result =
        flexibleSearchService.search("SELECT {PK} FROM {SolrQueryAggregatedStats}");
    org.fest.assertions.Assertions.assertThat(result.getResult()).isEmpty();
  }
  @Test
  public void testIfErrorDuringPerformance() {
    // given
    Mockito.when(mockSolrQueryStatisticsAggregator.aggregate()).thenThrow(new RuntimeException());
    solrQueryStatisticsCollectorJob.setSolrQueryStatisticsAggregator(
        mockSolrQueryStatisticsAggregator);

    TestUtils.disableFileAnalyzer("test for an error during job execution");
    // when
    final PerformResult perform = solrQueryStatisticsCollectorJob.perform(null);

    TestUtils.enableFileAnalyzer();

    // then
    org.fest.assertions.Assertions.assertThat(perform.getResult()).isEqualTo(CronJobResult.ERROR);
    org.fest.assertions.Assertions.assertThat(perform.getStatus())
        .isEqualTo(CronJobStatus.FINISHED);

    final SearchResult<SolrQueryAggregatedStatsModel> result =
        flexibleSearchService.search("SELECT {PK} FROM {SolrQueryAggregatedStats}");
    org.fest.assertions.Assertions.assertThat(result.getResult()).isEmpty();
  }