Search in sources :

Example 1 with StatsAnalytics

use of io.gravitee.rest.api.model.analytics.query.StatsAnalytics in project gravitee-management-rest-api by gravitee-io.

the class EnvironmentAnalyticsResourceTest method shouldGetCountAnalyticsWhenNotAdminAndApi.

@Test
public void shouldGetCountAnalyticsWhenNotAdminAndApi() {
    ApiEntity api = new ApiEntity();
    api.setId("apiId");
    when(apiService.findByUser(any(), any(), eq(false))).thenReturn(Collections.singleton(api));
    when(permissionService.hasPermission(API_ANALYTICS, api.getId(), READ)).thenReturn(true);
    Response response = envTarget().queryParam("type", "count").queryParam("field", "api").queryParam("interval", 1000).queryParam("to", 1000).request().get();
    assertThat(response).isNotNull();
    assertThat(response.getStatus()).isEqualTo(HttpStatusCode.OK_200);
    StatsAnalytics analytics = response.readEntity(StatsAnalytics.class);
    assertThat(analytics.getAvg()).isNull();
    assertThat(analytics.getCount()).isEqualTo(1);
}
Also used : Response(javax.ws.rs.core.Response) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) StatsAnalytics(io.gravitee.rest.api.model.analytics.query.StatsAnalytics) Test(org.junit.Test)

Example 2 with StatsAnalytics

use of io.gravitee.rest.api.model.analytics.query.StatsAnalytics in project gravitee-management-rest-api by gravitee-io.

the class EnvironmentAnalyticsResourceTest method shouldGetCountAnalyticsWhenNotAdminAndApp.

@Test
public void shouldGetCountAnalyticsWhenNotAdminAndApp() {
    ApplicationListItem app = new ApplicationListItem();
    app.setId("appId");
    when(applicationService.findByUser(any())).thenReturn(Collections.singleton(app));
    when(permissionService.hasPermission(APPLICATION_ANALYTICS, app.getId(), READ)).thenReturn(true);
    Response response = envTarget().queryParam("type", "count").queryParam("field", "application").queryParam("interval", 1000).queryParam("to", 1000).request().get();
    assertThat(response).isNotNull();
    assertThat(response.getStatus()).isEqualTo(HttpStatusCode.OK_200);
    StatsAnalytics analytics = response.readEntity(StatsAnalytics.class);
    assertThat(analytics.getAvg()).isNull();
    assertThat(analytics.getCount()).isEqualTo(1);
}
Also used : Response(javax.ws.rs.core.Response) ApplicationListItem(io.gravitee.rest.api.model.application.ApplicationListItem) StatsAnalytics(io.gravitee.rest.api.model.analytics.query.StatsAnalytics) Test(org.junit.Test)

Example 3 with StatsAnalytics

use of io.gravitee.rest.api.model.analytics.query.StatsAnalytics in project gravitee-management-rest-api by gravitee-io.

the class EnvironmentAnalyticsResourceTest method shouldGetEmptyCountAnalyticsWhenNotAdminAndNoApi.

@Test
public void shouldGetEmptyCountAnalyticsWhenNotAdminAndNoApi() {
    when(apiService.findByUser(any(), eq(null), eq(false))).thenReturn(Collections.emptySet());
    Response response = envTarget().queryParam("type", "count").queryParam("field", "api").queryParam("interval", 1000).queryParam("to", 1000).request().get();
    assertThat(response).isNotNull();
    assertThat(response.getStatus()).isEqualTo(HttpStatusCode.OK_200);
    StatsAnalytics analytics = response.readEntity(StatsAnalytics.class);
    assertThat(analytics.getCount()).isNull();
}
Also used : Response(javax.ws.rs.core.Response) StatsAnalytics(io.gravitee.rest.api.model.analytics.query.StatsAnalytics) Test(org.junit.Test)

Example 4 with StatsAnalytics

use of io.gravitee.rest.api.model.analytics.query.StatsAnalytics in project gravitee-management-rest-api by gravitee-io.

the class EnvironmentAnalyticsResourceTest method shouldGetEmptyStatsAnalyticsWhenNotAdminAndNoApp.

@Test
public void shouldGetEmptyStatsAnalyticsWhenNotAdminAndNoApp() {
    when(applicationService.findByUser(any())).thenReturn(Collections.emptySet());
    Response response = envTarget().queryParam("type", "stats").queryParam("field", "application").queryParam("interval", 1000).queryParam("to", 1000).request().get();
    assertThat(response).isNotNull();
    assertThat(response.getStatus()).isEqualTo(HttpStatusCode.OK_200);
    StatsAnalytics analytics = response.readEntity(StatsAnalytics.class);
    assertThat(analytics.getAvg()).isNull();
    assertThat(analytics.getCount()).isNull();
}
Also used : Response(javax.ws.rs.core.Response) StatsAnalytics(io.gravitee.rest.api.model.analytics.query.StatsAnalytics) Test(org.junit.Test)

Example 5 with StatsAnalytics

use of io.gravitee.rest.api.model.analytics.query.StatsAnalytics in project gravitee-management-rest-api by gravitee-io.

the class EnvironmentAnalyticsResourceTest method shouldGetEmptyCountAnalyticsWhenNotAdminAndNoApp.

@Test
public void shouldGetEmptyCountAnalyticsWhenNotAdminAndNoApp() {
    when(applicationService.findByUser(any())).thenReturn(Collections.emptySet());
    Response response = envTarget().queryParam("type", "count").queryParam("field", "application").queryParam("interval", 1000).queryParam("to", 1000).request().get();
    assertThat(response).isNotNull();
    assertThat(response.getStatus()).isEqualTo(HttpStatusCode.OK_200);
    StatsAnalytics analytics = response.readEntity(StatsAnalytics.class);
    assertThat(analytics.getCount()).isNull();
}
Also used : Response(javax.ws.rs.core.Response) StatsAnalytics(io.gravitee.rest.api.model.analytics.query.StatsAnalytics) Test(org.junit.Test)

Aggregations

StatsAnalytics (io.gravitee.rest.api.model.analytics.query.StatsAnalytics)10 Response (javax.ws.rs.core.Response)7 Test (org.junit.Test)7 StatsQuery (io.gravitee.rest.api.model.analytics.query.StatsQuery)2 SubscriptionEntity (io.gravitee.rest.api.model.SubscriptionEntity)1 Analytics (io.gravitee.rest.api.model.analytics.Analytics)1 HistogramAnalytics (io.gravitee.rest.api.model.analytics.HistogramAnalytics)1 TopHitsAnalytics (io.gravitee.rest.api.model.analytics.TopHitsAnalytics)1 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)1 ApplicationListItem (io.gravitee.rest.api.model.application.ApplicationListItem)1 ApiMetrics (io.gravitee.rest.api.portal.rest.model.ApiMetrics)1 ErrorResponse (io.gravitee.rest.api.portal.rest.model.ErrorResponse)1 ApiNotFoundException (io.gravitee.rest.api.service.exceptions.ApiNotFoundException)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 Instant (java.time.Instant)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1