use of io.gravitee.rest.api.model.api.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiService_UpdateTest method shouldNotDuplicateLabels.
@Test
public void shouldNotDuplicateLabels() throws TechnicalException {
prepareUpdate();
when(existingApi.getLabels()).thenReturn(asList("label1", "label1"));
when(api.getDefinition()).thenReturn("{\"id\": \"" + API_ID + "\",\"name\": \"" + API_NAME + "\",\"proxy\": {\"context_path\": \"/old\"} ,\"labels\": [\"public\"]}");
final ApiEntity apiEntity = apiService.update(API_ID, existingApi);
verify(apiRepository).update(argThat(api -> api.getLabels().size() == 1));
assertNotNull(apiEntity);
verify(searchEngineService, times(1)).index(any(), eq(false));
}
use of io.gravitee.rest.api.model.api.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiService_UpdateTest method shouldUpdateWithExistingAllowedTag.
@Test
public void shouldUpdateWithExistingAllowedTag() throws TechnicalException {
prepareUpdate();
when(existingApi.getTags()).thenReturn(singleton("private"));
Proxy proxy = new Proxy();
EndpointGroup endpointGroup = new EndpointGroup();
endpointGroup.setName("endpointGroupName");
Endpoint endpoint = new HttpEndpoint("EndpointName", null);
endpointGroup.setEndpoints(singleton(endpoint));
proxy.setGroups(singleton(endpointGroup));
when(existingApi.getProxy()).thenReturn(proxy);
when(api.getDefinition()).thenReturn("{\"id\": \"" + API_ID + "\",\"name\": \"" + API_NAME + "\",\"proxy\": {\"context_path\": \"/old\"} ,\"tags\": [\"public\"]}");
when(tagService.findByUser(any(), any(), any())).thenReturn(Sets.newSet("public", "private"));
final ApiEntity apiEntity = apiService.update(API_ID, existingApi);
assertNotNull(apiEntity);
assertEquals(API_NAME, apiEntity.getName());
verify(searchEngineService, times(1)).index(any(), eq(false));
}
use of io.gravitee.rest.api.model.api.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiService_hasHealthCheckEnabledTest method shouldBeEnabledWithEndpointsHC.
@Test
public void shouldBeEnabledWithEndpointsHC() {
ApiEntity api = mock(ApiEntity.class);
EndpointHealthCheckService hcSrv = mock(EndpointHealthCheckService.class);
when(hcSrv.isEnabled()).thenReturn(Boolean.FALSE);
Services services = new Services();
services.set(Collections.singletonList(hcSrv));
when(api.getServices()).thenReturn(services);
mockProxy(api, true);
boolean valid = apiService.hasHealthCheckEnabled(api, true);
assertTrue(valid);
}
use of io.gravitee.rest.api.model.api.ApiEntity 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());
}
use of io.gravitee.rest.api.model.api.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiService_UpdateTest method shouldNotUpdateWithInvalidSchedule.
@Test(expected = InvalidDataException.class)
public void shouldNotUpdateWithInvalidSchedule() throws TechnicalException {
prepareUpdate();
Services services = new Services();
HealthCheckService healthCheckService = mock(HealthCheckService.class);
when(healthCheckService.getSchedule()).thenReturn("**");
services.put(HealthCheckService.class, healthCheckService);
when(existingApi.getServices()).thenReturn(services);
final ApiEntity apiEntity = apiService.update(API_ID, existingApi);
assertNotNull(apiEntity);
assertEquals(API_NAME, apiEntity.getName());
}
Aggregations