From 7a9ec696af348adc1c4c82e9de0ed8568de3ce95 Mon Sep 17 00:00:00 2001 From: Tyrell Flurry Date: Wed, 1 Apr 2020 18:08:39 -0400 Subject: [PATCH 01/19] BAEL-3929: added unused maven dependencies example. --- maven-all/maven-unused-dependencies/pom.xml | 30 +++++++++++++++++++ .../src/main/java/com/baeldung/Main.java | 20 +++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 maven-all/maven-unused-dependencies/pom.xml create mode 100644 maven-all/maven-unused-dependencies/src/main/java/com/baeldung/Main.java diff --git a/maven-all/maven-unused-dependencies/pom.xml b/maven-all/maven-unused-dependencies/pom.xml new file mode 100644 index 0000000000..312f38ed93 --- /dev/null +++ b/maven-all/maven-unused-dependencies/pom.xml @@ -0,0 +1,30 @@ + + 4.0.0 + com.baeldung + maven-unused-dependencies + 0.0.1-SNAPSHOT + + + + commons-collections + commons-collections + 3.2.2 + + + org.slf4j + slf4j-api + 1.7.25 + + + + + + + maven-dependency-plugin + 3.1.1 + + + + \ No newline at end of file diff --git a/maven-all/maven-unused-dependencies/src/main/java/com/baeldung/Main.java b/maven-all/maven-unused-dependencies/src/main/java/com/baeldung/Main.java new file mode 100644 index 0000000000..8143c7d19f --- /dev/null +++ b/maven-all/maven-unused-dependencies/src/main/java/com/baeldung/Main.java @@ -0,0 +1,20 @@ +package com.baeldung; + +import java.util.HashMap; +import java.util.Map; + +import org.slf4j.LoggerFactory; + +public class Main { + + public static void main(String[] args) { + Map teamMap = new HashMap<>(); + teamMap.put("Dallas", "Cowboys"); + teamMap.put("Green Bay", "Packers"); + teamMap.put("Washington", "Redskins"); + + LoggerFactory.getLogger(Main.class) + .info("Team Map: {}", teamMap); + + } +} From 2231a044ea3f24eafad7040ea9854f1cbbf2c87d Mon Sep 17 00:00:00 2001 From: Tyrell Flurry Date: Thu, 9 Apr 2020 16:52:54 -0400 Subject: [PATCH 02/19] BAEL-3929: modified java. --- .../src/main/java/com/baeldung/Main.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/maven-all/maven-unused-dependencies/src/main/java/com/baeldung/Main.java b/maven-all/maven-unused-dependencies/src/main/java/com/baeldung/Main.java index 8143c7d19f..abf6c7a03d 100644 --- a/maven-all/maven-unused-dependencies/src/main/java/com/baeldung/Main.java +++ b/maven-all/maven-unused-dependencies/src/main/java/com/baeldung/Main.java @@ -6,15 +6,13 @@ import java.util.Map; import org.slf4j.LoggerFactory; public class Main { - public static void main(String[] args) { - Map teamMap = new HashMap<>(); - teamMap.put("Dallas", "Cowboys"); - teamMap.put("Green Bay", "Packers"); - teamMap.put("Washington", "Redskins"); + Map map = new HashMap<>(); + map.put("Dallas", "Texas"); + map.put("Green Bay", "Wisconsin"); + map.put("Seattle", "Washington"); LoggerFactory.getLogger(Main.class) - .info("Team Map: {}", teamMap); - + .info("Map: {}", map); } } From dcb65ba8bc29dee95c8e338cd710320ca26fdeac Mon Sep 17 00:00:00 2001 From: Tyrell Flurry Date: Sat, 11 Apr 2020 08:31:06 -0400 Subject: [PATCH 03/19] BAEL-3929: addressed code review comments. --- maven-all/maven-unused-dependencies/pom.xml | 23 ++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/maven-all/maven-unused-dependencies/pom.xml b/maven-all/maven-unused-dependencies/pom.xml index 312f38ed93..19a06fc605 100644 --- a/maven-all/maven-unused-dependencies/pom.xml +++ b/maven-all/maven-unused-dependencies/pom.xml @@ -10,21 +10,38 @@ commons-collections commons-collections - 3.2.2 + ${commons-collections.version} org.slf4j slf4j-api - 1.7.25 + ${slf4j-api.version} + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + 1.8 + 1.8 + + maven-dependency-plugin - 3.1.1 + ${maven-dependency-plugin.version} + + + 3.2.2 + 1.7.25 + 3.1.1 + 3.1 + + \ No newline at end of file From b14ab5ed7ac5ccaf3dd696f4eec9f97c499a2784 Mon Sep 17 00:00:00 2001 From: Tyrell Flurry Date: Tue, 14 Apr 2020 17:59:28 -0400 Subject: [PATCH 04/19] BAEL-3929: added another example per code review. --- .../src/main/java/com/baeldung/Main.java | 2 ++ .../main/java/com/baeldung/ReflectionMain.java | 15 +++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 maven-all/maven-unused-dependencies/src/main/java/com/baeldung/ReflectionMain.java diff --git a/maven-all/maven-unused-dependencies/src/main/java/com/baeldung/Main.java b/maven-all/maven-unused-dependencies/src/main/java/com/baeldung/Main.java index abf6c7a03d..2626bb30a3 100644 --- a/maven-all/maven-unused-dependencies/src/main/java/com/baeldung/Main.java +++ b/maven-all/maven-unused-dependencies/src/main/java/com/baeldung/Main.java @@ -6,6 +6,7 @@ import java.util.Map; import org.slf4j.LoggerFactory; public class Main { + public static void main(String[] args) { Map map = new HashMap<>(); map.put("Dallas", "Texas"); @@ -15,4 +16,5 @@ public class Main { LoggerFactory.getLogger(Main.class) .info("Map: {}", map); } + } diff --git a/maven-all/maven-unused-dependencies/src/main/java/com/baeldung/ReflectionMain.java b/maven-all/maven-unused-dependencies/src/main/java/com/baeldung/ReflectionMain.java new file mode 100644 index 0000000000..48e42f7c66 --- /dev/null +++ b/maven-all/maven-unused-dependencies/src/main/java/com/baeldung/ReflectionMain.java @@ -0,0 +1,15 @@ +package com.baeldung; + +public class ReflectionMain { + + public static void main(String[] args) { + ClassLoader classLoader = Main.class.getClassLoader(); + try { + System.out.println(classLoader.loadClass("org.apache.commons.collections.CollectionUtils") + .getSimpleName()); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + } + +} \ No newline at end of file From da174392ed63097a64d6a095eb71f442b563a356 Mon Sep 17 00:00:00 2001 From: mikr Date: Sun, 26 Apr 2020 22:34:22 +0200 Subject: [PATCH 05/19] JAVA-1470 Move 10 articles to libraries-4 module --- libraries-4/README.md | 43 +++ libraries-4/pom.xml | 111 +++++++ .../distinct/DistinctWithJavaFunction.java | 0 .../java/com/baeldung/distinct/Person.java | 0 .../ConvertContainerToAnother.java | 0 .../baeldung/eclipsecollections/Student.java | 0 .../com/baeldung/jdeffered/FilterDemo.java | 0 .../java/com/baeldung/jdeffered/PipeDemo.java | 0 .../com/baeldung/jdeffered/PromiseDemo.java | 0 .../baeldung/jdeffered/ThreadSafeDemo.java | 0 .../manager/DeferredManagerDemo.java | 0 .../DeferredManagerWithExecutorDemo.java | 0 .../manager/SimpleDeferredManagerDemo.java | 0 .../com/baeldung/mbassador/AckMessage.java | 0 .../java/com/baeldung/mbassador/Message.java | 0 .../com/baeldung/mbassador/RejectMessage.java | 0 .../noexception/CustomExceptionHandler.java | 0 .../java/com/baeldung/pairs/CustomPair.java | 0 .../com/baeldung/rome/RSSRomeExample.java | 0 .../com/baeldung/yarg/DocumentController.java | 0 ...istinctWithEclipseCollectionsUnitTest.java | 0 .../DistinctWithJavaFunctionUnitTest.java | 0 .../DistinctWithStreamexUnitTest.java | 0 .../distinct/DistinctWithVavrUnitTest.java | 0 .../distinct/PersonDataGenerator.java | 0 .../AllSatisfyPatternUnitTest.java | 0 .../AnySatisfyPatternUnitTest.java | 0 .../CollectPatternUnitTest.java | 0 .../ConvertContainerToAnotherUnitTest.java | 0 .../DetectPatternUnitTest.java | 0 .../FlatCollectUnitTest.java | 0 .../ForEachPatternUnitTest.java | 3 +- .../InjectIntoPatternUnitTest.java | 0 .../LazyIterationUnitTest.java | 0 .../PartitionPatternUnitTest.java | 0 .../RejectPatternUnitTest.java | 0 .../SelectPatternUnitTest.java | 0 .../eclipsecollections/ZipUnitTest.java | 0 .../ZipWithIndexUnitTest.java | 0 .../io/JavaDirectoryDeleteUnitTest.java | 276 +++++++++--------- .../baeldung/jdeffered/JDeferredUnitTest.java | 0 .../MBassadorAsyncDispatchUnitTest.java | 0 .../MBassadorAsyncInvocationUnitTest.java | 0 .../mbassador/MBassadorBasicUnitTest.java | 0 .../MBassadorConfigurationUnitTest.java | 0 .../mbassador/MBassadorFilterUnitTest.java | 0 .../mbassador/MBassadorHierarchyUnitTest.java | 0 .../noexception/NoExceptionUnitTest.java | 0 .../pairs/ApacheCommonsPairUnitTest.java | 0 .../baeldung/pairs/CoreJavaPairUnitTest.java | 0 .../pairs/CoreJavaSimpleEntryUnitTest.java | 0 .../com/baeldung/pairs/VavrPairsUnitTest.java | 0 .../pcollections/PCollectionsUnitTest.java | 0 libraries-5/pom.xml | 15 + libraries-6/pom.xml | 15 + libraries/README.md | 9 +- libraries/pom.xml | 134 ++++----- pom.xml | 4 + 58 files changed, 403 insertions(+), 207 deletions(-) create mode 100644 libraries-4/README.md create mode 100644 libraries-4/pom.xml rename {libraries => libraries-4}/src/main/java/com/baeldung/distinct/DistinctWithJavaFunction.java (100%) rename {libraries => libraries-4}/src/main/java/com/baeldung/distinct/Person.java (100%) rename {libraries => libraries-4}/src/main/java/com/baeldung/eclipsecollections/ConvertContainerToAnother.java (100%) rename {libraries => libraries-4}/src/main/java/com/baeldung/eclipsecollections/Student.java (100%) rename {libraries => libraries-4}/src/main/java/com/baeldung/jdeffered/FilterDemo.java (100%) rename {libraries => libraries-4}/src/main/java/com/baeldung/jdeffered/PipeDemo.java (100%) rename {libraries => libraries-4}/src/main/java/com/baeldung/jdeffered/PromiseDemo.java (100%) rename {libraries => libraries-4}/src/main/java/com/baeldung/jdeffered/ThreadSafeDemo.java (100%) rename {libraries => libraries-4}/src/main/java/com/baeldung/jdeffered/manager/DeferredManagerDemo.java (100%) rename {libraries => libraries-4}/src/main/java/com/baeldung/jdeffered/manager/DeferredManagerWithExecutorDemo.java (100%) rename {libraries => libraries-4}/src/main/java/com/baeldung/jdeffered/manager/SimpleDeferredManagerDemo.java (100%) rename {libraries => libraries-4}/src/main/java/com/baeldung/mbassador/AckMessage.java (100%) rename {libraries => libraries-4}/src/main/java/com/baeldung/mbassador/Message.java (100%) rename {libraries => libraries-4}/src/main/java/com/baeldung/mbassador/RejectMessage.java (100%) rename {libraries => libraries-4}/src/main/java/com/baeldung/noexception/CustomExceptionHandler.java (100%) rename {libraries => libraries-4}/src/main/java/com/baeldung/pairs/CustomPair.java (100%) rename {libraries => libraries-4}/src/main/java/com/baeldung/rome/RSSRomeExample.java (100%) rename {libraries => libraries-4}/src/main/java/com/baeldung/yarg/DocumentController.java (100%) rename {libraries => libraries-4}/src/test/java/com/baeldung/distinct/DistinctWithEclipseCollectionsUnitTest.java (100%) rename {libraries => libraries-4}/src/test/java/com/baeldung/distinct/DistinctWithJavaFunctionUnitTest.java (100%) rename {libraries => libraries-4}/src/test/java/com/baeldung/distinct/DistinctWithStreamexUnitTest.java (100%) rename {libraries => libraries-4}/src/test/java/com/baeldung/distinct/DistinctWithVavrUnitTest.java (100%) rename {libraries => libraries-4}/src/test/java/com/baeldung/distinct/PersonDataGenerator.java (100%) rename {libraries => libraries-4}/src/test/java/com/baeldung/eclipsecollections/AllSatisfyPatternUnitTest.java (100%) rename {libraries => libraries-4}/src/test/java/com/baeldung/eclipsecollections/AnySatisfyPatternUnitTest.java (100%) rename {libraries => libraries-4}/src/test/java/com/baeldung/eclipsecollections/CollectPatternUnitTest.java (100%) rename {libraries => libraries-4}/src/test/java/com/baeldung/eclipsecollections/ConvertContainerToAnotherUnitTest.java (100%) rename {libraries => libraries-4}/src/test/java/com/baeldung/eclipsecollections/DetectPatternUnitTest.java (100%) rename {libraries => libraries-4}/src/test/java/com/baeldung/eclipsecollections/FlatCollectUnitTest.java (100%) rename {libraries => libraries-4}/src/test/java/com/baeldung/eclipsecollections/ForEachPatternUnitTest.java (90%) rename {libraries => libraries-4}/src/test/java/com/baeldung/eclipsecollections/InjectIntoPatternUnitTest.java (100%) rename {libraries => libraries-4}/src/test/java/com/baeldung/eclipsecollections/LazyIterationUnitTest.java (100%) rename {libraries => libraries-4}/src/test/java/com/baeldung/eclipsecollections/PartitionPatternUnitTest.java (100%) rename {libraries => libraries-4}/src/test/java/com/baeldung/eclipsecollections/RejectPatternUnitTest.java (100%) rename {libraries => libraries-4}/src/test/java/com/baeldung/eclipsecollections/SelectPatternUnitTest.java (100%) rename {libraries => libraries-4}/src/test/java/com/baeldung/eclipsecollections/ZipUnitTest.java (100%) rename {libraries => libraries-4}/src/test/java/com/baeldung/eclipsecollections/ZipWithIndexUnitTest.java (100%) rename {libraries/src/test/java/com/baeldung/java => libraries-4/src/test/java/com/baeldung}/io/JavaDirectoryDeleteUnitTest.java (96%) rename {libraries => libraries-4}/src/test/java/com/baeldung/jdeffered/JDeferredUnitTest.java (100%) rename {libraries => libraries-4}/src/test/java/com/baeldung/mbassador/MBassadorAsyncDispatchUnitTest.java (100%) rename {libraries => libraries-4}/src/test/java/com/baeldung/mbassador/MBassadorAsyncInvocationUnitTest.java (100%) rename {libraries => libraries-4}/src/test/java/com/baeldung/mbassador/MBassadorBasicUnitTest.java (100%) rename {libraries => libraries-4}/src/test/java/com/baeldung/mbassador/MBassadorConfigurationUnitTest.java (100%) rename {libraries => libraries-4}/src/test/java/com/baeldung/mbassador/MBassadorFilterUnitTest.java (100%) rename {libraries => libraries-4}/src/test/java/com/baeldung/mbassador/MBassadorHierarchyUnitTest.java (100%) rename {libraries => libraries-4}/src/test/java/com/baeldung/noexception/NoExceptionUnitTest.java (100%) rename {libraries => libraries-4}/src/test/java/com/baeldung/pairs/ApacheCommonsPairUnitTest.java (100%) rename {libraries => libraries-4}/src/test/java/com/baeldung/pairs/CoreJavaPairUnitTest.java (100%) rename {libraries => libraries-4}/src/test/java/com/baeldung/pairs/CoreJavaSimpleEntryUnitTest.java (100%) rename {libraries => libraries-4}/src/test/java/com/baeldung/pairs/VavrPairsUnitTest.java (100%) rename {libraries => libraries-4}/src/test/java/com/baeldung/pcollections/PCollectionsUnitTest.java (100%) create mode 100644 libraries-5/pom.xml create mode 100644 libraries-6/pom.xml diff --git a/libraries-4/README.md b/libraries-4/README.md new file mode 100644 index 0000000000..f650c073a7 --- /dev/null +++ b/libraries-4/README.md @@ -0,0 +1,43 @@ +## Libraries + +This module contains articles about various Java libraries. +These are small libraries that are relatively easy to use and do not require any separate module of their own. + +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 + +- [Introduction to Javatuples](https://www.baeldung.com/java-tuples) +- [Introduction to Javassist](https://www.baeldung.com/javassist) +- [Introduction to Apache Flink with Java](https://www.baeldung.com/apache-flink) +- [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) +- [Locality-Sensitive Hashing in Java Using Java-LSH](https://www.baeldung.com/locality-sensitive-hashing) +- [Introduction to Neuroph](https://www.baeldung.com/neuroph) + +#5 +- [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) +- [Publish and Receive Messages with Nats Java Client](https://www.baeldung.com/nats-java-client) +- [Java Concurrency Utility with JCTools](https://www.baeldung.com/java-concurrency-jc-tools) + +#6 +- [Introduction to JavaPoet](https://www.baeldung.com/java-poet) +- [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) +- [A Guide to the Reflections Library](https://www.baeldung.com/reflections-library) + +- [Exactly Once Processing in Kafka](https://www.baeldung.com/kafka-exactly-once) +- More articles [[next -->]](/libraries-2) diff --git a/libraries-4/pom.xml b/libraries-4/pom.xml new file mode 100644 index 0000000000..1b2db27861 --- /dev/null +++ b/libraries-4/pom.xml @@ -0,0 +1,111 @@ + + + + parent-modules + com.baeldung + 1.0.0-SNAPSHOT + + 4.0.0 + + libraries-4 + + + + org.jdeferred + jdeferred-core + ${jdeferred.version} + + + org.eclipse.collections + eclipse-collections + ${eclipse-collections.version} + + + com.haulmont.yarg + yarg + ${yarg.version} + + + net.engio + mbassador + ${mbassador.version} + + + com.machinezoo.noexception + noexception + ${noexception.version} + + + rome + rome + ${rome.version} + + + org.springframework + spring-web + ${spring.version} + + + org.datanucleus + javax.jdo + ${javax.jdo.version} + + + javax.servlet + servlet-api + ${javax.servlet.version} + + + io.vavr + vavr + ${vavr.version} + + + org.assertj + assertj-core + ${assertj.version} + + + org.pcollections + pcollections + ${pcollections.version} + + + org.awaitility + awaitility + ${awaitility.version} + test + + + one.util + streamex + ${streamex.version} + + + javax.el + javax.el-api + ${javax.el.version} + + + + + 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 + 3.6.2 + 2.1.2 + 3.0.0 + 0.6.5 + 3.0.0 + + + \ No newline at end of file diff --git a/libraries/src/main/java/com/baeldung/distinct/DistinctWithJavaFunction.java b/libraries-4/src/main/java/com/baeldung/distinct/DistinctWithJavaFunction.java similarity index 100% rename from libraries/src/main/java/com/baeldung/distinct/DistinctWithJavaFunction.java rename to libraries-4/src/main/java/com/baeldung/distinct/DistinctWithJavaFunction.java diff --git a/libraries/src/main/java/com/baeldung/distinct/Person.java b/libraries-4/src/main/java/com/baeldung/distinct/Person.java similarity index 100% rename from libraries/src/main/java/com/baeldung/distinct/Person.java rename to libraries-4/src/main/java/com/baeldung/distinct/Person.java diff --git a/libraries/src/main/java/com/baeldung/eclipsecollections/ConvertContainerToAnother.java b/libraries-4/src/main/java/com/baeldung/eclipsecollections/ConvertContainerToAnother.java similarity index 100% rename from libraries/src/main/java/com/baeldung/eclipsecollections/ConvertContainerToAnother.java rename to libraries-4/src/main/java/com/baeldung/eclipsecollections/ConvertContainerToAnother.java diff --git a/libraries/src/main/java/com/baeldung/eclipsecollections/Student.java b/libraries-4/src/main/java/com/baeldung/eclipsecollections/Student.java similarity index 100% rename from libraries/src/main/java/com/baeldung/eclipsecollections/Student.java rename to libraries-4/src/main/java/com/baeldung/eclipsecollections/Student.java diff --git a/libraries/src/main/java/com/baeldung/jdeffered/FilterDemo.java b/libraries-4/src/main/java/com/baeldung/jdeffered/FilterDemo.java similarity index 100% rename from libraries/src/main/java/com/baeldung/jdeffered/FilterDemo.java rename to libraries-4/src/main/java/com/baeldung/jdeffered/FilterDemo.java diff --git a/libraries/src/main/java/com/baeldung/jdeffered/PipeDemo.java b/libraries-4/src/main/java/com/baeldung/jdeffered/PipeDemo.java similarity index 100% rename from libraries/src/main/java/com/baeldung/jdeffered/PipeDemo.java rename to libraries-4/src/main/java/com/baeldung/jdeffered/PipeDemo.java diff --git a/libraries/src/main/java/com/baeldung/jdeffered/PromiseDemo.java b/libraries-4/src/main/java/com/baeldung/jdeffered/PromiseDemo.java similarity index 100% rename from libraries/src/main/java/com/baeldung/jdeffered/PromiseDemo.java rename to libraries-4/src/main/java/com/baeldung/jdeffered/PromiseDemo.java diff --git a/libraries/src/main/java/com/baeldung/jdeffered/ThreadSafeDemo.java b/libraries-4/src/main/java/com/baeldung/jdeffered/ThreadSafeDemo.java similarity index 100% rename from libraries/src/main/java/com/baeldung/jdeffered/ThreadSafeDemo.java rename to libraries-4/src/main/java/com/baeldung/jdeffered/ThreadSafeDemo.java diff --git a/libraries/src/main/java/com/baeldung/jdeffered/manager/DeferredManagerDemo.java b/libraries-4/src/main/java/com/baeldung/jdeffered/manager/DeferredManagerDemo.java similarity index 100% rename from libraries/src/main/java/com/baeldung/jdeffered/manager/DeferredManagerDemo.java rename to libraries-4/src/main/java/com/baeldung/jdeffered/manager/DeferredManagerDemo.java diff --git a/libraries/src/main/java/com/baeldung/jdeffered/manager/DeferredManagerWithExecutorDemo.java b/libraries-4/src/main/java/com/baeldung/jdeffered/manager/DeferredManagerWithExecutorDemo.java similarity index 100% rename from libraries/src/main/java/com/baeldung/jdeffered/manager/DeferredManagerWithExecutorDemo.java rename to libraries-4/src/main/java/com/baeldung/jdeffered/manager/DeferredManagerWithExecutorDemo.java diff --git a/libraries/src/main/java/com/baeldung/jdeffered/manager/SimpleDeferredManagerDemo.java b/libraries-4/src/main/java/com/baeldung/jdeffered/manager/SimpleDeferredManagerDemo.java similarity index 100% rename from libraries/src/main/java/com/baeldung/jdeffered/manager/SimpleDeferredManagerDemo.java rename to libraries-4/src/main/java/com/baeldung/jdeffered/manager/SimpleDeferredManagerDemo.java diff --git a/libraries/src/main/java/com/baeldung/mbassador/AckMessage.java b/libraries-4/src/main/java/com/baeldung/mbassador/AckMessage.java similarity index 100% rename from libraries/src/main/java/com/baeldung/mbassador/AckMessage.java rename to libraries-4/src/main/java/com/baeldung/mbassador/AckMessage.java diff --git a/libraries/src/main/java/com/baeldung/mbassador/Message.java b/libraries-4/src/main/java/com/baeldung/mbassador/Message.java similarity index 100% rename from libraries/src/main/java/com/baeldung/mbassador/Message.java rename to libraries-4/src/main/java/com/baeldung/mbassador/Message.java diff --git a/libraries/src/main/java/com/baeldung/mbassador/RejectMessage.java b/libraries-4/src/main/java/com/baeldung/mbassador/RejectMessage.java similarity index 100% rename from libraries/src/main/java/com/baeldung/mbassador/RejectMessage.java rename to libraries-4/src/main/java/com/baeldung/mbassador/RejectMessage.java diff --git a/libraries/src/main/java/com/baeldung/noexception/CustomExceptionHandler.java b/libraries-4/src/main/java/com/baeldung/noexception/CustomExceptionHandler.java similarity index 100% rename from libraries/src/main/java/com/baeldung/noexception/CustomExceptionHandler.java rename to libraries-4/src/main/java/com/baeldung/noexception/CustomExceptionHandler.java diff --git a/libraries/src/main/java/com/baeldung/pairs/CustomPair.java b/libraries-4/src/main/java/com/baeldung/pairs/CustomPair.java similarity index 100% rename from libraries/src/main/java/com/baeldung/pairs/CustomPair.java rename to libraries-4/src/main/java/com/baeldung/pairs/CustomPair.java diff --git a/libraries/src/main/java/com/baeldung/rome/RSSRomeExample.java b/libraries-4/src/main/java/com/baeldung/rome/RSSRomeExample.java similarity index 100% rename from libraries/src/main/java/com/baeldung/rome/RSSRomeExample.java rename to libraries-4/src/main/java/com/baeldung/rome/RSSRomeExample.java diff --git a/libraries/src/main/java/com/baeldung/yarg/DocumentController.java b/libraries-4/src/main/java/com/baeldung/yarg/DocumentController.java similarity index 100% rename from libraries/src/main/java/com/baeldung/yarg/DocumentController.java rename to libraries-4/src/main/java/com/baeldung/yarg/DocumentController.java diff --git a/libraries/src/test/java/com/baeldung/distinct/DistinctWithEclipseCollectionsUnitTest.java b/libraries-4/src/test/java/com/baeldung/distinct/DistinctWithEclipseCollectionsUnitTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/distinct/DistinctWithEclipseCollectionsUnitTest.java rename to libraries-4/src/test/java/com/baeldung/distinct/DistinctWithEclipseCollectionsUnitTest.java diff --git a/libraries/src/test/java/com/baeldung/distinct/DistinctWithJavaFunctionUnitTest.java b/libraries-4/src/test/java/com/baeldung/distinct/DistinctWithJavaFunctionUnitTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/distinct/DistinctWithJavaFunctionUnitTest.java rename to libraries-4/src/test/java/com/baeldung/distinct/DistinctWithJavaFunctionUnitTest.java diff --git a/libraries/src/test/java/com/baeldung/distinct/DistinctWithStreamexUnitTest.java b/libraries-4/src/test/java/com/baeldung/distinct/DistinctWithStreamexUnitTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/distinct/DistinctWithStreamexUnitTest.java rename to libraries-4/src/test/java/com/baeldung/distinct/DistinctWithStreamexUnitTest.java diff --git a/libraries/src/test/java/com/baeldung/distinct/DistinctWithVavrUnitTest.java b/libraries-4/src/test/java/com/baeldung/distinct/DistinctWithVavrUnitTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/distinct/DistinctWithVavrUnitTest.java rename to libraries-4/src/test/java/com/baeldung/distinct/DistinctWithVavrUnitTest.java diff --git a/libraries/src/test/java/com/baeldung/distinct/PersonDataGenerator.java b/libraries-4/src/test/java/com/baeldung/distinct/PersonDataGenerator.java similarity index 100% rename from libraries/src/test/java/com/baeldung/distinct/PersonDataGenerator.java rename to libraries-4/src/test/java/com/baeldung/distinct/PersonDataGenerator.java diff --git a/libraries/src/test/java/com/baeldung/eclipsecollections/AllSatisfyPatternUnitTest.java b/libraries-4/src/test/java/com/baeldung/eclipsecollections/AllSatisfyPatternUnitTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/eclipsecollections/AllSatisfyPatternUnitTest.java rename to libraries-4/src/test/java/com/baeldung/eclipsecollections/AllSatisfyPatternUnitTest.java diff --git a/libraries/src/test/java/com/baeldung/eclipsecollections/AnySatisfyPatternUnitTest.java b/libraries-4/src/test/java/com/baeldung/eclipsecollections/AnySatisfyPatternUnitTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/eclipsecollections/AnySatisfyPatternUnitTest.java rename to libraries-4/src/test/java/com/baeldung/eclipsecollections/AnySatisfyPatternUnitTest.java diff --git a/libraries/src/test/java/com/baeldung/eclipsecollections/CollectPatternUnitTest.java b/libraries-4/src/test/java/com/baeldung/eclipsecollections/CollectPatternUnitTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/eclipsecollections/CollectPatternUnitTest.java rename to libraries-4/src/test/java/com/baeldung/eclipsecollections/CollectPatternUnitTest.java diff --git a/libraries/src/test/java/com/baeldung/eclipsecollections/ConvertContainerToAnotherUnitTest.java b/libraries-4/src/test/java/com/baeldung/eclipsecollections/ConvertContainerToAnotherUnitTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/eclipsecollections/ConvertContainerToAnotherUnitTest.java rename to libraries-4/src/test/java/com/baeldung/eclipsecollections/ConvertContainerToAnotherUnitTest.java diff --git a/libraries/src/test/java/com/baeldung/eclipsecollections/DetectPatternUnitTest.java b/libraries-4/src/test/java/com/baeldung/eclipsecollections/DetectPatternUnitTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/eclipsecollections/DetectPatternUnitTest.java rename to libraries-4/src/test/java/com/baeldung/eclipsecollections/DetectPatternUnitTest.java diff --git a/libraries/src/test/java/com/baeldung/eclipsecollections/FlatCollectUnitTest.java b/libraries-4/src/test/java/com/baeldung/eclipsecollections/FlatCollectUnitTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/eclipsecollections/FlatCollectUnitTest.java rename to libraries-4/src/test/java/com/baeldung/eclipsecollections/FlatCollectUnitTest.java diff --git a/libraries/src/test/java/com/baeldung/eclipsecollections/ForEachPatternUnitTest.java b/libraries-4/src/test/java/com/baeldung/eclipsecollections/ForEachPatternUnitTest.java similarity index 90% rename from libraries/src/test/java/com/baeldung/eclipsecollections/ForEachPatternUnitTest.java rename to libraries-4/src/test/java/com/baeldung/eclipsecollections/ForEachPatternUnitTest.java index 38d95047ed..a1bd280658 100644 --- a/libraries/src/test/java/com/baeldung/eclipsecollections/ForEachPatternUnitTest.java +++ b/libraries-4/src/test/java/com/baeldung/eclipsecollections/ForEachPatternUnitTest.java @@ -5,6 +5,7 @@ import static org.junit.Assert.assertEquals; import org.eclipse.collections.api.tuple.Pair; import org.eclipse.collections.impl.map.mutable.UnifiedMap; import org.eclipse.collections.impl.tuple.Tuples; +import org.junit.Assert; import org.junit.Test; public class ForEachPatternUnitTest { @@ -23,7 +24,7 @@ public class ForEachPatternUnitTest { } for (int i = 0; i < map.size(); i++) { - assertEquals("New Value", map.get(i + 1)); + Assert.assertEquals("New Value", map.get(i + 1)); } } } diff --git a/libraries/src/test/java/com/baeldung/eclipsecollections/InjectIntoPatternUnitTest.java b/libraries-4/src/test/java/com/baeldung/eclipsecollections/InjectIntoPatternUnitTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/eclipsecollections/InjectIntoPatternUnitTest.java rename to libraries-4/src/test/java/com/baeldung/eclipsecollections/InjectIntoPatternUnitTest.java diff --git a/libraries/src/test/java/com/baeldung/eclipsecollections/LazyIterationUnitTest.java b/libraries-4/src/test/java/com/baeldung/eclipsecollections/LazyIterationUnitTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/eclipsecollections/LazyIterationUnitTest.java rename to libraries-4/src/test/java/com/baeldung/eclipsecollections/LazyIterationUnitTest.java diff --git a/libraries/src/test/java/com/baeldung/eclipsecollections/PartitionPatternUnitTest.java b/libraries-4/src/test/java/com/baeldung/eclipsecollections/PartitionPatternUnitTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/eclipsecollections/PartitionPatternUnitTest.java rename to libraries-4/src/test/java/com/baeldung/eclipsecollections/PartitionPatternUnitTest.java diff --git a/libraries/src/test/java/com/baeldung/eclipsecollections/RejectPatternUnitTest.java b/libraries-4/src/test/java/com/baeldung/eclipsecollections/RejectPatternUnitTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/eclipsecollections/RejectPatternUnitTest.java rename to libraries-4/src/test/java/com/baeldung/eclipsecollections/RejectPatternUnitTest.java diff --git a/libraries/src/test/java/com/baeldung/eclipsecollections/SelectPatternUnitTest.java b/libraries-4/src/test/java/com/baeldung/eclipsecollections/SelectPatternUnitTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/eclipsecollections/SelectPatternUnitTest.java rename to libraries-4/src/test/java/com/baeldung/eclipsecollections/SelectPatternUnitTest.java diff --git a/libraries/src/test/java/com/baeldung/eclipsecollections/ZipUnitTest.java b/libraries-4/src/test/java/com/baeldung/eclipsecollections/ZipUnitTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/eclipsecollections/ZipUnitTest.java rename to libraries-4/src/test/java/com/baeldung/eclipsecollections/ZipUnitTest.java diff --git a/libraries/src/test/java/com/baeldung/eclipsecollections/ZipWithIndexUnitTest.java b/libraries-4/src/test/java/com/baeldung/eclipsecollections/ZipWithIndexUnitTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/eclipsecollections/ZipWithIndexUnitTest.java rename to libraries-4/src/test/java/com/baeldung/eclipsecollections/ZipWithIndexUnitTest.java diff --git a/libraries/src/test/java/com/baeldung/java/io/JavaDirectoryDeleteUnitTest.java b/libraries-4/src/test/java/com/baeldung/io/JavaDirectoryDeleteUnitTest.java similarity index 96% rename from libraries/src/test/java/com/baeldung/java/io/JavaDirectoryDeleteUnitTest.java rename to libraries-4/src/test/java/com/baeldung/io/JavaDirectoryDeleteUnitTest.java index 53d9d11bbb..c9c8242cd5 100644 --- a/libraries/src/test/java/com/baeldung/java/io/JavaDirectoryDeleteUnitTest.java +++ b/libraries-4/src/test/java/com/baeldung/io/JavaDirectoryDeleteUnitTest.java @@ -1,138 +1,138 @@ -package com.baeldung.java.io; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.io.File; -import java.io.IOException; -import java.nio.file.FileVisitResult; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.attribute.BasicFileAttributes; -import java.util.Arrays; -import java.util.Comparator; -import java.util.List; - -import org.apache.commons.io.FileUtils; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.springframework.util.FileSystemUtils; - -public class JavaDirectoryDeleteUnitTest { - private static Path TEMP_DIRECTORY; - private static final String DIRECTORY_NAME = "toBeDeleted"; - - private static final List ALL_LINES = Arrays.asList("This is line 1", "This is line 2", "This is line 3", "This is line 4", "This is line 5", "This is line 6"); - - @BeforeClass - public static void initializeTempDirectory() throws IOException { - TEMP_DIRECTORY = Files.createTempDirectory("tmpForJUnit"); - } - - @AfterClass - public static void cleanTempDirectory() throws IOException { - FileUtils.deleteDirectory(TEMP_DIRECTORY.toFile()); - } - - @Before - public void setupDirectory() throws IOException { - Path tempPathForEachTest = Files.createDirectory(TEMP_DIRECTORY.resolve(DIRECTORY_NAME)); - - // Create a directory structure - Files.write(tempPathForEachTest.resolve("file1.txt"), ALL_LINES.subList(0, 2)); - Files.write(tempPathForEachTest.resolve("file2.txt"), ALL_LINES.subList(2, 4)); - - Files.createDirectories(tempPathForEachTest.resolve("Empty")); - - Path aSubDir = Files.createDirectories(tempPathForEachTest.resolve("notEmpty")); - Files.write(aSubDir.resolve("file3.txt"), ALL_LINES.subList(3, 5)); - Files.write(aSubDir.resolve("file4.txt"), ALL_LINES.subList(0, 3)); - - aSubDir = Files.createDirectories(aSubDir.resolve("anotherSubDirectory")); - Files.write(aSubDir.resolve("file5.txt"), ALL_LINES.subList(4, 5)); - Files.write(aSubDir.resolve("file6.txt"), ALL_LINES.subList(0, 2)); - } - - @After - public void checkAndCleanupIfRequired() throws IOException { - Path pathToBeDeleted = TEMP_DIRECTORY.resolve(DIRECTORY_NAME); - if (Files.exists(pathToBeDeleted)) { - FileUtils.deleteDirectory(pathToBeDeleted.toFile()); - } - } - - private boolean deleteDirectory(File directoryToBeDeleted) { - File[] allContents = directoryToBeDeleted.listFiles(); - - if (allContents != null) { - for (File file : allContents) { - deleteDirectory(file); - } - } - - return directoryToBeDeleted.delete(); - } - - @Test - public void givenDirectory_whenDeletedWithRecursion_thenIsGone() throws IOException { - Path pathToBeDeleted = TEMP_DIRECTORY.resolve(DIRECTORY_NAME); - - boolean result = deleteDirectory(pathToBeDeleted.toFile()); - - assertTrue("Could not delete directory", result); - assertFalse("Directory still exists", Files.exists(pathToBeDeleted)); - } - - @Test - public void givenDirectory_whenDeletedWithCommonsIOFileUtils_thenIsGone() throws IOException { - Path pathToBeDeleted = TEMP_DIRECTORY.resolve(DIRECTORY_NAME); - - FileUtils.deleteDirectory(pathToBeDeleted.toFile()); - - assertFalse("Directory still exists", Files.exists(pathToBeDeleted)); - } - - @Test - public void givenDirectory_whenDeletedWithSpringFileSystemUtils_thenIsGone() throws IOException { - Path pathToBeDeleted = TEMP_DIRECTORY.resolve(DIRECTORY_NAME); - - boolean result = FileSystemUtils.deleteRecursively(pathToBeDeleted.toFile()); - - assertTrue("Could not delete directory", result); - assertFalse("Directory still exists", Files.exists(pathToBeDeleted)); - } - - @Test - public void givenDirectory_whenDeletedWithFilesWalk_thenIsGone() throws IOException { - Path pathToBeDeleted = TEMP_DIRECTORY.resolve(DIRECTORY_NAME); - - Files.walk(pathToBeDeleted).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete); - - assertFalse("Directory still exists", Files.exists(pathToBeDeleted)); - } - - @Test - public void givenDirectory_whenDeletedWithNIO2WalkFileTree_thenIsGone() throws IOException { - Path pathToBeDeleted = TEMP_DIRECTORY.resolve(DIRECTORY_NAME); - - Files.walkFileTree(pathToBeDeleted, new SimpleFileVisitor() { - @Override - public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { - Files.delete(dir); - return FileVisitResult.CONTINUE; - } - - @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { - Files.delete(file); - return FileVisitResult.CONTINUE; - } - }); - - assertFalse("Directory still exists", Files.exists(pathToBeDeleted)); - } -} +package com.baeldung.io; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; + +import org.apache.commons.io.FileUtils; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.springframework.util.FileSystemUtils; + +public class JavaDirectoryDeleteUnitTest { + private static Path TEMP_DIRECTORY; + private static final String DIRECTORY_NAME = "toBeDeleted"; + + private static final List ALL_LINES = Arrays.asList("This is line 1", "This is line 2", "This is line 3", "This is line 4", "This is line 5", "This is line 6"); + + @BeforeClass + public static void initializeTempDirectory() throws IOException { + TEMP_DIRECTORY = Files.createTempDirectory("tmpForJUnit"); + } + + @AfterClass + public static void cleanTempDirectory() throws IOException { + FileUtils.deleteDirectory(TEMP_DIRECTORY.toFile()); + } + + @Before + public void setupDirectory() throws IOException { + Path tempPathForEachTest = Files.createDirectory(TEMP_DIRECTORY.resolve(DIRECTORY_NAME)); + + // Create a directory structure + Files.write(tempPathForEachTest.resolve("file1.txt"), ALL_LINES.subList(0, 2)); + Files.write(tempPathForEachTest.resolve("file2.txt"), ALL_LINES.subList(2, 4)); + + Files.createDirectories(tempPathForEachTest.resolve("Empty")); + + Path aSubDir = Files.createDirectories(tempPathForEachTest.resolve("notEmpty")); + Files.write(aSubDir.resolve("file3.txt"), ALL_LINES.subList(3, 5)); + Files.write(aSubDir.resolve("file4.txt"), ALL_LINES.subList(0, 3)); + + aSubDir = Files.createDirectories(aSubDir.resolve("anotherSubDirectory")); + Files.write(aSubDir.resolve("file5.txt"), ALL_LINES.subList(4, 5)); + Files.write(aSubDir.resolve("file6.txt"), ALL_LINES.subList(0, 2)); + } + + @After + public void checkAndCleanupIfRequired() throws IOException { + Path pathToBeDeleted = TEMP_DIRECTORY.resolve(DIRECTORY_NAME); + if (Files.exists(pathToBeDeleted)) { + FileUtils.deleteDirectory(pathToBeDeleted.toFile()); + } + } + + private boolean deleteDirectory(File directoryToBeDeleted) { + File[] allContents = directoryToBeDeleted.listFiles(); + + if (allContents != null) { + for (File file : allContents) { + deleteDirectory(file); + } + } + + return directoryToBeDeleted.delete(); + } + + @Test + public void givenDirectory_whenDeletedWithRecursion_thenIsGone() throws IOException { + Path pathToBeDeleted = TEMP_DIRECTORY.resolve(DIRECTORY_NAME); + + boolean result = deleteDirectory(pathToBeDeleted.toFile()); + + assertTrue("Could not delete directory", result); + assertFalse("Directory still exists", Files.exists(pathToBeDeleted)); + } + + @Test + public void givenDirectory_whenDeletedWithCommonsIOFileUtils_thenIsGone() throws IOException { + Path pathToBeDeleted = TEMP_DIRECTORY.resolve(DIRECTORY_NAME); + + FileUtils.deleteDirectory(pathToBeDeleted.toFile()); + + assertFalse("Directory still exists", Files.exists(pathToBeDeleted)); + } + + @Test + public void givenDirectory_whenDeletedWithSpringFileSystemUtils_thenIsGone() throws IOException { + Path pathToBeDeleted = TEMP_DIRECTORY.resolve(DIRECTORY_NAME); + + boolean result = FileSystemUtils.deleteRecursively(pathToBeDeleted.toFile()); + + assertTrue("Could not delete directory", result); + assertFalse("Directory still exists", Files.exists(pathToBeDeleted)); + } + + @Test + public void givenDirectory_whenDeletedWithFilesWalk_thenIsGone() throws IOException { + Path pathToBeDeleted = TEMP_DIRECTORY.resolve(DIRECTORY_NAME); + + Files.walk(pathToBeDeleted).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete); + + assertFalse("Directory still exists", Files.exists(pathToBeDeleted)); + } + + @Test + public void givenDirectory_whenDeletedWithNIO2WalkFileTree_thenIsGone() throws IOException { + Path pathToBeDeleted = TEMP_DIRECTORY.resolve(DIRECTORY_NAME); + + Files.walkFileTree(pathToBeDeleted, new SimpleFileVisitor() { + @Override + public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { + Files.delete(dir); + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + Files.delete(file); + return FileVisitResult.CONTINUE; + } + }); + + assertFalse("Directory still exists", Files.exists(pathToBeDeleted)); + } +} diff --git a/libraries/src/test/java/com/baeldung/jdeffered/JDeferredUnitTest.java b/libraries-4/src/test/java/com/baeldung/jdeffered/JDeferredUnitTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/jdeffered/JDeferredUnitTest.java rename to libraries-4/src/test/java/com/baeldung/jdeffered/JDeferredUnitTest.java diff --git a/libraries/src/test/java/com/baeldung/mbassador/MBassadorAsyncDispatchUnitTest.java b/libraries-4/src/test/java/com/baeldung/mbassador/MBassadorAsyncDispatchUnitTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/mbassador/MBassadorAsyncDispatchUnitTest.java rename to libraries-4/src/test/java/com/baeldung/mbassador/MBassadorAsyncDispatchUnitTest.java diff --git a/libraries/src/test/java/com/baeldung/mbassador/MBassadorAsyncInvocationUnitTest.java b/libraries-4/src/test/java/com/baeldung/mbassador/MBassadorAsyncInvocationUnitTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/mbassador/MBassadorAsyncInvocationUnitTest.java rename to libraries-4/src/test/java/com/baeldung/mbassador/MBassadorAsyncInvocationUnitTest.java diff --git a/libraries/src/test/java/com/baeldung/mbassador/MBassadorBasicUnitTest.java b/libraries-4/src/test/java/com/baeldung/mbassador/MBassadorBasicUnitTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/mbassador/MBassadorBasicUnitTest.java rename to libraries-4/src/test/java/com/baeldung/mbassador/MBassadorBasicUnitTest.java diff --git a/libraries/src/test/java/com/baeldung/mbassador/MBassadorConfigurationUnitTest.java b/libraries-4/src/test/java/com/baeldung/mbassador/MBassadorConfigurationUnitTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/mbassador/MBassadorConfigurationUnitTest.java rename to libraries-4/src/test/java/com/baeldung/mbassador/MBassadorConfigurationUnitTest.java diff --git a/libraries/src/test/java/com/baeldung/mbassador/MBassadorFilterUnitTest.java b/libraries-4/src/test/java/com/baeldung/mbassador/MBassadorFilterUnitTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/mbassador/MBassadorFilterUnitTest.java rename to libraries-4/src/test/java/com/baeldung/mbassador/MBassadorFilterUnitTest.java diff --git a/libraries/src/test/java/com/baeldung/mbassador/MBassadorHierarchyUnitTest.java b/libraries-4/src/test/java/com/baeldung/mbassador/MBassadorHierarchyUnitTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/mbassador/MBassadorHierarchyUnitTest.java rename to libraries-4/src/test/java/com/baeldung/mbassador/MBassadorHierarchyUnitTest.java diff --git a/libraries/src/test/java/com/baeldung/noexception/NoExceptionUnitTest.java b/libraries-4/src/test/java/com/baeldung/noexception/NoExceptionUnitTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/noexception/NoExceptionUnitTest.java rename to libraries-4/src/test/java/com/baeldung/noexception/NoExceptionUnitTest.java diff --git a/libraries/src/test/java/com/baeldung/pairs/ApacheCommonsPairUnitTest.java b/libraries-4/src/test/java/com/baeldung/pairs/ApacheCommonsPairUnitTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/pairs/ApacheCommonsPairUnitTest.java rename to libraries-4/src/test/java/com/baeldung/pairs/ApacheCommonsPairUnitTest.java diff --git a/libraries/src/test/java/com/baeldung/pairs/CoreJavaPairUnitTest.java b/libraries-4/src/test/java/com/baeldung/pairs/CoreJavaPairUnitTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/pairs/CoreJavaPairUnitTest.java rename to libraries-4/src/test/java/com/baeldung/pairs/CoreJavaPairUnitTest.java diff --git a/libraries/src/test/java/com/baeldung/pairs/CoreJavaSimpleEntryUnitTest.java b/libraries-4/src/test/java/com/baeldung/pairs/CoreJavaSimpleEntryUnitTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/pairs/CoreJavaSimpleEntryUnitTest.java rename to libraries-4/src/test/java/com/baeldung/pairs/CoreJavaSimpleEntryUnitTest.java diff --git a/libraries/src/test/java/com/baeldung/pairs/VavrPairsUnitTest.java b/libraries-4/src/test/java/com/baeldung/pairs/VavrPairsUnitTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/pairs/VavrPairsUnitTest.java rename to libraries-4/src/test/java/com/baeldung/pairs/VavrPairsUnitTest.java diff --git a/libraries/src/test/java/com/baeldung/pcollections/PCollectionsUnitTest.java b/libraries-4/src/test/java/com/baeldung/pcollections/PCollectionsUnitTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/pcollections/PCollectionsUnitTest.java rename to libraries-4/src/test/java/com/baeldung/pcollections/PCollectionsUnitTest.java diff --git a/libraries-5/pom.xml b/libraries-5/pom.xml new file mode 100644 index 0000000000..b5a1ecd49c --- /dev/null +++ b/libraries-5/pom.xml @@ -0,0 +1,15 @@ + + + + parent-modules + com.baeldung + 1.0.0-SNAPSHOT + + 4.0.0 + + libraries-5 + + + \ No newline at end of file diff --git a/libraries-6/pom.xml b/libraries-6/pom.xml new file mode 100644 index 0000000000..be74ff9ef0 --- /dev/null +++ b/libraries-6/pom.xml @@ -0,0 +1,15 @@ + + + + parent-modules + com.baeldung + 1.0.0-SNAPSHOT + + 4.0.0 + + libraries-6 + + + \ No newline at end of file diff --git a/libraries/README.md b/libraries/README.md index 79ba8fe55d..3f259e4222 100644 --- a/libraries/README.md +++ b/libraries/README.md @@ -19,6 +19,8 @@ Remember, for advanced libraries like [Jackson](/jackson) and [JUnit](/testing-m - [Software Transactional Memory in Java Using Multiverse](https://www.baeldung.com/java-multiverse-stm) - [Locality-Sensitive Hashing in Java Using Java-LSH](https://www.baeldung.com/locality-sensitive-hashing) - [Introduction to Neuroph](https://www.baeldung.com/neuroph) + +#4 - [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) @@ -29,6 +31,8 @@ Remember, for advanced libraries like [Jackson](/jackson) and [JUnit](/testing-m - [Guide to JDeferred](https://www.baeldung.com/jdeferred) - [Introduction to MBassador](https://www.baeldung.com/mbassador) - [Using Pairs in Java](https://www.baeldung.com/java-pairs) + +#5 - [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) @@ -39,10 +43,13 @@ Remember, for advanced libraries like [Jackson](/jackson) and [JUnit](/testing-m - [Introduction to Atlassian Fugue](https://www.baeldung.com/java-fugue) - [Publish and Receive Messages with Nats Java Client](https://www.baeldung.com/nats-java-client) - [Java Concurrency Utility with JCTools](https://www.baeldung.com/java-concurrency-jc-tools) + +#6 - [Introduction to JavaPoet](https://www.baeldung.com/java-poet) - [Guide to Resilience4j](https://www.baeldung.com/resilience4j) -- [Exactly Once Processing in Kafka](https://www.baeldung.com/kafka-exactly-once) - [Implementing a FTP-Client in Java](https://www.baeldung.com/java-ftp-client) - [Introduction to Functional Java](https://www.baeldung.com/java-functional-library) - [A Guide to the Reflections Library](https://www.baeldung.com/reflections-library) + +- [Exactly Once Processing in Kafka](https://www.baeldung.com/kafka-exactly-once) - More articles [[next -->]](/libraries-2) diff --git a/libraries/pom.xml b/libraries/pom.xml index 41bc2b9311..5d540f0d90 100644 --- a/libraries/pom.xml +++ b/libraries/pom.xml @@ -70,11 +70,11 @@ ${jnats.version} - - rome - rome - ${rome.version} - + + + + + net.serenity-bdd serenity-core @@ -218,11 +218,11 @@ quartz ${quartz.version} - - one.util - streamex - ${streamex.version} - + + + + + org.jooq jool @@ -256,18 +256,18 @@ - - org.awaitility - awaitility - ${awaitility.version} - test - - - org.awaitility - awaitility-proxy - ${awaitility.version} - test - + + + + + + + + + + + + org.hamcrest java-hamcrest @@ -284,42 +284,42 @@ byte-buddy-agent ${bytebuddy.version} - - org.pcollections - pcollections - ${pcollections.version} - - - com.machinezoo.noexception - noexception - ${noexception.version} - - - org.eclipse.collections - eclipse-collections - ${eclipse-collections.version} - - - io.vavr - vavr - ${vavr.version} - + + + + + + + + + + + + + + + + + + + + - - com.haulmont.yarg - yarg - ${yarg.version} - - - net.engio - mbassador - ${mbassador.version} - - - org.jdeferred - jdeferred-core - ${jdeferred.version} - + + + + + + + + + + + + + + + com.codepoetics protonpack @@ -572,14 +572,14 @@ 1.1.0 0.10 3.5.0 - 3.0.0 + 2.0.0.0 1.7.1 - 2.1.2 - 1.0 - 8.2.0 - 0.6.5 - 0.9.0 + + + + + 1.15 2.5.5 @@ -604,10 +604,10 @@ 2.3.0 0.9.12 1.19 - 1.1.0 - 2.0.4 - 1.3.1 - 1.2.6 + + + + 4.8.1 4.5.1 3.0.2 diff --git a/pom.xml b/pom.xml index 44a94095b3..d481f95042 100644 --- a/pom.xml +++ b/pom.xml @@ -1011,6 +1011,10 @@ libraries-2 libraries-3 + libraries-4 + + + libraries-apache-commons libraries-apache-commons-collections libraries-apache-commons-io From f3ce1554c9dbdbcc8aef2d09665ca115ede478e6 Mon Sep 17 00:00:00 2001 From: Tyrell Flurry Date: Mon, 27 Apr 2020 10:47:52 -0400 Subject: [PATCH 06/19] BAEL-3929: made changes per code/article review. --- maven-all/maven-unused-dependencies/pom.xml | 14 ++++++------- .../src/main/java/com/baeldung/Main.java | 20 ------------------- .../java/com/baeldung/ReflectionMain.java | 15 -------------- .../UnusedDependenciesExample.java | 17 ++++++++++++++++ 4 files changed, 24 insertions(+), 42 deletions(-) delete mode 100644 maven-all/maven-unused-dependencies/src/main/java/com/baeldung/Main.java delete mode 100644 maven-all/maven-unused-dependencies/src/main/java/com/baeldung/ReflectionMain.java create mode 100644 maven-all/maven-unused-dependencies/src/main/java/com/baeldung/mavendependencyplugin/UnusedDependenciesExample.java diff --git a/maven-all/maven-unused-dependencies/pom.xml b/maven-all/maven-unused-dependencies/pom.xml index 19a06fc605..c8f6c1f04b 100644 --- a/maven-all/maven-unused-dependencies/pom.xml +++ b/maven-all/maven-unused-dependencies/pom.xml @@ -6,6 +6,13 @@ maven-unused-dependencies 0.0.1-SNAPSHOT + + 3.2.2 + 1.7.25 + 3.1.1 + 3.1 + + commons-collections @@ -37,11 +44,4 @@ - - 3.2.2 - 1.7.25 - 3.1.1 - 3.1 - - \ No newline at end of file diff --git a/maven-all/maven-unused-dependencies/src/main/java/com/baeldung/Main.java b/maven-all/maven-unused-dependencies/src/main/java/com/baeldung/Main.java deleted file mode 100644 index 2626bb30a3..0000000000 --- a/maven-all/maven-unused-dependencies/src/main/java/com/baeldung/Main.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.baeldung; - -import java.util.HashMap; -import java.util.Map; - -import org.slf4j.LoggerFactory; - -public class Main { - - public static void main(String[] args) { - Map map = new HashMap<>(); - map.put("Dallas", "Texas"); - map.put("Green Bay", "Wisconsin"); - map.put("Seattle", "Washington"); - - LoggerFactory.getLogger(Main.class) - .info("Map: {}", map); - } - -} diff --git a/maven-all/maven-unused-dependencies/src/main/java/com/baeldung/ReflectionMain.java b/maven-all/maven-unused-dependencies/src/main/java/com/baeldung/ReflectionMain.java deleted file mode 100644 index 48e42f7c66..0000000000 --- a/maven-all/maven-unused-dependencies/src/main/java/com/baeldung/ReflectionMain.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.baeldung; - -public class ReflectionMain { - - public static void main(String[] args) { - ClassLoader classLoader = Main.class.getClassLoader(); - try { - System.out.println(classLoader.loadClass("org.apache.commons.collections.CollectionUtils") - .getSimpleName()); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } - } - -} \ No newline at end of file diff --git a/maven-all/maven-unused-dependencies/src/main/java/com/baeldung/mavendependencyplugin/UnusedDependenciesExample.java b/maven-all/maven-unused-dependencies/src/main/java/com/baeldung/mavendependencyplugin/UnusedDependenciesExample.java new file mode 100644 index 0000000000..c9390880ed --- /dev/null +++ b/maven-all/maven-unused-dependencies/src/main/java/com/baeldung/mavendependencyplugin/UnusedDependenciesExample.java @@ -0,0 +1,17 @@ +package com.baeldung.mavendependencyplugin; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class UnusedDependenciesExample { + + /** + * When the Maven dependency analyzer analyzes the code, it will see that the slf4j dependency is being used in this method. + * + * @return the slf4j {@link Logger}. + */ + public Logger getLogger() { + return LoggerFactory.getLogger(UnusedDependenciesExample.class); + } + +} From 299effed3e9559f021b75a2f2e68d278b7b1ac07 Mon Sep 17 00:00:00 2001 From: mikr Date: Wed, 29 Apr 2020 20:49:15 +0200 Subject: [PATCH 07/19] Java-1470 Split libraries module --- libraries-4/README.md | 44 +-- libraries-5/README.md | 21 ++ libraries-5/pom.xml | 132 ++++++- .../java/com/baeldung/akka/FirstActor.java | 0 .../main/java/com/baeldung/akka/MyActor.java | 0 .../java/com/baeldung/akka/PrinterActor.java | 0 .../java/com/baeldung/akka/ReadingActor.java | 0 .../com/baeldung/akka/WordCounterActor.java | 0 .../main/java/com/baeldung/bytebuddy/Bar.java | 0 .../main/java/com/baeldung/bytebuddy/Foo.java | 0 .../com/baeldung/caffeine/DataObject.java | 0 .../com/baeldung/jctools/MpmcBenchmark.java | 0 .../main/java/com/baeldung/jctools/README.md | 0 .../java/com/baeldung/jnats/NatsClient.java | 0 .../main/java/com/baeldung/streamex/Role.java | 0 .../java/com/baeldung/streamex/StreamEX.java | 0 .../main/java/com/baeldung/streamex/User.java | 0 .../com/baeldung/akka/AkkaActorsUnitTest.java | 0 .../baeldung/bytebuddy/ByteBuddyUnitTest.java | 0 .../baeldung/caffeine/CaffeineUnitTest.java | 21 +- .../baeldung/dockerapi/ContainerLiveTest.java | 6 +- .../dockerapi/DockerClientLiveTest.java | 0 .../com/baeldung/dockerapi/ImageLiveTest.java | 4 +- .../baeldung/dockerapi/NetworkLiveTest.java | 3 +- .../baeldung/dockerapi/VolumeLiveTest.java | 5 +- .../com/baeldung}/fugue/FugueUnitTest.java | 2 +- .../com/baeldung/jctools/JCToolsUnitTest.java | 9 +- .../baeldung/jnats/NatsClientLiveTest.java | 0 .../java/com/baeldung/jool/JOOLUnitTest.java | 0 .../PactConsumerDrivenContractUnitTest.java | 0 .../StreamExMergeStreamsUnitTest.java | 2 +- .../src/test/resources/dockerapi/Dockerfile | 0 libraries-6/README.md | 17 + libraries-6/pom.xml | 96 +++++ .../com/baeldung/fj/FunctionalJavaIOMain.java | 86 ++--- .../com/baeldung/fj/FunctionalJavaMain.java | 96 ++--- .../main/java/com/baeldung/ftp/FtpClient.java | 0 .../baeldung/javapoet/PersonGenerator.java | 0 .../kafka/TransactionalMessageProducer.java | 0 .../kafka/TransactionalWordCount.java | 0 .../main/java/com/baeldung/kafka/Tuple.java | 0 .../baeldung/reflections/ReflectionsApp.java | 142 ++++---- .../baeldung/fj/FunctionalJavaUnitTest.java | 7 +- .../ftp/FtpClientIntegrationTest.java | 0 .../ftp/JdkFtpClientIntegrationTest.java | 0 .../test/PersonGeneratorUnitTest.java | 0 .../baeldung/javapoet/test/person/Gender.java | 0 .../baeldung/javapoet/test/person/Person.java | 0 .../javapoet/test/person/Student.java | 0 .../kafkastreams/KafkaStreamsLiveTest.java | 0 .../reflections/ReflectionsUnitTest.java | 100 +++--- .../resilence4j}/Resilience4jUnitTest.java | 2 +- .../src/test/resources/ftp/baz.txt | 0 libraries/pom.xml | 332 +++++++++--------- 54 files changed, 689 insertions(+), 438 deletions(-) create mode 100644 libraries-5/README.md rename {libraries => libraries-5}/src/main/java/com/baeldung/akka/FirstActor.java (100%) rename {libraries => libraries-5}/src/main/java/com/baeldung/akka/MyActor.java (100%) rename {libraries => libraries-5}/src/main/java/com/baeldung/akka/PrinterActor.java (100%) rename {libraries => libraries-5}/src/main/java/com/baeldung/akka/ReadingActor.java (100%) rename {libraries => libraries-5}/src/main/java/com/baeldung/akka/WordCounterActor.java (100%) rename {libraries => libraries-5}/src/main/java/com/baeldung/bytebuddy/Bar.java (100%) rename {libraries => libraries-5}/src/main/java/com/baeldung/bytebuddy/Foo.java (100%) rename {libraries => libraries-5}/src/main/java/com/baeldung/caffeine/DataObject.java (100%) rename {libraries => libraries-5}/src/main/java/com/baeldung/jctools/MpmcBenchmark.java (100%) rename {libraries => libraries-5}/src/main/java/com/baeldung/jctools/README.md (100%) rename {libraries => libraries-5}/src/main/java/com/baeldung/jnats/NatsClient.java (100%) rename {libraries => libraries-5}/src/main/java/com/baeldung/streamex/Role.java (100%) rename {libraries => libraries-5}/src/main/java/com/baeldung/streamex/StreamEX.java (100%) rename {libraries => libraries-5}/src/main/java/com/baeldung/streamex/User.java (100%) rename {libraries => libraries-5}/src/test/java/com/baeldung/akka/AkkaActorsUnitTest.java (100%) rename {libraries => libraries-5}/src/test/java/com/baeldung/bytebuddy/ByteBuddyUnitTest.java (100%) rename {libraries => libraries-5}/src/test/java/com/baeldung/caffeine/CaffeineUnitTest.java (88%) rename {libraries => libraries-5}/src/test/java/com/baeldung/dockerapi/ContainerLiveTest.java (94%) rename {libraries => libraries-5}/src/test/java/com/baeldung/dockerapi/DockerClientLiveTest.java (100%) rename {libraries => libraries-5}/src/test/java/com/baeldung/dockerapi/ImageLiveTest.java (96%) rename {libraries => libraries-5}/src/test/java/com/baeldung/dockerapi/NetworkLiveTest.java (95%) rename {libraries => libraries-5}/src/test/java/com/baeldung/dockerapi/VolumeLiveTest.java (92%) rename {libraries/src/test/java/com/baeldung/atlassian => libraries-5/src/test/java/com/baeldung}/fugue/FugueUnitTest.java (99%) rename {libraries => libraries-5}/src/test/java/com/baeldung/jctools/JCToolsUnitTest.java (88%) rename {libraries => libraries-5}/src/test/java/com/baeldung/jnats/NatsClientLiveTest.java (100%) rename {libraries => libraries-5}/src/test/java/com/baeldung/jool/JOOLUnitTest.java (100%) rename {libraries => libraries-5}/src/test/java/com/baeldung/pact/PactConsumerDrivenContractUnitTest.java (100%) rename {libraries/src/test/java/com/baeldung/stream => libraries-5/src/test/java/com/baeldung/streamex}/StreamExMergeStreamsUnitTest.java (98%) rename {libraries => libraries-5}/src/test/resources/dockerapi/Dockerfile (100%) create mode 100644 libraries-6/README.md rename {libraries => libraries-6}/src/main/java/com/baeldung/fj/FunctionalJavaIOMain.java (96%) rename {libraries => libraries-6}/src/main/java/com/baeldung/fj/FunctionalJavaMain.java (96%) rename {libraries => libraries-6}/src/main/java/com/baeldung/ftp/FtpClient.java (100%) rename {libraries => libraries-6}/src/main/java/com/baeldung/javapoet/PersonGenerator.java (100%) rename {libraries => libraries-6}/src/main/java/com/baeldung/kafka/TransactionalMessageProducer.java (100%) rename {libraries => libraries-6}/src/main/java/com/baeldung/kafka/TransactionalWordCount.java (100%) rename {libraries => libraries-6}/src/main/java/com/baeldung/kafka/Tuple.java (100%) rename {libraries => libraries-6}/src/main/java/com/baeldung/reflections/ReflectionsApp.java (97%) rename {libraries => libraries-6}/src/test/java/com/baeldung/fj/FunctionalJavaUnitTest.java (95%) rename {libraries => libraries-6}/src/test/java/com/baeldung/ftp/FtpClientIntegrationTest.java (100%) rename {libraries => libraries-6}/src/test/java/com/baeldung/ftp/JdkFtpClientIntegrationTest.java (100%) rename {libraries => libraries-6}/src/test/java/com/baeldung/javapoet/test/PersonGeneratorUnitTest.java (100%) rename {libraries => libraries-6}/src/test/java/com/baeldung/javapoet/test/person/Gender.java (100%) rename {libraries => libraries-6}/src/test/java/com/baeldung/javapoet/test/person/Person.java (100%) rename {libraries => libraries-6}/src/test/java/com/baeldung/javapoet/test/person/Student.java (100%) rename {libraries => libraries-6}/src/test/java/com/baeldung/kafkastreams/KafkaStreamsLiveTest.java (100%) rename {libraries => libraries-6}/src/test/java/com/baeldung/reflections/ReflectionsUnitTest.java (96%) rename {libraries/src/test/java/com/baeldung/resilience4j => libraries-6/src/test/java/com/baeldung/resilence4j}/Resilience4jUnitTest.java (99%) rename {libraries => libraries-6}/src/test/resources/ftp/baz.txt (100%) diff --git a/libraries-4/README.md b/libraries-4/README.md index f650c073a7..9cda07bdf5 100644 --- a/libraries-4/README.md +++ b/libraries-4/README.md @@ -1,4 +1,4 @@ -## Libraries +## Libraries-4 This module contains articles about various Java libraries. These are small libraries that are relatively easy to use and do not require any separate module of their own. @@ -8,36 +8,14 @@ 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 - -- [Introduction to Javatuples](https://www.baeldung.com/java-tuples) -- [Introduction to Javassist](https://www.baeldung.com/javassist) -- [Introduction to Apache Flink with Java](https://www.baeldung.com/apache-flink) -- [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) -- [Locality-Sensitive Hashing in Java Using Java-LSH](https://www.baeldung.com/locality-sensitive-hashing) -- [Introduction to Neuroph](https://www.baeldung.com/neuroph) - -#5 -- [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) -- [Publish and Receive Messages with Nats Java Client](https://www.baeldung.com/nats-java-client) -- [Java Concurrency Utility with JCTools](https://www.baeldung.com/java-concurrency-jc-tools) - -#6 -- [Introduction to JavaPoet](https://www.baeldung.com/java-poet) -- [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) -- [A Guide to the Reflections Library](https://www.baeldung.com/reflections-library) - -- [Exactly Once Processing in Kafka](https://www.baeldung.com/kafka-exactly-once) +- [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) +- [Using Pairs in Java](https://www.baeldung.com/java-pairs) - More articles [[next -->]](/libraries-2) diff --git a/libraries-5/README.md b/libraries-5/README.md new file mode 100644 index 0000000000..f1e749b293 --- /dev/null +++ b/libraries-5/README.md @@ -0,0 +1,21 @@ +## Libraries-5 + +This module contains articles about various Java libraries. +These are small libraries that are relatively easy to use and do not require any separate module of their own. + +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 +- [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) +- [Publish and Receive Messages with Nats Java Client](https://www.baeldung.com/nats-java-client) +- [Java Concurrency Utility with JCTools](https://www.baeldung.com/java-concurrency-jc-tools) +- More articles [[<-- prev]](/libraries-4) [[next -->]](/libraries-6) diff --git a/libraries-5/pom.xml b/libraries-5/pom.xml index b5a1ecd49c..41c92e54c3 100644 --- a/libraries-5/pom.xml +++ b/libraries-5/pom.xml @@ -7,9 +7,139 @@ com.baeldung 1.0.0-SNAPSHOT - 4.0.0 libraries-5 + 4.0.0 + + + org.springframework + spring-web + ${spring.version} + + + org.assertj + assertj-core + ${assertj.version} + + + org.jooq + jool + ${jool.version} + + + au.com.dius + pact-jvm-consumer-junit_2.11 + ${pact.version} + test + + + org.codehaus.groovy + groovy-all + + + + + + + com.typesafe.akka + akka-actor_2.12 + ${typesafe-akka.version} + + + com.typesafe.akka + akka-testkit_2.12 + ${typesafe-akka.version} + test + + + + one.util + streamex + ${streamex.version} + + + net.bytebuddy + byte-buddy + ${bytebuddy.version} + + + net.bytebuddy + byte-buddy-agent + ${bytebuddy.version} + + + + + com.github.docker-java + docker-java + ${docker.version} + + + org.slf4j + slf4j-log4j12 + + + org.slf4j + jcl-over-slf4j + + + ch.qos.logback + logback-classic + + + + + + + com.github.ben-manes.caffeine + caffeine + ${caffeine.version} + + + com.google.code.findbugs + jsr305 + ${findbugs.version} + test + + + + io.atlassian.fugue + fugue + ${fugue.version} + + + io.nats + jnats + ${jnats.version} + + + org.jctools + jctools-core + ${jctools.version} + + + org.openjdk.jmh + jmh-core + ${jmh.version} + + + + + 3.5.0 + 0.9.12 + 4.3.8.RELEASE + 3.6.2 + 2.5.26 + 0.6.5 + 1.7.1 + 3.0.14 + 2.5.5 + 3.0.2 + 4.5.1 + 1.0 + 2.1.2 + 1.19 + \ No newline at end of file diff --git a/libraries/src/main/java/com/baeldung/akka/FirstActor.java b/libraries-5/src/main/java/com/baeldung/akka/FirstActor.java similarity index 100% rename from libraries/src/main/java/com/baeldung/akka/FirstActor.java rename to libraries-5/src/main/java/com/baeldung/akka/FirstActor.java diff --git a/libraries/src/main/java/com/baeldung/akka/MyActor.java b/libraries-5/src/main/java/com/baeldung/akka/MyActor.java similarity index 100% rename from libraries/src/main/java/com/baeldung/akka/MyActor.java rename to libraries-5/src/main/java/com/baeldung/akka/MyActor.java diff --git a/libraries/src/main/java/com/baeldung/akka/PrinterActor.java b/libraries-5/src/main/java/com/baeldung/akka/PrinterActor.java similarity index 100% rename from libraries/src/main/java/com/baeldung/akka/PrinterActor.java rename to libraries-5/src/main/java/com/baeldung/akka/PrinterActor.java diff --git a/libraries/src/main/java/com/baeldung/akka/ReadingActor.java b/libraries-5/src/main/java/com/baeldung/akka/ReadingActor.java similarity index 100% rename from libraries/src/main/java/com/baeldung/akka/ReadingActor.java rename to libraries-5/src/main/java/com/baeldung/akka/ReadingActor.java diff --git a/libraries/src/main/java/com/baeldung/akka/WordCounterActor.java b/libraries-5/src/main/java/com/baeldung/akka/WordCounterActor.java similarity index 100% rename from libraries/src/main/java/com/baeldung/akka/WordCounterActor.java rename to libraries-5/src/main/java/com/baeldung/akka/WordCounterActor.java diff --git a/libraries/src/main/java/com/baeldung/bytebuddy/Bar.java b/libraries-5/src/main/java/com/baeldung/bytebuddy/Bar.java similarity index 100% rename from libraries/src/main/java/com/baeldung/bytebuddy/Bar.java rename to libraries-5/src/main/java/com/baeldung/bytebuddy/Bar.java diff --git a/libraries/src/main/java/com/baeldung/bytebuddy/Foo.java b/libraries-5/src/main/java/com/baeldung/bytebuddy/Foo.java similarity index 100% rename from libraries/src/main/java/com/baeldung/bytebuddy/Foo.java rename to libraries-5/src/main/java/com/baeldung/bytebuddy/Foo.java diff --git a/libraries/src/main/java/com/baeldung/caffeine/DataObject.java b/libraries-5/src/main/java/com/baeldung/caffeine/DataObject.java similarity index 100% rename from libraries/src/main/java/com/baeldung/caffeine/DataObject.java rename to libraries-5/src/main/java/com/baeldung/caffeine/DataObject.java diff --git a/libraries/src/main/java/com/baeldung/jctools/MpmcBenchmark.java b/libraries-5/src/main/java/com/baeldung/jctools/MpmcBenchmark.java similarity index 100% rename from libraries/src/main/java/com/baeldung/jctools/MpmcBenchmark.java rename to libraries-5/src/main/java/com/baeldung/jctools/MpmcBenchmark.java diff --git a/libraries/src/main/java/com/baeldung/jctools/README.md b/libraries-5/src/main/java/com/baeldung/jctools/README.md similarity index 100% rename from libraries/src/main/java/com/baeldung/jctools/README.md rename to libraries-5/src/main/java/com/baeldung/jctools/README.md diff --git a/libraries/src/main/java/com/baeldung/jnats/NatsClient.java b/libraries-5/src/main/java/com/baeldung/jnats/NatsClient.java similarity index 100% rename from libraries/src/main/java/com/baeldung/jnats/NatsClient.java rename to libraries-5/src/main/java/com/baeldung/jnats/NatsClient.java diff --git a/libraries/src/main/java/com/baeldung/streamex/Role.java b/libraries-5/src/main/java/com/baeldung/streamex/Role.java similarity index 100% rename from libraries/src/main/java/com/baeldung/streamex/Role.java rename to libraries-5/src/main/java/com/baeldung/streamex/Role.java diff --git a/libraries/src/main/java/com/baeldung/streamex/StreamEX.java b/libraries-5/src/main/java/com/baeldung/streamex/StreamEX.java similarity index 100% rename from libraries/src/main/java/com/baeldung/streamex/StreamEX.java rename to libraries-5/src/main/java/com/baeldung/streamex/StreamEX.java diff --git a/libraries/src/main/java/com/baeldung/streamex/User.java b/libraries-5/src/main/java/com/baeldung/streamex/User.java similarity index 100% rename from libraries/src/main/java/com/baeldung/streamex/User.java rename to libraries-5/src/main/java/com/baeldung/streamex/User.java diff --git a/libraries/src/test/java/com/baeldung/akka/AkkaActorsUnitTest.java b/libraries-5/src/test/java/com/baeldung/akka/AkkaActorsUnitTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/akka/AkkaActorsUnitTest.java rename to libraries-5/src/test/java/com/baeldung/akka/AkkaActorsUnitTest.java diff --git a/libraries/src/test/java/com/baeldung/bytebuddy/ByteBuddyUnitTest.java b/libraries-5/src/test/java/com/baeldung/bytebuddy/ByteBuddyUnitTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/bytebuddy/ByteBuddyUnitTest.java rename to libraries-5/src/test/java/com/baeldung/bytebuddy/ByteBuddyUnitTest.java diff --git a/libraries/src/test/java/com/baeldung/caffeine/CaffeineUnitTest.java b/libraries-5/src/test/java/com/baeldung/caffeine/CaffeineUnitTest.java similarity index 88% rename from libraries/src/test/java/com/baeldung/caffeine/CaffeineUnitTest.java rename to libraries-5/src/test/java/com/baeldung/caffeine/CaffeineUnitTest.java index d523d0ff8b..65c441c50d 100644 --- a/libraries/src/test/java/com/baeldung/caffeine/CaffeineUnitTest.java +++ b/libraries-5/src/test/java/com/baeldung/caffeine/CaffeineUnitTest.java @@ -8,6 +8,7 @@ import java.util.concurrent.TimeUnit; import javax.annotation.Nonnull; +import org.junit.Assert; import org.junit.Test; import com.github.benmanes.caffeine.cache.*; @@ -65,43 +66,43 @@ public class CaffeineUnitTest { assertEquals("Data for " + key, dataObject.getData()); }); - cache.getAll(Arrays.asList("A", "B", "C")).thenAccept(dataObjectMap -> assertEquals(3, dataObjectMap.size())); + cache.getAll(Arrays.asList("A", "B", "C")).thenAccept(dataObjectMap -> Assert.assertEquals(3, dataObjectMap.size())); } @Test public void givenLoadingCacheWithSmallSize_whenPut_thenSizeIsConstant() { LoadingCache cache = Caffeine.newBuilder().maximumSize(1).refreshAfterWrite(10, TimeUnit.MINUTES).build(k -> DataObject.get("Data for " + k)); - assertEquals(0, cache.estimatedSize()); + Assert.assertEquals(0, cache.estimatedSize()); cache.get("A"); - assertEquals(1, cache.estimatedSize()); + Assert.assertEquals(1, cache.estimatedSize()); cache.get("B"); cache.cleanUp(); - assertEquals(1, cache.estimatedSize()); + Assert.assertEquals(1, cache.estimatedSize()); } @Test public void givenLoadingCacheWithWeigher_whenPut_thenSizeIsConstant() { LoadingCache cache = Caffeine.newBuilder().maximumWeight(10).weigher((k, v) -> 5).build(k -> DataObject.get("Data for " + k)); - assertEquals(0, cache.estimatedSize()); + Assert.assertEquals(0, cache.estimatedSize()); cache.get("A"); - assertEquals(1, cache.estimatedSize()); + Assert.assertEquals(1, cache.estimatedSize()); cache.get("B"); - assertEquals(2, cache.estimatedSize()); + Assert.assertEquals(2, cache.estimatedSize()); cache.get("C"); cache.cleanUp(); - assertEquals(2, cache.estimatedSize()); + Assert.assertEquals(2, cache.estimatedSize()); } @Test @@ -138,7 +139,7 @@ public class CaffeineUnitTest { cache.get("A"); cache.get("A"); - assertEquals(1, cache.stats().hitCount()); - assertEquals(1, cache.stats().missCount()); + Assert.assertEquals(1, cache.stats().hitCount()); + Assert.assertEquals(1, cache.stats().missCount()); } } \ No newline at end of file diff --git a/libraries/src/test/java/com/baeldung/dockerapi/ContainerLiveTest.java b/libraries-5/src/test/java/com/baeldung/dockerapi/ContainerLiveTest.java similarity index 94% rename from libraries/src/test/java/com/baeldung/dockerapi/ContainerLiveTest.java rename to libraries-5/src/test/java/com/baeldung/dockerapi/ContainerLiveTest.java index e6f0fd1c31..007c70355a 100644 --- a/libraries/src/test/java/com/baeldung/dockerapi/ContainerLiveTest.java +++ b/libraries-5/src/test/java/com/baeldung/dockerapi/ContainerLiveTest.java @@ -6,6 +6,8 @@ import com.github.dockerjava.api.command.InspectContainerResponse; import com.github.dockerjava.api.model.Container; import com.github.dockerjava.api.model.PortBinding; import com.github.dockerjava.core.DockerClientBuilder; +import org.hamcrest.MatcherAssert; +import org.hamcrest.core.Is; import org.junit.BeforeClass; import org.junit.Test; @@ -51,7 +53,7 @@ public class ContainerLiveTest { CreateContainerResponse container = dockerClient.createContainerCmd("mongo:3.6").withCmd("--bind_ip_all").withName("mongo").withHostName("baeldung").withEnv("MONGO_LATEST_VERSION=3.6").withPortBindings(PortBinding.parse("9999:27017")).exec(); // then - assertThat(container.getId(), is(not(null))); + MatcherAssert.assertThat(container.getId(), is(not(null))); } @Test @@ -104,7 +106,7 @@ public class ContainerLiveTest { // then InspectContainerResponse containerResponse = dockerClient.inspectContainerCmd(container.getId()).exec(); - assertThat(containerResponse.getId(), is(container.getId())); + MatcherAssert.assertThat(containerResponse.getId(), Is.is(container.getId())); } @Test diff --git a/libraries/src/test/java/com/baeldung/dockerapi/DockerClientLiveTest.java b/libraries-5/src/test/java/com/baeldung/dockerapi/DockerClientLiveTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/dockerapi/DockerClientLiveTest.java rename to libraries-5/src/test/java/com/baeldung/dockerapi/DockerClientLiveTest.java diff --git a/libraries/src/test/java/com/baeldung/dockerapi/ImageLiveTest.java b/libraries-5/src/test/java/com/baeldung/dockerapi/ImageLiveTest.java similarity index 96% rename from libraries/src/test/java/com/baeldung/dockerapi/ImageLiveTest.java rename to libraries-5/src/test/java/com/baeldung/dockerapi/ImageLiveTest.java index 7e8cd6a354..96e7922f2a 100644 --- a/libraries/src/test/java/com/baeldung/dockerapi/ImageLiveTest.java +++ b/libraries-5/src/test/java/com/baeldung/dockerapi/ImageLiveTest.java @@ -8,6 +8,8 @@ import com.github.dockerjava.core.DockerClientBuilder; import com.github.dockerjava.core.command.BuildImageResultCallback; import com.github.dockerjava.core.command.PullImageResultCallback; import com.github.dockerjava.core.command.PushImageResultCallback; +import org.hamcrest.MatcherAssert; +import org.hamcrest.core.Is; import org.junit.BeforeClass; import org.junit.Test; @@ -81,7 +83,7 @@ public class ImageLiveTest { InspectImageResponse imageResponse = dockerClient.inspectImageCmd(image.getId()).exec(); // then - assertThat(imageResponse.getId(), is(image.getId())); + MatcherAssert.assertThat(imageResponse.getId(), Is.is(image.getId())); } @Test diff --git a/libraries/src/test/java/com/baeldung/dockerapi/NetworkLiveTest.java b/libraries-5/src/test/java/com/baeldung/dockerapi/NetworkLiveTest.java similarity index 95% rename from libraries/src/test/java/com/baeldung/dockerapi/NetworkLiveTest.java rename to libraries-5/src/test/java/com/baeldung/dockerapi/NetworkLiveTest.java index d3abbe2e7e..31ad32c7b5 100644 --- a/libraries/src/test/java/com/baeldung/dockerapi/NetworkLiveTest.java +++ b/libraries-5/src/test/java/com/baeldung/dockerapi/NetworkLiveTest.java @@ -5,6 +5,7 @@ import com.github.dockerjava.api.command.CreateNetworkResponse; import com.github.dockerjava.api.model.Network; import com.github.dockerjava.api.model.Network.Ipam; import com.github.dockerjava.core.DockerClientBuilder; +import org.hamcrest.MatcherAssert; import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; @@ -64,7 +65,7 @@ public class NetworkLiveTest { Network network = dockerClient.inspectNetworkCmd().withNetworkId(networkName).exec(); // then - assertThat(network.getName(), is(networkName)); + MatcherAssert.assertThat(network.getName(), is(networkName)); } @Test diff --git a/libraries/src/test/java/com/baeldung/dockerapi/VolumeLiveTest.java b/libraries-5/src/test/java/com/baeldung/dockerapi/VolumeLiveTest.java similarity index 92% rename from libraries/src/test/java/com/baeldung/dockerapi/VolumeLiveTest.java rename to libraries-5/src/test/java/com/baeldung/dockerapi/VolumeLiveTest.java index 9e60a76b33..f2a078b2c6 100644 --- a/libraries/src/test/java/com/baeldung/dockerapi/VolumeLiveTest.java +++ b/libraries-5/src/test/java/com/baeldung/dockerapi/VolumeLiveTest.java @@ -5,6 +5,7 @@ import com.github.dockerjava.api.command.CreateVolumeResponse; import com.github.dockerjava.api.command.InspectVolumeResponse; import com.github.dockerjava.api.command.ListVolumesResponse; import com.github.dockerjava.core.DockerClientBuilder; +import org.hamcrest.MatcherAssert; import org.junit.BeforeClass; import org.junit.Test; @@ -57,7 +58,7 @@ public class VolumeLiveTest { CreateVolumeResponse unnamedVolume = dockerClient.createVolumeCmd().exec(); // then - assertThat(unnamedVolume.getName(), is(not(null))); + MatcherAssert.assertThat(unnamedVolume.getName(), is(not(null))); } @Test @@ -67,7 +68,7 @@ public class VolumeLiveTest { CreateVolumeResponse namedVolume = dockerClient.createVolumeCmd().withName("myNamedVolume").exec(); // then - assertThat(namedVolume.getName(), is(not(null))); + MatcherAssert.assertThat(namedVolume.getName(), is(not(null))); } @Test diff --git a/libraries/src/test/java/com/baeldung/atlassian/fugue/FugueUnitTest.java b/libraries-5/src/test/java/com/baeldung/fugue/FugueUnitTest.java similarity index 99% rename from libraries/src/test/java/com/baeldung/atlassian/fugue/FugueUnitTest.java rename to libraries-5/src/test/java/com/baeldung/fugue/FugueUnitTest.java index 773e39b76a..c3a89a1355 100644 --- a/libraries/src/test/java/com/baeldung/atlassian/fugue/FugueUnitTest.java +++ b/libraries-5/src/test/java/com/baeldung/fugue/FugueUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.atlassian.fugue; +package com.baeldung.fugue; import io.atlassian.fugue.*; import org.junit.Assert; diff --git a/libraries/src/test/java/com/baeldung/jctools/JCToolsUnitTest.java b/libraries-5/src/test/java/com/baeldung/jctools/JCToolsUnitTest.java similarity index 88% rename from libraries/src/test/java/com/baeldung/jctools/JCToolsUnitTest.java rename to libraries-5/src/test/java/com/baeldung/jctools/JCToolsUnitTest.java index 4a9d0fadb2..a5dacdbdac 100644 --- a/libraries/src/test/java/com/baeldung/jctools/JCToolsUnitTest.java +++ b/libraries-5/src/test/java/com/baeldung/jctools/JCToolsUnitTest.java @@ -1,5 +1,6 @@ package com.baeldung.jctools; +import org.assertj.core.api.Assertions; import org.jctools.queues.SpscArrayQueue; import org.jctools.queues.SpscChunkedArrayQueue; import org.junit.Test; @@ -44,16 +45,16 @@ public class JCToolsUnitTest { @Test public void whenQueueIsFull_thenNoMoreElementsCanBeAdded() throws InterruptedException { SpscChunkedArrayQueue queue = new SpscChunkedArrayQueue<>(8, 16); - assertThat(queue.capacity()).isEqualTo(16); + Assertions.assertThat(queue.capacity()).isEqualTo(16); CountDownLatch startConsuming = new CountDownLatch(1); CountDownLatch awakeProducer = new CountDownLatch(1); AtomicReference error = new AtomicReference<>(); Thread producer = new Thread(() -> { IntStream.range(0, queue.capacity()).forEach(i -> { - assertThat(queue.offer(i)).isTrue(); + Assertions.assertThat(queue.offer(i)).isTrue(); }); - assertThat(queue.offer(queue.capacity())).isFalse(); + Assertions.assertThat(queue.offer(queue.capacity())).isFalse(); startConsuming.countDown(); try { awakeProducer.await(); @@ -61,7 +62,7 @@ public class JCToolsUnitTest { throw new RuntimeException(e); } - assertThat(queue.offer(queue.capacity())).isTrue(); + Assertions.assertThat(queue.offer(queue.capacity())).isTrue(); }); producer.setUncaughtExceptionHandler((t, e) -> { error.set(e); diff --git a/libraries/src/test/java/com/baeldung/jnats/NatsClientLiveTest.java b/libraries-5/src/test/java/com/baeldung/jnats/NatsClientLiveTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/jnats/NatsClientLiveTest.java rename to libraries-5/src/test/java/com/baeldung/jnats/NatsClientLiveTest.java diff --git a/libraries/src/test/java/com/baeldung/jool/JOOLUnitTest.java b/libraries-5/src/test/java/com/baeldung/jool/JOOLUnitTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/jool/JOOLUnitTest.java rename to libraries-5/src/test/java/com/baeldung/jool/JOOLUnitTest.java diff --git a/libraries/src/test/java/com/baeldung/pact/PactConsumerDrivenContractUnitTest.java b/libraries-5/src/test/java/com/baeldung/pact/PactConsumerDrivenContractUnitTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/pact/PactConsumerDrivenContractUnitTest.java rename to libraries-5/src/test/java/com/baeldung/pact/PactConsumerDrivenContractUnitTest.java diff --git a/libraries/src/test/java/com/baeldung/stream/StreamExMergeStreamsUnitTest.java b/libraries-5/src/test/java/com/baeldung/streamex/StreamExMergeStreamsUnitTest.java similarity index 98% rename from libraries/src/test/java/com/baeldung/stream/StreamExMergeStreamsUnitTest.java rename to libraries-5/src/test/java/com/baeldung/streamex/StreamExMergeStreamsUnitTest.java index 220348bf36..b267eaea9b 100644 --- a/libraries/src/test/java/com/baeldung/stream/StreamExMergeStreamsUnitTest.java +++ b/libraries-5/src/test/java/com/baeldung/streamex/StreamExMergeStreamsUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.stream; +package com.baeldung.streamex; import one.util.streamex.StreamEx; import org.junit.Test; diff --git a/libraries/src/test/resources/dockerapi/Dockerfile b/libraries-5/src/test/resources/dockerapi/Dockerfile similarity index 100% rename from libraries/src/test/resources/dockerapi/Dockerfile rename to libraries-5/src/test/resources/dockerapi/Dockerfile diff --git a/libraries-6/README.md b/libraries-6/README.md new file mode 100644 index 0000000000..79bb83113e --- /dev/null +++ b/libraries-6/README.md @@ -0,0 +1,17 @@ +## Libraries-6 + +This module contains articles about various Java libraries. +These are small libraries that are relatively easy to use and do not require any separate module of their own. + +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 +- [Introduction to JavaPoet](https://www.baeldung.com/java-poet) +- [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) +- [A Guide to the Reflections Library](https://www.baeldung.com/reflections-library) +- [Exactly Once Processing in Kafka](https://www.baeldung.com/kafka-exactly-once) +- More articles [[<-- prev]](/libraries-5) diff --git a/libraries-6/pom.xml b/libraries-6/pom.xml index be74ff9ef0..030e5aa77b 100644 --- a/libraries-6/pom.xml +++ b/libraries-6/pom.xml @@ -11,5 +11,101 @@ libraries-6 + + + org.functionaljava + functionaljava-java8 + ${functionaljava.version} + + + com.codepoetics + protonpack + ${protonpack.version} + + + org.apache.kafka + kafka-streams + ${kafka.version} + + + org.apache.kafka + kafka-clients + ${kafka.version} + test + test + + + io.github.resilience4j + resilience4j-circuitbreaker + ${resilience4j.version} + + + io.github.resilience4j + resilience4j-bulkhead + ${resilience4j.version} + + + io.github.resilience4j + resilience4j-retry + ${resilience4j.version} + + + io.github.resilience4j + resilience4j-timelimiter + ${resilience4j.version} + + + com.squareup + javapoet + ${javapoet.version} + + + org.mockftpserver + MockFtpServer + ${mockftpserver.version} + test + + + + org.reflections + reflections + ${reflections.version} + + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + commons-net + commons-net + ${commons-net.version} + + + org.assertj + assertj-core + ${assertj.version} + + + commons-io + commons-io + ${commonsio.version} + test + + + + + 2.0.0 + 1.10.0 + 0.9.11 + 2.7.1 + 4.8.1 + 0.12.1 + 1.15 + 3.6 + 3.6.2 + 2.6 + + \ No newline at end of file diff --git a/libraries/src/main/java/com/baeldung/fj/FunctionalJavaIOMain.java b/libraries-6/src/main/java/com/baeldung/fj/FunctionalJavaIOMain.java similarity index 96% rename from libraries/src/main/java/com/baeldung/fj/FunctionalJavaIOMain.java rename to libraries-6/src/main/java/com/baeldung/fj/FunctionalJavaIOMain.java index eaa201d1ba..e97f128b30 100644 --- a/libraries/src/main/java/com/baeldung/fj/FunctionalJavaIOMain.java +++ b/libraries-6/src/main/java/com/baeldung/fj/FunctionalJavaIOMain.java @@ -1,43 +1,43 @@ -package com.baeldung.fj; - -import fj.F; -import fj.F1Functions; -import fj.Unit; -import fj.data.IO; -import fj.data.IOFunctions; - -public class FunctionalJavaIOMain { - - public static IO printLetters(final String s) { - return () -> { - for (int i = 0; i < s.length(); i++) { - System.out.println(s.charAt(i)); - } - return Unit.unit(); - }; - } - - public static void main(String[] args) { - - F> printLetters = i -> printLetters(i); - - IO lowerCase = IOFunctions.stdoutPrintln("What's your first Name ?"); - - IO input = IOFunctions.stdoutPrint("First Name: "); - - IO userInput = IOFunctions.append(lowerCase, input); - - IO readInput = IOFunctions.stdinReadLine(); - - F toUpperCase = i -> i.toUpperCase(); - - F> transformInput = F1Functions., String> o(printLetters).f(toUpperCase); - - IO readAndPrintResult = IOFunctions.bind(readInput, transformInput); - - IO program = IOFunctions.bind(userInput, nothing -> readAndPrintResult); - - IOFunctions.toSafe(program).run(); - - } -} +package com.baeldung.fj; + +import fj.F; +import fj.F1Functions; +import fj.Unit; +import fj.data.IO; +import fj.data.IOFunctions; + +public class FunctionalJavaIOMain { + + public static IO printLetters(final String s) { + return () -> { + for (int i = 0; i < s.length(); i++) { + System.out.println(s.charAt(i)); + } + return Unit.unit(); + }; + } + + public static void main(String[] args) { + + F> printLetters = i -> printLetters(i); + + IO lowerCase = IOFunctions.stdoutPrintln("What's your first Name ?"); + + IO input = IOFunctions.stdoutPrint("First Name: "); + + IO userInput = IOFunctions.append(lowerCase, input); + + IO readInput = IOFunctions.stdinReadLine(); + + F toUpperCase = i -> i.toUpperCase(); + + F> transformInput = F1Functions., String> o(printLetters).f(toUpperCase); + + IO readAndPrintResult = IOFunctions.bind(readInput, transformInput); + + IO program = IOFunctions.bind(userInput, nothing -> readAndPrintResult); + + IOFunctions.toSafe(program).run(); + + } +} diff --git a/libraries/src/main/java/com/baeldung/fj/FunctionalJavaMain.java b/libraries-6/src/main/java/com/baeldung/fj/FunctionalJavaMain.java similarity index 96% rename from libraries/src/main/java/com/baeldung/fj/FunctionalJavaMain.java rename to libraries-6/src/main/java/com/baeldung/fj/FunctionalJavaMain.java index c6412f2923..1a59e6c22a 100644 --- a/libraries/src/main/java/com/baeldung/fj/FunctionalJavaMain.java +++ b/libraries-6/src/main/java/com/baeldung/fj/FunctionalJavaMain.java @@ -1,48 +1,48 @@ -package com.baeldung.fj; - -import fj.F; -import fj.Show; -import fj.data.Array; -import fj.data.List; -import fj.data.Option; -import fj.function.Characters; -import fj.function.Integers; - -public class FunctionalJavaMain { - - public static final F isEven = i -> i % 2 == 0; - - public static void main(String[] args) { - - List fList = List.list(3, 4, 5, 6); - List evenList = fList.map(isEven); - Show.listShow(Show.booleanShow).println(evenList); - - fList = fList.map(i -> i + 1); - Show.listShow(Show.intShow).println(fList); - - Array a = Array.array(17, 44, 67, 2, 22, 80, 1, 27); - Array b = a.filter(Integers.even); - Show.arrayShow(Show.intShow).println(b); - - Array array = Array.array("Welcome", "To", "baeldung"); - Boolean isExist = array.exists(s -> List.fromString(s).forall(Characters.isLowerCase)); - System.out.println(isExist); - - Array intArray = Array.array(17, 44, 67, 2, 22, 80, 1, 27); - int sum = intArray.foldLeft(Integers.add, 0); - System.out.println(sum); - - Option n1 = Option.some(1); - Option n2 = Option.some(2); - - F> f1 = i -> i % 2 == 0 ? Option.some(i + 100) : Option.none(); - - Option result1 = n1.bind(f1); - Option result2 = n2.bind(f1); - - Show.optionShow(Show.intShow).println(result1); - Show.optionShow(Show.intShow).println(result2); - } - -} +package com.baeldung.fj; + +import fj.F; +import fj.Show; +import fj.data.Array; +import fj.data.List; +import fj.data.Option; +import fj.function.Characters; +import fj.function.Integers; + +public class FunctionalJavaMain { + + public static final F isEven = i -> i % 2 == 0; + + public static void main(String[] args) { + + List fList = List.list(3, 4, 5, 6); + List evenList = fList.map(isEven); + Show.listShow(Show.booleanShow).println(evenList); + + fList = fList.map(i -> i + 1); + Show.listShow(Show.intShow).println(fList); + + Array a = Array.array(17, 44, 67, 2, 22, 80, 1, 27); + Array b = a.filter(Integers.even); + Show.arrayShow(Show.intShow).println(b); + + Array array = Array.array("Welcome", "To", "baeldung"); + Boolean isExist = array.exists(s -> List.fromString(s).forall(Characters.isLowerCase)); + System.out.println(isExist); + + Array intArray = Array.array(17, 44, 67, 2, 22, 80, 1, 27); + int sum = intArray.foldLeft(Integers.add, 0); + System.out.println(sum); + + Option n1 = Option.some(1); + Option n2 = Option.some(2); + + F> f1 = i -> i % 2 == 0 ? Option.some(i + 100) : Option.none(); + + Option result1 = n1.bind(f1); + Option result2 = n2.bind(f1); + + Show.optionShow(Show.intShow).println(result1); + Show.optionShow(Show.intShow).println(result2); + } + +} diff --git a/libraries/src/main/java/com/baeldung/ftp/FtpClient.java b/libraries-6/src/main/java/com/baeldung/ftp/FtpClient.java similarity index 100% rename from libraries/src/main/java/com/baeldung/ftp/FtpClient.java rename to libraries-6/src/main/java/com/baeldung/ftp/FtpClient.java diff --git a/libraries/src/main/java/com/baeldung/javapoet/PersonGenerator.java b/libraries-6/src/main/java/com/baeldung/javapoet/PersonGenerator.java similarity index 100% rename from libraries/src/main/java/com/baeldung/javapoet/PersonGenerator.java rename to libraries-6/src/main/java/com/baeldung/javapoet/PersonGenerator.java diff --git a/libraries/src/main/java/com/baeldung/kafka/TransactionalMessageProducer.java b/libraries-6/src/main/java/com/baeldung/kafka/TransactionalMessageProducer.java similarity index 100% rename from libraries/src/main/java/com/baeldung/kafka/TransactionalMessageProducer.java rename to libraries-6/src/main/java/com/baeldung/kafka/TransactionalMessageProducer.java diff --git a/libraries/src/main/java/com/baeldung/kafka/TransactionalWordCount.java b/libraries-6/src/main/java/com/baeldung/kafka/TransactionalWordCount.java similarity index 100% rename from libraries/src/main/java/com/baeldung/kafka/TransactionalWordCount.java rename to libraries-6/src/main/java/com/baeldung/kafka/TransactionalWordCount.java diff --git a/libraries/src/main/java/com/baeldung/kafka/Tuple.java b/libraries-6/src/main/java/com/baeldung/kafka/Tuple.java similarity index 100% rename from libraries/src/main/java/com/baeldung/kafka/Tuple.java rename to libraries-6/src/main/java/com/baeldung/kafka/Tuple.java diff --git a/libraries/src/main/java/com/baeldung/reflections/ReflectionsApp.java b/libraries-6/src/main/java/com/baeldung/reflections/ReflectionsApp.java similarity index 97% rename from libraries/src/main/java/com/baeldung/reflections/ReflectionsApp.java rename to libraries-6/src/main/java/com/baeldung/reflections/ReflectionsApp.java index 30da8ea837..4f5b6dd183 100644 --- a/libraries/src/main/java/com/baeldung/reflections/ReflectionsApp.java +++ b/libraries-6/src/main/java/com/baeldung/reflections/ReflectionsApp.java @@ -1,71 +1,71 @@ -package com.baeldung.reflections; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; -import java.util.Date; -import java.util.Set; -import java.util.regex.Pattern; - -import org.reflections.Reflections; -import org.reflections.scanners.MethodAnnotationsScanner; -import org.reflections.scanners.MethodParameterScanner; -import org.reflections.scanners.ResourcesScanner; -import org.reflections.scanners.Scanner; -import org.reflections.scanners.SubTypesScanner; -import org.reflections.util.ClasspathHelper; -import org.reflections.util.ConfigurationBuilder; - -public class ReflectionsApp { - - public Set> getReflectionsSubTypes() { - Reflections reflections = new Reflections("org.reflections"); - Set> scannersSet = reflections.getSubTypesOf(Scanner.class); - return scannersSet; - } - - public Set> getJDKFunctinalInterfaces() { - Reflections reflections = new Reflections("java.util.function"); - Set> typesSet = reflections.getTypesAnnotatedWith(FunctionalInterface.class); - return typesSet; - } - - public Set getDateDeprecatedMethods() { - Reflections reflections = new Reflections(java.util.Date.class, new MethodAnnotationsScanner()); - Set deprecatedMethodsSet = reflections.getMethodsAnnotatedWith(Deprecated.class); - return deprecatedMethodsSet; - } - - @SuppressWarnings("rawtypes") - public Set getDateDeprecatedConstructors() { - Reflections reflections = new Reflections(java.util.Date.class, new MethodAnnotationsScanner()); - Set constructorsSet = reflections.getConstructorsAnnotatedWith(Deprecated.class); - return constructorsSet; - } - - public Set getMethodsWithDateParam() { - Reflections reflections = new Reflections(java.text.SimpleDateFormat.class, new MethodParameterScanner()); - Set methodsSet = reflections.getMethodsMatchParams(Date.class); - return methodsSet; - } - - public Set getMethodsWithVoidReturn() { - Reflections reflections = new Reflections(java.text.SimpleDateFormat.class, new MethodParameterScanner()); - Set methodsSet = reflections.getMethodsReturn(void.class); - return methodsSet; - } - - public Set getPomXmlPaths() { - Reflections reflections = new Reflections(new ResourcesScanner()); - Set resourcesSet = reflections.getResources(Pattern.compile(".*pom\\.xml")); - return resourcesSet; - } - - public Set> getReflectionsSubTypesUsingBuilder() { - Reflections reflections = new Reflections(new ConfigurationBuilder().setUrls(ClasspathHelper.forPackage("org.reflections")) - .setScanners(new SubTypesScanner())); - - Set> scannersSet = reflections.getSubTypesOf(Scanner.class); - return scannersSet; - } - -} +package com.baeldung.reflections; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.util.Date; +import java.util.Set; +import java.util.regex.Pattern; + +import org.reflections.Reflections; +import org.reflections.scanners.MethodAnnotationsScanner; +import org.reflections.scanners.MethodParameterScanner; +import org.reflections.scanners.ResourcesScanner; +import org.reflections.scanners.Scanner; +import org.reflections.scanners.SubTypesScanner; +import org.reflections.util.ClasspathHelper; +import org.reflections.util.ConfigurationBuilder; + +public class ReflectionsApp { + + public Set> getReflectionsSubTypes() { + Reflections reflections = new Reflections("org.reflections"); + Set> scannersSet = reflections.getSubTypesOf(Scanner.class); + return scannersSet; + } + + public Set> getJDKFunctinalInterfaces() { + Reflections reflections = new Reflections("java.util.function"); + Set> typesSet = reflections.getTypesAnnotatedWith(FunctionalInterface.class); + return typesSet; + } + + public Set getDateDeprecatedMethods() { + Reflections reflections = new Reflections(java.util.Date.class, new MethodAnnotationsScanner()); + Set deprecatedMethodsSet = reflections.getMethodsAnnotatedWith(Deprecated.class); + return deprecatedMethodsSet; + } + + @SuppressWarnings("rawtypes") + public Set getDateDeprecatedConstructors() { + Reflections reflections = new Reflections(java.util.Date.class, new MethodAnnotationsScanner()); + Set constructorsSet = reflections.getConstructorsAnnotatedWith(Deprecated.class); + return constructorsSet; + } + + public Set getMethodsWithDateParam() { + Reflections reflections = new Reflections(java.text.SimpleDateFormat.class, new MethodParameterScanner()); + Set methodsSet = reflections.getMethodsMatchParams(Date.class); + return methodsSet; + } + + public Set getMethodsWithVoidReturn() { + Reflections reflections = new Reflections(java.text.SimpleDateFormat.class, new MethodParameterScanner()); + Set methodsSet = reflections.getMethodsReturn(void.class); + return methodsSet; + } + + public Set getPomXmlPaths() { + Reflections reflections = new Reflections(new ResourcesScanner()); + Set resourcesSet = reflections.getResources(Pattern.compile(".*pom\\.xml")); + return resourcesSet; + } + + public Set> getReflectionsSubTypesUsingBuilder() { + Reflections reflections = new Reflections(new ConfigurationBuilder().setUrls(ClasspathHelper.forPackage("org.reflections")) + .setScanners(new SubTypesScanner())); + + Set> scannersSet = reflections.getSubTypesOf(Scanner.class); + return scannersSet; + } + +} diff --git a/libraries/src/test/java/com/baeldung/fj/FunctionalJavaUnitTest.java b/libraries-6/src/test/java/com/baeldung/fj/FunctionalJavaUnitTest.java similarity index 95% rename from libraries/src/test/java/com/baeldung/fj/FunctionalJavaUnitTest.java rename to libraries-6/src/test/java/com/baeldung/fj/FunctionalJavaUnitTest.java index 97ead07470..f79d334b23 100644 --- a/libraries/src/test/java/com/baeldung/fj/FunctionalJavaUnitTest.java +++ b/libraries-6/src/test/java/com/baeldung/fj/FunctionalJavaUnitTest.java @@ -4,6 +4,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import org.junit.Assert; import org.junit.Test; import fj.F; @@ -96,9 +97,9 @@ public class FunctionalJavaUnitTest { Option result2 = n2.bind(function); Option result3 = n3.bind(function); - assertEquals(Option.none(), result1); - assertEquals(Option.some(102), result2); - assertEquals(Option.none(), result3); + Assert.assertEquals(Option.none(), result1); + Assert.assertEquals(Option.some(102), result2); + Assert.assertEquals(Option.none(), result3); } @Test diff --git a/libraries/src/test/java/com/baeldung/ftp/FtpClientIntegrationTest.java b/libraries-6/src/test/java/com/baeldung/ftp/FtpClientIntegrationTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/ftp/FtpClientIntegrationTest.java rename to libraries-6/src/test/java/com/baeldung/ftp/FtpClientIntegrationTest.java diff --git a/libraries/src/test/java/com/baeldung/ftp/JdkFtpClientIntegrationTest.java b/libraries-6/src/test/java/com/baeldung/ftp/JdkFtpClientIntegrationTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/ftp/JdkFtpClientIntegrationTest.java rename to libraries-6/src/test/java/com/baeldung/ftp/JdkFtpClientIntegrationTest.java diff --git a/libraries/src/test/java/com/baeldung/javapoet/test/PersonGeneratorUnitTest.java b/libraries-6/src/test/java/com/baeldung/javapoet/test/PersonGeneratorUnitTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/javapoet/test/PersonGeneratorUnitTest.java rename to libraries-6/src/test/java/com/baeldung/javapoet/test/PersonGeneratorUnitTest.java diff --git a/libraries/src/test/java/com/baeldung/javapoet/test/person/Gender.java b/libraries-6/src/test/java/com/baeldung/javapoet/test/person/Gender.java similarity index 100% rename from libraries/src/test/java/com/baeldung/javapoet/test/person/Gender.java rename to libraries-6/src/test/java/com/baeldung/javapoet/test/person/Gender.java diff --git a/libraries/src/test/java/com/baeldung/javapoet/test/person/Person.java b/libraries-6/src/test/java/com/baeldung/javapoet/test/person/Person.java similarity index 100% rename from libraries/src/test/java/com/baeldung/javapoet/test/person/Person.java rename to libraries-6/src/test/java/com/baeldung/javapoet/test/person/Person.java diff --git a/libraries/src/test/java/com/baeldung/javapoet/test/person/Student.java b/libraries-6/src/test/java/com/baeldung/javapoet/test/person/Student.java similarity index 100% rename from libraries/src/test/java/com/baeldung/javapoet/test/person/Student.java rename to libraries-6/src/test/java/com/baeldung/javapoet/test/person/Student.java diff --git a/libraries/src/test/java/com/baeldung/kafkastreams/KafkaStreamsLiveTest.java b/libraries-6/src/test/java/com/baeldung/kafkastreams/KafkaStreamsLiveTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/kafkastreams/KafkaStreamsLiveTest.java rename to libraries-6/src/test/java/com/baeldung/kafkastreams/KafkaStreamsLiveTest.java diff --git a/libraries/src/test/java/com/baeldung/reflections/ReflectionsUnitTest.java b/libraries-6/src/test/java/com/baeldung/reflections/ReflectionsUnitTest.java similarity index 96% rename from libraries/src/test/java/com/baeldung/reflections/ReflectionsUnitTest.java rename to libraries-6/src/test/java/com/baeldung/reflections/ReflectionsUnitTest.java index 9a3ef0747b..b86094b6f4 100644 --- a/libraries/src/test/java/com/baeldung/reflections/ReflectionsUnitTest.java +++ b/libraries-6/src/test/java/com/baeldung/reflections/ReflectionsUnitTest.java @@ -1,50 +1,50 @@ -package com.baeldung.reflections; - -import static org.junit.jupiter.api.Assertions.assertFalse; - -import org.junit.jupiter.api.Test; - -public class ReflectionsUnitTest { - - @Test - public void givenTypeThenGetAllSubTypes() { - ReflectionsApp reflectionsApp = new ReflectionsApp(); - assertFalse(reflectionsApp.getReflectionsSubTypes() - .isEmpty()); - } - - @Test - public void givenTypeAndUsingBuilderThenGetAllSubTypes() { - ReflectionsApp reflectionsApp = new ReflectionsApp(); - assertFalse(reflectionsApp.getReflectionsSubTypesUsingBuilder() - .isEmpty()); - } - - @Test - public void givenAnnotationThenGetAllAnnotatedMethods() { - ReflectionsApp reflectionsApp = new ReflectionsApp(); - assertFalse(reflectionsApp.getDateDeprecatedMethods() - .isEmpty()); - } - - @Test - public void givenAnnotationThenGetAllAnnotatedConstructors() { - ReflectionsApp reflectionsApp = new ReflectionsApp(); - assertFalse(reflectionsApp.getDateDeprecatedConstructors() - .isEmpty()); - } - - @Test - public void givenParamTypeThenGetAllMethods() { - ReflectionsApp reflectionsApp = new ReflectionsApp(); - assertFalse(reflectionsApp.getMethodsWithDateParam() - .isEmpty()); - } - - @Test - public void givenReturnTypeThenGetAllMethods() { - ReflectionsApp reflectionsApp = new ReflectionsApp(); - assertFalse(reflectionsApp.getMethodsWithVoidReturn() - .isEmpty()); - } -} +package com.baeldung.reflections; + +import static org.junit.jupiter.api.Assertions.assertFalse; + +import org.junit.jupiter.api.Test; + +public class ReflectionsUnitTest { + + @Test + public void givenTypeThenGetAllSubTypes() { + ReflectionsApp reflectionsApp = new ReflectionsApp(); + assertFalse(reflectionsApp.getReflectionsSubTypes() + .isEmpty()); + } + + @Test + public void givenTypeAndUsingBuilderThenGetAllSubTypes() { + ReflectionsApp reflectionsApp = new ReflectionsApp(); + assertFalse(reflectionsApp.getReflectionsSubTypesUsingBuilder() + .isEmpty()); + } + + @Test + public void givenAnnotationThenGetAllAnnotatedMethods() { + ReflectionsApp reflectionsApp = new ReflectionsApp(); + assertFalse(reflectionsApp.getDateDeprecatedMethods() + .isEmpty()); + } + + @Test + public void givenAnnotationThenGetAllAnnotatedConstructors() { + ReflectionsApp reflectionsApp = new ReflectionsApp(); + assertFalse(reflectionsApp.getDateDeprecatedConstructors() + .isEmpty()); + } + + @Test + public void givenParamTypeThenGetAllMethods() { + ReflectionsApp reflectionsApp = new ReflectionsApp(); + assertFalse(reflectionsApp.getMethodsWithDateParam() + .isEmpty()); + } + + @Test + public void givenReturnTypeThenGetAllMethods() { + ReflectionsApp reflectionsApp = new ReflectionsApp(); + assertFalse(reflectionsApp.getMethodsWithVoidReturn() + .isEmpty()); + } +} diff --git a/libraries/src/test/java/com/baeldung/resilience4j/Resilience4jUnitTest.java b/libraries-6/src/test/java/com/baeldung/resilence4j/Resilience4jUnitTest.java similarity index 99% rename from libraries/src/test/java/com/baeldung/resilience4j/Resilience4jUnitTest.java rename to libraries-6/src/test/java/com/baeldung/resilence4j/Resilience4jUnitTest.java index ced95c99cb..1d69d20bc2 100644 --- a/libraries/src/test/java/com/baeldung/resilience4j/Resilience4jUnitTest.java +++ b/libraries-6/src/test/java/com/baeldung/resilence4j/Resilience4jUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.resilience4j; +package com.baeldung.resilence4j; import io.github.resilience4j.bulkhead.Bulkhead; import io.github.resilience4j.bulkhead.BulkheadConfig; diff --git a/libraries/src/test/resources/ftp/baz.txt b/libraries-6/src/test/resources/ftp/baz.txt similarity index 100% rename from libraries/src/test/resources/ftp/baz.txt rename to libraries-6/src/test/resources/ftp/baz.txt diff --git a/libraries/pom.xml b/libraries/pom.xml index 5d540f0d90..da9c9de907 100644 --- a/libraries/pom.xml +++ b/libraries/pom.xml @@ -12,18 +12,18 @@ - - - com.typesafe.akka - akka-actor_2.12 - ${typesafe-akka.version} - - - com.typesafe.akka - akka-testkit_2.12 - ${typesafe-akka.version} - test - + + + + + + + + + + + + org.beykery @@ -36,16 +36,16 @@ cglib ${cglib.version} - - org.apache.commons - commons-lang3 - ${commons-lang3.version} - - - commons-net - commons-net - ${commons-net.version} - + + + + + + + + + + org.javatuples @@ -64,11 +64,11 @@ ${javers.version} - - io.nats - jnats - ${jnats.version} - + + + + + @@ -228,11 +228,11 @@ jool ${jool.version} - - org.openjdk.jmh - jmh-core - ${jmh.version} - + + + + + junit junit @@ -244,18 +244,18 @@ java-lsh ${java-lsh.version} - - au.com.dius - pact-jvm-consumer-junit_2.11 - ${pact.version} - test - - - org.codehaus.groovy - groovy-all - - - + + + + + + + + + + + + @@ -274,16 +274,16 @@ ${org.hamcrest.java-hamcrest.version} test - - net.bytebuddy - byte-buddy - ${bytebuddy.version} - - - net.bytebuddy - byte-buddy-agent - ${bytebuddy.version} - + + + + + + + + + + @@ -320,43 +320,43 @@ - - com.codepoetics - protonpack - ${protonpack.version} - - - org.functionaljava - functionaljava-java8 - ${functionaljava.version} - - - com.github.ben-manes.caffeine - caffeine - ${caffeine.version} - + + + + + + + + + + + + + + + - - - com.github.docker-java - docker-java - ${docker.version} - - - org.slf4j - slf4j-log4j12 - - - org.slf4j - jcl-over-slf4j - - - ch.qos.logback - logback-classic - - - - + + + + + + + + + + + + + + + + + + + + + @@ -364,58 +364,58 @@ google-oauth-client-jetty ${google-api.version} - - org.apache.kafka - kafka-streams - ${kafka.version} - - - org.apache.kafka - kafka-clients - ${kafka.version} - test - test - + + + + + + + + + + + + - - - io.atlassian.fugue - fugue - ${fugue.version} - + + + + + + - - org.jctools - jctools-core - ${jctools.version} - + + + + + - - io.github.resilience4j - resilience4j-circuitbreaker - ${resilience4j.version} - - - io.github.resilience4j - resilience4j-bulkhead - ${resilience4j.version} - - - io.github.resilience4j - resilience4j-retry - ${resilience4j.version} - - - io.github.resilience4j - resilience4j-timelimiter - ${resilience4j.version} - - - com.squareup - javapoet - ${javapoet.version} - + + + + + + + + + + + + + + + + + + + + + + + + + org.hamcrest hamcrest-all @@ -423,18 +423,18 @@ test - - org.mockftpserver - MockFtpServer - ${mockftpserver.version} - test - - - - org.reflections - reflections - ${reflections.version} - + + + + + + + + + + + + @@ -562,7 +562,7 @@ 1.2 3.6.2 3.1.0 - 1.0 + 2.92 1.9.26 @@ -574,24 +574,24 @@ 3.5.0 2.0.0.0 - 1.7.1 + - 1.15 - 2.5.5 + + 1.23.0 - 2.0.0 - 3.0.14 + + 0.9.4.0006L - 2.1.2 - 2.5.11 - 0.12.1 - 1.10.0 + + + + 1.3 3.2.0-m7 5.1.1 @@ -603,17 +603,17 @@ 3.0.3 2.3.0 0.9.12 - 1.19 + - 4.8.1 - 4.5.1 + + 3.0.2 - 2.7.1 - 3.6 - 0.9.11 + + + From 753c0ef0d0c8ac22f35964ba55889fbf3e03d33c Mon Sep 17 00:00:00 2001 From: mikr Date: Wed, 29 Apr 2020 21:55:48 +0200 Subject: [PATCH 08/19] Java-1470 Fix compilation errors and Readme files --- libraries-2/README.md | 2 +- libraries-3/README.md | 1 + libraries-4/README.md | 2 +- libraries/README.md | 33 ----- libraries/pom.xml | 273 +++++------------------------------------- 5 files changed, 32 insertions(+), 279 deletions(-) diff --git a/libraries-2/README.md b/libraries-2/README.md index edf513c6ee..8dae12a1cf 100644 --- a/libraries-2/README.md +++ b/libraries-2/README.md @@ -18,5 +18,5 @@ Remember, for advanced libraries like [Jackson](/jackson) and [JUnit](/testing-m - [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) +- More articles [[<-- prev]](/libraries) [[next -->]](/libraries-3) diff --git a/libraries-3/README.md b/libraries-3/README.md index ec433960ef..7c30cabaf1 100644 --- a/libraries-3/README.md +++ b/libraries-3/README.md @@ -17,3 +17,4 @@ Remember, for advanced libraries like [Jackson](/jackson) and [JUnit](/testing-m - [Using NullAway to Avoid NullPointerExceptions](https://www.baeldung.com/java-nullaway) - [Introduction to Alibaba Arthas](https://www.baeldung.com/java-alibaba-arthas-intro) - [Quick Guide to Spring Cloud Circuit Breaker](https://www.baeldung.com/spring-cloud-circuit-breaker) +- More articles [[<-- prev]](/libraries-2) [[next -->]](/libraries-4) \ No newline at end of file diff --git a/libraries-4/README.md b/libraries-4/README.md index 9cda07bdf5..0dee9f1c1e 100644 --- a/libraries-4/README.md +++ b/libraries-4/README.md @@ -18,4 +18,4 @@ Remember, for advanced libraries like [Jackson](/jackson) and [JUnit](/testing-m - [Guide to JDeferred](https://www.baeldung.com/jdeferred) - [Introduction to MBassador](https://www.baeldung.com/mbassador) - [Using Pairs in Java](https://www.baeldung.com/java-pairs) -- More articles [[next -->]](/libraries-2) +- More articles [[<-- prev]](/libraries-3) [[next -->]](/libraries-5) diff --git a/libraries/README.md b/libraries/README.md index 3f259e4222..b61289504c 100644 --- a/libraries/README.md +++ b/libraries/README.md @@ -19,37 +19,4 @@ Remember, for advanced libraries like [Jackson](/jackson) and [JUnit](/testing-m - [Software Transactional Memory in Java Using Multiverse](https://www.baeldung.com/java-multiverse-stm) - [Locality-Sensitive Hashing in Java Using Java-LSH](https://www.baeldung.com/locality-sensitive-hashing) - [Introduction to Neuroph](https://www.baeldung.com/neuroph) - -#4 -- [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) -- [Using Pairs in Java](https://www.baeldung.com/java-pairs) - -#5 -- [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) -- [Publish and Receive Messages with Nats Java Client](https://www.baeldung.com/nats-java-client) -- [Java Concurrency Utility with JCTools](https://www.baeldung.com/java-concurrency-jc-tools) - -#6 -- [Introduction to JavaPoet](https://www.baeldung.com/java-poet) -- [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) -- [A Guide to the Reflections Library](https://www.baeldung.com/reflections-library) - -- [Exactly Once Processing in Kafka](https://www.baeldung.com/kafka-exactly-once) - More articles [[next -->]](/libraries-2) diff --git a/libraries/pom.xml b/libraries/pom.xml index da9c9de907..fee66f928d 100644 --- a/libraries/pom.xml +++ b/libraries/pom.xml @@ -12,18 +12,6 @@ - - - - - - - - - - - - org.beykery @@ -36,16 +24,16 @@ cglib ${cglib.version} - - - - - - - - - - + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + commons-net + commons-net + ${commons-net.version} + org.javatuples @@ -63,18 +51,6 @@ javers-core ${javers.version} - - - - - - - - - - - - net.serenity-bdd serenity-core @@ -218,21 +194,16 @@ quartz ${quartz.version} - - - - - org.jooq jool ${jool.version} - - - - - + + org.openjdk.jmh + jmh-core + ${jmh.version} + junit junit @@ -244,119 +215,23 @@ java-lsh ${java-lsh.version} - - - - - - - - - - - - - - - - - - - - - - - - + + commons-io + commons-io + ${commonsio.version} + org.hamcrest java-hamcrest ${org.hamcrest.java-hamcrest.version} test - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + com.codepoetics + protonpack + ${protonpack.version} + @@ -364,77 +239,12 @@ google-oauth-client-jetty ${google-api.version} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - org.hamcrest hamcrest-all ${hamcrest-all.version} test - - - - - - - - - - - - - @@ -562,8 +372,6 @@ 1.2 3.6.2 3.1.0 - - 2.92 1.9.26 1.41.0 @@ -572,26 +380,10 @@ 1.1.0 0.10 3.5.0 - 2.0.0.0 - - - - - - - - - + 1.15 1.23.0 - - - 0.9.4.0006L - - - - 1.3 3.2.0-m7 5.1.1 @@ -603,17 +395,10 @@ 3.0.3 2.3.0 0.9.12 - - - - - - - + 1.19 3.0.2 - - - + 3.6 + 2.6 From 4552da7ba7126e190234553d39e77444f63785ff Mon Sep 17 00:00:00 2001 From: mikr Date: Wed, 29 Apr 2020 22:02:31 +0200 Subject: [PATCH 09/19] Java-1470 Add new modules to main pom --- pom.xml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index d481f95042..ed4b3e5b30 100644 --- a/pom.xml +++ b/pom.xml @@ -497,6 +497,9 @@ libraries-2 libraries-3 + libraries-4 + libraries-5 + libraries-6 libraries-apache-commons libraries-apache-commons-collections libraries-apache-commons-io @@ -1012,8 +1015,8 @@ libraries-2 libraries-3 libraries-4 - - + libraries-5 + libraries-6 libraries-apache-commons libraries-apache-commons-collections From b5159c71cb937b8f41ec51761953e327111c4865 Mon Sep 17 00:00:00 2001 From: mikr Date: Thu, 30 Apr 2020 16:17:05 +0200 Subject: [PATCH 10/19] Java-1470 Fix failing integration tests --- libraries-4/pom.xml | 5 +++++ libraries-5/pom.xml | 7 ++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/libraries-4/pom.xml b/libraries-4/pom.xml index 1b2db27861..f26e7fc055 100644 --- a/libraries-4/pom.xml +++ b/libraries-4/pom.xml @@ -88,6 +88,11 @@ javax.el-api ${javax.el.version} + + org.glassfish.web + javax.el + 2.2.4 + diff --git a/libraries-5/pom.xml b/libraries-5/pom.xml index 41c92e54c3..63296d4a89 100644 --- a/libraries-5/pom.xml +++ b/libraries-5/pom.xml @@ -43,12 +43,12 @@ com.typesafe.akka - akka-actor_2.12 + akka-actor_${scala.version} ${typesafe-akka.version} com.typesafe.akka - akka-testkit_2.12 + akka-testkit_${scala.version} ${typesafe-akka.version} test @@ -130,7 +130,8 @@ 0.9.12 4.3.8.RELEASE 3.6.2 - 2.5.26 + 2.11 + 2.5.11 0.6.5 1.7.1 3.0.14 From 52df2121273352051f1e620c57a78cf7f1905224 Mon Sep 17 00:00:00 2001 From: mikr Date: Fri, 1 May 2020 21:34:10 +0200 Subject: [PATCH 11/19] Java-1470 Move libraries-4/5/6 to different profile --- pom.xml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index ed4b3e5b30..171c652994 100644 --- a/pom.xml +++ b/pom.xml @@ -497,9 +497,6 @@ libraries-2 libraries-3 - libraries-4 - libraries-5 - libraries-6 libraries-apache-commons libraries-apache-commons-collections libraries-apache-commons-io @@ -814,6 +811,9 @@ jws libraries + libraries-4 + libraries-5 + libraries-6 vaadin vavr @@ -1014,9 +1014,6 @@ libraries-2 libraries-3 - libraries-4 - libraries-5 - libraries-6 libraries-apache-commons libraries-apache-commons-collections @@ -1317,6 +1314,9 @@ jws libraries + libraries-4 + libraries-5 + libraries-6 vaadin vavr From 714d60351b93e1dac87065e88e8c27dc93075217 Mon Sep 17 00:00:00 2001 From: Kirill Vlasov Date: Tue, 5 May 2020 11:44:30 +0500 Subject: [PATCH 12/19] Replacing postgres database with h2 for integration test --- .../resources/customlogouthandler/application.properties | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/test/resources/customlogouthandler/application.properties b/spring-security-modules/spring-security-mvc-boot-2/src/test/resources/customlogouthandler/application.properties index 9edd853f2c..84347c2664 100644 --- a/spring-security-modules/spring-security-mvc-boot-2/src/test/resources/customlogouthandler/application.properties +++ b/spring-security-modules/spring-security-mvc-boot-2/src/test/resources/customlogouthandler/application.properties @@ -1,5 +1,4 @@ -spring.datasource.url=jdbc:postgresql://localhost:5432/test +spring.datasource.driver-class-name=org.h2.Driver +spring.datasource.url=jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE spring.datasource.username=test -spring.datasource.password=test - -spring.jpa.hibernate.ddl-auto=create +spring.datasource.password=test \ No newline at end of file From 0cad7c5cc584059d15901f9270214e07dc533294 Mon Sep 17 00:00:00 2001 From: Eduard Ardeleanu Date: Tue, 5 May 2020 10:37:20 +0300 Subject: [PATCH 13/19] BAEL-3971: Generate DDL script in Spring (#9120) * BAEL-3971: Generate DDL script in Spring * BAEL-3971: implement review comments * BAEL-3971: fix typo * BAEL-3971: move code examples to module spring-data-jpa-5 Co-authored-by: ashleyfrieze --- persistence-modules/pom.xml | 1 + .../spring-data-jpa-5/README.md | 2 + persistence-modules/spring-data-jpa-5/pom.xml | 2 +- .../schemageneration/AccountApplication.java | 12 +++ .../schemageneration/HibernateUtil.java | 39 ++++++++++ .../schemageneration/model/Account.java | 74 +++++++++++++++++++ .../model/AccountSetting.java | 68 +++++++++++++++++ .../repository/AccountRepository.java | 8 ++ .../repository/AccountSettingRepository.java | 8 ++ .../src/main/resources/application.properties | 11 +++ .../AccountRepositoryIntegrationTest.java | 72 ++++++++++++++++++ .../resources/application-test.properties | 2 + 12 files changed, 298 insertions(+), 1 deletion(-) create mode 100644 persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/AccountApplication.java create mode 100644 persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/HibernateUtil.java create mode 100644 persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/model/Account.java create mode 100644 persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/model/AccountSetting.java create mode 100644 persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/repository/AccountRepository.java create mode 100644 persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/repository/AccountSettingRepository.java create mode 100644 persistence-modules/spring-data-jpa-5/src/test/java/com/baeldung/schemageneration/AccountRepositoryIntegrationTest.java diff --git a/persistence-modules/pom.xml b/persistence-modules/pom.xml index ec7f0bcec2..78da896861 100644 --- a/persistence-modules/pom.xml +++ b/persistence-modules/pom.xml @@ -61,6 +61,7 @@ spring-data-jpa-2 spring-data-jpa-3 spring-data-jpa-4 + spring-data-jpa-5 spring-data-keyvalue spring-data-mongodb spring-data-neo4j diff --git a/persistence-modules/spring-data-jpa-5/README.md b/persistence-modules/spring-data-jpa-5/README.md index dd4ac22e4a..e8f83654df 100644 --- a/persistence-modules/spring-data-jpa-5/README.md +++ b/persistence-modules/spring-data-jpa-5/README.md @@ -1,4 +1,5 @@ ### Relevant Articles: + - [Spring JPA @Embedded and @EmbeddedId](TBD) ### Eclipse Config @@ -9,3 +10,4 @@ This can be ignored: - Project -> Properties -> Java Persistance -> JPA -> Error/Warnings -> Select Ignore on "No persistence xml file found in project" Or: - Eclipse -> Preferences - Validation - disable the "Build" execution of the JPA Validator + diff --git a/persistence-modules/spring-data-jpa-5/pom.xml b/persistence-modules/spring-data-jpa-5/pom.xml index 7f2c724f98..3053384559 100644 --- a/persistence-modules/spring-data-jpa-5/pom.xml +++ b/persistence-modules/spring-data-jpa-5/pom.xml @@ -33,5 +33,5 @@ h2 - + diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/AccountApplication.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/AccountApplication.java new file mode 100644 index 0000000000..547992a6c1 --- /dev/null +++ b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/AccountApplication.java @@ -0,0 +1,12 @@ +package com.baeldung.schemageneration; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class AccountApplication { + + public static void main(String[] args) { + SpringApplication.run(AccountApplication.class, args); + } +} diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/HibernateUtil.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/HibernateUtil.java new file mode 100644 index 0000000000..7d69d65705 --- /dev/null +++ b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/HibernateUtil.java @@ -0,0 +1,39 @@ +package com.baeldung.schemageneration; + +import com.baeldung.schemageneration.model.Account; +import com.baeldung.schemageneration.model.AccountSetting; +import org.hibernate.boot.Metadata; +import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.StandardServiceRegistry; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.cfg.Environment; +import org.hibernate.tool.hbm2ddl.SchemaExport; +import org.hibernate.tool.schema.TargetType; + +import java.util.EnumSet; +import java.util.HashMap; +import java.util.Map; + +public class HibernateUtil { + + /** + * Generates database create commands for the specified entities using Hibernate native API, SchemaExport. + * Creation commands are exported into the create.sql file. + */ + public static void generateSchema() { + Map settings = new HashMap<>(); + settings.put(Environment.URL, "jdbc:h2:mem:schema"); + + StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(settings).build(); + + MetadataSources metadataSources = new MetadataSources(serviceRegistry); + metadataSources.addAnnotatedClass(Account.class); + metadataSources.addAnnotatedClass(AccountSetting.class); + Metadata metadata = metadataSources.buildMetadata(); + + SchemaExport schemaExport = new SchemaExport(); + schemaExport.setFormat(true); + schemaExport.setOutputFile("create.sql"); + schemaExport.createOnly(EnumSet.of(TargetType.SCRIPT), metadata); + } +} diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/model/Account.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/model/Account.java new file mode 100644 index 0000000000..785e275e26 --- /dev/null +++ b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/model/Account.java @@ -0,0 +1,74 @@ +package com.baeldung.schemageneration.model; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import java.util.ArrayList; +import java.util.List; + +@Entity +@Table(name = "accounts") +public class Account { + + @Id + @GeneratedValue + private Long id; + + @Column(nullable = false, length = 100) + private String name; + + @Column(name = "email_address") + private String emailAddress; + + @OneToMany(mappedBy = "account", cascade = CascadeType.ALL) + private List accountSettings = new ArrayList<>(); + + public Account() { + } + + public Account(String name, String emailAddress) { + this.name = name; + this.emailAddress = emailAddress; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getEmailAddress() { + return emailAddress; + } + + public void setEmailAddress(String emailAddress) { + this.emailAddress = emailAddress; + } + + public List getAccountSettings() { + return accountSettings; + } + + public void setAccountSettings(List accountSettings) { + this.accountSettings = accountSettings; + } + + public void addAccountSetting(AccountSetting setting) { + this.accountSettings.add(setting); + setting.setAccount(this); + } +} diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/model/AccountSetting.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/model/AccountSetting.java new file mode 100644 index 0000000000..61e43894a8 --- /dev/null +++ b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/model/AccountSetting.java @@ -0,0 +1,68 @@ +package com.baeldung.schemageneration.model; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +@Entity +@Table(name = "account_settings") +public class AccountSetting { + + @Id + @GeneratedValue + private Long id; + + @Column(name = "name", nullable = false) + private String settingName; + + @Column(name = "value", nullable = false) + private String settingValue; + + @ManyToOne() + @JoinColumn(name ="account_id", nullable = false) + private Account account; + + public AccountSetting() { + } + + public AccountSetting(String settingName, String settingValue) { + this.settingName = settingName; + this.settingValue = settingValue; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getSettingName() { + return settingName; + } + + public void setSettingName(String settingName) { + this.settingName = settingName; + } + + public String getSettingValue() { + return settingValue; + } + + public void setSettingValue(String settingValue) { + this.settingValue = settingValue; + } + + public Account getAccount() { + return account; + } + + public void setAccount(Account account) { + this.account = account; + } +} diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/repository/AccountRepository.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/repository/AccountRepository.java new file mode 100644 index 0000000000..dc57ffe6d3 --- /dev/null +++ b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/repository/AccountRepository.java @@ -0,0 +1,8 @@ +package com.baeldung.schemageneration.repository; + +import com.baeldung.schemageneration.model.Account; +import org.springframework.data.repository.CrudRepository; + +public interface AccountRepository extends CrudRepository { + Account findByName(String name); +} diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/repository/AccountSettingRepository.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/repository/AccountSettingRepository.java new file mode 100644 index 0000000000..c2b8ff7398 --- /dev/null +++ b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/repository/AccountSettingRepository.java @@ -0,0 +1,8 @@ +package com.baeldung.schemageneration.repository; + +import com.baeldung.schemageneration.model.AccountSetting; +import org.springframework.data.repository.CrudRepository; + +public interface AccountSettingRepository extends CrudRepository { + AccountSetting findByAccountId(Long accountId); +} diff --git a/persistence-modules/spring-data-jpa-5/src/main/resources/application.properties b/persistence-modules/spring-data-jpa-5/src/main/resources/application.properties index dfc5e56e33..f55ad438ff 100644 --- a/persistence-modules/spring-data-jpa-5/src/main/resources/application.properties +++ b/persistence-modules/spring-data-jpa-5/src/main/resources/application.properties @@ -1,2 +1,13 @@ + +spring.datasource.url=jdbc:h2:mem:baeldung + +# JPA-Schema-Generation +# Use below configuration to generate database schema create commands based on the entity models +# and export them into the create.sql file +#spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create +#spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=create.sql +#spring.jpa.properties.javax.persistence.schema-generation.scripts.create-source=metadata +#spring.jpa.properties.hibernate.format_sql=true + spring.jpa.show-sql=true diff --git a/persistence-modules/spring-data-jpa-5/src/test/java/com/baeldung/schemageneration/AccountRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-5/src/test/java/com/baeldung/schemageneration/AccountRepositoryIntegrationTest.java new file mode 100644 index 0000000000..86a7671fe4 --- /dev/null +++ b/persistence-modules/spring-data-jpa-5/src/test/java/com/baeldung/schemageneration/AccountRepositoryIntegrationTest.java @@ -0,0 +1,72 @@ +package com.baeldung.schemageneration; + +import com.baeldung.schemageneration.model.Account; +import com.baeldung.schemageneration.model.AccountSetting; +import com.baeldung.schemageneration.repository.AccountRepository; +import com.baeldung.schemageneration.repository.AccountSettingRepository; +import org.junit.After; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = AccountApplication.class) +public class AccountRepositoryIntegrationTest { + + private static final String USER_NAME = "Eduard"; + private static final String USER_EMAIL_ADDRESS = "eduard@gmx.com"; + private static final String ACCOUNT_SETTING_NAME = "Timezone"; + private static final String ACCOUNT_SETTING_VALUE = "UTC+02"; + + @Autowired + private AccountRepository accountRepository; + + @Autowired + private AccountSettingRepository accountSettingRepository; + + @After + public void tearDown() { + accountRepository.deleteAll(); + } + + @Test + public void givenNewAccount_whenSave_thenSuccess() { + Account account = new Account(USER_NAME, USER_EMAIL_ADDRESS); + accountRepository.save(account); + + assertEquals(1, accountRepository.count()); + } + + @Test + public void givenSavedAccount_whenFindByName_thenFound() { + Account account = new Account(USER_NAME, USER_EMAIL_ADDRESS); + accountRepository.save(account); + + Account accountFound = accountRepository.findByName(USER_NAME); + + assertNotNull(accountFound); + assertEquals(USER_NAME, accountFound.getName()); + assertEquals(USER_EMAIL_ADDRESS, accountFound.getEmailAddress()); + } + + @Test + public void givenSavedAccount_whenAccountSettingIsAdded_thenPersisted() { + Account account = new Account(USER_NAME, USER_EMAIL_ADDRESS); + account.addAccountSetting(new AccountSetting(ACCOUNT_SETTING_NAME, ACCOUNT_SETTING_VALUE)); + accountRepository.save(account); + + Account accountFound = accountRepository.findByName(USER_NAME); + assertNotNull(accountFound); + AccountSetting accountSetting = accountSettingRepository.findByAccountId(accountFound.getId()); + + assertNotNull(accountSetting); + assertEquals(ACCOUNT_SETTING_NAME, accountSetting.getSettingName()); + assertEquals(ACCOUNT_SETTING_VALUE, accountSetting.getSettingValue()); + } + +} diff --git a/persistence-modules/spring-data-jpa-5/src/test/resources/application-test.properties b/persistence-modules/spring-data-jpa-5/src/test/resources/application-test.properties index 207de2e8ec..e3d39fe1e2 100644 --- a/persistence-modules/spring-data-jpa-5/src/test/resources/application-test.properties +++ b/persistence-modules/spring-data-jpa-5/src/test/resources/application-test.properties @@ -1 +1,3 @@ spring.jpa.hibernate.ddl-auto=update +spring.datasource.url=jdbc:h2:mem:baeldung + From da533f662a495d2fb78d619c4e2edfd9db65dc77 Mon Sep 17 00:00:00 2001 From: Tyrell Flurry Date: Tue, 5 May 2020 08:01:34 -0400 Subject: [PATCH 14/19] BAEL-3929: changed plugin version. --- maven-all/maven-unused-dependencies/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maven-all/maven-unused-dependencies/pom.xml b/maven-all/maven-unused-dependencies/pom.xml index c8f6c1f04b..825858e481 100644 --- a/maven-all/maven-unused-dependencies/pom.xml +++ b/maven-all/maven-unused-dependencies/pom.xml @@ -9,7 +9,7 @@ 3.2.2 1.7.25 - 3.1.1 + 3.1.2 3.1 From 0f78e9a073b1c8b941375ac5e725a7180288fd42 Mon Sep 17 00:00:00 2001 From: Vikas Rajput Date: Tue, 5 May 2020 19:53:34 +0530 Subject: [PATCH 15/19] Bael 3557: Deleted /app package (#9242) * BAEL-3557: Completed a simple web application in spring boot and groovy * BAEL-3557: renamed packagename from com.baeldung.app to more unique name - com.baeldung.springwithgroovy * BAEL-3557: Deleted /app package Co-authored-by: Vikas Ramsingh Rajput --- .../app/SpringBootGroovyApplication.groovy | 13 --- .../app/controller/TodoController.groovy | 48 --------- .../com/baeldung/app/entity/Todo.groovy | 23 ----- .../app/repository/TodoRepository.groovy | 9 -- .../baeldung/app/service/TodoService.groovy | 16 --- .../app/service/impl/TodoServiceImpl.groovy | 40 -------- .../com/baeldung/app/TodoAppUnitTest.groovy | 97 ------------------- 7 files changed, 246 deletions(-) delete mode 100644 spring-boot-groovy/src/main/groovy/com/baeldung/app/SpringBootGroovyApplication.groovy delete mode 100644 spring-boot-groovy/src/main/groovy/com/baeldung/app/controller/TodoController.groovy delete mode 100644 spring-boot-groovy/src/main/groovy/com/baeldung/app/entity/Todo.groovy delete mode 100644 spring-boot-groovy/src/main/groovy/com/baeldung/app/repository/TodoRepository.groovy delete mode 100644 spring-boot-groovy/src/main/groovy/com/baeldung/app/service/TodoService.groovy delete mode 100644 spring-boot-groovy/src/main/groovy/com/baeldung/app/service/impl/TodoServiceImpl.groovy delete mode 100644 spring-boot-groovy/src/test/groovy/com/baeldung/app/TodoAppUnitTest.groovy diff --git a/spring-boot-groovy/src/main/groovy/com/baeldung/app/SpringBootGroovyApplication.groovy b/spring-boot-groovy/src/main/groovy/com/baeldung/app/SpringBootGroovyApplication.groovy deleted file mode 100644 index 226a2ff53d..0000000000 --- a/spring-boot-groovy/src/main/groovy/com/baeldung/app/SpringBootGroovyApplication.groovy +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.app - -import org.springframework.boot.SpringApplication -import org.springframework.boot.autoconfigure.SpringBootApplication - -import com.baeldung.app.SpringBootGroovyApplication - -@SpringBootApplication -class SpringBootGroovyApplication { - static void main(String[] args) { - SpringApplication.run SpringBootGroovyApplication, args - } -} diff --git a/spring-boot-groovy/src/main/groovy/com/baeldung/app/controller/TodoController.groovy b/spring-boot-groovy/src/main/groovy/com/baeldung/app/controller/TodoController.groovy deleted file mode 100644 index 02f6d0223b..0000000000 --- a/spring-boot-groovy/src/main/groovy/com/baeldung/app/controller/TodoController.groovy +++ /dev/null @@ -1,48 +0,0 @@ -package com.baeldung.app.controller - -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.web.bind.annotation.DeleteMapping -import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.PathVariable -import org.springframework.web.bind.annotation.PostMapping -import org.springframework.web.bind.annotation.PutMapping -import org.springframework.web.bind.annotation.RequestBody -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RequestMethod -import org.springframework.web.bind.annotation.RestController - -import com.baeldung.app.entity.Todo -import com.baeldung.app.service.TodoService - -@RestController -@RequestMapping('todo') -public class TodoController { - - @Autowired - TodoService todoService - - @GetMapping - List getAllTodoList(){ - todoService.findAll() - } - - @PostMapping - Todo saveTodo(@RequestBody Todo todo){ - todoService.saveTodo todo - } - - @PutMapping - Todo updateTodo(@RequestBody Todo todo){ - todoService.updateTodo todo - } - - @DeleteMapping('/{todoId}') - deleteTodo(@PathVariable Integer todoId){ - todoService.deleteTodo todoId - } - - @GetMapping('/{todoId}') - Todo getTodoById(@PathVariable Integer todoId){ - todoService.findById todoId - } -} \ No newline at end of file diff --git a/spring-boot-groovy/src/main/groovy/com/baeldung/app/entity/Todo.groovy b/spring-boot-groovy/src/main/groovy/com/baeldung/app/entity/Todo.groovy deleted file mode 100644 index 9f1253c5b3..0000000000 --- a/spring-boot-groovy/src/main/groovy/com/baeldung/app/entity/Todo.groovy +++ /dev/null @@ -1,23 +0,0 @@ -package com.baeldung.app.entity - -import javax.persistence.Column -import javax.persistence.Entity -import javax.persistence.GeneratedValue -import javax.persistence.GenerationType -import javax.persistence.Id -import javax.persistence.Table - -@Entity -@Table(name = 'todo') -class Todo { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - Integer id - - @Column - String task - - @Column - Boolean isCompleted - -} diff --git a/spring-boot-groovy/src/main/groovy/com/baeldung/app/repository/TodoRepository.groovy b/spring-boot-groovy/src/main/groovy/com/baeldung/app/repository/TodoRepository.groovy deleted file mode 100644 index c0b35cc37d..0000000000 --- a/spring-boot-groovy/src/main/groovy/com/baeldung/app/repository/TodoRepository.groovy +++ /dev/null @@ -1,9 +0,0 @@ -package com.baeldung.app.repository - -import org.springframework.data.jpa.repository.JpaRepository -import org.springframework.stereotype.Repository - -import com.baeldung.app.entity.Todo - -@Repository -interface TodoRepository extends JpaRepository {} \ No newline at end of file diff --git a/spring-boot-groovy/src/main/groovy/com/baeldung/app/service/TodoService.groovy b/spring-boot-groovy/src/main/groovy/com/baeldung/app/service/TodoService.groovy deleted file mode 100644 index 0a59d93330..0000000000 --- a/spring-boot-groovy/src/main/groovy/com/baeldung/app/service/TodoService.groovy +++ /dev/null @@ -1,16 +0,0 @@ -package com.baeldung.app.service - -import com.baeldung.app.entity.Todo - -interface TodoService { - - List findAll() - - Todo findById(Integer todoId) - - Todo saveTodo(Todo todo) - - Todo updateTodo(Todo todo) - - Todo deleteTodo(Integer todoId) -} diff --git a/spring-boot-groovy/src/main/groovy/com/baeldung/app/service/impl/TodoServiceImpl.groovy b/spring-boot-groovy/src/main/groovy/com/baeldung/app/service/impl/TodoServiceImpl.groovy deleted file mode 100644 index 6d0ee03a9f..0000000000 --- a/spring-boot-groovy/src/main/groovy/com/baeldung/app/service/impl/TodoServiceImpl.groovy +++ /dev/null @@ -1,40 +0,0 @@ -package com.baeldung.app.service.impl - -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.stereotype.Service - -import com.baeldung.app.entity.Todo -import com.baeldung.app.repository.TodoRepository -import com.baeldung.app.service.TodoService - -@Service -class TodoServiceImpl implements TodoService { - - @Autowired - TodoRepository todoRepository - - @Override - List findAll() { - todoRepository.findAll() - } - - @Override - Todo findById(Integer todoId) { - todoRepository.findById todoId get() - } - - @Override - Todo saveTodo(Todo todo){ - todoRepository.save todo - } - - @Override - Todo updateTodo(Todo todo){ - todoRepository.save todo - } - - @Override - Todo deleteTodo(Integer todoId){ - todoRepository.deleteById todoId - } -} diff --git a/spring-boot-groovy/src/test/groovy/com/baeldung/app/TodoAppUnitTest.groovy b/spring-boot-groovy/src/test/groovy/com/baeldung/app/TodoAppUnitTest.groovy deleted file mode 100644 index faf2d64ba7..0000000000 --- a/spring-boot-groovy/src/test/groovy/com/baeldung/app/TodoAppUnitTest.groovy +++ /dev/null @@ -1,97 +0,0 @@ -package com.baeldung.app - -import static org.junit.jupiter.api.Assertions.assertEquals -import static org.junit.jupiter.api.Assertions.assertTrue - -import org.junit.BeforeClass -import org.junit.Test -import org.junit.runner.RunWith -import org.springframework.boot.test.context.SpringBootTest -import org.springframework.http.HttpStatus -import org.springframework.http.MediaType -import org.springframework.test.context.event.annotation.BeforeTestClass -import org.springframework.test.context.junit4.SpringRunner - -import com.baeldung.app.entity.Todo - -import io.restassured.RestAssured -import io.restassured.response.Response - -class TodoAppUnitTest { - static API_ROOT = 'http://localhost:8081/todo' - static readingTodoId - static writingTodoId - - @BeforeClass - static void populateDummyData() { - Todo readingTodo = new Todo(task: 'Reading', isCompleted: false) - Todo writingTodo = new Todo(task: 'Writing', isCompleted: false) - - final Response readingResponse = - RestAssured.given() - .contentType(MediaType.APPLICATION_JSON_VALUE) - .body(readingTodo).post(API_ROOT) - - Todo cookingTodoResponse = readingResponse.as Todo.class - readingTodoId = cookingTodoResponse.getId() - - final Response writingResponse = - RestAssured.given() - .contentType(MediaType.APPLICATION_JSON_VALUE) - .body(writingTodo).post(API_ROOT) - - Todo writingTodoResponse = writingResponse.as Todo.class - writingTodoId = writingTodoResponse.getId() - } - - @Test - void whenGetAllTodoList_thenOk(){ - final Response response = RestAssured.get(API_ROOT) - - assertEquals HttpStatus.OK.value(),response.getStatusCode() - assertTrue response.as(List.class).size() > 0 - } - - @Test - void whenGetTodoById_thenOk(){ - final Response response = - RestAssured.get("$API_ROOT/$readingTodoId") - - assertEquals HttpStatus.OK.value(),response.getStatusCode() - Todo todoResponse = response.as Todo.class - assertEquals readingTodoId,todoResponse.getId() - } - - @Test - void whenUpdateTodoById_thenOk(){ - Todo todo = new Todo(id:readingTodoId, isCompleted: true) - final Response response = - RestAssured.given() - .contentType(MediaType.APPLICATION_JSON_VALUE) - .body(todo).put(API_ROOT) - - assertEquals HttpStatus.OK.value(),response.getStatusCode() - Todo todoResponse = response.as Todo.class - assertTrue todoResponse.getIsCompleted() - } - - @Test - void whenDeleteTodoById_thenOk(){ - final Response response = - RestAssured.given() - .delete("$API_ROOT/$writingTodoId") - - assertEquals HttpStatus.OK.value(),response.getStatusCode() - } - - @Test - void whenSaveTodo_thenOk(){ - Todo todo = new Todo(task: 'Blogging', isCompleted: false) - final Response response = - RestAssured.given() - .contentType(MediaType.APPLICATION_JSON_VALUE) - .body(todo).post(API_ROOT) - - assertEquals HttpStatus.OK.value(),response.getStatusCode() - } -} \ No newline at end of file From 50208fb01304c8398e92c816589de92ff3e7a46b Mon Sep 17 00:00:00 2001 From: kwoyke Date: Tue, 5 May 2020 22:27:16 +0200 Subject: [PATCH 16/19] Verify if the connection is still alive (#9246) --- .../com/baeldung/connectionpool/BasicConnectionPool.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/persistence-modules/core-java-persistence/src/main/java/com/baeldung/connectionpool/BasicConnectionPool.java b/persistence-modules/core-java-persistence/src/main/java/com/baeldung/connectionpool/BasicConnectionPool.java index 289db18c53..22ef0e5411 100644 --- a/persistence-modules/core-java-persistence/src/main/java/com/baeldung/connectionpool/BasicConnectionPool.java +++ b/persistence-modules/core-java-persistence/src/main/java/com/baeldung/connectionpool/BasicConnectionPool.java @@ -14,7 +14,8 @@ public class BasicConnectionPool implements ConnectionPool { private final List connectionPool; private final List usedConnections = new ArrayList<>(); private static final int INITIAL_POOL_SIZE = 10; - private final int MAX_POOL_SIZE = 20; + private static final int MAX_POOL_SIZE = 20; + private static final int MAX_TIMEOUT = 5; public static BasicConnectionPool create(String url, String user, String password) throws SQLException { List pool = new ArrayList<>(INITIAL_POOL_SIZE); @@ -42,6 +43,11 @@ public class BasicConnectionPool implements ConnectionPool { } Connection connection = connectionPool.remove(connectionPool.size() - 1); + + if(!connection.isValid(MAX_TIMEOUT)){ + connection = createConnection(url, user, password); + } + usedConnections.add(connection); return connection; } From fb5b157ce455b182a729ede1362d86bf4e1a235e Mon Sep 17 00:00:00 2001 From: sasam0320 <63002713+sasam0320@users.noreply.github.com> Date: Wed, 6 May 2020 05:28:28 +0200 Subject: [PATCH 17/19] Add missing code snippets (#9228) --- .../spring-boot-properties/pom.xml | 1 + .../processor/JdbcProperties.java | 21 +++++++++++ .../processor/PropertyBeanInjection.java | 11 ++++-- .../configurationproperties/Database.java | 36 +++++++++++++++++++ .../DatabaseConfig.java | 23 ++++++++++++ .../DatabaseConfigPropertiesApp.java | 13 +++++++ .../spring/PropertyPlaceholderConfig.java | 23 ++++++++++++ .../PropertySourcesPlaceholderConfig.java | 24 +++++++++++++ .../src/main/resources/application.properties | 3 -- .../main/resources/configForProperties.xml | 6 +++- .../configForPropertyPlaceholderBeans.xml | 23 ++++++++++++ .../configuration-processor.properties | 3 ++ .../src/main/resources/database.properties | 4 +++ .../src/main/resources/database.yml | 5 +++ .../PropertyBeanInjectionUnitTest.java | 5 +++ .../ConfigPropertiesIntegrationTest.java | 16 +++++++-- ...PlaceholdersJavaConfigIntegrationTest.java | 23 ++++++++++++ ...ePlaceholdersXmlConfigIntegrationTest.java | 25 +++++++++++++ ...plePropertiesXmlConfigIntegrationTest.java | 3 ++ .../baeldung/test/IntegrationTestSuite.java | 6 ++-- .../configuration-processor.properties | 1 + .../test/resources/database-test.properties | 3 ++ 22 files changed, 268 insertions(+), 10 deletions(-) create mode 100644 spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/configuration/processor/JdbcProperties.java create mode 100644 spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/configurationproperties/Database.java create mode 100644 spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/configurationproperties/DatabaseConfig.java create mode 100644 spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/configurationproperties/DatabaseConfigPropertiesApp.java create mode 100644 spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/spring/PropertyPlaceholderConfig.java create mode 100644 spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/spring/PropertySourcesPlaceholderConfig.java create mode 100644 spring-boot-modules/spring-boot-properties/src/main/resources/configForPropertyPlaceholderBeans.xml create mode 100644 spring-boot-modules/spring-boot-properties/src/main/resources/configuration-processor.properties create mode 100644 spring-boot-modules/spring-boot-properties/src/main/resources/database.properties create mode 100644 spring-boot-modules/spring-boot-properties/src/main/resources/database.yml create mode 100644 spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multiple/MultiplePlaceholdersJavaConfigIntegrationTest.java create mode 100644 spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multiple/MultiplePlaceholdersXmlConfigIntegrationTest.java create mode 100644 spring-boot-modules/spring-boot-properties/src/test/resources/database-test.properties diff --git a/spring-boot-modules/spring-boot-properties/pom.xml b/spring-boot-modules/spring-boot-properties/pom.xml index ec05ec1bdc..ef9c084f4c 100644 --- a/spring-boot-modules/spring-boot-properties/pom.xml +++ b/spring-boot-modules/spring-boot-properties/pom.xml @@ -128,6 +128,7 @@ 4.4.11 @ 2.2.4.RELEASE + com.baeldung.buildproperties.Application diff --git a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/configuration/processor/JdbcProperties.java b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/configuration/processor/JdbcProperties.java new file mode 100644 index 0000000000..bbd193acba --- /dev/null +++ b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/configuration/processor/JdbcProperties.java @@ -0,0 +1,21 @@ +package com.baeldung.configuration.processor; + +import org.springframework.boot.context.properties.*; +import org.springframework.context.annotation.*; +import org.springframework.beans.factory.annotation.*; + +@Configuration +@ConfigurationProperties(prefix = "com.baeldung") +public class JdbcProperties { + + @Value("${jdbc.url:jdbc:postgresql:/localhost:5432}") + private String jdbcUrl; + + public String getJdbcUrl() { + return jdbcUrl; + } + + public void setJdbcUrl(String jdbcUrl) { + this.jdbcUrl = jdbcUrl; + } +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/configuration/processor/PropertyBeanInjection.java b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/configuration/processor/PropertyBeanInjection.java index 3bcbf41f54..89a8f9458c 100644 --- a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/configuration/processor/PropertyBeanInjection.java +++ b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/configuration/processor/PropertyBeanInjection.java @@ -6,16 +6,23 @@ import org.springframework.stereotype.*; @Component public class PropertyBeanInjection { - private final CustomProperties customProperties; + private CustomProperties customProperties; - PropertyBeanInjection(@Autowired CustomProperties customProperties) { + private JdbcProperties jdbcProperties; + + PropertyBeanInjection(@Autowired CustomProperties customProperties, @Autowired JdbcProperties jdbcProperties) { this.customProperties = customProperties; + this.jdbcProperties = jdbcProperties; } String getUrl() { return customProperties.getUrl(); } + String getJdbcUrl() { + return jdbcProperties.getJdbcUrl(); + } + int getTimeoutInMilliseconds() { return customProperties.getTimeoutInMilliSeconds(); } diff --git a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/configurationproperties/Database.java b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/configurationproperties/Database.java new file mode 100644 index 0000000000..990ede35cd --- /dev/null +++ b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/configurationproperties/Database.java @@ -0,0 +1,36 @@ +package com.baeldung.configurationproperties; + +import org.springframework.boot.context.properties.ConfigurationProperties; + + +@ConfigurationProperties(prefix = "database") +public class Database { + + String url; + String username; + String password; + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/configurationproperties/DatabaseConfig.java b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/configurationproperties/DatabaseConfig.java new file mode 100644 index 0000000000..8f17c98f03 --- /dev/null +++ b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/configurationproperties/DatabaseConfig.java @@ -0,0 +1,23 @@ +package com.baeldung.configurationproperties; + +import org.springframework.core.env.Environment; +import org.springframework.beans.factory.annotation.*; +import org.springframework.context.annotation.*; + +@Configuration +public class DatabaseConfig { + + @Autowired private Environment env; + + @Bean(name="dataSource") + public Database dataSource() { + + Database dataSource = new Database(); + dataSource.setUrl(env.getProperty("jdbc.url")); + dataSource.setUsername(env.getProperty("database.username")); + dataSource.setPassword(env.getProperty("database.password")); + + return dataSource; + } + +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/configurationproperties/DatabaseConfigPropertiesApp.java b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/configurationproperties/DatabaseConfigPropertiesApp.java new file mode 100644 index 0000000000..bb1c937f60 --- /dev/null +++ b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/configurationproperties/DatabaseConfigPropertiesApp.java @@ -0,0 +1,13 @@ +package com.baeldung.configurationproperties; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; + +@SpringBootApplication +@ComponentScan(basePackageClasses = {Database.class,DatabaseConfig.class}) +public class DatabaseConfigPropertiesApp{ + + public static void main(String[]args) {SpringApplication.run(DatabaseConfigPropertiesApp.class,args);} + +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/spring/PropertyPlaceholderConfig.java b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/spring/PropertyPlaceholderConfig.java new file mode 100644 index 0000000000..0d1eb4ccf7 --- /dev/null +++ b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/spring/PropertyPlaceholderConfig.java @@ -0,0 +1,23 @@ +package com.baeldung.properties.spring; + +import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.*; + +@Configuration +public class PropertyPlaceholderConfig { + + public PropertyPlaceholderConfig(){ + super(); + } + + @Bean + public static PropertyPlaceholderConfigurer properties() { + PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); + Resource[] resources = new ClassPathResource[]{ new ClassPathResource("foo.properties") }; + ppc.setLocations( resources ); + ppc.setIgnoreUnresolvablePlaceholders( true ); + return ppc; + } +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/spring/PropertySourcesPlaceholderConfig.java b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/spring/PropertySourcesPlaceholderConfig.java new file mode 100644 index 0000000000..8ff464e4cf --- /dev/null +++ b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/spring/PropertySourcesPlaceholderConfig.java @@ -0,0 +1,24 @@ +package com.baeldung.properties.spring; + +import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.*; + +@Configuration +public class PropertySourcesPlaceholderConfig{ + + public PropertySourcesPlaceholderConfig(){ + super(); + } + + @Bean + public static PropertySourcesPlaceholderConfigurer properties(){ + PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer(); + Resource[] resources = new ClassPathResource[]{ new ClassPathResource("foo.properties") }; + pspc.setLocations(resources); + pspc.setIgnoreUnresolvablePlaceholders(true); + return pspc; + } + +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-properties/src/main/resources/application.properties b/spring-boot-modules/spring-boot-properties/src/main/resources/application.properties index d4d1df7abc..af38556f81 100644 --- a/spring-boot-modules/spring-boot-properties/src/main/resources/application.properties +++ b/spring-boot-modules/spring-boot-properties/src/main/resources/application.properties @@ -3,6 +3,3 @@ spring.properties.refreshDelay=1000 spring.config.location=file:extra.properties spring.main.allow-bean-definition-overriding=true -database.url=jdbc:postgresql:/localhost:5432/instance -database.username=foo -database.password=bar \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-properties/src/main/resources/configForProperties.xml b/spring-boot-modules/spring-boot-properties/src/main/resources/configForProperties.xml index d796f791cb..4468bb485f 100644 --- a/spring-boot-modules/spring-boot-properties/src/main/resources/configForProperties.xml +++ b/spring-boot-modules/spring-boot-properties/src/main/resources/configForProperties.xml @@ -7,10 +7,14 @@ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd" > - + + + + + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-properties/src/main/resources/configForPropertyPlaceholderBeans.xml b/spring-boot-modules/spring-boot-properties/src/main/resources/configForPropertyPlaceholderBeans.xml new file mode 100644 index 0000000000..a296cf5169 --- /dev/null +++ b/spring-boot-modules/spring-boot-properties/src/main/resources/configForPropertyPlaceholderBeans.xml @@ -0,0 +1,23 @@ + + + + + + + classpath:foo.properties + + + + + + + + + classpath:foo.properties + + + + + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-properties/src/main/resources/configuration-processor.properties b/spring-boot-modules/spring-boot-properties/src/main/resources/configuration-processor.properties new file mode 100644 index 0000000000..b68a4fbda3 --- /dev/null +++ b/spring-boot-modules/spring-boot-properties/src/main/resources/configuration-processor.properties @@ -0,0 +1,3 @@ +com.baeldung.url=www.abc.test.com +com.baeldung.jdbc.url= +com.baeldung.timeout-in-milli-seconds=2000 diff --git a/spring-boot-modules/spring-boot-properties/src/main/resources/database.properties b/spring-boot-modules/spring-boot-properties/src/main/resources/database.properties new file mode 100644 index 0000000000..6524ce6109 --- /dev/null +++ b/spring-boot-modules/spring-boot-properties/src/main/resources/database.properties @@ -0,0 +1,4 @@ +database.url=jdbc:postgresql:/localhost:5432/instance +database.username=foo +database.password=bar +jdbc.url=jdbc:postgresql:/localhost:5432 \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-properties/src/main/resources/database.yml b/spring-boot-modules/spring-boot-properties/src/main/resources/database.yml new file mode 100644 index 0000000000..8404d9411a --- /dev/null +++ b/spring-boot-modules/spring-boot-properties/src/main/resources/database.yml @@ -0,0 +1,5 @@ +database: + url: jdbc:postresql:/localhost:5432/instance + username: foo + password: bar +secret: foo \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/configuration/processor/PropertyBeanInjectionUnitTest.java b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/configuration/processor/PropertyBeanInjectionUnitTest.java index bdeb6547c3..eb6add2b94 100644 --- a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/configuration/processor/PropertyBeanInjectionUnitTest.java +++ b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/configuration/processor/PropertyBeanInjectionUnitTest.java @@ -15,6 +15,11 @@ class PropertyBeanInjectionUnitTest { @Autowired private PropertyBeanInjection propertyBeanInjection; + @Test + void checkThatJdbcPropertiesHaveTheCorrectValueFromPropertiesFile() { + Assertions.assertEquals("jdbc:postgresql:/localhost:5432", propertyBeanInjection.getJdbcUrl()); + } + @Test void checkThatCustomPropertiesHaveTheCorrectValueFromPropertiesFile() { Assertions.assertEquals("www.abc.test.com", propertyBeanInjection.getUrl()); diff --git a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/configurationproperties/ConfigPropertiesIntegrationTest.java b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/configurationproperties/ConfigPropertiesIntegrationTest.java index 141400b1fe..2b0833c387 100644 --- a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/configurationproperties/ConfigPropertiesIntegrationTest.java +++ b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/configurationproperties/ConfigPropertiesIntegrationTest.java @@ -4,6 +4,7 @@ import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; @@ -13,13 +14,17 @@ import com.baeldung.properties.AdditionalProperties; import com.baeldung.properties.ConfigPropertiesDemoApplication; @RunWith(SpringRunner.class) -@SpringBootTest(classes = ConfigPropertiesDemoApplication.class) -@TestPropertySource("classpath:configprops-test.properties") +@SpringBootTest(classes = {ConfigPropertiesDemoApplication.class, DatabaseConfigPropertiesApp.class}) +@TestPropertySource(locations = {"classpath:configprops-test.properties", "classpath:database-test.properties"}) public class ConfigPropertiesIntegrationTest { @Autowired private ConfigProperties properties; + @Autowired + @Qualifier("dataSource") + private Database databaseProperties; + @Autowired private AdditionalProperties additionalProperties; @@ -53,4 +58,11 @@ public class ConfigPropertiesIntegrationTest { Assert.assertTrue(additionalProperties.getUnit().equals("km")); Assert.assertTrue(additionalProperties.getMax() == 100); } + + @Test + public void whenDatabasePropertyQueriedthenReturnsProperty() { + Assert.assertTrue(databaseProperties.getUrl().equals("jdbc:postgresql:/localhost:5432")); + Assert.assertTrue(databaseProperties.getUsername().equals("foo")); + Assert.assertTrue(databaseProperties.getPassword().equals("bar")); + } } diff --git a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multiple/MultiplePlaceholdersJavaConfigIntegrationTest.java b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multiple/MultiplePlaceholdersJavaConfigIntegrationTest.java new file mode 100644 index 0000000000..8ebda90321 --- /dev/null +++ b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multiple/MultiplePlaceholdersJavaConfigIntegrationTest.java @@ -0,0 +1,23 @@ +package com.baeldung.properties.multiple; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; + +import com.baeldung.properties.spring.PropertyPlaceholderConfig; +import com.baeldung.properties.spring.PropertySourcesPlaceholderConfig; + +import static org.assertj.core.api.Assertions.assertThat; + +@SpringJUnitConfig({PropertyPlaceholderConfig.class, PropertySourcesPlaceholderConfig.class}) +public class MultiplePlaceholdersJavaConfigIntegrationTest { + + @Value("${key.something}") + private String something; + + + @Test + public void whenReadInjectedValues_thenGetCorrectValues() { + assertThat(something).isEqualTo("val"); + } +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multiple/MultiplePlaceholdersXmlConfigIntegrationTest.java b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multiple/MultiplePlaceholdersXmlConfigIntegrationTest.java new file mode 100644 index 0000000000..b863e2e080 --- /dev/null +++ b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multiple/MultiplePlaceholdersXmlConfigIntegrationTest.java @@ -0,0 +1,25 @@ +package com.baeldung.properties.multiple; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; + +import static org.assertj.core.api.Assertions.assertThat; + + +@SpringJUnitConfig(locations = "classpath:configForPropertyPlaceholderBeans.xml") +public class MultiplePlaceholdersXmlConfigIntegrationTest { + + @Value("${foo}") + private String something; + + @Value("${key.something}") + private String something2; + + + @Test + public void whenReadInjectedValues_thenGetCorrectValues() { + assertThat(something).isEqualTo("bar"); + assertThat(something2).isEqualTo("val"); + } +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multiple/MultiplePropertiesXmlConfigIntegrationTest.java b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multiple/MultiplePropertiesXmlConfigIntegrationTest.java index db71e816dd..6827ee1cf1 100644 --- a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multiple/MultiplePropertiesXmlConfigIntegrationTest.java +++ b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/multiple/MultiplePropertiesXmlConfigIntegrationTest.java @@ -13,9 +13,12 @@ public class MultiplePropertiesXmlConfigIntegrationTest { @Value("${key.something2}") private String something2; + @Value("${jdbc.url}") private String jdbcUrl; + @Test public void whenReadInjectedValues_thenGetCorrectValues() { assertThat(something).isEqualTo("val"); assertThat(something2).isEqualTo("val2"); + assertThat(jdbcUrl).isEqualTo("jdbc:postgresql:/localhost:5432"); } } diff --git a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/test/IntegrationTestSuite.java b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/test/IntegrationTestSuite.java index d41d328867..0e0f8f6230 100644 --- a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/test/IntegrationTestSuite.java +++ b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/test/IntegrationTestSuite.java @@ -10,6 +10,8 @@ import com.baeldung.properties.basic.PropertiesWithXmlIntegrationTest; import com.baeldung.properties.external.ExternalPropertiesWithJavaIntegrationTest; import com.baeldung.properties.external.ExternalPropertiesWithMultipleXmlsIntegrationTest; import com.baeldung.properties.external.ExternalPropertiesWithXmlManualTest; +import com.baeldung.properties.multiple.MultiplePropertiesXmlConfigIntegrationTest; +import com.baeldung.properties.multiple.MultiplePlaceholdersXmlConfigIntegrationTest; @RunWith(Suite.class) @SuiteClasses({ //@formatter:off @@ -17,8 +19,8 @@ import com.baeldung.properties.external.ExternalPropertiesWithXmlManualTest; ExternalPropertiesWithJavaIntegrationTest.class, ExternalPropertiesWithMultipleXmlsIntegrationTest.class, ExternalPropertiesWithXmlManualTest.class, - ExtendedPropertiesWithJavaIntegrationTest.class, - PropertiesWithMultipleXmlsIntegrationTest.class, + ExtendedPropertiesWithJavaIntegrationTest.class, MultiplePropertiesXmlConfigIntegrationTest.class, + PropertiesWithMultipleXmlsIntegrationTest.class, MultiplePlaceholdersXmlConfigIntegrationTest.class })// @formatter:on public final class IntegrationTestSuite { // diff --git a/spring-boot-modules/spring-boot-properties/src/test/resources/configuration-processor.properties b/spring-boot-modules/spring-boot-properties/src/test/resources/configuration-processor.properties index 00369f2eff..b68a4fbda3 100644 --- a/spring-boot-modules/spring-boot-properties/src/test/resources/configuration-processor.properties +++ b/spring-boot-modules/spring-boot-properties/src/test/resources/configuration-processor.properties @@ -1,2 +1,3 @@ com.baeldung.url=www.abc.test.com +com.baeldung.jdbc.url= com.baeldung.timeout-in-milli-seconds=2000 diff --git a/spring-boot-modules/spring-boot-properties/src/test/resources/database-test.properties b/spring-boot-modules/spring-boot-properties/src/test/resources/database-test.properties new file mode 100644 index 0000000000..384d0850ab --- /dev/null +++ b/spring-boot-modules/spring-boot-properties/src/test/resources/database-test.properties @@ -0,0 +1,3 @@ +jdbc.url=jdbc:postgresql:/localhost:5432 +database.username=foo +database.password=bar From 9770eda888cbb418aa6be7ff1c891c706bf1339c Mon Sep 17 00:00:00 2001 From: Michael Pratt Date: Wed, 6 May 2020 10:38:16 -0600 Subject: [PATCH 18/19] BAEL-3972: Move code examples to new package --- .../spring-security-core/README.md | 1 + .../app/controller/TaskController.java | 58 ----------------- .../java/com/baeldung/checkrolejava/App.java | 11 ++++ .../checkrolejava/UnauthorizedException.java | 8 +++ .../checkrolejava/UserController.java | 62 +++++++++++++++++++ 5 files changed, 82 insertions(+), 58 deletions(-) create mode 100644 spring-security-modules/spring-security-core/src/main/java/com/baeldung/checkrolejava/App.java create mode 100644 spring-security-modules/spring-security-core/src/main/java/com/baeldung/checkrolejava/UnauthorizedException.java create mode 100644 spring-security-modules/spring-security-core/src/main/java/com/baeldung/checkrolejava/UserController.java diff --git a/spring-security-modules/spring-security-core/README.md b/spring-security-modules/spring-security-core/README.md index e42dfecaa0..f28b3abb2b 100644 --- a/spring-security-modules/spring-security-core/README.md +++ b/spring-security-modules/spring-security-core/README.md @@ -8,6 +8,7 @@ This module contains articles about core Spring Security - [Introduction to Spring Method Security](https://www.baeldung.com/spring-security-method-security) - [Overview and Need for DelegatingFilterProxy in Spring](https://www.baeldung.com/spring-delegating-filter-proxy) - [Deny Access on Missing @PreAuthorize to Spring Controller Methods](https://www.baeldung.com/spring-deny-access) +- [Spring Security: Check If a User Has a Role in Java](https://www.baeldung.com/spring-security-check-user-role) ### Build the Project diff --git a/spring-security-modules/spring-security-core/src/main/java/com/baeldung/app/controller/TaskController.java b/spring-security-modules/spring-security-core/src/main/java/com/baeldung/app/controller/TaskController.java index 67072b5d61..7e6b2c3d9c 100644 --- a/spring-security-modules/spring-security-core/src/main/java/com/baeldung/app/controller/TaskController.java +++ b/spring-security-modules/spring-security-core/src/main/java/com/baeldung/app/controller/TaskController.java @@ -42,62 +42,4 @@ public class TaskController { return ResponseEntity.ok().body(tasks); } - - /** - * Example of restricting specific endpoints to specific roles using @PreAuthorize. - */ - @GetMapping("/manager") - @PreAuthorize("hasRole('ROLE_MANAGER')") - public ResponseEntity> getAlManagerTasks() { - Iterable tasks = taskService.findAll(); - - return ResponseEntity.ok().body(tasks); - } - - /** - * Example of restricting specific endpoints to specific roles using SecurityContext. - */ - @GetMapping("/actuator") - public ResponseEntity> getAlActuatorTasks() { - Authentication auth = SecurityContextHolder.getContext().getAuthentication(); - if (auth != null && auth.getAuthorities().stream().anyMatch(a -> a.getAuthority().equals("ACTUATOR"))) - { - return ResponseEntity.status(HttpStatus.FORBIDDEN).build(); - } - - Iterable tasks = taskService.findAll(); - - return ResponseEntity.ok().body(tasks); - } - - /** - * Example of restricting specific endpoints to specific roles using UserDetailsService. - */ - @GetMapping("/admin") - public ResponseEntity> getAlAdminTasks() { - if(userDetailsService != null) { - UserDetails details = userDetailsService.loadUserByUsername("pam"); - if (details != null && details.getAuthorities().stream().anyMatch(a -> a.getAuthority().equals("ADMIN"))) { - return ResponseEntity.status(HttpStatus.FORBIDDEN).build(); - } - } - - Iterable tasks = taskService.findAll(); - - return ResponseEntity.ok().body(tasks); - } - - /** - * Example of restricting specific endpoints to specific roles using HttpServletRequest. - */ - @GetMapping("/admin2") - public ResponseEntity> getAlAdminTasksUsingServlet(HttpServletRequest request) { - if (!request.isUserInRole("ROLE_ADMIN")) { - return ResponseEntity.status(HttpStatus.FORBIDDEN).build(); - } - - Iterable tasks = taskService.findAll(); - - return ResponseEntity.ok().body(tasks); - } } diff --git a/spring-security-modules/spring-security-core/src/main/java/com/baeldung/checkrolejava/App.java b/spring-security-modules/spring-security-core/src/main/java/com/baeldung/checkrolejava/App.java new file mode 100644 index 0000000000..357583a572 --- /dev/null +++ b/spring-security-modules/spring-security-core/src/main/java/com/baeldung/checkrolejava/App.java @@ -0,0 +1,11 @@ +package com.baeldung.checkrolejava; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class App { + public static void main(String[] args) { + SpringApplication.run(com.baeldung.app.App.class, args); + } +} diff --git a/spring-security-modules/spring-security-core/src/main/java/com/baeldung/checkrolejava/UnauthorizedException.java b/spring-security-modules/spring-security-core/src/main/java/com/baeldung/checkrolejava/UnauthorizedException.java new file mode 100644 index 0000000000..11fe9f9e5f --- /dev/null +++ b/spring-security-modules/spring-security-core/src/main/java/com/baeldung/checkrolejava/UnauthorizedException.java @@ -0,0 +1,8 @@ +package com.baeldung.checkrolejava; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +@ResponseStatus(value = HttpStatus.UNAUTHORIZED) +public class UnauthorizedException extends RuntimeException { +} diff --git a/spring-security-modules/spring-security-core/src/main/java/com/baeldung/checkrolejava/UserController.java b/spring-security-modules/spring-security-core/src/main/java/com/baeldung/checkrolejava/UserController.java new file mode 100644 index 0000000000..3092e94c7f --- /dev/null +++ b/spring-security-modules/spring-security-core/src/main/java/com/baeldung/checkrolejava/UserController.java @@ -0,0 +1,62 @@ +package com.baeldung.checkrolejava; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; + +import javax.servlet.http.HttpServletRequest; + +@Controller +public class UserController { + + @Autowired + private UserDetailsService userDetailsService; + + @PreAuthorize("hasRole('ROLE_ADMIN')") + @GetMapping("/user/{id}") + public String getUser(@PathVariable("id") String id) { + return "user"; + } + + @PreAuthorize("hasAnyRole('ROLE_ADMIN','ROLE_MANAGER')") + @GetMapping("/users") + public String getUsers() { + return "users"; + } + + @GetMapping("v2/user/{id}") + public String getUserUsingSecurityContext() { + Authentication auth = SecurityContextHolder.getContext().getAuthentication(); + if (auth != null && auth.getAuthorities().stream().anyMatch(a -> a.getAuthority().equals("ADMIN"))) { + return "user"; + } + + throw new UnauthorizedException(); + } + + @GetMapping("v2/users") + public String getUsersUsingDetailsService() { + UserDetails details = userDetailsService.loadUserByUsername("mike"); + if (details != null && details.getAuthorities().stream() + .anyMatch(a -> a.getAuthority().equals("ADMIN"))) { + return "users"; + } + + throw new UnauthorizedException(); + } + + @GetMapping("v3/users") + public String getUsers(HttpServletRequest request) { + if (request.isUserInRole("ROLE_ADMIN")) { + return "users"; + } + + throw new UnauthorizedException(); + } +} From 847d6ab0424833d0896e796c8a2fe91825f0c95b Mon Sep 17 00:00:00 2001 From: Yavuz Tas <12643010+yavuztas@users.noreply.github.com> Date: Thu, 7 May 2020 04:22:23 +0200 Subject: [PATCH 19/19] Changes for BAEL-2621 (#9217) * update dependency versions to latest * merge repository packages * remove obselete xml configuration * fix formatting * clean up * update package name * revert spring data jpa xml config and demonstrate how to import in PersistenceConfig by a commented @ImportResource annotation * rename jpa repositories xml to make it more clear * remove obselete @EnableJpaRepositories configs since we don't use spring data's jpa repositories for these congigurations --- .../spring-persistence-simple/pom.xml | 4 +-- .../baeldung/config/PersistenceConfig.java | 4 +-- .../baeldung/config/PersistenceJPAConfig.java | 2 -- .../persistence/config/PersistenceConfig.java | 17 ++++++------- .../spring/data/persistence/model/User.java | 25 ++++++++++++------- .../{dao => repository}/IFooDao.java | 4 ++- .../UserRepository.java | 22 ++++++++-------- .../UserRepositoryCustom.java | 8 +++--- .../UserRepositoryCustomImpl.java | 17 +++++-------- .../persistence/service/impl/FooService.java | 2 +- ...ml => springDataJpaRepositoriesConfig.xml} | 7 +++--- .../UserRepositoryCommon.java | 2 +- .../UserRepositoryIntegrationTest.java | 13 ++++------ 13 files changed, 62 insertions(+), 65 deletions(-) rename persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/{dao => repository}/IFooDao.java (87%) rename persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/{jpaquery => repository}/UserRepository.java (96%) rename persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/{jpaquery => repository}/UserRepositoryCustom.java (85%) rename persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/{jpaquery => repository}/UserRepositoryCustomImpl.java (85%) rename persistence-modules/spring-persistence-simple/src/main/resources/{springDataPersistenceConfig.xml => springDataJpaRepositoriesConfig.xml} (60%) rename persistence-modules/spring-persistence-simple/src/test/java/com/baeldung/spring/data/persistence/{jpaquery => repository}/UserRepositoryCommon.java (99%) rename persistence-modules/spring-persistence-simple/src/test/java/com/baeldung/spring/data/persistence/{jpaquery => repository}/UserRepositoryIntegrationTest.java (94%) diff --git a/persistence-modules/spring-persistence-simple/pom.xml b/persistence-modules/spring-persistence-simple/pom.xml index 878c4592f9..7318ec55bd 100644 --- a/persistence-modules/spring-persistence-simple/pom.xml +++ b/persistence-modules/spring-persistence-simple/pom.xml @@ -132,13 +132,13 @@ - 5.2.5.RELEASE + 5.2.6.RELEASE 5.4.13.Final 8.0.19 1.4.200 - 2.2.6.RELEASE + 2.2.7.RELEASE 9.0.0.M26 1.1 4.2.1 diff --git a/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/config/PersistenceConfig.java b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/config/PersistenceConfig.java index 80f3ff14c5..cdddbaa787 100644 --- a/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/config/PersistenceConfig.java +++ b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/config/PersistenceConfig.java @@ -11,7 +11,6 @@ import org.springframework.context.annotation.PropertySource; import org.springframework.core.env.Environment; import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; -import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.orm.hibernate5.HibernateTransactionManager; import org.springframework.orm.hibernate5.LocalSessionFactoryBean; import org.springframework.orm.jpa.JpaTransactionManager; @@ -26,7 +25,6 @@ import java.util.Properties; @Configuration @EnableTransactionManagement -@EnableJpaRepositories(basePackages = { "com.baeldung.hibernate.dao" }, transactionManagerRef = "jpaTransactionManager") @EnableJpaAuditing @PropertySource({ "classpath:persistence-mysql.properties" }) @ComponentScan(basePackages = { "com.baeldung.persistence.dao", "com.baeldung.jpa.dao" }) @@ -97,7 +95,7 @@ public class PersistenceConfig { return new FooService(); } - private final Properties hibernateProperties() { + private Properties hibernateProperties() { final Properties hibernateProperties = new Properties(); hibernateProperties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto")); hibernateProperties.setProperty("hibernate.dialect", env.getProperty("hibernate.dialect")); diff --git a/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/config/PersistenceJPAConfig.java b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/config/PersistenceJPAConfig.java index 06cae493c9..e8a2aefd6b 100644 --- a/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/config/PersistenceJPAConfig.java +++ b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/config/PersistenceJPAConfig.java @@ -8,7 +8,6 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; import org.springframework.core.env.Environment; import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor; -import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.jdbc.datasource.DriverManagerDataSource; import org.springframework.orm.jpa.JpaTransactionManager; import org.springframework.orm.jpa.JpaVendorAdapter; @@ -24,7 +23,6 @@ import java.util.Properties; @EnableTransactionManagement @PropertySource({ "classpath:persistence-h2.properties" }) @ComponentScan({ "com.baeldung.persistence","com.baeldung.jpa.dao" }) -@EnableJpaRepositories(basePackages = "com.baeldung.jpa.dao") public class PersistenceJPAConfig { @Autowired diff --git a/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/config/PersistenceConfig.java b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/config/PersistenceConfig.java index 66b540a692..604923d615 100644 --- a/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/config/PersistenceConfig.java +++ b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/config/PersistenceConfig.java @@ -1,9 +1,6 @@ package com.baeldung.spring.data.persistence.config; -import java.util.Properties; - -import javax.sql.DataSource; - +import com.google.common.base.Preconditions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -19,14 +16,15 @@ import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.annotation.EnableTransactionManagement; -import com.google.common.base.Preconditions; +import javax.sql.DataSource; +import java.util.Properties; @Configuration @EnableTransactionManagement @PropertySource({ "classpath:persistence-${envTarget:h2}.properties" }) @ComponentScan({ "com.baeldung.spring.data.persistence" }) -// @ImportResource("classpath*:springDataPersistenceConfig.xml") -@EnableJpaRepositories(basePackages = { "com.baeldung.spring.data.persistence.dao", "com.baeldung.spring.data.persistence.jpaquery" }) +//@ImportResource("classpath*:*springDataJpaRepositoriesConfig.xml") +@EnableJpaRepositories("com.baeldung.spring.data.persistence.repository") public class PersistenceConfig { @Autowired @@ -40,10 +38,9 @@ public class PersistenceConfig { public LocalContainerEntityManagerFactoryBean entityManagerFactory() { final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); em.setDataSource(dataSource()); - em.setPackagesToScan(new String[] { "com.baeldung.spring.data.persistence.model" }); + em.setPackagesToScan("com.baeldung.spring.data.persistence.model"); final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); - // vendorAdapter.set em.setJpaVendorAdapter(vendorAdapter); em.setJpaProperties(additionalProperties()); @@ -78,7 +75,7 @@ public class PersistenceConfig { final Properties hibernateProperties = new Properties(); hibernateProperties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto")); hibernateProperties.setProperty("hibernate.dialect", env.getProperty("hibernate.dialect")); - // hibernateProperties.setProperty("hibernate.globally_quoted_identifiers", "true"); + return hibernateProperties; } diff --git a/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/model/User.java b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/model/User.java index 09f1092644..1475eccbf0 100644 --- a/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/model/User.java +++ b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/model/User.java @@ -1,7 +1,6 @@ package com.baeldung.spring.data.persistence.model; import javax.persistence.*; - import java.time.LocalDate; import java.util.List; import java.util.Objects; @@ -13,14 +12,22 @@ public class User { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private int id; + private String name; + private LocalDate creationDate; + private LocalDate lastLoginDate; + private boolean active; + private int age; + @Column(unique = true, nullable = false) private String email; + private Integer status; + @OneToMany List possessionList; @@ -28,7 +35,7 @@ public class User { super(); } - public User(String name, LocalDate creationDate,String email, Integer status) { + public User(String name, LocalDate creationDate, String email, Integer status) { this.name = name; this.creationDate = creationDate; this.email = email; @@ -75,7 +82,7 @@ public class User { public void setAge(final int age) { this.age = age; } - + public LocalDate getCreationDate() { return creationDate; } @@ -94,18 +101,18 @@ public class User { builder.append("User [name=").append(name).append(", id=").append(id).append("]"); return builder.toString(); } - + @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; User user = (User) o; return id == user.id && - age == user.age && - Objects.equals(name, user.name) && - Objects.equals(creationDate, user.creationDate) && - Objects.equals(email, user.email) && - Objects.equals(status, user.status); + age == user.age && + Objects.equals(name, user.name) && + Objects.equals(creationDate, user.creationDate) && + Objects.equals(email, user.email) && + Objects.equals(status, user.status); } @Override diff --git a/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/dao/IFooDao.java b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/repository/IFooDao.java similarity index 87% rename from persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/dao/IFooDao.java rename to persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/repository/IFooDao.java index d2b746dc8b..0b750e37e1 100644 --- a/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/dao/IFooDao.java +++ b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/repository/IFooDao.java @@ -1,11 +1,13 @@ -package com.baeldung.spring.data.persistence.dao; +package com.baeldung.spring.data.persistence.repository; import com.baeldung.spring.data.persistence.model.Foo; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; + public interface IFooDao extends JpaRepository { @Query("SELECT f FROM Foo f WHERE LOWER(f.name) = LOWER(:name)") Foo retrieveByName(@Param("name") String name); + } diff --git a/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/jpaquery/UserRepository.java b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/repository/UserRepository.java similarity index 96% rename from persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/jpaquery/UserRepository.java rename to persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/repository/UserRepository.java index f22970c401..a8e3a536c3 100644 --- a/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/jpaquery/UserRepository.java +++ b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/repository/UserRepository.java @@ -1,9 +1,4 @@ -package com.baeldung.spring.data.persistence.jpaquery; - -import java.time.LocalDate; -import java.util.Collection; -import java.util.List; -import java.util.stream.Stream; +package com.baeldung.spring.data.persistence.repository; import com.baeldung.spring.data.persistence.model.User; import org.springframework.data.domain.Page; @@ -14,13 +9,18 @@ import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; +import java.time.LocalDate; +import java.util.Collection; +import java.util.List; +import java.util.stream.Stream; + public interface UserRepository extends JpaRepository, UserRepositoryCustom { Stream findAllByName(String name); @Query("SELECT u FROM User u WHERE u.status = 1") Collection findAllActiveUsers(); - + @Query("select u from User u where u.email like '%@gmail.com'") List findUsersWithGmailAddress(); @@ -74,14 +74,14 @@ public interface UserRepository extends JpaRepository, UserReposi @Query(value = "INSERT INTO Users (name, age, email, status, active) VALUES (:name, :age, :email, :status, :active)", nativeQuery = true) @Modifying void insertUser(@Param("name") String name, @Param("age") Integer age, @Param("email") String email, @Param("status") Integer status, @Param("active") boolean active); - + @Modifying @Query(value = "UPDATE Users u SET status = ? WHERE u.name = ?", nativeQuery = true) int updateUserSetStatusForNameNativePostgres(Integer status, String name); - + @Query(value = "SELECT u FROM User u WHERE u.name IN :names") - List findUserByNameList(@Param("names") Collection names); - + List findUserByNameList(@Param("names") Collection names); + void deleteAllByCreationDateAfter(LocalDate date); @Modifying(clearAutomatically = true, flushAutomatically = true) diff --git a/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/jpaquery/UserRepositoryCustom.java b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/repository/UserRepositoryCustom.java similarity index 85% rename from persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/jpaquery/UserRepositoryCustom.java rename to persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/repository/UserRepositoryCustom.java index 8bfcb93158..77e661bbbe 100644 --- a/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/jpaquery/UserRepositoryCustom.java +++ b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/repository/UserRepositoryCustom.java @@ -1,14 +1,16 @@ -package com.baeldung.spring.data.persistence.jpaquery; +package com.baeldung.spring.data.persistence.repository; + +import com.baeldung.spring.data.persistence.model.User; import java.util.Collection; import java.util.List; import java.util.Set; import java.util.function.Predicate; -import com.baeldung.spring.data.persistence.model.User; - public interface UserRepositoryCustom { + List findUserByEmails(Set emails); List findAllUsersByPredicates(Collection> predicates); + } diff --git a/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/jpaquery/UserRepositoryCustomImpl.java b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/repository/UserRepositoryCustomImpl.java similarity index 85% rename from persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/jpaquery/UserRepositoryCustomImpl.java rename to persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/repository/UserRepositoryCustomImpl.java index f264ca0b44..366b2c54d0 100644 --- a/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/jpaquery/UserRepositoryCustomImpl.java +++ b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/repository/UserRepositoryCustomImpl.java @@ -1,5 +1,10 @@ -package com.baeldung.spring.data.persistence.jpaquery; +package com.baeldung.spring.data.persistence.repository; +import com.baeldung.spring.data.persistence.model.User; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.criteria.*; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -7,16 +12,6 @@ import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Path; -import javax.persistence.criteria.Predicate; -import javax.persistence.criteria.Root; - -import com.baeldung.spring.data.persistence.model.User; - public class UserRepositoryCustomImpl implements UserRepositoryCustom { @PersistenceContext diff --git a/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/service/impl/FooService.java b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/service/impl/FooService.java index cd566ba9f6..c1406b8602 100644 --- a/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/service/impl/FooService.java +++ b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/service/impl/FooService.java @@ -2,7 +2,7 @@ package com.baeldung.spring.data.persistence.service.impl; import com.baeldung.spring.data.persistence.model.Foo; -import com.baeldung.spring.data.persistence.dao.IFooDao; +import com.baeldung.spring.data.persistence.repository.IFooDao; import com.baeldung.spring.data.persistence.service.IFooService; import com.baeldung.spring.data.persistence.service.common.AbstractService; import org.springframework.beans.factory.annotation.Autowired; diff --git a/persistence-modules/spring-persistence-simple/src/main/resources/springDataPersistenceConfig.xml b/persistence-modules/spring-persistence-simple/src/main/resources/springDataJpaRepositoriesConfig.xml similarity index 60% rename from persistence-modules/spring-persistence-simple/src/main/resources/springDataPersistenceConfig.xml rename to persistence-modules/spring-persistence-simple/src/main/resources/springDataJpaRepositoriesConfig.xml index 5ea2d9c05b..91778a17af 100644 --- a/persistence-modules/spring-persistence-simple/src/main/resources/springDataPersistenceConfig.xml +++ b/persistence-modules/spring-persistence-simple/src/main/resources/springDataJpaRepositoriesConfig.xml @@ -1,12 +1,13 @@ - - + \ No newline at end of file diff --git a/persistence-modules/spring-persistence-simple/src/test/java/com/baeldung/spring/data/persistence/jpaquery/UserRepositoryCommon.java b/persistence-modules/spring-persistence-simple/src/test/java/com/baeldung/spring/data/persistence/repository/UserRepositoryCommon.java similarity index 99% rename from persistence-modules/spring-persistence-simple/src/test/java/com/baeldung/spring/data/persistence/jpaquery/UserRepositoryCommon.java rename to persistence-modules/spring-persistence-simple/src/test/java/com/baeldung/spring/data/persistence/repository/UserRepositoryCommon.java index 5874b3c643..13b5b4357d 100644 --- a/persistence-modules/spring-persistence-simple/src/test/java/com/baeldung/spring/data/persistence/jpaquery/UserRepositoryCommon.java +++ b/persistence-modules/spring-persistence-simple/src/test/java/com/baeldung/spring/data/persistence/repository/UserRepositoryCommon.java @@ -1,4 +1,4 @@ -package com.baeldung.spring.data.persistence.jpaquery; +package com.baeldung.spring.data.persistence.repository; import com.baeldung.spring.data.persistence.config.PersistenceConfig; import com.baeldung.spring.data.persistence.model.User; diff --git a/persistence-modules/spring-persistence-simple/src/test/java/com/baeldung/spring/data/persistence/jpaquery/UserRepositoryIntegrationTest.java b/persistence-modules/spring-persistence-simple/src/test/java/com/baeldung/spring/data/persistence/repository/UserRepositoryIntegrationTest.java similarity index 94% rename from persistence-modules/spring-persistence-simple/src/test/java/com/baeldung/spring/data/persistence/jpaquery/UserRepositoryIntegrationTest.java rename to persistence-modules/spring-persistence-simple/src/test/java/com/baeldung/spring/data/persistence/repository/UserRepositoryIntegrationTest.java index 3bffb51917..c76e345fdd 100644 --- a/persistence-modules/spring-persistence-simple/src/test/java/com/baeldung/spring/data/persistence/jpaquery/UserRepositoryIntegrationTest.java +++ b/persistence-modules/spring-persistence-simple/src/test/java/com/baeldung/spring/data/persistence/repository/UserRepositoryIntegrationTest.java @@ -1,8 +1,4 @@ -package com.baeldung.spring.data.persistence.jpaquery; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.time.LocalDate; +package com.baeldung.spring.data.persistence.repository; import com.baeldung.spring.data.persistence.config.PersistenceConfig; import com.baeldung.spring.data.persistence.model.User; @@ -14,9 +10,10 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.support.AnnotationConfigContextLoader; import org.springframework.transaction.annotation.Transactional; -/** - * Created by adam. - */ +import java.time.LocalDate; + +import static org.assertj.core.api.Assertions.assertThat; + @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = { PersistenceConfig.class }, loader = AnnotationConfigContextLoader.class) @DirtiesContext