Search in sources :

Example 96 with HttpResponse

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

the class VersionTextHandlerTest method canCombineVersionTextFiles.

@Test
public void canCombineVersionTextFiles() {
    VersionTextHandler handler = new VersionTextHandler(resources("classpath:/versions/version1.txt", "classpath:/versions/version2.txt"));
    HttpResponse response = Mono.from(handler.handle(get("/version.txt").build(), requestContext())).block();
    assertThat(response.bodyAs(UTF_8), is("foo\nbar\n"));
}
Also used : HttpResponse(com.hotels.styx.api.HttpResponse) Test(org.junit.jupiter.api.Test)

Example 97 with HttpResponse

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

the class OriginsCommandHandlerTest method failsToIssueTheCommandForNonexistentAppId.

@ParameterizedTest
@MethodSource("nonexistentAppOrOriginId")
public void failsToIssueTheCommandForNonexistentAppId(String appId) {
    HttpResponse response = post(format("/admin/tasks/origins?cmd=disable_origin&appId=%s&originId=bar", appId));
    assertThat(response.status(), is(BAD_REQUEST));
    assertThat(response.bodyAs(UTF_8), is(format("application with id=%s is not found", appId)));
}
Also used : HttpResponse(com.hotels.styx.api.HttpResponse) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 98 with HttpResponse

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

the class OriginsCommandHandlerTest method returnsProperErrorMessageForMissingOriginId.

@Test
public void returnsProperErrorMessageForMissingOriginId() {
    HttpResponse response = post("/admin/tasks/origins?cmd=disable_origin&appId=foo");
    assertThat(response.status(), is(BAD_REQUEST));
    assertThat(response.bodyAs(UTF_8), is("cmd, appId and originId are all required parameters. cmd can be enable_origin|disable_origin"));
}
Also used : HttpResponse(com.hotels.styx.api.HttpResponse) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 99 with HttpResponse

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

the class OriginsCommandHandlerTest method failsToIssueTheCommandForNonexistentOriginId.

@ParameterizedTest
@MethodSource("nonexistentAppOrOriginId")
public void failsToIssueTheCommandForNonexistentOriginId(String originId) {
    HttpResponse response = post(format("/admin/tasks/origins?cmd=disable_origin&appId=activeAppId&originId=%s", originId));
    assertThat(response.status(), is(BAD_REQUEST));
    assertThat(response.bodyAs(UTF_8), is(format("origin with id=%s is not found for application=activeAppId", originId)));
}
Also used : HttpResponse(com.hotels.styx.api.HttpResponse) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 100 with HttpResponse

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

the class OriginsReloadCommandHandlerTest method returnsWithInformationWhenErrorDuringReload.

@Test
public void returnsWithInformationWhenErrorDuringReload() {
    mockRegistryReload(failedFuture(new RuntimeException(new RuntimeException("simulated error"))));
    HttpResponse response = Mono.from(handler.handle(get("/").build(), mock(HttpInterceptor.Context.class))).block();
    assertThat(response.status(), is(INTERNAL_SERVER_ERROR));
    assertThat(response.bodyAs(UTF_8), is(matchesRegex("There was an error processing your request. It has been logged \\(ID [0-9a-f-]+\\)\\.\n")));
}
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