Search in sources :

Example 1 with EndpointStatus

use of io.gravitee.reporter.api.health.EndpointStatus in project gravitee-gateway by gravitee-io.

the class HttpEndpointRuleHandlerTest method shouldValidate.

@Test
public void shouldValidate(TestContext context) throws InterruptedException {
    // Prepare HTTP endpoint
    stubFor(get(urlEqualTo("/")).willReturn(aResponse().withStatus(200).withBody("{\"status\": \"green\"}")));
    // Prepare
    EndpointRule rule = mock(EndpointRule.class);
    when(rule.endpoint()).thenReturn(createEndpoint());
    io.gravitee.definition.model.services.healthcheck.Step step = new io.gravitee.definition.model.services.healthcheck.Step();
    Request request = new Request();
    request.setPath("/");
    request.setMethod(HttpMethod.GET);
    step.setRequest(request);
    Response response = new Response();
    response.setAssertions(Collections.singletonList(Response.DEFAULT_ASSERTION));
    step.setResponse(response);
    when(rule.steps()).thenReturn(Collections.singletonList(step));
    HttpEndpointRuleHandler runner = new HttpEndpointRuleHandler(vertx, rule);
    Async async = context.async();
    // Verify
    runner.setStatusHandler(new Handler<EndpointStatus>() {

        @Override
        public void handle(EndpointStatus status) {
            Assert.assertTrue(status.isSuccess());
            async.complete();
        }
    });
    // Run
    runner.handle(null);
    // Wait until completion
    async.awaitSuccess();
}
Also used : EndpointRule(io.gravitee.gateway.services.healthcheck.EndpointRule) Request(io.gravitee.definition.model.services.healthcheck.Request) Step(io.gravitee.reporter.api.health.Step) Response(io.gravitee.definition.model.services.healthcheck.Response) EndpointStatus(io.gravitee.reporter.api.health.EndpointStatus) Async(io.vertx.ext.unit.Async) Test(org.junit.Test)

Example 2 with EndpointStatus

use of io.gravitee.reporter.api.health.EndpointStatus in project gravitee-gateway by gravitee-io.

the class HttpEndpointRuleHandlerTest method shouldNotValidate_invalidResponseBody.

@Test
public void shouldNotValidate_invalidResponseBody(TestContext context) throws InterruptedException {
    // Prepare HTTP endpoint
    stubFor(get(urlEqualTo("/")).willReturn(aResponse().withStatus(200).withBody("{\"status\": \"yellow\"}")));
    // Prepare
    EndpointRule rule = mock(EndpointRule.class);
    when(rule.endpoint()).thenReturn(createEndpoint());
    io.gravitee.definition.model.services.healthcheck.Step step = new io.gravitee.definition.model.services.healthcheck.Step();
    Request request = new Request();
    request.setPath("/");
    request.setMethod(HttpMethod.GET);
    step.setRequest(request);
    Response response = new Response();
    response.setAssertions(Collections.singletonList("#jsonPath(#response.content, '$.status') == 'green'"));
    step.setResponse(response);
    when(rule.steps()).thenReturn(Collections.singletonList(step));
    HttpEndpointRuleHandler runner = new HttpEndpointRuleHandler(vertx, rule);
    Async async = context.async();
    // Verify
    runner.setStatusHandler(new Handler<EndpointStatus>() {

        @Override
        public void handle(EndpointStatus status) {
            Assert.assertFalse(status.isSuccess());
            // When health-check is false, we store both request and response
            Step result = status.getSteps().get(0);
            Assert.assertEquals(HttpMethod.GET, result.getRequest().getMethod());
            Assert.assertNotNull(result.getResponse().getBody());
            async.complete();
        }
    });
    // Run
    runner.handle(null);
    // Wait until completion
    async.awaitSuccess();
}
Also used : EndpointRule(io.gravitee.gateway.services.healthcheck.EndpointRule) Request(io.gravitee.definition.model.services.healthcheck.Request) Step(io.gravitee.reporter.api.health.Step) Response(io.gravitee.definition.model.services.healthcheck.Response) EndpointStatus(io.gravitee.reporter.api.health.EndpointStatus) Async(io.vertx.ext.unit.Async) Test(org.junit.Test)

Example 3 with EndpointStatus

use of io.gravitee.reporter.api.health.EndpointStatus in project gravitee-gateway by gravitee-io.

the class HttpEndpointRuleHandlerTest method shouldValidateFromRoot.

@Test
public void shouldValidateFromRoot(TestContext context) throws InterruptedException {
    // Prepare HTTP endpoint
    stubFor(get(urlEqualTo("/")).willReturn(aResponse().withStatus(200).withBody("{\"status\": \"green\"}")));
    // Prepare
    EndpointRule rule = mock(EndpointRule.class);
    Endpoint endpoint = createEndpoint();
    endpoint.setTarget(endpoint.getTarget() + "/additional-but-unused-path-for-hc");
    when(rule.endpoint()).thenReturn(endpoint);
    io.gravitee.definition.model.services.healthcheck.Step step = new io.gravitee.definition.model.services.healthcheck.Step();
    Request request = new Request();
    request.setPath("/");
    request.setFromRoot(true);
    request.setMethod(HttpMethod.GET);
    step.setRequest(request);
    Response response = new Response();
    response.setAssertions(Collections.singletonList(Response.DEFAULT_ASSERTION));
    step.setResponse(response);
    when(rule.steps()).thenReturn(Collections.singletonList(step));
    HttpEndpointRuleHandler runner = new HttpEndpointRuleHandler(vertx, rule);
    Async async = context.async();
    // Verify
    runner.setStatusHandler(new Handler<EndpointStatus>() {

        @Override
        public void handle(EndpointStatus status) {
            Assert.assertTrue(status.isSuccess());
            async.complete();
        }
    });
    // Run
    runner.handle(null);
    // Wait until completion
    async.awaitSuccess();
}
Also used : EndpointRule(io.gravitee.gateway.services.healthcheck.EndpointRule) Request(io.gravitee.definition.model.services.healthcheck.Request) Step(io.gravitee.reporter.api.health.Step) Response(io.gravitee.definition.model.services.healthcheck.Response) EndpointStatus(io.gravitee.reporter.api.health.EndpointStatus) Endpoint(io.gravitee.definition.model.Endpoint) HttpEndpoint(io.gravitee.definition.model.endpoint.HttpEndpoint) Async(io.vertx.ext.unit.Async) Test(org.junit.Test)

Example 4 with EndpointStatus

use of io.gravitee.reporter.api.health.EndpointStatus in project gravitee-gateway by gravitee-io.

the class HttpEndpointRuleHandlerTest method shouldNotValidate_invalidEndpoint.

@Test
public void shouldNotValidate_invalidEndpoint(TestContext context) {
    // Prepare
    EndpointRule rule = mock(EndpointRule.class);
    when(rule.endpoint()).thenReturn(createEndpoint());
    io.gravitee.definition.model.services.healthcheck.Step step = new io.gravitee.definition.model.services.healthcheck.Step();
    Request request = new Request();
    request.setPath("/");
    request.setMethod(HttpMethod.GET);
    step.setRequest(request);
    Response response = new Response();
    response.setAssertions(Collections.singletonList(Response.DEFAULT_ASSERTION));
    step.setResponse(response);
    when(rule.steps()).thenReturn(Collections.singletonList(step));
    HttpEndpointRuleHandler runner = new HttpEndpointRuleHandler(vertx, rule);
    Async async = context.async();
    // Verify
    runner.setStatusHandler(new Handler<EndpointStatus>() {

        @Override
        public void handle(EndpointStatus status) {
            Assert.assertFalse(status.isSuccess());
            async.complete();
        }
    });
    // Run
    runner.handle(null);
    // Wait until completion
    async.awaitSuccess();
}
Also used : EndpointRule(io.gravitee.gateway.services.healthcheck.EndpointRule) Request(io.gravitee.definition.model.services.healthcheck.Request) Step(io.gravitee.reporter.api.health.Step) Response(io.gravitee.definition.model.services.healthcheck.Response) EndpointStatus(io.gravitee.reporter.api.health.EndpointStatus) Async(io.vertx.ext.unit.Async) Test(org.junit.Test)

Aggregations

Request (io.gravitee.definition.model.services.healthcheck.Request)4 Response (io.gravitee.definition.model.services.healthcheck.Response)4 EndpointRule (io.gravitee.gateway.services.healthcheck.EndpointRule)4 EndpointStatus (io.gravitee.reporter.api.health.EndpointStatus)4 Step (io.gravitee.reporter.api.health.Step)4 Async (io.vertx.ext.unit.Async)4 Test (org.junit.Test)4 Endpoint (io.gravitee.definition.model.Endpoint)1 HttpEndpoint (io.gravitee.definition.model.endpoint.HttpEndpoint)1