Search in sources :

Example 76 with HttpResponse

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

the class JVMMetricsHandlerTest method respondsToRequestWithJsonResponse.

@Test
public void respondsToRequestWithJsonResponse() {
    HttpResponse response = call(get("/jvm").build());
    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 77 with HttpResponse

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

the class LoggingConfigurationHandlerTest method showsErrorMessageInContentIfLogConfigFileDoesNotExist.

@Test
public void showsErrorMessageInContentIfLogConfigFileDoesNotExist() {
    StartupConfig startupConfig = newStartupConfigBuilder().logbackConfigLocation("/foo/bar").build();
    LoggingConfigurationHandler handler = new LoggingConfigurationHandler(startupConfig.logConfigLocation());
    HttpResponse response = Mono.from(handler.handle(get("/").build(), requestContext())).block();
    assertThat(response.status(), is(OK));
    assertThat(response.bodyAs(UTF_8), matchesRegex("Could not load resource=.*foo[\\\\/]bar'"));
}
Also used : HttpResponse(com.hotels.styx.api.HttpResponse) StartupConfig(com.hotels.styx.StartupConfig) Test(org.junit.jupiter.api.Test)

Example 78 with HttpResponse

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

the class MetricsHandlerTest method canRequestMetricsBeginningWithPrefix.

@Test
public void canRequestMetricsBeginningWithPrefix() {
    metricRegistry.counter("foo.bar").inc(1);
    metricRegistry.counter("foo.bar.baz").inc(1);
    // should not be included
    metricRegistry.counter("foo.barx").inc(1);
    HttpResponse response = Mono.from(handler.handle(get("/admin/metrics/foo.bar").build(), requestContext())).block();
    assertThat(response.bodyAs(UTF_8), is("{\"foo.bar\":{\"count\":1},\"foo.bar.baz\":{\"count\":1}}"));
}
Also used : HttpResponse(com.hotels.styx.api.HttpResponse) Test(org.junit.jupiter.api.Test)

Example 79 with HttpResponse

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

the class MetricsHandlerTest method searchReturnsEmptyJsonObjectWhenThereAreNoResults.

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

Example 80 with HttpResponse

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

the class MetricsHandlerTest method canSearchForTermWithinMetricName.

@Test
public void canSearchForTermWithinMetricName() {
    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);
    HttpResponse response = Mono.from(handler.handle(get("/admin/metrics/?filter=bar").build(), requestContext())).block();
    assertThat(response.status(), is(OK));
    assertThat(response.bodyAs(UTF_8), is("{" + "\"baz.bar.foo\":{\"count\":1}," + "\"foo.bar.a\":{\"count\":1}," + "\"foo.bar.b\":{\"count\":1}" + "}"));
}
Also used : HttpResponse(com.hotels.styx.api.HttpResponse) 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