diff --git a/apache-httpclient/pom.xml b/apache-httpclient/pom.xml index 3b178d4df8..f671c93cfc 100644 --- a/apache-httpclient/pom.xml +++ b/apache-httpclient/pom.xml @@ -63,11 +63,6 @@ ${wiremock.version} test - - org.apache.httpcomponents - httpclient - ${httpclient.version} - @@ -84,10 +79,9 @@ 5.6.1 3.3.1 - 5.2 - 5.2 - 5.2 - 4.5.14 + 5.2.2 + 5.2.2 + 5.2.2 diff --git a/apache-httpclient/src/test/java/com/baeldung/httpclient/HttpAsyncClientLiveTest.java b/apache-httpclient/src/test/java/com/baeldung/httpclient/HttpAsyncClientLiveTest.java index 50cf1b7a64..7b818f871a 100644 --- a/apache-httpclient/src/test/java/com/baeldung/httpclient/HttpAsyncClientLiveTest.java +++ b/apache-httpclient/src/test/java/com/baeldung/httpclient/HttpAsyncClientLiveTest.java @@ -25,6 +25,7 @@ import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManagerBu import org.apache.hc.client5.http.impl.routing.DefaultProxyRoutePlanner; import org.apache.hc.client5.http.protocol.HttpClientContext; import org.apache.hc.client5.http.ssl.ClientTlsStrategyBuilder; +import org.apache.hc.client5.http.ssl.NoopHostnameVerifier; import org.apache.hc.core5.http.HttpHost; import org.apache.hc.core5.http.HttpResponse; import org.apache.hc.core5.http.nio.ssl.TlsStrategy; @@ -33,7 +34,6 @@ import org.apache.hc.core5.http.protocol.HttpContext; import org.apache.hc.core5.reactor.IOReactorConfig; import org.apache.hc.core5.ssl.SSLContexts; import org.apache.hc.core5.ssl.TrustStrategy; -import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.junit.jupiter.api.Test; @@ -120,7 +120,7 @@ class HttpAsyncClientLiveTest extends GetRequestMockServer { .build(); final TlsStrategy tlsStrategy = ClientTlsStrategyBuilder.create() - .setHostnameVerifier(SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER) + .setHostnameVerifier(NoopHostnameVerifier.INSTANCE) .setSslContext(sslContext) .build(); diff --git a/apache-kafka-2/pom.xml b/apache-kafka-2/pom.xml index cd21a60e14..dedd5df602 100644 --- a/apache-kafka-2/pom.xml +++ b/apache-kafka-2/pom.xml @@ -55,7 +55,7 @@ com.fasterxml.jackson.core jackson-databind - ${jackson.databind.version} + ${jackson.databind.version} diff --git a/apache-kafka/pom.xml b/apache-kafka/pom.xml index 22be7a83c6..6aa5fb894a 100644 --- a/apache-kafka/pom.xml +++ b/apache-kafka/pom.xml @@ -181,6 +181,7 @@ + 2.13.4 3.4.0 1.19.3 1.15.3 diff --git a/apache-kafka/src/test/java/com/baeldung/flink/BackupCreatorIntegrationTest.java b/apache-kafka/src/test/java/com/baeldung/flink/BackupCreatorUnitTest.java similarity index 99% rename from apache-kafka/src/test/java/com/baeldung/flink/BackupCreatorIntegrationTest.java rename to apache-kafka/src/test/java/com/baeldung/flink/BackupCreatorUnitTest.java index f46fffbb59..046a9bb9ec 100644 --- a/apache-kafka/src/test/java/com/baeldung/flink/BackupCreatorIntegrationTest.java +++ b/apache-kafka/src/test/java/com/baeldung/flink/BackupCreatorUnitTest.java @@ -29,7 +29,7 @@ import java.util.List; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; -public class BackupCreatorIntegrationTest { +public class BackupCreatorUnitTest { public static ObjectMapper mapper; @Before diff --git a/apache-kafka/src/test/java/com/baeldung/flink/WordCapitalizerIntegrationTest.java b/apache-kafka/src/test/java/com/baeldung/flink/WordCapitalizerUnitTest.java similarity index 95% rename from apache-kafka/src/test/java/com/baeldung/flink/WordCapitalizerIntegrationTest.java rename to apache-kafka/src/test/java/com/baeldung/flink/WordCapitalizerUnitTest.java index 8a98dae4b5..c521cfa62e 100644 --- a/apache-kafka/src/test/java/com/baeldung/flink/WordCapitalizerIntegrationTest.java +++ b/apache-kafka/src/test/java/com/baeldung/flink/WordCapitalizerUnitTest.java @@ -10,7 +10,7 @@ import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; -public class WordCapitalizerIntegrationTest { +public class WordCapitalizerUnitTest { @Test public void givenDataSet_whenExecuteWordCapitalizer_thenReturnCapitalizedWords() throws Exception { diff --git a/apache-kafka/src/test/java/com/baeldung/kafkastreams/KafkaStreamsLiveTest.java b/apache-kafka/src/test/java/com/baeldung/kafkastreams/KafkaStreamsLiveTest.java index 3b559b619e..c733a4a1f4 100644 --- a/apache-kafka/src/test/java/com/baeldung/kafkastreams/KafkaStreamsLiveTest.java +++ b/apache-kafka/src/test/java/com/baeldung/kafkastreams/KafkaStreamsLiveTest.java @@ -21,8 +21,7 @@ import org.junit.Ignore; import org.junit.Test; public class KafkaStreamsLiveTest { - private String bootstrapServers = "localhost:9092"; - private Path stateDirectory; + private final String bootstrapServers = "localhost:9092"; @Test @Ignore("it needs to have kafka broker running on local") @@ -44,8 +43,8 @@ public class KafkaStreamsLiveTest { // Use a temporary directory for storing state, which will be automatically removed after the test. try { - this.stateDirectory = Files.createTempDirectory("kafka-streams"); - streamsConfiguration.put(StreamsConfig.STATE_DIR_CONFIG, this.stateDirectory.toAbsolutePath() + Path stateDirectory = Files.createTempDirectory("kafka-streams"); + streamsConfiguration.put(StreamsConfig.STATE_DIR_CONFIG, stateDirectory.toAbsolutePath() .toString()); } catch (final IOException e) { throw new UncheckedIOException("Cannot create temporary directory", e); diff --git a/asm/README.md b/asm/README.md deleted file mode 100644 index e10cdc45bd..0000000000 --- a/asm/README.md +++ /dev/null @@ -1,7 +0,0 @@ -## ASM - -This module contains articles about ASM - -### Relevant Articles: - -- [A Guide to Java Bytecode Manipulation with ASM](https://www.baeldung.com/java-asm) diff --git a/asm/pom.xml b/asm/pom.xml deleted file mode 100644 index 4edfe86ae5..0000000000 --- a/asm/pom.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - 4.0.0 - com.baeldung.examples - asm - 1.0 - asm - jar - - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - - - - - org.ow2.asm - asm - ${asm.version} - - - org.ow2.asm - asm-util - ${asm.version} - - - - - - - org.apache.maven.plugins - maven-jar-plugin - ${maven-jar-plugin.version} - - - - - com.baeldung.examples.asm.instrumentation.Premain - - - - - - - - - - 5.2 - - - \ No newline at end of file diff --git a/aws-modules/aws-dynamodb/pom.xml b/aws-modules/aws-dynamodb/pom.xml index adce036733..199b9a187e 100644 --- a/aws-modules/aws-dynamodb/pom.xml +++ b/aws-modules/aws-dynamodb/pom.xml @@ -1,7 +1,7 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 aws-dynamodb 0.1.0-SNAPSHOT @@ -40,22 +40,6 @@ - - org.apache.maven.plugins - maven-shade-plugin - ${maven-shade-plugin.version} - - false - - - - package - - shade - - - - org.apache.maven.plugins maven-dependency-plugin diff --git a/aws-modules/aws-miscellaneous/pom.xml b/aws-modules/aws-miscellaneous/pom.xml index b6326b6eb1..f04e84e14f 100644 --- a/aws-modules/aws-miscellaneous/pom.xml +++ b/aws-modules/aws-miscellaneous/pom.xml @@ -34,22 +34,6 @@ - - org.apache.maven.plugins - maven-shade-plugin - ${maven-shade-plugin.version} - - false - - - - package - - shade - - - - org.apache.maven.plugins maven-dependency-plugin diff --git a/aws-modules/aws-reactive/pom.xml b/aws-modules/aws-reactive/pom.xml index e6b50cadb2..965ce8fdcf 100644 --- a/aws-modules/aws-reactive/pom.xml +++ b/aws-modules/aws-reactive/pom.xml @@ -63,6 +63,7 @@ io.projectreactor reactor-test + ${reactor.version} test @@ -94,6 +95,7 @@ 2.2.1.RELEASE 2.17.283 1.18.20 + 3.6.0 \ No newline at end of file diff --git a/aws-modules/aws-s3/pom.xml b/aws-modules/aws-s3/pom.xml index e2bc04964a..9ba436b43f 100644 --- a/aws-modules/aws-s3/pom.xml +++ b/aws-modules/aws-s3/pom.xml @@ -39,27 +39,6 @@ - - - - org.apache.maven.plugins - maven-shade-plugin - ${maven-shade-plugin.version} - - false - - - - package - - shade - - - - - - - 2.20.52 1.10.L001 diff --git a/aws-modules/pom.xml b/aws-modules/pom.xml index 06cea2f260..ce27a4f2e0 100644 --- a/aws-modules/pom.xml +++ b/aws-modules/pom.xml @@ -5,6 +5,13 @@ 4.0.0 aws-modules aws-modules + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + com.amazonaws @@ -15,12 +22,6 @@ pom - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - - aws-app-sync aws-dynamodb diff --git a/core-groovy-modules/core-groovy-2/gmavenplus-pom.xml b/core-groovy-modules/core-groovy-2/gmavenplus-pom.xml index 975ad6f689..256b5e88ab 100644 --- a/core-groovy-modules/core-groovy-2/gmavenplus-pom.xml +++ b/core-groovy-modules/core-groovy-2/gmavenplus-pom.xml @@ -167,7 +167,6 @@ UTF-8 3.9 - 1.8 1.2.3 diff --git a/core-groovy-modules/core-groovy-2/pom.xml b/core-groovy-modules/core-groovy-2/pom.xml index de750daf0f..cc1d860ad1 100644 --- a/core-groovy-modules/core-groovy-2/pom.xml +++ b/core-groovy-modules/core-groovy-2/pom.xml @@ -13,6 +13,13 @@ 1.0.0-SNAPSHOT + + + groovy-plugins-release + https://groovy.jfrog.io/artifactory/plugins-release-local + + + org.apache.commons @@ -156,8 +163,8 @@ 1.1.3 3.4.2 3.8.1 - 3.7.0 - 3.0.8-01 + 3.9.0 + 3.0.9-03 diff --git a/core-java-modules/core-java-11-3/pom.xml b/core-java-modules/core-java-11-3/pom.xml index 22db9e62ab..0161f4dcca 100644 --- a/core-java-modules/core-java-11-3/pom.xml +++ b/core-java-modules/core-java-11-3/pom.xml @@ -45,7 +45,7 @@ 11 11 - 2.14.1 + 2.16.0 2.10 diff --git a/core-java-modules/core-java-12/pom.xml b/core-java-modules/core-java-12/pom.xml index 8165549d8c..ae61bdfad0 100644 --- a/core-java-modules/core-java-12/pom.xml +++ b/core-java-modules/core-java-12/pom.xml @@ -21,8 +21,4 @@ - - 17 - - \ No newline at end of file diff --git a/core-java-modules/core-java-13/pom.xml b/core-java-modules/core-java-13/pom.xml index 52cf227583..b8ec8cfdb9 100644 --- a/core-java-modules/core-java-13/pom.xml +++ b/core-java-modules/core-java-13/pom.xml @@ -13,8 +13,4 @@ 0.0.1-SNAPSHOT - - 17 - - \ No newline at end of file diff --git a/core-java-modules/core-java-15/pom.xml b/core-java-modules/core-java-15/pom.xml index 3996c69fa4..e6193b4ea3 100644 --- a/core-java-modules/core-java-15/pom.xml +++ b/core-java-modules/core-java-15/pom.xml @@ -26,8 +26,4 @@ - - 17 - - \ No newline at end of file diff --git a/core-java-modules/core-java-20/pom.xml b/core-java-modules/core-java-20/pom.xml index ad0a956b80..68c6ca4c93 100644 --- a/core-java-modules/core-java-20/pom.xml +++ b/core-java-modules/core-java-20/pom.xml @@ -3,19 +3,34 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 + core-java-20 + com.baeldung.core-java-modules core-java-modules 0.0.1-SNAPSHOT - core-java-20 - - - 20 - 20 - UTF-8 - + + + jakarta.servlet + jakarta.servlet-api + 6.0.0 + provided + + + org.assertj + assertj-core + 3.24.2 + test + + + org.mockito + mockito-junit-jupiter + 5.2.0 + test + + @@ -41,25 +56,10 @@ - - - jakarta.servlet - jakarta.servlet-api - 6.0.0 - provided - - - org.assertj - assertj-core - 3.24.2 - test - - - org.mockito - mockito-junit-jupiter - 5.2.0 - test - - + + 20 + 20 + UTF-8 + \ No newline at end of file diff --git a/core-java-modules/core-java-arrays-convert/README.md b/core-java-modules/core-java-arrays-convert/README.md index 2e34829525..118d8e00ed 100644 --- a/core-java-modules/core-java-arrays-convert/README.md +++ b/core-java-modules/core-java-arrays-convert/README.md @@ -11,3 +11,4 @@ This module contains articles about arrays conversion in Java - [Converting an int[] to HashSet in Java](https://www.baeldung.com/java-converting-int-array-to-hashset) - [Convert an ArrayList of String to a String Array in Java](https://www.baeldung.com/java-convert-string-arraylist-array) - [Convert Char Array to Int Array in Java](https://www.baeldung.com/java-convert-char-int-array) +- [How to Convert Byte Array to Char Array](https://www.baeldung.com/java-convert-byte-array-char) diff --git a/core-java-modules/core-java-arrays-operations-advanced/pom.xml b/core-java-modules/core-java-arrays-operations-advanced/pom.xml index 52787cc0c9..265577f75e 100644 --- a/core-java-modules/core-java-arrays-operations-advanced/pom.xml +++ b/core-java-modules/core-java-arrays-operations-advanced/pom.xml @@ -57,7 +57,7 @@ - + 11 diff --git a/core-java-modules/core-java-collections-conversions-2/pom.xml b/core-java-modules/core-java-collections-conversions-2/pom.xml index da6b6a564a..7723daa6db 100644 --- a/core-java-modules/core-java-collections-conversions-2/pom.xml +++ b/core-java-modules/core-java-collections-conversions-2/pom.xml @@ -43,7 +43,6 @@ 0.10.3 - 11 3.2.0 \ No newline at end of file diff --git a/core-java-modules/core-java-collections-list-5/pom.xml b/core-java-modules/core-java-collections-list-5/pom.xml index b8832df357..c11781eeda 100644 --- a/core-java-modules/core-java-collections-list-5/pom.xml +++ b/core-java-modules/core-java-collections-list-5/pom.xml @@ -39,7 +39,7 @@ org.projectlombok lombok - 1.18.26 + ${lombok.version} provided @@ -67,7 +67,7 @@ 1.21 2.2 2.10.1 - 2.15.2 + 2.16.0 20230618 \ No newline at end of file diff --git a/core-java-modules/core-java-collections-maps-6/pom.xml b/core-java-modules/core-java-collections-maps-6/pom.xml index 0d1732edb4..a0cdc07644 100644 --- a/core-java-modules/core-java-collections-maps-6/pom.xml +++ b/core-java-modules/core-java-collections-maps-6/pom.xml @@ -13,14 +13,11 @@ 0.0.1-SNAPSHOT - - 5.2.5.RELEASE - com.fasterxml.jackson.core jackson-databind - 2.13.1 + 2.16.0 org.openjdk.jmh @@ -51,4 +48,8 @@ + + 5.2.5.RELEASE + + \ No newline at end of file diff --git a/core-java-modules/core-java-collections-maps-7/README.md b/core-java-modules/core-java-collections-maps-7/README.md index c9f39dd2fa..73b36394a3 100644 --- a/core-java-modules/core-java-collections-maps-7/README.md +++ b/core-java-modules/core-java-collections-maps-7/README.md @@ -4,5 +4,7 @@ - [How to Write Hashmap to CSV File](https://www.baeldung.com/java-write-hashmap-csv) - [How to Get First or Last Entry From a LinkedHashMap in Java](https://www.baeldung.com/java-linkedhashmap-first-last-key-value-pair) - [How to Write and Read a File with a Java HashMap](https://www.baeldung.com/java-hashmap-write-read-file) -- [Limiting the Max Size of a HashMap in Java](https://www.baeldung.com/java-hashmap-max-size) -- More articles: [[<-- prev]](/core-java-modules/core-java-collections-maps-6) \ No newline at end of file +- [Limiting the Max Size of a HashMap in Java](https://www.baeldung.com/java-hashmap-size-bound) +- [How to Sort LinkedHashMap By Values in Java](https://www.baeldung.com/java-sort-linkedhashmap-using-values) +- [How to Increment a Map Value in Java](https://www.baeldung.com/java-increment-map-value) +- More articles: [[<-- prev]](/core-java-modules/core-java-collections-maps-6) diff --git a/core-java-modules/core-java-collections-maps-7/pom.xml b/core-java-modules/core-java-collections-maps-7/pom.xml index 2d08c0a438..bd355bea1e 100644 --- a/core-java-modules/core-java-collections-maps-7/pom.xml +++ b/core-java-modules/core-java-collections-maps-7/pom.xml @@ -1,15 +1,11 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 core-java-collections-maps-7 core-java-collections-maps-7 jar - - 2.10.1 - 1.5 - core-java-modules @@ -63,4 +59,10 @@ + + + 2.10.1 + 1.5 + + diff --git a/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/completablefuture/CompletableFutureUnitTest.java b/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/completablefuture/CompletableFutureUnitTest.java new file mode 100644 index 0000000000..5953c6d87a --- /dev/null +++ b/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/completablefuture/CompletableFutureUnitTest.java @@ -0,0 +1,150 @@ +package com.baeldung.concurrent.completablefuture; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionException; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Executor; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import java.util.stream.Collectors; + +import org.junit.Test; + +public class CompletableFutureUnitTest { + + @Test + public void givenAsyncTask_whenProcessingAsyncSucceed_thenReturnSuccess() throws ExecutionException, InterruptedException { + Microservice mockMicroserviceA = mock(Microservice.class); + Microservice mockMicroserviceB = mock(Microservice.class); + + when(mockMicroserviceA.retrieveAsync(any())).thenReturn(CompletableFuture.completedFuture("Hello")); + when(mockMicroserviceB.retrieveAsync(any())).thenReturn(CompletableFuture.completedFuture("World")); + + CompletableFuture resultFuture = processAsync(List.of(mockMicroserviceA, mockMicroserviceB)); + + String result = resultFuture.get(); + assertEquals("HelloWorld", result); + } + + @Test + public void givenAsyncTask_whenProcessingAsyncWithException_thenReturnException() throws ExecutionException, InterruptedException { + Microservice mockMicroserviceA = mock(Microservice.class); + Microservice mockMicroserviceB = mock(Microservice.class); + + when(mockMicroserviceA.retrieveAsync(any())).thenReturn(CompletableFuture.completedFuture("Hello")); + when(mockMicroserviceB.retrieveAsync(any())).thenReturn(CompletableFuture.failedFuture(new RuntimeException("Simulated Exception"))); + CompletableFuture resultFuture = processAsync(List.of(mockMicroserviceA, mockMicroserviceB)); + // Use assertThrows to verify that the expected exception is thrown + ExecutionException exception = assertThrows(ExecutionException.class, resultFuture::get); + // Assert the exception message + assertEquals("Simulated Exception", exception.getCause() + .getMessage()); + } + + @Test + public void givenAsyncTask_whenProcessingAsyncWithTimeout_thenHandleTimeoutException() throws ExecutionException, InterruptedException { + Microservice mockMicroserviceA = mock(Microservice.class); + Microservice mockMicroserviceB = mock(Microservice.class); + Executor delayedExecutor = CompletableFuture.delayedExecutor(200, TimeUnit.MILLISECONDS); + when(mockMicroserviceA.retrieveAsync(any())).thenReturn(CompletableFuture.supplyAsync(() -> "Hello", delayedExecutor)); + Executor delayedExecutor2 = CompletableFuture.delayedExecutor(500, TimeUnit.MILLISECONDS); + when(mockMicroserviceB.retrieveAsync(any())).thenReturn(CompletableFuture.supplyAsync(() -> "World", delayedExecutor2)); + CompletableFuture resultFuture = processAsync(List.of(mockMicroserviceA, mockMicroserviceB)); + assertThrows(TimeoutException.class, () -> resultFuture.get(300, TimeUnit.MILLISECONDS)); + } + + @Test + public void givenCompletableFuture_whenCompleted_thenStateIsDone() { + Executor delayedExecutor = CompletableFuture.delayedExecutor(200, TimeUnit.MILLISECONDS); + CompletableFuture cf1 = CompletableFuture.supplyAsync(() -> "Hello", delayedExecutor); + CompletableFuture cf2 = CompletableFuture.supplyAsync(() -> " World"); + CompletableFuture cf3 = CompletableFuture.supplyAsync(() -> "!"); + CompletableFuture[] cfs = new CompletableFuture[] { cf1, cf2, cf3 }; + + CompletableFuture allCf = CompletableFuture.allOf(cfs); + + assertFalse(allCf.isDone()); + allCf.join(); + String result = Arrays.stream(cfs) + .map(CompletableFuture::join) + .collect(Collectors.joining()); + + assertFalse(allCf.isCancelled()); + assertTrue(allCf.isDone()); + assertFalse(allCf.isCompletedExceptionally()); + assertEquals(result, "Hello World!"); + } + + @Test + public void givenCompletableFuture_whenCompletedWithException_thenStateIsCompletedExceptionally() throws ExecutionException, InterruptedException { + Executor delayedExecutor = CompletableFuture.delayedExecutor(200, TimeUnit.MILLISECONDS); + CompletableFuture cf1 = CompletableFuture.supplyAsync(() -> "Hello", delayedExecutor); + CompletableFuture cf2 = CompletableFuture.failedFuture(new RuntimeException("Simulated Exception")); + CompletableFuture cf3 = CompletableFuture.supplyAsync(() -> "!"); + CompletableFuture[] cfs = new CompletableFuture[] { cf1, cf2, cf3 }; + + CompletableFuture allCf = CompletableFuture.allOf(cfs); + + assertFalse(allCf.isDone()); + assertFalse(allCf.isCompletedExceptionally()); + + // Exception is expected, assert the cause + CompletionException exception = assertThrows(CompletionException.class, allCf::join); + + assertEquals("Simulated Exception", exception.getCause() + .getMessage()); + assertTrue(allCf.isCompletedExceptionally()); + assertTrue(allCf.isDone()); + assertFalse(allCf.isCancelled()); + } + + @Test + public void givenCompletableFuture_whenCancelled_thenStateIsCancelled() throws ExecutionException, InterruptedException { + Executor delayedExecutor = CompletableFuture.delayedExecutor(200, TimeUnit.MILLISECONDS); + CompletableFuture cf1 = CompletableFuture.supplyAsync(() -> "Hello", delayedExecutor); + CompletableFuture cf2 = CompletableFuture.supplyAsync(() -> " World"); + CompletableFuture cf3 = CompletableFuture.supplyAsync(() -> "!"); + CompletableFuture[] cfs = new CompletableFuture[] { cf1, cf2, cf3 }; + CompletableFuture allCf = CompletableFuture.allOf(cfs); + assertFalse(allCf.isDone()); + assertFalse(allCf.isCompletedExceptionally()); + allCf.cancel(true); + assertTrue(allCf.isCancelled()); + assertTrue(allCf.isDone()); + } + + CompletableFuture processAsync(List microservices) { + List> dataFetchFutures = fetchDataAsync(microservices); + return combineResults(dataFetchFutures); + } + + private List> fetchDataAsync(List microservices) { + return microservices.stream() + .map(client -> client.retrieveAsync("")) + .collect(Collectors.toList()); + } + + private CompletableFuture combineResults(List> dataFetchFutures) { + return CompletableFuture.allOf(dataFetchFutures.toArray(new CompletableFuture[0])) + .thenApply(v -> dataFetchFutures.stream() + .map(future -> future.exceptionally(ex -> { + throw new CompletionException(ex); + }) + .join()) + .collect(Collectors.joining())); + } + + interface Microservice { + CompletableFuture retrieveAsync(String input); + } +} diff --git a/core-java-modules/core-java-datetime-conversion/README.md b/core-java-modules/core-java-datetime-conversion/README.md index c7ba333222..f30a21f84c 100644 --- a/core-java-modules/core-java-datetime-conversion/README.md +++ b/core-java-modules/core-java-datetime-conversion/README.md @@ -11,3 +11,4 @@ This module contains articles about converting between Java date and time object - [Conversion From 12-Hour Time to 24-Hour Time in Java](https://www.baeldung.com/java-convert-time-format) - [Convert Epoch Time to LocalDate and LocalDateTime](https://www.baeldung.com/java-convert-epoch-localdate) - [Convert Timestamp String to Long in Java](https://www.baeldung.com/java-convert-timestamp-string-long) +- [Convert Long Timestamp to LocalDateTime in Java](https://www.baeldung.com/java-convert-long-timestamp-localdatetime) diff --git a/core-java-modules/core-java-function/src/main/java/com/baeldung/lazylambda/LambdaSupplier.java b/core-java-modules/core-java-function/src/main/java/com/baeldung/lazylambda/LambdaSupplier.java new file mode 100644 index 0000000000..36cd1b31ae --- /dev/null +++ b/core-java-modules/core-java-function/src/main/java/com/baeldung/lazylambda/LambdaSupplier.java @@ -0,0 +1,16 @@ +package com.baeldung.lazylambda; + +import java.util.function.Supplier; + +public class LambdaSupplier { + + protected final Supplier expensiveData; + + public LambdaSupplier(Supplier expensiveData) { + this.expensiveData = expensiveData; + } + + public T getData() { + return expensiveData.get(); + } +} diff --git a/core-java-modules/core-java-function/src/main/java/com/baeldung/lazylambda/LazyLambdaSupplier.java b/core-java-modules/core-java-function/src/main/java/com/baeldung/lazylambda/LazyLambdaSupplier.java new file mode 100644 index 0000000000..dce3cc4997 --- /dev/null +++ b/core-java-modules/core-java-function/src/main/java/com/baeldung/lazylambda/LazyLambdaSupplier.java @@ -0,0 +1,21 @@ +package com.baeldung.lazylambda; + +import java.util.function.Supplier; + +public class LazyLambdaSupplier extends LambdaSupplier { + + private T data; + + public LazyLambdaSupplier(Supplier expensiveData) { + super(expensiveData); + } + + @Override + public T getData() { + if (data != null) { + return data; + } + return data = expensiveData.get(); + } + +} diff --git a/core-java-modules/core-java-function/src/main/java/com/baeldung/lazylambda/LazyLambdaThreadSafeSupplier.java b/core-java-modules/core-java-function/src/main/java/com/baeldung/lazylambda/LazyLambdaThreadSafeSupplier.java new file mode 100644 index 0000000000..32eec0a5d8 --- /dev/null +++ b/core-java-modules/core-java-function/src/main/java/com/baeldung/lazylambda/LazyLambdaThreadSafeSupplier.java @@ -0,0 +1,26 @@ +package com.baeldung.lazylambda; + +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Supplier; + +public class LazyLambdaThreadSafeSupplier extends LambdaSupplier { + + private final AtomicReference data; + + public LazyLambdaThreadSafeSupplier(Supplier expensiveData) { + super(expensiveData); + data = new AtomicReference<>(); + } + + public T getData() { + if (data.get() == null) { + synchronized (data) { + if (data.get() == null) { + data.set(expensiveData.get()); + } + } + } + return data.get(); + } + +} diff --git a/core-java-modules/core-java-function/src/test/java/com/baeldung/lazylambda/LambdaSupplierUnitTest.java b/core-java-modules/core-java-function/src/test/java/com/baeldung/lazylambda/LambdaSupplierUnitTest.java new file mode 100644 index 0000000000..f0a500e084 --- /dev/null +++ b/core-java-modules/core-java-function/src/test/java/com/baeldung/lazylambda/LambdaSupplierUnitTest.java @@ -0,0 +1,24 @@ +package com.baeldung.lazylambda; + +import java.util.function.Supplier; + +import org.junit.Test; +import org.mockito.Mockito; + +public class LambdaSupplierUnitTest { + + @Test + public void whenCalledMultipleTimes_thenShouldBeCalledMultipleTimes() { + @SuppressWarnings("unchecked") Supplier mockedExpensiveFunction = Mockito.mock(Supplier.class); + Mockito.when(mockedExpensiveFunction.get()) + .thenReturn("expensive call"); + LambdaSupplier testee = new LambdaSupplier<>(mockedExpensiveFunction); + Mockito.verify(mockedExpensiveFunction, Mockito.never()) + .get(); + testee.getData(); + testee.getData(); + Mockito.verify(mockedExpensiveFunction, Mockito.times(2)) + .get(); + } + +} diff --git a/core-java-modules/core-java-function/src/test/java/com/baeldung/lazylambda/LazyLambdaSupplierUnitTest.java b/core-java-modules/core-java-function/src/test/java/com/baeldung/lazylambda/LazyLambdaSupplierUnitTest.java new file mode 100644 index 0000000000..1371983a3d --- /dev/null +++ b/core-java-modules/core-java-function/src/test/java/com/baeldung/lazylambda/LazyLambdaSupplierUnitTest.java @@ -0,0 +1,51 @@ +package com.baeldung.lazylambda; + +import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import java.util.function.Supplier; + +import org.junit.Test; +import org.mockito.Mockito; +import org.mockito.stubbing.Answer; + +public class LazyLambdaSupplierUnitTest { + + @Test + public void whenCalledMultipleTimes_thenShouldBeCalledOnlyOnce() { + @SuppressWarnings("unchecked") Supplier mockedExpensiveFunction = Mockito.mock(Supplier.class); + Mockito.when(mockedExpensiveFunction.get()) + .thenReturn("expensive call"); + LazyLambdaSupplier testee = new LazyLambdaSupplier<>(mockedExpensiveFunction); + Mockito.verify(mockedExpensiveFunction, Mockito.never()) + .get(); + testee.getData(); + testee.getData(); + Mockito.verify(mockedExpensiveFunction, Mockito.times(1)) + .get(); + } + + @Test + public void whenCalledMultipleTimesConcurrently_thenShouldBeCalledMultipleTimes() throws InterruptedException { + @SuppressWarnings("unchecked") Supplier mockedExpensiveFunction = Mockito.mock(Supplier.class); + Mockito.when(mockedExpensiveFunction.get()) + .thenAnswer((Answer) invocation -> { + Thread.sleep(1000L); + return "Late response!"; + }); + LazyLambdaSupplier testee = new LazyLambdaSupplier<>(mockedExpensiveFunction); + Mockito.verify(mockedExpensiveFunction, Mockito.never()) + .get(); + + ExecutorService executorService = Executors.newFixedThreadPool(4); + executorService.invokeAll(List.of(testee::getData, testee::getData)); + executorService.shutdown(); + if (!executorService.awaitTermination(5, TimeUnit.SECONDS)) { + executorService.shutdownNow(); + } + + Mockito.verify(mockedExpensiveFunction, Mockito.times(2)) + .get(); + } +} diff --git a/core-java-modules/core-java-function/src/test/java/com/baeldung/lazylambda/LazyLambdaThreadSafeSupplierUnitTest.java b/core-java-modules/core-java-function/src/test/java/com/baeldung/lazylambda/LazyLambdaThreadSafeSupplierUnitTest.java new file mode 100644 index 0000000000..83bd49aa7e --- /dev/null +++ b/core-java-modules/core-java-function/src/test/java/com/baeldung/lazylambda/LazyLambdaThreadSafeSupplierUnitTest.java @@ -0,0 +1,52 @@ +package com.baeldung.lazylambda; + +import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import java.util.function.Supplier; + +import org.junit.Test; +import org.mockito.Mockito; +import org.mockito.stubbing.Answer; + +public class LazyLambdaThreadSafeSupplierUnitTest { + + @Test + public void whenCalledMultipleTimes_thenShouldBeCalledOnlyOnce() { + @SuppressWarnings("unchecked") Supplier mockedExpensiveFunction = Mockito.mock(Supplier.class); + Mockito.when(mockedExpensiveFunction.get()) + .thenReturn("expensive call"); + LazyLambdaThreadSafeSupplier testee = new LazyLambdaThreadSafeSupplier<>(mockedExpensiveFunction); + Mockito.verify(mockedExpensiveFunction, Mockito.never()) + .get(); + testee.getData(); + testee.getData(); + Mockito.verify(mockedExpensiveFunction, Mockito.times(1)) + .get(); + } + + @Test + public void whenCalledMultipleTimesConcurrently_thenShouldBeCalledOnlyOnce() throws InterruptedException { + @SuppressWarnings("unchecked") Supplier mockedExpensiveFunction = Mockito.mock(Supplier.class); + Mockito.when(mockedExpensiveFunction.get()) + .thenAnswer((Answer) invocation -> { + Thread.sleep(1000L); + return "Late response!"; + }); + LazyLambdaThreadSafeSupplier testee = new LazyLambdaThreadSafeSupplier<>(mockedExpensiveFunction); + Mockito.verify(mockedExpensiveFunction, Mockito.never()) + .get(); + + ExecutorService executorService = Executors.newFixedThreadPool(4); + executorService.invokeAll(List.of(testee::getData, testee::getData)); + executorService.shutdown(); + if (!executorService.awaitTermination(5, TimeUnit.SECONDS)) { + executorService.shutdownNow(); + } + + Mockito.verify(mockedExpensiveFunction, Mockito.times(1)) + .get(); + } + +} diff --git a/core-java-modules/core-java-lang-6/README.md b/core-java-modules/core-java-lang-6/README.md index 91c0e5212c..214409dd04 100644 --- a/core-java-modules/core-java-lang-6/README.md +++ b/core-java-modules/core-java-lang-6/README.md @@ -9,3 +9,5 @@ This module contains articles about core features in the Java language - [Get a Random Element From a Set in Java](https://www.baeldung.com/java-set-draw-sample) - [Stop Executing Further Code in Java](https://www.baeldung.com/java-stop-running-code) - [Using the Apache Commons Lang 3 for Comparing Objects in Java](https://www.baeldung.com/java-apache-commons-lang-3-compare-objects) +- [Return First Non-null Value in Java](https://www.baeldung.com/java-first-non-null) +- [Static Final Variables in Java](https://www.baeldung.com/java-static-final-variables) diff --git a/core-java-modules/core-java-lang-6/pom.xml b/core-java-modules/core-java-lang-6/pom.xml index 54035c1eb0..a47ed459f6 100644 --- a/core-java-modules/core-java-lang-6/pom.xml +++ b/core-java-modules/core-java-lang-6/pom.xml @@ -23,6 +23,16 @@ commons-lang3 ${commons-lang3.version} + + org.openjdk.jmh + jmh-core + ${jmh.version} + + + org.openjdk.jmh + jmh-generator-annprocess + ${jmh.version} + @@ -39,6 +49,11 @@ mapstruct-processor ${mapstruct.version} + + org.openjdk.jmh + jmh-generator-annprocess + ${jmh.version} + @@ -50,6 +65,7 @@ 17 UTF-8 1.6.0.Beta1 + 1.37 \ No newline at end of file diff --git a/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/staticfinal/Bike.java b/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/staticfinal/Bike.java new file mode 100644 index 0000000000..bde7b44897 --- /dev/null +++ b/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/staticfinal/Bike.java @@ -0,0 +1,14 @@ +package com.baeldung.staticfinal; + +import java.util.HashMap; + +public class Bike { + public static final int TIRE = 2; + public static final int PEDAL; + public static final HashMap PART = new HashMap<>(); + + static { + PEDAL = 5; + } + +} diff --git a/core-java-modules/core-java-lang-6/src/test/java/com/baeldung/recursivelysumintarray/RecursivelySumIntArrayUnitTest.java b/core-java-modules/core-java-lang-6/src/test/java/com/baeldung/recursivelysumintarray/RecursivelySumIntArrayUnitTest.java new file mode 100644 index 0000000000..fc61a806e1 --- /dev/null +++ b/core-java-modules/core-java-lang-6/src/test/java/com/baeldung/recursivelysumintarray/RecursivelySumIntArrayUnitTest.java @@ -0,0 +1,38 @@ +package com.baeldung.recursivelysumintarray; + +import org.junit.jupiter.api.Test; + +import java.util.Arrays; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class RecursivelySumIntArrayUnitTest { + + private static final int[] INT_ARRAY = { 1, 2, 3, 4, 5 }; + + static int sumIntArray1(int[] array) { + if (array.length == 1) { + return array[0]; + } else { + return array[0] + sumIntArray1(Arrays.copyOfRange(array, 1, array.length)); + } + } + + static int sumIntArray2(int[] array, int index) { + if (index == 0) { + return array[index]; + } else { + return array[index] + sumIntArray2(array, index - 1); + } + } + + @Test + void whenUsingSumIntArray1_thenGetExpectedResult() { + assertEquals(15, sumIntArray1(INT_ARRAY)); + } + + @Test + void whenUsingSumIntArray2_thenGetExpectedResult() { + assertEquals(15, sumIntArray2(INT_ARRAY, INT_ARRAY.length - 1)); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-lang-6/src/test/java/com/baeldung/recursivelysumintarray/SumArrayBenchmark.java b/core-java-modules/core-java-lang-6/src/test/java/com/baeldung/recursivelysumintarray/SumArrayBenchmark.java new file mode 100644 index 0000000000..7d6a612a8d --- /dev/null +++ b/core-java-modules/core-java-lang-6/src/test/java/com/baeldung/recursivelysumintarray/SumArrayBenchmark.java @@ -0,0 +1,61 @@ +package com.baeldung.recursivelysumintarray; + +import static com.baeldung.recursivelysumintarray.RecursivelySumIntArrayUnitTest.sumIntArray1; +import static com.baeldung.recursivelysumintarray.RecursivelySumIntArrayUnitTest.sumIntArray2; + +import java.util.Random; +import java.util.concurrent.TimeUnit; + +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Fork; +import org.openjdk.jmh.annotations.Measurement; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Param; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.annotations.Warmup; +import org.openjdk.jmh.runner.Runner; +import org.openjdk.jmh.runner.options.Options; +import org.openjdk.jmh.runner.options.OptionsBuilder; + +@BenchmarkMode(Mode.AverageTime) +@State(Scope.Thread) +@OutputTimeUnit(TimeUnit.NANOSECONDS) +@Warmup(iterations = 2) +@Fork(1) +@Measurement(iterations = 5) +public class SumArrayBenchmark { + + public static void main(String[] args) throws Exception { + Options options = new OptionsBuilder().include(SumArrayBenchmark.class.getSimpleName()) + .build(); + new Runner(options).run(); + } + + @Param({ "10", "10000" }) + public int size; + int[] array; + + @Setup + public void setup() { + var r = new Random(); + array = new int[size]; + + for (int i = 0; i < size; i++) { + array[i] = r.nextInt(); + } + } + + @Benchmark + public int withArrayCopy() { + return sumIntArray1(array); + } + + @Benchmark + public int withoutArrayCopy() { + return sumIntArray2(array, array.length - 1); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-lang-6/src/test/java/com/baeldung/staticfinal/BikeUnitTest.java b/core-java-modules/core-java-lang-6/src/test/java/com/baeldung/staticfinal/BikeUnitTest.java new file mode 100644 index 0000000000..2201dae4d1 --- /dev/null +++ b/core-java-modules/core-java-lang-6/src/test/java/com/baeldung/staticfinal/BikeUnitTest.java @@ -0,0 +1,33 @@ +package com.baeldung.staticfinal; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class BikeUnitTest { + + @Test + void givenTireConstantSetUponDeclaration_whenGetTire_thenReturnTwo() { + assertEquals(2, Bike.TIRE); + } + + @Test + void givenPedalConstantSetByStaticBlock_whenGetPedal_thenReturnFive() { + assertEquals(5, Bike.PEDAL); + } + + @Test + void givenPartConstantObject_whenObjectStateChanged_thenCorrect() { + Bike.PART.put("seat", 1); + assertEquals(1, Bike.PART.get("seat")); + + Bike.PART.put("seat", 5); + assertEquals(5, Bike.PART.get("seat")); + } + + @Test + void givenMathClass_whenAccessingPiConstant_thenVerifyPiValueIsCorrect() { + assertEquals(3.141592653589793, Math.PI); + } + +} \ No newline at end of file diff --git a/core-java-modules/core-java-lang-operators-2/README.md b/core-java-modules/core-java-lang-operators-2/README.md index e8b792e634..4b93f8d192 100644 --- a/core-java-modules/core-java-lang-operators-2/README.md +++ b/core-java-modules/core-java-lang-operators-2/README.md @@ -10,3 +10,4 @@ This module contains articles about Java operators - [Check if at Least Two Out of Three Booleans Are True in Java](https://www.baeldung.com/java-check-two-of-three-booleans) - [Alternatives for instanceof Operator in Java](https://www.baeldung.com/java-instanceof-alternatives) - [What Does “––>” Mean in Java?](https://www.baeldung.com/java-minus-minus-greaterthan) +- [All the Ways Java Uses the Colon Character](https://www.baeldung.com/java-colon) diff --git a/core-java-modules/core-java-lang-operators-2/src/main/java/com/baeldung/colonexamples/ColonExamples.java b/core-java-modules/core-java-lang-operators-2/src/main/java/com/baeldung/colonexamples/ColonExamples.java new file mode 100644 index 0000000000..873e28c3f6 --- /dev/null +++ b/core-java-modules/core-java-lang-operators-2/src/main/java/com/baeldung/colonexamples/ColonExamples.java @@ -0,0 +1,178 @@ +package com.baeldung.colonexamples; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.sql.Connection; +import java.util.*; +import java.util.stream.Collectors; + +/** + * Examples of the different ways Java uses the colon (:) character. + */ +public class ColonExamples { + + private final static Logger LOG = LoggerFactory.getLogger(ColonExamples.class); + + public void example1_enhancedForLoop() { + + // Original style + for(int i = 0; i < 10; i++) { + // do something + } + + // Using enhanced for loop + int[] numbers = new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9}; + for(int i : numbers) { + // do something + } + + // Using List instead of array + List numbersList = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9); + for(Integer i : numbersList) { + // do something + } + } + + public void example2_switchStatement(String animal) { + + // Original style + if(animal.equals("cat")) { + System.out.println("meow"); + } + else if(animal.equals("lion")) { + System.out.println("roar"); + } + else if(animal.equals("dog") || animal.equals("seal")) { + System.out.println("bark"); + } + else { + System.out.println("unknown"); + } + + // Using switch statement + switch(animal) { + case "cat": + System.out.println("meow"); + break; + case "lion": + System.out.println("roar"); + break; + case "dog": + case "seal": + System.out.println("bark"); + break; + default: + System.out.println("unknown"); + } + } + + public void example3_labels() { + + // For loops without labels + for(int i = 0; i < 10; i++) { + for (int j = 0; j < 10; j++) { + if (checkSomeCondition()) { + break; + } + } + } + + outterLoop: for(int i = 0; i < 10; i++) { + innerLoop: for (int j = 0; j < 10; j++) { + if (checkSomeCondition()) { + break outterLoop; + } + } + } + } + + public void example4_ternaryOperator() { + + // Original way using if/else + int x; + if(checkSomeCondition()) { + x = 1; + } + else { + x = 2; + } + + // Using ternary operator + x = checkSomeCondition() ? 1 : 2; + + // Using with other statements + boolean remoteCallResult = callRemoteApi(); + LOG.info(String.format( + "The result of the remote API call %s successful", + remoteCallResult ? "was" : "was not" + )); + } + + public void example5_methodReferences() { + // Original way without lambdas and method references + List names = Arrays.asList("ross", "joey", "chandler"); + List upperCaseNames = new ArrayList<>(); + for(String name : names) { + upperCaseNames.add(name.toUpperCase()); + } + + // Using method reference with stream map operation + List petNames = Arrays.asList("ross", "joey", "chandler"); + List petUpperCaseNames = petNames + .stream() + .map(String::toUpperCase) + .collect(Collectors.toList()); + + // Method reference with stream filter + List pets = Arrays.asList(new Cat(), new Dog(), new Parrot()); + List onlyDogs = pets + .stream() + .filter(Dog.class::isInstance) + .collect(Collectors.toList()); + + // Method reference with constructors + Set onlyDogsSet = pets + .stream() + .filter(Dog.class::isInstance) + .collect(Collectors.toCollection(TreeSet::new)); + } + + public void example6_asserttion() { + // Original way without assertions + Connection conn = getConnection(); + if(conn == null) { + throw new RuntimeException("Connection is null"); + } + + // Using assert keyword + assert getConnection() != null : "Connection is null"; + } + + private boolean checkSomeCondition() { + return new Random().nextBoolean(); + } + + private boolean callRemoteApi() { + return new Random().nextBoolean(); + } + + private Connection getConnection() { + return null; + } + + private static interface Animal { + + } + private static class Dog implements Animal { + + } + + private static class Cat implements Animal { + + } + + private static class Parrot implements Animal { + + } +} diff --git a/core-java-modules/core-java-numbers-7/README.md b/core-java-modules/core-java-numbers-7/README.md new file mode 100644 index 0000000000..42a43fd1fd --- /dev/null +++ b/core-java-modules/core-java-numbers-7/README.md @@ -0,0 +1,2 @@ +## Relevant Articles +- [Check if a double Is an Integer in Java](https://www.baeldung.com/java-check-double-integer) diff --git a/core-java-modules/core-java-numbers-7/pom.xml b/core-java-modules/core-java-numbers-7/pom.xml new file mode 100644 index 0000000000..dec3084108 --- /dev/null +++ b/core-java-modules/core-java-numbers-7/pom.xml @@ -0,0 +1,37 @@ + + 4.0.0 + core-java-numbers-7 + core-java-numbers-7 + jar + + + com.baeldung.core-java-modules + core-java-modules + 0.0.1-SNAPSHOT + + + + + org.junit.jupiter + junit-jupiter-engine + ${junit-jupiter.version} + test + + + com.google.guava + guava + ${guava.version} + + + + core-java-numbers-7 + + + src/main/resources + true + + + + \ No newline at end of file diff --git a/core-java-modules/core-java-numbers-7/src/test/java/com/baeldung/bigdecimalzero/BigDecimalZeroVsNewBigDecimalUnitTest.java b/core-java-modules/core-java-numbers-7/src/test/java/com/baeldung/bigdecimalzero/BigDecimalZeroVsNewBigDecimalUnitTest.java new file mode 100644 index 0000000000..a10a615e2f --- /dev/null +++ b/core-java-modules/core-java-numbers-7/src/test/java/com/baeldung/bigdecimalzero/BigDecimalZeroVsNewBigDecimalUnitTest.java @@ -0,0 +1,39 @@ +package com.baeldung.bigdecimalzero; + +import org.junit.jupiter.api.Test; + +import java.math.BigDecimal; + +import static org.junit.jupiter.api.Assertions.*; + +public class BigDecimalZeroVsNewBigDecimalUnitTest { + @Test + void whenComparingZeroAndNewBigDecimal_thenGetExpectedResult() { + BigDecimal bd1 = new BigDecimal("42.00"); + BigDecimal bd2 = new BigDecimal("42.0000"); + assertEquals(0, bd1.compareTo(bd2)); + + assertNotEquals(bd1, bd2); + + BigDecimal zero0 = new BigDecimal(0); + assertNotEquals(zero0, new BigDecimal("0.000")); + + BigDecimal zero = BigDecimal.ZERO; + assertEquals(zero, zero0); + } + + @Test + void whenCallingBigDecimalZero_thenAlwaysGetTheSameObject() { + BigDecimal z1 = BigDecimal.ZERO; + BigDecimal z2 = BigDecimal.ZERO; + assertSame(z1, z2); + } + + @Test + void whenCallingNewBigDecimal_thenAlwaysGetTheSameObject() { + BigDecimal z1 = new BigDecimal(0); + BigDecimal z2 = new BigDecimal(0); + assertNotSame(z1, z2); + } + +} \ No newline at end of file diff --git a/core-java-modules/core-java-numbers-7/src/test/java/com/baeldung/doubleisint/CheckDoubleIsAnIntegerUnitTest.java b/core-java-modules/core-java-numbers-7/src/test/java/com/baeldung/doubleisint/CheckDoubleIsAnIntegerUnitTest.java new file mode 100644 index 0000000000..90d2c52595 --- /dev/null +++ b/core-java-modules/core-java-numbers-7/src/test/java/com/baeldung/doubleisint/CheckDoubleIsAnIntegerUnitTest.java @@ -0,0 +1,83 @@ +package com.baeldung.doubleisint; + +import com.google.common.math.DoubleMath; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class CheckDoubleIsAnIntegerUnitTest { + + boolean notNaNOrInfinity(double d) { + return !(Double.isNaN(d) || Double.isInfinite(d)); + } + + @Test + void whenConvertingToInt_thenGetExpectedResult() { + double d1 = 42.0D; + boolean d1IsInteger = notNaNOrInfinity(d1) && (int) d1 == d1; + assertTrue(d1IsInteger); + + double d2 = 42.42D; + boolean d2IsInteger = notNaNOrInfinity(d2) && (int) d2 == d2; + assertFalse(d2IsInteger); + + double d3 = 2.0D * Integer.MAX_VALUE; + boolean d3IsInteger = notNaNOrInfinity(d3) && (int) d3 == d3; + assertTrue(!d3IsInteger); // <-- fails if exceeding Integer's range + } + + @Test + void whenUsingModuloOperator_thenGetExpectedResult() { + double d1 = 42.0D; + boolean d1IsInteger = notNaNOrInfinity(d1) && (d1 % 1) == 0; + assertTrue(d1IsInteger); + + double d2 = 42.42D; + boolean d2IsInteger = notNaNOrInfinity(d2) && (d2 % 1) == 0; + assertFalse(d2IsInteger); + + double d3 = 2.0D * Integer.MAX_VALUE; + boolean d3IsInteger = notNaNOrInfinity(d3) && (d3 % 1) == 0; + assertTrue(d3IsInteger); + + } + + + @Test + void whenCheckingFloorOrCeilingValue_thenGetExpectedResult() { + double d1 = 42.0D; + boolean d1IsInteger = notNaNOrInfinity(d1) && Math.floor(d1) == d1; + assertTrue(d1IsInteger); + + double d2 = 42.42D; + boolean d2IsInteger = notNaNOrInfinity(d2) && Math.floor(d2) == d2; + assertFalse(d2IsInteger); + + double d3 = 2.0D * Integer.MAX_VALUE; + boolean d3IsInteger = notNaNOrInfinity(d3) && Math.floor(d3) == d3; + assertTrue(d3IsInteger); + + } + + @Test + void whenUsingGuava_thenGetExpectedResult() { + double d1 = 42.0D; + boolean d1IsInteger = DoubleMath.isMathematicalInteger(d1); + assertTrue(d1IsInteger); + + double d2 = 42.42D; + boolean d2IsInteger = DoubleMath.isMathematicalInteger(d2); + assertFalse(d2IsInteger); + + double d3 = 2.0D * Integer.MAX_VALUE; + boolean d3IsInteger = DoubleMath.isMathematicalInteger(d3); + assertTrue(d3IsInteger); + + boolean isInfinityInt = DoubleMath.isMathematicalInteger(Double.POSITIVE_INFINITY); + assertFalse(isInfinityInt); + + boolean isNanInt = DoubleMath.isMathematicalInteger(Double.NaN); + assertFalse(isNanInt); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-numbers-conversions/README.md b/core-java-modules/core-java-numbers-conversions/README.md index dead88f025..b5f02a9d47 100644 --- a/core-java-modules/core-java-numbers-conversions/README.md +++ b/core-java-modules/core-java-numbers-conversions/README.md @@ -4,3 +4,5 @@ - [Convert int to Long in Java](https://www.baeldung.com/java-convert-int-long) - [How To Convert Double To Float In Java](https://www.baeldung.com/java-convert-double-float) - [Converting from float to BigDecimal in Java](https://www.baeldung.com/java-convert-float-bigdecimal) +- [Convert Positive Integer to Negative and Vice Versa in Java](https://www.baeldung.com/java-negating-integer) +- [Rounding Up a Number to Nearest Multiple of 5 in Java](https://www.baeldung.com/java-round-nearest-multiple-five) diff --git a/core-java-modules/core-java-os/src/test/java/com/baeldung/example/soundapi/AppUnitTest.java b/core-java-modules/core-java-os/src/test/java/com/baeldung/example/soundapi/AppUnitTest.java index 27bc750d8a..849f71dc03 100644 --- a/core-java-modules/core-java-os/src/test/java/com/baeldung/example/soundapi/AppUnitTest.java +++ b/core-java-modules/core-java-os/src/test/java/com/baeldung/example/soundapi/AppUnitTest.java @@ -23,7 +23,7 @@ public class AppUnitTest { soundRecorder.build(af); try { soundRecorder.start(); - Thread.sleep(20000); + Thread.sleep(5000); soundRecorder.stop(); } catch (InterruptedException ex) { fail("Exception: " + ex); diff --git a/core-java-modules/core-java-os/src/test/java/com/baeldung/java9/process/ProcessApiUnitTest.java b/core-java-modules/core-java-os/src/test/java/com/baeldung/java9/process/ProcessApiUnitTest.java index c3f390d8ae..dae1a705ed 100644 --- a/core-java-modules/core-java-os/src/test/java/com/baeldung/java9/process/ProcessApiUnitTest.java +++ b/core-java-modules/core-java-os/src/test/java/com/baeldung/java9/process/ProcessApiUnitTest.java @@ -69,7 +69,7 @@ public class ProcessApiUnitTest { }); }); - Thread.sleep(10000); + Thread.sleep(5000); childProc = ProcessHandle.current().children(); childProc.forEach(procHandle -> { @@ -100,7 +100,7 @@ public class ProcessApiUnitTest { private void waistCPU() throws NoSuchAlgorithmException { ArrayList randArr = new ArrayList(4096); SecureRandom sr = SecureRandom.getInstanceStrong(); - Duration somecpu = Duration.ofMillis(4200L); + Duration somecpu = Duration.ofMillis(2000L); Instant end = Instant.now().plus(somecpu); while (Instant.now().isBefore(end)) { // System.out.println(sr.nextInt()); diff --git a/core-java-modules/core-java-reflection-3/pom.xml b/core-java-modules/core-java-reflection-3/pom.xml index fa5fe897e0..e60652f1f2 100644 --- a/core-java-modules/core-java-reflection-3/pom.xml +++ b/core-java-modules/core-java-reflection-3/pom.xml @@ -1,7 +1,7 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 core-java-reflection-3 core-java-reflection-3 diff --git a/core-java-modules/core-java-security-4/README.md b/core-java-modules/core-java-security-4/README.md index 236715713b..3c910e50be 100644 --- a/core-java-modules/core-java-security-4/README.md +++ b/core-java-modules/core-java-security-4/README.md @@ -5,4 +5,5 @@ This module contains articles about core Java Security ### Relevant Articles: - [Check if Certificate Is Self-Signed or CA-Signed With Java](https://www.baeldung.com/java-check-certificate-sign) - [Extract CN From X509 Certificate in Java](https://www.baeldung.com/java-extract-common-name-x509-certificate) +- [Check Certificate Name and Alias in Keystore File](https://www.baeldung.com/java-keystore-check-certificate-name-alias) - More articles: [[<-- prev]](/core-java-modules/core-java-security-3) diff --git a/core-java-modules/core-java-streams-4/pom.xml b/core-java-modules/core-java-streams-4/pom.xml index e832cc1616..383f14d573 100644 --- a/core-java-modules/core-java-streams-4/pom.xml +++ b/core-java-modules/core-java-streams-4/pom.xml @@ -71,7 +71,7 @@ io.projectreactor reactor-core - ${io.reactor3.version} + ${reactor-core.version} org.apache.commons @@ -121,7 +121,7 @@ 2.2.2 3.1.5 1.0.0-alpha-4 - 3.5.1 + 3.6.0 4.4 10.4.1 diff --git a/core-java-modules/core-java-streams-5/pom.xml b/core-java-modules/core-java-streams-5/pom.xml index e217271f4c..33cd69f761 100644 --- a/core-java-modules/core-java-streams-5/pom.xml +++ b/core-java-modules/core-java-streams-5/pom.xml @@ -48,6 +48,11 @@ guava ${guava.version} + + org.apache.commons + commons-collections4 + ${commons-collections4.version} + diff --git a/core-java-modules/core-java-streams-5/src/main/java/com/baeldung/streams/firstmatchingelement/User.java b/core-java-modules/core-java-streams-5/src/main/java/com/baeldung/streams/firstmatchingelement/User.java new file mode 100644 index 0000000000..cb29af529a --- /dev/null +++ b/core-java-modules/core-java-streams-5/src/main/java/com/baeldung/streams/firstmatchingelement/User.java @@ -0,0 +1,21 @@ +package com.baeldung.streams.firstmatchingelement; + +public class User { + + private String userName; + private Integer userId; + + public User(Integer userId, String userName) { + this.userId = userId; + this.userName = userName; + } + + public String getUserName() { + return userName; + } + + public Integer getUserId() { + return userId; + } + +} diff --git a/core-java-modules/core-java-streams-5/src/test/java/com/baeldung/findfirstnullpointerexception/FindFirstNullPointerExceptionUnitTest.java b/core-java-modules/core-java-streams-5/src/test/java/com/baeldung/findfirstnullpointerexception/FindFirstNullPointerExceptionUnitTest.java new file mode 100644 index 0000000000..074aec29d6 --- /dev/null +++ b/core-java-modules/core-java-streams-5/src/test/java/com/baeldung/findfirstnullpointerexception/FindFirstNullPointerExceptionUnitTest.java @@ -0,0 +1,42 @@ +package com.baeldung.findfirstnullpointerexception; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.function.Function; + +import org.junit.Test; + +public class FindFirstNullPointerExceptionUnitTest { + + private final List inputs = Arrays.asList(null, "foo", "bar"); + + @Test(expected = NullPointerException.class) + public void givenStream_whenCallingFindFirst_thenThrowNullPointerException() { + Optional firstElement = inputs.stream() + .findFirst(); + } + + @Test + public void givenStream_whenUsingOfNullableBeforeFindFirst_thenCorrect() { + Optional firstElement = inputs.stream() + .map(Optional::ofNullable) + .findFirst() + .flatMap(Function.identity()); + + assertTrue(firstElement.isEmpty()); + } + + @Test + public void givenStream_whenUsingFilterBeforeFindFirst_thenCorrect() { + Optional firstNonNullElement = inputs.stream() + .filter(Objects::nonNull) + .findFirst(); + + assertTrue(firstNonNullElement.isPresent()); + } + +} diff --git a/core-java-modules/core-java-streams-5/src/test/java/com/baeldung/streams/firstmatchingelement/FirstMatchingElementUnitTest.java b/core-java-modules/core-java-streams-5/src/test/java/com/baeldung/streams/firstmatchingelement/FirstMatchingElementUnitTest.java new file mode 100644 index 0000000000..db9415e94b --- /dev/null +++ b/core-java-modules/core-java-streams-5/src/test/java/com/baeldung/streams/firstmatchingelement/FirstMatchingElementUnitTest.java @@ -0,0 +1,72 @@ +package com.baeldung.streams.firstmatchingelement; + + +import static org.junit.Assert.assertEquals; + +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.IntStream; + +import org.apache.commons.collections4.IterableUtils; +import org.junit.Test; + +import com.google.common.collect.Iterables; + +public class FirstMatchingElementUnitTest { + + private List userList = List.of(new User(1, "David"), new User(2, "John"), new User(3, "Roger"), new User(4, "John")); + private String searchName = "John"; + + @Test + public void whenUsingStream_thenFindFirstMatchingUserIndex() { + AtomicInteger counter = new AtomicInteger(-1); + int index = userList.stream() + .filter(user -> { + counter.getAndIncrement(); + return searchName.equals(user.getUserName()); + }) + .mapToInt(user -> counter.get()) + .findFirst() + .orElse(-1); + + assertEquals(1, index); + } + + @Test + public void whenUsingIntStream_thenFindFirstMatchingUserIndex() { + int index = IntStream.range(0, userList.size() - 1) + .filter(streamIndex -> searchName.equals(userList.get(streamIndex).getUserName())) + .findFirst() + .orElse(-1); + assertEquals(1, index); + } + + @Test + public void whenUsingTakeWhile_thenFindFirstMatchingUserIndex() { + long predicateIndex = userList.stream() + .takeWhile(user -> !user.getUserName().equals(searchName)) + .count(); + assertEquals(1, predicateIndex); + } + + @Test + public void whenUsingTakeWhile_thenFindIndexFromNoMatchingElement() { + List userList = List.of(new User(1, "David"), new User(2, "Vick"), new User(3, "Roger"), new User(4, "James")); + long predicateIndex = userList.stream() + .takeWhile(user -> !user.getUserName().equals(searchName)) + .count(); + assertEquals(4, predicateIndex); + } + + @Test + public void whenUsingGoogleGuava_thenFindFirstMatchingUserIndex() { + int index = Iterables.indexOf(userList, user -> searchName.equals(user.getUserName())); + assertEquals(1, index); + } + + @Test + public void whenUsingApacheCommons_thenFindFirstMatchingUserIndex() { + int index = IterableUtils.indexOf(userList, user -> searchName.equals(user.getUserName())); + assertEquals(1, index); + } +} diff --git a/core-java-modules/core-java-streams/src/test/java/com/baeldung/skipinputstream/SkipInputStreamUnitTest.java b/core-java-modules/core-java-streams/src/test/java/com/baeldung/skipinputstream/SkipInputStreamUnitTest.java new file mode 100644 index 0000000000..a41e5642fe --- /dev/null +++ b/core-java-modules/core-java-streams/src/test/java/com/baeldung/skipinputstream/SkipInputStreamUnitTest.java @@ -0,0 +1,33 @@ +package com.baeldung.skipinputstream; + +import org.junit.Test; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; + +import static org.junit.Assert.assertArrayEquals; + +public class SkipInputStreamUnitTest { + @Test + public void givenInputStreamWithBytes_whenSkipBytes_thenRemainingBytes() throws IOException { + byte[] inputData = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + InputStream inputStream = new ByteArrayInputStream(inputData); + + long bytesToSkip = 3; + long skippedBytes = inputStream.skip(bytesToSkip); + + assertArrayEquals(new byte[]{4, 5, 6, 7, 8, 9, 10}, readRemainingBytes(inputStream)); + + assert skippedBytes == bytesToSkip : "Incorrect number of bytes skipped"; + } + + private byte[] readRemainingBytes(InputStream inputStream) throws IOException { + byte[] buffer = new byte[inputStream.available()]; + int bytesRead = inputStream.read(buffer); + if (bytesRead == -1) { + throw new IOException("End of stream reached"); + } + return buffer; + } +} diff --git a/core-java-modules/core-java-string-operations-2/pom.xml b/core-java-modules/core-java-string-operations-2/pom.xml index 27071e5427..76f21aa726 100644 --- a/core-java-modules/core-java-string-operations-2/pom.xml +++ b/core-java-modules/core-java-string-operations-2/pom.xml @@ -44,10 +44,10 @@ commons-codec ${commons-codec.version} - - org.springframework - spring-core - ${spring-core.version} + + org.springframework + spring-core + ${spring-core.version} diff --git a/core-java-modules/core-java-string-operations-3/pom.xml b/core-java-modules/core-java-string-operations-3/pom.xml index 0558e71a35..59d14805a0 100644 --- a/core-java-modules/core-java-string-operations-3/pom.xml +++ b/core-java-modules/core-java-string-operations-3/pom.xml @@ -72,7 +72,7 @@ 5.3.9 3.6.3 6.1.1 - 2.11.1 + 2.16.0 3.1.0 diff --git a/core-java-modules/core-java-string-operations-3/src/test/java/com/baeldung/versioncomparison/VersionComparisonUnitTest.java b/core-java-modules/core-java-string-operations-3/src/test/java/com/baeldung/versioncomparison/VersionComparisonUnitTest.java index 145e9788e4..a99778201a 100644 --- a/core-java-modules/core-java-string-operations-3/src/test/java/com/baeldung/versioncomparison/VersionComparisonUnitTest.java +++ b/core-java-modules/core-java-string-operations-3/src/test/java/com/baeldung/versioncomparison/VersionComparisonUnitTest.java @@ -87,7 +87,7 @@ public class VersionComparisonUnitTest { assertTrue(version1_1_maven.compareTo(version1_1_gradle) < 0); Version version1_1_snapshot = new Version(1, 1, 0, "snapshot", null, null); - assertEquals(0, version1_1.compareTo(version1_1_snapshot)); + assertEquals(1, version1_1.compareTo(version1_1_snapshot)); assertTrue(version1_1_snapshot.isSnapshot()); } diff --git a/core-java-modules/core-java-string-operations-7/src/main/java/com/baeldung/stringmaxlength/StringMaxLengthMain.java b/core-java-modules/core-java-string-operations-7/src/main/java/com/baeldung/stringmaxlength/StringMaxLengthMain.java new file mode 100644 index 0000000000..42d0c05582 --- /dev/null +++ b/core-java-modules/core-java-string-operations-7/src/main/java/com/baeldung/stringmaxlength/StringMaxLengthMain.java @@ -0,0 +1,35 @@ +package com.baeldung.stringmaxlength; + +public class StringMaxLengthMain { + + public static void main(String[] args) { + displayRuntimeMaxStringLength(); + displayMaxStringLength(); + simulateStringOverflow(); + } + + public static void simulateStringOverflow() { + try { + int maxLength = Integer.MAX_VALUE; + char[] charArray = new char[maxLength]; + for (int i = 0; i < maxLength; i++) { + charArray[i] = 'a'; + } + String longString = new String(charArray); + System.out.println("Successfully created a string of length: " + longString.length()); + } catch (OutOfMemoryError e) { + System.err.println("Overflow error: Attempting to create a string longer than Integer.MAX_VALUE"); + e.printStackTrace(); + } + } + + public static void displayRuntimeMaxStringLength() { + long maxMemory = Runtime.getRuntime().maxMemory(); + System.out.println("Maximum String length based on available memory: " + (maxMemory)); + } + + public static void displayMaxStringLength() { + int maxStringLength = Integer.MAX_VALUE; + System.out.println("Maximum String length based on Integer.MAX_VALUE: " + maxStringLength); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-strings/src/main/java/com/baeldung/stringbuffer/ComparePerformance.java b/core-java-modules/core-java-strings/src/main/java/com/baeldung/stringbuffer/ComparePerformance.java index 28cd2e64e9..4d045fe318 100644 --- a/core-java-modules/core-java-strings/src/main/java/com/baeldung/stringbuffer/ComparePerformance.java +++ b/core-java-modules/core-java-strings/src/main/java/com/baeldung/stringbuffer/ComparePerformance.java @@ -28,6 +28,7 @@ public class ComparePerformance { @Benchmark public String benchmarkStringConcatenation() { + strFinal = ""; strFinal += strInitial; return strFinal; } diff --git a/core-java-modules/core-java-swing/target/classes/org/example/Main.class b/core-java-modules/core-java-swing/target/classes/org/example/Main.class deleted file mode 100644 index 5914458bc4..0000000000 Binary files a/core-java-modules/core-java-swing/target/classes/org/example/Main.class and /dev/null differ diff --git a/core-java-modules/core-java-uuid/README.md b/core-java-modules/core-java-uuid/README.md index bd7bd9d9da..a32c1ae04f 100644 --- a/core-java-modules/core-java-uuid/README.md +++ b/core-java-modules/core-java-uuid/README.md @@ -6,3 +6,4 @@ - [Validate UUID String in Java](https://www.baeldung.com/java-validate-uuid-string) - [Generate the Same UUID From a String in Java](https://www.baeldung.com/java-generate-same-uuid-from-string) - [Generating Time Based UUIDs](https://www.baeldung.com/java-generating-time-based-uuids) +- [Generating Unique Positive long Using UUID in Java](https://www.baeldung.com/java-uuid-unique-long-generation) diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml index b3ef8167a5..d20a1650b9 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -59,16 +59,16 @@ core-java-lang-oop-constructors-2 core-java-methods core-java-networking-3 - core-java-os + core-java-perf-2 core-java-streams-4 core-java-streams-5 core-java-streams-collect core-java-streams-maps core-java-string-algorithms-3 - core-java-string-operations-3 + core-java-string-operations-4 - core-java-string-operations-5 + core-java-time-measurements core-java-annotations @@ -123,13 +123,13 @@ core-java-io core-java-io-2 core-java-io-3 - core-java-io-4 + core-java-io-5 core-java-io-apis core-java-io-apis-2 core-java-io-conversions core-java-jar - core-java-jndi + core-java-jvm core-java-jvm-2 core-java-jvm-3 @@ -144,11 +144,11 @@ core-java-lang-oop-constructors core-java-lang-oop-patterns core-java-lang-oop-generics - core-java-lang-oop-modifiers + core-java-lang-oop-types core-java-lang-oop-types-2 core-java-lang-oop-inheritance - core-java-lang-oop-methods + core-java-lang-oop-others core-java-lang-operators core-java-lang-operators-2 @@ -166,6 +166,7 @@ core-java-numbers-4 core-java-numbers-5 core-java-numbers-6 + core-java-numbers-7 core-java-optional core-java-perf core-java-properties @@ -184,8 +185,8 @@ core-java-string-algorithms core-java-string-algorithms-2 core-java-string-apis + core-java-swing - core-java-string-apis-2 core-java-string-conversions core-java-string-conversions-2 core-java-string-conversions-3 @@ -225,5 +226,4 @@ - diff --git a/deeplearning4j/pom.xml b/deeplearning4j/pom.xml index 875d8cdf85..aab19a166d 100644 --- a/deeplearning4j/pom.xml +++ b/deeplearning4j/pom.xml @@ -68,7 +68,6 @@ 0.9.1 4.3.5 - 1.18.20 \ No newline at end of file diff --git a/docker-modules/docker-caching/multi-module-caching/pom.xml b/docker-modules/docker-caching/multi-module-caching/pom.xml index bebfb85e8a..f2b52f246d 100644 --- a/docker-modules/docker-caching/multi-module-caching/pom.xml +++ b/docker-modules/docker-caching/multi-module-caching/pom.xml @@ -25,8 +25,6 @@ - UTF-8 - 1.8 32.1.3-jre diff --git a/docker-modules/docker-containers/pom.xml b/docker-modules/docker-containers/pom.xml index 79bf0aee72..f8b903c87d 100644 --- a/docker-modules/docker-containers/pom.xml +++ b/docker-modules/docker-containers/pom.xml @@ -27,6 +27,7 @@ io.projectreactor reactor-test + ${reactor.version} test @@ -45,7 +46,7 @@ com.google.cloud.tools jib-maven-plugin - 2.7.1 + ${jib-maven-plugin.version} docker-demo-jib @@ -55,4 +56,10 @@ + + 3.6.0 + 2.7.1 + + + \ No newline at end of file diff --git a/docker-modules/pom.xml b/docker-modules/pom.xml index b4c5240718..4eeab746eb 100644 --- a/docker-modules/pom.xml +++ b/docker-modules/pom.xml @@ -24,8 +24,4 @@ docker-java-jar - - 11 - - \ No newline at end of file diff --git a/gradle-modules/gradle-7/README.md b/gradle-modules/gradle-7/README.md index fe05a4b9bc..c452ee8b33 100644 --- a/gradle-modules/gradle-7/README.md +++ b/gradle-modules/gradle-7/README.md @@ -5,4 +5,5 @@ - [Working With Multiple Repositories in Gradle](https://www.baeldung.com/java-gradle-multiple-repositories) - [Different Dependency Version Declarations in Gradle](https://www.baeldung.com/gradle-different-dependency-version-declarations) - [Generating Javadoc With Gradle](https://www.baeldung.com/java-gradle-javadoc) -- [Generating WSDL Stubs With Gradle](https://www.baeldung.com/java-gradle-create-wsdl-stubs) \ No newline at end of file +- [Generating WSDL Stubs With Gradle](https://www.baeldung.com/java-gradle-create-wsdl-stubs) +- [Gradle Proxy Configuration](https://www.baeldung.com/gradle-proxy-configuration) diff --git a/httpclient-simple/pom.xml b/httpclient-simple/pom.xml index a0f2dd6514..e0488bf0b1 100644 --- a/httpclient-simple/pom.xml +++ b/httpclient-simple/pom.xml @@ -203,7 +203,6 @@ - 17 1.16.0 diff --git a/jackson-modules/jackson-exceptions/src/main/java/com/baeldung/mismatchedinputexception/Animals.java b/jackson-modules/jackson-exceptions/src/main/java/com/baeldung/mismatchedinputexception/Animals.java new file mode 100644 index 0000000000..1ad1014414 --- /dev/null +++ b/jackson-modules/jackson-exceptions/src/main/java/com/baeldung/mismatchedinputexception/Animals.java @@ -0,0 +1,27 @@ +package com.baeldung.mismatchedinputexception; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class Animals { + + private final int id; + private String name; + + + public Animals(@JsonProperty("id") int id, @JsonProperty("name")String name) { + this.id = id; + this.name = name; + } + + public int getId() { + return id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/jackson-modules/jackson-exceptions/src/main/java/com/baeldung/mismatchedinputexception/Book.java b/jackson-modules/jackson-exceptions/src/main/java/com/baeldung/mismatchedinputexception/Book.java new file mode 100644 index 0000000000..28fe118ac5 --- /dev/null +++ b/jackson-modules/jackson-exceptions/src/main/java/com/baeldung/mismatchedinputexception/Book.java @@ -0,0 +1,27 @@ +package com.baeldung.mismatchedinputexception; + +public class Book { + + private int id; + private String title; + + public Book(int id, String title) { + this.id = id; + this.title = title; + } + + public Book() { + } + + public int getId() { + return id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } +} diff --git a/jackson-modules/jackson-exceptions/src/test/java/com/baeldung/mismatchedinputexception/MismatchedinputExceptionUnitTest.java b/jackson-modules/jackson-exceptions/src/test/java/com/baeldung/mismatchedinputexception/MismatchedinputExceptionUnitTest.java new file mode 100644 index 0000000000..178ad1a8db --- /dev/null +++ b/jackson-modules/jackson-exceptions/src/test/java/com/baeldung/mismatchedinputexception/MismatchedinputExceptionUnitTest.java @@ -0,0 +1,39 @@ +package com.baeldung.mismatchedinputexception; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class MismatchedinputExceptionUnitTest { + + @Test + void givenJsonString_whenDeserializingToJavaObjectWithImmutableField_thenIdIsCorrect() throws JsonProcessingException { + String jsonString = "{\"id\":10,\"name\":\"Dog\"}"; + ObjectMapper mapper = new ObjectMapper(); + Animals animal = mapper.readValue(jsonString, Animals.class); + assertEquals(animal.getId(),10); + } + + @Test + void givenJsonString_whenDeserializingToBook_thenIdIsCorrect() throws JsonProcessingException { + String jsonString = "{\"id\":\"10\",\"title\":\"Harry Potter\"}"; + ObjectMapper mapper = new ObjectMapper(); + Book book = mapper.readValue(jsonString, Book.class); + assertEquals(book.getId(),10); + } + + + @Test + void givenJsonString_whenDeserializingToBookList_thenTitleIsCorrect() throws JsonProcessingException { + String jsonString = "[{\"id\":\"10\",\"title\":\"Harry Potter\"}]"; + ObjectMapper mapper = new ObjectMapper(); + List book = mapper.readValue(jsonString, new TypeReference>(){}); + assertEquals(book.get(0).getTitle(),"Harry Potter"); + } + +} \ No newline at end of file diff --git a/jackson-modules/jackson-polymorphic-deserialization/pom.xml b/jackson-modules/jackson-polymorphic-deserialization/pom.xml index 0d88c19500..cbf67e5013 100644 --- a/jackson-modules/jackson-polymorphic-deserialization/pom.xml +++ b/jackson-modules/jackson-polymorphic-deserialization/pom.xml @@ -16,7 +16,7 @@ com.fasterxml.jackson.core jackson-core - ${jackson-core.version} + ${jackson.version} org.reflections @@ -36,7 +36,7 @@ - 2.15.2 + 2.16.0 0.9.11 diff --git a/jackson-simple/pom.xml b/jackson-simple/pom.xml index 3bf523bbfa..daa6504709 100644 --- a/jackson-simple/pom.xml +++ b/jackson-simple/pom.xml @@ -33,8 +33,7 @@ - 2.15.2 - 17 + 2.16.0 \ No newline at end of file diff --git a/javafx/README.md b/javafx/README.md index 7db1478129..d6ea5b226f 100644 --- a/javafx/README.md +++ b/javafx/README.md @@ -7,4 +7,4 @@ This module contains articles about JavaFX. - [Introduction to JavaFx](https://www.baeldung.com/javafx) - [Display Custom Items in JavaFX ListView](https://www.baeldung.com/javafx-listview-display-custom-items) - [Adding EventHandler to JavaFX Button](https://www.baeldung.com/javafx-button-eventhandler) - +- [How to Use a Custom Font in Java](https://www.baeldung.com/java-custom-font) diff --git a/jhipster-6/bookstore-monolith/pom.xml b/jhipster-6/bookstore-monolith/pom.xml index efe3d2a118..0db1f46b1e 100644 --- a/jhipster-6/bookstore-monolith/pom.xml +++ b/jhipster-6/bookstore-monolith/pom.xml @@ -1125,7 +1125,6 @@ 3.0.0 - 11 2.12.6 v10.15.0 6.4.1 diff --git a/jhipster-modules/README.md b/jhipster-modules/README.md index 11c3d5397f..2aae8a5697 100644 --- a/jhipster-modules/README.md +++ b/jhipster-modules/README.md @@ -1,7 +1,5 @@ ## JHipster -This module contains articles about JHipster. - -### Relevant articles: - +This module contains articles about JHipster. +Relevant articles are listed in the nested module folders. diff --git a/jhipster-modules/jhipster-microservice/car-app/pom.xml b/jhipster-modules/jhipster-microservice/car-app/pom.xml index f345688939..069a1f6848 100644 --- a/jhipster-modules/jhipster-microservice/car-app/pom.xml +++ b/jhipster-modules/jhipster-microservice/car-app/pom.xml @@ -23,13 +23,13 @@ 0.4.13 1.2 5.2.8.Final - 2.6.0 + 5.1.0 0.7.9 1.8 3.21.0-GA 1.0.0 1.1.0 - 0.7.0 + 0.12.3 1.0.0 3.6 2.0.0 @@ -216,7 +216,7 @@ io.jsonwebtoken - jjwt + jjwt-api ${jjwt.version} diff --git a/jhipster-modules/jhipster-microservice/car-app/src/main/java/com/car/app/security/jwt/TokenProvider.java b/jhipster-modules/jhipster-microservice/car-app/src/main/java/com/car/app/security/jwt/TokenProvider.java index 3908bfa8f3..028f34e3f0 100644 --- a/jhipster-modules/jhipster-microservice/car-app/src/main/java/com/car/app/security/jwt/TokenProvider.java +++ b/jhipster-modules/jhipster-microservice/car-app/src/main/java/com/car/app/security/jwt/TokenProvider.java @@ -70,7 +70,7 @@ public class TokenProvider { public Authentication getAuthentication(String token) { Claims claims = Jwts.parser() - .setSigningKey(secretKey) + .setSigningKey(secretKey).build() .parseClaimsJws(token) .getBody(); @@ -86,7 +86,7 @@ public class TokenProvider { public boolean validateToken(String authToken) { try { - Jwts.parser().setSigningKey(secretKey).parseClaimsJws(authToken); + Jwts.parser().setSigningKey(secretKey).build().parseClaimsJws(authToken); return true; } catch (SignatureException e) { log.info("Invalid JWT signature."); diff --git a/jhipster-modules/jhipster-microservice/dealer-app/pom.xml b/jhipster-modules/jhipster-microservice/dealer-app/pom.xml index 056bd60f33..43f9b046c7 100644 --- a/jhipster-modules/jhipster-microservice/dealer-app/pom.xml +++ b/jhipster-modules/jhipster-microservice/dealer-app/pom.xml @@ -23,12 +23,12 @@ 0.4.13 1.2 5.2.8.Final - 2.6.0 + 5.1.0 0.7.9 3.21.0-GA 1.0.0 1.1.0 - 0.7.0 + 0.12.3 1.0.0 3.6 2.0.0 @@ -215,7 +215,7 @@ io.jsonwebtoken - jjwt + jjwt-api ${jjwt.version} diff --git a/jhipster-modules/jhipster-microservice/dealer-app/src/main/java/com/dealer/app/security/jwt/TokenProvider.java b/jhipster-modules/jhipster-microservice/dealer-app/src/main/java/com/dealer/app/security/jwt/TokenProvider.java index 47a5bf75af..38cee99e01 100644 --- a/jhipster-modules/jhipster-microservice/dealer-app/src/main/java/com/dealer/app/security/jwt/TokenProvider.java +++ b/jhipster-modules/jhipster-microservice/dealer-app/src/main/java/com/dealer/app/security/jwt/TokenProvider.java @@ -70,7 +70,7 @@ public class TokenProvider { public Authentication getAuthentication(String token) { Claims claims = Jwts.parser() - .setSigningKey(secretKey) + .setSigningKey(secretKey).build() .parseClaimsJws(token) .getBody(); @@ -86,7 +86,7 @@ public class TokenProvider { public boolean validateToken(String authToken) { try { - Jwts.parser().setSigningKey(secretKey).parseClaimsJws(authToken); + Jwts.parser().setSigningKey(secretKey).build().parseClaimsJws(authToken); return true; } catch (SignatureException e) { log.info("Invalid JWT signature."); diff --git a/jhipster-modules/jhipster-microservice/gateway-app/pom.xml b/jhipster-modules/jhipster-microservice/gateway-app/pom.xml index b90f22f009..90d703b8c7 100644 --- a/jhipster-modules/jhipster-microservice/gateway-app/pom.xml +++ b/jhipster-modules/jhipster-microservice/gateway-app/pom.xml @@ -26,12 +26,12 @@ 1.3 1.2 5.2.8.Final - 2.6.0 + 5.1.0 0.7.9 3.21.0-GA 1.0.0 1.1.0 - 0.7.0 + 0.12.3 1.0.0 3.6 2.0.0 @@ -243,7 +243,7 @@ io.jsonwebtoken - jjwt + jjwt-api ${jjwt.version} diff --git a/jhipster-modules/jhipster-microservice/gateway-app/src/main/java/com/gateway/security/jwt/TokenProvider.java b/jhipster-modules/jhipster-microservice/gateway-app/src/main/java/com/gateway/security/jwt/TokenProvider.java index 5ffb55f33e..14d343c0d7 100644 --- a/jhipster-modules/jhipster-microservice/gateway-app/src/main/java/com/gateway/security/jwt/TokenProvider.java +++ b/jhipster-modules/jhipster-microservice/gateway-app/src/main/java/com/gateway/security/jwt/TokenProvider.java @@ -70,7 +70,7 @@ public class TokenProvider { public Authentication getAuthentication(String token) { Claims claims = Jwts.parser() - .setSigningKey(secretKey) + .setSigningKey(secretKey).build() .parseClaimsJws(token) .getBody(); @@ -86,7 +86,7 @@ public class TokenProvider { public boolean validateToken(String authToken) { try { - Jwts.parser().setSigningKey(secretKey).parseClaimsJws(authToken); + Jwts.parser().setSigningKey(secretKey).build().parseClaimsJws(authToken); return true; } catch (SignatureException e) { log.info("Invalid JWT signature."); diff --git a/jhipster-modules/jhipster-monolithic/pom.xml b/jhipster-modules/jhipster-monolithic/pom.xml index fbcee8f1ff..f1ee479756 100644 --- a/jhipster-modules/jhipster-monolithic/pom.xml +++ b/jhipster-modules/jhipster-monolithic/pom.xml @@ -122,7 +122,7 @@ io.jsonwebtoken - jjwt + jjwt-api ${jjwt.version} @@ -892,12 +892,12 @@ 2.2.1 2.2.3 5.2.8.Final - 2.6.0 + 5.1.0 0.7.9 3.21.0-GA 1.0.0 1.1.0 - 0.7.0 + 0.12.3 1.1.3 3.6 2.0.0 diff --git a/jhipster-modules/jhipster-monolithic/src/main/java/com/baeldung/security/jwt/TokenProvider.java b/jhipster-modules/jhipster-monolithic/src/main/java/com/baeldung/security/jwt/TokenProvider.java index 3ba4d7c793..095663065b 100644 --- a/jhipster-modules/jhipster-monolithic/src/main/java/com/baeldung/security/jwt/TokenProvider.java +++ b/jhipster-modules/jhipster-monolithic/src/main/java/com/baeldung/security/jwt/TokenProvider.java @@ -70,7 +70,7 @@ public class TokenProvider { public Authentication getAuthentication(String token) { Claims claims = Jwts.parser() - .setSigningKey(secretKey) + .setSigningKey(secretKey).build() .parseClaimsJws(token) .getBody(); @@ -86,7 +86,7 @@ public class TokenProvider { public boolean validateToken(String authToken) { try { - Jwts.parser().setSigningKey(secretKey).parseClaimsJws(authToken); + Jwts.parser().setSigningKey(secretKey).build().parseClaimsJws(authToken); return true; } catch (SignatureException e) { log.info("Invalid JWT signature."); diff --git a/json-modules/gson-2/README.md b/json-modules/gson-2/README.md index 3deb61f25d..912f8b0a20 100644 --- a/json-modules/gson-2/README.md +++ b/json-modules/gson-2/README.md @@ -5,4 +5,4 @@ This module contains articles about Gson ### Relevant Articles: - [Solving Gson Parsing Errors](https://www.baeldung.com/gson-parsing-errors) - [Difference between Gson @Expose and @SerializedName](https://www.baeldung.com/gson-expose-vs-serializedname) - +- [Resolving Gson’s “Multiple JSON Fields” Exception](https://www.baeldung.com/java-gson-multiple-json-fields-exception) diff --git a/json-modules/json-conversion/src/test/java/com/baeldung/jsonnodetojsonobject/JsonNodeToJsonObjectUnitTest.java b/json-modules/json-conversion/src/test/java/com/baeldung/jsonnodetojsonobject/JsonNodeToJsonObjectUnitTest.java new file mode 100644 index 0000000000..38d097e5b8 --- /dev/null +++ b/json-modules/json-conversion/src/test/java/com/baeldung/jsonnodetojsonobject/JsonNodeToJsonObjectUnitTest.java @@ -0,0 +1,29 @@ +package com.baeldung.jsonnodetojsonobject; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.JsonNode; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class JsonNodeToJsonObjectUnitTest { + + public static String jsonString = "{\"name\": \"John\", \"gender\": \"male\", \"company\": \"Baeldung\", \"isEmployee\": true, \"age\": 30}"; + + @Test + public void givenJsonNode_whenConvertingToObjectNode_thenVerifyFieldsIntegrity() throws JsonProcessingException { + + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode jsonNode = objectMapper.readTree(jsonString); + ObjectNode objectNode = objectMapper.createObjectNode().setAll((ObjectNode) jsonNode); + + assertEquals("John", objectNode.get("name").asText()); + assertEquals("male", objectNode.get("gender").asText()); + assertEquals("Baeldung", objectNode.get("company").asText()); + assertTrue(objectNode.get("isEmployee").asBoolean()); + assertEquals(30, objectNode.get("age").asInt()); + } +} diff --git a/json-modules/json/README.md b/json-modules/json/README.md index d643914fc7..d6e1b400f5 100644 --- a/json-modules/json/README.md +++ b/json-modules/json/README.md @@ -12,4 +12,5 @@ This module contains articles about JSON. - [Iterating Over an Instance of org.json.JSONObject](https://www.baeldung.com/jsonobject-iteration) - [Escape JSON String in Java](https://www.baeldung.com/java-json-escaping) - [Reducing JSON Data Size](https://www.baeldung.com/json-reduce-data-size) +- [How to Convert JsonNode to ObjectNode](https://www.baeldung.com/java-jackson-jsonnode-objectnode) - More Articles: [[next -->]](../json-2) diff --git a/ksqldb/pom.xml b/ksqldb/pom.xml index e55398d635..ebb3bfa7ee 100644 --- a/ksqldb/pom.xml +++ b/ksqldb/pom.xml @@ -17,7 +17,7 @@ confluent confluent-repo - http://packages.confluent.io/maven/ + https://packages.confluent.io/maven/ diff --git a/kubernetes-modules/k8s-admission-controller/pom.xml b/kubernetes-modules/k8s-admission-controller/pom.xml index 18bf98a830..6a1d695f8d 100644 --- a/kubernetes-modules/k8s-admission-controller/pom.xml +++ b/kubernetes-modules/k8s-admission-controller/pom.xml @@ -22,6 +22,7 @@ org.projectlombok lombok + ${lombok.version} true @@ -32,6 +33,7 @@ io.projectreactor reactor-test + ${reactor.version} test @@ -78,4 +80,9 @@ + + 3.6.0 + + + \ No newline at end of file diff --git a/kubernetes-modules/kubernetes-spring/pom.xml b/kubernetes-modules/kubernetes-spring/pom.xml index 05532ab0b0..a9c780d59d 100644 --- a/kubernetes-modules/kubernetes-spring/pom.xml +++ b/kubernetes-modules/kubernetes-spring/pom.xml @@ -33,6 +33,7 @@ io.projectreactor reactor-test + ${reactor.version} test @@ -46,8 +47,8 @@ - - 11 - + + 3.6.0 + \ No newline at end of file diff --git a/libraries-2/README.md b/libraries-2/README.md index 8dae12a1cf..3eb788a34a 100644 --- a/libraries-2/README.md +++ b/libraries-2/README.md @@ -10,13 +10,10 @@ Remember, for advanced libraries like [Jackson](/jackson) and [JUnit](/testing-m ### Relevant articles - [A Guide to jBPM with Java](https://www.baeldung.com/jbpm-java) - [Guide to Classgraph Library](https://www.baeldung.com/classgraph) -- [Create a Java Command Line Program with Picocli](https://www.baeldung.com/java-picocli-create-command-line-program) -- [Guide to Java Parallel Collectors Library](https://www.baeldung.com/java-parallel-collectors) - [Templating with Handlebars](https://www.baeldung.com/handlebars) - [A Guide to Crawler4j](https://www.baeldung.com/crawler4j) - [Key Value Store with Chronicle Map](https://www.baeldung.com/java-chronicle-map) - [Guide to MapDB](https://www.baeldung.com/mapdb) - [A Guide to Apache Mesos](https://www.baeldung.com/apache-mesos) -- [JasperReports with Spring](https://www.baeldung.com/spring-jasper) - More articles [[<-- prev]](/libraries) [[next -->]](/libraries-3) diff --git a/libraries-2/pom.xml b/libraries-2/pom.xml index d9b0545d54..9eff129a63 100644 --- a/libraries-2/pom.xml +++ b/libraries-2/pom.xml @@ -18,11 +18,6 @@ mapdb ${mapdb.version} - - com.pivovarit - parallel-collectors - ${parallel-collectors.version} - io.github.classgraph classgraph @@ -41,11 +36,6 @@ - - info.picocli - picocli - ${picocli.version} - org.springframework.boot spring-boot-starter @@ -83,17 +73,6 @@ mesos ${mesos.library.version} - - net.sf.jasperreports - jasperreports - ${jasperreports.version} - - - commons-logging - commons-logging - - - org.hsqldb hsqldb @@ -133,14 +112,11 @@ 3.0.8 4.8.153 7.20.0.Final - 4.7.0 3.24ea1 4.4.0 2.7.8 1.11.0 - 1.1.0 4.3.1 - 6.20.0 5.3.25 2.7.1 diff --git a/libraries-3/README.md b/libraries-3/README.md index 99b1b60a0a..faef721a22 100644 --- a/libraries-3/README.md +++ b/libraries-3/README.md @@ -8,9 +8,7 @@ The code examples related to different libraries are each in their own module. Remember, for advanced libraries like [Jackson](/jackson) and [JUnit](/testing-modules) we already have separate modules. Please make sure to have a look at the existing modules in such cases. ### Relevant Articles: -- [Parsing Command-Line Parameters with JCommander](https://www.baeldung.com/jcommander-parsing-command-line-parameters) - [Guide to the Cactoos Library](https://www.baeldung.com/java-cactoos) -- [Parsing Command-Line Parameters with Airline](https://www.baeldung.com/java-airline) - [Introduction to cache2k](https://www.baeldung.com/java-cache2k) - [Introduction to the jcabi-aspects AOP Annotations Library](https://www.baeldung.com/java-jcabi-aspects) - [Introduction to Takes](https://www.baeldung.com/java-takes) diff --git a/libraries-3/pom.xml b/libraries-3/pom.xml index 9923e46267..bff0a654c6 100644 --- a/libraries-3/pom.xml +++ b/libraries-3/pom.xml @@ -13,21 +13,11 @@ - - com.beust - jcommander - ${jcommander.version} - org.projectlombok lombok ${lombok.version} - - com.github.rvesse - airline - ${airline.version} - org.cactoos cactoos @@ -125,7 +115,7 @@ javax.annotation javax.annotation-api - 1.3.2 + ${javax.annotation-api.version} @@ -159,10 +149,6 @@ org.apache.maven.plugins maven-compiler-plugin - - 11 - 11 - @@ -214,9 +200,7 @@ - 1.78 0.43 - 2.7.2 1.2.3.Final 0.22.6 1.9.20.1 @@ -233,6 +217,7 @@ 1.0.0 2.5.6 0.9.6 + 1.3.2 \ No newline at end of file diff --git a/libraries-4/README.md b/libraries-4/README.md index 0dee9f1c1e..102f17acdb 100644 --- a/libraries-4/README.md +++ b/libraries-4/README.md @@ -11,9 +11,7 @@ Remember, for advanced libraries like [Jackson](/jackson) and [JUnit](/testing-m - [Quick Guide to RSS with Rome](https://www.baeldung.com/rome-rss) - [Introduction to PCollections](https://www.baeldung.com/java-pcollections) - [Introduction to Eclipse Collections](https://www.baeldung.com/eclipse-collections) -- [DistinctBy in the Java Stream API](https://www.baeldung.com/java-streams-distinct-by) - [Introduction to NoException](https://www.baeldung.com/no-exception) -- [Spring Yarg Integration](https://www.baeldung.com/spring-yarg) - [Delete a Directory Recursively in Java](https://www.baeldung.com/java-delete-directory) - [Guide to JDeferred](https://www.baeldung.com/jdeferred) - [Introduction to MBassador](https://www.baeldung.com/mbassador) diff --git a/libraries-4/pom.xml b/libraries-4/pom.xml index 3949d50875..6b818be9c2 100644 --- a/libraries-4/pom.xml +++ b/libraries-4/pom.xml @@ -22,17 +22,6 @@ eclipse-collections ${eclipse-collections.version} - - com.haulmont.yarg - yarg - ${yarg.version} - - - org.olap4j - olap4j - - - org.olap4j olap4j @@ -68,11 +57,6 @@ servlet-api ${javax.servlet.version} - - io.vavr - vavr - ${vavr.version} - org.pcollections pcollections @@ -119,21 +103,33 @@ jackson-annotations ${jackson-annotations.version} + + io.vavr + vavr + ${vavr.version} + + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + commons-io + commons-io + ${commons-io.version} + 2.14.2 2.14.2 1.2.6 - 8.2.0 1.1.0 - 2.0.12 1.3.1 1.0 4.3.8.RELEASE 2.5 3.2.0-m7 - 0.9.0 2.1.2 3.0.0 0.6.5 @@ -142,6 +138,8 @@ 1.2.0 19 10.3.0 + 8.2.0 + 0.9.0 \ No newline at end of file diff --git a/libraries-5/README.md b/libraries-5/README.md index f1e749b293..50fb70bd05 100644 --- a/libraries-5/README.md +++ b/libraries-5/README.md @@ -9,10 +9,8 @@ Remember, for advanced libraries like [Jackson](/jackson) and [JUnit](/testing-m ### Relevant articles - [Introduction to Caffeine](https://www.baeldung.com/java-caching-caffeine) -- [Introduction to StreamEx](https://www.baeldung.com/streamex) - [A Docker Guide for Java](https://www.baeldung.com/docker-java-api) - [Introduction to Akka Actors in Java](https://www.baeldung.com/akka-actors-java) -- [A Guide to Byte Buddy](https://www.baeldung.com/byte-buddy) - [Introduction to jOOL](https://www.baeldung.com/jool) - [Consumer Driven Contracts with Pact](https://www.baeldung.com/pact-junit-consumer-driven-contracts) - [Introduction to Atlassian Fugue](https://www.baeldung.com/java-fugue) diff --git a/libraries-5/pom.xml b/libraries-5/pom.xml index a043b4bfa8..85f8896890 100644 --- a/libraries-5/pom.xml +++ b/libraries-5/pom.xml @@ -49,21 +49,6 @@ ${typesafe-akka.version} test - - one.util - streamex - ${streamex.version} - - - net.bytebuddy - byte-buddy - ${byte-buddy.version} - - - net.bytebuddy - byte-buddy-agent - ${byte-buddy.version} - com.github.docker-java @@ -139,7 +124,6 @@ 4.3.8.RELEASE 2.12 2.5.11 - 0.8.1 3.0.14 3.1.8 3.0.2 diff --git a/libraries-6/README.md b/libraries-6/README.md index bbebcbc1e0..4236a65d95 100644 --- a/libraries-6/README.md +++ b/libraries-6/README.md @@ -12,7 +12,6 @@ Remember, for advanced libraries like [Jackson](/jackson) and [JUnit](/testing-m - [Guide to Resilience4j](https://www.baeldung.com/resilience4j) - [Implementing a FTP-Client in Java](https://www.baeldung.com/java-ftp-client) - [Introduction to Functional Java](https://www.baeldung.com/java-functional-library) -- [Introduction to Protonpack](https://www.baeldung.com/java-protonpack) - [Guide to Simple Binary Encoding](https://www.baeldung.com/java-sbe) - [Java-R Integration](https://www.baeldung.com/java-r-integration) - [Using libphonenumber to Validate Phone Numbers](https://www.baeldung.com/java-libphonenumber) diff --git a/libraries-6/pom.xml b/libraries-6/pom.xml index f073ca424c..372c5b1cc7 100644 --- a/libraries-6/pom.xml +++ b/libraries-6/pom.xml @@ -17,11 +17,6 @@ functionaljava-java8 ${functionaljava.version} - - com.codepoetics - protonpack - ${protonpack.version} - io.github.resilience4j resilience4j-circuitbreaker @@ -198,7 +193,6 @@ 2.7.1 4.8.1 2.1.0 - 1.15 3.6 3.5-beta72 3.0 diff --git a/libraries-bytecode/.gitignore b/libraries-bytecode/.gitignore new file mode 100644 index 0000000000..e594daf27a --- /dev/null +++ b/libraries-bytecode/.gitignore @@ -0,0 +1,9 @@ +*.class + +# Folders # +/gensrc +/target + +# Packaged files # +*.jar +/bin/ diff --git a/libraries-bytecode/README.md b/libraries-bytecode/README.md new file mode 100644 index 0000000000..cc30511ad1 --- /dev/null +++ b/libraries-bytecode/README.md @@ -0,0 +1,9 @@ +## Server + +This module contains articles about bytecode libraries. + +### Relevant Articles: + +- [Introduction to Javassist](https://www.baeldung.com/javassist) +- [A Guide to Byte Buddy](https://www.baeldung.com/byte-buddy) +- [A Guide to Java Bytecode Manipulation with ASM](https://www.baeldung.com/java-asm) \ No newline at end of file diff --git a/libraries-bytecode/pom.xml b/libraries-bytecode/pom.xml new file mode 100644 index 0000000000..f21911d77e --- /dev/null +++ b/libraries-bytecode/pom.xml @@ -0,0 +1,85 @@ + + + 4.0.0 + libraries-bytecode + 0.0.1-SNAPSHOT + libraries-bytecode + jar + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + + + + org.javassist + javassist + ${javaassist.version} + + + net.bytebuddy + byte-buddy + ${byte-buddy.version} + + + net.bytebuddy + byte-buddy-agent + ${byte-buddy.version} + + + org.ow2.asm + asm + ${asm.version} + + + org.ow2.asm + asm-util + ${asm.version} + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + --add-exports=java.base/jdk.internal.ref=ALL-UNNAMED + --add-exports=java.base/sun.nio.ch=ALL-UNNAMED + --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED + --add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED + --add-opens=jdk.compiler/com.sun.tools.javac=ALL-UNNAMED + --add-opens=java.base/java.lang=ALL-UNNAMED + --add-opens=java.base/java.lang.reflect=ALL-UNNAMED + --add-opens=java.base/java.io=ALL-UNNAMED + --add-opens=java.base/java.util=ALL-UNNAMED + + + + + org.apache.maven.plugins + maven-jar-plugin + ${maven-jar-plugin.version} + + + + + com.baeldung.examples.asm.instrumentation.Premain + + + + + + + + + + 3.29.2-GA + 5.2 + + + \ No newline at end of file diff --git a/asm/src/main/java/com/baeldung/examples/asm/CustomClassWriter.java b/libraries-bytecode/src/main/java/com/baeldung/asm/CustomClassWriter.java similarity index 96% rename from asm/src/main/java/com/baeldung/examples/asm/CustomClassWriter.java rename to libraries-bytecode/src/main/java/com/baeldung/asm/CustomClassWriter.java index d41a1a16a3..f05a753320 100644 --- a/asm/src/main/java/com/baeldung/examples/asm/CustomClassWriter.java +++ b/libraries-bytecode/src/main/java/com/baeldung/asm/CustomClassWriter.java @@ -1,160 +1,160 @@ -package com.baeldung.examples.asm; - -import java.io.IOException; -import java.io.PrintWriter; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.objectweb.asm.ClassReader; -import org.objectweb.asm.ClassVisitor; -import org.objectweb.asm.ClassWriter; -import org.objectweb.asm.FieldVisitor; -import org.objectweb.asm.MethodVisitor; -import static org.objectweb.asm.Opcodes.ACC_PUBLIC; -import static org.objectweb.asm.Opcodes.ACC_STATIC; -import static org.objectweb.asm.Opcodes.ASM4; -import static org.objectweb.asm.Opcodes.V1_5; -import org.objectweb.asm.Type; -import org.objectweb.asm.util.TraceClassVisitor; - -/** - * - * @author baeldung - * @param - */ -public class CustomClassWriter { - - ClassReader reader; - ClassWriter writer; - AddFieldAdapter addFieldAdapter; - AddInterfaceAdapter addInterfaceAdapter; - PublicizeMethodAdapter pubMethAdapter; - final static String CLASSNAME = "java.lang.Integer"; - final static String CLONEABLE = "java/lang/Cloneable"; - - public CustomClassWriter() { - - try { - reader = new ClassReader(CLASSNAME); - writer = new ClassWriter(reader, 0); - - } catch (IOException ex) { - Logger.getLogger(CustomClassWriter.class.getName()).log(Level.SEVERE, null, ex); - } - } - - public CustomClassWriter(byte[] contents) { - reader = new ClassReader(contents); - writer = new ClassWriter(reader, 0); - } - - public static void main(String[] args) { - CustomClassWriter ccw = new CustomClassWriter(); - ccw.publicizeMethod(); - } - - public byte[] addField() { - addFieldAdapter = new AddFieldAdapter("aNewBooleanField", org.objectweb.asm.Opcodes.ACC_PUBLIC, writer); - reader.accept(addFieldAdapter, 0); - return writer.toByteArray(); - } - - public byte[] publicizeMethod() { - pubMethAdapter = new PublicizeMethodAdapter(writer); - reader.accept(pubMethAdapter, 0); - return writer.toByteArray(); - } - - public byte[] addInterface() { - addInterfaceAdapter = new AddInterfaceAdapter(writer); - reader.accept(addInterfaceAdapter, 0); - return writer.toByteArray(); - } - - public class AddInterfaceAdapter extends ClassVisitor { - - public AddInterfaceAdapter(ClassVisitor cv) { - super(ASM4, cv); - } - - @Override - public void visit(int version, int access, String name, - String signature, String superName, String[] interfaces) { - String[] holding = new String[interfaces.length + 1]; - holding[holding.length - 1] = CLONEABLE; - System.arraycopy(interfaces, 0, holding, 0, interfaces.length); - - cv.visit(V1_5, access, name, signature, superName, holding); - } - - } - - public class PublicizeMethodAdapter extends ClassVisitor { - - final Logger logger = Logger.getLogger("PublicizeMethodAdapter"); - TraceClassVisitor tracer; - PrintWriter pw = new PrintWriter(System.out); - - public PublicizeMethodAdapter(ClassVisitor cv) { - super(ASM4, cv); - this.cv = cv; - tracer = new TraceClassVisitor(cv, pw); - } - - @Override - public MethodVisitor visitMethod(int access, - String name, - String desc, - String signature, - String[] exceptions) { - - if (name.equals("toUnsignedString0")) { - logger.info("Visiting unsigned method"); - return tracer.visitMethod(ACC_PUBLIC + ACC_STATIC, name, desc, signature, exceptions); - } - return tracer.visitMethod(access, name, desc, signature, exceptions); - - } - - public void visitEnd() { - tracer.visitEnd(); - System.out.println(tracer.p.getText()); - } - - } - - public class AddFieldAdapter extends ClassVisitor { - - String fieldName; - int access; - boolean isFieldPresent; - - public AddFieldAdapter(String fieldName, int access, ClassVisitor cv) { - super(ASM4, cv); - this.cv = cv; - this.access = access; - this.fieldName = fieldName; - } - - @Override - public FieldVisitor visitField(int access, String name, String desc, - String signature, Object value) { - if (name.equals(fieldName)) { - isFieldPresent = true; - } - return cv.visitField(access, name, desc, signature, value); - } - - @Override - public void visitEnd() { - if (!isFieldPresent) { - FieldVisitor fv = cv.visitField(access, fieldName, Type.BOOLEAN_TYPE.toString(), null, null); - if (fv != null) { - fv.visitEnd(); - } - } - cv.visitEnd(); - } - - } - -} +package com.baeldung.asm; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.objectweb.asm.ClassReader; +import org.objectweb.asm.ClassVisitor; +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.FieldVisitor; +import org.objectweb.asm.MethodVisitor; +import static org.objectweb.asm.Opcodes.ACC_PUBLIC; +import static org.objectweb.asm.Opcodes.ACC_STATIC; +import static org.objectweb.asm.Opcodes.ASM4; +import static org.objectweb.asm.Opcodes.V1_5; +import org.objectweb.asm.Type; +import org.objectweb.asm.util.TraceClassVisitor; + +/** + * + * @author baeldung + * @param + */ +public class CustomClassWriter { + + ClassReader reader; + ClassWriter writer; + AddFieldAdapter addFieldAdapter; + AddInterfaceAdapter addInterfaceAdapter; + PublicizeMethodAdapter pubMethAdapter; + final static String CLASSNAME = "java.lang.Integer"; + final static String CLONEABLE = "java/lang/Cloneable"; + + public CustomClassWriter() { + + try { + reader = new ClassReader(CLASSNAME); + writer = new ClassWriter(reader, 0); + + } catch (IOException ex) { + Logger.getLogger(CustomClassWriter.class.getName()).log(Level.SEVERE, null, ex); + } + } + + public CustomClassWriter(byte[] contents) { + reader = new ClassReader(contents); + writer = new ClassWriter(reader, 0); + } + + public static void main(String[] args) { + CustomClassWriter ccw = new CustomClassWriter(); + ccw.publicizeMethod(); + } + + public byte[] addField() { + addFieldAdapter = new AddFieldAdapter("aNewBooleanField", org.objectweb.asm.Opcodes.ACC_PUBLIC, writer); + reader.accept(addFieldAdapter, 0); + return writer.toByteArray(); + } + + public byte[] publicizeMethod() { + pubMethAdapter = new PublicizeMethodAdapter(writer); + reader.accept(pubMethAdapter, 0); + return writer.toByteArray(); + } + + public byte[] addInterface() { + addInterfaceAdapter = new AddInterfaceAdapter(writer); + reader.accept(addInterfaceAdapter, 0); + return writer.toByteArray(); + } + + public class AddInterfaceAdapter extends ClassVisitor { + + public AddInterfaceAdapter(ClassVisitor cv) { + super(ASM4, cv); + } + + @Override + public void visit(int version, int access, String name, + String signature, String superName, String[] interfaces) { + String[] holding = new String[interfaces.length + 1]; + holding[holding.length - 1] = CLONEABLE; + System.arraycopy(interfaces, 0, holding, 0, interfaces.length); + + cv.visit(V1_5, access, name, signature, superName, holding); + } + + } + + public class PublicizeMethodAdapter extends ClassVisitor { + + final Logger logger = Logger.getLogger("PublicizeMethodAdapter"); + TraceClassVisitor tracer; + PrintWriter pw = new PrintWriter(System.out); + + public PublicizeMethodAdapter(ClassVisitor cv) { + super(ASM4, cv); + this.cv = cv; + tracer = new TraceClassVisitor(cv, pw); + } + + @Override + public MethodVisitor visitMethod(int access, + String name, + String desc, + String signature, + String[] exceptions) { + + if (name.equals("toUnsignedString0")) { + logger.info("Visiting unsigned method"); + return tracer.visitMethod(ACC_PUBLIC + ACC_STATIC, name, desc, signature, exceptions); + } + return tracer.visitMethod(access, name, desc, signature, exceptions); + + } + + public void visitEnd() { + tracer.visitEnd(); + System.out.println(tracer.p.getText()); + } + + } + + public class AddFieldAdapter extends ClassVisitor { + + String fieldName; + int access; + boolean isFieldPresent; + + public AddFieldAdapter(String fieldName, int access, ClassVisitor cv) { + super(ASM4, cv); + this.cv = cv; + this.access = access; + this.fieldName = fieldName; + } + + @Override + public FieldVisitor visitField(int access, String name, String desc, + String signature, Object value) { + if (name.equals(fieldName)) { + isFieldPresent = true; + } + return cv.visitField(access, name, desc, signature, value); + } + + @Override + public void visitEnd() { + if (!isFieldPresent) { + FieldVisitor fv = cv.visitField(access, fieldName, Type.BOOLEAN_TYPE.toString(), null, null); + if (fv != null) { + fv.visitEnd(); + } + } + cv.visitEnd(); + } + + } + +} diff --git a/asm/src/main/java/com/baeldung/examples/asm/instrumentation/Premain.java b/libraries-bytecode/src/main/java/com/baeldung/asm/instrumentation/Premain.java similarity index 88% rename from asm/src/main/java/com/baeldung/examples/asm/instrumentation/Premain.java rename to libraries-bytecode/src/main/java/com/baeldung/asm/instrumentation/Premain.java index a3e69b6785..502137bd3d 100644 --- a/asm/src/main/java/com/baeldung/examples/asm/instrumentation/Premain.java +++ b/libraries-bytecode/src/main/java/com/baeldung/asm/instrumentation/Premain.java @@ -1,6 +1,6 @@ -package com.baeldung.examples.asm.instrumentation; +package com.baeldung.asm.instrumentation; -import com.baeldung.examples.asm.CustomClassWriter; +import com.baeldung.asm.CustomClassWriter; import java.lang.instrument.ClassFileTransformer; import java.lang.instrument.IllegalClassFormatException; import java.lang.instrument.Instrumentation; diff --git a/libraries-5/src/main/java/com/baeldung/bytebuddy/Bar.java b/libraries-bytecode/src/main/java/com/baeldung/bytebuddy/Bar.java similarity index 100% rename from libraries-5/src/main/java/com/baeldung/bytebuddy/Bar.java rename to libraries-bytecode/src/main/java/com/baeldung/bytebuddy/Bar.java diff --git a/libraries-5/src/main/java/com/baeldung/bytebuddy/Foo.java b/libraries-bytecode/src/main/java/com/baeldung/bytebuddy/Foo.java similarity index 100% rename from libraries-5/src/main/java/com/baeldung/bytebuddy/Foo.java rename to libraries-bytecode/src/main/java/com/baeldung/bytebuddy/Foo.java diff --git a/libraries/src/main/java/com/baeldung/javasisst/Point.java b/libraries-bytecode/src/main/java/com/baeldung/javasisst/Point.java similarity index 100% rename from libraries/src/main/java/com/baeldung/javasisst/Point.java rename to libraries-bytecode/src/main/java/com/baeldung/javasisst/Point.java diff --git a/libraries/src/main/java/com/baeldung/javasisst/ThreeDimensionalPoint.java b/libraries-bytecode/src/main/java/com/baeldung/javasisst/ThreeDimensionalPoint.java similarity index 100% rename from libraries/src/main/java/com/baeldung/javasisst/ThreeDimensionalPoint.java rename to libraries-bytecode/src/main/java/com/baeldung/javasisst/ThreeDimensionalPoint.java diff --git a/asm/src/main/resources/logback.xml b/libraries-bytecode/src/main/resources/logback.xml similarity index 100% rename from asm/src/main/resources/logback.xml rename to libraries-bytecode/src/main/resources/logback.xml diff --git a/libraries-5/src/test/java/com/baeldung/bytebuddy/ByteBuddyUnitTest.java b/libraries-bytecode/src/test/java/com/baeldung/bytebuddy/ByteBuddyUnitTest.java similarity index 93% rename from libraries-5/src/test/java/com/baeldung/bytebuddy/ByteBuddyUnitTest.java rename to libraries-bytecode/src/test/java/com/baeldung/bytebuddy/ByteBuddyUnitTest.java index 5f721025c3..398e873223 100644 --- a/libraries-5/src/test/java/com/baeldung/bytebuddy/ByteBuddyUnitTest.java +++ b/libraries-bytecode/src/test/java/com/baeldung/bytebuddy/ByteBuddyUnitTest.java @@ -1,5 +1,16 @@ package com.baeldung.bytebuddy; +import static net.bytebuddy.matcher.ElementMatchers.isDeclaredBy; +import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.returns; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; + +import org.junit.Test; + import net.bytebuddy.ByteBuddy; import net.bytebuddy.agent.ByteBuddyAgent; import net.bytebuddy.dynamic.DynamicType; @@ -8,14 +19,6 @@ import net.bytebuddy.dynamic.loading.ClassReloadingStrategy; import net.bytebuddy.implementation.FixedValue; import net.bytebuddy.implementation.MethodDelegation; import net.bytebuddy.matcher.ElementMatchers; -import org.junit.Test; - -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; - -import static net.bytebuddy.matcher.ElementMatchers.*; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; public class ByteBuddyUnitTest { diff --git a/libraries/src/test/java/com/baeldung/javassist/JavasisstUnitTest.java b/libraries-bytecode/src/test/java/com/baeldung/javassist/JavasisstUnitTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/javassist/JavasisstUnitTest.java rename to libraries-bytecode/src/test/java/com/baeldung/javassist/JavasisstUnitTest.java diff --git a/libraries-cli/.gitignore b/libraries-cli/.gitignore new file mode 100644 index 0000000000..e594daf27a --- /dev/null +++ b/libraries-cli/.gitignore @@ -0,0 +1,9 @@ +*.class + +# Folders # +/gensrc +/target + +# Packaged files # +*.jar +/bin/ diff --git a/libraries-cli/README.md b/libraries-cli/README.md new file mode 100644 index 0000000000..b31bb2853d --- /dev/null +++ b/libraries-cli/README.md @@ -0,0 +1,9 @@ +## Server + +This module contains articles about cli libraries. + +### Relevant Articles: + +- [Create a Java Command Line Program with Picocli](https://www.baeldung.com/java-picocli-create-command-line-program) +- [Parsing Command-Line Parameters with JCommander](https://www.baeldung.com/jcommander-parsing-command-line-parameters) +- [Parsing Command-Line Parameters with Airline](https://www.baeldung.com/java-airline) \ No newline at end of file diff --git a/libraries-cli/pom.xml b/libraries-cli/pom.xml new file mode 100644 index 0000000000..d204f3c735 --- /dev/null +++ b/libraries-cli/pom.xml @@ -0,0 +1,69 @@ + + + 4.0.0 + libraries-cli + 0.0.1-SNAPSHOT + libraries-cli + jar + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + + + + org.springframework.boot + spring-boot-starter + ${spring-boot-starter.version} + + + org.springframework + spring-context + ${spring.version} + + + org.springframework + spring-jdbc + ${spring.version} + + + info.picocli + picocli + ${picocli.version} + + + com.beust + jcommander + ${jcommander.version} + + + com.github.rvesse + airline + ${airline.version} + + + org.projectlombok + lombok + ${lombok.version} + + + + + + + + + + + 4.7.0 + 1.78 + 2.7.2 + 2.7.8 + 5.3.25 + + + \ No newline at end of file diff --git a/libraries-3/src/main/java/com/baeldung/airline/CommandLine.java b/libraries-cli/src/main/java/com/baeldung/airline/CommandLine.java similarity index 100% rename from libraries-3/src/main/java/com/baeldung/airline/CommandLine.java rename to libraries-cli/src/main/java/com/baeldung/airline/CommandLine.java diff --git a/libraries-3/src/main/java/com/baeldung/airline/DatabaseSetupCommand.java b/libraries-cli/src/main/java/com/baeldung/airline/DatabaseSetupCommand.java similarity index 100% rename from libraries-3/src/main/java/com/baeldung/airline/DatabaseSetupCommand.java rename to libraries-cli/src/main/java/com/baeldung/airline/DatabaseSetupCommand.java diff --git a/libraries-3/src/main/java/com/baeldung/airline/LoggingCommand.java b/libraries-cli/src/main/java/com/baeldung/airline/LoggingCommand.java similarity index 100% rename from libraries-3/src/main/java/com/baeldung/airline/LoggingCommand.java rename to libraries-cli/src/main/java/com/baeldung/airline/LoggingCommand.java diff --git a/libraries-3/src/main/java/com/baeldung/jcommander/helloworld/HelloWorldApp.java b/libraries-cli/src/main/java/com/baeldung/jcommander/helloworld/HelloWorldApp.java similarity index 100% rename from libraries-3/src/main/java/com/baeldung/jcommander/helloworld/HelloWorldApp.java rename to libraries-cli/src/main/java/com/baeldung/jcommander/helloworld/HelloWorldApp.java diff --git a/libraries-3/src/main/java/com/baeldung/jcommander/usagebilling/UsageBasedBillingApp.java b/libraries-cli/src/main/java/com/baeldung/jcommander/usagebilling/UsageBasedBillingApp.java similarity index 100% rename from libraries-3/src/main/java/com/baeldung/jcommander/usagebilling/UsageBasedBillingApp.java rename to libraries-cli/src/main/java/com/baeldung/jcommander/usagebilling/UsageBasedBillingApp.java diff --git a/libraries-3/src/main/java/com/baeldung/jcommander/usagebilling/cli/FetchCurrentChargesCommand.java b/libraries-cli/src/main/java/com/baeldung/jcommander/usagebilling/cli/FetchCurrentChargesCommand.java similarity index 99% rename from libraries-3/src/main/java/com/baeldung/jcommander/usagebilling/cli/FetchCurrentChargesCommand.java rename to libraries-cli/src/main/java/com/baeldung/jcommander/usagebilling/cli/FetchCurrentChargesCommand.java index ea6b18af53..a28066ac3d 100644 --- a/libraries-3/src/main/java/com/baeldung/jcommander/usagebilling/cli/FetchCurrentChargesCommand.java +++ b/libraries-cli/src/main/java/com/baeldung/jcommander/usagebilling/cli/FetchCurrentChargesCommand.java @@ -1,5 +1,10 @@ package com.baeldung.jcommander.usagebilling.cli; +import static com.baeldung.jcommander.usagebilling.cli.UsageBasedBilling.FETCH_CMD; +import static com.baeldung.jcommander.usagebilling.service.FetchCurrentChargesService.getDefault; + +import java.util.List; + import com.baeldung.jcommander.usagebilling.cli.splitter.ColonParameterSplitter; import com.baeldung.jcommander.usagebilling.cli.validator.UUIDValidator; import com.baeldung.jcommander.usagebilling.model.CurrentChargesRequest; @@ -7,13 +12,9 @@ import com.baeldung.jcommander.usagebilling.model.CurrentChargesResponse; import com.baeldung.jcommander.usagebilling.service.FetchCurrentChargesService; import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; + import lombok.Getter; -import java.util.List; - -import static com.baeldung.jcommander.usagebilling.cli.UsageBasedBilling.*; -import static com.baeldung.jcommander.usagebilling.service.FetchCurrentChargesService.getDefault; - @Parameters( commandNames = { FETCH_CMD }, commandDescription = "Fetch charges for a customer in the current month, can be itemized or aggregated" diff --git a/libraries-3/src/main/java/com/baeldung/jcommander/usagebilling/cli/SubmitUsageCommand.java b/libraries-cli/src/main/java/com/baeldung/jcommander/usagebilling/cli/SubmitUsageCommand.java similarity index 99% rename from libraries-3/src/main/java/com/baeldung/jcommander/usagebilling/cli/SubmitUsageCommand.java rename to libraries-cli/src/main/java/com/baeldung/jcommander/usagebilling/cli/SubmitUsageCommand.java index d3516b19d3..5c12ac665c 100644 --- a/libraries-3/src/main/java/com/baeldung/jcommander/usagebilling/cli/SubmitUsageCommand.java +++ b/libraries-cli/src/main/java/com/baeldung/jcommander/usagebilling/cli/SubmitUsageCommand.java @@ -1,5 +1,11 @@ package com.baeldung.jcommander.usagebilling.cli; +import static com.baeldung.jcommander.usagebilling.cli.UsageBasedBilling.SUBMIT_CMD; +import static com.baeldung.jcommander.usagebilling.service.SubmitUsageService.getDefault; + +import java.math.BigDecimal; +import java.time.Instant; + import com.baeldung.jcommander.usagebilling.cli.converter.ISO8601TimestampConverter; import com.baeldung.jcommander.usagebilling.cli.validator.UUIDValidator; import com.baeldung.jcommander.usagebilling.model.UsageRequest; @@ -7,14 +13,9 @@ import com.baeldung.jcommander.usagebilling.model.UsageRequest.PricingType; import com.baeldung.jcommander.usagebilling.service.SubmitUsageService; import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; + import lombok.Getter; -import java.math.BigDecimal; -import java.time.Instant; - -import static com.baeldung.jcommander.usagebilling.cli.UsageBasedBilling.*; -import static com.baeldung.jcommander.usagebilling.service.SubmitUsageService.getDefault; - @Parameters( commandNames = { SUBMIT_CMD }, commandDescription = "Submit usage for a given customer and subscription, accepts one usage item" diff --git a/libraries-3/src/main/java/com/baeldung/jcommander/usagebilling/cli/UsageBasedBilling.java b/libraries-cli/src/main/java/com/baeldung/jcommander/usagebilling/cli/UsageBasedBilling.java similarity index 100% rename from libraries-3/src/main/java/com/baeldung/jcommander/usagebilling/cli/UsageBasedBilling.java rename to libraries-cli/src/main/java/com/baeldung/jcommander/usagebilling/cli/UsageBasedBilling.java diff --git a/libraries-3/src/main/java/com/baeldung/jcommander/usagebilling/cli/converter/ISO8601TimestampConverter.java b/libraries-cli/src/main/java/com/baeldung/jcommander/usagebilling/cli/converter/ISO8601TimestampConverter.java similarity index 100% rename from libraries-3/src/main/java/com/baeldung/jcommander/usagebilling/cli/converter/ISO8601TimestampConverter.java rename to libraries-cli/src/main/java/com/baeldung/jcommander/usagebilling/cli/converter/ISO8601TimestampConverter.java index e54865a811..c173f62684 100644 --- a/libraries-3/src/main/java/com/baeldung/jcommander/usagebilling/cli/converter/ISO8601TimestampConverter.java +++ b/libraries-cli/src/main/java/com/baeldung/jcommander/usagebilling/cli/converter/ISO8601TimestampConverter.java @@ -1,7 +1,6 @@ package com.baeldung.jcommander.usagebilling.cli.converter; -import com.beust.jcommander.ParameterException; -import com.beust.jcommander.converters.BaseConverter; +import static java.lang.String.format; import java.time.Instant; import java.time.LocalDateTime; @@ -9,7 +8,8 @@ import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; -import static java.lang.String.format; +import com.beust.jcommander.ParameterException; +import com.beust.jcommander.converters.BaseConverter; public class ISO8601TimestampConverter extends BaseConverter { diff --git a/libraries-3/src/main/java/com/baeldung/jcommander/usagebilling/cli/splitter/ColonParameterSplitter.java b/libraries-cli/src/main/java/com/baeldung/jcommander/usagebilling/cli/splitter/ColonParameterSplitter.java similarity index 100% rename from libraries-3/src/main/java/com/baeldung/jcommander/usagebilling/cli/splitter/ColonParameterSplitter.java rename to libraries-cli/src/main/java/com/baeldung/jcommander/usagebilling/cli/splitter/ColonParameterSplitter.java index f24c028123..1e73b54045 100644 --- a/libraries-3/src/main/java/com/baeldung/jcommander/usagebilling/cli/splitter/ColonParameterSplitter.java +++ b/libraries-cli/src/main/java/com/baeldung/jcommander/usagebilling/cli/splitter/ColonParameterSplitter.java @@ -1,10 +1,10 @@ package com.baeldung.jcommander.usagebilling.cli.splitter; -import com.beust.jcommander.converters.IParameterSplitter; +import static java.util.Arrays.asList; import java.util.List; -import static java.util.Arrays.asList; +import com.beust.jcommander.converters.IParameterSplitter; public class ColonParameterSplitter implements IParameterSplitter { diff --git a/libraries-3/src/main/java/com/baeldung/jcommander/usagebilling/cli/validator/UUIDValidator.java b/libraries-cli/src/main/java/com/baeldung/jcommander/usagebilling/cli/validator/UUIDValidator.java similarity index 100% rename from libraries-3/src/main/java/com/baeldung/jcommander/usagebilling/cli/validator/UUIDValidator.java rename to libraries-cli/src/main/java/com/baeldung/jcommander/usagebilling/cli/validator/UUIDValidator.java index a72912f7d0..f8d9f81203 100644 --- a/libraries-3/src/main/java/com/baeldung/jcommander/usagebilling/cli/validator/UUIDValidator.java +++ b/libraries-cli/src/main/java/com/baeldung/jcommander/usagebilling/cli/validator/UUIDValidator.java @@ -1,10 +1,10 @@ package com.baeldung.jcommander.usagebilling.cli.validator; +import java.util.regex.Pattern; + import com.beust.jcommander.IParameterValidator; import com.beust.jcommander.ParameterException; -import java.util.regex.Pattern; - public class UUIDValidator implements IParameterValidator { private static final String UUID_REGEX = diff --git a/libraries-3/src/main/java/com/baeldung/jcommander/usagebilling/model/CurrentChargesRequest.java b/libraries-cli/src/main/java/com/baeldung/jcommander/usagebilling/model/CurrentChargesRequest.java similarity index 70% rename from libraries-3/src/main/java/com/baeldung/jcommander/usagebilling/model/CurrentChargesRequest.java rename to libraries-cli/src/main/java/com/baeldung/jcommander/usagebilling/model/CurrentChargesRequest.java index 93dd7a5732..c57805b784 100644 --- a/libraries-3/src/main/java/com/baeldung/jcommander/usagebilling/model/CurrentChargesRequest.java +++ b/libraries-cli/src/main/java/com/baeldung/jcommander/usagebilling/model/CurrentChargesRequest.java @@ -1,9 +1,13 @@ package com.baeldung.jcommander.usagebilling.model; -import lombok.*; - import java.util.List; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + @NoArgsConstructor(access = AccessLevel.PACKAGE) @AllArgsConstructor(access = AccessLevel.PACKAGE) @Builder diff --git a/libraries-3/src/main/java/com/baeldung/jcommander/usagebilling/model/CurrentChargesResponse.java b/libraries-cli/src/main/java/com/baeldung/jcommander/usagebilling/model/CurrentChargesResponse.java similarity index 91% rename from libraries-3/src/main/java/com/baeldung/jcommander/usagebilling/model/CurrentChargesResponse.java rename to libraries-cli/src/main/java/com/baeldung/jcommander/usagebilling/model/CurrentChargesResponse.java index 865a6e4a3d..46fb86ba78 100644 --- a/libraries-3/src/main/java/com/baeldung/jcommander/usagebilling/model/CurrentChargesResponse.java +++ b/libraries-cli/src/main/java/com/baeldung/jcommander/usagebilling/model/CurrentChargesResponse.java @@ -1,11 +1,15 @@ package com.baeldung.jcommander.usagebilling.model; -import lombok.*; - import java.math.BigDecimal; import java.math.RoundingMode; import java.util.List; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + @NoArgsConstructor(access = AccessLevel.PACKAGE) @AllArgsConstructor(access = AccessLevel.PACKAGE) @Builder diff --git a/libraries-3/src/main/java/com/baeldung/jcommander/usagebilling/model/UsageRequest.java b/libraries-cli/src/main/java/com/baeldung/jcommander/usagebilling/model/UsageRequest.java similarity index 89% rename from libraries-3/src/main/java/com/baeldung/jcommander/usagebilling/model/UsageRequest.java rename to libraries-cli/src/main/java/com/baeldung/jcommander/usagebilling/model/UsageRequest.java index 2785474acf..07da8ee4b5 100644 --- a/libraries-3/src/main/java/com/baeldung/jcommander/usagebilling/model/UsageRequest.java +++ b/libraries-cli/src/main/java/com/baeldung/jcommander/usagebilling/model/UsageRequest.java @@ -1,10 +1,14 @@ package com.baeldung.jcommander.usagebilling.model; -import lombok.*; - import java.math.BigDecimal; import java.time.Instant; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + @NoArgsConstructor(access = AccessLevel.PACKAGE) @AllArgsConstructor(access = AccessLevel.PACKAGE) @Builder diff --git a/libraries-3/src/main/java/com/baeldung/jcommander/usagebilling/service/DefaultFetchCurrentChargesService.java b/libraries-cli/src/main/java/com/baeldung/jcommander/usagebilling/service/DefaultFetchCurrentChargesService.java similarity index 100% rename from libraries-3/src/main/java/com/baeldung/jcommander/usagebilling/service/DefaultFetchCurrentChargesService.java rename to libraries-cli/src/main/java/com/baeldung/jcommander/usagebilling/service/DefaultFetchCurrentChargesService.java index 6436d49875..e1c5e25856 100644 --- a/libraries-3/src/main/java/com/baeldung/jcommander/usagebilling/service/DefaultFetchCurrentChargesService.java +++ b/libraries-cli/src/main/java/com/baeldung/jcommander/usagebilling/service/DefaultFetchCurrentChargesService.java @@ -1,13 +1,5 @@ package com.baeldung.jcommander.usagebilling.service; -import com.baeldung.jcommander.usagebilling.model.CurrentChargesRequest; -import com.baeldung.jcommander.usagebilling.model.CurrentChargesResponse; -import com.baeldung.jcommander.usagebilling.model.CurrentChargesResponse.LineItem; - -import java.math.BigDecimal; -import java.util.List; -import java.util.UUID; - import static java.lang.String.format; import static java.util.Arrays.asList; import static java.util.Arrays.fill; @@ -15,6 +7,14 @@ import static java.util.Collections.emptyList; import static java.util.concurrent.ThreadLocalRandom.current; import static java.util.stream.Collectors.toList; +import java.math.BigDecimal; +import java.util.List; +import java.util.UUID; + +import com.baeldung.jcommander.usagebilling.model.CurrentChargesRequest; +import com.baeldung.jcommander.usagebilling.model.CurrentChargesResponse; +import com.baeldung.jcommander.usagebilling.model.CurrentChargesResponse.LineItem; + class DefaultFetchCurrentChargesService implements FetchCurrentChargesService { @Override diff --git a/libraries-3/src/main/java/com/baeldung/jcommander/usagebilling/service/DefaultSubmitUsageService.java b/libraries-cli/src/main/java/com/baeldung/jcommander/usagebilling/service/DefaultSubmitUsageService.java similarity index 100% rename from libraries-3/src/main/java/com/baeldung/jcommander/usagebilling/service/DefaultSubmitUsageService.java rename to libraries-cli/src/main/java/com/baeldung/jcommander/usagebilling/service/DefaultSubmitUsageService.java index 44ac9e9ed7..fb214c9ab9 100644 --- a/libraries-3/src/main/java/com/baeldung/jcommander/usagebilling/service/DefaultSubmitUsageService.java +++ b/libraries-cli/src/main/java/com/baeldung/jcommander/usagebilling/service/DefaultSubmitUsageService.java @@ -1,9 +1,9 @@ package com.baeldung.jcommander.usagebilling.service; -import com.baeldung.jcommander.usagebilling.model.UsageRequest; - import java.util.UUID; +import com.baeldung.jcommander.usagebilling.model.UsageRequest; + class DefaultSubmitUsageService implements SubmitUsageService { @Override diff --git a/libraries-3/src/main/java/com/baeldung/jcommander/usagebilling/service/FetchCurrentChargesService.java b/libraries-cli/src/main/java/com/baeldung/jcommander/usagebilling/service/FetchCurrentChargesService.java similarity index 100% rename from libraries-3/src/main/java/com/baeldung/jcommander/usagebilling/service/FetchCurrentChargesService.java rename to libraries-cli/src/main/java/com/baeldung/jcommander/usagebilling/service/FetchCurrentChargesService.java diff --git a/libraries-3/src/main/java/com/baeldung/jcommander/usagebilling/service/SubmitUsageService.java b/libraries-cli/src/main/java/com/baeldung/jcommander/usagebilling/service/SubmitUsageService.java similarity index 100% rename from libraries-3/src/main/java/com/baeldung/jcommander/usagebilling/service/SubmitUsageService.java rename to libraries-cli/src/main/java/com/baeldung/jcommander/usagebilling/service/SubmitUsageService.java diff --git a/libraries-2/src/main/java/com/baeldung/picocli/git/Application.java b/libraries-cli/src/main/java/com/baeldung/picocli/git/Application.java similarity index 99% rename from libraries-2/src/main/java/com/baeldung/picocli/git/Application.java rename to libraries-cli/src/main/java/com/baeldung/picocli/git/Application.java index 04af524e45..80c132d637 100644 --- a/libraries-2/src/main/java/com/baeldung/picocli/git/Application.java +++ b/libraries-cli/src/main/java/com/baeldung/picocli/git/Application.java @@ -1,13 +1,15 @@ package com.baeldung.picocli.git; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + import com.baeldung.picocli.git.commands.programmative.GitCommand; import com.baeldung.picocli.git.commands.subcommands.GitAddCommand; import com.baeldung.picocli.git.commands.subcommands.GitCommitCommand; import com.baeldung.picocli.git.commands.subcommands.GitConfigCommand; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; + import picocli.CommandLine; @SpringBootApplication diff --git a/libraries-2/src/main/java/com/baeldung/picocli/git/commands/declarative/GitCommand.java b/libraries-cli/src/main/java/com/baeldung/picocli/git/commands/declarative/GitCommand.java similarity index 99% rename from libraries-2/src/main/java/com/baeldung/picocli/git/commands/declarative/GitCommand.java rename to libraries-cli/src/main/java/com/baeldung/picocli/git/commands/declarative/GitCommand.java index f3c690a3e6..fbd7907eb8 100644 --- a/libraries-2/src/main/java/com/baeldung/picocli/git/commands/declarative/GitCommand.java +++ b/libraries-cli/src/main/java/com/baeldung/picocli/git/commands/declarative/GitCommand.java @@ -1,14 +1,15 @@ package com.baeldung.picocli.git.commands.declarative; -import com.baeldung.picocli.git.model.ConfigElement; -import com.baeldung.picocli.git.commands.subcommands.GitAddCommand; -import com.baeldung.picocli.git.commands.subcommands.GitCommitCommand; -import com.baeldung.picocli.git.commands.subcommands.GitConfigCommand; -import picocli.CommandLine; - import static picocli.CommandLine.*; import static picocli.CommandLine.Command; +import com.baeldung.picocli.git.commands.subcommands.GitAddCommand; +import com.baeldung.picocli.git.commands.subcommands.GitCommitCommand; +import com.baeldung.picocli.git.commands.subcommands.GitConfigCommand; +import com.baeldung.picocli.git.model.ConfigElement; + +import picocli.CommandLine; + @Command( name = "git", subcommands = { diff --git a/libraries-2/src/main/java/com/baeldung/picocli/git/commands/methods/GitCommand.java b/libraries-cli/src/main/java/com/baeldung/picocli/git/commands/methods/GitCommand.java similarity index 100% rename from libraries-2/src/main/java/com/baeldung/picocli/git/commands/methods/GitCommand.java rename to libraries-cli/src/main/java/com/baeldung/picocli/git/commands/methods/GitCommand.java index 2c3e440b8b..74993a50fe 100644 --- a/libraries-2/src/main/java/com/baeldung/picocli/git/commands/methods/GitCommand.java +++ b/libraries-cli/src/main/java/com/baeldung/picocli/git/commands/methods/GitCommand.java @@ -1,9 +1,9 @@ package com.baeldung.picocli.git.commands.methods; -import picocli.CommandLine; - import static picocli.CommandLine.Command; +import picocli.CommandLine; + @Command(name = "git") public class GitCommand implements Runnable { public static void main(String[] args) { diff --git a/libraries-2/src/main/java/com/baeldung/picocli/git/commands/programmative/GitCommand.java b/libraries-cli/src/main/java/com/baeldung/picocli/git/commands/programmative/GitCommand.java similarity index 99% rename from libraries-2/src/main/java/com/baeldung/picocli/git/commands/programmative/GitCommand.java rename to libraries-cli/src/main/java/com/baeldung/picocli/git/commands/programmative/GitCommand.java index 81ecfd78be..fabd0e4cc7 100644 --- a/libraries-2/src/main/java/com/baeldung/picocli/git/commands/programmative/GitCommand.java +++ b/libraries-cli/src/main/java/com/baeldung/picocli/git/commands/programmative/GitCommand.java @@ -1,13 +1,15 @@ package com.baeldung.picocli.git.commands.programmative; -import com.baeldung.picocli.git.commands.subcommands.GitAddCommand; -import com.baeldung.picocli.git.commands.subcommands.GitCommitCommand; -import org.springframework.stereotype.Component; -import picocli.CommandLine; - import static picocli.CommandLine.Command; import static picocli.CommandLine.RunLast; +import org.springframework.stereotype.Component; + +import com.baeldung.picocli.git.commands.subcommands.GitAddCommand; +import com.baeldung.picocli.git.commands.subcommands.GitCommitCommand; + +import picocli.CommandLine; + @Command(name = "git") @Component public class GitCommand implements Runnable { diff --git a/libraries-2/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitAddCommand.java b/libraries-cli/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitAddCommand.java similarity index 100% rename from libraries-2/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitAddCommand.java rename to libraries-cli/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitAddCommand.java index 803cd8dc7d..f87e55a5cc 100644 --- a/libraries-2/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitAddCommand.java +++ b/libraries-cli/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitAddCommand.java @@ -1,11 +1,11 @@ package com.baeldung.picocli.git.commands.subcommands; -import org.springframework.stereotype.Component; +import static picocli.CommandLine.*; import java.nio.file.Path; import java.util.List; -import static picocli.CommandLine.*; +import org.springframework.stereotype.Component; @Command( name = "add" diff --git a/libraries-2/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitCommitCommand.java b/libraries-cli/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitCommitCommand.java similarity index 100% rename from libraries-2/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitCommitCommand.java rename to libraries-cli/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitCommitCommand.java index df4928983c..f2136f9c39 100644 --- a/libraries-2/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitCommitCommand.java +++ b/libraries-cli/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitCommitCommand.java @@ -1,10 +1,10 @@ package com.baeldung.picocli.git.commands.subcommands; -import org.springframework.stereotype.Component; - import static picocli.CommandLine.Command; import static picocli.CommandLine.Option; +import org.springframework.stereotype.Component; + @Command( name = "commit" ) diff --git a/libraries-2/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitConfigCommand.java b/libraries-cli/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitConfigCommand.java similarity index 99% rename from libraries-2/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitConfigCommand.java rename to libraries-cli/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitConfigCommand.java index 80e14c0121..6ba803140a 100644 --- a/libraries-2/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitConfigCommand.java +++ b/libraries-cli/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitConfigCommand.java @@ -1,11 +1,12 @@ package com.baeldung.picocli.git.commands.subcommands; -import com.baeldung.picocli.git.model.ConfigElement; -import org.springframework.stereotype.Component; - import static picocli.CommandLine.Command; import static picocli.CommandLine.Parameters; +import org.springframework.stereotype.Component; + +import com.baeldung.picocli.git.model.ConfigElement; + @Command( name = "config" ) diff --git a/libraries-2/src/main/java/com/baeldung/picocli/git/model/ConfigElement.java b/libraries-cli/src/main/java/com/baeldung/picocli/git/model/ConfigElement.java similarity index 100% rename from libraries-2/src/main/java/com/baeldung/picocli/git/model/ConfigElement.java rename to libraries-cli/src/main/java/com/baeldung/picocli/git/model/ConfigElement.java diff --git a/libraries-2/src/main/java/com/baeldung/picocli/helloworld/HelloWorldCommand.java b/libraries-cli/src/main/java/com/baeldung/picocli/helloworld/HelloWorldCommand.java similarity index 100% rename from libraries-2/src/main/java/com/baeldung/picocli/helloworld/HelloWorldCommand.java rename to libraries-cli/src/main/java/com/baeldung/picocli/helloworld/HelloWorldCommand.java index 97a861e2f0..2df8ac0a5b 100644 --- a/libraries-2/src/main/java/com/baeldung/picocli/helloworld/HelloWorldCommand.java +++ b/libraries-cli/src/main/java/com/baeldung/picocli/helloworld/HelloWorldCommand.java @@ -1,9 +1,9 @@ package com.baeldung.picocli.helloworld; -import picocli.CommandLine; - import static picocli.CommandLine.Command; +import picocli.CommandLine; + @Command( name = "hello", description = "Says hello" diff --git a/libraries-cli/src/main/resources/logback.xml b/libraries-cli/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/libraries-cli/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/libraries-3/src/test/java/com/baeldung/jcommander/helloworld/HelloWorldAppUnitTest.java b/libraries-cli/src/test/java/com/baeldung/jcommander/helloworld/HelloWorldAppUnitTest.java similarity index 99% rename from libraries-3/src/test/java/com/baeldung/jcommander/helloworld/HelloWorldAppUnitTest.java rename to libraries-cli/src/test/java/com/baeldung/jcommander/helloworld/HelloWorldAppUnitTest.java index 48b3ac2896..c73e8e9d48 100644 --- a/libraries-3/src/test/java/com/baeldung/jcommander/helloworld/HelloWorldAppUnitTest.java +++ b/libraries-cli/src/test/java/com/baeldung/jcommander/helloworld/HelloWorldAppUnitTest.java @@ -1,9 +1,10 @@ package com.baeldung.jcommander.helloworld; -import com.beust.jcommander.JCommander; +import static org.junit.Assert.assertEquals; + import org.junit.Test; -import static org.junit.Assert.assertEquals; +import com.beust.jcommander.JCommander; public class HelloWorldAppUnitTest { diff --git a/libraries-3/src/test/java/com/baeldung/jcommander/usagebilling/cli/FetchCurrentChargesCommandUnitTest.java b/libraries-cli/src/test/java/com/baeldung/jcommander/usagebilling/cli/FetchCurrentChargesCommandUnitTest.java similarity index 99% rename from libraries-3/src/test/java/com/baeldung/jcommander/usagebilling/cli/FetchCurrentChargesCommandUnitTest.java rename to libraries-cli/src/test/java/com/baeldung/jcommander/usagebilling/cli/FetchCurrentChargesCommandUnitTest.java index b639661c39..aba4585f6e 100644 --- a/libraries-3/src/test/java/com/baeldung/jcommander/usagebilling/cli/FetchCurrentChargesCommandUnitTest.java +++ b/libraries-cli/src/test/java/com/baeldung/jcommander/usagebilling/cli/FetchCurrentChargesCommandUnitTest.java @@ -1,11 +1,12 @@ package com.baeldung.jcommander.usagebilling.cli; -import com.beust.jcommander.JCommander; -import org.junit.Test; - import static org.hamcrest.collection.IsIterableContainingInOrder.contains; import static org.junit.Assert.assertThat; +import org.junit.Test; + +import com.beust.jcommander.JCommander; + public class FetchCurrentChargesCommandUnitTest { private JCommander jc = JCommander.newBuilder() diff --git a/libraries-3/src/test/java/com/baeldung/jcommander/usagebilling/cli/SubmitUsageCommandUnitTest.java b/libraries-cli/src/test/java/com/baeldung/jcommander/usagebilling/cli/SubmitUsageCommandUnitTest.java similarity index 95% rename from libraries-3/src/test/java/com/baeldung/jcommander/usagebilling/cli/SubmitUsageCommandUnitTest.java rename to libraries-cli/src/test/java/com/baeldung/jcommander/usagebilling/cli/SubmitUsageCommandUnitTest.java index d6ce132053..a4d8273638 100644 --- a/libraries-3/src/test/java/com/baeldung/jcommander/usagebilling/cli/SubmitUsageCommandUnitTest.java +++ b/libraries-cli/src/test/java/com/baeldung/jcommander/usagebilling/cli/SubmitUsageCommandUnitTest.java @@ -1,12 +1,11 @@ package com.baeldung.jcommander.usagebilling.cli; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.Test; + import com.beust.jcommander.JCommander; import com.beust.jcommander.ParameterException; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; public class SubmitUsageCommandUnitTest { diff --git a/libraries-data-db/pom.xml b/libraries-data-db/pom.xml index ed184d72e0..6ee8daa2a5 100644 --- a/libraries-data-db/pom.xml +++ b/libraries-data-db/pom.xml @@ -152,6 +152,7 @@ org.projectlombok lombok + ${lombok.version} io.ebean @@ -299,7 +300,7 @@ 6.0.0-release 6.0.1 3.2.1 - 5.0.1 + 5.1.0 13.15.2 2.1.3.Final 2.2.3 diff --git a/libraries-data-io/pom.xml b/libraries-data-io/pom.xml index c8d895b4e5..9fc2814312 100644 --- a/libraries-data-io/pom.xml +++ b/libraries-data-io/pom.xml @@ -98,7 +98,7 @@ - 1.21 + 2.2 4.0.1 1.7.0 5.8 diff --git a/libraries-data-io/src/test/java/com/baeldung/libraries/snakeyaml/YAMLToJavaDeserialisationUnitTest.java b/libraries-data-io/src/test/java/com/baeldung/libraries/snakeyaml/YAMLToJavaDeserialisationUnitTest.java index 6f32f143a9..4c92bf41e1 100644 --- a/libraries-data-io/src/test/java/com/baeldung/libraries/snakeyaml/YAMLToJavaDeserialisationUnitTest.java +++ b/libraries-data-io/src/test/java/com/baeldung/libraries/snakeyaml/YAMLToJavaDeserialisationUnitTest.java @@ -1,15 +1,19 @@ package com.baeldung.libraries.snakeyaml; -import org.junit.Test; -import org.yaml.snakeyaml.TypeDescription; -import org.yaml.snakeyaml.Yaml; -import org.yaml.snakeyaml.constructor.Constructor; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import java.io.InputStream; import java.util.Date; import java.util.Map; -import static org.junit.Assert.*; +import org.junit.Test; +import org.yaml.snakeyaml.LoaderOptions; +import org.yaml.snakeyaml.TypeDescription; +import org.yaml.snakeyaml.Yaml; +import org.yaml.snakeyaml.constructor.Constructor; +import org.yaml.snakeyaml.inspector.TagInspector; public class YAMLToJavaDeserialisationUnitTest { @@ -27,7 +31,7 @@ public class YAMLToJavaDeserialisationUnitTest { @Test public void whenLoadYAMLDocumentWithTopLevelClass_thenLoadCorrectJavaObject() { - Yaml yaml = new Yaml(new Constructor(Customer.class)); + Yaml yaml = new Yaml(new Constructor(Customer.class,new LoaderOptions())); InputStream inputStream = this.getClass() .getClassLoader() .getResourceAsStream("yaml/customer.yaml"); @@ -39,7 +43,11 @@ public class YAMLToJavaDeserialisationUnitTest { @Test public void whenLoadYAMLDocumentWithAssumedClass_thenLoadCorrectJavaObject() { - Yaml yaml = new Yaml(); + LoaderOptions loaderoptions = new LoaderOptions(); + TagInspector taginspector = tag -> tag.getClassName() + .equals(Customer.class.getName()); + loaderoptions.setTagInspector(taginspector); + Yaml yaml = new Yaml(new Constructor(Customer.class, loaderoptions)); InputStream inputStream = this.getClass() .getClassLoader() .getResourceAsStream("yaml/customer_with_type.yaml"); @@ -61,7 +69,7 @@ public class YAMLToJavaDeserialisationUnitTest { @Test public void whenLoadYAMLDocumentWithTopLevelClass_thenLoadCorrectJavaObjectWithNestedObjects() { - Yaml yaml = new Yaml(new Constructor(Customer.class)); + Yaml yaml = new Yaml(new Constructor(Customer.class, new LoaderOptions())); InputStream inputStream = this.getClass() .getClassLoader() .getResourceAsStream("yaml/customer_with_contact_details_and_address.yaml"); @@ -91,7 +99,7 @@ public class YAMLToJavaDeserialisationUnitTest { @Test public void whenLoadYAMLDocumentWithTypeDescription_thenLoadCorrectJavaObjectWithCorrectGenericType() { - Constructor constructor = new Constructor(Customer.class); + Constructor constructor = new Constructor(Customer.class, new LoaderOptions()); TypeDescription customTypeDescription = new TypeDescription(Customer.class); customTypeDescription.addPropertyParameters("contactDetails", Contact.class); constructor.addTypeDescription(customTypeDescription); @@ -116,7 +124,7 @@ public class YAMLToJavaDeserialisationUnitTest { @Test public void whenLoadMultipleYAMLDocuments_thenLoadCorrectJavaObjects() { - Yaml yaml = new Yaml(new Constructor(Customer.class)); + Yaml yaml = new Yaml(new Constructor(Customer.class, new LoaderOptions())); InputStream inputStream = this.getClass() .getClassLoader() .getResourceAsStream("yaml/customers.yaml"); diff --git a/libraries-http-2/pom.xml b/libraries-http-2/pom.xml index b49e4b9387..5e803cde8a 100644 --- a/libraries-http-2/pom.xml +++ b/libraries-http-2/pom.xml @@ -118,7 +118,7 @@ 2.3.0 5.1.9.RELEASE 1.0.3 - 3.2.12.RELEASE + 3.6.0 1.49 diff --git a/libraries-reporting/.gitignore b/libraries-reporting/.gitignore new file mode 100644 index 0000000000..e594daf27a --- /dev/null +++ b/libraries-reporting/.gitignore @@ -0,0 +1,9 @@ +*.class + +# Folders # +/gensrc +/target + +# Packaged files # +*.jar +/bin/ diff --git a/libraries-reporting/README.md b/libraries-reporting/README.md new file mode 100644 index 0000000000..6d405911ab --- /dev/null +++ b/libraries-reporting/README.md @@ -0,0 +1,8 @@ +## Server + +This module contains articles about reporting libraries. + +### Relevant Articles: + +- [JasperReports with Spring](https://www.baeldung.com/spring-jasper) +- [Spring Yarg Integration](https://www.baeldung.com/spring-yarg) \ No newline at end of file diff --git a/libraries-reporting/pom.xml b/libraries-reporting/pom.xml new file mode 100644 index 0000000000..526f187af8 --- /dev/null +++ b/libraries-reporting/pom.xml @@ -0,0 +1,75 @@ + + + 4.0.0 + libraries-reporting + 0.0.1-SNAPSHOT + libraries-reporting + jar + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + + + + org.springframework.boot + spring-boot-starter + ${spring-boot-starter.version} + + + org.springframework + spring-web + ${spring.version} + + + org.springframework + spring-context + ${spring.version} + + + org.springframework + spring-jdbc + ${spring.version} + + + javax.servlet + servlet-api + ${javax.servlet.version} + + + net.sf.jasperreports + jasperreports + ${jasperreports.version} + + + commons-logging + commons-logging + + + + + com.haulmont.yarg + yarg + ${yarg.version} + + + org.olap4j + olap4j + + + + + + + 2.7.8 + 5.3.25 + 2.5 + 6.20.0 + 2.0.12 + + + \ No newline at end of file diff --git a/libraries-2/src/main/java/com/baeldung/jasperreports/Main.java b/libraries-reporting/src/main/java/com/baeldung/jasperreports/Main.java similarity index 100% rename from libraries-2/src/main/java/com/baeldung/jasperreports/Main.java rename to libraries-reporting/src/main/java/com/baeldung/jasperreports/Main.java diff --git a/libraries-2/src/main/java/com/baeldung/jasperreports/SimpleReportExporter.java b/libraries-reporting/src/main/java/com/baeldung/jasperreports/SimpleReportExporter.java similarity index 100% rename from libraries-2/src/main/java/com/baeldung/jasperreports/SimpleReportExporter.java rename to libraries-reporting/src/main/java/com/baeldung/jasperreports/SimpleReportExporter.java diff --git a/libraries-2/src/main/java/com/baeldung/jasperreports/SimpleReportFiller.java b/libraries-reporting/src/main/java/com/baeldung/jasperreports/SimpleReportFiller.java similarity index 100% rename from libraries-2/src/main/java/com/baeldung/jasperreports/SimpleReportFiller.java rename to libraries-reporting/src/main/java/com/baeldung/jasperreports/SimpleReportFiller.java diff --git a/libraries-2/src/main/java/com/baeldung/jasperreports/config/JasperRerportsSimpleConfig.java b/libraries-reporting/src/main/java/com/baeldung/jasperreports/config/JasperRerportsSimpleConfig.java similarity index 100% rename from libraries-2/src/main/java/com/baeldung/jasperreports/config/JasperRerportsSimpleConfig.java rename to libraries-reporting/src/main/java/com/baeldung/jasperreports/config/JasperRerportsSimpleConfig.java diff --git a/libraries-4/src/main/java/com/baeldung/yarg/DocumentController.java b/libraries-reporting/src/main/java/com/baeldung/yarg/DocumentController.java similarity index 99% rename from libraries-4/src/main/java/com/baeldung/yarg/DocumentController.java rename to libraries-reporting/src/main/java/com/baeldung/yarg/DocumentController.java index ff0d452108..9ae9b61ad1 100644 --- a/libraries-4/src/main/java/com/baeldung/yarg/DocumentController.java +++ b/libraries-reporting/src/main/java/com/baeldung/yarg/DocumentController.java @@ -5,6 +5,16 @@ */ package com.baeldung.yarg; +import java.io.File; +import java.io.IOException; + +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.io.FileUtils; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + import com.haulmont.yarg.formatters.factory.DefaultFormatterFactory; import com.haulmont.yarg.loaders.factory.DefaultLoaderFactory; import com.haulmont.yarg.loaders.impl.JsonDataLoader; @@ -16,13 +26,6 @@ import com.haulmont.yarg.structure.ReportOutputType; import com.haulmont.yarg.structure.impl.BandBuilder; import com.haulmont.yarg.structure.impl.ReportBuilder; import com.haulmont.yarg.structure.impl.ReportTemplateBuilder; -import java.io.File; -import java.io.IOException; -import javax.servlet.http.HttpServletResponse; -import org.apache.commons.io.FileUtils; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RestController; @RestController public class DocumentController { diff --git a/libraries-2/src/main/resources/employee-schema.sql b/libraries-reporting/src/main/resources/employee-schema.sql similarity index 100% rename from libraries-2/src/main/resources/employee-schema.sql rename to libraries-reporting/src/main/resources/employee-schema.sql diff --git a/libraries-2/src/main/resources/employeeEmailReport.jrxml b/libraries-reporting/src/main/resources/employeeEmailReport.jrxml similarity index 100% rename from libraries-2/src/main/resources/employeeEmailReport.jrxml rename to libraries-reporting/src/main/resources/employeeEmailReport.jrxml diff --git a/libraries-2/src/main/resources/employeeReport.jrxml b/libraries-reporting/src/main/resources/employeeReport.jrxml similarity index 100% rename from libraries-2/src/main/resources/employeeReport.jrxml rename to libraries-reporting/src/main/resources/employeeReport.jrxml diff --git a/libraries-reporting/src/main/resources/logback.xml b/libraries-reporting/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/libraries-reporting/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/libraries-stream/.gitignore b/libraries-stream/.gitignore new file mode 100644 index 0000000000..e594daf27a --- /dev/null +++ b/libraries-stream/.gitignore @@ -0,0 +1,9 @@ +*.class + +# Folders # +/gensrc +/target + +# Packaged files # +*.jar +/bin/ diff --git a/libraries-stream/README.md b/libraries-stream/README.md new file mode 100644 index 0000000000..6aa5a28cd9 --- /dev/null +++ b/libraries-stream/README.md @@ -0,0 +1,11 @@ +## Server + +This module contains articles about stream libraries. + +### Relevant Articles: + +- [Merging Streams in Java](https://www.baeldung.com/java-merge-streams) +- [Guide to Java Parallel Collectors Library](https://www.baeldung.com/java-parallel-collectors) +- [DistinctBy in the Java Stream API](https://www.baeldung.com/java-streams-distinct-by) +- [Introduction to StreamEx](https://www.baeldung.com/streamex) +- [Introduction to Protonpack](https://www.baeldung.com/java-protonpack) \ No newline at end of file diff --git a/libraries-stream/pom.xml b/libraries-stream/pom.xml new file mode 100644 index 0000000000..8f00be3dab --- /dev/null +++ b/libraries-stream/pom.xml @@ -0,0 +1,59 @@ + + + 4.0.0 + libraries-stream + 0.0.1-SNAPSHOT + libraries-stream + jar + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + + + + org.jooq + jool + ${jool.version} + + + com.pivovarit + parallel-collectors + ${parallel-collectors.version} + + + io.vavr + vavr + ${vavr.version} + + + org.eclipse.collections + eclipse-collections + ${eclipse-collections.version} + + + one.util + streamex + ${streamex.version} + + + com.codepoetics + protonpack + ${protonpack.version} + + + + + 0.9.12 + 1.1.0 + 0.9.0 + 8.2.0 + 0.8.1 + 1.15 + + + \ No newline at end of file diff --git a/libraries-4/src/main/java/com/baeldung/distinct/DistinctWithJavaFunction.java b/libraries-stream/src/main/java/com/baeldung/distinct/DistinctWithJavaFunction.java similarity index 100% rename from libraries-4/src/main/java/com/baeldung/distinct/DistinctWithJavaFunction.java rename to libraries-stream/src/main/java/com/baeldung/distinct/DistinctWithJavaFunction.java diff --git a/libraries-4/src/main/java/com/baeldung/distinct/Person.java b/libraries-stream/src/main/java/com/baeldung/distinct/Person.java similarity index 100% rename from libraries-4/src/main/java/com/baeldung/distinct/Person.java rename to libraries-stream/src/main/java/com/baeldung/distinct/Person.java diff --git a/libraries-5/src/main/java/com/baeldung/streamex/Role.java b/libraries-stream/src/main/java/com/baeldung/streamex/Role.java similarity index 100% rename from libraries-5/src/main/java/com/baeldung/streamex/Role.java rename to libraries-stream/src/main/java/com/baeldung/streamex/Role.java diff --git a/libraries-5/src/main/java/com/baeldung/streamex/StreamEX.java b/libraries-stream/src/main/java/com/baeldung/streamex/StreamEX.java similarity index 99% rename from libraries-5/src/main/java/com/baeldung/streamex/StreamEX.java rename to libraries-stream/src/main/java/com/baeldung/streamex/StreamEX.java index 56a3860f05..989b65bef6 100644 --- a/libraries-5/src/main/java/com/baeldung/streamex/StreamEX.java +++ b/libraries-stream/src/main/java/com/baeldung/streamex/StreamEX.java @@ -7,6 +7,7 @@ import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; + import one.util.streamex.DoubleStreamEx; import one.util.streamex.EntryStream; import one.util.streamex.IntStreamEx; diff --git a/libraries-5/src/main/java/com/baeldung/streamex/User.java b/libraries-stream/src/main/java/com/baeldung/streamex/User.java similarity index 100% rename from libraries-5/src/main/java/com/baeldung/streamex/User.java rename to libraries-stream/src/main/java/com/baeldung/streamex/User.java diff --git a/libraries-stream/src/main/resources/logback.xml b/libraries-stream/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/libraries-stream/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/libraries-4/src/test/java/com/baeldung/distinct/DistinctWithEclipseCollectionsUnitTest.java b/libraries-stream/src/test/java/com/baeldung/distinct/DistinctWithEclipseCollectionsUnitTest.java similarity index 100% rename from libraries-4/src/test/java/com/baeldung/distinct/DistinctWithEclipseCollectionsUnitTest.java rename to libraries-stream/src/test/java/com/baeldung/distinct/DistinctWithEclipseCollectionsUnitTest.java diff --git a/libraries-4/src/test/java/com/baeldung/distinct/DistinctWithJavaFunctionUnitTest.java b/libraries-stream/src/test/java/com/baeldung/distinct/DistinctWithJavaFunctionUnitTest.java similarity index 100% rename from libraries-4/src/test/java/com/baeldung/distinct/DistinctWithJavaFunctionUnitTest.java rename to libraries-stream/src/test/java/com/baeldung/distinct/DistinctWithJavaFunctionUnitTest.java index 936fd3e839..196c6603dd 100644 --- a/libraries-4/src/test/java/com/baeldung/distinct/DistinctWithJavaFunctionUnitTest.java +++ b/libraries-stream/src/test/java/com/baeldung/distinct/DistinctWithJavaFunctionUnitTest.java @@ -1,7 +1,7 @@ package com.baeldung.distinct; -import static org.junit.Assert.assertTrue; import static com.baeldung.distinct.DistinctWithJavaFunction.distinctByKey; +import static org.junit.Assert.assertTrue; import java.util.List; import java.util.stream.Collectors; diff --git a/libraries-4/src/test/java/com/baeldung/distinct/DistinctWithStreamexUnitTest.java b/libraries-stream/src/test/java/com/baeldung/distinct/DistinctWithStreamexUnitTest.java similarity index 100% rename from libraries-4/src/test/java/com/baeldung/distinct/DistinctWithStreamexUnitTest.java rename to libraries-stream/src/test/java/com/baeldung/distinct/DistinctWithStreamexUnitTest.java diff --git a/libraries-4/src/test/java/com/baeldung/distinct/DistinctWithVavrUnitTest.java b/libraries-stream/src/test/java/com/baeldung/distinct/DistinctWithVavrUnitTest.java similarity index 100% rename from libraries-4/src/test/java/com/baeldung/distinct/DistinctWithVavrUnitTest.java rename to libraries-stream/src/test/java/com/baeldung/distinct/DistinctWithVavrUnitTest.java diff --git a/libraries-4/src/test/java/com/baeldung/distinct/PersonDataGenerator.java b/libraries-stream/src/test/java/com/baeldung/distinct/PersonDataGenerator.java similarity index 100% rename from libraries-4/src/test/java/com/baeldung/distinct/PersonDataGenerator.java rename to libraries-stream/src/test/java/com/baeldung/distinct/PersonDataGenerator.java diff --git a/libraries-2/src/test/java/com/baeldung/parallel_collectors/ParallelCollectorsUnitTest.java b/libraries-stream/src/test/java/com/baeldung/parallel_collectors/ParallelCollectorsUnitTest.java similarity index 100% rename from libraries-2/src/test/java/com/baeldung/parallel_collectors/ParallelCollectorsUnitTest.java rename to libraries-stream/src/test/java/com/baeldung/parallel_collectors/ParallelCollectorsUnitTest.java diff --git a/libraries-6/src/test/java/com/baeldung/protonpack/ProtonpackUnitTest.java b/libraries-stream/src/test/java/com/baeldung/protonpack/ProtonpackUnitTest.java similarity index 99% rename from libraries-6/src/test/java/com/baeldung/protonpack/ProtonpackUnitTest.java rename to libraries-stream/src/test/java/com/baeldung/protonpack/ProtonpackUnitTest.java index c28248e52c..ed5fec254d 100644 --- a/libraries-6/src/test/java/com/baeldung/protonpack/ProtonpackUnitTest.java +++ b/libraries-stream/src/test/java/com/baeldung/protonpack/ProtonpackUnitTest.java @@ -1,11 +1,9 @@ package com.baeldung.protonpack; -import com.codepoetics.protonpack.Indexed; -import com.codepoetics.protonpack.StreamUtils; -import com.codepoetics.protonpack.collectors.CollectorUtils; -import com.codepoetics.protonpack.collectors.NonUniqueValueException; -import com.codepoetics.protonpack.selectors.Selectors; -import org.junit.Test; +import static java.util.Arrays.asList; +import static java.util.Arrays.stream; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import java.util.List; import java.util.Optional; @@ -13,10 +11,13 @@ import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; -import static java.util.Arrays.asList; -import static java.util.Arrays.stream; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import org.junit.Test; + +import com.codepoetics.protonpack.Indexed; +import com.codepoetics.protonpack.StreamUtils; +import com.codepoetics.protonpack.collectors.CollectorUtils; +import com.codepoetics.protonpack.collectors.NonUniqueValueException; +import com.codepoetics.protonpack.selectors.Selectors; public class ProtonpackUnitTest { @Test diff --git a/libraries/src/test/java/com/baeldung/stream/JoolMergeStreamsUnitTest.java b/libraries-stream/src/test/java/com/baeldung/stream/JoolMergeStreamsUnitTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/stream/JoolMergeStreamsUnitTest.java rename to libraries-stream/src/test/java/com/baeldung/stream/JoolMergeStreamsUnitTest.java diff --git a/libraries/src/test/java/com/baeldung/stream/MergeStreamsUnitTest.java b/libraries-stream/src/test/java/com/baeldung/stream/MergeStreamsUnitTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/stream/MergeStreamsUnitTest.java rename to libraries-stream/src/test/java/com/baeldung/stream/MergeStreamsUnitTest.java diff --git a/libraries-5/src/test/java/com/baeldung/streamex/StreamExMergeStreamsUnitTest.java b/libraries-stream/src/test/java/com/baeldung/streamex/StreamExMergeStreamsUnitTest.java similarity index 99% rename from libraries-5/src/test/java/com/baeldung/streamex/StreamExMergeStreamsUnitTest.java rename to libraries-stream/src/test/java/com/baeldung/streamex/StreamExMergeStreamsUnitTest.java index b267eaea9b..de474b825c 100644 --- a/libraries-5/src/test/java/com/baeldung/streamex/StreamExMergeStreamsUnitTest.java +++ b/libraries-stream/src/test/java/com/baeldung/streamex/StreamExMergeStreamsUnitTest.java @@ -1,13 +1,14 @@ package com.baeldung.streamex; -import one.util.streamex.StreamEx; -import org.junit.Test; +import static org.junit.Assert.assertEquals; import java.util.Arrays; import java.util.stream.Collectors; import java.util.stream.Stream; -import static org.junit.Assert.assertEquals; +import org.junit.Test; + +import one.util.streamex.StreamEx; public class StreamExMergeStreamsUnitTest { diff --git a/libraries/README.md b/libraries/README.md index 33c40ea67c..a8aa34973b 100644 --- a/libraries/README.md +++ b/libraries/README.md @@ -10,9 +10,7 @@ Remember, for advanced libraries like [Jackson](/jackson) and [JUnit](/testing-m ### Relevant articles - [Introduction to Javatuples](https://www.baeldung.com/java-tuples) -- [Introduction to Javassist](https://www.baeldung.com/javassist) - [Intro to JaVers](https://www.baeldung.com/javers) -- [Merging Streams in Java](https://www.baeldung.com/java-merge-streams) - [Introduction to Quartz](https://www.baeldung.com/quartz) - [How to Warm Up the JVM](https://www.baeldung.com/java-jvm-warmup) - [Software Transactional Memory in Java Using Multiverse](https://www.baeldung.com/java-multiverse-stm) diff --git a/libraries/pom.xml b/libraries/pom.xml index 07a4853728..756f455f4b 100644 --- a/libraries/pom.xml +++ b/libraries/pom.xml @@ -40,11 +40,6 @@ javatuples ${javatuples.version} - - org.javassist - javassist - ${javaassist.version} - org.javers javers-core @@ -120,11 +115,6 @@ quartz ${quartz.version} - - org.jooq - jool - ${jool.version} - org.openjdk.jmh jmh-core @@ -289,8 +279,6 @@ 4.3.8.RELEASE 3.0.3 2.3.0 - 3.29.2-GA - 0.9.12 3.6 2.6 diff --git a/lightrun/lightrun-api-service/pom.xml b/lightrun/lightrun-api-service/pom.xml index b7ed5f951b..77dbbb8b99 100644 --- a/lightrun/lightrun-api-service/pom.xml +++ b/lightrun/lightrun-api-service/pom.xml @@ -40,8 +40,4 @@ - - 17 - - \ No newline at end of file diff --git a/lightrun/lightrun-tasks-service/pom.xml b/lightrun/lightrun-tasks-service/pom.xml index 2689a9794d..773c81a9d5 100644 --- a/lightrun/lightrun-tasks-service/pom.xml +++ b/lightrun/lightrun-tasks-service/pom.xml @@ -65,8 +65,4 @@ - - 17 - - \ No newline at end of file diff --git a/lightrun/lightrun-users-service/pom.xml b/lightrun/lightrun-users-service/pom.xml index 40594db725..0b3e856069 100644 --- a/lightrun/lightrun-users-service/pom.xml +++ b/lightrun/lightrun-users-service/pom.xml @@ -57,8 +57,4 @@ - - 17 - - \ No newline at end of file diff --git a/logging-modules/logback/pom.xml b/logging-modules/logback/pom.xml index 8df95c18bb..fbd180c74d 100644 --- a/logging-modules/logback/pom.xml +++ b/logging-modules/logback/pom.xml @@ -121,7 +121,6 @@ 2.0.0 1.4.8 2.0.4 - 1.18.22 \ No newline at end of file diff --git a/maven-modules/maven-exec-plugin/pom.xml b/maven-modules/maven-exec-plugin/pom.xml index 1bac52ae2c..370b344167 100644 --- a/maven-modules/maven-exec-plugin/pom.xml +++ b/maven-modules/maven-exec-plugin/pom.xml @@ -47,7 +47,6 @@ 1.2.6 3.11.0 3.1.0 - 1.8 \ No newline at end of file diff --git a/maven-modules/maven-generate-war/pom.xml b/maven-modules/maven-generate-war/pom.xml index 7de3f15298..d73ffe8b1d 100644 --- a/maven-modules/maven-generate-war/pom.xml +++ b/maven-modules/maven-generate-war/pom.xml @@ -70,10 +70,7 @@ - 11 2.17.1 - 11 - 11 \ No newline at end of file diff --git a/messaging-modules/pom.xml b/messaging-modules/pom.xml index 27524637ab..f96d57b960 100644 --- a/messaging-modules/pom.xml +++ b/messaging-modules/pom.xml @@ -20,8 +20,8 @@ jgroups rabbitmq spring-amqp - spring-apache-camel - spring-jms + + postgres-notify diff --git a/messaging-modules/postgres-notify/pom.xml b/messaging-modules/postgres-notify/pom.xml index 876519f40c..a9b930543b 100644 --- a/messaging-modules/postgres-notify/pom.xml +++ b/messaging-modules/postgres-notify/pom.xml @@ -41,13 +41,11 @@ org.projectlombok lombok true + ${lombok.version} - - 1.8 - diff --git a/messaging-modules/postgres-notify/src/main/java/com/baeldung/messaging/postgresql/controller/OrdersController.java b/messaging-modules/postgres-notify/src/main/java/com/baeldung/messaging/postgresql/controller/OrdersController.java index 70daa14abd..4a1db320dc 100644 --- a/messaging-modules/postgres-notify/src/main/java/com/baeldung/messaging/postgresql/controller/OrdersController.java +++ b/messaging-modules/postgres-notify/src/main/java/com/baeldung/messaging/postgresql/controller/OrdersController.java @@ -42,7 +42,7 @@ public class OrdersController { public ResponseEntity getOrderById(@PathVariable Long id) { Optional o = orders.findById(id); - if (o.isEmpty()) { + if (!o.isPresent()) { return ResponseEntity.notFound().build(); } diff --git a/messaging-modules/postgres-notify/src/main/java/com/baeldung/messaging/postgresql/service/NotificationHandler.java b/messaging-modules/postgres-notify/src/main/java/com/baeldung/messaging/postgresql/service/NotificationHandler.java index 61b970f3a2..da333b89ff 100644 --- a/messaging-modules/postgres-notify/src/main/java/com/baeldung/messaging/postgresql/service/NotificationHandler.java +++ b/messaging-modules/postgres-notify/src/main/java/com/baeldung/messaging/postgresql/service/NotificationHandler.java @@ -23,7 +23,7 @@ public class NotificationHandler implements Consumer{ public void accept(PGNotification t) { log.info("Notification received: pid={}, name={}, param={}",t.getPID(),t.getName(),t.getParameter()); Optional order = orders.findById(Long.valueOf(t.getParameter())); - if ( !order.isEmpty()) { + if ( order.isPresent()) { log.info("order details: {}", order.get()); } } diff --git a/messaging-modules/postgres-notify/src/main/java/com/baeldung/messaging/postgresql/service/OrdersService.java b/messaging-modules/postgres-notify/src/main/java/com/baeldung/messaging/postgresql/service/OrdersService.java index cc369c1f3e..038c2f6492 100644 --- a/messaging-modules/postgres-notify/src/main/java/com/baeldung/messaging/postgresql/service/OrdersService.java +++ b/messaging-modules/postgres-notify/src/main/java/com/baeldung/messaging/postgresql/service/OrdersService.java @@ -43,14 +43,14 @@ public class OrdersService { @Transactional(readOnly = true) public Optional findById(Long id) { Optional o = Optional.ofNullable(ordersCache.get(id, Order.class)); - if ( !o.isEmpty() ) { + if ( o.isPresent() ) { log.info("findById: cache hit, id={}",id); return o; } log.info("findById: cache miss, id={}",id); o = repo.findById(id); - if ( o.isEmpty()) { + if ( !o.isPresent()) { return o; } diff --git a/netflix-modules/mantis/pom.xml b/netflix-modules/mantis/pom.xml index 351f079481..ed57eed01e 100644 --- a/netflix-modules/mantis/pom.xml +++ b/netflix-modules/mantis/pom.xml @@ -43,6 +43,7 @@ org.projectlombok lombok + ${lombok.version} org.springframework diff --git a/parent-boot-3/pom.xml b/parent-boot-3/pom.xml index 9f9d6f7901..f1ab699c83 100644 --- a/parent-boot-3/pom.xml +++ b/parent-boot-3/pom.xml @@ -233,9 +233,6 @@ 3.1.5 5.8.2 0.9.17 - 17 - ${java.version} - ${java.version} 1.4.4 2.0.3 diff --git a/patterns-modules/axon/pom.xml b/patterns-modules/axon/pom.xml index 473a1b0e15..4d83f8f9e6 100644 --- a/patterns-modules/axon/pom.xml +++ b/patterns-modules/axon/pom.xml @@ -51,6 +51,7 @@ io.projectreactor reactor-core + ${reactor.version} com.h2database @@ -70,6 +71,7 @@ io.projectreactor reactor-test + ${reactor.version} test @@ -114,6 +116,7 @@ 4.6.3 3.4.8 + 3.6.0 \ No newline at end of file diff --git a/patterns-modules/ddd/pom.xml b/patterns-modules/ddd/pom.xml index 80147c29c6..1eb1f90741 100644 --- a/patterns-modules/ddd/pom.xml +++ b/patterns-modules/ddd/pom.xml @@ -10,29 +10,11 @@ com.baeldung - parent-boot-2 + parent-boot-3 0.0.1-SNAPSHOT - ../../parent-boot-2 + ../../parent-boot-3 - - - - org.junit - junit-bom - ${junit-jupiter.version} - pom - import - - - org.springframework.boot - spring-boot-dependencies - ${spring-boot.version} - pom - import - - - @@ -88,12 +70,15 @@ de.flapdoodle.embed de.flapdoodle.embed.mongo + ${de.flapdoodle.embed.mongo.version} test + com.baeldung.ddd.PersistingDddAggregatesApplication 1.0.1 + 4.11.1 \ No newline at end of file diff --git a/patterns-modules/ddd/src/main/java/com/baeldung/ddd/order/jpa/JpaOrder.java b/patterns-modules/ddd/src/main/java/com/baeldung/ddd/order/jpa/JpaOrder.java index 81ae3bbd19..e0e7ea9a4e 100644 --- a/patterns-modules/ddd/src/main/java/com/baeldung/ddd/order/jpa/JpaOrder.java +++ b/patterns-modules/ddd/src/main/java/com/baeldung/ddd/order/jpa/JpaOrder.java @@ -4,12 +4,12 @@ import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; -import javax.persistence.ElementCollection; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.Table; +import jakarta.persistence.ElementCollection; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.persistence.Table; @Entity @Table(name = "order_table") diff --git a/patterns-modules/ddd/src/main/java/com/baeldung/ddd/order/jpa/JpaOrderLine.java b/patterns-modules/ddd/src/main/java/com/baeldung/ddd/order/jpa/JpaOrderLine.java index a3b50f0502..bf1d7020be 100644 --- a/patterns-modules/ddd/src/main/java/com/baeldung/ddd/order/jpa/JpaOrderLine.java +++ b/patterns-modules/ddd/src/main/java/com/baeldung/ddd/order/jpa/JpaOrderLine.java @@ -1,7 +1,7 @@ package com.baeldung.ddd.order.jpa; -import javax.persistence.Embeddable; -import javax.persistence.Embedded; +import jakarta.persistence.Embeddable; +import jakarta.persistence.Embedded; @Embeddable class JpaOrderLine { diff --git a/patterns-modules/ddd/src/main/java/com/baeldung/ddd/order/jpa/JpaProduct.java b/patterns-modules/ddd/src/main/java/com/baeldung/ddd/order/jpa/JpaProduct.java index 1d2ae5230a..30b074b2e4 100644 --- a/patterns-modules/ddd/src/main/java/com/baeldung/ddd/order/jpa/JpaProduct.java +++ b/patterns-modules/ddd/src/main/java/com/baeldung/ddd/order/jpa/JpaProduct.java @@ -2,7 +2,7 @@ package com.baeldung.ddd.order.jpa; import java.math.BigDecimal; -import javax.persistence.Embeddable; +import jakarta.persistence.Embeddable; @Embeddable class JpaProduct { diff --git a/patterns-modules/ddd/src/main/java/com/baeldung/dddhexagonalspring/application/request/AddProductRequest.java b/patterns-modules/ddd/src/main/java/com/baeldung/dddhexagonalspring/application/request/AddProductRequest.java index ec107d635b..76dc438b63 100644 --- a/patterns-modules/ddd/src/main/java/com/baeldung/dddhexagonalspring/application/request/AddProductRequest.java +++ b/patterns-modules/ddd/src/main/java/com/baeldung/dddhexagonalspring/application/request/AddProductRequest.java @@ -4,7 +4,7 @@ import com.baeldung.dddhexagonalspring.domain.Product; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -import javax.validation.constraints.NotNull; +import jakarta.validation.constraints.NotNull; public class AddProductRequest { @NotNull private Product product; diff --git a/patterns-modules/ddd/src/main/java/com/baeldung/dddhexagonalspring/application/request/CreateOrderRequest.java b/patterns-modules/ddd/src/main/java/com/baeldung/dddhexagonalspring/application/request/CreateOrderRequest.java index 8c51fbe479..ff81908811 100644 --- a/patterns-modules/ddd/src/main/java/com/baeldung/dddhexagonalspring/application/request/CreateOrderRequest.java +++ b/patterns-modules/ddd/src/main/java/com/baeldung/dddhexagonalspring/application/request/CreateOrderRequest.java @@ -4,7 +4,7 @@ import com.baeldung.dddhexagonalspring.domain.Product; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -import javax.validation.constraints.NotNull; +import jakarta.validation.constraints.NotNull; public class CreateOrderRequest { @NotNull private Product product; diff --git a/persistence-modules/core-java-persistence/pom.xml b/persistence-modules/core-java-persistence/pom.xml index 5d5c36ef01..20553da4e8 100644 --- a/persistence-modules/core-java-persistence/pom.xml +++ b/persistence-modules/core-java-persistence/pom.xml @@ -62,7 +62,7 @@ 2.9.0 - 5.0.1 + 5.1.0 0.9.5.5 3.0.4 6.0.6 diff --git a/persistence-modules/fauna/pom.xml b/persistence-modules/fauna/pom.xml index a0626e0cd2..4c37c2ae9e 100644 --- a/persistence-modules/fauna/pom.xml +++ b/persistence-modules/fauna/pom.xml @@ -44,6 +44,7 @@ org.projectlombok lombok provided + ${lombok.version} @@ -57,7 +58,6 @@ - 17 4.2.0 diff --git a/persistence-modules/hibernate-mapping/pom.xml b/persistence-modules/hibernate-mapping/pom.xml index 0ce112b9e6..45d8e24b41 100644 --- a/persistence-modules/hibernate-mapping/pom.xml +++ b/persistence-modules/hibernate-mapping/pom.xml @@ -86,7 +86,7 @@ 3.0.1-b11 1.1 1.4.2 - 2.14.2 + 2.16.0 \ No newline at end of file diff --git a/persistence-modules/java-harperdb/README.md b/persistence-modules/java-harperdb/README.md new file mode 100644 index 0000000000..99a91e00ed --- /dev/null +++ b/persistence-modules/java-harperdb/README.md @@ -0,0 +1,2 @@ +## Relevant Articles +- [Working With HarperDB and Java](https://www.baeldung.com/java-harperdb) diff --git a/persistence-modules/java-harperdb/pom.xml b/persistence-modules/java-harperdb/pom.xml new file mode 100644 index 0000000000..7340aa4dbc --- /dev/null +++ b/persistence-modules/java-harperdb/pom.xml @@ -0,0 +1,65 @@ + + + 4.0.0 + + com.baeldung + java-harperdb + 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 9 + 9 + + + + + + + com.baeldung + persistence-modules + 1.0.0-SNAPSHOT + + + + com.baeldung + java-harperdb + ${haperdb-driver.version} + system + + ${project.basedir}/lib/cdata.jdbc.harperdb.jar + + + org.testcontainers + testcontainers + test + + + org.apache.derby + derby + 10.13.1.1 + + + + + + + org.testcontainers + testcontainers-bom + 1.19.3 + pom + import + + + + + + 4.2 + + + \ No newline at end of file diff --git a/persistence-modules/java-harperdb/src/main/resources/data-model.puml b/persistence-modules/java-harperdb/src/main/resources/data-model.puml new file mode 100644 index 0000000000..8e3681c749 --- /dev/null +++ b/persistence-modules/java-harperdb/src/main/resources/data-model.puml @@ -0,0 +1,41 @@ +@startuml +'https://gist.github.com/QuantumGhost/0955a45383a0b6c0bc24f9654b3cb561 +' uncomment the line below if you're using computer with a retina display +' skinparam dpi 300 +!theme sketchy-outline +!define Table(name,desc) class name as "desc" << (T, #63b175) >> +' we use bold for primary key +' green color for unique +' and underscore for not_null +!define primary_key(x) x +!define unique(x) x +!define not_null(x) x +' other tags available: +' +' , where color is a color name or html color code +' (#FFAACC) +' see: http://plantuml.com/classes.html#More +hide methods +hide stereotypes + +' entities + + +Table(Teacher, "Teacher") { + primary_key(Id) Number + Name Varchar + joining_date Date +} +Table(Subject, "Subject") { + primary_key(Id) Number + Name Varchar +} +Table(Teacher_Details, "Teacher_Details") { + primary_key(Id) Number + teacher_id Number + subject_id Number +} + +Teacher_Details "*" -left-> "1" Subject: " " +Teacher "1" -left-> "*" Teacher_Details: " " +@enduml \ No newline at end of file diff --git a/persistence-modules/java-harperdb/src/test/java/com/baeldung/harperdb/HarperDBApiService.java b/persistence-modules/java-harperdb/src/test/java/com/baeldung/harperdb/HarperDBApiService.java new file mode 100644 index 0000000000..361e17bd83 --- /dev/null +++ b/persistence-modules/java-harperdb/src/test/java/com/baeldung/harperdb/HarperDBApiService.java @@ -0,0 +1,78 @@ +package com.baeldung.harperdb; + +import com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.classic.methods.HttpPost; +import com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.impl.classic.HttpClientBuilder; +import com.github.dockerjava.zerodep.shaded.org.apache.hc.core5.http.ClassicHttpRequest; +import com.github.dockerjava.zerodep.shaded.org.apache.hc.core5.http.HttpEntity; +import com.github.dockerjava.zerodep.shaded.org.apache.hc.core5.http.io.entity.StringEntity; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.Base64; + +public class HarperDBApiService { + private static final Logger LOGGER = LoggerFactory.getLogger(HarperDBApiService.class); + private String url; + private String base64auth; + + public HarperDBApiService(String url, String user, String password) { + this.url = url; + this.base64auth = Base64.getEncoder() + .encodeToString(new StringBuilder().append(user) + .append(":") + .append(password) + .toString() + .getBytes()); + } + + public void createSchema(String schema) throws IOException { + String requestBody = "{\"operation\":\"create_schema\", \"" + "schema\":\"" + schema + "\"" + "}"; + executeHttpPostRequest(requestBody); + } + + public void createTable(String schema, String table, String ... attributes) throws IOException { + String createTableReq = "{\"operation\":\"create_table\"," + + "\"schema\":\"" + schema + + "\",\"table\":\"" + table + + "\",\"hash_attribute\":\"id\"" + + "}"; + executeHttpPostRequest(createTableReq); + LOGGER.info("created table:" + table); + for (String attribute : attributes) { + String createAttrReq = "{\"operation\":\"create_attribute\",\"schema\":\"" + + schema + "\",\"table\":\"" + + table + "\",\"attribute\":\"" + + attribute + "\"" + + "}"; + executeHttpPostRequest(createAttrReq); + LOGGER.info("created attribute:" + attribute + " in table:" + table); + } + } + + public void insertRecords(String schema, String table, String records) throws IOException { + String requestBody = "{\"table\":" + "\"" + table + "\"," + + "\"schema\":" + "\"" + schema + "\"" + "," + + "\"operation\":" + "\"" + "insert" + "\"" + "," + + "\"records\":" + records + + "}"; + executeHttpPostRequest(requestBody); + } + + private void executeHttpPostRequest(String httpRequest) throws IOException { + LOGGER.info("Post request body:" + httpRequest); + + try (CloseableHttpClient closeableHttpClient = HttpClientBuilder.create() + .build()) { + HttpPost request = new HttpPost(this.url); + request.addHeader("Authorization", "Basic " + this.base64auth); + request.addHeader("Content-Type", "application/json"); + request.setEntity((HttpEntity) new StringEntity(httpRequest)); + CloseableHttpResponse response = closeableHttpClient.execute((ClassicHttpRequest) request); + LOGGER.info("REST API response:" + response.toString()); + assert (200 == response.getCode()); + } + } +} diff --git a/persistence-modules/java-harperdb/src/test/java/com/baeldung/harperdb/HarperDBContainer.java b/persistence-modules/java-harperdb/src/test/java/com/baeldung/harperdb/HarperDBContainer.java new file mode 100644 index 0000000000..12ef87fa99 --- /dev/null +++ b/persistence-modules/java-harperdb/src/test/java/com/baeldung/harperdb/HarperDBContainer.java @@ -0,0 +1,36 @@ +package com.baeldung.harperdb; + +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testcontainers.containers.GenericContainer; + +public class HarperDBContainer { + + private final static Logger LOGGER = LoggerFactory.getLogger(HarperDBContainer.class); + + private static final Map DEFAULT_ENV_MAP = Map.of("HDB_ADMIN_USERNAME", "admin", "HDB_ADMIN_PASSWORD", "password", + "OPERATIONSAPI_NETWORK_PORT", "9925", "ROOTPATH", "/home/harperdb/hdb", "LOGGING_STDSTREAMS", "true"); + + private static final Integer[] DEFAULT_EXPOSED_PORTS = { 9925, 9926 }; + + private static final String HARPER_DOCKER_IMAGE = "harperdb/harperdb:latest"; + + public void stop() { + harperDBContainer.stop(); + } + + GenericContainer harperDBContainer; + + public GenericContainer installHarperDB() { + harperDBContainer = new GenericContainer(HARPER_DOCKER_IMAGE).withEnv(DEFAULT_ENV_MAP) + .withExposedPorts(DEFAULT_EXPOSED_PORTS); + return harperDBContainer; + } + + public GenericContainer installHarperDB(String dockerImgage, final Map envMap, final Integer... exposedPorts) { + return new GenericContainer(dockerImgage).withEnv(envMap) + .withExposedPorts(exposedPorts); + } +} diff --git a/persistence-modules/java-harperdb/src/test/java/com/baeldung/harperdb/HarperDBLiveTest.java b/persistence-modules/java-harperdb/src/test/java/com/baeldung/harperdb/HarperDBLiveTest.java new file mode 100644 index 0000000000..34d2f8d29b --- /dev/null +++ b/persistence-modules/java-harperdb/src/test/java/com/baeldung/harperdb/HarperDBLiveTest.java @@ -0,0 +1,379 @@ +package com.baeldung.harperdb; + +import cdata.jdbc.harperdb.HarperDBConnectionPoolDataSource; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testcontainers.containers.GenericContainer; + +import java.io.IOException; +import java.net.URISyntaxException; +import java.net.URL; +import java.sql.*; +import java.util.Arrays; +import java.util.Map; +import java.util.Properties; + +import static org.junit.jupiter.api.Assertions.*; + +public class HarperDBLiveTest { + + private static final Logger logger = LoggerFactory.getLogger(HarperDBLiveTest.class); + + private static Integer port; + + private static HarperDBContainer harperDBContainer; + + private static HarperDBApiService harperDbApiService; + + @BeforeAll + static void setupHarperDB() throws IOException, InterruptedException, URISyntaxException { + installHarperDB(); + initHarperDBApiService(); + setupDB(); + } + + private static void installHarperDB() { + harperDBContainer = new HarperDBContainer(); + + GenericContainer genericContainer = harperDBContainer.installHarperDB(); + + genericContainer.start(); + + port = genericContainer.getFirstMappedPort(); + } + + private static void initHarperDBApiService() { + String url = "http://localhost:" + port + "/"; + harperDbApiService = new HarperDBApiService(url, "admin", "password"); + } + + private static void setupDB() throws IOException { + harperDbApiService.createSchema("Demo"); + + harperDbApiService.createTable("Demo", "Subject", "name"); + harperDbApiService.createTable("Demo", "Teacher", "name", "joining_date", "subject_id"); + harperDbApiService.createTable("Demo", "Teacher_Details", "teacher_id", "subject_id"); + + insertSubjectRecords(); + insertTeacherRecords(); + insertTeacherDetailsRecords(); + } + + private static void insertSubjectRecords() throws IOException { + String records = "[" + + "{\"id\":1, \"name\":\"English\"}," + + "{\"id\":2, \"name\":\"Maths\"}," + + "{\"id\":3, \"name\":\"Science\"}" + + "]"; + + harperDbApiService.insertRecords("Demo", "Subject", records); + } + + private static void insertTeacherRecords() throws IOException { + String records = "[" + "{\"id\":1, \"name\":\"James Cameron\", \"joining_date\":\"04-05-2000\"}," + + "{\"id\":2, \"name\":\"Joe Biden\", \"joining_date\":\"20-10-2005\"}," + + "{\"id\":3, \"name\":\"Jessie Williams\", \"joining_date\":\"04-06-1997\"}," + + "{\"id\":4, \"name\":\"Robin Williams\", \"joining_date\":\"01-01-2020\"}," + + "{\"id\":5, \"name\":\"Eric Johnson\", \"joining_date\":\"04-05-2022\"}," + + "{\"id\":6, \"name\":\"Raghu Yadav\", \"joining_date\":\"02-02-1999\"}" + "]"; + harperDbApiService.insertRecords("Demo", "Teacher", records); + } + + private static void insertTeacherDetailsRecords() throws IOException { + String records = "[" + "{\"id\":1, \"teacher_id\":1, \"subject_id\":1}," + "{\"id\":2, \"teacher_id\":1, \"subject_id\":2}," + + "{\"id\":3, \"teacher_id\":2, \"subject_id\":3 }," + "{\"id\":4, \"teacher_id\":3, \"subject_id\":1}," + + "{\"id\":5, \"teacher_id\":3, \"subject_id\":3}," + "{\"id\":6, \"teacher_id\":4, \"subject_id\":2}," + + "{\"id\":7, \"teacher_id\":5, \"subject_id\":3}," + "{\"id\":8, \"teacher_id\":6, \"subject_id\":1}," + + "{\"id\":9, \"teacher_id\":6, \"subject_id\":2}," + "{\"id\":15, \"teacher_id\":6, \"subject_id\":3}" + "]"; + + harperDbApiService.insertRecords("Demo", "Teacher_Details", records); + } + + @AfterAll + static void stopHarperDB() { + harperDBContainer.stop(); + } + + @Test + void whenConnectionInfoInURL_thenConnectSuccess() { + assertDoesNotThrow(() -> { + final String JDBC_URL = "jdbc:harperdb:Server=127.0.0.1:" + port + ";User=admin;Password=password;"; + + try (Connection connection = DriverManager.getConnection(JDBC_URL)) { + connection.createStatement() + .executeQuery("select 1"); + logger.info("Connection Successful"); + } + }); + } + + @Test + void whenConnectionInfoInProperties_thenConnectSuccess() { + assertDoesNotThrow(() -> { + Properties prop = new Properties(); + prop.setProperty("Server", "127.0.0.1:" + port); + prop.setProperty("User", "admin"); + prop.setProperty("Password", "password"); + + try (Connection connection = DriverManager.getConnection("jdbc:harperdb:", prop)) { + connection.createStatement() + .executeQuery("select 1"); + logger.info("Connection Successful"); + } + }); + } + + @Test + void whenConnectionPooling_thenConnectSuccess() { + assertDoesNotThrow(() -> { + HarperDBConnectionPoolDataSource harperdbPoolDataSource = new HarperDBConnectionPoolDataSource(); + final String JDBC_URL = "jdbc:harperdb:UseConnectionPooling=true;PoolMaxSize=2;Server=127.0.0.1:" + port + ";User=admin;Password=password;"; + harperdbPoolDataSource.setURL(JDBC_URL); + + try (Connection connection = harperdbPoolDataSource.getPooledConnection() + .getConnection()) { + connection.createStatement() + .executeQuery("select 1"); + logger.info("Connection Pool Successful"); + } + }); + } + + @Test + void whenExecuteStoredToCreateTable_thenSuccess() throws SQLException { + final String CREATE_TABLE_PROC = "CreateTable"; + try (Connection connection = getConnection()) { + CallableStatement callableStatement = connection.prepareCall(CREATE_TABLE_PROC); + + callableStatement.setString("SchemaName", "prod"); + callableStatement.setString("TableName", "subject"); + callableStatement.setString("PrimaryKey", "id"); + Boolean result = callableStatement.execute(); + + ResultSet resultSet = callableStatement.getResultSet(); + + while (resultSet.next()) { + String tableCreated = resultSet.getString("Success"); + assertEquals("true", tableCreated); + logger.info("Table Created Successfully"); + } + } + } + + @Test + void givenStatement_whenInsertRecord_thenSuccess() throws SQLException { + final String INSERT_SQL = "insert into Demo.Subject(id, name) values " + + "(4, 'Social Studies')," + + "(5, 'Geography')"; + + try (Connection connection = getConnection()) { + Statement statement = connection.createStatement(); + assertDoesNotThrow(() -> statement.execute(INSERT_SQL)); + assertEquals(2, statement.getUpdateCount()); + } + } + + @Test + void givenPrepareStatement_whenAddToBatch_thenSuccess() throws SQLException { + final String INSERT_SQL = "insert into Demo.Teacher(id, name, joining_date) values" + + "(?, ?, ?)"; + + try (Connection connection = getConnection()) { + PreparedStatement preparedStatement = connection.prepareStatement(INSERT_SQL); + preparedStatement.setInt(1, 7); + preparedStatement.setString(2, "Bret Lee"); + preparedStatement.setString(3, "07-08-2002"); + preparedStatement.addBatch(); + + preparedStatement.setInt(1, 8); + preparedStatement.setString(2, "Sarah Glimmer"); + preparedStatement.setString(3, "07-08-1997"); + preparedStatement.addBatch(); + + int[] recordsInserted = preparedStatement.executeBatch(); + + assertEquals(2, Arrays.stream(recordsInserted).sum()); + } + } + + private static Connection getConnection() throws SQLException { + String URL = "jdbc:harperdb:Server=127.0.0.1:" + port + ";User=admin;Password=password;"; + return DriverManager.getConnection(URL); + } + + private static Connection getConnection(Map properties) throws SQLException { + Properties prop = new Properties(); + prop.setProperty("Server", "127.0.0.1:" + port); + prop.setProperty("User", "admin"); + prop.setProperty("Password", "password"); + for (Map.Entry entry : properties.entrySet()) { + prop.setProperty(entry.getKey(), entry.getValue()); + } + + return DriverManager.getConnection("jdbc:harperdb:", prop); + } + + @Test + void givenStatement_whenFetchRecord_thenSuccess() throws SQLException { + final String SQL_QUERY = "select id, name from Demo.Subject where name = 'Maths'"; + + try (Connection connection = getConnection()) { + Statement statement = connection.createStatement(); + ResultSet resultSet = statement.executeQuery(SQL_QUERY); + while (resultSet.next()) { + Integer id = resultSet.getInt("id"); + String name = resultSet.getString("name"); + assertNotNull(id); + assertEquals("Maths", name); + logger.info("Subject id:" + id + " Subject Name:" + name); + } + } + } + + @Test + void givenPreparedStatement_whenExecuteJoinQuery_thenSuccess() throws SQLException { + final String JOIN_QUERY = "SELECT t.name as teacher_name, t.joining_date as joining_date, s.name as subject_name " + + "from Demo.Teacher_Details AS td " + + "INNER JOIN Demo.Teacher AS t ON t.id = td.teacher_id " + + "INNER JOIN Demo.Subject AS s on s.id = td.subject_id " + + "where t.name = ?"; + + try (Connection connection = getConnection()) { + PreparedStatement preparedStatement = connection.prepareStatement(JOIN_QUERY); + preparedStatement.setString(1, "Eric Johnson"); + + ResultSet resultSet = preparedStatement.executeQuery(); + while (resultSet.next()) { + String teacherName = resultSet.getString("teacher_name"); + String subjectName = resultSet.getString("subject_name"); + String joiningDate = resultSet.getString("joining_date"); + assertEquals("Eric Johnson", teacherName); + assertEquals("Maths", subjectName); + logger.info("Teacher Name:" + teacherName + " Subject Name:" + subjectName + " Joining Date:" + joiningDate); + } + } + } + + @Test + void givenStatement_whenUpdateRecord_thenSuccess() throws SQLException { + final String UPDATE_SQL = "update Demo.Teacher_Details set subject_id = 2 " + + "where teacher_id in (2, 5)"; + final String UPDATE_SQL_WITH_SUB_QUERY = "update Demo.Teacher_Details " + + "set subject_id = (select id from Demo.Subject where name = 'Maths') " + + "where teacher_id in (select id from Demo.Teacher where name in ('Joe Biden', 'Eric Johnson'))"; + + try (Connection connection = getConnection()) { + Statement statement = connection.createStatement(); + assertDoesNotThrow(() -> statement.execute(UPDATE_SQL)); + assertEquals(2, statement.getUpdateCount()); + } + + try (Connection connection = getConnection()) { + assertThrows(SQLException.class, () -> connection.createStatement().execute(UPDATE_SQL_WITH_SUB_QUERY)); + } + } + + @Test + void givenPreparedStatement_whenUpdateRecord_thenSuccess() throws SQLException { + final String UPDATE_SQL = "update Demo.Teacher_Details set subject_id = ? " + + "where teacher_id in (?, ?)"; + + try (Connection connection = getConnection()) { + PreparedStatement preparedStatement = connection.prepareStatement(UPDATE_SQL); + preparedStatement.setInt(1, 1); + //following is not supported by the HarperDB driver + //Integer[] teacherIds = {4, 5}; + //Array teacherIdArray = connection.createArrayOf(Integer.class.getTypeName(), teacherIds); + preparedStatement.setInt(2, 4); + preparedStatement.setInt(3, 5); + assertDoesNotThrow(() -> preparedStatement.execute()); + assertEquals(2, preparedStatement.getUpdateCount()); + } + } + + @Test + void givenStatement_whenDeleteRecord_thenSuccess() throws SQLException { + final String DELETE_SQL = "delete from Demo.Teacher_Details where teacher_id = 6 and subject_id = 3"; + + try (Connection connection = getConnection()) { + Statement statement = connection.createStatement(); + assertDoesNotThrow(() -> statement.execute(DELETE_SQL)); + assertEquals(1, statement.getUpdateCount()); + } + } + + @Test + void givenPreparedStatement_whenDeleteRecord_thenSuccess() throws SQLException { + final String DELETE_SQL = "delete from Demo.Teacher_Details where teacher_id = ? and subject_id = ?"; + + try (Connection connection = getConnection()) { + PreparedStatement preparedStatement = connection.prepareStatement(DELETE_SQL); + preparedStatement.setInt(1, 6); + preparedStatement.setInt(2, 2); + assertDoesNotThrow(() -> preparedStatement.execute()); + assertEquals(1, preparedStatement.getUpdateCount()); + } + } + + @Test + void givenTempTable_whenInsertIntoSelectTempTable_thenSuccess() throws SQLException { + try (Connection connection = getConnection()) { + Statement statement = connection.createStatement(); + assertDoesNotThrow(() -> { + statement.execute("insert into Teacher#TEMP(id, name, joining_date) " + + "values('12', 'David Flinch', '04-04-2014')"); + statement.execute("insert into Teacher#TEMP(id, name, joining_date) " + + "values('13', 'Stephen Hawkins', '04-07-2017')"); + statement.execute("insert into Teacher#TEMP(id, name, joining_date) " + + "values('14', 'Albert Einstein', '12-08-2020')"); + statement.execute("insert into Teacher#TEMP(id, name, joining_date) " + + "values('15', 'Leo Tolstoy', '20-08-2022')"); + }); + assertDoesNotThrow(() -> statement.execute("insert into Demo.Teacher(id, name, joining_date) " + + "select id, name, joining_date from Teacher#TEMP")); + ResultSet resultSet = statement.executeQuery("select count(id) as rows from Demo.Teacher where id in" + + " (12, 13, 14, 15)"); + resultSet.next(); + int totalRows = resultSet.getInt("rows"); + logger.info("total number of rows fetched:" + totalRows); + assertEquals(4, totalRows); + } + } + + @Test + void givenUserDefinedView_whenQueryView_thenSuccess() throws SQLException { + URL url = ClassLoader.getSystemClassLoader().getResource("UserDefinedViews.json"); + + String folderPath = url.getPath().substring(0, url.getPath().lastIndexOf('/')); + + try(Connection connection = getConnection(Map.of("Location", folderPath))) { + PreparedStatement preparedStatement = connection.prepareStatement("select teacher_name,subject_name" + + " from UserViews.View_Teacher_Details where subject_name = ?"); + preparedStatement.setString(1, "Science"); + ResultSet resultSet = preparedStatement.executeQuery(); + while(resultSet.next()) { + assertEquals("Science", resultSet.getString("subject_name")); + logger.info("Science Teacher Name:" + resultSet.getString("teacher_name")); + } + } + } + + @Test + void givenAutoCache_whenQuery_thenSuccess() throws SQLException { + URL url = ClassLoader.getSystemClassLoader().getResource("test.db"); + String folderPath = url.getPath().substring(0, url.getPath().lastIndexOf('/')); + logger.info("Cache Location:" + folderPath); + try(Connection connection = getConnection(Map.of("AutoCache", "true", "CacheLocation", folderPath))) { + PreparedStatement preparedStatement = connection.prepareStatement("select id, name from Demo.Subject"); + + ResultSet resultSet = preparedStatement.executeQuery(); + while(resultSet.next()) { + logger.info("Subject Name:" + resultSet.getString("name")); + } + } + } +} diff --git a/persistence-modules/java-harperdb/src/test/resources/UserDefinedViews.json b/persistence-modules/java-harperdb/src/test/resources/UserDefinedViews.json new file mode 100644 index 0000000000..fba67def3c --- /dev/null +++ b/persistence-modules/java-harperdb/src/test/resources/UserDefinedViews.json @@ -0,0 +1,5 @@ +{ + "View_Teacher_Details": { + "query": "SELECT t.name as teacher_name, t.joining_date as joining_date, s.name as subject_name from Demo.Teacher_Details AS td INNER JOIN Demo.Teacher AS t ON t.id = td.teacher_id INNER JOIN Demo.Subject AS s on s.id = td.subject_id" + } +} \ No newline at end of file diff --git a/persistence-modules/java-harperdb/src/test/resources/test.db b/persistence-modules/java-harperdb/src/test/resources/test.db new file mode 100644 index 0000000000..e69de29bb2 diff --git a/persistence-modules/pom.xml b/persistence-modules/pom.xml index d9ee7e358c..41ff596ccf 100644 --- a/persistence-modules/pom.xml +++ b/persistence-modules/pom.xml @@ -60,15 +60,15 @@ solr spring-boot-persistence-2 - spring-boot-persistence-3 - spring-boot-mysql + + spring-boot-persistence spring-boot-persistence-h2 spring-boot-persistence-mongodb spring-boot-persistence-mongodb-2 spring-boot-persistence-mongodb-3 spring-data-arangodb - spring-data-cassandra + spring-data-cassandra-test spring-data-cosmosdb spring-data-couchbase-2 @@ -108,8 +108,8 @@ spring-jpa spring-jpa-2 spring-jdbc - spring-jdbc-2 - spring-jooq + spring-jdbc-2 + spring-mybatis spring-persistence-simple spring-data-yugabytedb diff --git a/persistence-modules/r2dbc/pom.xml b/persistence-modules/r2dbc/pom.xml index 5260bb9860..a2c8e3148d 100644 --- a/persistence-modules/r2dbc/pom.xml +++ b/persistence-modules/r2dbc/pom.xml @@ -52,6 +52,7 @@ org.projectlombok lombok + ${lombok.version} org.springframework.boot diff --git a/persistence-modules/rethinkdb/pom.xml b/persistence-modules/rethinkdb/pom.xml index 17c7036ed3..352be80469 100644 --- a/persistence-modules/rethinkdb/pom.xml +++ b/persistence-modules/rethinkdb/pom.xml @@ -46,8 +46,4 @@ - - 17 - - diff --git a/persistence-modules/scylladb/pom.xml b/persistence-modules/scylladb/pom.xml index f84db87742..66dd89afa9 100644 --- a/persistence-modules/scylladb/pom.xml +++ b/persistence-modules/scylladb/pom.xml @@ -37,6 +37,7 @@ org.projectlombok lombok true + ${lombok.version} org.springframework.boot diff --git a/persistence-modules/spring-boot-persistence-2/pom.xml b/persistence-modules/spring-boot-persistence-2/pom.xml index 7d6b6909c4..9b22e6902c 100644 --- a/persistence-modules/spring-boot-persistence-2/pom.xml +++ b/persistence-modules/spring-boot-persistence-2/pom.xml @@ -74,6 +74,7 @@ org.projectlombok lombok true + ${lombok.version} org.springframework.boot diff --git a/persistence-modules/spring-data-cassandra-2/pom.xml b/persistence-modules/spring-data-cassandra-2/pom.xml index 01b5ce5ed6..6532da7f95 100644 --- a/persistence-modules/spring-data-cassandra-2/pom.xml +++ b/persistence-modules/spring-data-cassandra-2/pom.xml @@ -99,7 +99,6 @@ - 11 3.4.15 1.19.0 1.1.0 diff --git a/persistence-modules/spring-data-cassandra-reactive/pom.xml b/persistence-modules/spring-data-cassandra-reactive/pom.xml index cddb62186b..41f184e233 100644 --- a/persistence-modules/spring-data-cassandra-reactive/pom.xml +++ b/persistence-modules/spring-data-cassandra-reactive/pom.xml @@ -23,6 +23,7 @@ io.projectreactor reactor-core + ${reactor.version} org.springframework.boot @@ -45,6 +46,7 @@ io.projectreactor reactor-test + ${reactor.version} test @@ -57,6 +59,7 @@ 4.3.1.0 + 3.6.0 \ No newline at end of file diff --git a/persistence-modules/spring-data-cosmosdb/pom.xml b/persistence-modules/spring-data-cosmosdb/pom.xml index 30dc4f999c..fbd4af9456 100644 --- a/persistence-modules/spring-data-cosmosdb/pom.xml +++ b/persistence-modules/spring-data-cosmosdb/pom.xml @@ -32,6 +32,7 @@ org.projectlombok lombok + ${lombok.version} diff --git a/persistence-modules/spring-data-elasticsearch/pom.xml b/persistence-modules/spring-data-elasticsearch/pom.xml index 6535b9ac4b..b8edae68d3 100644 --- a/persistence-modules/spring-data-elasticsearch/pom.xml +++ b/persistence-modules/spring-data-elasticsearch/pom.xml @@ -40,7 +40,7 @@ org.projectlombok lombok - 1.18.28 + ${lombok.version} org.springframework.boot @@ -60,7 +60,7 @@ 5.1.2 8.9.0 - 2.15.2 + 2.16.0 \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-enterprise-2/README.md b/persistence-modules/spring-data-jpa-enterprise-2/README.md index 8e154f6b75..0c1e9968bc 100644 --- a/persistence-modules/spring-data-jpa-enterprise-2/README.md +++ b/persistence-modules/spring-data-jpa-enterprise-2/README.md @@ -3,7 +3,8 @@ This module contains articles about Spring Data JPA used in enterprise applications such as transactions, sessions, naming conventions and more ### Relevant Articles: - +- [Custom Naming Convention with Spring Data JPA](https://www.baeldung.com/spring-data-jpa-custom-naming) +- [Working with Lazy Element Collections in JPA](https://www.baeldung.com/java-jpa-lazy-collections) ### Eclipse Config diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/elementcollection/ElementCollectionApplication.java b/persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/elementcollection/ElementCollectionApplication.java similarity index 100% rename from persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/elementcollection/ElementCollectionApplication.java rename to persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/elementcollection/ElementCollectionApplication.java diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/elementcollection/model/Employee.java b/persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/elementcollection/model/Employee.java similarity index 87% rename from persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/elementcollection/model/Employee.java rename to persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/elementcollection/model/Employee.java index 8b98164d63..9bc0663016 100644 --- a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/elementcollection/model/Employee.java +++ b/persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/elementcollection/model/Employee.java @@ -1,9 +1,14 @@ package com.baeldung.elementcollection.model; -import javax.persistence.*; import java.util.List; import java.util.Objects; +import javax.persistence.CollectionTable; +import javax.persistence.ElementCollection; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.JoinColumn; + @Entity public class Employee { @Id diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/elementcollection/model/Phone.java b/persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/elementcollection/model/Phone.java similarity index 99% rename from persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/elementcollection/model/Phone.java rename to persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/elementcollection/model/Phone.java index d73d30c47a..15d05aea98 100644 --- a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/elementcollection/model/Phone.java +++ b/persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/elementcollection/model/Phone.java @@ -1,8 +1,9 @@ package com.baeldung.elementcollection.model; -import javax.persistence.Embeddable; import java.util.Objects; +import javax.persistence.Embeddable; + @Embeddable public class Phone { private String type; diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/elementcollection/repository/EmployeeRepository.java b/persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/elementcollection/repository/EmployeeRepository.java similarity index 99% rename from persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/elementcollection/repository/EmployeeRepository.java rename to persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/elementcollection/repository/EmployeeRepository.java index 49180c35eb..996cac7cd9 100644 --- a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/elementcollection/repository/EmployeeRepository.java +++ b/persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/elementcollection/repository/EmployeeRepository.java @@ -1,14 +1,16 @@ package com.baeldung.elementcollection.repository; -import com.baeldung.elementcollection.model.Employee; -import org.springframework.stereotype.Repository; -import org.springframework.transaction.annotation.Transactional; +import java.util.HashMap; +import java.util.Map; import javax.persistence.EntityGraph; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; -import java.util.HashMap; -import java.util.Map; + +import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; + +import com.baeldung.elementcollection.model.Employee; @Repository public class EmployeeRepository { diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/Person.java b/persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/namingstrategy/Person.java similarity index 94% rename from persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/Person.java rename to persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/namingstrategy/Person.java index cfb6e67c2c..35dd2dc226 100644 --- a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/Person.java +++ b/persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/namingstrategy/Person.java @@ -1,6 +1,5 @@ package com.baeldung.namingstrategy; -import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/PersonRepository.java b/persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/namingstrategy/PersonRepository.java similarity index 100% rename from persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/PersonRepository.java rename to persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/namingstrategy/PersonRepository.java diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/QuotedLowerCaseNamingStrategy.java b/persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/namingstrategy/QuotedLowerCaseNamingStrategy.java similarity index 100% rename from persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/QuotedLowerCaseNamingStrategy.java rename to persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/namingstrategy/QuotedLowerCaseNamingStrategy.java diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/QuotedUpperCaseNamingStrategy.java b/persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/namingstrategy/QuotedUpperCaseNamingStrategy.java similarity index 100% rename from persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/QuotedUpperCaseNamingStrategy.java rename to persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/namingstrategy/QuotedUpperCaseNamingStrategy.java diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/SpringDataJpaNamingConventionApplication.java b/persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/namingstrategy/SpringDataJpaNamingConventionApplication.java similarity index 100% rename from persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/SpringDataJpaNamingConventionApplication.java rename to persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/namingstrategy/SpringDataJpaNamingConventionApplication.java diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/UnquotedLowerCaseNamingStrategy.java b/persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/namingstrategy/UnquotedLowerCaseNamingStrategy.java similarity index 100% rename from persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/UnquotedLowerCaseNamingStrategy.java rename to persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/namingstrategy/UnquotedLowerCaseNamingStrategy.java diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/UnquotedUpperCaseNamingStrategy.java b/persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/namingstrategy/UnquotedUpperCaseNamingStrategy.java similarity index 100% rename from persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/UnquotedUpperCaseNamingStrategy.java rename to persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/namingstrategy/UnquotedUpperCaseNamingStrategy.java diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/elementcollection/ElementCollectionIntegrationTest.java b/persistence-modules/spring-data-jpa-enterprise-2/src/test/java/com/baeldung/elementcollection/ElementCollectionIntegrationTest.java similarity index 99% rename from persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/elementcollection/ElementCollectionIntegrationTest.java rename to persistence-modules/spring-data-jpa-enterprise-2/src/test/java/com/baeldung/elementcollection/ElementCollectionIntegrationTest.java index 306798aa68..ed2bb97252 100644 --- a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/elementcollection/ElementCollectionIntegrationTest.java +++ b/persistence-modules/spring-data-jpa-enterprise-2/src/test/java/com/baeldung/elementcollection/ElementCollectionIntegrationTest.java @@ -1,8 +1,10 @@ package com.baeldung.elementcollection; -import com.baeldung.elementcollection.model.Employee; -import com.baeldung.elementcollection.model.Phone; -import com.baeldung.elementcollection.repository.EmployeeRepository; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; + +import java.util.Arrays; + import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -12,10 +14,9 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.transaction.annotation.Transactional; -import java.util.Arrays; - -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; +import com.baeldung.elementcollection.model.Employee; +import com.baeldung.elementcollection.model.Phone; +import com.baeldung.elementcollection.repository.EmployeeRepository; @RunWith(SpringRunner.class) @SpringBootTest(classes = ElementCollectionApplication.class) diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/QuotedLowerCaseNamingStrategyH2IntegrationTest.java b/persistence-modules/spring-data-jpa-enterprise-2/src/test/java/com/baeldung/namingstrategy/QuotedLowerCaseNamingStrategyH2IntegrationTest.java similarity index 99% rename from persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/QuotedLowerCaseNamingStrategyH2IntegrationTest.java rename to persistence-modules/spring-data-jpa-enterprise-2/src/test/java/com/baeldung/namingstrategy/QuotedLowerCaseNamingStrategyH2IntegrationTest.java index 71a4dbda3f..b3225175ca 100644 --- a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/QuotedLowerCaseNamingStrategyH2IntegrationTest.java +++ b/persistence-modules/spring-data-jpa-enterprise-2/src/test/java/com/baeldung/namingstrategy/QuotedLowerCaseNamingStrategyH2IntegrationTest.java @@ -1,5 +1,17 @@ package com.baeldung.namingstrategy; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.math.BigInteger; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.Query; + import org.hibernate.exception.SQLGrammarException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -10,17 +22,6 @@ import org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfigur import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.test.context.TestPropertySource; -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.persistence.Query; -import java.math.BigInteger; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; - @DataJpaTest(excludeAutoConfiguration = TestDatabaseAutoConfiguration.class) @TestPropertySource("quoted-lower-case-naming-strategy.properties") class QuotedLowerCaseNamingStrategyH2IntegrationTest { diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/QuotedLowerCaseNamingStrategyPostgresLiveTest.java b/persistence-modules/spring-data-jpa-enterprise-2/src/test/java/com/baeldung/namingstrategy/QuotedLowerCaseNamingStrategyPostgresLiveTest.java similarity index 99% rename from persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/QuotedLowerCaseNamingStrategyPostgresLiveTest.java rename to persistence-modules/spring-data-jpa-enterprise-2/src/test/java/com/baeldung/namingstrategy/QuotedLowerCaseNamingStrategyPostgresLiveTest.java index 6b1c984600..b21fdf9edd 100644 --- a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/QuotedLowerCaseNamingStrategyPostgresLiveTest.java +++ b/persistence-modules/spring-data-jpa-enterprise-2/src/test/java/com/baeldung/namingstrategy/QuotedLowerCaseNamingStrategyPostgresLiveTest.java @@ -1,5 +1,17 @@ package com.baeldung.namingstrategy; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.math.BigInteger; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.Query; + import org.hibernate.exception.SQLGrammarException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -10,17 +22,6 @@ import org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfigur import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.test.context.TestPropertySource; -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.persistence.Query; -import java.math.BigInteger; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; - @DataJpaTest(excludeAutoConfiguration = TestDatabaseAutoConfiguration.class) @TestPropertySource("quoted-lower-case-naming-strategy-on-postgres.properties") class QuotedLowerCaseNamingStrategyPostgresLiveTest { diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/QuotedUpperCaseNamingStrategyH2IntegrationTest.java b/persistence-modules/spring-data-jpa-enterprise-2/src/test/java/com/baeldung/namingstrategy/QuotedUpperCaseNamingStrategyH2IntegrationTest.java similarity index 99% rename from persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/QuotedUpperCaseNamingStrategyH2IntegrationTest.java rename to persistence-modules/spring-data-jpa-enterprise-2/src/test/java/com/baeldung/namingstrategy/QuotedUpperCaseNamingStrategyH2IntegrationTest.java index f819327a5c..74f82f0d39 100644 --- a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/QuotedUpperCaseNamingStrategyH2IntegrationTest.java +++ b/persistence-modules/spring-data-jpa-enterprise-2/src/test/java/com/baeldung/namingstrategy/QuotedUpperCaseNamingStrategyH2IntegrationTest.java @@ -1,5 +1,17 @@ package com.baeldung.namingstrategy; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.math.BigInteger; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.Query; + import org.hibernate.exception.SQLGrammarException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -10,17 +22,6 @@ import org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfigur import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.test.context.TestPropertySource; -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.persistence.Query; -import java.math.BigInteger; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; - @DataJpaTest(excludeAutoConfiguration = TestDatabaseAutoConfiguration.class) @TestPropertySource("quoted-upper-case-naming-strategy.properties") class QuotedUpperCaseNamingStrategyH2IntegrationTest { diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/QuotedUpperCaseNamingStrategyPostgresLiveTest.java b/persistence-modules/spring-data-jpa-enterprise-2/src/test/java/com/baeldung/namingstrategy/QuotedUpperCaseNamingStrategyPostgresLiveTest.java similarity index 99% rename from persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/QuotedUpperCaseNamingStrategyPostgresLiveTest.java rename to persistence-modules/spring-data-jpa-enterprise-2/src/test/java/com/baeldung/namingstrategy/QuotedUpperCaseNamingStrategyPostgresLiveTest.java index bd23b81b4b..6741b09366 100644 --- a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/QuotedUpperCaseNamingStrategyPostgresLiveTest.java +++ b/persistence-modules/spring-data-jpa-enterprise-2/src/test/java/com/baeldung/namingstrategy/QuotedUpperCaseNamingStrategyPostgresLiveTest.java @@ -1,5 +1,17 @@ package com.baeldung.namingstrategy; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.math.BigInteger; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.Query; + import org.hibernate.exception.SQLGrammarException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -10,17 +22,6 @@ import org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfigur import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.test.context.TestPropertySource; -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.persistence.Query; -import java.math.BigInteger; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; - @DataJpaTest(excludeAutoConfiguration = TestDatabaseAutoConfiguration.class) @TestPropertySource("quoted-upper-case-naming-strategy-on-postgres.properties") class QuotedUpperCaseNamingStrategyPostgresLiveTest { diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/SpringPhysicalNamingStrategyH2IntegrationTest.java b/persistence-modules/spring-data-jpa-enterprise-2/src/test/java/com/baeldung/namingstrategy/SpringPhysicalNamingStrategyH2IntegrationTest.java similarity index 99% rename from persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/SpringPhysicalNamingStrategyH2IntegrationTest.java rename to persistence-modules/spring-data-jpa-enterprise-2/src/test/java/com/baeldung/namingstrategy/SpringPhysicalNamingStrategyH2IntegrationTest.java index 1850fea173..dbbccdd61d 100644 --- a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/SpringPhysicalNamingStrategyH2IntegrationTest.java +++ b/persistence-modules/spring-data-jpa-enterprise-2/src/test/java/com/baeldung/namingstrategy/SpringPhysicalNamingStrategyH2IntegrationTest.java @@ -1,5 +1,17 @@ package com.baeldung.namingstrategy; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.math.BigInteger; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.Query; + import org.hibernate.exception.SQLGrammarException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -10,17 +22,6 @@ import org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfigur import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.test.context.TestPropertySource; -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.persistence.Query; -import java.math.BigInteger; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; - @DataJpaTest(excludeAutoConfiguration = TestDatabaseAutoConfiguration.class) @TestPropertySource("spring-physical-naming-strategy.properties") class SpringPhysicalNamingStrategyH2IntegrationTest { diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/SpringPhysicalNamingStrategyPostgresLiveTest.java b/persistence-modules/spring-data-jpa-enterprise-2/src/test/java/com/baeldung/namingstrategy/SpringPhysicalNamingStrategyPostgresLiveTest.java similarity index 99% rename from persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/SpringPhysicalNamingStrategyPostgresLiveTest.java rename to persistence-modules/spring-data-jpa-enterprise-2/src/test/java/com/baeldung/namingstrategy/SpringPhysicalNamingStrategyPostgresLiveTest.java index e26ebb148d..760dacdaa2 100644 --- a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/SpringPhysicalNamingStrategyPostgresLiveTest.java +++ b/persistence-modules/spring-data-jpa-enterprise-2/src/test/java/com/baeldung/namingstrategy/SpringPhysicalNamingStrategyPostgresLiveTest.java @@ -1,5 +1,17 @@ package com.baeldung.namingstrategy; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.math.BigInteger; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.Query; + import org.hibernate.exception.SQLGrammarException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -10,17 +22,6 @@ import org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfigur import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.test.context.TestPropertySource; -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.persistence.Query; -import java.math.BigInteger; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; - @DataJpaTest(excludeAutoConfiguration = TestDatabaseAutoConfiguration.class) @TestPropertySource("spring-physical-naming-strategy-on-postgres.properties") class SpringPhysicalNamingStrategyPostgresLiveTest { diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/UnquotedLowerCaseNamingStrategyH2IntegrationTest.java b/persistence-modules/spring-data-jpa-enterprise-2/src/test/java/com/baeldung/namingstrategy/UnquotedLowerCaseNamingStrategyH2IntegrationTest.java similarity index 98% rename from persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/UnquotedLowerCaseNamingStrategyH2IntegrationTest.java rename to persistence-modules/spring-data-jpa-enterprise-2/src/test/java/com/baeldung/namingstrategy/UnquotedLowerCaseNamingStrategyH2IntegrationTest.java index 6311c42e93..d0e86384b8 100644 --- a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/UnquotedLowerCaseNamingStrategyH2IntegrationTest.java +++ b/persistence-modules/spring-data-jpa-enterprise-2/src/test/java/com/baeldung/namingstrategy/UnquotedLowerCaseNamingStrategyH2IntegrationTest.java @@ -1,5 +1,17 @@ package com.baeldung.namingstrategy; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.math.BigInteger; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.Query; + import org.hibernate.exception.SQLGrammarException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -10,18 +22,6 @@ import org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfigur import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.test.context.TestPropertySource; -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.persistence.Query; -import java.math.BigInteger; -import java.sql.SQLException; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; - @DataJpaTest(excludeAutoConfiguration = TestDatabaseAutoConfiguration.class) @TestPropertySource("unquoted-lower-case-naming-strategy.properties") class UnquotedLowerCaseNamingStrategyH2IntegrationTest { diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/UnquotedLowerCaseNamingStrategyPostgresLiveTest.java b/persistence-modules/spring-data-jpa-enterprise-2/src/test/java/com/baeldung/namingstrategy/UnquotedLowerCaseNamingStrategyPostgresLiveTest.java similarity index 99% rename from persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/UnquotedLowerCaseNamingStrategyPostgresLiveTest.java rename to persistence-modules/spring-data-jpa-enterprise-2/src/test/java/com/baeldung/namingstrategy/UnquotedLowerCaseNamingStrategyPostgresLiveTest.java index 033a213cf5..121b184a3c 100644 --- a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/UnquotedLowerCaseNamingStrategyPostgresLiveTest.java +++ b/persistence-modules/spring-data-jpa-enterprise-2/src/test/java/com/baeldung/namingstrategy/UnquotedLowerCaseNamingStrategyPostgresLiveTest.java @@ -1,5 +1,17 @@ package com.baeldung.namingstrategy; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.math.BigInteger; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.Query; + import org.hibernate.exception.SQLGrammarException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -10,17 +22,6 @@ import org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfigur import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.test.context.TestPropertySource; -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.persistence.Query; -import java.math.BigInteger; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; - @DataJpaTest(excludeAutoConfiguration = TestDatabaseAutoConfiguration.class) @TestPropertySource("unquoted-lower-case-naming-strategy-on-postgres.properties") class UnquotedLowerCaseNamingStrategyPostgresLiveTest { diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/UnquotedUpperCaseNamingStrategyH2IntegrationTest.java b/persistence-modules/spring-data-jpa-enterprise-2/src/test/java/com/baeldung/namingstrategy/UnquotedUpperCaseNamingStrategyH2IntegrationTest.java similarity index 99% rename from persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/UnquotedUpperCaseNamingStrategyH2IntegrationTest.java rename to persistence-modules/spring-data-jpa-enterprise-2/src/test/java/com/baeldung/namingstrategy/UnquotedUpperCaseNamingStrategyH2IntegrationTest.java index 7af8001854..b4f25605bd 100644 --- a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/UnquotedUpperCaseNamingStrategyH2IntegrationTest.java +++ b/persistence-modules/spring-data-jpa-enterprise-2/src/test/java/com/baeldung/namingstrategy/UnquotedUpperCaseNamingStrategyH2IntegrationTest.java @@ -1,5 +1,17 @@ package com.baeldung.namingstrategy; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.math.BigInteger; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.Query; + import org.hibernate.exception.SQLGrammarException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -10,17 +22,6 @@ import org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfigur import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.test.context.TestPropertySource; -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.persistence.Query; -import java.math.BigInteger; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; - @DataJpaTest(excludeAutoConfiguration = TestDatabaseAutoConfiguration.class) @TestPropertySource("unquoted-upper-case-naming-strategy.properties") class UnquotedUpperCaseNamingStrategyH2IntegrationTest { diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/UnquotedUpperCaseNamingStrategyPostgresLiveTest.java b/persistence-modules/spring-data-jpa-enterprise-2/src/test/java/com/baeldung/namingstrategy/UnquotedUpperCaseNamingStrategyPostgresLiveTest.java similarity index 99% rename from persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/UnquotedUpperCaseNamingStrategyPostgresLiveTest.java rename to persistence-modules/spring-data-jpa-enterprise-2/src/test/java/com/baeldung/namingstrategy/UnquotedUpperCaseNamingStrategyPostgresLiveTest.java index 0151e7ece4..7ecd4cc80e 100644 --- a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/UnquotedUpperCaseNamingStrategyPostgresLiveTest.java +++ b/persistence-modules/spring-data-jpa-enterprise-2/src/test/java/com/baeldung/namingstrategy/UnquotedUpperCaseNamingStrategyPostgresLiveTest.java @@ -1,5 +1,17 @@ package com.baeldung.namingstrategy; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.math.BigInteger; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.Query; + import org.hibernate.exception.SQLGrammarException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -10,17 +22,6 @@ import org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfigur import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.test.context.TestPropertySource; -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.persistence.Query; -import java.math.BigInteger; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; - @DataJpaTest(excludeAutoConfiguration = TestDatabaseAutoConfiguration.class) @TestPropertySource("unquoted-upper-case-naming-strategy-on-postgres.properties") class UnquotedUpperCaseNamingStrategyPostgresLiveTest { diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/quoted-lower-case-naming-strategy-on-postgres.properties b/persistence-modules/spring-data-jpa-enterprise-2/src/test/resources/com/baeldung/namingstrategy/quoted-lower-case-naming-strategy-on-postgres.properties similarity index 100% rename from persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/quoted-lower-case-naming-strategy-on-postgres.properties rename to persistence-modules/spring-data-jpa-enterprise-2/src/test/resources/com/baeldung/namingstrategy/quoted-lower-case-naming-strategy-on-postgres.properties diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/quoted-lower-case-naming-strategy.properties b/persistence-modules/spring-data-jpa-enterprise-2/src/test/resources/com/baeldung/namingstrategy/quoted-lower-case-naming-strategy.properties similarity index 100% rename from persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/quoted-lower-case-naming-strategy.properties rename to persistence-modules/spring-data-jpa-enterprise-2/src/test/resources/com/baeldung/namingstrategy/quoted-lower-case-naming-strategy.properties diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/quoted-upper-case-naming-strategy-on-postgres.properties b/persistence-modules/spring-data-jpa-enterprise-2/src/test/resources/com/baeldung/namingstrategy/quoted-upper-case-naming-strategy-on-postgres.properties similarity index 100% rename from persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/quoted-upper-case-naming-strategy-on-postgres.properties rename to persistence-modules/spring-data-jpa-enterprise-2/src/test/resources/com/baeldung/namingstrategy/quoted-upper-case-naming-strategy-on-postgres.properties diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/quoted-upper-case-naming-strategy.properties b/persistence-modules/spring-data-jpa-enterprise-2/src/test/resources/com/baeldung/namingstrategy/quoted-upper-case-naming-strategy.properties similarity index 100% rename from persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/quoted-upper-case-naming-strategy.properties rename to persistence-modules/spring-data-jpa-enterprise-2/src/test/resources/com/baeldung/namingstrategy/quoted-upper-case-naming-strategy.properties diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/spring-physical-naming-strategy-on-postgres.properties b/persistence-modules/spring-data-jpa-enterprise-2/src/test/resources/com/baeldung/namingstrategy/spring-physical-naming-strategy-on-postgres.properties similarity index 100% rename from persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/spring-physical-naming-strategy-on-postgres.properties rename to persistence-modules/spring-data-jpa-enterprise-2/src/test/resources/com/baeldung/namingstrategy/spring-physical-naming-strategy-on-postgres.properties diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/spring-physical-naming-strategy.properties b/persistence-modules/spring-data-jpa-enterprise-2/src/test/resources/com/baeldung/namingstrategy/spring-physical-naming-strategy.properties similarity index 100% rename from persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/spring-physical-naming-strategy.properties rename to persistence-modules/spring-data-jpa-enterprise-2/src/test/resources/com/baeldung/namingstrategy/spring-physical-naming-strategy.properties diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/unquoted-lower-case-naming-strategy-on-postgres.properties b/persistence-modules/spring-data-jpa-enterprise-2/src/test/resources/com/baeldung/namingstrategy/unquoted-lower-case-naming-strategy-on-postgres.properties similarity index 100% rename from persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/unquoted-lower-case-naming-strategy-on-postgres.properties rename to persistence-modules/spring-data-jpa-enterprise-2/src/test/resources/com/baeldung/namingstrategy/unquoted-lower-case-naming-strategy-on-postgres.properties diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/unquoted-lower-case-naming-strategy.properties b/persistence-modules/spring-data-jpa-enterprise-2/src/test/resources/com/baeldung/namingstrategy/unquoted-lower-case-naming-strategy.properties similarity index 100% rename from persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/unquoted-lower-case-naming-strategy.properties rename to persistence-modules/spring-data-jpa-enterprise-2/src/test/resources/com/baeldung/namingstrategy/unquoted-lower-case-naming-strategy.properties diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/unquoted-upper-case-naming-strategy-on-postgres.properties b/persistence-modules/spring-data-jpa-enterprise-2/src/test/resources/com/baeldung/namingstrategy/unquoted-upper-case-naming-strategy-on-postgres.properties similarity index 100% rename from persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/unquoted-upper-case-naming-strategy-on-postgres.properties rename to persistence-modules/spring-data-jpa-enterprise-2/src/test/resources/com/baeldung/namingstrategy/unquoted-upper-case-naming-strategy-on-postgres.properties diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/unquoted-upper-case-naming-strategy.properties b/persistence-modules/spring-data-jpa-enterprise-2/src/test/resources/com/baeldung/namingstrategy/unquoted-upper-case-naming-strategy.properties similarity index 100% rename from persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/unquoted-upper-case-naming-strategy.properties rename to persistence-modules/spring-data-jpa-enterprise-2/src/test/resources/com/baeldung/namingstrategy/unquoted-upper-case-naming-strategy.properties diff --git a/persistence-modules/spring-data-jpa-enterprise/README.md b/persistence-modules/spring-data-jpa-enterprise/README.md index b563fa46d4..c48a519a87 100644 --- a/persistence-modules/spring-data-jpa-enterprise/README.md +++ b/persistence-modules/spring-data-jpa-enterprise/README.md @@ -7,8 +7,6 @@ This module contains articles about Spring Data JPA used in enterprise applicati - [Spring Data Java 8 Support](https://www.baeldung.com/spring-data-java-8) - [DB Integration Tests with Spring Boot and Testcontainers](https://www.baeldung.com/spring-boot-testcontainers-integration-test) - [A Guide to Spring’s Open Session in View](https://www.baeldung.com/spring-open-session-in-view) -- [Working with Lazy Element Collections in JPA](https://www.baeldung.com/java-jpa-lazy-collections) -- [Custom Naming Convention with Spring Data JPA](https://www.baeldung.com/spring-data-jpa-custom-naming) - [Partial Data Update With Spring Data](https://www.baeldung.com/spring-data-partial-update) - [Spring Data JPA @Modifying Annotation](https://www.baeldung.com/spring-data-jpa-modifying-annotation) - [Spring JPA – Multiple Databases](https://www.baeldung.com/spring-data-jpa-multiple-databases) diff --git a/persistence-modules/spring-data-mongodb-reactive/pom.xml b/persistence-modules/spring-data-mongodb-reactive/pom.xml index 85c9a4c4b6..ca45d4a758 100644 --- a/persistence-modules/spring-data-mongodb-reactive/pom.xml +++ b/persistence-modules/spring-data-mongodb-reactive/pom.xml @@ -18,7 +18,7 @@ io.projectreactor reactor-core - ${reactor-core.version} + ${reactor.version} org.springframework.boot @@ -35,10 +35,12 @@ org.projectlombok lombok + ${lombok.version} io.projectreactor reactor-test + ${reactor.version} test @@ -125,7 +127,7 @@ 5.3.15 4.5.2 - 3.3.1.RELEASE + 3.6.0 \ No newline at end of file diff --git a/persistence-modules/spring-data-redis/pom.xml b/persistence-modules/spring-data-redis/pom.xml index 052935e215..382cdf83f5 100644 --- a/persistence-modules/spring-data-redis/pom.xml +++ b/persistence-modules/spring-data-redis/pom.xml @@ -27,6 +27,7 @@ org.projectlombok lombok + ${lombok.version} io.projectreactor diff --git a/persistence-modules/spring-jpa-2/pom.xml b/persistence-modules/spring-jpa-2/pom.xml index 9abf888fb2..c20c43912b 100644 --- a/persistence-modules/spring-jpa-2/pom.xml +++ b/persistence-modules/spring-jpa-2/pom.xml @@ -54,8 +54,8 @@ io.jsonwebtoken - jjwt - 0.9.1 + jjwt-api + 0.12.3 diff --git a/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/multitenant/security/AuthenticationService.java b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/multitenant/security/AuthenticationService.java index 00db7eebc4..42eab1d6de 100644 --- a/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/multitenant/security/AuthenticationService.java +++ b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/multitenant/security/AuthenticationService.java @@ -30,7 +30,7 @@ public class AuthenticationService { if (token != null) { String user = Jwts.parser() .setSigningKey(SIGNINGKEY) - .parseClaimsJws(token.replace(PREFIX, "")) + .build().parseClaimsJws(token.replace(PREFIX, "")) .getBody() .getSubject(); if (user != null) { @@ -48,9 +48,11 @@ public class AuthenticationService { } String tenant = Jwts.parser() .setSigningKey(SIGNINGKEY) - .parseClaimsJws(token.replace(PREFIX, "")) + .build().parseClaimsJws(token.replace(PREFIX, "")) .getBody() - .getAudience(); + .getAudience() + .iterator() + .next(); return tenant; } } diff --git a/pom.xml b/pom.xml index 167509d2b3..48da93fea4 100644 --- a/pom.xml +++ b/pom.xml @@ -709,7 +709,6 @@ apache-tika apache-velocity asciidoctor - asm atomix aws-modules azure @@ -756,7 +755,7 @@ jersey jetbrains jgit - jhipster-6 + jib jmeter jmh @@ -777,6 +776,8 @@ libraries-apache-commons-collections libraries-apache-commons-io libraries-apache-commons + libraries-bytecode + libraries-cli libraries-concurrency libraries-data-2 libraries-data-db @@ -788,10 +789,12 @@ libraries-io libraries-llms libraries-primitive + libraries-reporting libraries-rpc libraries-security libraries-server-2 libraries-server + libraries-stream libraries-testing libraries-transform libraries @@ -800,7 +803,7 @@ lombok-modules lucene mapstruct - maven-modules + mesos-marathon messaging-modules metrics @@ -817,6 +820,7 @@ pdf performance-tests persistence-modules + persistence-modules/spring-data-neo4j protobuffer quarkus-modules @@ -835,19 +839,19 @@ spring-activiti spring-actuator spring-aop-2 - spring-aop + spring-batch-2 spring-batch spring-boot-modules spring-boot-rest spring-cloud-modules/spring-cloud-azure spring-cloud-modules/spring-cloud-circuit-breaker - spring-cloud-modules/spring-cloud-contract - spring-cloud-modules/spring-cloud-data-flow + + spring-cloud-modules/spring-cloud-eureka spring-cloud-modules/spring-cloud-netflix-feign spring-cloud-modules/spring-cloud-security - spring-cloud-modules/spring-cloud-stream-starters + spring-cloud-modules/spring-cloud-zuul-eureka-integration spring-core-2 spring-core-3 @@ -855,14 +859,14 @@ spring-core spring-credhub spring-cucumber - spring-di-2 + spring-di-3 spring-di-4 spring-di spring-drools spring-ejb-modules spring-exceptions - spring-integration + spring-jenkins-pipeline spring-jersey spring-jinq @@ -890,25 +894,26 @@ spring-web-modules spring-websockets - tablesaw + tensorflow-java testing-modules testing-modules/mockito-simple + timefold-solver vaadin vavr-modules vertx-modules web-modules webrtc - xml-2 + xml xstream UTF-8 - 11 - 11 - 11 + 17 + 17 + 17 @@ -954,7 +959,6 @@ apache-tika apache-velocity asciidoctor - asm atomix aws-modules azure @@ -1001,7 +1005,7 @@ jersey jetbrains jgit - jhipster-6 + jib jmeter jmh @@ -1022,6 +1026,8 @@ libraries-apache-commons-collections libraries-apache-commons-io libraries-apache-commons + libraries-bytecode + libraries-cli libraries-concurrency libraries-data-2 libraries-data-db @@ -1033,10 +1039,12 @@ libraries-io libraries-llms libraries-primitive + libraries-reporting libraries-rpc libraries-security libraries-server-2 libraries-server + libraries-stream libraries-testing libraries-transform libraries @@ -1045,7 +1053,7 @@ lombok-modules lucene mapstruct - maven-modules + mesos-marathon messaging-modules metrics @@ -1080,19 +1088,19 @@ spring-activiti spring-actuator spring-aop-2 - spring-aop + spring-batch-2 spring-batch spring-boot-modules spring-boot-rest spring-cloud-modules/spring-cloud-azure spring-cloud-modules/spring-cloud-circuit-breaker - spring-cloud-modules/spring-cloud-contract - spring-cloud-modules/spring-cloud-data-flow + + spring-cloud-modules/spring-cloud-eureka spring-cloud-modules/spring-cloud-netflix-feign spring-cloud-modules/spring-cloud-security - spring-cloud-modules/spring-cloud-stream-starters + spring-cloud-modules/spring-cloud-zuul-eureka-integration spring-core-2 spring-core-3 @@ -1100,14 +1108,14 @@ spring-core spring-credhub spring-cucumber - spring-di-2 + spring-di-3 spring-di-4 spring-di spring-drools spring-ejb-modules spring-exceptions - spring-integration + spring-jenkins-pipeline spring-jersey spring-jinq @@ -1134,25 +1142,26 @@ spring-web-modules spring-websockets - tablesaw + tensorflow-java testing-modules testing-modules/mockito-simple + timefold-solver vaadin vavr-modules vertx-modules web-modules webrtc - xml-2 + xml xstream UTF-8 - 11 - 11 - 11 + 17 + 17 + 17 @@ -1222,7 +1231,7 @@ 1.2 2.3.3 1.2 - 2.15.2 + 2.16.0 1.5 1.9.2 5.9.2 @@ -1233,7 +1242,7 @@ 3.12.2 3.3.0 3.21.0 - 1.18.28 + 1.18.30 2.1.214 32.1.3-jre 3.3.0 diff --git a/quarkus-modules/quarkus-vs-springboot/spring-project/pom.xml b/quarkus-modules/quarkus-vs-springboot/spring-project/pom.xml index 74deab3558..c3ee41223f 100644 --- a/quarkus-modules/quarkus-vs-springboot/spring-project/pom.xml +++ b/quarkus-modules/quarkus-vs-springboot/spring-project/pom.xml @@ -253,10 +253,7 @@ 1.17.2 - 11 0.12.1 - 11 - 11 3.1.0 0.9.11 2.0.8 diff --git a/reactive-systems/inventory-service/pom.xml b/reactive-systems/inventory-service/pom.xml index 4aeec24922..baf5151fdc 100644 --- a/reactive-systems/inventory-service/pom.xml +++ b/reactive-systems/inventory-service/pom.xml @@ -31,6 +31,7 @@ org.projectlombok lombok true + ${lombok.version} org.springframework.boot diff --git a/reactive-systems/order-service/pom.xml b/reactive-systems/order-service/pom.xml index b9e5d36d3a..b6cfb70678 100644 --- a/reactive-systems/order-service/pom.xml +++ b/reactive-systems/order-service/pom.xml @@ -31,6 +31,7 @@ org.projectlombok lombok true + ${lombok.version} org.springframework.boot diff --git a/reactive-systems/shipping-service/pom.xml b/reactive-systems/shipping-service/pom.xml index 5fac674bbc..8f94dabdea 100644 --- a/reactive-systems/shipping-service/pom.xml +++ b/reactive-systems/shipping-service/pom.xml @@ -31,6 +31,7 @@ org.projectlombok lombok true + ${lombok.version} org.springframework.boot diff --git a/reactor-core/pom.xml b/reactor-core/pom.xml index dd7533fe73..7bf34c93ad 100644 --- a/reactor-core/pom.xml +++ b/reactor-core/pom.xml @@ -29,7 +29,7 @@ io.projectreactor.addons reactor-extra - ${reactor.version} + ${reactor-extra.version} org.projectlombok @@ -40,7 +40,8 @@ - 3.5.1 + 3.6.0 + 3.5.1 \ No newline at end of file diff --git a/saas-modules/stripe/pom.xml b/saas-modules/stripe/pom.xml index 44bc5be4a8..77bb912b7b 100644 --- a/saas-modules/stripe/pom.xml +++ b/saas-modules/stripe/pom.xml @@ -27,6 +27,7 @@ org.projectlombok lombok + ${lombok.version} com.stripe diff --git a/security-modules/jjwt/pom.xml b/security-modules/jjwt/pom.xml index 3ea4a46b8a..3693eaf9c4 100644 --- a/security-modules/jjwt/pom.xml +++ b/security-modules/jjwt/pom.xml @@ -35,13 +35,23 @@ io.jsonwebtoken - jjwt + jjwt-api + ${jjwt.version} + + + io.jsonwebtoken + jjwt-impl + ${jjwt.version} + + + io.jsonwebtoken + jjwt-jackson ${jjwt.version} - 0.7.0 + 0.12.3 \ No newline at end of file diff --git a/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/config/WebSecurityConfig.java b/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/config/WebSecurityConfig.java index e453f33d5e..c0f176034e 100644 --- a/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/config/WebSecurityConfig.java +++ b/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/config/WebSecurityConfig.java @@ -66,7 +66,7 @@ public class WebSecurityConfig { // CsrfFilter already made sure the token matched. Here, we'll make sure it's not expired try { Jwts.parser() - .setSigningKeyResolver(secretService.getSigningKeyResolver()) + .setSigningKeyResolver(secretService.getSigningKeyResolver()).build() .parseClaimsJws(token.getToken()); } catch (JwtException e) { // most likely an ExpiredJwtException, but this will handle any diff --git a/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/controller/DynamicJWTController.java b/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/controller/DynamicJWTController.java index 3d157827d1..1c29a753b6 100644 --- a/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/controller/DynamicJWTController.java +++ b/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/controller/DynamicJWTController.java @@ -4,7 +4,7 @@ import io.jsonwebtoken.JwtBuilder; import io.jsonwebtoken.JwtException; import io.jsonwebtoken.Jwts; import io.jsonwebtoken.SignatureAlgorithm; -import io.jsonwebtoken.impl.compression.CompressionCodecs; +import io.jsonwebtoken.impl.compression.DeflateCompressionAlgorithm; import io.jsonwebtoken.jjwtfun.model.JwtResponse; import io.jsonwebtoken.jjwtfun.service.SecretService; import org.springframework.beans.factory.annotation.Autowired; @@ -38,7 +38,7 @@ public class DynamicJWTController extends BaseController { public JwtResponse dynamicBuildercompress(@RequestBody Map claims) throws UnsupportedEncodingException { String jws = Jwts.builder() .setClaims(claims) - .compressWith(CompressionCodecs.DEFLATE) + .compressWith(new DeflateCompressionAlgorithm()) .signWith(SignatureAlgorithm.HS256, secretService.getHS256SecretBytes()) .compact(); return new JwtResponse(jws); diff --git a/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/controller/SecretsController.java b/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/controller/SecretsController.java index 1ca0973c33..4975385398 100644 --- a/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/controller/SecretsController.java +++ b/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/controller/SecretsController.java @@ -6,6 +6,7 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.security.NoSuchAlgorithmException; import java.util.Map; import static org.springframework.web.bind.annotation.RequestMethod.GET; @@ -23,7 +24,7 @@ public class SecretsController extends BaseController { } @RequestMapping(value = "/refresh-secrets", method = GET) - public Map refreshSecrets() { + public Map refreshSecrets() throws NoSuchAlgorithmException { return secretService.refreshSecrets(); } diff --git a/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/controller/StaticJWTController.java b/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/controller/StaticJWTController.java index efafa4b1b7..4ff71a620e 100644 --- a/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/controller/StaticJWTController.java +++ b/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/controller/StaticJWTController.java @@ -42,7 +42,7 @@ public class StaticJWTController extends BaseController { public JwtResponse parser(@RequestParam String jwt) throws UnsupportedEncodingException { Jws jws = Jwts.parser() - .setSigningKeyResolver(secretService.getSigningKeyResolver()) + .setSigningKeyResolver(secretService.getSigningKeyResolver()).build() .parseClaimsJws(jwt); return new JwtResponse(jws); @@ -53,7 +53,7 @@ public class StaticJWTController extends BaseController { Jws jws = Jwts.parser() .requireIssuer("Stormpath") .require("hasMotorcycle", true) - .setSigningKeyResolver(secretService.getSigningKeyResolver()) + .setSigningKeyResolver(secretService.getSigningKeyResolver()).build() .parseClaimsJws(jwt); return new JwtResponse(jws); diff --git a/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/service/SecretService.java b/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/service/SecretService.java index 4426a4b9b0..958d6fb48f 100644 --- a/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/service/SecretService.java +++ b/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/service/SecretService.java @@ -6,12 +6,14 @@ import io.jsonwebtoken.SignatureAlgorithm; import io.jsonwebtoken.SigningKeyResolver; import io.jsonwebtoken.SigningKeyResolverAdapter; import io.jsonwebtoken.impl.TextCodec; -import io.jsonwebtoken.impl.crypto.MacProvider; import io.jsonwebtoken.lang.Assert; import org.springframework.stereotype.Service; import javax.annotation.PostConstruct; +import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; + +import java.security.NoSuchAlgorithmException; import java.util.HashMap; import java.util.Map; @@ -28,7 +30,7 @@ public class SecretService { }; @PostConstruct - public void setup() { + public void setup() throws NoSuchAlgorithmException { refreshSecrets(); } @@ -42,32 +44,34 @@ public class SecretService { public void setSecrets(Map secrets) { Assert.notNull(secrets); - Assert.hasText(secrets.get(SignatureAlgorithm.HS256.getValue())); - Assert.hasText(secrets.get(SignatureAlgorithm.HS384.getValue())); - Assert.hasText(secrets.get(SignatureAlgorithm.HS512.getValue())); + Assert.hasText(secrets.get(SignatureAlgorithm.HS256.getJcaName())); + Assert.hasText(secrets.get(SignatureAlgorithm.HS384.getJcaName())); + Assert.hasText(secrets.get(SignatureAlgorithm.HS512.getJcaName())); this.secrets = secrets; } public byte[] getHS256SecretBytes() { - return TextCodec.BASE64.decode(secrets.get(SignatureAlgorithm.HS256.getValue())); + return TextCodec.BASE64.decode(secrets.get(SignatureAlgorithm.HS256.getJcaName())); } public byte[] getHS384SecretBytes() { - return TextCodec.BASE64.decode(secrets.get(SignatureAlgorithm.HS384.getValue())); + return TextCodec.BASE64.decode(secrets.get(SignatureAlgorithm.HS384.getJcaName())); } public byte[] getHS512SecretBytes() { - return TextCodec.BASE64.decode(secrets.get(SignatureAlgorithm.HS512.getValue())); + return TextCodec.BASE64.decode(secrets.get(SignatureAlgorithm.HS512.getJcaName())); } - public Map refreshSecrets() { - SecretKey key = MacProvider.generateKey(SignatureAlgorithm.HS256); - secrets.put(SignatureAlgorithm.HS256.getValue(), TextCodec.BASE64.encode(key.getEncoded())); - key = MacProvider.generateKey(SignatureAlgorithm.HS384); - secrets.put(SignatureAlgorithm.HS384.getValue(), TextCodec.BASE64.encode(key.getEncoded())); - key = MacProvider.generateKey(SignatureAlgorithm.HS512); - secrets.put(SignatureAlgorithm.HS512.getValue(), TextCodec.BASE64.encode(key.getEncoded())); + public Map refreshSecrets() throws NoSuchAlgorithmException { + SecretKey key = KeyGenerator.getInstance(SignatureAlgorithm.HS256.getJcaName()).generateKey(); + secrets.put(SignatureAlgorithm.HS256.getJcaName(), TextCodec.BASE64.encode(key.getEncoded())); + + key = KeyGenerator.getInstance(SignatureAlgorithm.HS384.getJcaName()).generateKey(); + secrets.put(SignatureAlgorithm.HS384.getJcaName(), TextCodec.BASE64.encode(key.getEncoded())); + + key = KeyGenerator.getInstance(SignatureAlgorithm.HS512.getJcaName()).generateKey(); + secrets.put(SignatureAlgorithm.HS512.getJcaName(), TextCodec.BASE64.encode(key.getEncoded())); return secrets; } } diff --git a/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/util/JWTDecoderUtil.java b/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/util/JWTDecoderUtil.java index 0fbf7637dd..2fc97b0b51 100644 --- a/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/util/JWTDecoderUtil.java +++ b/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/util/JWTDecoderUtil.java @@ -1,12 +1,14 @@ package io.jsonwebtoken.jjwtfun.util; +import io.jsonwebtoken.Jwt; +import io.jsonwebtoken.JwtParser; +import io.jsonwebtoken.Jwts; import io.jsonwebtoken.SignatureAlgorithm; -import io.jsonwebtoken.impl.crypto.DefaultJwtSignatureValidator; import javax.crypto.spec.SecretKeySpec; + import java.util.Base64; -import static io.jsonwebtoken.SignatureAlgorithm.HS256; public class JWTDecoderUtil { @@ -21,26 +23,19 @@ public class JWTDecoderUtil { return header + " " + payload; } - public static String decodeJWTToken(String token, String secretKey) throws Exception { - Base64.Decoder decoder = Base64.getUrlDecoder(); + public static boolean isTokenValid(String token, String secretKey) throws Exception { + SecretKeySpec secretKeySpec = new SecretKeySpec(secretKey.getBytes(), SignatureAlgorithm.HS256.getJcaName()); - String[] chunks = token.split("\\."); + JwtParser jwtParser = Jwts.parser() + .verifyWith(secretKeySpec) + .build(); - String header = new String(decoder.decode(chunks[0])); - String payload = new String(decoder.decode(chunks[1])); - - String tokenWithoutSignature = chunks[0] + "." + chunks[1]; - String signature = chunks[2]; - - SignatureAlgorithm sa = HS256; - SecretKeySpec secretKeySpec = new SecretKeySpec(secretKey.getBytes(), sa.getJcaName()); - - DefaultJwtSignatureValidator validator = new DefaultJwtSignatureValidator(sa, secretKeySpec); - - if (!validator.isValid(tokenWithoutSignature, signature)) { - throw new Exception("Could not verify JWT token integrity!"); + try { + jwtParser.parse(token); + } catch (Exception e) { + throw new Exception("Could not verify JWT token integrity!", e); } - return header + " " + payload; + return true; } } diff --git a/security-modules/jjwt/src/test/java/io/jsonwebtoken/jjwtfun/util/JWTDecoderUtilUnitTest.java b/security-modules/jjwt/src/test/java/io/jsonwebtoken/jjwtfun/util/JWTDecoderUtilUnitTest.java index 3103a6c8a3..4cdfdc59ba 100644 --- a/security-modules/jjwt/src/test/java/io/jsonwebtoken/jjwtfun/util/JWTDecoderUtilUnitTest.java +++ b/security-modules/jjwt/src/test/java/io/jsonwebtoken/jjwtfun/util/JWTDecoderUtilUnitTest.java @@ -1,16 +1,16 @@ package io.jsonwebtoken.jjwtfun.util; import io.jsonwebtoken.SignatureAlgorithm; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertTrue; class JWTDecoderUtilUnitTest { private final static String SIMPLE_TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkJhZWxkdW5nIFVzZXIiLCJpYXQiOjE1MTYyMzkwMjJ9"; - private final static String SIGNED_TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkJhZWxkdW5nIFVzZXIiLCJpYXQiOjE1MTYyMzkwMjJ9.qH7Zj_m3kY69kxhaQXTa-ivIpytKXXjZc1ZSmapZnGE"; + private final static String SIGNED_TOKEN = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkJhZWxkdW5nIFVzZXIiLCJpYXQiOjE1MTYyMzkwMjJ9.6h_QYBTbyKxfMq3TGiAhVI416rctV0c0SpzWxVm-0-Y"; @Test void givenSimpleToken_whenDecoding_thenStringOfHeaderPayloadAreReturned() { @@ -20,13 +20,13 @@ class JWTDecoderUtilUnitTest { @Test void givenSignedToken_whenDecodingWithInvalidSecret_thenIntegrityIsNotValidated() { - assertThatThrownBy(() -> JWTDecoderUtil.decodeJWTToken(SIGNED_TOKEN, "BAD_SECRET")) + assertThatThrownBy(() -> JWTDecoderUtil. + isTokenValid(SIGNED_TOKEN, "BAD_SECRET")) .hasMessage("Could not verify JWT token integrity!"); } @Test void givenSignedToken_whenDecodingWithValidSecret_thenIntegrityIsValidated() throws Exception { - assertThat(JWTDecoderUtil.decodeJWTToken(SIGNED_TOKEN, "MySecretKey")) - .contains("Baeldung User"); + assertTrue(JWTDecoderUtil.isTokenValid(SIGNED_TOKEN, "randomSecretWithSome!!CharacterS!")); } } diff --git a/security-modules/sql-injection-samples/pom.xml b/security-modules/sql-injection-samples/pom.xml index 7953e43ebe..37779e0d14 100644 --- a/security-modules/sql-injection-samples/pom.xml +++ b/security-modules/sql-injection-samples/pom.xml @@ -38,6 +38,7 @@ org.projectlombok lombok + ${lombok.version} provided diff --git a/spring-4/pom.xml b/spring-4/pom.xml index 681747c1f6..9a50319d13 100644 --- a/spring-4/pom.xml +++ b/spring-4/pom.xml @@ -57,6 +57,7 @@ org.projectlombok lombok + ${lombok.version} provided @@ -120,7 +121,7 @@ 1.0.1 3.6 2.4.0 - 4.0.3 + 5.1.0 2.17.1 diff --git a/spring-5-webflux/pom.xml b/spring-5-webflux/pom.xml index fe6dbe5292..8a381b250a 100644 --- a/spring-5-webflux/pom.xml +++ b/spring-5-webflux/pom.xml @@ -46,6 +46,7 @@ org.projectlombok lombok + ${lombok.version} org.springframework.boot diff --git a/spring-5/pom.xml b/spring-5/pom.xml index 1ac696e7bd..65f1b77520 100644 --- a/spring-5/pom.xml +++ b/spring-5/pom.xml @@ -143,7 +143,7 @@ 1.0 1.5.6 ${project.build.directory}/generated-snippets - 4.0.3 + 5.1.0 \ No newline at end of file diff --git a/spring-batch/pom.xml b/spring-batch/pom.xml index 20b0ef6d1c..bca0030729 100644 --- a/spring-batch/pom.xml +++ b/spring-batch/pom.xml @@ -77,7 +77,7 @@ 5.8 4.0.0 4.0.2 - 2.14.2 + 2.16.0 4.5.14 1.5.3 com.baeldung.batchtesting.SpringBatchApplication diff --git a/spring-boot-modules/pom.xml b/spring-boot-modules/pom.xml index 433f23f4ba..eaf04cf015 100644 --- a/spring-boot-modules/pom.xml +++ b/spring-boot-modules/pom.xml @@ -42,7 +42,7 @@ spring-boot-exceptions spring-boot-flowable spring-boot-graphql - spring-boot-groovy + spring-boot-jasypt spring-boot-jsp diff --git a/spring-boot-modules/spring-boot-3-2/pom.xml b/spring-boot-modules/spring-boot-3-2/pom.xml index c85488d44b..e48b232a52 100644 --- a/spring-boot-modules/spring-boot-3-2/pom.xml +++ b/spring-boot-modules/spring-boot-3-2/pom.xml @@ -79,6 +79,7 @@ org.projectlombok lombok + ${lombok.version} true diff --git a/spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/CassandraConnectionDetailsIntegrationTest.java b/spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/CassandraConnectionDetailsLiveTest.java similarity index 80% rename from spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/CassandraConnectionDetailsIntegrationTest.java rename to spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/CassandraConnectionDetailsLiveTest.java index 4130b6cb6b..9198cc1f68 100644 --- a/spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/CassandraConnectionDetailsIntegrationTest.java +++ b/spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/CassandraConnectionDetailsLiveTest.java @@ -1,3 +1,8 @@ +/** + * These test cases have dependency with docker because they pull the docker images from docker hub + * and run the container. So, please make sure to install docker before running the tests. + * For the image details please look into the docker-compose files under resources/connectiondetails/docker + **/ package com.baeldung.connectiondetails; import com.baeldung.connectiondetails.configuration.CustomCassandraConnectionDetailsConfiguration; @@ -22,8 +27,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue; @ComponentScan(basePackages = "com.baeldung.connectiondetails") @TestPropertySource(locations = {"classpath:connectiondetails/application-cassandra.properties"}) @ActiveProfiles("cassandra") -public class CassandraConnectionDetailsIntegrationTest { - private static final Logger logger = LoggerFactory.getLogger(CassandraConnectionDetailsIntegrationTest.class); +public class CassandraConnectionDetailsLiveTest { + private static final Logger logger = LoggerFactory.getLogger(CassandraConnectionDetailsLiveTest.class); @Autowired private CassandraTemplate cassandraTemplate; @Test diff --git a/spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/CouchbaseConnectionDetailsIntegrationTest.java b/spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/CouchbaseConnectionDetailsLiveTest.java similarity index 77% rename from spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/CouchbaseConnectionDetailsIntegrationTest.java rename to spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/CouchbaseConnectionDetailsLiveTest.java index 454aad4c6c..6f19382950 100644 --- a/spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/CouchbaseConnectionDetailsIntegrationTest.java +++ b/spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/CouchbaseConnectionDetailsLiveTest.java @@ -1,3 +1,8 @@ +/** + * These test cases have dependency with docker because they pull the docker images from docker hub + * and run the container. So, please make sure to install docker before running the tests. + * For the image details please look into the docker-compose files under resources/connectiondetails/docker + **/ package com.baeldung.connectiondetails; import com.baeldung.connectiondetails.configuration.CustomCouchBaseConnectionDetailsConfiguration; @@ -20,7 +25,7 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; @ComponentScan(basePackages = "com.baeldung.connectiondetails") @TestPropertySource(locations = {"classpath:connectiondetails/application-couch.properties"}) @ActiveProfiles("couch") -public class CouchbaseConnectionDetailsIntegrationTest { +public class CouchbaseConnectionDetailsLiveTest { @Autowired private Cluster cluster; @Test diff --git a/spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/ElasticsearchConnectionDetailsIntegrationTest.java b/spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/ElasticsearchConnectionDetailsLiveTest.java similarity index 81% rename from spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/ElasticsearchConnectionDetailsIntegrationTest.java rename to spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/ElasticsearchConnectionDetailsLiveTest.java index ee698cd6ea..10d0e9d019 100644 --- a/spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/ElasticsearchConnectionDetailsIntegrationTest.java +++ b/spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/ElasticsearchConnectionDetailsLiveTest.java @@ -1,3 +1,8 @@ +/** + * These test cases have dependency with docker because they pull the docker images from docker hub + * and run the container. So, please make sure to install docker before running the tests. + * For the image details please look into the docker-compose files under resources/connectiondetails/docker + **/ package com.baeldung.connectiondetails; import com.baeldung.connectiondetails.configuration.CustomElasticsearchConnectionDetailsConfiguration; @@ -24,8 +29,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue; @ComponentScan(basePackages = "com.baeldung.connectiondetails") @TestPropertySource(locations = {"classpath:connectiondetails/application-elastic.properties"}) @ActiveProfiles("elastic") -public class ElasticsearchConnectionDetailsIntegrationTest { - private static final Logger logger = LoggerFactory.getLogger(ElasticsearchConnectionDetailsIntegrationTest.class); +public class ElasticsearchConnectionDetailsLiveTest { + private static final Logger logger = LoggerFactory.getLogger(ElasticsearchConnectionDetailsLiveTest.class); @Autowired private ElasticsearchTemplate elasticsearchTemplate; diff --git a/spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/JdbcConnectionDetailsIntegrationTest.java b/spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/JdbcConnectionDetailsLiveTest.java similarity index 79% rename from spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/JdbcConnectionDetailsIntegrationTest.java rename to spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/JdbcConnectionDetailsLiveTest.java index 748bc27b0b..b074eb9bfd 100644 --- a/spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/JdbcConnectionDetailsIntegrationTest.java +++ b/spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/JdbcConnectionDetailsLiveTest.java @@ -1,3 +1,8 @@ +/** + * These test cases have dependency with docker because they pull the docker images from docker hub + * and run the container. So, please make sure to install docker before running the tests. + * For the image details please look into the docker-compose files under resources/connectiondetails/docker + **/ package com.baeldung.connectiondetails; import com.baeldung.connectiondetails.configuration.JdbcConnectionDetailsConfiguration; @@ -25,8 +30,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; @ComponentScan(basePackages = "com.baeldung.connectiondetails") @TestPropertySource(locations = {"classpath:connectiondetails/application-jdbc.properties"}) @ActiveProfiles("jdbc") -public class JdbcConnectionDetailsIntegrationTest { - private static final Logger logger = LoggerFactory.getLogger(JdbcConnectionDetailsIntegrationTest.class); +public class JdbcConnectionDetailsLiveTest { + private static final Logger logger = LoggerFactory.getLogger(JdbcConnectionDetailsLiveTest.class); @Autowired private JdbcTemplate jdbcTemplate; @Test diff --git a/spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/KafkaConnectionDetailsIntegrationTest.java b/spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/KafkaConnectionDetailsLiveTest.java similarity index 78% rename from spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/KafkaConnectionDetailsIntegrationTest.java rename to spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/KafkaConnectionDetailsLiveTest.java index bc0e174b3f..f23e610d3a 100644 --- a/spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/KafkaConnectionDetailsIntegrationTest.java +++ b/spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/KafkaConnectionDetailsLiveTest.java @@ -1,3 +1,8 @@ +/** + * These test cases have dependency with docker because they pull the docker images from docker hub + * and run the container. So, please make sure to install docker before running the tests. + * For the image details please look into the docker-compose files under resources/connectiondetails/docker + **/ package com.baeldung.connectiondetails; import com.baeldung.connectiondetails.configuration.CustomKafkaConnectionDetailsConfiguration; @@ -21,7 +26,7 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; @ComponentScan(basePackages = "com.baeldung.connectiondetails") @TestPropertySource(locations = {"classpath:connectiondetails/application-kafka.properties"}) @ActiveProfiles("kafka") -public class KafkaConnectionDetailsIntegrationTest { +public class KafkaConnectionDetailsLiveTest { @Autowired private KafkaTemplate kafkaTemplate; diff --git a/spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/MongoDBConnectionDetailsIntegrationTest.java b/spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/MongoDBConnectionDetailsLiveTest.java similarity index 85% rename from spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/MongoDBConnectionDetailsIntegrationTest.java rename to spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/MongoDBConnectionDetailsLiveTest.java index 868ebfea98..e2dceff9ec 100644 --- a/spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/MongoDBConnectionDetailsIntegrationTest.java +++ b/spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/MongoDBConnectionDetailsLiveTest.java @@ -1,3 +1,8 @@ +/** + * These test cases have dependency with docker because they pull the docker images from docker hub + * and run the container. So, please make sure to install docker before running the tests. + * For the image details please look into the docker-compose files under resources/connectiondetails/docker + **/ package com.baeldung.connectiondetails; import com.baeldung.connectiondetails.configuration.MongoDBConnectionDetailsConfiguration; @@ -26,7 +31,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; @ComponentScan(basePackages = "com.baeldung.connectiondetails") @TestPropertySource(locations = {"classpath:connectiondetails/application-mongo.properties"}) @ActiveProfiles("mongo") -public class MongoDBConnectionDetailsIntegrationTest { +public class MongoDBConnectionDetailsLiveTest { @Autowired private MongoTemplate mongoTemplate; diff --git a/spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/Neo4jConnectionDetailsIntegrationTest.java b/spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/Neo4jConnectionDetailsLiveTest.java similarity index 81% rename from spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/Neo4jConnectionDetailsIntegrationTest.java rename to spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/Neo4jConnectionDetailsLiveTest.java index 943ed7bdea..8eb9ec44d2 100644 --- a/spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/Neo4jConnectionDetailsIntegrationTest.java +++ b/spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/Neo4jConnectionDetailsLiveTest.java @@ -1,3 +1,8 @@ +/** + * These test cases have dependency with docker because they pull the docker images from docker hub + * and run the container. So, please make sure to install docker before running the tests. + * For the image details please look into the docker-compose files under resources/connectiondetails/docker + **/ package com.baeldung.connectiondetails; import com.baeldung.connectiondetails.configuration.CustomNeo4jConnectionDetailsConfiguration; @@ -22,7 +27,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; @ComponentScan(basePackages = "com.baeldung.connectiondetails") @TestPropertySource(locations = {"classpath:connectiondetails/application-neo4j.properties"}) @ActiveProfiles("neo4j") -public class Neo4jConnectionDetailsIntegrationTest { +public class Neo4jConnectionDetailsLiveTest { @Autowired private Neo4jTemplate neo4jTemplate; diff --git a/spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/R2dbcConnectionDetailsIntegrationTest.java b/spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/R2dbcConnectionDetailsLiveTest.java similarity index 80% rename from spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/R2dbcConnectionDetailsIntegrationTest.java rename to spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/R2dbcConnectionDetailsLiveTest.java index 5f8c8349fb..460a48e7ff 100644 --- a/spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/R2dbcConnectionDetailsIntegrationTest.java +++ b/spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/R2dbcConnectionDetailsLiveTest.java @@ -1,3 +1,8 @@ +/** + * These test cases have dependency with docker because they pull the docker images from docker hub + * and run the container. So, please make sure to install docker before running the tests. + * For the image details please look into the docker-compose files under resources/connectiondetails/docker + **/ package com.baeldung.connectiondetails; import com.baeldung.connectiondetails.configuration.R2dbcPostgresConnectionDetailsConfiguration; @@ -20,8 +25,8 @@ import java.util.List; @Import(R2dbcPostgresConnectionDetailsConfiguration.class) @TestPropertySource(locations = {"classpath:connectiondetails/application-r2dbc.properties"}) @ActiveProfiles("r2dbc") -public class R2dbcConnectionDetailsIntegrationTest { - Logger logger = LoggerFactory.getLogger(R2dbcConnectionDetailsIntegrationTest.class); +public class R2dbcConnectionDetailsLiveTest { + Logger logger = LoggerFactory.getLogger(R2dbcConnectionDetailsLiveTest.class); @Autowired private R2dbcEntityTemplate r2dbcEntityTemplate; diff --git a/spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/RabbitmqConnectionDetailsIntegrationTest.java b/spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/RabbitmqConnectionDetailsLiveTest.java similarity index 85% rename from spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/RabbitmqConnectionDetailsIntegrationTest.java rename to spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/RabbitmqConnectionDetailsLiveTest.java index 9e10973ed7..5f7eb055eb 100644 --- a/spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/RabbitmqConnectionDetailsIntegrationTest.java +++ b/spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/RabbitmqConnectionDetailsLiveTest.java @@ -1,3 +1,8 @@ +/** + * These test cases have dependency with docker because they pull the docker images from docker hub + * and run the container. So, please make sure to install docker before running the tests. + * For the image details please look into the docker-compose files under resources/connectiondetails/docker + **/ package com.baeldung.connectiondetails; import com.baeldung.connectiondetails.configuration.RabbitMQConnectionDetailsConfiguration; @@ -25,9 +30,9 @@ import static org.junit.jupiter.api.Assertions.assertEquals; @Import(RabbitMQConnectionDetailsConfiguration.class) @TestPropertySource(locations = {"classpath:connectiondetails/application-rabbitmq.properties"}) @ActiveProfiles("rabbitmq") -public class RabbitmqConnectionDetailsIntegrationTest { +public class RabbitmqConnectionDetailsLiveTest { - private static final Logger logger = LoggerFactory.getLogger(RabbitmqConnectionDetailsIntegrationTest.class); + private static final Logger logger = LoggerFactory.getLogger(RabbitmqConnectionDetailsLiveTest.class); @Autowired private RabbitTemplate rabbitTemplate; diff --git a/spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/RedisCacheConnnectionDetailsIntegrationTest.java b/spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/RedisCacheConnnectionDetailsLiveTest.java similarity index 76% rename from spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/RedisCacheConnnectionDetailsIntegrationTest.java rename to spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/RedisCacheConnnectionDetailsLiveTest.java index 5dbd2d6c03..919f968323 100644 --- a/spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/RedisCacheConnnectionDetailsIntegrationTest.java +++ b/spring-boot-modules/spring-boot-3-2/src/test/java/com/baeldung/connectiondetails/RedisCacheConnnectionDetailsLiveTest.java @@ -1,3 +1,8 @@ +/** + * These test cases have dependency with docker because they pull the docker images from docker hub + * and run the container. So, please make sure to install docker before running the tests. + * For the image details please look into the docker-compose files under resources/connectiondetails/docker + **/ package com.baeldung.connectiondetails; import com.baeldung.connectiondetails.configuration.RedisConnectionDetailsConfiguration; @@ -20,8 +25,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; @Import(RedisConnectionDetailsConfiguration.class) @TestPropertySource(locations = {"classpath:connectiondetails/application-redis.properties"}) @ActiveProfiles("redis") -public class RedisCacheConnnectionDetailsIntegrationTest { - private static final Logger logger = LoggerFactory.getLogger(RedisCacheConnnectionDetailsIntegrationTest.class); +public class RedisCacheConnnectionDetailsLiveTest { + private static final Logger logger = LoggerFactory.getLogger(RedisCacheConnnectionDetailsLiveTest.class); @Autowired RedisTemplate redisTemplate; diff --git a/spring-boot-modules/spring-boot-3-url-matching/pom.xml b/spring-boot-modules/spring-boot-3-url-matching/pom.xml index 43f89eab47..42bd8583b3 100644 --- a/spring-boot-modules/spring-boot-3-url-matching/pom.xml +++ b/spring-boot-modules/spring-boot-3-url-matching/pom.xml @@ -96,8 +96,8 @@ 6.0.6 3.1.0 - 3.5.4 - 3.5.4> + 3.6.0 + 3.6.0> 3.0.0-M7 diff --git a/spring-boot-modules/spring-boot-cassandre/pom.xml b/spring-boot-modules/spring-boot-cassandre/pom.xml index e2964183d2..3834d7b88c 100644 --- a/spring-boot-modules/spring-boot-cassandre/pom.xml +++ b/spring-boot-modules/spring-boot-cassandre/pom.xml @@ -40,7 +40,6 @@ - 11 4.2.1 5.0.7 2.5.1 diff --git a/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/entitydtodifferences/Application.java b/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/entitydtodifferences/Application.java new file mode 100644 index 0000000000..4a780ac17a --- /dev/null +++ b/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/entitydtodifferences/Application.java @@ -0,0 +1,12 @@ +package com.baeldung.entitydtodifferences; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} diff --git a/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/entitydtodifferences/controller/UserController.java b/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/entitydtodifferences/controller/UserController.java new file mode 100644 index 0000000000..66cecacd9b --- /dev/null +++ b/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/entitydtodifferences/controller/UserController.java @@ -0,0 +1,39 @@ +package com.baeldung.entitydtodifferences.controller; + +import java.util.List; +import java.util.stream.Collectors; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.baeldung.entitydtodifferences.dto.UserCreationDto; +import com.baeldung.entitydtodifferences.dto.UserResponseDto; +import com.baeldung.entitydtodifferences.mapper.UserMapper; +import com.baeldung.entitydtodifferences.repository.UserRepository; + +@RestController +@RequestMapping("/users") +public class UserController { + + private final UserRepository userRepository; + + public UserController(UserRepository userRepository) { + this.userRepository = userRepository; + } + + @GetMapping + public List getUsers() { + return userRepository.findAll() + .stream() + .map(UserMapper::toDto) + .collect(Collectors.toList()); + } + + @PostMapping + public UserResponseDto createUser(@RequestBody UserCreationDto userCreationDto) { + return UserMapper.toDto(userRepository.save(UserMapper.toEntity(userCreationDto))); + } +} diff --git a/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/entitydtodifferences/dto/BookDto.java b/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/entitydtodifferences/dto/BookDto.java new file mode 100644 index 0000000000..a5ee25f105 --- /dev/null +++ b/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/entitydtodifferences/dto/BookDto.java @@ -0,0 +1,30 @@ +package com.baeldung.entitydtodifferences.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class BookDto { + + @JsonProperty("NAME") + private final String name; + + @JsonProperty("AUTHOR") + private final String author; + + // Default constructor for Jackson deserialization + public BookDto() { + this(null, null); + } + + public BookDto(String name, String author) { + this.name = name; + this.author = author; + } + + public String getName() { + return name; + } + + public String getAuthor() { + return author; + } +} diff --git a/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/entitydtodifferences/dto/UserCreationDto.java b/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/entitydtodifferences/dto/UserCreationDto.java new file mode 100644 index 0000000000..0859c042cf --- /dev/null +++ b/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/entitydtodifferences/dto/UserCreationDto.java @@ -0,0 +1,48 @@ +package com.baeldung.entitydtodifferences.dto; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class UserCreationDto { + + @JsonProperty("FIRST_NAME") + private final String firstName; + + @JsonProperty("LAST_NAME") + private final String lastName; + + @JsonProperty("ADDRESS") + private final String address; + + @JsonProperty("BOOKS") + private final List books; + + // Default constructor for Jackson deserialization + public UserCreationDto() { + this(null, null, null, null); + } + + public UserCreationDto(String firstName, String lastName, String address, List books) { + this.firstName = firstName; + this.lastName = lastName; + this.address = address; + this.books = books; + } + + public String getFirstName() { + return firstName; + } + + public String getLastName() { + return lastName; + } + + public String getAddress() { + return address; + } + + public List getBooks() { + return books; + } +} diff --git a/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/entitydtodifferences/dto/UserResponseDto.java b/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/entitydtodifferences/dto/UserResponseDto.java new file mode 100644 index 0000000000..910689dd41 --- /dev/null +++ b/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/entitydtodifferences/dto/UserResponseDto.java @@ -0,0 +1,48 @@ +package com.baeldung.entitydtodifferences.dto; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class UserResponseDto { + + @JsonProperty("ID") + private final Long id; + + @JsonProperty("FIRST_NAME") + private final String firstName; + + @JsonProperty("LAST_NAME") + private final String lastName; + + @JsonProperty("BOOKS") + private final List books; + + // Default constructor for Jackson deserialization + public UserResponseDto() { + this(null, null, null, null); + } + + public UserResponseDto(Long id, String firstName, String lastName, List books) { + this.id = id; + this.firstName = firstName; + this.lastName = lastName; + this.books = books; + } + + public Long getId() { + return id; + } + + public String getFirstName() { + return firstName; + } + + public String getLastName() { + return lastName; + } + + public List getBooks() { + return books; + } +} diff --git a/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/entitydtodifferences/entity/Book.java b/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/entitydtodifferences/entity/Book.java new file mode 100644 index 0000000000..88e895467a --- /dev/null +++ b/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/entitydtodifferences/entity/Book.java @@ -0,0 +1,39 @@ +package com.baeldung.entitydtodifferences.entity; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name = "books") +public class Book { + + @Id + private String name; + private String author; + + // Default constructor for JPA deserialization + public Book() { + } + + public Book(String name, String author) { + this.name = name; + this.author = author; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getAuthor() { + return author; + } + + public void setAuthor(String author) { + this.author = author; + } +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/entitydtodifferences/entity/User.java b/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/entitydtodifferences/entity/User.java new file mode 100644 index 0000000000..6a404e9f1f --- /dev/null +++ b/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/entitydtodifferences/entity/User.java @@ -0,0 +1,90 @@ +package com.baeldung.entitydtodifferences.entity; + +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import javax.persistence.CascadeType; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.OneToMany; +import javax.persistence.Table; + +@Entity +@Table(name = "users") +public class User { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + private String firstName; + private String lastName; + private String address; + + @OneToMany(cascade = CascadeType.ALL) + private List books; + + // Default constructor for JPA deserialization + public User() { + } + + public User(String firstName, String lastName, String address, List books) { + this.firstName = firstName; + this.lastName = lastName; + this.address = address; + this.books = books; + } + + public String getNameOfMostOwnedBook() { + Map bookOwnershipCount = books.stream() + .collect(Collectors.groupingBy(Book::getName, Collectors.counting())); + return bookOwnershipCount.entrySet() + .stream() + .max(Map.Entry.comparingByValue()) + .map(Map.Entry::getKey) + .orElse(null); + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public List getBooks() { + return books; + } + + public void setBooks(List books) { + this.books = books; + } +} diff --git a/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/entitydtodifferences/mapper/UserMapper.java b/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/entitydtodifferences/mapper/UserMapper.java new file mode 100644 index 0000000000..0c6899f98b --- /dev/null +++ b/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/entitydtodifferences/mapper/UserMapper.java @@ -0,0 +1,34 @@ +package com.baeldung.entitydtodifferences.mapper; + +import java.util.stream.Collectors; + +import com.baeldung.entitydtodifferences.dto.BookDto; +import com.baeldung.entitydtodifferences.dto.UserCreationDto; +import com.baeldung.entitydtodifferences.dto.UserResponseDto; +import com.baeldung.entitydtodifferences.entity.Book; +import com.baeldung.entitydtodifferences.entity.User; + +public class UserMapper { + + public static UserResponseDto toDto(User entity) { + return new UserResponseDto(entity.getId(), entity.getFirstName(), entity.getLastName(), entity.getBooks() + .stream() + .map(UserMapper::toDto) + .collect(Collectors.toList())); + } + + public static User toEntity(UserCreationDto dto) { + return new User(dto.getFirstName(), dto.getLastName(), dto.getAddress(), dto.getBooks() + .stream() + .map(UserMapper::toEntity) + .collect(Collectors.toList())); + } + + public static BookDto toDto(Book entity) { + return new BookDto(entity.getName(), entity.getAuthor()); + } + + public static Book toEntity(BookDto dto) { + return new Book(dto.getName(), dto.getAuthor()); + } +} diff --git a/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/entitydtodifferences/repository/UserRepository.java b/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/entitydtodifferences/repository/UserRepository.java new file mode 100644 index 0000000000..4529de698e --- /dev/null +++ b/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/entitydtodifferences/repository/UserRepository.java @@ -0,0 +1,11 @@ +package com.baeldung.entitydtodifferences.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import com.baeldung.entitydtodifferences.entity.User; + +@Repository +public interface UserRepository extends JpaRepository { + +} diff --git a/spring-boot-modules/spring-boot-crud/src/test/java/com/baeldung/entitydtodifferences/ApplicationIntegrationTest.java b/spring-boot-modules/spring-boot-crud/src/test/java/com/baeldung/entitydtodifferences/ApplicationIntegrationTest.java new file mode 100644 index 0000000000..839bb381ec --- /dev/null +++ b/spring-boot-modules/spring-boot-crud/src/test/java/com/baeldung/entitydtodifferences/ApplicationIntegrationTest.java @@ -0,0 +1,15 @@ +package com.baeldung.entitydtodifferences; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +public class ApplicationIntegrationTest { + + @Test + public void contextLoads() { + } +} diff --git a/spring-boot-modules/spring-boot-crud/src/test/java/com/baeldung/entitydtodifferences/controller/UserControllerIntegrationTest.java b/spring-boot-modules/spring-boot-crud/src/test/java/com/baeldung/entitydtodifferences/controller/UserControllerIntegrationTest.java new file mode 100644 index 0000000000..83e359e378 --- /dev/null +++ b/spring-boot-modules/spring-boot-crud/src/test/java/com/baeldung/entitydtodifferences/controller/UserControllerIntegrationTest.java @@ -0,0 +1,93 @@ +package com.baeldung.entitydtodifferences.controller; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.Arrays; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; + +import com.baeldung.entitydtodifferences.entity.Book; +import com.baeldung.entitydtodifferences.entity.User; +import com.baeldung.entitydtodifferences.repository.UserRepository; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +@SpringBootTest +@AutoConfigureMockMvc +public class UserControllerIntegrationTest { + + @Autowired + private MockMvc mockMvc; + + @Autowired + private UserRepository userRepository; + + @Autowired + private ObjectMapper objectMapper; + + @BeforeEach + public void beforeEach() { + userRepository.deleteAll(); + } + + @Test + public void givenUsersAreExisting_whenGetUsers_thenUsersAreReturned() throws Exception { + //given + Book book1 = new Book("Book1", "Author1"); + Book book2 = new Book("Book2", "Author2"); + User savedUser = userRepository.save(new User("John", "Doe", "123 Main St", Arrays.asList(book1, book2))); + String expectedJson = String.format( + "[{\"ID\":%s,\"FIRST_NAME\":\"John\",\"LAST_NAME\":\"Doe\",\"BOOKS\":[{\"NAME\":\"Book1\",\"AUTHOR\":\"Author1\"},{\"NAME\":\"Book2\",\"AUTHOR\":\"Author2\"}]}]", + savedUser.getId()); + //when + MvcResult result = mockMvc.perform(MockMvcRequestBuilders.get("/users") + .contentType(MediaType.APPLICATION_JSON)) + .andReturn(); + //then + assertEquals(expectedJson, result.getResponse() + .getContentAsString()); + } + + @Test + public void givenValidUser_whenPostUser_thenUserIsCreated() throws Exception { + //given + String user = "{\"FIRST_NAME\":\"John\",\"LAST_NAME\":\"Doe\",\"BOOKS\":[{\"NAME\":\"Book1\",\"AUTHOR\":\"Author1\"},{\"NAME\":\"Book2\",\"AUTHOR\":\"Author2\"}]}"; + //when + MvcResult result = mockMvc.perform(MockMvcRequestBuilders.post("/users") + .content(user) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andReturn(); + JsonNode responseJson = objectMapper.readTree(result.getResponse() + .getContentAsString()); + //then + assertEquals("John", responseJson.get("FIRST_NAME") + .asText()); + assertEquals("Doe", responseJson.get("LAST_NAME") + .asText()); + assertTrue(responseJson.has("BOOKS")); + JsonNode booksArray = responseJson.get("BOOKS"); + assertEquals(2, booksArray.size()); + assertEquals("Book1", booksArray.get(0) + .get("NAME") + .asText()); + assertEquals("Author1", booksArray.get(0) + .get("AUTHOR") + .asText()); + assertEquals("Book2", booksArray.get(1) + .get("NAME") + .asText()); + assertEquals("Author2", booksArray.get(1) + .get("AUTHOR") + .asText()); + } +} diff --git a/spring-boot-modules/spring-boot-crud/src/test/java/com/baeldung/entitydtodifferences/entity/BookUnitTest.java b/spring-boot-modules/spring-boot-crud/src/test/java/com/baeldung/entitydtodifferences/entity/BookUnitTest.java new file mode 100644 index 0000000000..60e229b7c9 --- /dev/null +++ b/spring-boot-modules/spring-boot-crud/src/test/java/com/baeldung/entitydtodifferences/entity/BookUnitTest.java @@ -0,0 +1,19 @@ +package com.baeldung.entitydtodifferences.entity; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import org.junit.Test; + +public class BookUnitTest { + + @Test + public void whenBookInitialized_thenInitializedCorrectly() { + //when + Book book = new Book("Book1", "Author1"); + //then + assertNotNull(book); + assertEquals("Book1", book.getName()); + assertEquals("Author1", book.getAuthor()); + } +} diff --git a/spring-boot-modules/spring-boot-crud/src/test/java/com/baeldung/entitydtodifferences/entity/UserUnitTest.java b/spring-boot-modules/spring-boot-crud/src/test/java/com/baeldung/entitydtodifferences/entity/UserUnitTest.java new file mode 100644 index 0000000000..0d1efe7129 --- /dev/null +++ b/spring-boot-modules/spring-boot-crud/src/test/java/com/baeldung/entitydtodifferences/entity/UserUnitTest.java @@ -0,0 +1,51 @@ +package com.baeldung.entitydtodifferences.entity; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; + +import java.util.Arrays; +import java.util.Collections; + +import org.junit.Test; + +public class UserUnitTest { + + @Test + public void whenUserInitialized_thenInitializedCorrectly() { + //when + Book book1 = new Book("Book1", "Author1"); + Book book2 = new Book("Book2", "Author2"); + User user = new User("John", "Doe", "123 Main St", Arrays.asList(book1, book2)); + //then + assertNotNull(user); + assertEquals("John", user.getFirstName()); + assertEquals("Doe", user.getLastName()); + assertEquals("123 Main St", user.getAddress()); + assertEquals(2, user.getBooks() + .size()); + } + + @Test + public void givenUserOwningMultipleBooks_whenGetNameOfMostOwnedBook_thenComputedCorrectly() { + //given + Book book1 = new Book("Book1", "Author1"); + Book book2 = new Book("Book2", "Author2"); + Book book3 = new Book("Book2", "Author3"); + User user = new User("John", "Doe", "123 Main St", Arrays.asList(book1, book2, book3)); + //when + String mostOwnedBook = user.getNameOfMostOwnedBook(); + //then + assertEquals("Book2", mostOwnedBook); + } + + @Test + public void givenUserWithNoBooks_henGetNameOfMostOwnedBook_thenReturnedNull() { + //given + User user = new User("John", "Doe", "123 Main St", Collections.emptyList()); + //when + String mostOwnedBook = user.getNameOfMostOwnedBook(); + //then + assertNull(mostOwnedBook); + } +} diff --git a/spring-boot-modules/spring-boot-crud/src/test/java/com/baeldung/entitydtodifferences/mapper/UserMapperUnitTest.java b/spring-boot-modules/spring-boot-crud/src/test/java/com/baeldung/entitydtodifferences/mapper/UserMapperUnitTest.java new file mode 100644 index 0000000000..5154898877 --- /dev/null +++ b/spring-boot-modules/spring-boot-crud/src/test/java/com/baeldung/entitydtodifferences/mapper/UserMapperUnitTest.java @@ -0,0 +1,87 @@ +package com.baeldung.entitydtodifferences.mapper; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.Arrays; +import java.util.List; + +import org.junit.Test; + +import com.baeldung.entitydtodifferences.dto.BookDto; +import com.baeldung.entitydtodifferences.dto.UserCreationDto; +import com.baeldung.entitydtodifferences.dto.UserResponseDto; +import com.baeldung.entitydtodifferences.entity.Book; +import com.baeldung.entitydtodifferences.entity.User; + +public class UserMapperUnitTest { + + @Test + public void givenUserEntity_whenMappedToDto_thenMappedCorrectly() { + //given + Book book1 = new Book("Book1", "Author1"); + Book book2 = new Book("Book2", "Author2"); + User user = new User("John", "Doe", "123 Main St", Arrays.asList(book1, book2)); + //when + UserResponseDto userDto = UserMapper.toDto(user); + //then + assertEquals(user.getId(), userDto.getId()); + assertEquals(user.getFirstName(), userDto.getFirstName()); + assertEquals(user.getLastName(), userDto.getLastName()); + List bookDtos = userDto.getBooks(); + assertEquals(2, bookDtos.size()); + assertEquals(book1.getName(), bookDtos.get(0) + .getName()); + assertEquals(book1.getAuthor(), bookDtos.get(0) + .getAuthor()); + assertEquals(book2.getName(), bookDtos.get(1) + .getName()); + assertEquals(book2.getAuthor(), bookDtos.get(1) + .getAuthor()); + } + + @Test + public void givenUserDto_whenMappedToEntity_thenMappedCorrectly() { + //given + BookDto bookDto1 = new BookDto("Book3", "Author3"); + BookDto bookDto2 = new BookDto("Book4", "Author4"); + UserCreationDto userDto = new UserCreationDto("Jane", "Doe", "456 Oak St", Arrays.asList(bookDto1, bookDto2)); + //when + User user = UserMapper.toEntity(userDto); + //then + assertEquals(user.getFirstName(), userDto.getFirstName()); + assertEquals(user.getLastName(), userDto.getLastName()); + assertEquals(user.getAddress(), userDto.getAddress()); + List books = user.getBooks(); + assertEquals(2, books.size()); + assertEquals(bookDto1.getName(), books.get(0) + .getName()); + assertEquals(bookDto1.getAuthor(), books.get(0) + .getAuthor()); + assertEquals(bookDto2.getName(), books.get(1) + .getName()); + assertEquals(bookDto2.getAuthor(), books.get(1) + .getAuthor()); + } + + @Test + public void givenBookEntity_whenMappedToDto_thenMappedCorrectly() { + //given + Book book = new Book("Book5", "Author5"); + //when + BookDto bookDto = UserMapper.toDto(book); + //then + assertEquals(book.getName(), bookDto.getName()); + assertEquals(book.getAuthor(), bookDto.getAuthor()); + } + + @Test + public void givenBookDto_whenMappedToEntity_thenMappedCorrectly() { + //given + BookDto bookDto = new BookDto("Book6", "Author6"); + //when + Book book = UserMapper.toEntity(bookDto); + //then + assertEquals(bookDto.getName(), book.getName()); + assertEquals(bookDto.getAuthor(), book.getAuthor()); + } +} diff --git a/spring-boot-modules/spring-boot-data-2/README.md b/spring-boot-modules/spring-boot-data-2/README.md index 8e6619dce4..b8f0347453 100644 --- a/spring-boot-modules/spring-boot-data-2/README.md +++ b/spring-boot-modules/spring-boot-data-2/README.md @@ -6,4 +6,4 @@ - [Using JaVers for Data Model Auditing in Spring Data](https://www.baeldung.com/spring-data-javers-audit) - [BootstrapMode for JPA Repositories](https://www.baeldung.com/jpa-bootstrap-mode) - [Dynamic DTO Validation Config Retrieved from the Database](https://www.baeldung.com/spring-dynamic-dto-validation) - +- [Spring Custom Property Editor](https://www.baeldung.com/spring-mvc-custom-property-editor) diff --git a/spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/propertyeditor/PropertyEditorApplication.java b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/propertyeditor/PropertyEditorApplication.java similarity index 100% rename from spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/propertyeditor/PropertyEditorApplication.java rename to spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/propertyeditor/PropertyEditorApplication.java diff --git a/spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/propertyeditor/PropertyEditorRestController.java b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/propertyeditor/PropertyEditorRestController.java similarity index 100% rename from spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/propertyeditor/PropertyEditorRestController.java rename to spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/propertyeditor/PropertyEditorRestController.java diff --git a/spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/propertyeditor/creditcard/CreditCard.java b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/propertyeditor/creditcard/CreditCard.java similarity index 100% rename from spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/propertyeditor/creditcard/CreditCard.java rename to spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/propertyeditor/creditcard/CreditCard.java diff --git a/spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/propertyeditor/creditcard/CreditCardEditor.java b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/propertyeditor/creditcard/CreditCardEditor.java similarity index 100% rename from spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/propertyeditor/creditcard/CreditCardEditor.java rename to spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/propertyeditor/creditcard/CreditCardEditor.java diff --git a/spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/propertyeditor/exotictype/editor/CustomExoticTypeEditor.java b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/propertyeditor/exotictype/editor/CustomExoticTypeEditor.java similarity index 100% rename from spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/propertyeditor/exotictype/editor/CustomExoticTypeEditor.java rename to spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/propertyeditor/exotictype/editor/CustomExoticTypeEditor.java diff --git a/spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/propertyeditor/exotictype/model/ExoticType.java b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/propertyeditor/exotictype/model/ExoticType.java similarity index 100% rename from spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/propertyeditor/exotictype/model/ExoticType.java rename to spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/propertyeditor/exotictype/model/ExoticType.java diff --git a/spring-boot-modules/spring-boot-data/src/test/java/com/baeldung/propertyeditor/creditcard/CreditCardEditorUnitTest.java b/spring-boot-modules/spring-boot-data-2/src/test/java/com/baeldung/propertyeditor/creditcard/CreditCardEditorUnitTest.java similarity index 100% rename from spring-boot-modules/spring-boot-data/src/test/java/com/baeldung/propertyeditor/creditcard/CreditCardEditorUnitTest.java rename to spring-boot-modules/spring-boot-data-2/src/test/java/com/baeldung/propertyeditor/creditcard/CreditCardEditorUnitTest.java diff --git a/spring-boot-modules/spring-boot-data/README.md b/spring-boot-modules/spring-boot-data/README.md index aa745b77a2..49a6eedbed 100644 --- a/spring-boot-modules/spring-boot-data/README.md +++ b/spring-boot-modules/spring-boot-data/README.md @@ -8,7 +8,6 @@ This module contains articles about Spring Boot with Spring Data - [Rendering Exceptions in JSON with Spring](https://www.baeldung.com/spring-exceptions-json) - [Disable Spring Data Auto Configuration](https://www.baeldung.com/spring-data-disable-auto-config) - [Repositories with Multiple Spring Data Modules](https://www.baeldung.com/spring-multiple-data-modules) -- [Spring Custom Property Editor](https://www.baeldung.com/spring-mvc-custom-property-editor) - [Using @JsonComponent in Spring Boot](https://www.baeldung.com/spring-boot-jsoncomponent) - [Guide To Running Logic on Startup in Spring](https://www.baeldung.com/running-setup-logic-on-startup-in-spring) - [Spring Boot: Customize the Jackson ObjectMapper](https://www.baeldung.com/spring-boot-customize-jackson-objectmapper) diff --git a/spring-boot-modules/spring-boot-graphql/pom.xml b/spring-boot-modules/spring-boot-graphql/pom.xml index d3c122709d..b3f27f1b84 100644 --- a/spring-boot-modules/spring-boot-graphql/pom.xml +++ b/spring-boot-modules/spring-boot-graphql/pom.xml @@ -59,6 +59,7 @@ org.projectlombok lombok + ${lombok.version} com.h2database diff --git a/spring-boot-modules/spring-boot-graphql/src/test/java/com/baeldung/graphql/intro/SpringContextTest.java b/spring-boot-modules/spring-boot-graphql/src/test/java/com/baeldung/graphql/intro/SpringContextTest.java index 87bebf644c..a2e63a96f8 100644 --- a/spring-boot-modules/spring-boot-graphql/src/test/java/com/baeldung/graphql/intro/SpringContextTest.java +++ b/spring-boot-modules/spring-boot-graphql/src/test/java/com/baeldung/graphql/intro/SpringContextTest.java @@ -1,6 +1,5 @@ package com.baeldung.graphql.intro; -import com.baeldung.graphql.intro.GraphqlApplication; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; diff --git a/spring-boot-modules/spring-boot-libraries/pom.xml b/spring-boot-modules/spring-boot-libraries/pom.xml index b0f0c780aa..fd3daa1a79 100644 --- a/spring-boot-modules/spring-boot-libraries/pom.xml +++ b/spring-boot-modules/spring-boot-libraries/pom.xml @@ -225,7 +225,7 @@ 2.2.4 3.2.0 0.23.0 - 2.1.0 + 5.10.0 1.5-beta1 2.1 2.6.0 diff --git a/spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/scheduling/shedlock/BaeldungTaskScheduler.java b/spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/scheduling/shedlock/BaeldungTaskScheduler.java index cd5f63e962..c03d351c20 100644 --- a/spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/scheduling/shedlock/BaeldungTaskScheduler.java +++ b/spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/scheduling/shedlock/BaeldungTaskScheduler.java @@ -1,13 +1,13 @@ package com.baeldung.scheduling.shedlock; -import net.javacrumbs.shedlock.core.SchedulerLock; +import net.javacrumbs.shedlock.spring.annotation.SchedulerLock; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @Component class BaeldungTaskScheduler { @Scheduled(cron = "0 0/15 * * * ?") - @SchedulerLock(name = "TaskScheduler_scheduledTask", lockAtLeastForString = "PT5M", lockAtMostForString = "PT14M") + @SchedulerLock(name = "TaskScheduler_scheduledTask", lockAtLeastFor = "PT5M", lockAtMostFor = "PT14M") public void scheduledTask() { System.out.println("Running ShedLock task"); } diff --git a/spring-boot-modules/spring-boot-libraries/src/main/resources/application.yml b/spring-boot-modules/spring-boot-libraries/src/main/resources/application.yml index 3477520208..03c24f7778 100644 --- a/spring-boot-modules/spring-boot-libraries/src/main/resources/application.yml +++ b/spring-boot-modules/spring-boot-libraries/src/main/resources/application.yml @@ -1,6 +1,6 @@ spring: datasource: driverClassName: org.h2.Driver - url: jdbc:h2:mem:shedlock_DB;INIT=CREATE SCHEMA IF NOT EXISTS shedlock;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE + url: jdbc:h2:mem:shedlock_db;INIT=CREATE SCHEMA IF NOT EXISTS shedlock;DATABASE_TO_UPPER=false;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE username: sa password: diff --git a/spring-boot-modules/spring-boot-libraries/src/main/resources/schema.sql b/spring-boot-modules/spring-boot-libraries/src/main/resources/schema.sql new file mode 100644 index 0000000000..d5a5d51b74 --- /dev/null +++ b/spring-boot-modules/spring-boot-libraries/src/main/resources/schema.sql @@ -0,0 +1,7 @@ +CREATE TABLE IF NOT EXISTS shedlock( + name VARCHAR(64) NOT NULL, + lock_until TIMESTAMP NOT NULL, + locked_at TIMESTAMP NOT NULL, + locked_by VARCHAR(255) NOT NULL, + PRIMARY KEY (name) +); \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-logging-log4j2/pom.xml b/spring-boot-modules/spring-boot-logging-log4j2/pom.xml index 31c0f4bd02..de21a99ab3 100644 --- a/spring-boot-modules/spring-boot-logging-log4j2/pom.xml +++ b/spring-boot-modules/spring-boot-logging-log4j2/pom.xml @@ -40,6 +40,7 @@ org.projectlombok lombok + ${lombok.version} provided diff --git a/spring-boot-modules/spring-boot-mvc-5/README.md b/spring-boot-modules/spring-boot-mvc-5/README.md index 782adb7b34..c72d72c84f 100644 --- a/spring-boot-modules/spring-boot-mvc-5/README.md +++ b/spring-boot-modules/spring-boot-mvc-5/README.md @@ -5,3 +5,4 @@ This module contains articles about Spring Web MVC in Spring Boot projects. ### Relevant Articles: - [Enable and Disable Endpoints at Runtime With Spring Boot](https://www.baeldung.com/spring-boot-enable-disable-endpoints-at-runtime) - [Extracting a Custom Header From the Request](https://www.baeldung.com/spring-extract-custom-header-request) +- [Modify Request Body Before Reaching Controller in Spring Boot](https://www.baeldung.com/spring-boot-change-request-body-before-controller) diff --git a/spring-boot-modules/spring-boot-mvc-birt/pom.xml b/spring-boot-modules/spring-boot-mvc-birt/pom.xml index cc4b7f8283..b2cda67974 100644 --- a/spring-boot-modules/spring-boot-mvc-birt/pom.xml +++ b/spring-boot-modules/spring-boot-mvc-birt/pom.xml @@ -48,6 +48,7 @@ org.projectlombok lombok + ${lombok.version} provided diff --git a/spring-boot-modules/spring-boot-mvc/pom.xml b/spring-boot-modules/spring-boot-mvc/pom.xml index 963cda61b9..ab1c867d66 100644 --- a/spring-boot-modules/spring-boot-mvc/pom.xml +++ b/spring-boot-modules/spring-boot-mvc/pom.xml @@ -92,6 +92,7 @@ org.projectlombok lombok + ${lombok.version} diff --git a/spring-boot-modules/spring-boot-redis/pom.xml b/spring-boot-modules/spring-boot-redis/pom.xml index fa6b5a59c1..57a894e2fc 100644 --- a/spring-boot-modules/spring-boot-redis/pom.xml +++ b/spring-boot-modules/spring-boot-redis/pom.xml @@ -73,7 +73,6 @@ - 15 6.0.3 0.7.3 diff --git a/spring-boot-modules/spring-boot-resilience4j/pom.xml b/spring-boot-modules/spring-boot-resilience4j/pom.xml index 355ef8f92d..2f3af8f9d2 100644 --- a/spring-boot-modules/spring-boot-resilience4j/pom.xml +++ b/spring-boot-modules/spring-boot-resilience4j/pom.xml @@ -53,7 +53,7 @@ 2.35.0 2.0.2 - 2.15.2 + 2.16.0 \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-telegram/pom.xml b/spring-boot-modules/spring-boot-telegram/pom.xml index 9077e90400..a26566819a 100644 --- a/spring-boot-modules/spring-boot-telegram/pom.xml +++ b/spring-boot-modules/spring-boot-telegram/pom.xml @@ -39,7 +39,6 @@ - 17 6.7.0 diff --git a/spring-cloud-modules/spring-cloud-archaius/spring-cloud-archaius-dynamodb-config/pom.xml b/spring-cloud-modules/spring-cloud-archaius/spring-cloud-archaius-dynamodb-config/pom.xml index 600fedc774..371b5c2976 100644 --- a/spring-cloud-modules/spring-cloud-archaius/spring-cloud-archaius-dynamodb-config/pom.xml +++ b/spring-cloud-modules/spring-cloud-archaius/spring-cloud-archaius-dynamodb-config/pom.xml @@ -44,7 +44,6 @@ 1.11.407 5.0.3 0.7.6 - 1.18.26 \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-archaius/spring-cloud-archaius-jdbc-config/pom.xml b/spring-cloud-modules/spring-cloud-archaius/spring-cloud-archaius-jdbc-config/pom.xml index 2871f129b5..1ef57d4be3 100644 --- a/spring-cloud-modules/spring-cloud-archaius/spring-cloud-archaius-jdbc-config/pom.xml +++ b/spring-cloud-modules/spring-cloud-archaius/spring-cloud-archaius-jdbc-config/pom.xml @@ -34,8 +34,4 @@ - - 1.18.26 - - \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/pom.xml b/spring-cloud-modules/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/pom.xml index 08a85d191a..e540645f30 100644 --- a/spring-cloud-modules/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/pom.xml +++ b/spring-cloud-modules/spring-cloud-eureka/spring-cloud-eureka-feign-client-integration-test/pom.xml @@ -74,6 +74,7 @@ org.projectlombok lombok + ${lombok.version} org.testcontainers diff --git a/spring-cloud-modules/spring-cloud-netflix-sidecar/spring-cloud-netflix-sidecar-demo/pom.xml b/spring-cloud-modules/spring-cloud-netflix-sidecar/spring-cloud-netflix-sidecar-demo/pom.xml index f8552aba93..60b68fc4bd 100644 --- a/spring-cloud-modules/spring-cloud-netflix-sidecar/spring-cloud-netflix-sidecar-demo/pom.xml +++ b/spring-cloud-modules/spring-cloud-netflix-sidecar/spring-cloud-netflix-sidecar-demo/pom.xml @@ -26,6 +26,7 @@ io.projectreactor reactor-core + ${reactor-core.version} org.springframework.boot @@ -53,4 +54,7 @@ + + 3.6.0 + \ No newline at end of file diff --git a/spring-core-2/pom.xml b/spring-core-2/pom.xml index f27b16acc3..d22178004c 100644 --- a/spring-core-2/pom.xml +++ b/spring-core-2/pom.xml @@ -119,20 +119,10 @@ spring-boot-starter-test test - - - net.javacrumbs.shedlock - shedlock-spring - ${shedlock.version} - - - net.javacrumbs.shedlock - shedlock-provider-jdbc-template - ${shedlock.version} - org.projectlombok lombok + ${lombok.version} @@ -161,7 +151,6 @@ 1.3.2 3.6 - 2.1.0 3.22.0-GA 3.2.2 diff --git a/spring-credhub/pom.xml b/spring-credhub/pom.xml index defe378b6b..f257d549bf 100644 --- a/spring-credhub/pom.xml +++ b/spring-credhub/pom.xml @@ -23,6 +23,7 @@ org.projectlombok lombok + ${lombok.version} org.springframework.credhub diff --git a/spring-integration/pom.xml b/spring-integration/pom.xml index abf5cfb3d6..315f549c12 100644 --- a/spring-integration/pom.xml +++ b/spring-integration/pom.xml @@ -17,7 +17,6 @@ - org.springframework.integration spring-integration-core @@ -29,11 +28,6 @@ ${javax-activation.version} true - - javax.mail - mail - ${javax-mail.version} - org.springframework.integration spring-integration-twitter @@ -85,16 +79,21 @@ h2 ${h2.version} - - javax.xml.bind - jaxb-api - ${jaxb-api.version} - org.postgresql postgresql ${postgresql.version} + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + + + com.sun.mail + jakarta.mail + ${jakarta.mail.version} + @@ -124,14 +123,13 @@ - 5.1.13.RELEASE + 6.0.0 1.1.4.RELEASE 5.0.13.RELEASE - 1.4.7 1.1.1 2.10 - 2.3.0 42.3.8 + 2.0.1 \ No newline at end of file diff --git a/spring-integration/src/main/java/com/baeldung/dsl/JavaDSLFileCopyConfig.java b/spring-integration/src/main/java/com/baeldung/dsl/JavaDSLFileCopyConfig.java index adaeac5386..8afd39e9ab 100644 --- a/spring-integration/src/main/java/com/baeldung/dsl/JavaDSLFileCopyConfig.java +++ b/spring-integration/src/main/java/com/baeldung/dsl/JavaDSLFileCopyConfig.java @@ -1,6 +1,7 @@ package com.baeldung.dsl; import java.io.File; +import java.time.Duration; import java.util.Scanner; import java.util.concurrent.TimeUnit; @@ -14,7 +15,6 @@ import org.springframework.integration.config.EnableIntegration; import org.springframework.integration.core.GenericSelector; import org.springframework.integration.core.MessageSource; import org.springframework.integration.dsl.IntegrationFlow; -import org.springframework.integration.dsl.IntegrationFlows; import org.springframework.integration.dsl.Pollers; import org.springframework.integration.dsl.MessageChannels; import org.springframework.integration.file.FileReadingMessageSource; @@ -69,7 +69,7 @@ public class JavaDSLFileCopyConfig { @Bean public IntegrationFlow fileMover() { - return IntegrationFlows.from(sourceDirectory(), configurer -> configurer.poller(Pollers.fixedDelay(10000))) + return IntegrationFlow.from(sourceDirectory(), configurer -> configurer.poller(Pollers.fixedDelay(10000))) .filter(onlyJpgs()) .handle(targetDirectory()) .get(); @@ -77,7 +77,7 @@ public class JavaDSLFileCopyConfig { // @Bean public IntegrationFlow fileMoverWithLambda() { - return IntegrationFlows.from(sourceDirectory(), configurer -> configurer.poller(Pollers.fixedDelay(10000))) + return IntegrationFlow.from(sourceDirectory(), configurer -> configurer.poller(Pollers.fixedDelay(10000))) .filter(message -> ((File) message).getName() .endsWith(".jpg")) .handle(targetDirectory()) @@ -92,7 +92,7 @@ public class JavaDSLFileCopyConfig { // @Bean public IntegrationFlow fileMoverWithPriorityChannel() { - return IntegrationFlows.from(sourceDirectory()) + return IntegrationFlow.from(sourceDirectory()) .filter(onlyJpgs()) .channel("alphabetically") .handle(targetDirectory()) @@ -113,7 +113,7 @@ public class JavaDSLFileCopyConfig { // @Bean public IntegrationFlow fileReader() { - return IntegrationFlows.from(sourceDirectory(), configurer -> configurer.poller(Pollers.fixedDelay(10))) + return IntegrationFlow.from(sourceDirectory(), configurer -> configurer.poller(Pollers.fixedDelay(10))) .filter(onlyJpgs()) .channel("holdingTank") .get(); @@ -121,16 +121,16 @@ public class JavaDSLFileCopyConfig { // @Bean public IntegrationFlow fileWriter() { - return IntegrationFlows.from("holdingTank") - .bridge(e -> e.poller(Pollers.fixedRate(1, TimeUnit.SECONDS, 20))) + return IntegrationFlow.from("holdingTank") + .bridge(e -> e.poller(Pollers.fixedRate(Duration.of(1, TimeUnit.SECONDS.toChronoUnit()), Duration.of(20, TimeUnit.SECONDS.toChronoUnit())))) .handle(targetDirectory()) .get(); } // @Bean public IntegrationFlow anotherFileWriter() { - return IntegrationFlows.from("holdingTank") - .bridge(e -> e.poller(Pollers.fixedRate(2, TimeUnit.SECONDS, 10))) + return IntegrationFlow.from("holdingTank") + .bridge(e -> e.poller(Pollers.fixedRate(Duration.of(2, TimeUnit.SECONDS.toChronoUnit()), Duration.of(10, TimeUnit.SECONDS.toChronoUnit())))) .handle(anotherTargetDirectory()) .get(); } diff --git a/spring-kafka-2/pom.xml b/spring-kafka-2/pom.xml index 05da9418b7..7a4d5a5fea 100644 --- a/spring-kafka-2/pom.xml +++ b/spring-kafka-2/pom.xml @@ -38,6 +38,7 @@ org.projectlombok lombok + ${lombok.version} org.springframework.kafka diff --git a/spring-kafka-2/src/test/java/com/baeldung/spring/kafka/managingkafkaconsumergroups/ManagingConsumerGroupsIntegrationTest.java b/spring-kafka-2/src/test/java/com/baeldung/spring/kafka/managingkafkaconsumergroups/ManagingConsumerGroupsIntegrationTest.java index 1620add9ca..ddbb105a67 100644 --- a/spring-kafka-2/src/test/java/com/baeldung/spring/kafka/managingkafkaconsumergroups/ManagingConsumerGroupsIntegrationTest.java +++ b/spring-kafka-2/src/test/java/com/baeldung/spring/kafka/managingkafkaconsumergroups/ManagingConsumerGroupsIntegrationTest.java @@ -14,7 +14,7 @@ import java.util.Objects; import static org.junit.jupiter.api.Assertions.assertEquals; @SpringBootTest(classes = ManagingConsumerGroupsApplicationKafkaApp.class) -@EmbeddedKafka(partitions = 2, brokerProperties = {"listeners=PLAINTEXT://localhost:9092", "port=9092"}) +@EmbeddedKafka(partitions = 2, brokerProperties = {"listeners=PLAINTEXT://localhost:9098", "port=9098"}) public class ManagingConsumerGroupsIntegrationTest { private static final String CONSUMER_1_IDENTIFIER = "org.springframework.kafka.KafkaListenerEndpointContainer#1"; diff --git a/spring-kafka/pom.xml b/spring-kafka/pom.xml index ddef3ca180..6428734de2 100644 --- a/spring-kafka/pom.xml +++ b/spring-kafka/pom.xml @@ -48,6 +48,7 @@ org.projectlombok lombok + ${lombok.version} org.springframework.kafka diff --git a/spring-native/pom-nativeimage.xml b/spring-native/pom-nativeimage.xml index 6d42bedbe1..4fc01e4574 100644 --- a/spring-native/pom-nativeimage.xml +++ b/spring-native/pom-nativeimage.xml @@ -114,9 +114,6 @@ 2.7.1 0.12.1 0.9.17 - 1.8 - 1.8 - 1.8 diff --git a/spring-pulsar/pom.xml b/spring-pulsar/pom.xml index a1c834f830..b2feaddfb1 100644 --- a/spring-pulsar/pom.xml +++ b/spring-pulsar/pom.xml @@ -43,7 +43,6 @@ - 17 0.2.0 diff --git a/spring-reactive-modules/pom.xml b/spring-reactive-modules/pom.xml index 61a3c3d17d..c349707027 100644 --- a/spring-reactive-modules/pom.xml +++ b/spring-reactive-modules/pom.xml @@ -59,7 +59,22 @@ pom import + + io.projectreactor + reactor-core + ${reactor.version} + + + io.projectreactor + reactor-test + ${reactor.version} + test + + + 3.6.0 + + \ No newline at end of file diff --git a/spring-reactive-modules/spring-reactive-2/pom.xml b/spring-reactive-modules/spring-reactive-2/pom.xml index 90c5300cc8..fac93154c8 100644 --- a/spring-reactive-modules/spring-reactive-2/pom.xml +++ b/spring-reactive-modules/spring-reactive-2/pom.xml @@ -10,9 +10,10 @@ spring sample project about new features - com.baeldung.spring.reactive - spring-reactive-modules - 1.0.0-SNAPSHOT + com.baeldung + parent-boot-3 + 0.0.1-SNAPSHOT + ../../parent-boot-3 @@ -37,6 +38,7 @@ org.projectlombok lombok provided + ${lombok.version} org.springframework.boot @@ -44,8 +46,8 @@ test - com.github.tomakehurst - wiremock-jre8 + org.wiremock + wiremock ${wiremock.version} test @@ -63,6 +65,11 @@ org.springframework.boot spring-boot-starter-tomcat + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + @@ -115,7 +122,7 @@ 1.0.1.RELEASE - 2.24.0 + 3.3.1 \ No newline at end of file diff --git a/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/Spring5ReactiveApplication.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/Spring6ReactiveApplication.java similarity index 77% rename from spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/Spring5ReactiveApplication.java rename to spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/Spring6ReactiveApplication.java index ef862dd957..f716af4a0e 100644 --- a/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/Spring5ReactiveApplication.java +++ b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/Spring6ReactiveApplication.java @@ -5,10 +5,10 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration; @SpringBootApplication(exclude = { RedisAutoConfiguration.class }) -public class Spring5ReactiveApplication{ +public class Spring6ReactiveApplication { public static void main(String[] args) { - SpringApplication.run(Spring5ReactiveApplication.class, args); + SpringApplication.run(Spring6ReactiveApplication.class, args); } } diff --git a/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/consumer/ConsumerSSEApplication.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/consumer/ConsumerSSEApplication.java index d8edaf7fd5..bec7dd2e0c 100644 --- a/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/consumer/ConsumerSSEApplication.java +++ b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/consumer/ConsumerSSEApplication.java @@ -22,9 +22,10 @@ public class ConsumerSSEApplication { @Bean public SecurityWebFilterChain sseConsumerSpringSecurityFilterChain(ServerHttpSecurity http) { - http.authorizeExchange() - .anyExchange() - .permitAll(); + http.authorizeExchange(auth -> auth + .anyExchange().permitAll() + ) + .csrf(ServerHttpSecurity.CsrfSpec::disable); return http.build(); } diff --git a/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/urlmatch/FormHandler.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/urlmatch/FormHandler.java index 7b1fb06459..1652e2f25d 100644 --- a/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/urlmatch/FormHandler.java +++ b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/urlmatch/FormHandler.java @@ -34,7 +34,7 @@ public class FormHandler { private AtomicLong extractData(List dataBuffers) { AtomicLong atomicLong = new AtomicLong(0); - dataBuffers.forEach(d -> atomicLong.addAndGet(d.asByteBuffer() + dataBuffers.forEach(d -> atomicLong.addAndGet(d.toByteBuffer() .array().length)); return atomicLong; } diff --git a/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/util/CpuUtils.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/util/CpuUtils.java index 8d16434920..20cc162cde 100644 --- a/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/util/CpuUtils.java +++ b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/util/CpuUtils.java @@ -9,7 +9,7 @@ public class CpuUtils { private static OperatingSystemMXBean operatingSystemMXBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); static Double getUsage() { - return (operatingSystemMXBean.getSystemCpuLoad() / operatingSystemMXBean.getAvailableProcessors()) * 100; + return (operatingSystemMXBean.getCpuLoad() / operatingSystemMXBean.getAvailableProcessors()) * 100; } } diff --git a/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/staticcontent/StaticContentConfig.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/staticcontent/StaticContentConfig.java index 1fbb9958e7..456eec8f84 100644 --- a/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/staticcontent/StaticContentConfig.java +++ b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/staticcontent/StaticContentConfig.java @@ -23,7 +23,7 @@ public class StaticContentConfig { GET("/"), request -> ok() .contentType(MediaType.TEXT_HTML) - .syncBody(html) + .bodyValue(html) ); } diff --git a/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/FunctionalValidationsApplication.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/FunctionalValidationsApplication.java index 4cbb65dc60..bcbd4d55d7 100644 --- a/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/FunctionalValidationsApplication.java +++ b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/FunctionalValidationsApplication.java @@ -15,10 +15,11 @@ public class FunctionalValidationsApplication { @Bean public SecurityWebFilterChain functionalValidationsSpringSecurityFilterChain(ServerHttpSecurity http) { - http.authorizeExchange() - .anyExchange() - .permitAll(); - http.csrf().disable(); + http.authorizeExchange(auth -> auth + .anyExchange().permitAll() + ) + .csrf(ServerHttpSecurity.CsrfSpec::disable); + return http.build(); } } diff --git a/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/model/AnnotatedRequestEntity.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/model/AnnotatedRequestEntity.java index 992f07481c..6ca6c369c1 100644 --- a/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/model/AnnotatedRequestEntity.java +++ b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/model/AnnotatedRequestEntity.java @@ -1,7 +1,7 @@ package com.baeldung.validations.functional.model; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/backpressure/BackpressureUnitTest.java b/spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/backpressure/BackpressureUnitTest.java index a12d762fe5..c087e10b3f 100644 --- a/spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/backpressure/BackpressureUnitTest.java +++ b/spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/backpressure/BackpressureUnitTest.java @@ -24,49 +24,45 @@ public class BackpressureUnitTest { ); StepVerifier.create(limit) - .expectSubscription() - .thenRequest(15) - .expectNext(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) - .expectNext(11, 12, 13, 14, 15) - .thenRequest(10) - .expectNext(16, 17, 18, 19, 20, 21, 22, 23, 24, 25) - .verifyComplete(); + .expectSubscription() + .thenRequest(15) + .expectNext(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) + .expectNext(11, 12, 13, 14, 15) + .thenRequest(10) + .expectNext(16, 17, 18, 19, 20, 21, 22, 23, 24, 25) + .verifyComplete(); } @Test public void whenRequestingChunks10_thenMessagesAreReceived() { Flux request = Flux.range(1, 50); - request.subscribe( - integer -> LOGGER.debug(String.valueOf(integer)), - err -> err.printStackTrace(), - () -> LOGGER.debug("All 50 items have been successfully processed!!!"), - subscription -> { - for (int i = 0; i < 5; i++) { - LOGGER.debug("Requesting the next 10 elements!!!"); - subscription.request(10); - } - } - ); + request.subscribe(integer -> LOGGER.debug(String.valueOf(integer)), err -> err.printStackTrace(), () -> LOGGER.debug("All 50 items have been successfully processed!!!"), subscription -> { + for (int i = 0; i < 5; i++) { + LOGGER.debug("Requesting the next 10 elements!!!"); + subscription.request(10); + } + }); StepVerifier.create(request) - .expectSubscription() - .thenRequest(10) - .expectNext(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) - .thenRequest(10) - .expectNext(11, 12, 13, 14, 15, 16, 17, 18, 19, 20) - .thenRequest(10) - .expectNext(21, 22, 23, 24, 25, 26, 27 , 28, 29 ,30) - .thenRequest(10) - .expectNext(31, 32, 33, 34, 35, 36, 37 , 38, 39 ,40) - .thenRequest(10) - .expectNext(41, 42, 43, 44, 45, 46, 47 , 48, 49 ,50) - .verifyComplete(); + .expectSubscription() + .thenRequest(10) + .expectNext(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) + .thenRequest(10) + .expectNext(11, 12, 13, 14, 15, 16, 17, 18, 19, 20) + .thenRequest(10) + .expectNext(21, 22, 23, 24, 25, 26, 27, 28, 29, 30) + .thenRequest(10) + .expectNext(31, 32, 33, 34, 35, 36, 37, 38, 39, 40) + .thenRequest(10) + .expectNext(41, 42, 43, 44, 45, 46, 47, 48, 49, 50) + .verifyComplete(); } @Test public void whenCancel_thenSubscriptionFinished() { - Flux cancel = Flux.range(1, 10).log(); + Flux cancel = Flux.range(1, 10) + .log(); cancel.subscribe(new BaseSubscriber() { @Override @@ -78,9 +74,9 @@ public class BackpressureUnitTest { }); StepVerifier.create(cancel) - .expectNext(1, 2, 3) - .thenCancel() - .verify(); + .expectNext(1, 2, 3) + .thenCancel() + .verify(); } } diff --git a/spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/reactive/urlmatch/PathPatternsUsingHandlerMethodIntegrationTest.java b/spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/reactive/urlmatch/PathPatternsUsingHandlerMethodIntegrationTest.java index 0b4607b54a..4069888dcd 100644 --- a/spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/reactive/urlmatch/PathPatternsUsingHandlerMethodIntegrationTest.java +++ b/spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/reactive/urlmatch/PathPatternsUsingHandlerMethodIntegrationTest.java @@ -8,11 +8,11 @@ import org.springframework.security.test.context.support.WithMockUser; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.reactive.server.WebTestClient; -import com.baeldung.reactive.Spring5ReactiveApplication; +import com.baeldung.reactive.Spring6ReactiveApplication; import com.baeldung.reactive.controller.PathPatternController; @RunWith(SpringRunner.class) -@SpringBootTest(classes = Spring5ReactiveApplication.class) +@SpringBootTest(classes = Spring6ReactiveApplication.class) @WithMockUser public class PathPatternsUsingHandlerMethodIntegrationTest { diff --git a/spring-reactive-modules/spring-reactive-3/pom.xml b/spring-reactive-modules/spring-reactive-3/pom.xml index bf2cdbbf2d..17c9690157 100644 --- a/spring-reactive-modules/spring-reactive-3/pom.xml +++ b/spring-reactive-modules/spring-reactive-3/pom.xml @@ -46,6 +46,7 @@ org.projectlombok lombok + ${lombok.version} org.springframework.boot diff --git a/spring-reactive-modules/spring-reactive-client-2/pom.xml b/spring-reactive-modules/spring-reactive-client-2/pom.xml index 5d5f3ebc2e..f7d82053bb 100644 --- a/spring-reactive-modules/spring-reactive-client-2/pom.xml +++ b/spring-reactive-modules/spring-reactive-client-2/pom.xml @@ -135,7 +135,6 @@ 1.0.1.RELEASE 1.1.6 - 3.2.10.RELEASE 1.7.1 diff --git a/spring-reactive-modules/spring-reactive-client/pom.xml b/spring-reactive-modules/spring-reactive-client/pom.xml index 5736ce497f..634fef1273 100644 --- a/spring-reactive-modules/spring-reactive-client/pom.xml +++ b/spring-reactive-modules/spring-reactive-client/pom.xml @@ -106,6 +106,7 @@ org.projectlombok lombok + ${lombok.version} org.mockito @@ -116,7 +117,6 @@ io.projectreactor reactor-test - ${reactor-test.version} test diff --git a/spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/reactive/logging/WebClientLoggingIntegrationTest.java b/spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/reactive/logging/WebClientLoggingIntegrationTest.java index e1eefe4d61..27dde13608 100644 --- a/spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/reactive/logging/WebClientLoggingIntegrationTest.java +++ b/spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/reactive/logging/WebClientLoggingIntegrationTest.java @@ -2,6 +2,7 @@ package com.baeldung.reactive.logging; import static com.baeldung.reactive.logging.jetty.RequestLogEnhancer.enhance; import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -136,9 +137,7 @@ public class WebClientLoggingIntegrationTest { public void givenDefaultHttpClientWithFilter_whenEndpointIsConsumed_thenRequestAndResponseLogged() { WebClient .builder() - .filters(exchangeFilterFunctions -> { - exchangeFilterFunctions.addAll(LogFilters.prepareFilters()); - }) + .filters(exchangeFilterFunctions -> exchangeFilterFunctions.addAll(LogFilters.prepareFilters())) .build() .post() .uri(sampleUrl) @@ -146,8 +145,6 @@ public class WebClientLoggingIntegrationTest { .exchange() .block(); - verify(mockAppender).doAppend(argThat(argument -> (((LoggingEvent) argument).getFormattedMessage()).contains(sampleUrl))); + verify(mockAppender, atLeast(1)).doAppend(argThat(argument -> (((LoggingEvent) argument).getFormattedMessage()).contains(sampleUrl))); } - - } diff --git a/spring-reactive-modules/spring-reactive-data-couchbase/pom.xml b/spring-reactive-modules/spring-reactive-data-couchbase/pom.xml index 2ac8ad19ac..84515fedeb 100644 --- a/spring-reactive-modules/spring-reactive-data-couchbase/pom.xml +++ b/spring-reactive-modules/spring-reactive-data-couchbase/pom.xml @@ -29,7 +29,6 @@ io.projectreactor reactor-core - ${reactor-core.version} org.springframework.boot @@ -136,11 +135,9 @@ 5.2.2.RELEASE 4.5.2 1.5.23 - 3.3.1.RELEASE 2.2.6.RELEASE 2.17.1 - 1.18.26 \ No newline at end of file diff --git a/spring-reactive-modules/spring-reactive-data/pom.xml b/spring-reactive-modules/spring-reactive-data/pom.xml index a598315d5d..d72072e419 100644 --- a/spring-reactive-modules/spring-reactive-data/pom.xml +++ b/spring-reactive-modules/spring-reactive-data/pom.xml @@ -13,9 +13,6 @@ 1.0.0-SNAPSHOT - - UTF-8 - @@ -53,6 +50,7 @@ org.projectlombok lombok true + ${lombok.version} io.projectreactor @@ -62,7 +60,7 @@ javax.validation validation-api - 2.0.1.Final + ${validation-api.version} io.r2dbc @@ -70,4 +68,9 @@ + + UTF-8 + 2.0.1.Final + + \ No newline at end of file diff --git a/spring-reactive-modules/spring-reactive-security/pom.xml b/spring-reactive-modules/spring-reactive-security/pom.xml index cf34b21083..d501a03c46 100644 --- a/spring-reactive-modules/spring-reactive-security/pom.xml +++ b/spring-reactive-modules/spring-reactive-security/pom.xml @@ -41,6 +41,7 @@ org.projectlombok lombok compile + ${lombok.version} org.apache.geronimo.specs @@ -81,7 +82,7 @@ io.projectreactor reactor-test - ${project-reactor-test.version} + ${reactor-test.version} test @@ -114,7 +115,8 @@ 1.1.3 1.0 1.0 - 3.1.6.RELEASE + 3.1.6.RELEASE + 3.4.29 \ No newline at end of file diff --git a/spring-reactive-modules/spring-reactive/pom.xml b/spring-reactive-modules/spring-reactive/pom.xml index f19809e302..04bd32d632 100644 --- a/spring-reactive-modules/spring-reactive/pom.xml +++ b/spring-reactive-modules/spring-reactive/pom.xml @@ -104,7 +104,7 @@ - 3.4.16 + 3.6.0 1.3.10 2.2.21 diff --git a/spring-reactive-modules/spring-reactor/pom.xml b/spring-reactive-modules/spring-reactor/pom.xml index c2635765f0..54a97b92de 100644 --- a/spring-reactive-modules/spring-reactor/pom.xml +++ b/spring-reactive-modules/spring-reactor/pom.xml @@ -27,17 +27,18 @@ io.projectreactor reactor-bus - ${reactor.version} + ${reactor-bus.version} io.projectreactor reactor-core - ${reactor.version} + ${reactor-core.version} - 2.0.8.RELEASE + 2.0.8.RELEASE + 2.0.8.RELEASE \ No newline at end of file diff --git a/spring-scheduling/README.md b/spring-scheduling/README.md index 4ee306c0e0..4c42c60c37 100644 --- a/spring-scheduling/README.md +++ b/spring-scheduling/README.md @@ -5,3 +5,4 @@ - [How To Do @Async in Spring](https://www.baeldung.com/spring-async) - [Conditionally Enable Scheduled Jobs in Spring](https://www.baeldung.com/spring-scheduled-enabled-conditionally) - [Remote Debugging with IntelliJ IDEA](https://www.baeldung.com/intellij-remote-debugging) +- [Setup Asynchronous Retry Mechanism in Spring](https://www.baeldung.com/spring-async-retry) diff --git a/spring-security-modules/spring-security-azuread/pom.xml b/spring-security-modules/spring-security-azuread/pom.xml index 7e67a7e635..b32a1eb16a 100644 --- a/spring-security-modules/spring-security-azuread/pom.xml +++ b/spring-security-modules/spring-security-azuread/pom.xml @@ -11,10 +11,6 @@ spring-security-azuread - - 1.8 - - org.springframework.boot @@ -48,6 +44,7 @@ org.projectlombok lombok true + ${lombok.version} org.springframework.boot diff --git a/spring-security-modules/spring-security-oauth2-testing/reactive-resource-server/pom.xml b/spring-security-modules/spring-security-oauth2-testing/reactive-resource-server/pom.xml index 3d5ff0cb69..a5ce06f4d9 100644 --- a/spring-security-modules/spring-security-oauth2-testing/reactive-resource-server/pom.xml +++ b/spring-security-modules/spring-security-oauth2-testing/reactive-resource-server/pom.xml @@ -12,9 +12,7 @@ reactive-resource-server reactive-resource-server Demo project for Spring Boot reactive resource-server - - 17 - + org.springframework.boot diff --git a/spring-security-modules/spring-security-oauth2-testing/servlet-resource-server/pom.xml b/spring-security-modules/spring-security-oauth2-testing/servlet-resource-server/pom.xml index eb507fc3d3..44403cf341 100644 --- a/spring-security-modules/spring-security-oauth2-testing/servlet-resource-server/pom.xml +++ b/spring-security-modules/spring-security-oauth2-testing/servlet-resource-server/pom.xml @@ -12,9 +12,7 @@ servlet-resource-server servlet-resource-server Demo project for Spring Boot servlet resource-server - - 17 - + org.springframework.boot diff --git a/spring-security-modules/spring-security-opa/pom.xml b/spring-security-modules/spring-security-opa/pom.xml index a6240f6e69..81c4709124 100644 --- a/spring-security-modules/spring-security-opa/pom.xml +++ b/spring-security-modules/spring-security-opa/pom.xml @@ -23,6 +23,7 @@ org.projectlombok lombok + ${lombok.version} com.google.guava diff --git a/spring-security-modules/spring-security-saml2/pom.xml b/spring-security-modules/spring-security-saml2/pom.xml index 6de69fd201..64a4e22627 100644 --- a/spring-security-modules/spring-security-saml2/pom.xml +++ b/spring-security-modules/spring-security-saml2/pom.xml @@ -82,7 +82,6 @@ - 17 4.1.1 diff --git a/spring-soap/pom.xml b/spring-soap/pom.xml index 6c49f1f39c..c796b08e9a 100644 --- a/spring-soap/pom.xml +++ b/spring-soap/pom.xml @@ -102,7 +102,6 @@ - 17 4.0.0 3.1.0 0.15.3 diff --git a/spring-swagger-codegen/custom-validations-opeanpi-codegen/pom.xml b/spring-swagger-codegen/custom-validations-opeanpi-codegen/pom.xml index 95d3239b96..136f5b8907 100644 --- a/spring-swagger-codegen/custom-validations-opeanpi-codegen/pom.xml +++ b/spring-swagger-codegen/custom-validations-opeanpi-codegen/pom.xml @@ -11,9 +11,8 @@ com.baeldung - parent-boot-2 + spring-swagger-codegen 0.0.1-SNAPSHOT - ../../parent-boot-2 @@ -83,12 +82,11 @@ - 11 3.0.0 2.17.1 1.7.0 3.3.4 - 2.10.0.pr3 + 2.16.0 5.1.0 diff --git a/spring-swagger-codegen/pom.xml b/spring-swagger-codegen/pom.xml index d4fff7eb63..ce28f28c22 100644 --- a/spring-swagger-codegen/pom.xml +++ b/spring-swagger-codegen/pom.xml @@ -16,6 +16,7 @@ + custom-validations-opeanpi-codegen spring-swagger-codegen-api-client spring-openapi-generator-api-client spring-swagger-codegen-app diff --git a/spring-swagger-codegen/spring-swagger-codegen-api-client/pom.xml b/spring-swagger-codegen/spring-swagger-codegen-api-client/pom.xml index af12f9cef0..5ad15f6851 100644 --- a/spring-swagger-codegen/spring-swagger-codegen-api-client/pom.xml +++ b/spring-swagger-codegen/spring-swagger-codegen-api-client/pom.xml @@ -33,7 +33,6 @@ com.baeldung spring-swagger-codegen 0.0.1-SNAPSHOT - ../../spring-swagger-codegen diff --git a/spring-swagger-codegen/spring-swagger-codegen-app/pom.xml b/spring-swagger-codegen/spring-swagger-codegen-app/pom.xml index d3f57474ef..a7969df518 100644 --- a/spring-swagger-codegen/spring-swagger-codegen-app/pom.xml +++ b/spring-swagger-codegen/spring-swagger-codegen-app/pom.xml @@ -10,7 +10,6 @@ com.baeldung spring-swagger-codegen 0.0.1-SNAPSHOT - ../../spring-swagger-codegen diff --git a/spring-vault/pom.xml b/spring-vault/pom.xml index b3690c7b7f..768303cb4b 100644 --- a/spring-vault/pom.xml +++ b/spring-vault/pom.xml @@ -83,7 +83,6 @@ 2.3.4 2.20.140 3.1.3 - 17 \ No newline at end of file diff --git a/spring-web-modules/spring-mvc-forms-thymeleaf/pom.xml b/spring-web-modules/spring-mvc-forms-thymeleaf/pom.xml index eb31723798..9c9d6804ae 100644 --- a/spring-web-modules/spring-mvc-forms-thymeleaf/pom.xml +++ b/spring-web-modules/spring-mvc-forms-thymeleaf/pom.xml @@ -27,6 +27,7 @@ org.projectlombok lombok + ${lombok.version} diff --git a/spring-web-modules/spring-mvc-java-2/README.md b/spring-web-modules/spring-mvc-java-2/README.md index 1f8231bada..61549b539a 100644 --- a/spring-web-modules/spring-mvc-java-2/README.md +++ b/spring-web-modules/spring-mvc-java-2/README.md @@ -5,3 +5,5 @@ - [A Quick Guide to Spring MVC Matrix Variables](https://www.baeldung.com/spring-mvc-matrix-variables) - [Converting a Spring MultipartFile to a File](https://www.baeldung.com/spring-multipartfile-to-file) - [Testing a Spring Multipart POST Request](https://www.baeldung.com/spring-multipart-post-request-test) +- [Introduction to HtmlUnit](https://www.baeldung.com/htmlunit) +- [Upload and Display Excel Files with Spring MVC](https://www.baeldung.com/spring-mvc-excel-files) diff --git a/spring-web-modules/spring-mvc-java-2/pom.xml b/spring-web-modules/spring-mvc-java-2/pom.xml index b1b5a797f8..a4484ed56d 100644 --- a/spring-web-modules/spring-mvc-java-2/pom.xml +++ b/spring-web-modules/spring-mvc-java-2/pom.xml @@ -46,6 +46,57 @@ commons-fileupload ${commons-fileupload.version} + + net.sourceforge.htmlunit + htmlunit + ${htmlunit.version} + + + commons-logging + commons-logging + + + commons-io + commons-io + + + + + + org.apache.poi + poi-ooxml + ${poi.version} + + + org.glassfish + javax.el + ${javax.el.version} + + + javax.servlet.jsp + javax.servlet.jsp-api + ${javax-servlet-api.version} + + + javax.servlet + jstl + + + org.apache.tomcat.embed + tomcat-embed-jasper + provided + + + + org.thymeleaf + thymeleaf-spring4 + ${thymeleaf.version} + + + org.thymeleaf + thymeleaf + ${thymeleaf.version} + @@ -63,6 +114,11 @@ 5.2.2.RELEASE 2.3.5 1.5 + 2.32 + 3.16-beta1 + 3.0.1-b09 + 2.3.3 + 3.0.9.RELEASE \ No newline at end of file diff --git a/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/ExcelController.java b/spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/excel/ExcelController.java similarity index 97% rename from spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/ExcelController.java rename to spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/excel/ExcelController.java index f76f7441a5..5cb5de7124 100644 --- a/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/web/controller/ExcelController.java +++ b/spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/excel/ExcelController.java @@ -1,18 +1,19 @@ -package com.baeldung.web.controller; +package com.baeldung.excel; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.Map; + +import javax.annotation.Resource; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.multipart.MultipartFile; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import com.baeldung.excel.*; -import java.util.Map; -import java.util.List; -import javax.annotation.Resource; @Controller public class ExcelController { diff --git a/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/excel/ExcelPOIHelper.java b/spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/excel/ExcelPOIHelper.java similarity index 100% rename from spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/excel/ExcelPOIHelper.java rename to spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/excel/ExcelPOIHelper.java index 0519a8f3c7..7a213d523b 100644 --- a/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/excel/ExcelPOIHelper.java +++ b/spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/excel/ExcelPOIHelper.java @@ -1,13 +1,14 @@ package com.baeldung.excel; -import org.apache.poi.ss.usermodel.Cell; -import org.apache.poi.xssf.usermodel.XSSFCell; -import org.apache.poi.xssf.usermodel.XSSFCellStyle; -import org.apache.poi.xssf.usermodel.XSSFColor; -import org.apache.poi.xssf.usermodel.XSSFFont; -import org.apache.poi.xssf.usermodel.XSSFRow; -import org.apache.poi.xssf.usermodel.XSSFSheet; -import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.IntStream; + import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFCellStyle; import org.apache.poi.hssf.usermodel.HSSFFont; @@ -15,16 +16,15 @@ import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.util.HSSFColor; +import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.DateUtil; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.Map; -import java.util.HashMap; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.IntStream; +import org.apache.poi.xssf.usermodel.XSSFCell; +import org.apache.poi.xssf.usermodel.XSSFCellStyle; +import org.apache.poi.xssf.usermodel.XSSFColor; +import org.apache.poi.xssf.usermodel.XSSFFont; +import org.apache.poi.xssf.usermodel.XSSFRow; +import org.apache.poi.xssf.usermodel.XSSFSheet; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; public class ExcelPOIHelper { diff --git a/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/excel/MyCell.java b/spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/excel/MyCell.java similarity index 100% rename from spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/excel/MyCell.java rename to spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/excel/MyCell.java diff --git a/spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/excel/WebConfig.java b/spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/excel/WebConfig.java new file mode 100644 index 0000000000..f6a4d4dba3 --- /dev/null +++ b/spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/excel/WebConfig.java @@ -0,0 +1,32 @@ +package com.baeldung.excel; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + + +@EnableWebMvc +@Configuration +@ComponentScan(basePackages = { "com.baeldung.excel" }) +public class WebConfig implements WebMvcConfigurer { + + @Override + public void addViewControllers(final ViewControllerRegistry registry) { + registry.addViewController("/").setViewName("index"); + } + + @Override + public void addResourceHandlers(final ResourceHandlerRegistry registry) { + registry.addResourceHandler("/resources/**").addResourceLocations("/resources/"); + } + + + @Bean + public ExcelPOIHelper excelPOIHelper() { + return new ExcelPOIHelper(); + } +} diff --git a/spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/htmlunit/HtmlUnitAndJUnitLiveTest.java b/spring-web-modules/spring-mvc-java-2/src/test/java/com/baeldung/htmlunit/HtmlUnitAndJUnitLiveTest.java similarity index 100% rename from spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/htmlunit/HtmlUnitAndJUnitLiveTest.java rename to spring-web-modules/spring-mvc-java-2/src/test/java/com/baeldung/htmlunit/HtmlUnitAndJUnitLiveTest.java diff --git a/spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/htmlunit/HtmlUnitAndSpringLiveTest.java b/spring-web-modules/spring-mvc-java-2/src/test/java/com/baeldung/htmlunit/HtmlUnitAndSpringLiveTest.java similarity index 100% rename from spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/htmlunit/HtmlUnitAndSpringLiveTest.java rename to spring-web-modules/spring-mvc-java-2/src/test/java/com/baeldung/htmlunit/HtmlUnitAndSpringLiveTest.java diff --git a/spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/htmlunit/HtmlUnitWebScrapingLiveTest.java b/spring-web-modules/spring-mvc-java-2/src/test/java/com/baeldung/htmlunit/HtmlUnitWebScrapingLiveTest.java similarity index 100% rename from spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/htmlunit/HtmlUnitWebScrapingLiveTest.java rename to spring-web-modules/spring-mvc-java-2/src/test/java/com/baeldung/htmlunit/HtmlUnitWebScrapingLiveTest.java diff --git a/spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/htmlunit/TestConfig.java b/spring-web-modules/spring-mvc-java-2/src/test/java/com/baeldung/htmlunit/TestConfig.java similarity index 99% rename from spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/htmlunit/TestConfig.java rename to spring-web-modules/spring-mvc-java-2/src/test/java/com/baeldung/htmlunit/TestConfig.java index 75efd57ae4..6e55f01454 100644 --- a/spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/htmlunit/TestConfig.java +++ b/spring-web-modules/spring-mvc-java-2/src/test/java/com/baeldung/htmlunit/TestConfig.java @@ -20,7 +20,7 @@ public class TestConfig implements WebMvcConfigurer { @Autowired private ServletContext ctx; - + @Bean public ViewResolver thymeleafViewResolver() { final ThymeleafViewResolver viewResolver = new ThymeleafViewResolver(); @@ -44,4 +44,4 @@ public class TestConfig implements WebMvcConfigurer { templateEngine.setTemplateResolver(templateResolver()); return templateEngine; } -} +} \ No newline at end of file diff --git a/spring-web-modules/spring-mvc-java/README.md b/spring-web-modules/spring-mvc-java/README.md index 656e415f6a..d89f33fdc1 100644 --- a/spring-web-modules/spring-mvc-java/README.md +++ b/spring-web-modules/spring-mvc-java/README.md @@ -9,8 +9,6 @@ The "REST With Spring" Classes: https://bit.ly/restwithspring ### Relevant Articles: - [Integration Testing in Spring](https://www.baeldung.com/integration-testing-in-spring) - [File Upload with Spring MVC](https://www.baeldung.com/spring-file-upload) -- [Introduction to HtmlUnit](https://www.baeldung.com/htmlunit) -- [Upload and Display Excel Files with Spring MVC](https://www.baeldung.com/spring-mvc-excel-files) - [web.xml vs Initializer with Spring](https://www.baeldung.com/spring-xml-vs-java-config) - [A Java Web Application Without a web.xml](https://www.baeldung.com/java-web-app-without-web-xml) - [Accessing Spring MVC Model Objects in JavaScript](https://www.baeldung.com/spring-mvc-model-objects-js) diff --git a/spring-web-modules/spring-mvc-java/pom.xml b/spring-web-modules/spring-mvc-java/pom.xml index 395b12a278..d4c8f24431 100644 --- a/spring-web-modules/spring-mvc-java/pom.xml +++ b/spring-web-modules/spring-mvc-java/pom.xml @@ -44,21 +44,7 @@ provided - - net.sourceforge.htmlunit - htmlunit - ${htmlunit.version} - - - commons-logging - commons-logging - - - commons-io - commons-io - - - + commons-io commons-io @@ -91,12 +77,7 @@ spring-boot-starter-test test - - - org.apache.poi - poi-ooxml - ${poi.version} - + org.hibernate.validator @@ -221,19 +202,15 @@ 4.4.5 4.5.2 - 2.23 2.7 1.6.1 3.1.0 1.9.1 - - 3.16-beta1 3.0.1-b09 4.0.1 2.3.3 - 2.32 2.8.0 com.baeldung.SpringMVCApplication diff --git a/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/WebConfig.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/WebConfig.java index 768fda1c4a..c135164a95 100644 --- a/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/WebConfig.java +++ b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/WebConfig.java @@ -27,7 +27,6 @@ import org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver; import org.thymeleaf.spring4.view.ThymeleafViewResolver; import org.thymeleaf.templateresolver.ITemplateResolver; -import com.baeldung.excel.ExcelPOIHelper; @EnableWebMvc @Configuration @@ -118,11 +117,6 @@ public class WebConfig implements WebMvcConfigurer { configurer.setUrlPathHelper(urlPathHelper); } - @Bean - public ExcelPOIHelper excelPOIHelper() { - return new ExcelPOIHelper(); - } - @Bean(name = "multipartResolver") public CommonsMultipartResolver multipartResolver() { CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver(); diff --git a/spring-web-modules/spring-session/spring-session-jdbc/pom.xml b/spring-web-modules/spring-session/spring-session-jdbc/pom.xml index 3cc2b8d18e..24194f5426 100644 --- a/spring-web-modules/spring-session/spring-session-jdbc/pom.xml +++ b/spring-web-modules/spring-session/spring-session-jdbc/pom.xml @@ -11,9 +11,9 @@ com.baeldung - parent-boot-2 + parent-boot-3 0.0.1-SNAPSHOT - ../../../parent-boot-2 + ../../../parent-boot-3 diff --git a/spring-web-modules/spring-session/spring-session-jdbc/src/main/java/com/baeldung/springsessionjdbc/controller/SpringSessionJdbcController.java b/spring-web-modules/spring-session/spring-session-jdbc/src/main/java/com/baeldung/springsessionjdbc/controller/SpringSessionJdbcController.java index 509a5f292b..a173636ed8 100644 --- a/spring-web-modules/spring-session/spring-session-jdbc/src/main/java/com/baeldung/springsessionjdbc/controller/SpringSessionJdbcController.java +++ b/spring-web-modules/spring-session/spring-session-jdbc/src/main/java/com/baeldung/springsessionjdbc/controller/SpringSessionJdbcController.java @@ -7,11 +7,12 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpSession; import java.util.ArrayList; import java.util.List; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpSession; + @Controller public class SpringSessionJdbcController { diff --git a/spring-web-modules/spring-session/spring-session-jdbc/src/test/java/com/baeldung/springsessionjdbc/SpringSessionJdbcIntegrationTest.java b/spring-web-modules/spring-session/spring-session-jdbc/src/test/java/com/baeldung/springsessionjdbc/SpringSessionJdbcIntegrationTest.java index 2dcc0b3af8..7133111e4c 100644 --- a/spring-web-modules/spring-session/spring-session-jdbc/src/test/java/com/baeldung/springsessionjdbc/SpringSessionJdbcIntegrationTest.java +++ b/spring-web-modules/spring-session/spring-session-jdbc/src/test/java/com/baeldung/springsessionjdbc/SpringSessionJdbcIntegrationTest.java @@ -9,7 +9,7 @@ import org.junit.runners.MethodSorters; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.boot.test.web.server.LocalServerPort; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; diff --git a/spring-websockets/pom.xml b/spring-websockets/pom.xml index a28ef8749a..d6c5fbe561 100644 --- a/spring-websockets/pom.xml +++ b/spring-websockets/pom.xml @@ -22,11 +22,12 @@ io.projectreactor reactor-core + ${reactor-core.version} com.github.javafaker javafaker - 1.0.2 + ${javafaker.version} com.google.code.gson @@ -44,4 +45,9 @@ + + 3.6.0 + 1.0.2 + + \ No newline at end of file diff --git a/static-analysis/README.md b/static-analysis/README.md index 235b79853b..ea0d797407 100644 --- a/static-analysis/README.md +++ b/static-analysis/README.md @@ -6,3 +6,4 @@ This module contains articles about static program analysis - [Introduction to PMD](https://www.baeldung.com/pmd) - [Java Static Analysis Tools in Eclipse and IntelliJ IDEA](https://www.baeldung.com/java-static-analysis-tools) +- [Catch Common Mistakes with Error Prone Library in Java](https://www.baeldung.com/java-error-prone-library) diff --git a/static-analysis/error-prone-project/pom.xml b/static-analysis/error-prone-project/pom.xml index 59f7bb7270..2d5706d0d2 100644 --- a/static-analysis/error-prone-project/pom.xml +++ b/static-analysis/error-prone-project/pom.xml @@ -3,14 +3,14 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 + error-prone-project + com.baeldung static-analysis 1.0-SNAPSHOT - error-prone-project - @@ -19,7 +19,6 @@ ${maven-compiler-plugin.version} 17 - UTF-8 true -XDcompilePolicy=simple @@ -44,7 +43,7 @@ com.baeldung my-bugchecker-plugin - 1.0-SNAPSHOT + ${my-bugchecker-plugin.version} @@ -53,9 +52,7 @@ - 17 - 17 - UTF-8 + 1.0-SNAPSHOT diff --git a/static-analysis/my-bugchecker-plugin/pom.xml b/static-analysis/my-bugchecker-plugin/pom.xml index cbe16b0a14..eb11f07b4e 100644 --- a/static-analysis/my-bugchecker-plugin/pom.xml +++ b/static-analysis/my-bugchecker-plugin/pom.xml @@ -3,13 +3,14 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 + my-bugchecker-plugin + jar + com.baeldung static-analysis 1.0-SNAPSHOT - jar - my-bugchecker-plugin @@ -47,10 +48,4 @@ - - 17 - 17 - UTF-8 - - diff --git a/static-analysis/pmd/pom.xml b/static-analysis/pmd/pom.xml index 31914fe9f0..372c122776 100644 --- a/static-analysis/pmd/pom.xml +++ b/static-analysis/pmd/pom.xml @@ -3,18 +3,12 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 + pmd + com.baeldung static-analysis 1.0-SNAPSHOT - pmd - - - 17 - 17 - UTF-8 - - diff --git a/tablesaw/pom.xml b/tablesaw/pom.xml index f38e4cb8b4..c45931a9e2 100644 --- a/tablesaw/pom.xml +++ b/tablesaw/pom.xml @@ -25,11 +25,6 @@ org.apache.maven.plugins maven-compiler-plugin - 3.8.0 - - 17 - 17 - diff --git a/testing-modules/cucumber/pom.xml b/testing-modules/cucumber/pom.xml index 6d178b86a3..088a75a941 100644 --- a/testing-modules/cucumber/pom.xml +++ b/testing-modules/cucumber/pom.xml @@ -42,6 +42,7 @@ org.projectlombok lombok provided + ${lombok.version} io.cucumber @@ -120,8 +121,6 @@ - 14 - 14 6.10.3 5.4.0 3.141.59 diff --git a/testing-modules/gatling-java/pom.xml b/testing-modules/gatling-java/pom.xml index abe033f298..54dee1fd88 100644 --- a/testing-modules/gatling-java/pom.xml +++ b/testing-modules/gatling-java/pom.xml @@ -72,9 +72,6 @@ - 1.8 - 1.8 - UTF-8 3.9.5 4.3.0 1.0.2 diff --git a/testing-modules/gatling/pom.xml b/testing-modules/gatling/pom.xml index 82ce988bac..e5b1db2bfb 100644 --- a/testing-modules/gatling/pom.xml +++ b/testing-modules/gatling/pom.xml @@ -105,9 +105,6 @@ - 1.8 - 1.8 - UTF-8 2.12.6 3.3.1 4.3.0 diff --git a/testing-modules/jqwik/pom.xml b/testing-modules/jqwik/pom.xml index 6ef9b61a6a..85c4ba571a 100644 --- a/testing-modules/jqwik/pom.xml +++ b/testing-modules/jqwik/pom.xml @@ -17,7 +17,7 @@ net.jqwik jqwik - 1.7.4 + ${jqwik.version} test @@ -53,5 +53,9 @@ + + 1.7.4 + + diff --git a/testing-modules/junit-5-advanced/pom.xml b/testing-modules/junit-5-advanced/pom.xml index 411f189638..fc0349ff8e 100644 --- a/testing-modules/junit-5-advanced/pom.xml +++ b/testing-modules/junit-5-advanced/pom.xml @@ -18,7 +18,7 @@ com.github.stefanbirkner system-lambda - 1.2.1 + ${system-lambda.version} test @@ -79,6 +79,7 @@ + 1.2.1 1.49 3.24.2 1.10.1 diff --git a/testing-modules/junit-5-basics-2/pom.xml b/testing-modules/junit-5-basics-2/pom.xml index b430161380..f03b74f47a 100644 --- a/testing-modules/junit-5-basics-2/pom.xml +++ b/testing-modules/junit-5-basics-2/pom.xml @@ -36,18 +36,11 @@ org.apache.maven.plugins maven-compiler-plugin - - 11 - 11 - - 11 - 11 - UTF-8 1.5.0 5.10.0 5.5.0 diff --git a/testing-modules/junit-5/pom.xml b/testing-modules/junit-5/pom.xml index 8afaa085b1..cdddf90855 100644 --- a/testing-modules/junit-5/pom.xml +++ b/testing-modules/junit-5/pom.xml @@ -107,7 +107,6 @@ org.codehaus.mojo exec-maven-plugin - ${exec-maven-plugin.version} diff --git a/testing-modules/load-testing-comparison/pom.xml b/testing-modules/load-testing-comparison/pom.xml index d5a389d311..af42523ca9 100644 --- a/testing-modules/load-testing-comparison/pom.xml +++ b/testing-modules/load-testing-comparison/pom.xml @@ -66,9 +66,6 @@ - 1.8 - 1.8 - UTF-8 2.12.12 3.4.0 4.4.0 diff --git a/testing-modules/mockito-2/pom.xml b/testing-modules/mockito-2/pom.xml index 0e0f19b6b3..100c9d7015 100644 --- a/testing-modules/mockito-2/pom.xml +++ b/testing-modules/mockito-2/pom.xml @@ -21,9 +21,6 @@ - 8 - 8 - UTF-8 4.8.1 diff --git a/testing-modules/mockito-2/src/main/java/com/baeldung/lambdacalls/LambdaExample.java b/testing-modules/mockito-2/src/main/java/com/baeldung/lambdacalls/LambdaExample.java new file mode 100644 index 0000000000..bc6274eb18 --- /dev/null +++ b/testing-modules/mockito-2/src/main/java/com/baeldung/lambdacalls/LambdaExample.java @@ -0,0 +1,26 @@ +package com.baeldung.lambdacalls; + +import java.util.ArrayList; + +public class LambdaExample { + + private BrickLayer brickLayer = new BrickLayer(); + + static ArrayList bricksList = new ArrayList<>(); + + public void createWall(String bricks){ + Runnable build = () -> brickLayer.layBricks(bricks); + build.run(); + } + + public ArrayList getBricksList(){ + return bricksList; + } + + static class BrickLayer { + void layBricks(String bricks){ + bricksList.add(bricks); + } + } + +} diff --git a/testing-modules/mockito-2/src/test/java/com/baeldung/lambdacalls/LambdaCallsUnitTest.java b/testing-modules/mockito-2/src/test/java/com/baeldung/lambdacalls/LambdaCallsUnitTest.java new file mode 100644 index 0000000000..67127c641c --- /dev/null +++ b/testing-modules/mockito-2/src/test/java/com/baeldung/lambdacalls/LambdaCallsUnitTest.java @@ -0,0 +1,41 @@ +package com.baeldung.lambdacalls; + +import static com.baeldung.lambdacalls.LambdaExample.*; +import static junit.framework.TestCase.assertEquals; +import static org.mockito.Mockito.verify; + +import java.util.ArrayList; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + +@RunWith(MockitoJUnitRunner.class) +public class LambdaCallsUnitTest { + + @Mock + private/**/ BrickLayer brickLayer; + @InjectMocks + private LambdaExample lambdaExample; + + @Test + public void whenCallingALambda_thenTheInvocationCanBeConfirmedWithCorrectArguments(){ + String bricks = "red bricks"; + lambdaExample.createWall(bricks); + verify(brickLayer).layBricks(bricks); + } + + @Test + public void whenCallingALambda_thenCorrectBehaviourIsPerformed(){ + LambdaExample lambdaExample = new LambdaExample(); + String bricks = "red bricks"; + + lambdaExample.createWall(bricks); + ArrayList bricksList = lambdaExample.getBricksList(); + + assertEquals(bricks, bricksList.get(0)); + } + +} diff --git a/testing-modules/mocks-2/pom.xml b/testing-modules/mocks-2/pom.xml index 22a5198b8c..2ef1a03dff 100644 --- a/testing-modules/mocks-2/pom.xml +++ b/testing-modules/mocks-2/pom.xml @@ -33,7 +33,7 @@ 1.6.0 - 2.13.4 + 2.16.0 5.3.25 diff --git a/testing-modules/pom.xml b/testing-modules/pom.xml index fa72b1e696..b2e73570d5 100644 --- a/testing-modules/pom.xml +++ b/testing-modules/pom.xml @@ -34,8 +34,8 @@ load-testing-comparison mockito - mocks - mocks-2 + + mockserver parallel-tests-junit powermock diff --git a/testing-modules/spring-mockito/pom.xml b/testing-modules/spring-mockito/pom.xml index 6283ea2d1f..8e13f511d2 100644 --- a/testing-modules/spring-mockito/pom.xml +++ b/testing-modules/spring-mockito/pom.xml @@ -29,6 +29,7 @@ org.projectlombok lombok + ${lombok.version} diff --git a/timefold-solver/README.md b/timefold-solver/README.md new file mode 100644 index 0000000000..1abc4d4ca0 --- /dev/null +++ b/timefold-solver/README.md @@ -0,0 +1,6 @@ +## Timefold Solver + +This module contains articles about (Timefold Solver)[https://timefold.ai]. + +### Relevant articles + diff --git a/timefold-solver/pom.xml b/timefold-solver/pom.xml new file mode 100644 index 0000000000..a16afb9e54 --- /dev/null +++ b/timefold-solver/pom.xml @@ -0,0 +1,44 @@ + + + 4.0.0 + timefold-solver + timefold-solver + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + + + + + ai.timefold.solver + timefold-solver-bom + ${version.ai.timefold.solver} + pom + import + + + + + + ai.timefold.solver + timefold-solver-core + + + ai.timefold.solver + timefold-solver-test + test + + + + + 17 + 17 + 1.4.0 + + + diff --git a/timefold-solver/src/main/java/com/baeldung/timefoldsolver/Employee.java b/timefold-solver/src/main/java/com/baeldung/timefoldsolver/Employee.java new file mode 100644 index 0000000000..ef4752a8c6 --- /dev/null +++ b/timefold-solver/src/main/java/com/baeldung/timefoldsolver/Employee.java @@ -0,0 +1,28 @@ +package com.baeldung.timefoldsolver; + +import java.util.Set; + +public class Employee { + + private String name; + private Set skills; + + public Employee(String name, Set skills) { + this.name = name; + this.skills = skills; + } + + @Override + public String toString() { + return name; + } + + public String getName() { + return name; + } + + public Set getSkills() { + return skills; + } + +} diff --git a/timefold-solver/src/main/java/com/baeldung/timefoldsolver/Shift.java b/timefold-solver/src/main/java/com/baeldung/timefoldsolver/Shift.java new file mode 100644 index 0000000000..2ef2f2a1b9 --- /dev/null +++ b/timefold-solver/src/main/java/com/baeldung/timefoldsolver/Shift.java @@ -0,0 +1,54 @@ +package com.baeldung.timefoldsolver; + +import java.time.LocalDateTime; + +import ai.timefold.solver.core.api.domain.entity.PlanningEntity; +import ai.timefold.solver.core.api.domain.variable.PlanningVariable; + +@PlanningEntity +public class Shift { + + private LocalDateTime start; + private LocalDateTime end; + private String requiredSkill; + + @PlanningVariable + private Employee employee; + + // A no-arg constructor is required for @PlanningEntity annotated classes + public Shift() { + } + + public Shift(LocalDateTime start, LocalDateTime end, String requiredSkill) { + this(start, end, requiredSkill, null); + } + + public Shift(LocalDateTime start, LocalDateTime end, String requiredSkill, Employee employee) { + this.start = start; + this.end = end; + this.requiredSkill = requiredSkill; + this.employee = employee; + } + + @Override + public String toString() { + return start + " - " + end; + } + + public LocalDateTime getStart() { + return start; + } + + public LocalDateTime getEnd() { + return end; + } + + public String getRequiredSkill() { + return requiredSkill; + } + + public Employee getEmployee() { + return employee; + } + +} diff --git a/timefold-solver/src/main/java/com/baeldung/timefoldsolver/ShiftSchedule.java b/timefold-solver/src/main/java/com/baeldung/timefoldsolver/ShiftSchedule.java new file mode 100644 index 0000000000..794c31e5b7 --- /dev/null +++ b/timefold-solver/src/main/java/com/baeldung/timefoldsolver/ShiftSchedule.java @@ -0,0 +1,43 @@ +package com.baeldung.timefoldsolver; + +import java.util.List; + +import ai.timefold.solver.core.api.domain.solution.PlanningEntityCollectionProperty; +import ai.timefold.solver.core.api.domain.solution.PlanningScore; +import ai.timefold.solver.core.api.domain.solution.PlanningSolution; +import ai.timefold.solver.core.api.domain.valuerange.ValueRangeProvider; +import ai.timefold.solver.core.api.score.buildin.hardsoft.HardSoftScore; + +@PlanningSolution +public class ShiftSchedule { + + @ValueRangeProvider + private List employees; + @PlanningEntityCollectionProperty + private List shifts; + + @PlanningScore + private HardSoftScore score; + + // A no-arg constructor is required for @PlanningSolution annotated classes + public ShiftSchedule() { + } + + public ShiftSchedule(List employees, List shifts) { + this.employees = employees; + this.shifts = shifts; + } + + public List getEmployees() { + return employees; + } + + public List getShifts() { + return shifts; + } + + public HardSoftScore getScore() { + return score; + } + +} diff --git a/timefold-solver/src/main/java/com/baeldung/timefoldsolver/ShiftScheduleConstraintProvider.java b/timefold-solver/src/main/java/com/baeldung/timefoldsolver/ShiftScheduleConstraintProvider.java new file mode 100644 index 0000000000..bd308dacbf --- /dev/null +++ b/timefold-solver/src/main/java/com/baeldung/timefoldsolver/ShiftScheduleConstraintProvider.java @@ -0,0 +1,35 @@ +package com.baeldung.timefoldsolver; + +import static ai.timefold.solver.core.api.score.stream.Joiners.equal; + +import ai.timefold.solver.core.api.score.buildin.hardsoft.HardSoftScore; +import ai.timefold.solver.core.api.score.stream.Constraint; +import ai.timefold.solver.core.api.score.stream.ConstraintFactory; +import ai.timefold.solver.core.api.score.stream.ConstraintProvider; + +public class ShiftScheduleConstraintProvider implements ConstraintProvider { + + @Override + public Constraint[] defineConstraints(ConstraintFactory constraintFactory) { + return new Constraint[] { atMostOneShiftPerDay(constraintFactory), requiredSkill(constraintFactory) }; + } + + public Constraint atMostOneShiftPerDay(ConstraintFactory constraintFactory) { + return constraintFactory.forEach(Shift.class) + .join(Shift.class, equal(shift -> shift.getStart() + .toLocalDate()), equal(Shift::getEmployee)) + .filter((shift1, shift2) -> shift1 != shift2) + .penalize(HardSoftScore.ONE_HARD) + .asConstraint("At most one shift per day"); + } + + public Constraint requiredSkill(ConstraintFactory constraintFactory) { + return constraintFactory.forEach(Shift.class) + .filter(shift -> !shift.getEmployee() + .getSkills() + .contains(shift.getRequiredSkill())) + .penalize(HardSoftScore.ONE_HARD) + .asConstraint("Required skill"); + } + +} diff --git a/timefold-solver/src/test/java/com/baeldung/timefoldsolver/ShiftScheduleConstraintProviderUnitTest.java b/timefold-solver/src/test/java/com/baeldung/timefoldsolver/ShiftScheduleConstraintProviderUnitTest.java new file mode 100644 index 0000000000..c8ec5b53c4 --- /dev/null +++ b/timefold-solver/src/test/java/com/baeldung/timefoldsolver/ShiftScheduleConstraintProviderUnitTest.java @@ -0,0 +1,52 @@ +package com.baeldung.timefoldsolver; + +import java.time.LocalDate; +import java.util.Set; + +import org.junit.jupiter.api.Test; + +import ai.timefold.solver.test.api.score.stream.ConstraintVerifier; + +class ShiftScheduleConstraintProviderUnitTest { + + private static final LocalDate MONDAY = LocalDate.of(2030, 4, 1); + private static final LocalDate TUESDAY = LocalDate.of(2030, 4, 2); + + ConstraintVerifier constraintVerifier = ConstraintVerifier.build(new ShiftScheduleConstraintProvider(), + ShiftSchedule.class, Shift.class); + + @Test + void givenTwoShiftsOnOneDay_whenApplyingAtMostOneShiftPerDayConstraint_thenPenalize() { + Employee ann = new Employee("Ann", null); + constraintVerifier.verifyThat(ShiftScheduleConstraintProvider::atMostOneShiftPerDay) + .given(ann, new Shift(MONDAY.atTime(6, 0), MONDAY.atTime(14, 0), null, ann), new Shift(MONDAY.atTime(14, 0), MONDAY.atTime(22, 0), null, ann)) + // Penalizes by 2 because both {shiftA, shiftB} and {shiftB, shiftA} match. + // To avoid that, use forEachUniquePair(Shift) instead of forEach(Shift).join(Shift) in ShiftScheduleConstraintProvider.atMostOneShiftPerDay(). + .penalizesBy(2); + } + + @Test + void givenTwoShiftsOnDifferentDays_whenApplyingAtMostOneShiftPerDayConstraint_thenDoNotPenalize() { + Employee ann = new Employee("Ann", null); + constraintVerifier.verifyThat(ShiftScheduleConstraintProvider::atMostOneShiftPerDay) + .given(ann, new Shift(MONDAY.atTime(6, 0), MONDAY.atTime(14, 0), null, ann), new Shift(TUESDAY.atTime(14, 0), TUESDAY.atTime(22, 0), null, ann)) + .penalizesBy(0); + } + + @Test + void givenEmployeeLacksRequiredSkill_whenApplyingRequiredSkillConstraint_thenPenalize() { + Employee ann = new Employee("Ann", Set.of("Waiter")); + constraintVerifier.verifyThat(ShiftScheduleConstraintProvider::requiredSkill) + .given(ann, new Shift(MONDAY.atTime(6, 0), MONDAY.atTime(14, 0), "Cook", ann)) + .penalizesBy(1); + } + + @Test + void givenEmployeeHasRequiredSkill_whenApplyingRequiredSkillConstraint_thenDoNotPenalize() { + Employee ann = new Employee("Ann", Set.of("Waiter")); + constraintVerifier.verifyThat(ShiftScheduleConstraintProvider::requiredSkill) + .given(ann, new Shift(MONDAY.atTime(6, 0), MONDAY.atTime(14, 0), "Waiter", ann)) + .penalizesBy(0); + } + +} diff --git a/timefold-solver/src/test/java/com/baeldung/timefoldsolver/ShiftScheduleSolverUnitTest.java b/timefold-solver/src/test/java/com/baeldung/timefoldsolver/ShiftScheduleSolverUnitTest.java new file mode 100644 index 0000000000..873ce1a853 --- /dev/null +++ b/timefold-solver/src/test/java/com/baeldung/timefoldsolver/ShiftScheduleSolverUnitTest.java @@ -0,0 +1,65 @@ +package com.baeldung.timefoldsolver; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +import java.time.Duration; +import java.time.LocalDate; +import java.util.List; +import java.util.Set; + +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import ai.timefold.solver.core.api.score.buildin.hardsoft.HardSoftScore; +import ai.timefold.solver.core.api.solver.Solver; +import ai.timefold.solver.core.api.solver.SolverFactory; +import ai.timefold.solver.core.config.solver.SolverConfig; +import ai.timefold.solver.core.config.solver.termination.TerminationConfig; + +public class ShiftScheduleSolverUnitTest { + + private static final Logger logger = LoggerFactory.getLogger(ShiftScheduleSolverUnitTest.class); + + @Test + public void given3Employees5Shifts_whenSolve_thenScoreIsOptimalAndAllShiftsAssigned() { + SolverFactory solverFactory = SolverFactory.create(new SolverConfig().withSolutionClass(ShiftSchedule.class) + .withEntityClasses(Shift.class) + .withConstraintProviderClass(ShiftScheduleConstraintProvider.class) + // For this dataset, we know the optimal score in advance (which is normally not the case). + // So we can use .withBestScoreLimit() instead of .withTerminationSpentLimit(). + .withTerminationConfig(new TerminationConfig().withBestScoreLimit("0hard/0soft"))); + Solver solver = solverFactory.buildSolver(); + + ShiftSchedule problem = loadProblem(); + ShiftSchedule solution = solver.solve(problem); + assertThat(solution.getScore()).isEqualTo(HardSoftScore.ZERO); + assertThat(solution.getShifts().size()).isNotZero(); + for (Shift shift : solution.getShifts()) { + assertThat(shift.getEmployee()).isNotNull(); + } + printSolution(solution); + } + + private ShiftSchedule loadProblem() { + LocalDate monday = LocalDate.of(2030, 4, 1); + LocalDate tuesday = LocalDate.of(2030, 4, 2); + return new ShiftSchedule( + List.of(new Employee("Ann", Set.of("Bartender")), new Employee("Beth", Set.of("Waiter", "Bartender")), new Employee("Carl", Set.of("Waiter"))), + List.of(new Shift(monday.atTime(6, 0), monday.atTime(14, 0), "Waiter"), new Shift(monday.atTime(9, 0), monday.atTime(17, 0), "Bartender"), + new Shift(monday.atTime(14, 0), monday.atTime(22, 0), "Bartender"), new Shift(tuesday.atTime(6, 0), tuesday.atTime(14, 0), "Waiter"), + new Shift(tuesday.atTime(14, 0), tuesday.atTime(22, 0), "Bartender"))); + } + + private void printSolution(ShiftSchedule solution) { + logger.info("Shift assignments"); + for (Shift shift : solution.getShifts()) { + logger.info(" " + shift.getStart() + .toLocalDate() + " " + shift.getStart() + .toLocalTime() + " - " + shift.getEnd() + .toLocalTime() + ": " + shift.getEmployee() + .getName()); + } + } + +} diff --git a/vavr-modules/java-vavr-stream/pom.xml b/vavr-modules/java-vavr-stream/pom.xml index cda9d1f734..e369fa7cf3 100644 --- a/vavr-modules/java-vavr-stream/pom.xml +++ b/vavr-modules/java-vavr-stream/pom.xml @@ -19,12 +19,8 @@ io.vavr vavr - ${io.vavr.version} + ${vavr.version} - - 0.9.2 - - \ No newline at end of file diff --git a/vavr-modules/pom.xml b/vavr-modules/pom.xml index 416c689511..e9a3b121aa 100644 --- a/vavr-modules/pom.xml +++ b/vavr-modules/pom.xml @@ -30,4 +30,8 @@ + + 0.9.2 + + \ No newline at end of file diff --git a/vavr-modules/vavr-2/pom.xml b/vavr-modules/vavr-2/pom.xml index 0063daa518..54f3cb4d71 100644 --- a/vavr-modules/vavr-2/pom.xml +++ b/vavr-modules/vavr-2/pom.xml @@ -21,8 +21,4 @@ - - 0.9.1 - - \ No newline at end of file diff --git a/vertx-modules/pom.xml b/vertx-modules/pom.xml index 7d9614ad61..00f0bc46f5 100644 --- a/vertx-modules/pom.xml +++ b/vertx-modules/pom.xml @@ -30,4 +30,8 @@ + + 3.9.15 + + \ No newline at end of file diff --git a/vertx-modules/vertx-and-rxjava/pom.xml b/vertx-modules/vertx-and-rxjava/pom.xml index 16eaf8ebaa..b68117ddeb 100644 --- a/vertx-modules/vertx-and-rxjava/pom.xml +++ b/vertx-modules/vertx-and-rxjava/pom.xml @@ -40,8 +40,4 @@ - - 3.9.15 - - \ No newline at end of file diff --git a/vertx-modules/vertx/pom.xml b/vertx-modules/vertx/pom.xml index 75df2fae69..d34deca9d8 100644 --- a/vertx-modules/vertx/pom.xml +++ b/vertx-modules/vertx/pom.xml @@ -65,7 +65,6 @@ - 3.9.15 3.2.1 diff --git a/web-modules/apache-tapestry/pom.xml b/web-modules/apache-tapestry/pom.xml index 562cdff00c..bfc7c22415 100644 --- a/web-modules/apache-tapestry/pom.xml +++ b/web-modules/apache-tapestry/pom.xml @@ -78,17 +78,13 @@ org.apache.maven.plugins maven-compiler-plugin - ${compiler.plugin.version} - ${source.version} - ${target.version} true org.apache.maven.plugins maven-surefire-plugin - ${compiler.surefire.version} Qa @@ -118,7 +114,6 @@ org.apache.maven.plugins maven-war-plugin - 3.3.1 @@ -140,9 +135,6 @@ 6.1.16 3.0.0-M5 - 3.8.1 - 11 - 11 5.8.2 2.5 6.8.21 diff --git a/web-modules/blade/pom.xml b/web-modules/blade/pom.xml index 2748c05663..fb0ca13dbe 100644 --- a/web-modules/blade/pom.xml +++ b/web-modules/blade/pom.xml @@ -62,7 +62,6 @@ org.apache.maven.plugins maven-failsafe-plugin - ${maven-failsafe-plugin.version} true diff --git a/web-modules/jakarta-ee/pom.xml b/web-modules/jakarta-ee/pom.xml index 066bc14766..d90e848323 100644 --- a/web-modules/jakarta-ee/pom.xml +++ b/web-modules/jakarta-ee/pom.xml @@ -2,7 +2,6 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.baeldung jakarta-ee 1.0-SNAPSHOT jakarta-ee @@ -51,7 +50,7 @@ org.glassfish.maven.plugin maven-glassfish-plugin - 2.1 + ${maven-glassfish-plugin.version} ${local.glassfish.home} admin @@ -76,11 +75,6 @@ org.apache.maven.plugins maven-compiler-plugin - 3.8.0 - - 11 - 11 - org.apache.maven.plugins @@ -104,6 +98,7 @@ ${local.glassfish.home}\\domains\\${local.glassfish.domain}\\config\\domain-passwords + 2.1 \ No newline at end of file diff --git a/xml/README.md b/xml/README.md index 16942c6836..596ddc14aa 100644 --- a/xml/README.md +++ b/xml/README.md @@ -13,3 +13,4 @@ This module contains articles about eXtensible Markup Language (XML) - [Parsing an XML File Using StAX](https://www.baeldung.com/java-stax) - [Parsing an XML File Using SAX Parser](https://www.baeldung.com/java-sax-parser) - [Remove HTML Tags Using Java](https://www.baeldung.com/java-remove-html-tags) +- [Convert an XML File to CSV File](https://www.baeldung.com/java-convert-xml-csv) diff --git a/xml/src/main/java/com/baeldung/xml/DefaultParser.java b/xml/src/main/java/com/baeldung/xml/DefaultParser.java index 83280aa0f2..63e4a453c3 100644 --- a/xml/src/main/java/com/baeldung/xml/DefaultParser.java +++ b/xml/src/main/java/com/baeldung/xml/DefaultParser.java @@ -163,10 +163,10 @@ public class DefaultParser { private void clean(Node node) { - NodeList childs = node.getChildNodes(); + NodeList childNodes = node.getChildNodes(); - for (int n = childs.getLength() - 1; n >= 0; n--) { - Node child = childs.item(n); + for (int n = childNodes.getLength() - 1; n >= 0; n--) { + Node child = childNodes.item(n); short nodeType = child.getNodeType(); if (nodeType == Node.ELEMENT_NODE)