Search in sources :

Example 26 with HttpResponse

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

the class StyxHttpClientTest method sendsMessagesInAbsoluteUrlFormat.

@Disabled
@Test
public /*
     * Wiremock (or Jetty server) origin converts an absolute URL to an origin
     * form. Therefore we are unable to use an origin to verify that client used
     * an absolute URL. However I (Mikko) have verified with WireShark that the
     * request is indeed sent in absolute form.
     */
void sendsMessagesInAbsoluteUrlFormat() throws ExecutionException, InterruptedException {
    HttpResponse response = new StyxHttpClient.Builder().build().send(get(format("http://%s/index.html", hostString(server.port()))).build()).get();
    assertThat(response.status(), is(OK));
    server.verify(getRequestedFor(urlEqualTo(format("http://%s/index.html", hostString(server.port())))).withHeader("Host", equalTo(hostString(server.port()))));
}
Also used : HttpResponse(com.hotels.styx.api.HttpResponse) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 27 with HttpResponse

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

the class StyxHttpClientTest method overridesTlsSettingsWithSecure.

/*
     * StyxHttpClientTransaction
     * - secure() method applies default TLS settings
     */
@Test
public void overridesTlsSettingsWithSecure() throws ExecutionException, InterruptedException {
    StyxHttpClient client = new StyxHttpClient.Builder().build();
    HttpResponse response = client.secure().send(secureRequest).get();
    assertThat(response.status(), is(OK));
}
Also used : HttpResponse(com.hotels.styx.api.HttpResponse) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) Test(org.junit.jupiter.api.Test)

Example 28 with HttpResponse

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

the class StyxHttpClientTest method overridesTlsSettingsWithSecureBoolean.

/*
     * StyxHttpClientTransaction
     * - secure(true) applies default TLS settings
     */
@Test
public void overridesTlsSettingsWithSecureBoolean() throws ExecutionException, InterruptedException {
    StyxHttpClient client = new StyxHttpClient.Builder().build();
    HttpResponse response = client.secure(true).send(secureRequest).get();
    assertThat(response.status(), is(OK));
}
Also used : HttpResponse(com.hotels.styx.api.HttpResponse) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) Test(org.junit.jupiter.api.Test)

Example 29 with HttpResponse

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

the class StyxHttpClientTest method overridesTlsSettingsWithSecureBooleanFalse.

/*
     * StyxHttpClientTransaction
     * - secure(false) disables TLS protection
     */
@Test
public void overridesTlsSettingsWithSecureBooleanFalse() throws ExecutionException, InterruptedException {
    StyxHttpClient client = new StyxHttpClient.Builder().tlsSettings(new TlsSettings.Builder().build()).build();
    HttpResponse response = client.secure(false).send(httpRequest).get();
    assertThat(response.status(), is(OK));
}
Also used : HttpResponse(com.hotels.styx.api.HttpResponse) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) TlsSettings(com.hotels.styx.api.extension.service.TlsSettings) Test(org.junit.jupiter.api.Test)

Example 30 with HttpResponse

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

the class MockOriginServerTest method configuresEndpoints.

@Test
public void configuresEndpoints() {
    server = MockOriginServer.create("", "", 0, new HttpConnectorConfig(0)).start().stub(WireMock.get(urlMatching("/.*")), aResponse().withStatus(200).withHeader("a", "b").withBody("Hello, World!"));
    HttpResponse response = await(client.sendRequest(get(format("http://localhost:%d/mock", server.port())).header("X-Forwarded-Proto", "http").build()));
    assertThat(response.status(), is(OK));
    assertThat(response.header("a"), is(Optional.of("b")));
    assertThat(response.bodyAs(UTF_8), is("Hello, World!"));
    server.verify(getRequestedFor(urlEqualTo("/mock")).withHeader("X-Forwarded-Proto", valueMatchingStrategy("http")));
}
Also used : HttpResponse(com.hotels.styx.api.HttpResponse) HttpConnectorConfig(com.hotels.styx.server.HttpConnectorConfig) 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