Search in sources :

Example 21 with LiveHttpRequest

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

the class FunctionResolverTest method resolvesZeroArgumentFunctions.

@Test
public void resolvesZeroArgumentFunctions() {
    LiveHttpRequest request = get("/foo").build();
    assertThat(functionResolver.resolveFunction("path", emptyList()).call(request, context), is("/foo"));
    assertThat(functionResolver.resolveFunction("method", emptyList()).call(request, context), is("GET"));
}
Also used : LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) Test(org.junit.jupiter.api.Test)

Example 22 with LiveHttpRequest

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

the class CompositeHttpErrorStatusListenerTest method propagatesProxyErrorsWithRequests.

@Test
public void propagatesProxyErrorsWithRequests() {
    LiveHttpRequest request = LiveHttpRequest.get("/foo").build();
    IOException cause = new IOException();
    InetSocketAddress clientAddress = InetSocketAddress.createUnresolved("127.0.0.1", 0);
    listener.proxyErrorOccurred(request, clientAddress, INTERNAL_SERVER_ERROR, cause);
    verify(delegate1).proxyErrorOccurred(request, clientAddress, INTERNAL_SERVER_ERROR, cause);
    verify(delegate2).proxyErrorOccurred(request, clientAddress, INTERNAL_SERVER_ERROR, cause);
    verify(delegate3).proxyErrorOccurred(request, clientAddress, INTERNAL_SERVER_ERROR, cause);
}
Also used : LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Example 23 with LiveHttpRequest

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

the class AggregateRequestBodyExamplePluginTest method contentIsModified.

@Test
public void contentIsModified() {
    // Set up
    Config config = new Config("MyExtraText");
    String originalBody = "OriginalBody";
    AggregateRequestBodyExamplePlugin plugin = new AggregateRequestBodyExamplePlugin(config);
    LiveHttpRequest request = LiveHttpRequest.post("/", ByteStream.from(originalBody, UTF_8)).build();
    // Our implementation of "chain.proceed()" verifies the content of the request
    HttpInterceptor.Chain chain = intRequest -> {
        String requestBody = Mono.from(intRequest.aggregate(100)).block().bodyAs(UTF_8);
        assertThat(requestBody, is(originalBody + config.extraText()));
        return Eventual.of(LiveHttpResponse.response().build());
    };
    // Invoke plugin and wait until it finishes execution
    Mono.from(plugin.intercept(request, chain)).block();
}
Also used : HttpInterceptor(com.hotels.styx.api.HttpInterceptor) Test(org.junit.jupiter.api.Test) CoreMatchers.is(org.hamcrest.CoreMatchers.is) Config(com.hotels.styx.AggregateRequestBodyExamplePlugin.Config) Eventual(com.hotels.styx.api.Eventual) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) ByteStream(com.hotels.styx.api.ByteStream) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Mono(reactor.core.publisher.Mono) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) Config(com.hotels.styx.AggregateRequestBodyExamplePlugin.Config) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) HttpInterceptor(com.hotels.styx.api.HttpInterceptor) Test(org.junit.jupiter.api.Test)

Example 24 with LiveHttpRequest

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

the class HttpRequestMessageLoggerTest method logsClientSideResponseDetailsLongFormat.

@Test
public void logsClientSideResponseDetailsLongFormat() {
    LiveHttpRequest styxRequest = get("http://www.hotels.com/foo/bar/request").build();
    LiveHttpResponse styxResponse = response(OK).build();
    new HttpRequestMessageLogger("com.hotels.styx.http-messages.outbound", true, httpMessageFormatter).logResponse(styxRequest, styxResponse);
    assertThat(log.lastMessage(), is(loggingEvent(INFO, format("requestId=%s, response=" + FORMATTED_RESPONSE, styxRequest.id()))));
}
Also used : HttpRequestMessageLogger(com.hotels.styx.common.logging.HttpRequestMessageLogger) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 25 with LiveHttpRequest

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

the class HttpRequestMessageLoggerTest method responseLogUnexpectedArguments.

private static Stream<Arguments> responseLogUnexpectedArguments() {
    LiveHttpRequest normalRequest = get("http://www.hotels.com/foo/bar/request").build();
    LiveHttpResponse normalResponse = response(OK).build();
    return Stream.of(Arguments.of(normalRequest, null, WARN, "requestId=.*, response=null"), Arguments.of(null, normalResponse, INFO, "requestId=null, response=\\{version=HTTP/1.1, status=200 OK\\}"), Arguments.of(null, null, WARN, "requestId=null, response=null"));
}
Also used : LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse)

Aggregations

LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)82 Test (org.junit.jupiter.api.Test)76 Condition (com.hotels.styx.server.routing.Condition)19 LiveHttpResponse (com.hotels.styx.api.LiveHttpResponse)14 HttpHandler (com.hotels.styx.api.HttpHandler)10 MicrometerRegistry (com.hotels.styx.api.MicrometerRegistry)9 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)9 MeterRegistry (com.hotels.styx.api.MeterRegistry)8 BackendService (com.hotels.styx.api.extension.service.BackendService)7 Registry (com.hotels.styx.api.extension.service.spi.Registry)7 Eventual (com.hotels.styx.api.Eventual)6 HttpInterceptor (com.hotels.styx.api.HttpInterceptor)6 HttpResponse (com.hotels.styx.api.HttpResponse)5 Origin.newOriginBuilder (com.hotels.styx.api.extension.Origin.newOriginBuilder)5 DefaultHttpRequest (io.netty.handler.codec.http.DefaultHttpRequest)5 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 Mono (reactor.core.publisher.Mono)5 HttpRequestMessageLogger (com.hotels.styx.common.logging.HttpRequestMessageLogger)4 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)4