aboutsummaryrefslogtreecommitdiffstats
path: root/http-utils
diff options
context:
space:
mode:
authorJon Marius Venstad <venstad@gmail.com>2021-03-23 13:03:11 +0100
committerJon Marius Venstad <venstad@gmail.com>2021-03-23 13:03:11 +0100
commit9de276bb472166383c40d82666dc0dbd044603bd (patch)
tree8dd3f01ec4eee9c9f439cf15fbb5f1dcd1a64715 /http-utils
parent6169d5ddcc3c69750830b326c07c05fac4de0c1f (diff)
Add test for route planner
Diffstat (limited to 'http-utils')
-rw-r--r--http-utils/src/test/java/ai/vespa/util/http/hc5/HttpToHttpsRoutePlannerTest.java59
1 files changed, 59 insertions, 0 deletions
diff --git a/http-utils/src/test/java/ai/vespa/util/http/hc5/HttpToHttpsRoutePlannerTest.java b/http-utils/src/test/java/ai/vespa/util/http/hc5/HttpToHttpsRoutePlannerTest.java
new file mode 100644
index 00000000000..58dc25fdf1a
--- /dev/null
+++ b/http-utils/src/test/java/ai/vespa/util/http/hc5/HttpToHttpsRoutePlannerTest.java
@@ -0,0 +1,59 @@
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package ai.vespa.util.http.hc5;
+
+import org.apache.hc.client5.http.HttpRoute;
+import org.apache.hc.client5.http.config.RequestConfig;
+import org.apache.hc.client5.http.protocol.HttpClientContext;
+import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.HttpHost;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author jonmv
+ */
+public class HttpToHttpsRoutePlannerTest {
+
+ final HttpToHttpsRoutePlanner planner = new HttpToHttpsRoutePlanner();
+
+ @Test
+ public void verifySchemeMustBeHttp() throws HttpException {
+ try {
+ planner.determineRoute(new HttpHost("https", "host", 1), new HttpClientContext());
+ }
+ catch (IllegalArgumentException e) {
+ assertEquals("Scheme must be 'http' when using HttpToHttpsRoutePlanner", e.getMessage());
+ }
+ }
+
+ @Test
+ public void verifyPortMustBeSet() throws HttpException {
+ try {
+ planner.determineRoute(new HttpHost("http", "host", -1), new HttpClientContext());
+ }
+ catch (IllegalArgumentException e) {
+ assertEquals("Port must be set when using HttpToHttpsRoutePlanner", e.getMessage());
+ }
+ }
+
+
+ @Test
+ public void verifyProxyIsDisallowed() throws HttpException {
+ HttpClientContext context = new HttpClientContext();
+ context.setRequestConfig(RequestConfig.custom().setProxy(new HttpHost("proxy")).build());
+ try {
+ planner.determineRoute(new HttpHost("http", "host", 1), context);
+ }
+ catch (IllegalArgumentException e) {
+ assertEquals("Proxies are not supported with HttpToHttpsRoutePlanner", e.getMessage());
+ }
+ }
+
+ @Test
+ public void verifySchemeIsRewritten() throws HttpException {
+ assertEquals(new HttpRoute(new HttpHost("https", "host", 1)),
+ planner.determineRoute(new HttpHost("http", "host", 1), new HttpClientContext()));
+ }
+
+}