From 7e9c5b0dff43f234b49c204a23adc8c4ae741a3a Mon Sep 17 00:00:00 2001 From: A423630 Date: Thu, 13 Jun 2024 17:38:18 +0200 Subject: [PATCH 1/3] Enable openJDK17 compatibility --- pom.xml | 55 +++++++++++++++++-- .../DefaultLogFormatter.java | 4 +- .../DefaultLogFormatterTest.java | 8 +-- .../LoggingCustomizerIT.java | 18 +++--- .../LoggingCustomizerTest.java | 14 ++--- .../LoggingInterceptorTest.java | 12 ++-- 6 files changed, 77 insertions(+), 34 deletions(-) diff --git a/pom.xml b/pom.xml index 861c7eb..29efe20 100644 --- a/pom.xml +++ b/pom.xml @@ -63,6 +63,11 @@ + + 17 + 17 + true + @@ -73,8 +78,7 @@ org.apache.maven.plugins maven-compiler-plugin - 1.8 - 1.8 + 17 @@ -96,7 +100,37 @@ - + + org.openrewrite.maven + rewrite-maven-plugin + 5.32.1 + + + org.openrewrite.java.migrate.UpgradeToJava17 + org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_2 + org.openrewrite.java.spring.boot2.SpringBoot2JUnit4to5Migration + org.openrewrite.hibernate.MigrateToHibernate63 + org.openrewrite.hibernate.TypeAnnotationParameter + + + + + org.openrewrite.recipe + rewrite-migrate-java + 2.16.0 + + + org.openrewrite.recipe + rewrite-spring + 5.11.0 + + + org.openrewrite.recipe + rewrite-hibernate + 1.5.1 + + + @@ -108,7 +142,7 @@ org.springframework.boot spring-boot-dependencies - 2.2.4.RELEASE + 3.2.6 pom import @@ -116,9 +150,18 @@ com.github.tomakehurst wiremock - 2.26.0 + 2.27.2 + + + org.openrewrite.recipe + rewrite-recipe-bom + 2.11.1 + pom + import + + @@ -148,6 +191,6 @@ - + diff --git a/src/main/java/org/hobsoft/spring/resttemplatelogger/DefaultLogFormatter.java b/src/main/java/org/hobsoft/spring/resttemplatelogger/DefaultLogFormatter.java index 7722011..e0a712b 100644 --- a/src/main/java/org/hobsoft/spring/resttemplatelogger/DefaultLogFormatter.java +++ b/src/main/java/org/hobsoft/spring/resttemplatelogger/DefaultLogFormatter.java @@ -46,7 +46,7 @@ public String formatRequest(HttpRequest request, byte[] body) { String formattedBody = formatBody(body, getCharset(request)); - return String.format("Request: %s %s %s", request.getMethod(), request.getURI(), formattedBody); + return "Request: %s %s %s".formatted(request.getMethod(), request.getURI(), formattedBody); } @Override @@ -54,7 +54,7 @@ public String formatResponse(ClientHttpResponse response) throws IOException { String formattedBody = formatBody(copyToByteArray(response.getBody()), getCharset(response)); - return String.format("Response: %s %s", response.getStatusCode().value(), formattedBody); + return "Response: %s %s".formatted(response.getStatusCode().value(), formattedBody); } // ---------------------------------------------------------------------------------------------------------------- diff --git a/src/test/java/org/hobsoft/spring/resttemplatelogger/DefaultLogFormatterTest.java b/src/test/java/org/hobsoft/spring/resttemplatelogger/DefaultLogFormatterTest.java index 672ca58..23c5be8 100644 --- a/src/test/java/org/hobsoft/spring/resttemplatelogger/DefaultLogFormatterTest.java +++ b/src/test/java/org/hobsoft/spring/resttemplatelogger/DefaultLogFormatterTest.java @@ -16,16 +16,16 @@ import java.io.IOException; import java.net.URI; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.mock.http.client.MockClientHttpRequest; import org.springframework.mock.http.client.MockClientHttpResponse; import static java.nio.charset.StandardCharsets.ISO_8859_1; import static java.nio.charset.StandardCharsets.UTF_8; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; import static org.springframework.http.HttpMethod.POST; import static org.springframework.http.HttpStatus.OK; import static org.springframework.http.MediaType.parseMediaType; @@ -45,7 +45,7 @@ public class DefaultLogFormatterTest // JUnit methods // ---------------------------------------------------------------------------------------------------------------- - @Before + @BeforeEach public void setUp() { formatter = new DefaultLogFormatter(); diff --git a/src/test/java/org/hobsoft/spring/resttemplatelogger/LoggingCustomizerIT.java b/src/test/java/org/hobsoft/spring/resttemplatelogger/LoggingCustomizerIT.java index 5648fb4..dcbb79e 100644 --- a/src/test/java/org/hobsoft/spring/resttemplatelogger/LoggingCustomizerIT.java +++ b/src/test/java/org/hobsoft/spring/resttemplatelogger/LoggingCustomizerIT.java @@ -14,20 +14,20 @@ package org.hobsoft.spring.resttemplatelogger; import org.apache.commons.logging.Log; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.http.ResponseEntity; import org.springframework.web.client.RestTemplate; -import com.github.tomakehurst.wiremock.junit.WireMockRule; +import com.github.tomakehurst.wiremock.junit5.WireMockExtension; import static java.net.HttpURLConnection.HTTP_OK; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -49,8 +49,8 @@ public class LoggingCustomizerIT // fields // ---------------------------------------------------------------------------------------------------------------- - @Rule - public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort()); + @RegisterExtension + private WireMockExtension wireMockRule = WireMockExtension.newInstance().options(options().dynamicPort()).build(); private Log log; @@ -60,7 +60,7 @@ public class LoggingCustomizerIT // JUnit methods // ---------------------------------------------------------------------------------------------------------------- - @Before + @BeforeEach public void setUp() { log = mock(Log.class); @@ -84,7 +84,7 @@ public void canLogRequest() restTemplate.postForEntity("/hello", "world", String.class); - verify(log).debug(String.format("Request: POST http://localhost:%d/hello world", wireMockRule.port())); + verify(log).debug("Request: POST http://localhost:%d/hello world".formatted(wireMockRule.port())); } @Test diff --git a/src/test/java/org/hobsoft/spring/resttemplatelogger/LoggingCustomizerTest.java b/src/test/java/org/hobsoft/spring/resttemplatelogger/LoggingCustomizerTest.java index 5e01f31..9209a2e 100644 --- a/src/test/java/org/hobsoft/spring/resttemplatelogger/LoggingCustomizerTest.java +++ b/src/test/java/org/hobsoft/spring/resttemplatelogger/LoggingCustomizerTest.java @@ -18,11 +18,11 @@ import java.net.URI; import org.apache.commons.logging.Log; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.http.client.ClientHttpRequestFactory; import org.springframework.http.client.ClientHttpResponse; import org.springframework.mock.http.client.MockClientHttpRequest; @@ -31,8 +31,8 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; -import static org.junit.Assert.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.springframework.http.HttpMethod.GET; @@ -42,7 +42,7 @@ /** * Tests {@code LoggingCustomizer}. */ -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class LoggingCustomizerTest { // ---------------------------------------------------------------------------------------------------------------- @@ -60,7 +60,7 @@ public class LoggingCustomizerTest // JUnit methods // ---------------------------------------------------------------------------------------------------------------- - @Before + @BeforeEach public void setUp() { Log log = mock(Log.class); diff --git a/src/test/java/org/hobsoft/spring/resttemplatelogger/LoggingInterceptorTest.java b/src/test/java/org/hobsoft/spring/resttemplatelogger/LoggingInterceptorTest.java index 44d733f..e9dca43 100644 --- a/src/test/java/org/hobsoft/spring/resttemplatelogger/LoggingInterceptorTest.java +++ b/src/test/java/org/hobsoft/spring/resttemplatelogger/LoggingInterceptorTest.java @@ -16,11 +16,11 @@ import java.io.IOException; import org.apache.commons.logging.Log; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.http.client.ClientHttpRequestExecution; import org.springframework.http.client.ClientHttpResponse; import org.springframework.mock.http.client.MockClientHttpRequest; @@ -32,7 +32,7 @@ /** * Tests {@code LoggingInterceptor}. */ -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class LoggingInterceptorTest { // ---------------------------------------------------------------------------------------------------------------- @@ -54,7 +54,7 @@ public class LoggingInterceptorTest // JUnit methods // ---------------------------------------------------------------------------------------------------------------- - @Before + @BeforeEach public void setUp() { when(log.isDebugEnabled()).thenReturn(true); From b51636dda2db45d4af884bfae6110ce6c7370fc8 Mon Sep 17 00:00:00 2001 From: A423630 Date: Thu, 13 Jun 2024 17:46:22 +0200 Subject: [PATCH 2/3] Add nexus reference and customized version --- pom.xml | 92 +++++++++++++++++++++++++-------------------------------- 1 file changed, 41 insertions(+), 51 deletions(-) diff --git a/pom.xml b/pom.xml index 29efe20..4395f3d 100644 --- a/pom.xml +++ b/pom.xml @@ -13,24 +13,25 @@ See the License for the specific language governing permissions and limitations under the License. --> - + org.hobsoft hobsoft-parent 0.4.2 - + 4.0.0 org.hobsoft.spring spring-rest-template-logger - 2.0.1-SNAPSHOT - + 2.0.1.GEMMA + Spring RestTemplate Logger Spring RestTemplate customizer to log HTTP traffic. https://github.com/markhobson/rest-template-logger 2017 - + The Apache Software License, Version 2.0 @@ -38,42 +39,31 @@ repo - - - scm:git:git@github.com:markhobson/rest-template-logger.git - scm:git:git@github.com:markhobson/rest-template-logger.git - https://github.com/markhobson/rest-template-logger - HEAD - - - - GitHub - https://github.com/markhobson/rest-template-logger/issues - - - - - markhobson - Mark Hobson - markhobson@gmail.com - - Project Lead - - 0 - - - + 17 17 true + https://nexus.gemma-eviden.com:8443/repository + + + + maven-snapshots + ${nexus.url}/maven-snapshots/ + + + maven-releases + ${nexus.url}/maven-releases/ + + + - + - + - + org.apache.maven.plugins maven-compiler-plugin @@ -81,13 +71,13 @@ 17 - + - + - + - + org.apache.maven.plugins maven-failsafe-plugin @@ -130,15 +120,15 @@ 1.5.1 - + - + - + - + - + org.springframework.boot spring-boot-dependencies @@ -146,7 +136,7 @@ pom import - + com.github.tomakehurst wiremock @@ -163,34 +153,34 @@ - + - + - + org.springframework.boot spring-boot - + org.springframework spring-web - + org.springframework.boot spring-boot-starter-test test - + com.github.tomakehurst wiremock test - + - + From ff5864bd80daa92292bbde1a7e2b0f27efb17488 Mon Sep 17 00:00:00 2001 From: A423630 Date: Thu, 13 Jun 2024 18:13:53 +0200 Subject: [PATCH 3/3] Fixed some pom insistencies --- pom.xml | 117 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 67 insertions(+), 50 deletions(-) diff --git a/pom.xml b/pom.xml index 4395f3d..aec7f9e 100644 --- a/pom.xml +++ b/pom.xml @@ -44,7 +44,7 @@ 17 17 true - https://nexus.gemma-eviden.com:8443/repository + https://nexus.gemma-atos.net:8443/repository @@ -71,60 +71,77 @@ 17 - + + org.apache.maven.plugins + maven-failsafe-plugin + + + + integration-test + verify + + + + + + org.openrewrite.maven + rewrite-maven-plugin + 5.32.1 + + + org.openrewrite.java.migrate.UpgradeToJava17 + org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_2 + org.openrewrite.java.spring.boot2.SpringBoot2JUnit4to5Migration + org.openrewrite.hibernate.MigrateToHibernate63 + org.openrewrite.hibernate.TypeAnnotationParameter + + + + + org.openrewrite.recipe + rewrite-migrate-java + 2.16.0 + + + org.openrewrite.recipe + rewrite-spring + 5.11.0 + + + org.openrewrite.recipe + rewrite-hibernate + 1.5.1 + + + + - - - - - org.apache.maven.plugins - maven-failsafe-plugin - - - - integration-test - verify - - - - - - org.openrewrite.maven - rewrite-maven-plugin - 5.32.1 - - - org.openrewrite.java.migrate.UpgradeToJava17 - org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_2 - org.openrewrite.java.spring.boot2.SpringBoot2JUnit4to5Migration - org.openrewrite.hibernate.MigrateToHibernate63 - org.openrewrite.hibernate.TypeAnnotationParameter - - - - - org.openrewrite.recipe - rewrite-migrate-java - 2.16.0 - - - org.openrewrite.recipe - rewrite-spring - 5.11.0 - - - org.openrewrite.recipe - rewrite-hibernate - 1.5.1 - - - - - + + + repos + + true + + + + maven-public + + true + + + true + + ${nexus.url}/maven-public/ + default + + + + +