Search in sources :

Example 1 with TopApiEntity

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

the class FilteringServiceTest method shouldGetFeaturedApis.

@Test
public void shouldGetFeaturedApis() {
    TopApiEntity topApi5 = new TopApiEntity();
    topApi5.setApi("5");
    topApi5.setOrder(2);
    TopApiEntity topApi6 = new TopApiEntity();
    topApi6.setApi("6");
    topApi6.setOrder(1);
    doReturn(Arrays.asList(topApi5, topApi6)).when(topApiService).findAll();
    FilteredEntities<ApiEntity> apiEntityFilteredEntities = filteringService.filterApis(mockApis, FilteringService.FilterType.FEATURED, null);
    List<ApiEntity> filteredItems = apiEntityFilteredEntities.getFilteredItems();
    assertEquals(2, filteredItems.size());
    assertEquals("6", filteredItems.get(0).getId());
    assertEquals("5", filteredItems.get(1).getId());
}
Also used : TopApiEntity(io.gravitee.rest.api.model.TopApiEntity) TopApiEntity(io.gravitee.rest.api.model.TopApiEntity) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Test(org.junit.Test)

Example 2 with TopApiEntity

use of io.gravitee.rest.api.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, apiId -> apiService.findById(apiId), apiService::exists, ParameterReferenceType.ENVIRONMENT);
    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 : UpdateTopApiEntity(io.gravitee.rest.api.model.UpdateTopApiEntity) TopApiEntity(io.gravitee.rest.api.model.TopApiEntity) NewTopApiEntity(io.gravitee.rest.api.model.NewTopApiEntity) ArrayList(java.util.ArrayList) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) UpdateTopApiEntity(io.gravitee.rest.api.model.UpdateTopApiEntity) TopApiEntity(io.gravitee.rest.api.model.TopApiEntity) NewTopApiEntity(io.gravitee.rest.api.model.NewTopApiEntity)

Example 3 with TopApiEntity

use of io.gravitee.rest.api.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), any(Function.class), any(Predicate.class), any(ParameterReferenceType.class))).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 : Function(java.util.function.Function) UpdateTopApiEntity(io.gravitee.rest.api.model.UpdateTopApiEntity) TopApiEntity(io.gravitee.rest.api.model.TopApiEntity) NewTopApiEntity(io.gravitee.rest.api.model.NewTopApiEntity) ParameterReferenceType(io.gravitee.rest.api.model.parameters.ParameterReferenceType) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) UpdateTopApiEntity(io.gravitee.rest.api.model.UpdateTopApiEntity) TopApiEntity(io.gravitee.rest.api.model.TopApiEntity) NewTopApiEntity(io.gravitee.rest.api.model.NewTopApiEntity) Predicate(java.util.function.Predicate) Test(org.junit.Test)

Aggregations

TopApiEntity (io.gravitee.rest.api.model.TopApiEntity)3 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)3 NewTopApiEntity (io.gravitee.rest.api.model.NewTopApiEntity)2 UpdateTopApiEntity (io.gravitee.rest.api.model.UpdateTopApiEntity)2 Test (org.junit.Test)2 ParameterReferenceType (io.gravitee.rest.api.model.parameters.ParameterReferenceType)1 ArrayList (java.util.ArrayList)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1