use of io.gravitee.definition.model.services.healthcheck.Response 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();
}
use of io.gravitee.definition.model.services.healthcheck.Response 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();
}
use of io.gravitee.definition.model.services.healthcheck.Response 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();
}
use of io.gravitee.definition.model.services.healthcheck.Response 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();
}
Aggregations