Search in sources :

Example 11 with HttpRequest

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

the class StyxHttpClientTest method requestWithNoHostOrUrlAuthorityCausesException.

/*
     * StyxHttpClient
     * - Rejects requests without URL authority or host header
     */
@Test
public void requestWithNoHostOrUrlAuthorityCausesException() {
    HttpRequest request = get("/foo.txt").build();
    StyxHttpClient client = new StyxHttpClient.Builder().build();
    assertThrows(IllegalArgumentException.class, () -> await(client.send(request)));
}
Also used : HttpRequest(com.hotels.styx.api.HttpRequest) Test(org.junit.jupiter.api.Test)

Example 12 with HttpRequest

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

the class JsonHandlerTest method prettyPrintsOutputWhenPrettyIsSetToTrue.

@Test
public void prettyPrintsOutputWhenPrettyIsSetToTrue() {
    HttpRequest request = get("/?pretty=true").build();
    Supplier<Convertible> supplier = sequentialSupplier(new Convertible("foo", 456));
    JsonHandler<Convertible> handler = new JsonHandler<>(supplier, Optional.empty());
    assertThat(responseFor(handler, request), is("{\n" + "  \"string\" : \"foo\",\n" + "  \"integer\" : 456\n" + "}"));
}
Also used : HttpRequest(com.hotels.styx.api.HttpRequest) Test(org.junit.jupiter.api.Test)

Example 13 with HttpRequest

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

the class PluginToggleHandlerTest method disablesEnabledPlugin.

@Test
public void disablesEnabledPlugin() {
    HttpRequest request = put("/foo/on/enabled").body("false", UTF_8).build();
    HttpResponse response = Mono.from(handler.handle(request, requestContext())).block();
    assertThat(response.status(), is(OK));
    assertThat(body(response), is("{\"message\":\"State of 'on' changed to 'disabled'\",\"plugin\":{\"name\":\"on\",\"state\":\"disabled\"}}"));
    assertThat(initiallyEnabled.enabled(), is(false));
    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 14 with HttpRequest

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

the class PluginToggleHandlerTest method saysBadRequestWhenNoStateSpecified.

@Test
public void saysBadRequestWhenNoStateSpecified() {
    HttpRequest request = put("/foo/on/enabled").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 15 with HttpRequest

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

the class PluginToggleHandlerTest method enablesDisabledPlugin.

@Test
public void enablesDisabledPlugin() {
    HttpRequest request = put("/foo/off/enabled").body("true", UTF_8).build();
    HttpResponse response = Mono.from(handler.handle(request, requestContext())).block();
    assertThat(response.status(), is(OK));
    assertThat(body(response), is("{\"message\":\"State of 'off' changed to 'enabled'\",\"plugin\":{\"name\":\"off\",\"state\":\"enabled\"}}"));
    assertThat(initiallyEnabled.enabled(), is(true));
    assertThat(initiallyDisabled.enabled(), is(true));
}
Also used : HttpRequest(com.hotels.styx.api.HttpRequest) HttpResponse(com.hotels.styx.api.HttpResponse) Test(org.junit.jupiter.api.Test)

Aggregations

HttpRequest (com.hotels.styx.api.HttpRequest)22 Test (org.junit.jupiter.api.Test)19 HttpResponse (com.hotels.styx.api.HttpResponse)16 StyxObjectRecord (com.hotels.styx.StyxObjectRecord)5 WebServiceHandler (com.hotels.styx.api.WebServiceHandler)3 StyxObjectDefinition (com.hotels.styx.routing.config.StyxObjectDefinition)2 StyxObjectStore (com.hotels.styx.routing.db.StyxObjectStore)2 Eventual (com.hotels.styx.api.Eventual)1 HttpInterceptor (com.hotels.styx.api.HttpInterceptor)1 HttpMethod (com.hotels.styx.api.HttpMethod)1 DELETE (com.hotels.styx.api.HttpMethod.DELETE)1 GET (com.hotels.styx.api.HttpMethod.GET)1 POST (com.hotels.styx.api.HttpMethod.POST)1 PUT (com.hotels.styx.api.HttpMethod.PUT)1 HttpResponse.response (com.hotels.styx.api.HttpResponse.response)1 INTERNAL_SERVER_ERROR (com.hotels.styx.api.HttpResponseStatus.INTERNAL_SERVER_ERROR)1 NOT_FOUND (com.hotels.styx.api.HttpResponseStatus.NOT_FOUND)1 Support.requestContext (com.hotels.styx.support.Support.requestContext)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1