Search in sources :

Example 56 with HttpResponse

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

the class StyxProxyTest method startsServerWithBothHttpAndHttpsConnectors.

@Disabled
@Test
public void startsServerWithBothHttpAndHttpsConnectors() throws IOException {
    Service server = StyxServers.toGuavaService(newBuilder().setProtocolConnector(connector(0)).build());
    server.startAsync().awaitRunning();
    assertThat("Server should be running", server.isRunning());
    LOGGER.info("server is running: " + server.isRunning());
    HttpResponse clearResponse = get("http://localhost:8080/search?q=fanta");
    assertThat(clearResponse.bodyAs(UTF_8), containsString("Response from http Connector"));
    HttpResponse secureResponse = get("https://localhost:8443/secure");
    assertThat(secureResponse.bodyAs(UTF_8), containsString("Response from https Connector"));
    server.stopAsync().awaitTerminated();
    assertThat("Server should not be running", !server.isRunning());
}
Also used : Service(com.google.common.util.concurrent.Service) 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 57 with HttpResponse

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

the class StyxHttpClientTest method sendsMessagesInOriginUrlFormat.

/*
     * StyxHttpClient
     * - Sends a request when HTTP "request-target" is in origin format.
     * - Ref: https://tools.ietf.org/html/rfc7230#section-5.3.1
     */
@Test
public void sendsMessagesInOriginUrlFormat() throws ExecutionException, InterruptedException {
    HttpResponse response = new StyxHttpClient.Builder().build().send(get("/index.html").header(HOST, hostString(server.port())).build()).get();
    assertThat(response.status(), is(OK));
    server.verify(getRequestedFor(urlEqualTo("/index.html")).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)

Example 58 with HttpResponse

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

the class StyxHttpClientTest method usesDefaultUserAgent.

/*
     * StyxHttpClient
     * - Uses default user-agent string.
     */
@Test
public void usesDefaultUserAgent() throws ExecutionException, InterruptedException {
    StyxHttpClient client = new StyxHttpClient.Builder().userAgent("Simple-Client-Parent-Settings").build();
    HttpResponse response = client.send(httpRequest).get();
    assertThat(response.status(), is(OK));
    server.verify(getRequestedFor(urlEqualTo("/")).withHeader("User-Agent", equalTo("Simple-Client-Parent-Settings")));
}
Also used : HttpResponse(com.hotels.styx.api.HttpResponse) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) Test(org.junit.jupiter.api.Test)

Example 59 with HttpResponse

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

the class StyxHttpClientTest method usesDefaultTlsSettings.

/*
     * StyxHttpClient
     * - Applies default TLS settings
     */
@Test
public void usesDefaultTlsSettings() throws ExecutionException, InterruptedException {
    StyxHttpClient client = new StyxHttpClient.Builder().tlsSettings(new TlsSettings.Builder().build()).build();
    HttpResponse response = client.send(secureRequest).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 60 with HttpResponse

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

the class AbstractStyxServiceTest method exposesNameAndStatusViaAdminInterface.

@Test
public void exposesNameAndStatusViaAdminInterface() throws ExecutionException, InterruptedException {
    DerivedStyxService service = new DerivedStyxService("derived-service", new CompletableFuture<>());
    HttpResponse response = Mono.from(service.adminInterfaceHandlers().get("status").handle(get, MOCK_CONTEXT).flatMap(r -> r.aggregate(1024))).block();
    assertThat(response.bodyAs(UTF_8), is("{ name: \"derived-service\" status: \"CREATED\" }"));
}
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