diff options
author | Bjørn Christian Seime <bjorncs@verizonmedia.com> | 2019-04-05 15:13:23 +0200 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@verizonmedia.com> | 2019-04-08 12:40:47 +0200 |
commit | 34fdd0de9b5a8e06d74fc919434ee0d0dd77a14f (patch) | |
tree | 42df761afe00901d9cf20b85b3ea9cab234ffe82 /http-utils/src/test | |
parent | b8f02d9ef033d418764d1af6ebfd773fb2673086 (diff) |
Add 'http-utils' module with VespaHttpClientBuilder
- Move VespaHttpClientBuilder source code from 'security-utils' to 'http-utils'.
- Improve configuration of connection manager.
- Add static factory for client builder with BasicHttpClientConnectionManager.
- Simplify implementations of ConnectionManagerFactory by improving its interface.
Diffstat (limited to 'http-utils/src/test')
-rw-r--r-- | http-utils/src/test/java/ai/vespa/util/http/VespaHttpClientBuilderTest.java | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/http-utils/src/test/java/ai/vespa/util/http/VespaHttpClientBuilderTest.java b/http-utils/src/test/java/ai/vespa/util/http/VespaHttpClientBuilderTest.java new file mode 100644 index 00000000000..7ffd0e459b0 --- /dev/null +++ b/http-utils/src/test/java/ai/vespa/util/http/VespaHttpClientBuilderTest.java @@ -0,0 +1,39 @@ +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package ai.vespa.util.http; + +import ai.vespa.util.http.VespaHttpClientBuilder.HttpToHttpsRewritingRequestInterceptor; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.protocol.BasicHttpContext; +import org.junit.Test; + +import java.net.URI; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +/** + * @author bjorncs + */ +public class VespaHttpClientBuilderTest { + + @Test + public void request_interceptor_modifies_scheme_of_requests() { + verifyProcessedUriMatchesExpectedOutput("http://dummyhostname:8080/a/path/to/resource?query=value", + "https://dummyhostname:8080/a/path/to/resource?query=value"); + } + + @Test + public void request_interceptor_add_handles_implicit_http_port() { + verifyProcessedUriMatchesExpectedOutput("http://dummyhostname/a/path/to/resource?query=value", + "https://dummyhostname:80/a/path/to/resource?query=value"); + } + + private static void verifyProcessedUriMatchesExpectedOutput(String inputUri, String expectedOutputUri) { + var interceptor = new HttpToHttpsRewritingRequestInterceptor(); + HttpGet request = new HttpGet(inputUri); + interceptor.process(request, new BasicHttpContext()); + URI modifiedUri = request.getURI(); + URI expectedUri = URI.create(expectedOutputUri); + assertThat(modifiedUri).isEqualTo(expectedUri); + } + +}
\ No newline at end of file |