From e899aae3d5027851c82ba4295beec035584e2aca Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Wed, 22 Nov 2023 12:25:19 +0100 Subject: [PATCH] Fixed deprecations --- .../http/AbstractJsonEntityConsumerTest.java | 5 ++-- .../json/http/JsonResponseConsumerTest.java | 23 ++++++++++++++----- .../examles/JsonObjectRequestExample.java | 4 ++-- .../examles/JsonSequenceRequestExample.java | 4 ++-- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/hc5-async-json/src/test/java/com/ok2c/hc5/json/http/AbstractJsonEntityConsumerTest.java b/hc5-async-json/src/test/java/com/ok2c/hc5/json/http/AbstractJsonEntityConsumerTest.java index f61e8d4..7b9c5d1 100644 --- a/hc5-async-json/src/test/java/com/ok2c/hc5/json/http/AbstractJsonEntityConsumerTest.java +++ b/hc5-async-json/src/test/java/com/ok2c/hc5/json/http/AbstractJsonEntityConsumerTest.java @@ -1,11 +1,10 @@ package com.ok2c.hc5.json.http; -import java.net.URI; import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; import org.apache.hc.client5.http.async.methods.SimpleHttpRequest; -import org.apache.hc.client5.http.async.methods.SimpleHttpRequests; +import org.apache.hc.client5.http.async.methods.SimpleRequestBuilder; import org.apache.hc.client5.http.async.methods.SimpleRequestProducer; import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient; import org.apache.hc.client5.http.impl.async.HttpAsyncClients; @@ -28,7 +27,7 @@ void testRequestWithINVALIDrequest() throws Exception { // Verify that a request to self with an invalid url still calls the completion. try (CloseableHttpAsyncClient httpClient = HttpAsyncClients.createHttp2Default()) { httpClient.start(); - SimpleHttpRequest request = SimpleHttpRequests.get(URI.create("http://localhost/INVALID")); + SimpleHttpRequest request = SimpleRequestBuilder.get("http://localhost/INVALID").build(); JsonFactory jsonFactory = mapper.getFactory(); JsonTokenEventHandler mockJsonTokenEventHandler = Mockito.mock(JsonTokenEventHandler.class); @SuppressWarnings("unchecked") diff --git a/hc5-async-json/src/test/java/com/ok2c/hc5/json/http/JsonResponseConsumerTest.java b/hc5-async-json/src/test/java/com/ok2c/hc5/json/http/JsonResponseConsumerTest.java index 5e4605f..8933566 100644 --- a/hc5-async-json/src/test/java/com/ok2c/hc5/json/http/JsonResponseConsumerTest.java +++ b/hc5-async-json/src/test/java/com/ok2c/hc5/json/http/JsonResponseConsumerTest.java @@ -4,8 +4,10 @@ import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; +import java.time.Duration; import java.util.Collections; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; import org.apache.hc.client5.http.HttpResponseException; import org.apache.hc.client5.http.protocol.HttpClientContext; @@ -65,8 +67,11 @@ public void cancelled() { consumer.streamEnd(null); // SUCCESS: Non-JSON content-type is ignored by the consumer, it returns a 'null' to the callback. - assertThat(resultFuture).hasFailedWithThrowableThat() - .isInstanceOf(HttpResponseException.class); + assertThat(resultFuture) + .failsWithin(Duration.ofMinutes(1)) + .withThrowableThat() + .isInstanceOf(ExecutionException.class) + .withCauseInstanceOf(HttpResponseException.class); } @Test @@ -103,8 +108,11 @@ public void cancelled() { consumer.streamEnd(null); // FAILS: consumer attempts to parse the error body as it was a successful response and throws a parsing error - assertThat(resultFuture).hasFailedWithThrowableThat() - .isInstanceOf(HttpResponseException.class); + assertThat(resultFuture) + .failsWithin(Duration.ofMinutes(1)) + .withThrowableThat() + .isInstanceOf(ExecutionException.class) + .withCauseInstanceOf(HttpResponseException.class); } @Test @@ -141,8 +149,11 @@ public void cancelled() { consumer.streamEnd(null); // FAILS: consumer attempts to parse the error body as it was a successful response and throws a parsing error - assertThat(resultFuture).hasFailedWithThrowableThat() - .isInstanceOf(HttpResponseException.class); + assertThat(resultFuture) + .failsWithin(Duration.ofMinutes(1)) + .withThrowableThat() + .isInstanceOf(ExecutionException.class) + .withCauseInstanceOf(HttpResponseException.class); } private static void handleResponseResult(Message result, CompletableFuture resultFuture) { diff --git a/hc5-async-json/src/test/java/com/ok2c/hc5/json/http/examles/JsonObjectRequestExample.java b/hc5-async-json/src/test/java/com/ok2c/hc5/json/http/examles/JsonObjectRequestExample.java index e2a1f15..8cc0605 100644 --- a/hc5-async-json/src/test/java/com/ok2c/hc5/json/http/examles/JsonObjectRequestExample.java +++ b/hc5-async-json/src/test/java/com/ok2c/hc5/json/http/examles/JsonObjectRequestExample.java @@ -18,13 +18,13 @@ import java.net.URI; import java.util.concurrent.Future; -import org.apache.hc.client5.http.async.methods.BasicHttpRequests; import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient; import org.apache.hc.client5.http.impl.async.HttpAsyncClients; import org.apache.hc.core5.concurrent.FutureCallback; import org.apache.hc.core5.http.HttpResponse; import org.apache.hc.core5.http.Message; import org.apache.hc.core5.http.message.BasicNameValuePair; +import org.apache.hc.core5.http.support.BasicRequestBuilder; import org.apache.hc.core5.io.CloseMode; import com.fasterxml.jackson.core.JsonFactory; @@ -48,7 +48,7 @@ public static void main(String... args) throws Exception { objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); System.out.println("Executing POST " + uri); Future future = client.execute( - JsonRequestProducers.create(BasicHttpRequests.post(uri), + JsonRequestProducers.create(BasicRequestBuilder.post(uri).build(), new BasicNameValuePair("name", "value"), objectMapper), JsonResponseConsumers.create(objectMapper, RequestData.class), new FutureCallback>() { diff --git a/hc5-async-json/src/test/java/com/ok2c/hc5/json/http/examles/JsonSequenceRequestExample.java b/hc5-async-json/src/test/java/com/ok2c/hc5/json/http/examles/JsonSequenceRequestExample.java index 6b7edb9..cb6c8bd 100644 --- a/hc5-async-json/src/test/java/com/ok2c/hc5/json/http/examles/JsonSequenceRequestExample.java +++ b/hc5-async-json/src/test/java/com/ok2c/hc5/json/http/examles/JsonSequenceRequestExample.java @@ -18,13 +18,13 @@ import java.net.URI; import java.util.concurrent.Future; -import org.apache.hc.client5.http.async.methods.BasicHttpRequests; import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient; import org.apache.hc.client5.http.impl.async.HttpAsyncClients; import org.apache.hc.core5.concurrent.FutureCallback; import org.apache.hc.core5.http.HttpResponse; import org.apache.hc.core5.http.Message; import org.apache.hc.core5.http.message.BasicNameValuePair; +import org.apache.hc.core5.http.support.BasicRequestBuilder; import org.apache.hc.core5.io.CloseMode; import com.fasterxml.jackson.core.JsonFactory; @@ -48,7 +48,7 @@ public static void main(String... args) throws Exception { objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); System.out.println("Executing POST " + uri); Future future = client.execute( - JsonRequestProducers.create(BasicHttpRequests.post(uri), + JsonRequestProducers.create(BasicRequestBuilder.post(uri).build(), objectMapper, channel -> { channel.write(new BasicNameValuePair("name1", "value1"));