From b4210cb0d60119596049170c565230ba8a0fa6bb Mon Sep 17 00:00:00 2001 From: Timon Borter Date: Tue, 26 Nov 2024 12:25:21 +0100 Subject: [PATCH] chore(deps): upgrade to spring v6.2.0 --- .../http/client/HttpResponseErrorHandler.java | 14 ++++---- .../http/server/HttpServerTest.java | 34 ++++++++++++++++--- pom.xml | 32 ++++++++--------- 3 files changed, 54 insertions(+), 26 deletions(-) diff --git a/endpoints/citrus-http/src/main/java/org/citrusframework/http/client/HttpResponseErrorHandler.java b/endpoints/citrus-http/src/main/java/org/citrusframework/http/client/HttpResponseErrorHandler.java index c6c3cd2ce2..a3a8245971 100644 --- a/endpoints/citrus-http/src/main/java/org/citrusframework/http/client/HttpResponseErrorHandler.java +++ b/endpoints/citrus-http/src/main/java/org/citrusframework/http/client/HttpResponseErrorHandler.java @@ -16,13 +16,17 @@ package org.citrusframework.http.client; -import java.io.IOException; - import org.citrusframework.exceptions.CitrusRuntimeException; import org.citrusframework.message.ErrorHandlingStrategy; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatusCode; import org.springframework.http.client.ClientHttpResponse; +import org.springframework.lang.Nullable; import org.springframework.web.client.DefaultResponseErrorHandler; +import java.io.IOException; +import java.net.URI; + /** * @since 2.7 */ @@ -32,17 +36,15 @@ public class HttpResponseErrorHandler extends DefaultResponseErrorHandler { /** * Default constructor using error handling strategy. - * @param errorHandlingStrategy */ public HttpResponseErrorHandler(ErrorHandlingStrategy errorHandlingStrategy) { this.errorHandlingStrategy = errorHandlingStrategy; } @Override - public void handleError(ClientHttpResponse response) throws IOException { + protected void handleError(ClientHttpResponse response, HttpStatusCode statusCode, @Nullable URI url, @Nullable HttpMethod method) throws IOException { if (errorHandlingStrategy.equals(ErrorHandlingStrategy.PROPAGATE)) { - throw new HttpErrorPropagatingException(response.getStatusCode(), response.getStatusText(), - response.getHeaders(), getResponseBody(response), getCharset(response)); + throw new HttpErrorPropagatingException(response.getStatusCode(), response.getStatusText(), response.getHeaders(), getResponseBody(response), getCharset(response)); } else if (errorHandlingStrategy.equals(ErrorHandlingStrategy.THROWS_EXCEPTION)) { super.handleError(response); } else { diff --git a/endpoints/citrus-http/src/test/java/org/citrusframework/http/server/HttpServerTest.java b/endpoints/citrus-http/src/test/java/org/citrusframework/http/server/HttpServerTest.java index 2edf9b11f2..ae420b1800 100644 --- a/endpoints/citrus-http/src/test/java/org/citrusframework/http/server/HttpServerTest.java +++ b/endpoints/citrus-http/src/test/java/org/citrusframework/http/server/HttpServerTest.java @@ -16,8 +16,7 @@ package org.citrusframework.http.server; -import java.util.Random; - +import org.apache.hc.core5.http.ContentType; import org.citrusframework.context.SpringBeanReferenceResolver; import org.citrusframework.context.TestContext; import org.citrusframework.endpoint.EndpointAdapter; @@ -29,7 +28,6 @@ import org.citrusframework.message.MessageHeaders; import org.citrusframework.testng.AbstractTestNGUnitTest; import org.citrusframework.util.SocketUtils; -import org.apache.hc.core5.http.ContentType; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; @@ -39,10 +37,16 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import java.util.Random; + +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; +import static org.testng.Assert.fail; /** * Simple unit test for HttpServer @@ -79,7 +83,7 @@ public void shutdown() { try { client.send(new HttpMessage().method(HttpMethod.GET), context); - Assert.fail("Server supposed to be in shutdown state, but was accessible via client request"); + fail("Server supposed to be in shutdown state, but was accessible via client request"); } catch (ResourceAccessException e) { Assert.assertTrue(e.getMessage().contains("Connection refused")); } @@ -224,4 +228,26 @@ public void testCustomContentType() { verify(mockResponseEndpointAdapter).handleMessage(any(Message.class)); } + @Test + public void testHttpResponseErrorHandlerWithPropagateStrategy() { + TestContext context = testContextFactory.getObject(); + + reset(mockResponseEndpointAdapter); + doReturn(new HttpMessage().status(INTERNAL_SERVER_ERROR)) + .when(mockResponseEndpointAdapter).handleMessage(any(Message.class)); + + client.send(new HttpMessage() + .path("/hello") + .method(HttpMethod.GET), context); + + Message response = client.receive(context); + + assertThat(response) + .isInstanceOf(HttpMessage.class) + .satisfies( + r -> assertThat(((HttpMessage) r).getStatusCode()).isEqualTo(INTERNAL_SERVER_ERROR) + ); + + verify(mockResponseEndpointAdapter).handleMessage(any(Message.class)); + } } diff --git a/pom.xml b/pom.xml index b2f765442c..e947c96a9c 100644 --- a/pom.xml +++ b/pom.xml @@ -195,13 +195,13 @@ 1.8.0 3.26.3 4.2.2 - 2.27.19 - 1.78.1 - 1.15.7 + 2.29.21 + 1.79 + 1.15.10 2.12.0 1.9.0 1.17.1 - 2.17.0 + 2.18.0 3.17.0 1.3.4 3.11.1 @@ -209,12 +209,12 @@ 3.4.0 4.2.28 1.2.0 - 3.0.22 - 2.1.0 + 3.0.23 + 2.1.1 3.0 4.13.0 5.4.1 - 2.7.3 + 2.7.4 2.18.1 2.1.3 2.0.1 @@ -233,7 +233,7 @@ 2.0.0 0.1.55 2.9.0 - 1.5.2 + 1.5.4 2.5.1 r938 5.11.3 @@ -242,7 +242,7 @@ 2.10.1 6.13.4 6.13.4 - 3.8.0 + 3.9.0 6.13.4 2.22.1 5.14.2 @@ -250,20 +250,20 @@ 4.1.105.Final 4.12.0 4.7.6 - 42.7.3 + 42.7.4 3.0.4 - 4.25.0 + 4.27.0 2.0.11 1.1.10.7 2.3 - 6.1.14 + 6.2.0 4.0.11 - 6.3.5 - 3.0.2 + 6.4.0 + 3.0.3 2.14.0 1.6.9 2.1.22 - 1.20.1 + 1.20.4 7.10.2 4.5.10 1.6.3 @@ -271,7 +271,7 @@ 5.2.1 2.6.0 2.12.2 - 1.4.20 + 1.4.21 3.9.3 false