use of io.gravitee.rest.api.model.analytics.query.Aggregation in project gravitee-management-rest-api by gravitee-io.
the class ApplicationAnalyticsResourceTest method shouldGetDateHistoAnalytics.
@Test
public void shouldGetDateHistoAnalytics() {
final Response response = target(APPLICATION).path("analytics").queryParam("from", 0).queryParam("to", 100).queryParam("interval", 10_000).queryParam("query", APPLICATION).queryParam("type", "DATE_HISTO").queryParam("aggs", "AVG:hit").request().get();
assertEquals(HttpStatusCode.OK_200, response.getStatus());
ArgumentCaptor<DateHistogramQuery> queryCaptor = ArgumentCaptor.forClass(DateHistogramQuery.class);
Mockito.verify(analyticsService).execute(queryCaptor.capture());
final DateHistogramQuery query = queryCaptor.getValue();
assertEquals(0, query.getFrom());
assertEquals(100, query.getTo());
assertEquals(10_000, query.getInterval());
assertEquals(ANALYTICS_ROOT_FIELD, query.getRootField());
assertEquals(APPLICATION, query.getRootIdentifier());
List<Aggregation> aggregations = query.getAggregations();
assertNotNull(aggregations);
assertEquals(1, aggregations.size());
Aggregation agg = aggregations.get(0);
assertNotNull(agg);
assertEquals(AggregationType.AVG, agg.type());
assertEquals("hit", agg.field());
}
Aggregations