Search in sources :

Example 1 with Config

use of com.hotels.styx.AggregateRequestBodyExamplePlugin.Config 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)

Aggregations

Config (com.hotels.styx.AggregateRequestBodyExamplePlugin.Config)1 ByteStream (com.hotels.styx.api.ByteStream)1 Eventual (com.hotels.styx.api.Eventual)1 HttpInterceptor (com.hotels.styx.api.HttpInterceptor)1 LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)1 LiveHttpResponse (com.hotels.styx.api.LiveHttpResponse)1 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)1 CoreMatchers.is (org.hamcrest.CoreMatchers.is)1 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)1 Test (org.junit.jupiter.api.Test)1 Mono (reactor.core.publisher.Mono)1