|
18 | 18 | import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
|
19 | 19 | import static com.github.tomakehurst.wiremock.client.WireMock.any;
|
20 | 20 | import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
|
| 21 | +import static com.github.tomakehurst.wiremock.client.WireMock.post; |
21 | 22 | import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor;
|
22 | 23 | import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
|
23 | 24 | import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
|
24 | 25 | import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
|
25 | 26 | import static com.github.tomakehurst.wiremock.client.WireMock.verify;
|
26 | 27 | import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
|
| 28 | +import static java.util.Collections.emptyMap; |
27 | 29 | import static java.util.Collections.singletonMap;
|
28 | 30 | import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
|
| 31 | +import static org.apache.commons.lang3.RandomStringUtils.randomAscii; |
29 | 32 | import static org.apache.commons.lang3.StringUtils.reverse;
|
30 | 33 | import static org.assertj.core.api.Assertions.assertThat;
|
31 | 34 | import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
|
41 | 44 | import static software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClientTestUtils.makeSimpleRequest;
|
42 | 45 |
|
43 | 46 | import com.github.tomakehurst.wiremock.WireMockServer;
|
| 47 | +import com.github.tomakehurst.wiremock.client.WireMock; |
44 | 48 | import com.github.tomakehurst.wiremock.http.Fault;
|
45 | 49 | import com.github.tomakehurst.wiremock.junit.WireMockRule;
|
46 | 50 | import io.netty.channel.Channel;
|
|
55 | 59 | import io.netty.util.AttributeKey;
|
56 | 60 | import java.io.IOException;
|
57 | 61 | import java.net.URI;
|
| 62 | +import java.nio.ByteBuffer; |
58 | 63 | import java.time.Duration;
|
59 | 64 | import java.util.ArrayList;
|
60 | 65 | import java.util.Collections;
|
|
80 | 85 | import software.amazon.awssdk.http.SdkHttpFullRequest;
|
81 | 86 | import software.amazon.awssdk.http.SdkHttpMethod;
|
82 | 87 | import software.amazon.awssdk.http.SdkHttpRequest;
|
| 88 | +import software.amazon.awssdk.http.SimpleHttpContentPublisher; |
83 | 89 | import software.amazon.awssdk.http.async.AsyncExecuteRequest;
|
84 | 90 | import software.amazon.awssdk.http.async.SdkAsyncHttpClient;
|
85 | 91 | import software.amazon.awssdk.http.nio.netty.internal.NettyConfiguration;
|
@@ -558,6 +564,25 @@ public ChannelFuture close() {
|
558 | 564 | assertThat(channelClosedFuture.get(5, TimeUnit.SECONDS)).isTrue();
|
559 | 565 | }
|
560 | 566 |
|
| 567 | + @Test |
| 568 | + public void execute_requestByteBufferWithNonZeroPosition_shouldHonor() throws Exception { |
| 569 | + String body = randomAlphabetic(70); |
| 570 | + byte[] content = randomAscii(100).getBytes(); |
| 571 | + ByteBuffer requestContent = ByteBuffer.wrap(content); |
| 572 | + requestContent.position(95); |
| 573 | + String expected = new String(content, 95, 5); |
| 574 | + |
| 575 | + URI uri = URI.create("http://localhost:" + mockServer.port()); |
| 576 | + stubFor(post(urlPathEqualTo("/")) |
| 577 | + .withRequestBody(equalTo(expected)).willReturn(aResponse().withBody(body))); |
| 578 | + SdkHttpRequest request = createRequest(uri, "/", expected, SdkHttpMethod.POST, emptyMap()); |
| 579 | + RecordingResponseHandler recorder = new RecordingResponseHandler(); |
| 580 | + |
| 581 | + client.execute(AsyncExecuteRequest.builder().request(request).requestContentPublisher(new SimpleHttpContentPublisher(requestContent)).responseHandler(recorder).build()); |
| 582 | + recorder.completeFuture.get(5, TimeUnit.SECONDS); |
| 583 | + verify(postRequestedFor(urlPathEqualTo("/")).withRequestBody(equalTo(expected))); |
| 584 | + } |
| 585 | + |
561 | 586 | // Needs to be a non-anon class in order to spy
|
562 | 587 | public static class CustomThreadFactory implements ThreadFactory {
|
563 | 588 | @Override
|
|
0 commit comments