|
| 1 | +/* |
| 2 | + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"). |
| 5 | + * You may not use this file except in compliance with the License. |
| 6 | + * A copy of the License is located at |
| 7 | + * |
| 8 | + * http://aws.amazon.com/apache2.0 |
| 9 | + * |
| 10 | + * or in the "license" file accompanying this file. This file is distributed |
| 11 | + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 12 | + * express or implied. See the License for the specific language governing |
| 13 | + * permissions and limitations under the License. |
| 14 | + */ |
| 15 | + |
| 16 | +package software.amazon.awssdk.http.urlconnection; |
| 17 | + |
| 18 | +import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; |
| 19 | +import static com.github.tomakehurst.wiremock.client.WireMock.putRequestedFor; |
| 20 | +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; |
| 21 | + |
| 22 | +import com.github.tomakehurst.wiremock.WireMockServer; |
| 23 | +import java.io.ByteArrayInputStream; |
| 24 | +import java.io.IOException; |
| 25 | +import java.util.Arrays; |
| 26 | +import org.junit.jupiter.api.AfterAll; |
| 27 | +import org.junit.jupiter.api.BeforeAll; |
| 28 | +import org.junit.jupiter.api.Test; |
| 29 | +import software.amazon.awssdk.http.ContentStreamProvider; |
| 30 | +import software.amazon.awssdk.http.HttpExecuteRequest; |
| 31 | +import software.amazon.awssdk.http.SdkHttpClient; |
| 32 | +import software.amazon.awssdk.http.SdkHttpFullRequest; |
| 33 | +import software.amazon.awssdk.http.SdkHttpMethod; |
| 34 | + |
| 35 | +public class HeadersListTest { |
| 36 | + private static final WireMockServer WIRE_MOCK = new WireMockServer(0); |
| 37 | + private static SdkHttpClient client; |
| 38 | + |
| 39 | + @BeforeAll |
| 40 | + public static void setup() { |
| 41 | + WIRE_MOCK.start(); |
| 42 | + client = UrlConnectionHttpClient.create(); |
| 43 | + } |
| 44 | + |
| 45 | + @AfterAll |
| 46 | + public static void teardown() { |
| 47 | + client.close(); |
| 48 | + WIRE_MOCK.stop(); |
| 49 | + } |
| 50 | + |
| 51 | + @Test |
| 52 | + public void execute_requestHeaderHasMultipleValues_allValuesSent() throws IOException { |
| 53 | + ContentStreamProvider provider = () -> new ByteArrayInputStream(new byte[0]); |
| 54 | + SdkHttpFullRequest httpRequest = SdkHttpFullRequest.builder() |
| 55 | + .method(SdkHttpMethod.PUT) |
| 56 | + .host("localhost") |
| 57 | + .port(WIRE_MOCK.port()) |
| 58 | + .protocol("http") |
| 59 | + .putHeader("my-header", Arrays.asList("value1", "value2")) |
| 60 | + .encodedPath("/test") |
| 61 | + .build(); |
| 62 | + |
| 63 | + HttpExecuteRequest request = HttpExecuteRequest.builder() |
| 64 | + .request(httpRequest) |
| 65 | + .contentStreamProvider(provider) |
| 66 | + .build(); |
| 67 | + |
| 68 | + client.prepareRequest(request).call(); |
| 69 | + |
| 70 | + WIRE_MOCK.verify(putRequestedFor(urlEqualTo("/test")) |
| 71 | + .withHeader("my-header", equalTo("value1,value2"))); |
| 72 | + } |
| 73 | +} |
0 commit comments