Search in sources :

Example 81 with HttpResponse

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

the class OriginsHandlerTest method respondsToRequestWithJsonResponse.

@Test
public void respondsToRequestWithJsonResponse() throws IOException {
    String originsFile = fixturesHome() + "conf/origins/origins-for-jsontest.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));
        Iterable<BackendService> result = newBackendServices(unmarshalApplications(response.bodyAs(UTF_8)));
        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)

Example 82 with HttpResponse

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

the class OriginsHandlerTest method respondsWithEmptyArrayWhenNoOrigins.

@Test
public void respondsWithEmptyArrayWhenNoOrigins() {
    Registry<BackendService> backendServicesRegistry = new MemoryBackedRegistry<>();
    OriginsHandler handler = new OriginsHandler(backendServicesRegistry);
    HttpResponse response = Mono.from(handler.handle(get("/admin/configuration/origins").build(), requestContext())).block();
    assertThat(response.status(), is(OK));
    assertThat(response.contentType(), isValue(APPLICATION_JSON));
    assertThat(response.bodyAs(UTF_8), is("[]"));
}
Also used : BackendService(com.hotels.styx.api.extension.service.BackendService) MemoryBackedRegistry(com.hotels.styx.infrastructure.MemoryBackedRegistry) HttpResponse(com.hotels.styx.api.HttpResponse) Test(org.junit.jupiter.api.Test)

Example 83 with HttpResponse

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

the class OriginsInventoryHandlerTest method prettyPrintsOriginsSnapshot.

@Test
public void prettyPrintsOriginsSnapshot() {
    EventBus eventBus = new EventBus();
    OriginsInventoryHandler handler = new OriginsInventoryHandler(eventBus);
    Set<Origin> disabledOrigins = generateOrigins(2);
    eventBus.post(new OriginsSnapshot(APP_ID, pool(emptySet()), pool(emptySet()), pool(disabledOrigins)));
    HttpResponse response = Mono.from(handler.handle(get("/?pretty=1").build(), requestContext())).block();
    assertThat(body(response).replace("\r\n", "\n"), matchesRegex("\\{\n" + "  \"" + APP_ID + "\" : \\{\n" + "    \"appId\" : \"" + APP_ID + "\",\n" + "    \"activeOrigins\" : \\[ ],\n" + "    \"inactiveOrigins\" : \\[ ],\n" + "    \"disabledOrigins\" : \\[ \\{\n" + "      \"id\" : \"origin.\",\n" + "      \"host\" : \"localhost:....\"\n" + "    }, \\{\n" + "      \"id\" : \"origin.\",\n" + "      \"host\" : \"localhost:....\"\n" + "    } ]\n" + "  }\n" + "}"));
}
Also used : Origin(com.hotels.styx.api.extension.Origin) HttpResponse(com.hotels.styx.api.HttpResponse) EventBus(com.google.common.eventbus.EventBus) OriginsSnapshot(com.hotels.styx.api.extension.OriginsSnapshot) Test(org.junit.jupiter.api.Test)

Example 84 with HttpResponse

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

the class OriginsInventoryHandlerTest method respondsWithCorrectSnapshot.

@Test
public void respondsWithCorrectSnapshot() throws IOException {
    EventBus eventBus = new EventBus();
    OriginsInventoryHandler handler = new OriginsInventoryHandler(eventBus);
    Set<Origin> activeOrigins = generateOrigins(3);
    Set<Origin> inactiveOrigins = generateOrigins(4);
    Set<Origin> disabledOrigins = generateOrigins(2);
    eventBus.post(new OriginsSnapshot(APP_ID, pool(activeOrigins), pool(inactiveOrigins), pool(disabledOrigins)));
    HttpResponse response = Mono.from(handler.handle(get("/").build(), requestContext())).block();
    assertThat(response.bodyAs(UTF_8).split("\n").length, is(1));
    Map<Id, OriginsSnapshot> output = deserialiseJson(response.bodyAs(UTF_8));
    assertThat(output.keySet(), contains(APP_ID));
    OriginsSnapshot snapshot = output.get(APP_ID);
    assertThat(snapshot.appId(), is(APP_ID));
    assertThat(snapshot.activeOrigins(), is(activeOrigins));
    assertThat(snapshot.inactiveOrigins(), is(inactiveOrigins));
    assertThat(snapshot.disabledOrigins(), is(disabledOrigins));
}
Also used : Origin(com.hotels.styx.api.extension.Origin) HttpResponse(com.hotels.styx.api.HttpResponse) EventBus(com.google.common.eventbus.EventBus) Id(com.hotels.styx.api.Id) OriginsSnapshot(com.hotels.styx.api.extension.OriginsSnapshot) Test(org.junit.jupiter.api.Test)

Example 85 with HttpResponse

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

the class PingHandlerTest method respondsPongToPingRequest.

@Test
public void respondsPongToPingRequest() {
    HttpResponse response = Mono.from(handler.handle(get("/ping").build(), requestContext())).block();
    assertThat(response.status(), is(OK));
    assertThat(response.headers(), isNotCacheable());
    assertThat(response.contentType().get(), is("text/plain; charset=utf-8"));
    assertThat(response.bodyAs(UTF_8), is("pong"));
}
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