Search in sources :

Example 6 with HttpResponse

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

the class PluginToggleHandlerTest method notifiesWhenPluginAlreadyDisabled.

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

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

the class PluginToggleHandlerTest method saysBadRequestWhenPluginDoesNotExist.

@Test
public void saysBadRequestWhenPluginDoesNotExist() {
    HttpRequest request = put("/foo/nonexistent/enabled").body("true", UTF_8).build();
    HttpResponse response = Mono.from(handler.handle(request, requestContext())).block();
    assertThat(response.status(), is(NOT_FOUND));
    assertThat(body(response), is("No such plugin: pluginName=nonexistent"));
    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 8 with HttpResponse

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

the class ServiceProviderHandlerTest method returnsNotFoundStatusWhenNamedProviderNotFound.

@Test
public void returnsNotFoundStatusWhenNamedProviderNotFound() throws IOException {
    StyxObjectStore<StyxObjectRecord<StyxService>> store = createTestStore();
    ServiceProviderHandler handler = new ServiceProviderHandler(store);
    HttpRequest request = HttpRequest.get("/admin/service/provider/nonexistent").build();
    HttpResponse response = Mono.from(handler.handle(request, requestContext())).block();
    assertThat(response.status(), equalTo(NOT_FOUND));
}
Also used : StyxObjectRecord(com.hotels.styx.StyxObjectRecord) HttpRequest(com.hotels.styx.api.HttpRequest) HttpResponse(com.hotels.styx.api.HttpResponse) Test(org.junit.jupiter.api.Test)

Example 9 with HttpResponse

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

the class ServiceProviderHandlerTest method returnsNotFoundStatusWithNonHandledUrl.

@Test
public void returnsNotFoundStatusWithNonHandledUrl() {
    StyxObjectStore<StyxObjectRecord<StyxService>> empty = new StyxObjectStore<>();
    ServiceProviderHandler handler = new ServiceProviderHandler(empty);
    HttpRequest request = HttpRequest.get("/not/my/url").build();
    HttpResponse response = Mono.from(handler.handle(request, requestContext())).block();
    assertThat(response.status(), equalTo(NOT_FOUND));
}
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 10 with HttpResponse

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

the class StartupConfigHandlerTest method outputsExpectedData.

@Test
public void outputsExpectedData() {
    StartupConfig startupConfig = newStartupConfigBuilder().styxHome("/foo").configFileLocation("/bar/configure-me.yml").logbackConfigLocation("/baz/logback-conf.xml").build();
    StartupConfigHandler handler = new StartupConfigHandler(startupConfig);
    HttpResponse response = Mono.from(handler.handle(get("/").build(), requestContext())).block();
    assertThat(response.status(), is(OK));
    assertThat(response.bodyAs(UTF_8), matchesRegex("<html><body>" + "Styx Home='[/\\\\]foo'" + "<br />Config File Location='.*[/\\\\]bar[/\\\\]configure-me.yml'" + "<br />Log Config Location='.*[/\\\\]baz[/\\\\]logback-conf.xml'" + "</body></html>"));
}
Also used : HttpResponse(com.hotels.styx.api.HttpResponse) StartupConfig(com.hotels.styx.StartupConfig) 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