summaryrefslogtreecommitdiffstats
path: root/http-utils
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@yahooinc.com>2022-07-27 15:52:17 +0200
committerBjørn Christian Seime <bjorncs@yahooinc.com>2022-07-27 15:58:37 +0200
commitb434b82feae653f432762e30d2a59e4f2ee651e7 (patch)
tree275b0a8771fae8f352779b617f090eabb74c535c /http-utils
parent4ed0df01b4c4ff7a8238c7dd31b9c252e94ce87a (diff)
Convert http-utils to junit5
Diffstat (limited to 'http-utils')
-rw-r--r--http-utils/pom.xml9
-rw-r--r--http-utils/src/test/java/ai/vespa/util/http/hc4/VespaHttpClientBuilderTest.java10
-rw-r--r--http-utils/src/test/java/ai/vespa/util/http/hc4/retry/DelayedConnectionLevelRetryHandlerTest.java16
-rw-r--r--http-utils/src/test/java/ai/vespa/util/http/hc4/retry/DelayedResponseLevelRetryHandlerTest.java20
-rw-r--r--http-utils/src/test/java/ai/vespa/util/http/hc5/HttpToHttpsRoutePlannerTest.java14
5 files changed, 37 insertions, 32 deletions
diff --git a/http-utils/pom.xml b/http-utils/pom.xml
index 5b26235b62e..6cb6cd018c8 100644
--- a/http-utils/pom.xml
+++ b/http-utils/pom.xml
@@ -50,8 +50,13 @@
<!-- test scope -->
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
diff --git a/http-utils/src/test/java/ai/vespa/util/http/hc4/VespaHttpClientBuilderTest.java b/http-utils/src/test/java/ai/vespa/util/http/hc4/VespaHttpClientBuilderTest.java
index cf80375611f..27819ff0117 100644
--- a/http-utils/src/test/java/ai/vespa/util/http/hc4/VespaHttpClientBuilderTest.java
+++ b/http-utils/src/test/java/ai/vespa/util/http/hc4/VespaHttpClientBuilderTest.java
@@ -7,9 +7,9 @@ import org.apache.http.HttpRequest;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.conn.routing.HttpRoutePlanner;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;
/**
@@ -18,17 +18,17 @@ import static org.mockito.Mockito.mock;
public class VespaHttpClientBuilderTest {
@Test
- public void route_planner_modifies_scheme_of_requests() throws HttpException {
+ void route_planner_modifies_scheme_of_requests() throws HttpException {
verifyProcessedUriMatchesExpectedOutput("http://dummyhostname:8080", "https://dummyhostname:8080");
}
@Test
- public void route_planer_handles_implicit_http_port() throws HttpException {
+ void route_planer_handles_implicit_http_port() throws HttpException {
verifyProcessedUriMatchesExpectedOutput("http://dummyhostname", "https://dummyhostname:80");
}
@Test
- public void route_planer_handles_https_port() throws HttpException {
+ void route_planer_handles_https_port() throws HttpException {
verifyProcessedUriMatchesExpectedOutput("http://dummyhostname:443", "https://dummyhostname:443");
}
diff --git a/http-utils/src/test/java/ai/vespa/util/http/hc4/retry/DelayedConnectionLevelRetryHandlerTest.java b/http-utils/src/test/java/ai/vespa/util/http/hc4/retry/DelayedConnectionLevelRetryHandlerTest.java
index bd034ab9ef2..0b83227d538 100644
--- a/http-utils/src/test/java/ai/vespa/util/http/hc4/retry/DelayedConnectionLevelRetryHandlerTest.java
+++ b/http-utils/src/test/java/ai/vespa/util/http/hc4/retry/DelayedConnectionLevelRetryHandlerTest.java
@@ -2,7 +2,7 @@
package ai.vespa.util.http.hc4.retry;
import org.apache.http.client.protocol.HttpClientContext;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import javax.net.ssl.SSLException;
import java.io.IOException;
@@ -10,8 +10,8 @@ import java.net.ConnectException;
import java.time.Duration;
import java.util.Arrays;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -23,7 +23,7 @@ public class DelayedConnectionLevelRetryHandlerTest {
@SuppressWarnings("unchecked")
@Test
- public void retry_consumers_are_invoked() {
+ void retry_consumers_are_invoked() {
RetryConsumer<IOException> retryConsumer = (RetryConsumer<IOException>) mock(RetryConsumer.class);
RetryFailedConsumer<IOException> retryFailedConsumer = (RetryFailedConsumer<IOException>) mock(RetryFailedConsumer.class);
@@ -51,7 +51,7 @@ public class DelayedConnectionLevelRetryHandlerTest {
}
@Test
- public void retry_with_fixed_delay_sleeps_for_expected_duration() {
+ void retry_with_fixed_delay_sleeps_for_expected_duration() {
Sleeper sleeper = mock(Sleeper.class);
Duration delay = Duration.ofSeconds(2);
@@ -73,7 +73,7 @@ public class DelayedConnectionLevelRetryHandlerTest {
}
@Test
- public void retry_with_fixed_backoff_sleeps_for_expected_durations() {
+ void retry_with_fixed_backoff_sleeps_for_expected_durations() {
Sleeper sleeper = mock(Sleeper.class);
Duration startDelay = Duration.ofMillis(500);
@@ -100,7 +100,7 @@ public class DelayedConnectionLevelRetryHandlerTest {
}
@Test
- public void retries_for_listed_exceptions_until_max_retries_exceeded() {
+ void retries_for_listed_exceptions_until_max_retries_exceeded() {
int maxRetries = 2;
DelayedConnectionLevelRetryHandler handler = DelayedConnectionLevelRetryHandler.Builder
@@ -119,7 +119,7 @@ public class DelayedConnectionLevelRetryHandlerTest {
}
@Test
- public void does_not_retry_for_non_listed_exception() {
+ void does_not_retry_for_non_listed_exception() {
DelayedConnectionLevelRetryHandler handler = DelayedConnectionLevelRetryHandler.Builder
.withFixedDelay(Duration.ofSeconds(2), 2)
.retryForExceptions(Arrays.asList(SSLException.class, ConnectException.class))
diff --git a/http-utils/src/test/java/ai/vespa/util/http/hc4/retry/DelayedResponseLevelRetryHandlerTest.java b/http-utils/src/test/java/ai/vespa/util/http/hc4/retry/DelayedResponseLevelRetryHandlerTest.java
index adbc445de1a..374dee63019 100644
--- a/http-utils/src/test/java/ai/vespa/util/http/hc4/retry/DelayedResponseLevelRetryHandlerTest.java
+++ b/http-utils/src/test/java/ai/vespa/util/http/hc4/retry/DelayedResponseLevelRetryHandlerTest.java
@@ -7,15 +7,15 @@ import org.apache.http.HttpVersion;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.message.BasicHttpResponse;
import org.apache.http.message.BasicStatusLine;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.time.Duration;
import java.util.Arrays;
import java.util.List;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -26,7 +26,7 @@ public class DelayedResponseLevelRetryHandlerTest {
@Test
@SuppressWarnings("unchecked")
- public void retry_consumers_are_invoked() {
+ void retry_consumers_are_invoked() {
RetryConsumer<HttpResponse> retryConsumer = mock(RetryConsumer.class);
RetryFailedConsumer<HttpResponse> retryFailedConsumer = mock(RetryFailedConsumer.class);
@@ -53,7 +53,7 @@ public class DelayedResponseLevelRetryHandlerTest {
}
@Test
- public void retry_with_fixed_delay_sleeps_for_expected_duration() {
+ void retry_with_fixed_delay_sleeps_for_expected_duration() {
Duration delay = Duration.ofSeconds(2);
int maxRetries = 2;
@@ -71,7 +71,7 @@ public class DelayedResponseLevelRetryHandlerTest {
}
@Test
- public void retry_with_fixed_backoff_sleeps_for_expected_durations() {
+ void retry_with_fixed_backoff_sleeps_for_expected_durations() {
Duration startDelay = Duration.ofMillis(500);
Duration maxDelay = Duration.ofSeconds(5);
int maxRetries = 10;
@@ -90,12 +90,12 @@ public class DelayedResponseLevelRetryHandlerTest {
Duration.ofSeconds(5), Duration.ofSeconds(5), Duration.ofSeconds(5));
for (int i = 1; i <= lastExecutionCount; i++) {
handler.retryRequest(response, i, ctx);
- assertEquals(expectedIntervals.get(i-1).toMillis(), handler.getRetryInterval());
+ assertEquals(expectedIntervals.get(i - 1).toMillis(), handler.getRetryInterval());
}
}
@Test
- public void retries_for_listed_exceptions_until_max_retries_exceeded() {
+ void retries_for_listed_exceptions_until_max_retries_exceeded() {
int maxRetries = 2;
DelayedResponseLevelRetryHandler handler = DelayedResponseLevelRetryHandler.Builder
@@ -113,7 +113,7 @@ public class DelayedResponseLevelRetryHandlerTest {
}
@Test
- public void does_not_retry_for_non_listed_exception() {
+ void does_not_retry_for_non_listed_exception() {
DelayedResponseLevelRetryHandler handler = DelayedResponseLevelRetryHandler.Builder
.withFixedDelay(Duration.ofSeconds(2), 2)
.retryForStatusCodes(Arrays.asList(HttpStatus.SC_SERVICE_UNAVAILABLE, HttpStatus.SC_BAD_GATEWAY))
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
index 78c413fba56..b20d801e39c 100644
--- 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
@@ -6,9 +6,9 @@ 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 org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author jonmv
@@ -18,7 +18,7 @@ public class HttpToHttpsRoutePlannerTest {
final HttpToHttpsRoutePlanner planner = new HttpToHttpsRoutePlanner();
@Test
- public void verifySchemeMustBeHttp() throws HttpException {
+ void verifySchemeMustBeHttp() throws HttpException {
try {
planner.determineRoute(new HttpHost("https", "host", 1), new HttpClientContext());
}
@@ -28,7 +28,7 @@ public class HttpToHttpsRoutePlannerTest {
}
@Test
- public void verifyPortMustBeSet() throws HttpException {
+ void verifyPortMustBeSet() throws HttpException {
try {
planner.determineRoute(new HttpHost("http", "host", -1), new HttpClientContext());
}
@@ -39,7 +39,7 @@ public class HttpToHttpsRoutePlannerTest {
@Test
- public void verifyProxyIsDisallowed() throws HttpException {
+ void verifyProxyIsDisallowed() throws HttpException {
HttpClientContext context = new HttpClientContext();
context.setRequestConfig(RequestConfig.custom().setProxy(new HttpHost("proxy")).build());
try {
@@ -51,9 +51,9 @@ public class HttpToHttpsRoutePlannerTest {
}
@Test
- public void verifySchemeIsRewritten() throws HttpException {
+ void verifySchemeIsRewritten() throws HttpException {
assertEquals(new HttpRoute(new HttpHost("https", "host", 1)),
- planner.determineRoute(new HttpHost("http", "host", 1), new HttpClientContext()));
+ planner.determineRoute(new HttpHost("http", "host", 1), new HttpClientContext()));
}
}