Search in sources :

Example 21 with HttpResponse

use of com.hotels.styx.api.HttpResponse in project styx by ExpediaGroup.

the class MetricsHandlerTest method exposesRegisteredMetrics.

@Disabled
@Test
public void exposesRegisteredMetrics() {
    metricRegistry.counter("foo").inc();
    HttpResponse response = Mono.from(handler.handle(get("/admin/metrics").build(), requestContext())).block();
    assertThat(response.bodyAs(UTF_8), matchesRegex(quote("{\"version\":\"") + "\\d+\\.\\d+\\.\\d+" + quote("\",\"gauges\":{},\"counters\":{\"foo\":{\"count\":1}},\"histograms\":{},\"meters\":{},\"timers\":{}}")));
}
Also used : HttpResponse(com.hotels.styx.api.HttpResponse) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 22 with HttpResponse

use of com.hotels.styx.api.HttpResponse in project styx by ExpediaGroup.

the class MetricsHandlerTest method canRequestMetricsBeginningWithPrefixAndSearchForTermTogether.

@Test
public void canRequestMetricsBeginningWithPrefixAndSearchForTermTogether() {
    metricRegistry.counter("foo.bar.a").inc(1);
    metricRegistry.counter("foo.bar.b").inc(1);
    metricRegistry.counter("baz.bar.foo").inc(1);
    metricRegistry.counter("foo.baz.a").inc(1);
    metricRegistry.counter("foo.baz.a.bar").inc(1);
    HttpResponse response = Mono.from(handler.handle(get("/admin/metrics/foo?filter=bar").build(), requestContext())).block();
    assertThat(response.status(), is(OK));
    assertThat(response.bodyAs(UTF_8), is("{" + "\"foo.bar.a\":{\"count\":1}," + "\"foo.bar.b\":{\"count\":1}," + "\"foo.baz.a.bar\":{\"count\":1}" + "}"));
}
Also used : HttpResponse(com.hotels.styx.api.HttpResponse) Test(org.junit.jupiter.api.Test)

Example 23 with HttpResponse

use of com.hotels.styx.api.HttpResponse in project styx by ExpediaGroup.

the class MetricsHandlerTest method ifNoMetricsMatchNameThen404NotFoundIsReturned.

@Test
public void ifNoMetricsMatchNameThen404NotFoundIsReturned() {
    HttpResponse response = Mono.from(handler.handle(get("/admin/metrics/foo.bar").build(), requestContext())).block();
    assertThat(response.status(), is(NOT_FOUND));
}
Also used : HttpResponse(com.hotels.styx.api.HttpResponse) Test(org.junit.jupiter.api.Test)

Example 24 with HttpResponse

use of com.hotels.styx.api.HttpResponse in project styx by ExpediaGroup.

the class MetricsHandlerTest method respondsToRequestWithJsonResponse.

@Test
public void respondsToRequestWithJsonResponse() {
    HttpResponse response = Mono.from(handler.handle(get("/admin/metrics").build(), requestContext())).block();
    assertThat(response.status(), is(OK));
    assertThat(response.contentType().get(), is(APPLICATION_JSON.toString()));
}
Also used : HttpResponse(com.hotels.styx.api.HttpResponse) Test(org.junit.jupiter.api.Test)

Example 25 with HttpResponse

use of com.hotels.styx.api.HttpResponse in project styx by ExpediaGroup.

the class OriginsHandlerTest method healthCheckIsAbsentWhenNotConfigured.

@Test
public void healthCheckIsAbsentWhenNotConfigured() throws IOException {
    String originsFile = fixturesHome() + "conf/origins/origins-for-jsontest-no-healthcheck.yml";
    Iterable<BackendService> expected = loadFromPath(originsFile).get();
    withOriginsHandler(originsFile, handler -> {
        HttpResponse response = Mono.from(handler.handle(get("/admin/configuration/origins").build(), requestContext())).block();
        assertThat(response.status(), is(OK));
        assertThat(response.contentType(), isValue(APPLICATION_JSON));
        String body = response.bodyAs(UTF_8);
        assertThat(body, not(containsString("healthCheck")));
        Iterable<BackendService> result = newBackendServices(unmarshalApplications(body));
        assertThat(result, is(expected));
    });
}
Also used : BackendService(com.hotels.styx.api.extension.service.BackendService) HttpResponse(com.hotels.styx.api.HttpResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Aggregations

HttpResponse (com.hotels.styx.api.HttpResponse)107 Test (org.junit.jupiter.api.Test)99 LiveHttpResponse (com.hotels.styx.api.LiveHttpResponse)30 HttpRequest (com.hotels.styx.api.HttpRequest)18 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 Eventual (com.hotels.styx.api.Eventual)10 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)9 StyxHttpClient (com.hotels.styx.client.StyxHttpClient)8 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)8 TlsSettings (com.hotels.styx.api.extension.service.TlsSettings)7 StyxObjectRecord (com.hotels.styx.StyxObjectRecord)6 HttpHandler (com.hotels.styx.api.HttpHandler)6 LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)6 OK (com.hotels.styx.api.HttpResponseStatus.OK)5 HttpClient (com.hotels.styx.client.HttpClient)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 HttpInterceptor (com.hotels.styx.api.HttpInterceptor)4 Plugin (com.hotels.styx.api.plugins.spi.Plugin)4 PluginFactory (com.hotels.styx.api.plugins.spi.PluginFactory)4 WireMockServer (com.github.tomakehurst.wiremock.WireMockServer)3