Search in sources :

Example 86 with HttpResponse

use of com.hotels.styx.api.HttpResponse 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 87 with HttpResponse

use of com.hotels.styx.api.HttpResponse 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 88 with HttpResponse

use of com.hotels.styx.api.HttpResponse 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)

Example 89 with HttpResponse

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

the class PluginToggleHandlerTest method notifiesWhenPluginAlreadyEnabled.

@Test
public void notifiesWhenPluginAlreadyEnabled() {
    HttpRequest request = put("/foo/on/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 'on' was already 'enabled'\",\"plugin\":{\"name\":\"on\",\"state\":\"enabled\"}}"));
    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 90 with HttpResponse

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

the class PluginToggleHandlerTest method saysBadRequestWhenUrlIsInvalid.

@Test
public void saysBadRequestWhenUrlIsInvalid() {
    HttpRequest request = put("/foo//enabled").body("true", UTF_8).build();
    HttpResponse response = Mono.from(handler.handle(request, requestContext())).block();
    assertThat(response.status(), is(BAD_REQUEST));
    assertThat(body(response), is("Invalid URL"));
    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)

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