Search in sources :

Example 1 with EndpointHealthCheckService

use of io.gravitee.definition.model.services.healthcheck.EndpointHealthCheckService 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 2 with EndpointHealthCheckService

use of io.gravitee.definition.model.services.healthcheck.EndpointHealthCheckService 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 3 with EndpointHealthCheckService

use of io.gravitee.definition.model.services.healthcheck.EndpointHealthCheckService in project gravitee-management-rest-api by gravitee-io.

the class ApiService_hasHealthCheckEnabledTest method shouldNotBeEnabledWithOnlyOneEndpointHC.

@Test
public void shouldNotBeEnabledWithOnlyOneEndpointHC() {
    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, true);
    assertFalse(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 4 with EndpointHealthCheckService

use of io.gravitee.definition.model.services.healthcheck.EndpointHealthCheckService in project gravitee-management-rest-api by gravitee-io.

the class ApiService_hasHealthCheckEnabledTest method mockProxy.

private void mockProxy(final ApiEntity api, final boolean withHC) {
    final Proxy proxy = mock(Proxy.class);
    when(api.getProxy()).thenReturn(proxy);
    final EndpointGroup endpointGroup = mock(EndpointGroup.class);
    when(proxy.getGroups()).thenReturn(Collections.singleton(endpointGroup));
    final HttpEndpoint endpoint1 = mock(HttpEndpoint.class);
    final HttpEndpoint endpoint2 = mock(HttpEndpoint.class);
    when(endpointGroup.getEndpoints()).thenReturn(new HashSet<>(Arrays.asList(endpoint1, endpoint2)));
    final EndpointHealthCheckService endpointHealthCheckService1 = mock(EndpointHealthCheckService.class);
    when(endpoint1.getHealthCheck()).thenReturn(endpointHealthCheckService1);
    when(endpointHealthCheckService1.isEnabled()).thenReturn(true);
    final EndpointHealthCheckService endpointHealthCheckService2 = mock(EndpointHealthCheckService.class);
    when(endpoint2.getHealthCheck()).thenReturn(endpointHealthCheckService2);
    when(endpointHealthCheckService2.isEnabled()).thenReturn(withHC);
}
Also used : Proxy(io.gravitee.definition.model.Proxy) EndpointHealthCheckService(io.gravitee.definition.model.services.healthcheck.EndpointHealthCheckService) EndpointGroup(io.gravitee.definition.model.EndpointGroup) HttpEndpoint(io.gravitee.definition.model.endpoint.HttpEndpoint)

Aggregations

EndpointHealthCheckService (io.gravitee.definition.model.services.healthcheck.EndpointHealthCheckService)4 Services (io.gravitee.definition.model.services.Services)3 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)3 Test (org.junit.Test)3 EndpointGroup (io.gravitee.definition.model.EndpointGroup)1 Proxy (io.gravitee.definition.model.Proxy)1 HttpEndpoint (io.gravitee.definition.model.endpoint.HttpEndpoint)1