use of org.graylog.plugins.views.search.SearchSummary in project graylog2-server by Graylog2.
the class SearchesCleanUpJobTest method testForMixedReferencedNonReferencedExpiredAndNonexpiredSearches.
@Test
public void testForMixedReferencedNonReferencedExpiredAndNonexpiredSearches() {
final String searchId = "This search is in use";
final ViewSummaryDTO view = mock(ViewSummaryDTO.class);
when(view.searchId()).thenReturn(searchId);
when(viewService.streamAll()).thenReturn(Stream.of(view));
final SearchSummary search1 = mock(SearchSummary.class);
when(search1.createdAt()).thenReturn(DateTime.now(DateTimeZone.UTC).minus(Duration.standardDays(30)));
when(search1.id()).thenReturn(searchId);
final SearchSummary search2 = mock(SearchSummary.class);
when(search2.createdAt()).thenReturn(DateTime.now(DateTimeZone.UTC).minus(Duration.standardHours(2)));
final SearchSummary search3 = mock(SearchSummary.class);
when(search3.createdAt()).thenReturn(DateTime.now(DateTimeZone.UTC).minus(Duration.standardDays(30)));
when(search3.id()).thenReturn("This search is expired and should be deleted");
when(searchDbService.findSummaries()).thenReturn(Stream.of(search1, search2, search3));
when(searchDbService.getExpiredSearches(any(), any())).thenCallRealMethod();
this.searchesCleanUpJob.doRun();
final ArgumentCaptor<String> deletedSearchId = ArgumentCaptor.forClass(String.class);
verify(searchDbService, times(1)).delete(deletedSearchId.capture());
assertThat(deletedSearchId.getValue()).isEqualTo("This search is expired and should be deleted");
}
use of org.graylog.plugins.views.search.SearchSummary in project graylog2-server by Graylog2.
the class SearchesCleanUpJobTest method testForEmptyViews.
@Test
public void testForEmptyViews() {
when(viewService.streamAll()).thenReturn(Stream.empty());
final SearchSummary search = mock(SearchSummary.class);
when(search.createdAt()).thenReturn(DateTime.now(DateTimeZone.UTC).minus(Duration.standardDays(30)));
when(search.id()).thenReturn("This search is expired and should be deleted");
when(searchDbService.findSummaries()).thenReturn(Stream.of(search));
when(searchDbService.getExpiredSearches(any(), any())).thenCallRealMethod();
this.searchesCleanUpJob.doRun();
final ArgumentCaptor<String> deletedSearchId = ArgumentCaptor.forClass(String.class);
verify(searchDbService, times(1)).delete(deletedSearchId.capture());
assertThat(deletedSearchId.getValue()).isEqualTo("This search is expired and should be deleted");
}
Aggregations