Search in sources :

Example 41 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 shouldUpdateWithValidSchedule.

@Test
public void shouldUpdateWithValidSchedule() throws TechnicalException {
    prepareUpdate();
    Services services = new Services();
    HealthCheckService healthCheckService = new HealthCheckService();
    healthCheckService.setSchedule("1,2 */100 5-8 * * *");
    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());
    verify(searchEngineService, times(1)).index(any(), eq(false));
}
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)

Example 42 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 shouldNotBeEnabledWithDisabledGlobalHC.

@Test
public void shouldNotBeEnabledWithDisabledGlobalHC() {
    ApiEntity api = mock(ApiEntity.class);
    HealthCheckService hcSrv = mock(HealthCheckService.class);
    when(hcSrv.isEnabled()).thenReturn(Boolean.FALSE);
    Services services = new Services();
    services.set(Collections.singletonList(hcSrv));
    when(api.getServices()).thenReturn(services);
    mockProxy(api, false);
    boolean valid = apiService.hasHealthCheckEnabled(api, true);
    assertFalse(valid);
}
Also used : Services(io.gravitee.definition.model.services.Services) HealthCheckService(io.gravitee.definition.model.services.healthcheck.HealthCheckService) EndpointHealthCheckService(io.gravitee.definition.model.services.healthcheck.EndpointHealthCheckService) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Test(org.junit.Test)

Example 43 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 shouldBeEnabledWithOnlyOneEndpointHC.

@Test
public void shouldBeEnabledWithOnlyOneEndpointHC() {
    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, false);
    boolean valid = apiService.hasHealthCheckEnabled(api, false);
    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 44 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 shouldBeEnabledWithGlobalHC.

@Test
public void shouldBeEnabledWithGlobalHC() {
    ApiEntity api = mock(ApiEntity.class);
    HealthCheckService hcSrv = mock(HealthCheckService.class);
    when(hcSrv.isEnabled()).thenReturn(Boolean.TRUE);
    Services services = new Services();
    services.set(Collections.singletonList(hcSrv));
    when(api.getServices()).thenReturn(services);
    mockProxy(api, false);
    boolean valid = apiService.hasHealthCheckEnabled(api, true);
    assertTrue(valid);
}
Also used : Services(io.gravitee.definition.model.services.Services) HealthCheckService(io.gravitee.definition.model.services.healthcheck.HealthCheckService) EndpointHealthCheckService(io.gravitee.definition.model.services.healthcheck.EndpointHealthCheckService) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Test(org.junit.Test)

Example 45 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 shouldNotBeEnabledWithoutServices.

@Test
public void shouldNotBeEnabledWithoutServices() {
    ApiEntity api = mock(ApiEntity.class);
    mockProxy(api, false);
    boolean valid = apiService.hasHealthCheckEnabled(api, true);
    assertFalse(valid);
}
Also used : 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