diff --git a/pom.xml b/pom.xml index 861c7eb..aec7f9e 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,115 +39,164 @@ 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-atos.net:8443/repository + + + + + maven-snapshots + ${nexus.url}/maven-snapshots/ + + + maven-releases + ${nexus.url}/maven-releases/ + + + - + - + - + org.apache.maven.plugins maven-compiler-plugin - 1.8 - 1.8 + 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 - - - - - - - + - + + + + repos + + true + + + + maven-public + + true + + + true + + ${nexus.url}/maven-public/ + default + + + + + - + - + org.springframework.boot spring-boot-dependencies - 2.2.4.RELEASE + 3.2.6 pom import - + com.github.tomakehurst wiremock - 2.26.0 + 2.27.2 + + + org.openrewrite.recipe + rewrite-recipe-bom + 2.11.1 + pom + import + + - + - + - + org.springframework.boot spring-boot - + org.springframework spring-web - + org.springframework.boot spring-boot-starter-test test - + com.github.tomakehurst wiremock test - + 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);