|
| 1 | +/* |
| 2 | + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +package software.amazon.smithy.java.client.http; |
| 7 | + |
| 8 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 9 | +import static org.hamcrest.Matchers.equalTo; |
| 10 | + |
| 11 | +import java.net.URI; |
| 12 | +import java.util.concurrent.CompletableFuture; |
| 13 | +import org.junit.jupiter.api.Test; |
| 14 | +import software.amazon.smithy.java.client.core.endpoint.Endpoint; |
| 15 | +import software.amazon.smithy.java.context.Context; |
| 16 | +import software.amazon.smithy.java.core.schema.ApiOperation; |
| 17 | +import software.amazon.smithy.java.core.schema.SerializableStruct; |
| 18 | +import software.amazon.smithy.java.core.serde.Codec; |
| 19 | +import software.amazon.smithy.java.core.serde.TypeRegistry; |
| 20 | +import software.amazon.smithy.java.http.api.HttpRequest; |
| 21 | +import software.amazon.smithy.java.http.api.HttpResponse; |
| 22 | +import software.amazon.smithy.model.shapes.ShapeId; |
| 23 | + |
| 24 | +public class HttpClientProtocolTest { |
| 25 | + @Test |
| 26 | + public void mergesPaths() throws Exception { |
| 27 | + var hcp = new HttpClientProtocol(ShapeId.from("foo#Bar")) { |
| 28 | + @Override |
| 29 | + public Codec payloadCodec() { |
| 30 | + return null; |
| 31 | + } |
| 32 | + |
| 33 | + @Override |
| 34 | + public <I extends SerializableStruct, O extends SerializableStruct> HttpRequest createRequest( |
| 35 | + ApiOperation<I, O> operation, |
| 36 | + I input, |
| 37 | + Context context, |
| 38 | + URI endpoint |
| 39 | + ) { |
| 40 | + return null; |
| 41 | + } |
| 42 | + |
| 43 | + @Override |
| 44 | + public <I extends SerializableStruct, |
| 45 | + O extends SerializableStruct> CompletableFuture<O> deserializeResponse( |
| 46 | + ApiOperation<I, O> operation, |
| 47 | + Context context, |
| 48 | + TypeRegistry errorRegistry, |
| 49 | + HttpRequest request, |
| 50 | + HttpResponse response |
| 51 | + ) { |
| 52 | + return null; |
| 53 | + } |
| 54 | + }; |
| 55 | + |
| 56 | + var endpoint = Endpoint.builder().uri("https://example.com/foo%20/bar").build(); |
| 57 | + var request = HttpRequest.builder() |
| 58 | + .method("GET") |
| 59 | + .uri(new URI("/bam%20")) |
| 60 | + .build(); |
| 61 | + var merged = hcp.setServiceEndpoint(request, endpoint); |
| 62 | + |
| 63 | + // It concats the endpoints and maintains percent encoding. |
| 64 | + assertThat(merged.uri().toString(), equalTo("https://example.com/foo%20/bar/bam%20")); |
| 65 | + } |
| 66 | +} |
0 commit comments