Search in sources :

Example 1 with TopApiEntity

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

the class TopApiServiceTest method shouldFindAll.

@Test
public void shouldFindAll() {
    final ApiEntity api1 = new ApiEntity();
    api1.setId("1");
    api1.setName("name");
    api1.setVersion("version");
    api1.setDescription("description");
    final ApiEntity api2 = new ApiEntity();
    api2.setId("2");
    when(parameterService.findAll(eq(PORTAL_TOP_APIS.getKey()), any(), any())).thenReturn(asList(api1, api2, api1));
    final List<TopApiEntity> topApis = topApiService.findAll();
    assertEquals("1", topApis.get(0).getApi());
    assertEquals("name", topApis.get(0).getName());
    assertEquals("version", topApis.get(0).getVersion());
    assertEquals("description", topApis.get(0).getDescription());
    assertEquals(0, topApis.get(0).getOrder());
    assertEquals("2", topApis.get(1).getApi());
    assertEquals(1, topApis.get(1).getOrder());
    assertEquals("1", topApis.get(2).getApi());
    assertEquals(2, topApis.get(2).getOrder());
}
Also used : TopApiEntity(io.gravitee.management.model.TopApiEntity) UpdateTopApiEntity(io.gravitee.management.model.UpdateTopApiEntity) NewTopApiEntity(io.gravitee.management.model.NewTopApiEntity) ApiEntity(io.gravitee.management.model.ApiEntity) TopApiEntity(io.gravitee.management.model.TopApiEntity) UpdateTopApiEntity(io.gravitee.management.model.UpdateTopApiEntity) NewTopApiEntity(io.gravitee.management.model.NewTopApiEntity) Test(org.junit.Test)

Example 2 with TopApiEntity

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

the class TopApiServiceImpl method findAll.

@Override
public List<TopApiEntity> findAll() {
    LOGGER.debug("Find all top APIs");
    final List<ApiEntity> apis = parameterService.findAll(PORTAL_TOP_APIS.getKey(), apiId -> apiService.findById(apiId), apiService::exists);
    if (!apis.isEmpty()) {
        final List<TopApiEntity> topApis = new ArrayList<>(apis.size());
        for (int i = 0; i < apis.size(); i++) {
            final ApiEntity api = apis.get(i);
            final TopApiEntity topApiEntity = new TopApiEntity();
            topApiEntity.setApi(api.getId());
            topApiEntity.setName(api.getName());
            topApiEntity.setVersion(api.getVersion());
            topApiEntity.setDescription(api.getDescription());
            topApiEntity.setOrder(i);
            topApis.add(topApiEntity);
        }
        return topApis;
    }
    return emptyList();
}
Also used : TopApiEntity(io.gravitee.management.model.TopApiEntity) UpdateTopApiEntity(io.gravitee.management.model.UpdateTopApiEntity) NewTopApiEntity(io.gravitee.management.model.NewTopApiEntity) ArrayList(java.util.ArrayList) ApiEntity(io.gravitee.management.model.ApiEntity) TopApiEntity(io.gravitee.management.model.TopApiEntity) UpdateTopApiEntity(io.gravitee.management.model.UpdateTopApiEntity) NewTopApiEntity(io.gravitee.management.model.NewTopApiEntity)

Aggregations

ApiEntity (io.gravitee.management.model.ApiEntity)2 NewTopApiEntity (io.gravitee.management.model.NewTopApiEntity)2 TopApiEntity (io.gravitee.management.model.TopApiEntity)2 UpdateTopApiEntity (io.gravitee.management.model.UpdateTopApiEntity)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1