Search in sources :

Example 91 with HttpResponse

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

the class PluginToggleHandlerTest method saysBadRequestWhenValueIsInvalid.

@Test
public void saysBadRequestWhenValueIsInvalid() {
    HttpRequest request = put("/foo/off/enabled").body("invalid", UTF_8).build();
    HttpResponse response = Mono.from(handler.handle(request, requestContext())).block();
    assertThat(response.status(), is(BAD_REQUEST));
    assertThat(body(response), is("No such state: only 'true' and 'false' are valid."));
    assertThat(initiallyEnabled.enabled(), is(true));
    assertThat(initiallyDisabled.enabled(), is(false));
}
Also used : HttpRequest(com.hotels.styx.api.HttpRequest) HttpResponse(com.hotels.styx.api.HttpResponse) Test(org.junit.jupiter.api.Test)

Example 92 with HttpResponse

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

the class ProviderListHandlerTest method showsEndpointsForAllConfiguredProviders.

@Test
public void showsEndpointsForAllConfiguredProviders() throws JsonProcessingException {
    JsonNode config = new ObjectMapper().readTree("{\"setting1\" : \"A\", \"setting2\" : \"A\"}");
    StyxObjectStore<StyxObjectRecord<StyxService>> store = new StyxObjectStore<>();
    store.insert("Service-A1", new StyxObjectRecord<>("ServiceA", new HashSet<>(), config, new SampleServiceA("Service-A-1")));
    store.insert("Service-A2", new StyxObjectRecord<>("ServiceA", new HashSet<>(), config, new SampleServiceA("Service-A-2")));
    store.insert("Service-B", new StyxObjectRecord<>("ServiceB", new HashSet<>(), config, new SampleServiceB("Service-B")));
    ProviderListHandler handler = new ProviderListHandler(store);
    HttpResponse response = Mono.from(handler.handle(get("/").build(), requestContext())).block();
    assertThat(response.status(), equalTo(OK));
    assertThat(response.bodyAs(UTF_8), stringContainsInOrder("Service-A1 (ServiceA)", "<a href=\"/admin/providers/Service-A1/status\">/admin/providers/Service-A1/status</a>", "Service-A2 (ServiceA)", "<a href=\"/admin/providers/Service-A2/status\">/admin/providers/Service-A2/status</a>", "Service-B (ServiceB)", "<a href=\"/admin/providers/Service-B/withslash/\">/admin/providers/Service-B/withslash/</a>", "<a href=\"/admin/providers/Service-B/noslash\">/admin/providers/Service-B/noslash</a>", "<a href=\"/admin/providers/Service-B/\">/admin/providers/Service-B/</a>"));
}
Also used : StyxObjectRecord(com.hotels.styx.StyxObjectRecord) StyxObjectStore(com.hotels.styx.routing.db.StyxObjectStore) HttpResponse(com.hotels.styx.api.HttpResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 93 with HttpResponse

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

the class ServiceProviderHandlerTest method returnsAllProviders.

@Test
public void returnsAllProviders() throws IOException {
    StyxObjectStore<StyxObjectRecord<StyxService>> store = createTestStore();
    ServiceProviderHandler handler = new ServiceProviderHandler(store);
    HttpRequest request = HttpRequest.get("/admin/service/providers").build();
    HttpResponse response = Mono.from(handler.handle(request, requestContext())).block();
    assertThat(response.status(), equalTo(OK));
    List<StyxObjectDefinition> actualProviders = extractProviders(response.bodyAs(UTF_8));
    assertThat(actualProviders.size(), equalTo(store.entrySet().size()));
    for (StyxObjectDefinition actual : actualProviders) {
        Optional<StyxObjectRecord<StyxService>> rec = store.get(actual.name());
        assertTrue(rec.isPresent());
        validateProvider(actual, rec.get());
    }
}
Also used : StyxObjectRecord(com.hotels.styx.StyxObjectRecord) HttpRequest(com.hotels.styx.api.HttpRequest) HttpResponse(com.hotels.styx.api.HttpResponse) StyxObjectDefinition(com.hotels.styx.routing.config.StyxObjectDefinition) Test(org.junit.jupiter.api.Test)

Example 94 with HttpResponse

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

the class ServiceProviderHandlerTest method returnsNoContentStatusWhenNoProvidersAvailable.

@Test
public void returnsNoContentStatusWhenNoProvidersAvailable() {
    StyxObjectStore<StyxObjectRecord<StyxService>> empty = new StyxObjectStore<>();
    ServiceProviderHandler handler = new ServiceProviderHandler(empty);
    HttpRequest request = HttpRequest.get("/admin/service/providers").build();
    HttpResponse response = Mono.from(handler.handle(request, requestContext())).block();
    assertThat(response.status(), equalTo(NO_CONTENT));
    assertFalse(response.contentLength().isPresent());
}
Also used : StyxObjectRecord(com.hotels.styx.StyxObjectRecord) HttpRequest(com.hotels.styx.api.HttpRequest) StyxObjectStore(com.hotels.styx.routing.db.StyxObjectStore) HttpResponse(com.hotels.styx.api.HttpResponse) Test(org.junit.jupiter.api.Test)

Example 95 with HttpResponse

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

the class ServiceProviderHandlerTest method returnsNamedProvider.

@Test
public void returnsNamedProvider() throws IOException {
    StyxObjectStore<StyxObjectRecord<StyxService>> store = createTestStore();
    ServiceProviderHandler handler = new ServiceProviderHandler(store);
    HttpRequest request = HttpRequest.get("/admin/service/provider/object2").build();
    HttpResponse response = Mono.from(handler.handle(request, requestContext())).block();
    assertThat(response.status(), equalTo(OK));
    StyxObjectDefinition actualProvider = deserialiseProvider(response.bodyAs(UTF_8));
    assertThat(actualProvider, notNullValue());
    assertThat(actualProvider.name(), equalTo("object2"));
    validateProvider(actualProvider, store.get("object2").get());
}
Also used : StyxObjectRecord(com.hotels.styx.StyxObjectRecord) HttpRequest(com.hotels.styx.api.HttpRequest) HttpResponse(com.hotels.styx.api.HttpResponse) StyxObjectDefinition(com.hotels.styx.routing.config.StyxObjectDefinition) 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