Search in sources :

Example 11 with Application

use of io.gravitee.rest.api.portal.rest.model.Application in project gravitee-management-rest-api by gravitee-io.

the class ApiSubscribersResourceTest method shouldGetApiSubscribersAsPrimaryOwner.

@Test
public void shouldGetApiSubscribersAsPrimaryOwner() {
    TopHitsAnalytics mockAnalytics = new TopHitsAnalytics();
    Map<String, Long> mockedValues = new HashMap<>();
    mockedValues.put("A", 10L);
    mockedValues.put("B", 20L);
    mockedValues.put("C", 30L);
    mockAnalytics.setValues(mockedValues);
    doReturn(mockAnalytics).when(analyticsService).execute(any(GroupByQuery.class));
    SubscriptionEntity subA1 = new SubscriptionEntity();
    subA1.setApplication("A");
    subA1.setApi(API);
    SubscriptionEntity subB1 = new SubscriptionEntity();
    subB1.setApplication("B");
    subB1.setApi(API);
    SubscriptionEntity subC1 = new SubscriptionEntity();
    subC1.setApplication("C");
    subC1.setApi(API);
    doReturn(Arrays.asList(subB1, subC1, subA1)).when(subscriptionService).search(any());
    ApplicationEntity appA = new ApplicationEntity();
    appA.setId("A");
    doReturn(appA).when(applicationService).findById("A");
    doReturn(new Application().id("A")).when(applicationMapper).convert(eq(appA), any());
    ApplicationEntity appB = new ApplicationEntity();
    appB.setId("B");
    doReturn(appB).when(applicationService).findById("B");
    doReturn(new Application().id("B")).when(applicationMapper).convert(eq(appB), any());
    ApplicationEntity appC = new ApplicationEntity();
    appC.setId("C");
    doReturn(appC).when(applicationService).findById("C");
    doReturn(new Application().id("C")).when(applicationMapper).convert(eq(appC), any());
    final Response response = target(API).path("subscribers").request().get();
    assertEquals(OK_200, response.getStatus());
    final ApplicationsResponse applicationsResponse = response.readEntity(ApplicationsResponse.class);
    assertNotNull(applicationsResponse);
    assertEquals(3, applicationsResponse.getData().size());
    assertEquals("C", applicationsResponse.getData().get(0).getId());
    assertEquals("B", applicationsResponse.getData().get(1).getId());
    assertEquals("A", applicationsResponse.getData().get(2).getId());
}
Also used : ApplicationsResponse(io.gravitee.rest.api.portal.rest.model.ApplicationsResponse) ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Response(javax.ws.rs.core.Response) GroupByQuery(io.gravitee.rest.api.model.analytics.query.GroupByQuery) ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity) TopHitsAnalytics(io.gravitee.rest.api.model.analytics.TopHitsAnalytics) SubscriptionEntity(io.gravitee.rest.api.model.SubscriptionEntity) Application(io.gravitee.rest.api.portal.rest.model.Application) ApplicationsResponse(io.gravitee.rest.api.portal.rest.model.ApplicationsResponse) Test(org.junit.Test)

Aggregations

Application (io.gravitee.rest.api.portal.rest.model.Application)11 Test (org.junit.Test)7 ApplicationEntity (io.gravitee.rest.api.model.ApplicationEntity)6 ApplicationSettings (io.gravitee.rest.api.model.application.ApplicationSettings)5 SimpleApplicationSettings (io.gravitee.rest.api.model.application.SimpleApplicationSettings)5 SubscriptionEntity (io.gravitee.rest.api.model.SubscriptionEntity)4 TopHitsAnalytics (io.gravitee.rest.api.model.analytics.TopHitsAnalytics)4 GroupByQuery (io.gravitee.rest.api.model.analytics.query.GroupByQuery)4 ApplicationListItem (io.gravitee.rest.api.model.application.ApplicationListItem)4 OAuthClientSettings (io.gravitee.rest.api.model.application.OAuthClientSettings)4 Response (javax.ws.rs.core.Response)4 UserEntity (io.gravitee.rest.api.model.UserEntity)3 ApplicationsResponse (io.gravitee.rest.api.portal.rest.model.ApplicationsResponse)3 ErrorResponse (io.gravitee.rest.api.portal.rest.model.ErrorResponse)3 Collectors (java.util.stream.Collectors)3 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)2 ApiQuery (io.gravitee.rest.api.model.api.ApiQuery)2 SubscriptionQuery (io.gravitee.rest.api.model.subscription.SubscriptionQuery)2 ApplicationLinks (io.gravitee.rest.api.portal.rest.model.ApplicationLinks)2 Group (io.gravitee.rest.api.portal.rest.model.Group)2