use of org.graylog.plugins.views.search.timeranges.OffsetRange in project graylog2-server by Graylog2.
the class OffsetRangeTest method returnsCorrectRangeForTimeRangeOfQuery.
@Test
public void returnsCorrectRangeForTimeRangeOfQuery() throws Exception {
final OffsetRange offsetRange = constructRange("300", "query", "");
final TimeRange sourceRange = mock(TimeRange.class);
when(sourceRange.getFrom()).thenReturn(DateTime.parse("2019-11-18T10:00:00.000Z"));
when(sourceRange.getTo()).thenReturn(DateTime.parse("2019-11-21T12:00:00.000Z"));
final Query query = queryWithTimeRange(sourceRange);
final TimeRange result = offsetRange.deriveTimeRange(query, null);
assertThat(result).isEqualTo(AbsoluteRange.create("2019-11-18T09:55:00.000Z", "2019-11-21T11:55:00.000Z"));
}
use of org.graylog.plugins.views.search.timeranges.OffsetRange in project graylog2-server by Graylog2.
the class OffsetRangeTest method returnsCorrectRangeWithZeroUnitOffset.
@Test
public void returnsCorrectRangeWithZeroUnitOffset() throws Exception {
final OffsetRange offsetRange = constructRange("0i", "search_type", "searchTypeId");
final TimeRange sourceRange = mock(TimeRange.class);
when(sourceRange.getFrom()).thenReturn(DateTime.parse("2019-11-18T10:00:00.000Z"));
when(sourceRange.getTo()).thenReturn(DateTime.parse("2019-11-21T12:00:00.000Z"));
final Query query = queryWithSearchTypeTimeRange(sourceRange, "searchTypeId");
final TimeRange result = offsetRange.deriveTimeRange(query, null);
assertThat(result).isEqualTo(AbsoluteRange.create("2019-11-18T10:00:00.000Z", "2019-11-21T12:00:00.000Z"));
}
use of org.graylog.plugins.views.search.timeranges.OffsetRange in project graylog2-server by Graylog2.
the class OffsetRangeTest method throwsExceptionIfInvalidSearchTypeIsReferenced.
@Test
public void throwsExceptionIfInvalidSearchTypeIsReferenced() throws Exception {
final OffsetRange offsetRange = constructRange("300", "search_type", "invalidSearchType");
final TimeRange sourceRange = mock(TimeRange.class);
when(sourceRange.getFrom()).thenReturn(DateTime.parse("2019-11-18T10:00:00.000Z"));
when(sourceRange.getTo()).thenReturn(DateTime.parse("2019-11-21T12:00:00.000Z"));
final Query query = mock(Query.class);
final SearchType searchType = mock(SearchType.class);
when(searchType.id()).thenReturn("searchTypeId");
when(searchType.timerange()).thenReturn(Optional.of(DerivedTimeRange.of(sourceRange)));
when(query.searchTypes()).thenReturn(ImmutableSet.of(searchType));
when(query.effectiveTimeRange(searchType)).thenReturn(sourceRange);
assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> offsetRange.deriveTimeRange(query, searchType)).withMessage("Search type searchTypeId has offset timerange referencing invalid search type: invalidSearchType");
}
use of org.graylog.plugins.views.search.timeranges.OffsetRange in project graylog2-server by Graylog2.
the class OffsetRangeTest method returnsCorrectRangeForTimeRangeOfQueryWithOffsetInUnits.
@Test
public void returnsCorrectRangeForTimeRangeOfQueryWithOffsetInUnits() throws Exception {
final OffsetRange offsetRange = constructRange("3i", "query", "");
final TimeRange sourceRange = mock(TimeRange.class);
when(sourceRange.getFrom()).thenReturn(DateTime.parse("2019-11-18T10:00:00.000Z"));
when(sourceRange.getTo()).thenReturn(DateTime.parse("2019-11-21T12:00:00.000Z"));
final Query query = queryWithTimeRange(sourceRange);
final TimeRange result = offsetRange.deriveTimeRange(query, null);
assertThat(result).isEqualTo(AbsoluteRange.create("2019-11-09T04:00:00.000Z", "2019-11-12T06:00:00.000Z"));
}
use of org.graylog.plugins.views.search.timeranges.OffsetRange in project graylog2-server by Graylog2.
the class OffsetRangeTest method throwsExceptionIfNoSearchTypeIsReferenced.
@Test
public void throwsExceptionIfNoSearchTypeIsReferenced() throws Exception {
final OffsetRange offsetRange = constructRange("300", "search_type", null);
final TimeRange sourceRange = mock(TimeRange.class);
when(sourceRange.getFrom()).thenReturn(DateTime.parse("2019-11-18T10:00:00.000Z"));
when(sourceRange.getTo()).thenReturn(DateTime.parse("2019-11-21T12:00:00.000Z"));
final Query query = mock(Query.class);
final SearchType searchType = mock(SearchType.class);
when(searchType.id()).thenReturn("searchTypeId");
when(searchType.timerange()).thenReturn(Optional.of(DerivedTimeRange.of(sourceRange)));
when(query.searchTypes()).thenReturn(ImmutableSet.of(searchType));
when(query.effectiveTimeRange(searchType)).thenReturn(sourceRange);
assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> offsetRange.deriveTimeRange(query, searchType)).withMessage("Search type searchTypeId has offset timerange referencing search type but id is missing!");
}
Aggregations