Search in sources :

Example 36 with ApiEntity

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));
}
Also used : API(io.gravitee.rest.api.model.WorkflowReferenceType.API) ApiLifecycleState(io.gravitee.rest.api.model.api.ApiLifecycleState) Services(io.gravitee.definition.model.services.Services) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Sets.newSet(org.mockito.internal.util.collections.Sets.newSet) RoleScope(io.gravitee.rest.api.model.permissions.RoleScope) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) ApiPermissionFilter(io.gravitee.rest.api.service.jackson.filter.ApiPermissionFilter) Arrays.asList(java.util.Arrays.asList) ApiRepository(io.gravitee.repository.management.api.ApiRepository) After(org.junit.After) Spy(org.mockito.Spy) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) RolePermissionAction(io.gravitee.rest.api.model.permissions.RolePermissionAction) AfterClass(org.junit.AfterClass) ApiLifecycleState(io.gravitee.repository.management.model.ApiLifecycleState) Reader(java.io.Reader) SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) Key(io.gravitee.rest.api.model.parameters.Key) Api(io.gravitee.repository.management.model.Api) SecurityContext(org.springframework.security.core.context.SecurityContext) EmailNotificationBuilder(io.gravitee.rest.api.service.builder.EmailNotificationBuilder) HealthCheckService(io.gravitee.definition.model.services.healthcheck.HealthCheckService) Authentication(org.springframework.security.core.Authentication) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) SystemRole(io.gravitee.rest.api.model.permissions.SystemRole) ApiServiceImpl(io.gravitee.rest.api.service.impl.ApiServiceImpl) SearchEngineService(io.gravitee.rest.api.service.search.SearchEngineService) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) java.util(java.util) Mock(org.mockito.Mock) ApiPermission(io.gravitee.rest.api.model.permissions.ApiPermission) RunWith(org.junit.runner.RunWith) GraviteeContext(io.gravitee.rest.api.service.common.GraviteeContext) NotificationTemplateService(io.gravitee.rest.api.service.notification.NotificationTemplateService) Sets(org.mockito.internal.util.collections.Sets) UpdateApiEntity(io.gravitee.rest.api.model.api.UpdateApiEntity) io.gravitee.rest.api.model(io.gravitee.rest.api.model) HttpEndpoint(io.gravitee.definition.model.endpoint.HttpEndpoint) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) ParameterReferenceType(io.gravitee.rest.api.model.parameters.ParameterReferenceType) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) io.gravitee.definition.model(io.gravitee.definition.model) GraviteeMapper(io.gravitee.definition.jackson.datatype.GraviteeMapper) Mockito(org.mockito.Mockito) io.gravitee.rest.api.service.exceptions(io.gravitee.rest.api.service.exceptions) Workflow(io.gravitee.repository.management.model.Workflow) PropertyFilter(com.fasterxml.jackson.databind.ser.PropertyFilter) Assert(org.junit.Assert) Collections(java.util.Collections) REVIEW(io.gravitee.rest.api.model.WorkflowType.REVIEW) UpdateApiEntity(io.gravitee.rest.api.model.api.UpdateApiEntity) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Test(org.junit.Test)

Example 37 with ApiEntity

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));
}
Also used : HttpEndpoint(io.gravitee.definition.model.endpoint.HttpEndpoint) UpdateApiEntity(io.gravitee.rest.api.model.api.UpdateApiEntity) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) HttpEndpoint(io.gravitee.definition.model.endpoint.HttpEndpoint) Test(org.junit.Test)

Example 38 with ApiEntity

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);
}
Also used : Services(io.gravitee.definition.model.services.Services) EndpointHealthCheckService(io.gravitee.definition.model.services.healthcheck.EndpointHealthCheckService) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Test(org.junit.Test)

Example 39 with ApiEntity

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());
}
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 40 with ApiEntity

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());
}
Also used : Services(io.gravitee.definition.model.services.Services) HealthCheckService(io.gravitee.definition.model.services.healthcheck.HealthCheckService) UpdateApiEntity(io.gravitee.rest.api.model.api.UpdateApiEntity) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Test(org.junit.Test)

Aggregations

ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)273 Test (org.junit.Test)180 Response (javax.ws.rs.core.Response)65 Before (org.junit.Before)46 ApiQuery (io.gravitee.rest.api.model.api.ApiQuery)35 Error (io.gravitee.rest.api.portal.rest.model.Error)32 java.util (java.util)30 Collectors (java.util.stream.Collectors)27 Mockito.doReturn (org.mockito.Mockito.doReturn)27 Mockito (org.mockito.Mockito)25 ArgumentMatchers (org.mockito.ArgumentMatchers)24 UpdateApiEntity (io.gravitee.rest.api.model.api.UpdateApiEntity)23 Assert (org.junit.Assert)22 Collections.singletonList (java.util.Collections.singletonList)21 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)20 IOException (java.io.IOException)20 HttpStatusCode (io.gravitee.common.http.HttpStatusCode)19 Entity (javax.ws.rs.client.Entity)19 HashSet (java.util.HashSet)18 Api (io.gravitee.repository.management.model.Api)17