diff --git a/.gitignore b/.gitignore
index 21586748b7..b981a473f6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -19,6 +19,7 @@
.idea/
*.iml
*.iws
+out/
# Mac
.DS_Store
@@ -27,6 +28,9 @@
log/
target/
+# Gradle
+.gradle/
+
spring-openid/src/main/resources/application.properties
.recommenders/
/spring-hibernate4/nbproject/
diff --git a/akka-streams/pom.xml b/akka-streams/pom.xml
index a885753ce2..7719bb7351 100644
--- a/akka-streams/pom.xml
+++ b/akka-streams/pom.xml
@@ -14,18 +14,19 @@
com.typesafe.akka
- akka-stream_2.11
+ akka-stream_${scala.version}
${akkastreams.version}
com.typesafe.akka
- akka-stream-testkit_2.11
+ akka-stream-testkit_${scala.version}
${akkastreams.version}
2.5.2
+ 2.11
\ No newline at end of file
diff --git a/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/reversingtree/TreeNode.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/reversingtree/TreeNode.java
index 7905b752a9..a6ec2277e5 100644
--- a/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/reversingtree/TreeNode.java
+++ b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/reversingtree/TreeNode.java
@@ -1,42 +1,42 @@
-package com.baeldung.algorithms.reversingtree;
-
-public class TreeNode {
-
- private int value;
- private TreeNode rightChild;
- private TreeNode leftChild;
-
- public int getValue() {
- return value;
- }
-
- public void setValue(int value) {
- this.value = value;
- }
-
- public TreeNode getRightChild() {
- return rightChild;
- }
-
- public void setRightChild(TreeNode rightChild) {
- this.rightChild = rightChild;
- }
-
- public TreeNode getLeftChild() {
- return leftChild;
- }
-
- public void setLeftChild(TreeNode leftChild) {
- this.leftChild = leftChild;
- }
-
- public TreeNode(int value, TreeNode rightChild, TreeNode leftChild) {
- this.value = value;
- this.rightChild = rightChild;
- this.leftChild = leftChild;
- }
-
- public TreeNode(int value) {
- this.value = value;
- }
-}
+package com.baeldung.algorithms.reversingtree;
+
+public class TreeNode {
+
+ private int value;
+ private TreeNode rightChild;
+ private TreeNode leftChild;
+
+ public int getValue() {
+ return value;
+ }
+
+ public void setValue(int value) {
+ this.value = value;
+ }
+
+ public TreeNode getRightChild() {
+ return rightChild;
+ }
+
+ public void setRightChild(TreeNode rightChild) {
+ this.rightChild = rightChild;
+ }
+
+ public TreeNode getLeftChild() {
+ return leftChild;
+ }
+
+ public void setLeftChild(TreeNode leftChild) {
+ this.leftChild = leftChild;
+ }
+
+ public TreeNode(int value, TreeNode leftChild, TreeNode rightChild) {
+ this.value = value;
+ this.rightChild = rightChild;
+ this.leftChild = leftChild;
+ }
+
+ public TreeNode(int value) {
+ this.value = value;
+ }
+}
diff --git a/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/reversingtree/TreeReverser.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/reversingtree/TreeReverser.java
index 6d3a9ddd31..162119d390 100644
--- a/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/reversingtree/TreeReverser.java
+++ b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/reversingtree/TreeReverser.java
@@ -1,68 +1,53 @@
-package com.baeldung.algorithms.reversingtree;
-
-import java.util.LinkedList;
-
-public class TreeReverser {
-
- public TreeNode createBinaryTree() {
-
- TreeNode leaf1 = new TreeNode(3);
- TreeNode leaf2 = new TreeNode(1);
- TreeNode leaf3 = new TreeNode(9);
- TreeNode leaf4 = new TreeNode(6);
-
- TreeNode nodeLeft = new TreeNode(2, leaf1, leaf2);
- TreeNode nodeRight = new TreeNode(7, leaf3, leaf4);
-
- TreeNode root = new TreeNode(4, nodeRight, nodeLeft);
-
- return root;
- }
-
- public void reverseRecursive(TreeNode treeNode) {
- if (treeNode == null) {
- return;
- }
-
- TreeNode temp = treeNode.getLeftChild();
- treeNode.setLeftChild(treeNode.getRightChild());
- treeNode.setRightChild(temp);
-
- reverseRecursive(treeNode.getLeftChild());
- reverseRecursive(treeNode.getRightChild());
- }
-
- public void reverseIterative(TreeNode treeNode) {
- LinkedList queue = new LinkedList();
-
- if (treeNode != null) {
- queue.add(treeNode);
- }
-
- while (!queue.isEmpty()) {
-
- TreeNode node = queue.poll();
- if (node.getLeftChild() != null)
- queue.add(node.getLeftChild());
- if (node.getRightChild() != null)
- queue.add(node.getRightChild());
-
- TreeNode temp = node.getLeftChild();
- node.setLeftChild(node.getRightChild());
- node.setRightChild(temp);
- }
- }
-
- public String toString(TreeNode root) {
- if (root == null) {
- return "";
- }
-
- StringBuffer buffer = new StringBuffer(String.valueOf(root.getValue())).append(" ");
-
- buffer.append(toString(root.getLeftChild()));
- buffer.append(toString(root.getRightChild()));
-
- return buffer.toString();
- }
-}
+package com.baeldung.algorithms.reversingtree;
+
+import java.util.LinkedList;
+
+public class TreeReverser {
+
+ public void reverseRecursive(TreeNode treeNode) {
+ if (treeNode == null) {
+ return;
+ }
+
+ TreeNode temp = treeNode.getLeftChild();
+ treeNode.setLeftChild(treeNode.getRightChild());
+ treeNode.setRightChild(temp);
+
+ reverseRecursive(treeNode.getLeftChild());
+ reverseRecursive(treeNode.getRightChild());
+ }
+
+ public void reverseIterative(TreeNode treeNode) {
+ LinkedList queue = new LinkedList();
+
+ if (treeNode != null) {
+ queue.add(treeNode);
+ }
+
+ while (!queue.isEmpty()) {
+
+ TreeNode node = queue.poll();
+ if (node.getLeftChild() != null)
+ queue.add(node.getLeftChild());
+ if (node.getRightChild() != null)
+ queue.add(node.getRightChild());
+
+ TreeNode temp = node.getLeftChild();
+ node.setLeftChild(node.getRightChild());
+ node.setRightChild(temp);
+ }
+ }
+
+ public String toString(TreeNode root) {
+ if (root == null) {
+ return "";
+ }
+
+ StringBuffer buffer = new StringBuffer(String.valueOf(root.getValue())).append(" ");
+
+ buffer.append(toString(root.getLeftChild()));
+ buffer.append(toString(root.getRightChild()));
+
+ return buffer.toString();
+ }
+}
diff --git a/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/reversingtree/TreeReverserUnitTest.java b/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/reversingtree/TreeReverserUnitTest.java
index cbc265fae1..44fac57361 100644
--- a/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/reversingtree/TreeReverserUnitTest.java
+++ b/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/reversingtree/TreeReverserUnitTest.java
@@ -1,33 +1,47 @@
-package com.baeldung.algorithms.reversingtree;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-import org.junit.jupiter.api.Test;
-
-public class TreeReverserUnitTest {
-
- @Test
- public void givenTreeWhenReversingRecursivelyThenReversed() {
- TreeReverser reverser = new TreeReverser();
-
- TreeNode treeNode = reverser.createBinaryTree();
-
- reverser.reverseRecursive(treeNode);
-
- assertEquals("4 7 9 6 2 3 1", reverser.toString(treeNode)
- .trim());
- }
-
- @Test
- public void givenTreeWhenReversingIterativelyThenReversed() {
- TreeReverser reverser = new TreeReverser();
-
- TreeNode treeNode = reverser.createBinaryTree();
-
- reverser.reverseIterative(treeNode);
-
- assertEquals("4 7 9 6 2 3 1", reverser.toString(treeNode)
- .trim());
- }
-
-}
+package com.baeldung.algorithms.reversingtree;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.api.Test;
+
+public class TreeReverserUnitTest {
+
+ @Test
+ public void givenTreeWhenReversingRecursivelyThenReversed() {
+ TreeReverser reverser = new TreeReverser();
+
+ TreeNode treeNode = createBinaryTree();
+
+ reverser.reverseRecursive(treeNode);
+
+ assertEquals("4 7 9 6 2 3 1", reverser.toString(treeNode)
+ .trim());
+ }
+
+ @Test
+ public void givenTreeWhenReversingIterativelyThenReversed() {
+ TreeReverser reverser = new TreeReverser();
+
+ TreeNode treeNode = createBinaryTree();
+
+ reverser.reverseIterative(treeNode);
+
+ assertEquals("4 7 9 6 2 3 1", reverser.toString(treeNode)
+ .trim());
+ }
+
+ private TreeNode createBinaryTree() {
+
+ TreeNode leaf1 = new TreeNode(1);
+ TreeNode leaf2 = new TreeNode(3);
+ TreeNode leaf3 = new TreeNode(6);
+ TreeNode leaf4 = new TreeNode(9);
+
+ TreeNode nodeRight = new TreeNode(7, leaf3, leaf4);
+ TreeNode nodeLeft = new TreeNode(2, leaf1, leaf2);
+
+ TreeNode root = new TreeNode(4, nodeLeft, nodeRight);
+
+ return root;
+ }
+}
diff --git a/antlr/pom.xml b/antlr/pom.xml
index ac66891598..91b939a882 100644
--- a/antlr/pom.xml
+++ b/antlr/pom.xml
@@ -10,6 +10,14 @@
1.0.0-SNAPSHOT
+
+
+ org.antlr
+ antlr4-runtime
+ ${antlr.version}
+
+
+
@@ -44,13 +52,7 @@
-
-
- org.antlr
- antlr4-runtime
- ${antlr.version}
-
-
+
4.7.1
3.0.0
diff --git a/apache-cxf/sse-jaxrs/sse-jaxrs-client/pom.xml b/apache-cxf/sse-jaxrs/sse-jaxrs-client/pom.xml
index c7acf22c32..be2138e172 100644
--- a/apache-cxf/sse-jaxrs/sse-jaxrs-client/pom.xml
+++ b/apache-cxf/sse-jaxrs/sse-jaxrs-client/pom.xml
@@ -12,9 +12,18 @@
0.0.1-SNAPSHOT
-
- 3.2.0
-
+
+
+ org.apache.cxf
+ cxf-rt-rs-client
+ ${cxf-version}
+
+
+ org.apache.cxf
+ cxf-rt-rs-sse
+ ${cxf-version}
+
+
@@ -45,17 +54,8 @@
-
-
- org.apache.cxf
- cxf-rt-rs-client
- ${cxf-version}
-
-
- org.apache.cxf
- cxf-rt-rs-sse
- ${cxf-version}
-
-
+
+ 3.2.0
+
diff --git a/apache-cxf/sse-jaxrs/sse-jaxrs-server/pom.xml b/apache-cxf/sse-jaxrs/sse-jaxrs-server/pom.xml
index eeb5726ee1..43bbcf1ef4 100644
--- a/apache-cxf/sse-jaxrs/sse-jaxrs-server/pom.xml
+++ b/apache-cxf/sse-jaxrs/sse-jaxrs-server/pom.xml
@@ -13,11 +13,28 @@
0.0.1-SNAPSHOT
-
- 2.4.2
- false
- 18.0.0.2
-
+
+
+
+ javax.ws.rs
+ javax.ws.rs-api
+ 2.1
+ provided
+
+
+ javax.enterprise
+ cdi-api
+ 2.0
+ provided
+
+
+ javax.json.bind
+ javax.json.bind-api
+ 1.0
+ provided
+
+
+
${project.artifactId}
@@ -59,27 +76,10 @@
-
-
-
- javax.ws.rs
- javax.ws.rs-api
- 2.1
- provided
-
-
- javax.enterprise
- cdi-api
- 2.0
- provided
-
-
- javax.json.bind
- javax.json.bind-api
- 1.0
- provided
-
-
-
+
+ 2.4.2
+ false
+ 18.0.0.2
+
diff --git a/apache-meecrowave/pom.xml b/apache-meecrowave/pom.xml
index fb5af69f9b..bb851577e2 100644
--- a/apache-meecrowave/pom.xml
+++ b/apache-meecrowave/pom.xml
@@ -6,6 +6,12 @@
0.0.1
apache-meecrowave
A sample REST API application with Meecrowave
+
+
+ com.baeldung
+ parent-modules
+ 1.0.0-SNAPSHOT
+
diff --git a/apache-meecrowave/src/test/java/com/baeldung/meecrowave/ArticleEndpointsTest.java b/apache-meecrowave/src/test/java/com/baeldung/meecrowave/ArticleEndpointsUnitTest.java
similarity index 96%
rename from apache-meecrowave/src/test/java/com/baeldung/meecrowave/ArticleEndpointsTest.java
rename to apache-meecrowave/src/test/java/com/baeldung/meecrowave/ArticleEndpointsUnitTest.java
index 0dc9773490..f9a06fd7b9 100644
--- a/apache-meecrowave/src/test/java/com/baeldung/meecrowave/ArticleEndpointsTest.java
+++ b/apache-meecrowave/src/test/java/com/baeldung/meecrowave/ArticleEndpointsUnitTest.java
@@ -17,7 +17,7 @@ import okhttp3.Request;
import okhttp3.Response;
@RunWith(MonoMeecrowave.Runner.class)
-public class ArticleEndpointsTest {
+public class ArticleEndpointsUnitTest {
@ConfigurationInject
private Meecrowave.Builder config;
diff --git a/azure/README.md b/azure/README.md
index c60186e1ce..ae8c443660 100644
--- a/azure/README.md
+++ b/azure/README.md
@@ -1,4 +1,4 @@
### Relevant Articles:
-- [Deploy Spring Boot App to Azure](http://www.baeldung.com/spring-boot-azure)
+- [Deploy a Spring Boot App to Azure](http://www.baeldung.com/spring-boot-azure)
diff --git a/blade/README.md b/blade/README.md
index d823de775f..1f2a00ed3f 100644
--- a/blade/README.md
+++ b/blade/README.md
@@ -1,5 +1,5 @@
### Relevant Articles:
-- [Blade - A Complete GuideBook](http://www.baeldung.com/blade)
+- [Blade – A Complete Guidebook](http://www.baeldung.com/blade)
-Run Integration Tests with `mvn integration-test`
\ No newline at end of file
+Run Integration Tests with `mvn integration-test`
diff --git a/cloud-foundry-uaa/cf-uaa-oauth2-client/pom.xml b/cloud-foundry-uaa/cf-uaa-oauth2-client/pom.xml
index 8e31cc41fb..f650498b69 100644
--- a/cloud-foundry-uaa/cf-uaa-oauth2-client/pom.xml
+++ b/cloud-foundry-uaa/cf-uaa-oauth2-client/pom.xml
@@ -2,24 +2,20 @@
4.0.0
-
- org.springframework.boot
- spring-boot-starter-parent
- 2.1.3.RELEASE
-
-
com.example
cf-uaa-oauth2-client
0.0.1-SNAPSHOT
uaa-client-webapp
Demo project for Spring Boot
-
- 1.8
-
+
+ parent-boot-2
+ com.baeldung
+ 0.0.1-SNAPSHOT
+ ../../parent-boot-2
+
-
org.springframework.boot
spring-boot-starter-web
@@ -28,7 +24,6 @@
org.springframework.boot
spring-boot-starter-oauth2-client
-
@@ -40,4 +35,7 @@
+
+ 1.8
+
diff --git a/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/pom.xml b/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/pom.xml
index 9cf8993cd2..710cecbd4e 100644
--- a/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/pom.xml
+++ b/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/pom.xml
@@ -2,24 +2,20 @@
4.0.0
-
- org.springframework.boot
- spring-boot-starter-parent
- 2.1.3.RELEASE
-
-
com.baeldung.cfuaa
cf-uaa-oauth2-resource-server
0.0.1-SNAPSHOT
cf-uaa-oauth2-resource-server
Demo project for Spring Boot
-
- 1.8
-
-
+
+ parent-boot-2
+ com.baeldung
+ 0.0.1-SNAPSHOT
+ ../../parent-boot-2
+
+
-
org.springframework.boot
spring-boot-starter-oauth2-resource-server
@@ -28,7 +24,6 @@
org.springframework.boot
spring-boot-starter-web
-
@@ -40,4 +35,8 @@
+
+ 1.8
+
+
diff --git a/core-groovy-2/README.md b/core-groovy-2/README.md
new file mode 100644
index 0000000000..9701976142
--- /dev/null
+++ b/core-groovy-2/README.md
@@ -0,0 +1,5 @@
+# Groovy
+
+## Relevant articles:
+
+- [String Matching in Groovy](http://www.baeldung.com/)
\ No newline at end of file
diff --git a/core-groovy-2/pom.xml b/core-groovy-2/pom.xml
new file mode 100644
index 0000000000..bbedbf2157
--- /dev/null
+++ b/core-groovy-2/pom.xml
@@ -0,0 +1,80 @@
+
+
+ 4.0.0
+ core-groovy
+ 1.0-SNAPSHOT
+ core-groovy-2
+ jar
+
+
+ com.baeldung
+ parent-modules
+ 1.0.0-SNAPSHOT
+
+
+
+
+ org.codehaus.groovy
+ groovy-all
+ ${groovy-all.version}
+ pom
+
+
+ org.hsqldb
+ hsqldb
+ ${hsqldb.version}
+ test
+
+
+ org.spockframework
+ spock-core
+ ${spock-core.version}
+ test
+
+
+
+
+
+
+ org.codehaus.gmavenplus
+ gmavenplus-plugin
+ ${gmavenplus-plugin.version}
+
+
+
+ compile
+ compileTests
+
+
+
+
+
+ maven-surefire-plugin
+ 2.20.1
+
+ false
+
+ **/*Test.java
+ **/*Spec.java
+
+
+
+
+
+
+
+
+ central
+ http://jcenter.bintray.com
+
+
+
+
+ 2.5.6
+ 2.4.0
+ 1.3-groovy-2.5
+ 1.6.3
+
+
+
diff --git a/core-groovy-2/src/test/groovy/com/baeldung/strings/StringMatchingSpec.groovy b/core-groovy-2/src/test/groovy/com/baeldung/strings/StringMatchingSpec.groovy
new file mode 100644
index 0000000000..3865bc73fa
--- /dev/null
+++ b/core-groovy-2/src/test/groovy/com/baeldung/strings/StringMatchingSpec.groovy
@@ -0,0 +1,44 @@
+package com.baeldung.strings
+
+import spock.lang.Specification
+
+import java.util.regex.Pattern
+
+class StringMatchingSpec extends Specification {
+
+ def "pattern operator example"() {
+ given: "a pattern"
+ def p = ~'foo'
+
+ expect:
+ p instanceof Pattern
+
+ and: "you can use slash strings to avoid escaping of blackslash"
+ def digitPattern = ~/\d*/
+ digitPattern.matcher('4711').matches()
+ }
+
+ def "match operator example"() {
+ expect:
+ 'foobar' ==~ /.*oba.*/
+
+ and: "matching is strict"
+ !('foobar' ==~ /foo/)
+ }
+
+ def "find operator example"() {
+ when: "using the find operator"
+ def matcher = 'foo and bar, baz and buz' =~ /(\w+) and (\w+)/
+
+ then: "will find groups"
+ matcher.size() == 2
+
+ and: "can access groups using array"
+ matcher[0][0] == 'foo and bar'
+ matcher[1][2] == 'buz'
+
+ and: "you can use it as a predicate"
+ 'foobarbaz' =~ /bar/
+ }
+
+}
diff --git a/core-groovy/README.md b/core-groovy/README.md
index 606a317747..321c37be8d 100644
--- a/core-groovy/README.md
+++ b/core-groovy/README.md
@@ -8,6 +8,8 @@
- [Types of Strings in Groovy](https://www.baeldung.com/groovy-strings)
- [A Quick Guide to Iterating a Map in Groovy](https://www.baeldung.com/groovy-map-iterating)
- [An Introduction to Traits in Groovy](https://www.baeldung.com/groovy-traits)
+- [Closures in Groovy](https://www.baeldung.com/groovy-closures)
+- [Finding Elements in Collections in Groovy](https://www.baeldung.com/groovy-collections-find-elements)
- [Lists in Groovy](https://www.baeldung.com/groovy-lists)
- [Converting a String to a Date in Groovy](https://www.baeldung.com/groovy-string-to-date)
-- [Guide to I/O in Groovy](https://www.baeldung.com/groovy-io)
+- [Guide to I/O in Groovy](https://www.baeldung.com/groovy-io)
\ No newline at end of file
diff --git a/core-groovy/src/test/groovy/com/baeldung/strings/StringMatchingSpec.groovy b/core-groovy/src/test/groovy/com/baeldung/strings/StringMatchingSpec.groovy
new file mode 100644
index 0000000000..3865bc73fa
--- /dev/null
+++ b/core-groovy/src/test/groovy/com/baeldung/strings/StringMatchingSpec.groovy
@@ -0,0 +1,44 @@
+package com.baeldung.strings
+
+import spock.lang.Specification
+
+import java.util.regex.Pattern
+
+class StringMatchingSpec extends Specification {
+
+ def "pattern operator example"() {
+ given: "a pattern"
+ def p = ~'foo'
+
+ expect:
+ p instanceof Pattern
+
+ and: "you can use slash strings to avoid escaping of blackslash"
+ def digitPattern = ~/\d*/
+ digitPattern.matcher('4711').matches()
+ }
+
+ def "match operator example"() {
+ expect:
+ 'foobar' ==~ /.*oba.*/
+
+ and: "matching is strict"
+ !('foobar' ==~ /foo/)
+ }
+
+ def "find operator example"() {
+ when: "using the find operator"
+ def matcher = 'foo and bar, baz and buz' =~ /(\w+) and (\w+)/
+
+ then: "will find groups"
+ matcher.size() == 2
+
+ and: "can access groups using array"
+ matcher[0][0] == 'foo and bar'
+ matcher[1][2] == 'buz'
+
+ and: "you can use it as a predicate"
+ 'foobarbaz' =~ /bar/
+ }
+
+}
diff --git a/core-java-11/README.md b/core-java-11/README.md
index b09649f4f1..a4b0e0e59c 100644
--- a/core-java-11/README.md
+++ b/core-java-11/README.md
@@ -6,3 +6,4 @@
- [Java 11 Nest Based Access Control](https://www.baeldung.com/java-nest-based-access-control)
- [Exploring the New HTTP Client in Java 9 and 11](https://www.baeldung.com/java-9-http-client)
- [An Introduction to Epsilon GC: A No-Op Experimental Garbage Collector](https://www.baeldung.com/jvm-epsilon-gc-garbage-collector)
+- [Guide to jlink](https://www.baeldung.com/jlink)
diff --git a/core-java-11/pom.xml b/core-java-11/pom.xml
index a9776d8f3b..933acdbecc 100644
--- a/core-java-11/pom.xml
+++ b/core-java-11/pom.xml
@@ -14,6 +14,14 @@
1.0.0-SNAPSHOT
+
+
+ com.google.guava
+ guava
+ ${guava.version}
+
+
+
@@ -31,6 +39,7 @@
11
11
+ 27.1-jre
diff --git a/core-java-11/src/test/java/com/baeldung/EmptyStringToEmptyOptionalUnitTest.java b/core-java-11/src/test/java/com/baeldung/EmptyStringToEmptyOptionalUnitTest.java
new file mode 100644
index 0000000000..cc429209d4
--- /dev/null
+++ b/core-java-11/src/test/java/com/baeldung/EmptyStringToEmptyOptionalUnitTest.java
@@ -0,0 +1,32 @@
+package com.baeldung;
+
+import com.google.common.base.Strings;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Optional;
+import java.util.function.Predicate;
+
+public class EmptyStringToEmptyOptionalUnitTest {
+
+ @Test
+ public void givenEmptyString_whenFilteringOnOptional_thenEmptyOptionalIsReturned() {
+ String str = "";
+ Optional opt = Optional.ofNullable(str).filter(s -> !s.isEmpty());
+ Assert.assertFalse(opt.isPresent());
+ }
+
+ @Test
+ public void givenEmptyString_whenFilteringOnOptionalInJava11_thenEmptyOptionalIsReturned() {
+ String str = "";
+ Optional opt = Optional.ofNullable(str).filter(Predicate.not(String::isEmpty));
+ Assert.assertFalse(opt.isPresent());
+ }
+
+ @Test
+ public void givenEmptyString_whenPassingResultOfEmptyToNullToOfNullable_thenEmptyOptionalIsReturned() {
+ String str = "";
+ Optional opt = Optional.ofNullable(Strings.emptyToNull(str));
+ Assert.assertFalse(opt.isPresent());
+ }
+}
diff --git a/core-java-12/pom.xml b/core-java-12/pom.xml
index defef5e9d3..c5eec1a4bb 100644
--- a/core-java-12/pom.xml
+++ b/core-java-12/pom.xml
@@ -34,6 +34,7 @@
${maven.compiler.source.version}
${maven.compiler.target.version}
+ --enable-preview
diff --git a/core-java-12/src/test/java/com/baeldung/switchExpression/SwitchUnitTest.java b/core-java-12/src/test/java/com/baeldung/switchExpression/SwitchUnitTest.java
new file mode 100644
index 0000000000..708e416090
--- /dev/null
+++ b/core-java-12/src/test/java/com/baeldung/switchExpression/SwitchUnitTest.java
@@ -0,0 +1,37 @@
+package com.baeldung.switchExpression;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class SwitchUnitTest {
+
+ @Test
+ public void switchJava12(){
+
+ var month = Month.AUG;
+
+ var value = switch(month){
+ case JAN,JUN, JUL -> 3;
+ case FEB,SEP, OCT, NOV, DEC -> 1;
+ case MAR,MAY, APR, AUG -> 2;
+ };
+
+ Assert.assertEquals(value, 2);
+ }
+
+ @Test
+ public void switchLocalVariable(){
+ var month = Month.AUG;
+ int i = switch (month){
+ case JAN,JUN, JUL -> 3;
+ case FEB,SEP, OCT, NOV, DEC -> 1;
+ case MAR,MAY, APR, AUG -> {
+ int j = month.toString().length() * 4;
+ break j;
+ }
+ };
+ Assert.assertEquals(12, i);
+ }
+
+ enum Month {JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC}
+}
diff --git a/core-java-8-2/README.md b/core-java-8-2/README.md
new file mode 100644
index 0000000000..e2b12e8819
--- /dev/null
+++ b/core-java-8-2/README.md
@@ -0,0 +1,6 @@
+=========
+
+## Core Java 8 Cookbooks and Examples (part 2)
+
+### Relevant Articles:
+- [Anonymous Classes in Java](http://www.baeldung.com/)
diff --git a/core-java-8-2/pom.xml b/core-java-8-2/pom.xml
new file mode 100644
index 0000000000..7035f12fb7
--- /dev/null
+++ b/core-java-8-2/pom.xml
@@ -0,0 +1,43 @@
+
+
+ 4.0.0
+ com.baeldung
+ core-java-8-2
+ 0.1.0-SNAPSHOT
+ core-java-8-2
+ jar
+
+
+
+ com.baeldung
+ parent-java
+ 0.0.1-SNAPSHOT
+ ../parent-java
+
+
+
+ UTF-8
+ 1.8
+ 1.8
+
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ ${maven-compiler-plugin.version}
+
+ ${maven.compiler.source}
+ ${maven.compiler.target}
+
+
+
+
+
+
diff --git a/core-java-8-2/src/main/java/com/baeldung/anonymous/Book.java b/core-java-8-2/src/main/java/com/baeldung/anonymous/Book.java
new file mode 100644
index 0000000000..964156e8e4
--- /dev/null
+++ b/core-java-8-2/src/main/java/com/baeldung/anonymous/Book.java
@@ -0,0 +1,15 @@
+package com.baeldung.anonymous;
+
+public class Book {
+
+ final String title;
+
+ public Book(String title) {
+ this.title = title;
+ }
+
+ public String description() {
+ return "Title: " + title;
+ }
+
+}
diff --git a/core-java-8-2/src/main/java/com/baeldung/anonymous/Main.java b/core-java-8-2/src/main/java/com/baeldung/anonymous/Main.java
new file mode 100644
index 0000000000..d4eed69567
--- /dev/null
+++ b/core-java-8-2/src/main/java/com/baeldung/anonymous/Main.java
@@ -0,0 +1,64 @@
+package com.baeldung.anonymous;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Code snippet that illustrates the usage of anonymous classes.
+ *
+ * Note that use of Runnable instances in this example does not demonstrate their
+ * common use.
+ *
+ * @author A. Shcherbakov
+ *
+ */
+public class Main {
+
+ public static void main(String[] args) {
+ final List actions = new ArrayList(2);
+
+ Runnable action = new Runnable() {
+ @Override
+ public void run() {
+ System.out.println("Hello from runnable.");
+ }
+
+ };
+ actions.add(action);
+
+ Book book = new Book("Design Patterns") {
+ @Override
+ public String description() {
+ return "Famous GoF book.";
+ }
+ };
+
+ System.out.println(String.format("Title: %s, description: %s", book.title, book.description()));
+
+ actions.add(new Runnable() {
+ @Override
+ public void run() {
+ System.out.println("Hello from runnable #2.");
+
+ }
+ });
+
+ int count = 1;
+
+ Runnable action2 = new Runnable() {
+ static final int x = 0;
+ // static int y = 0;
+
+ @Override
+ public void run() {
+ System.out.println(String.format("Runnable with captured variables: count = %s, x = %s", count, x));
+ }
+ };
+ actions.add(action2);
+
+ for (Runnable a : actions) {
+ a.run();
+ }
+ }
+
+}
diff --git a/core-java-8-2/src/test/java/com/baeldung/UnitTest.java b/core-java-8-2/src/test/java/com/baeldung/UnitTest.java
new file mode 100644
index 0000000000..9757901f52
--- /dev/null
+++ b/core-java-8-2/src/test/java/com/baeldung/UnitTest.java
@@ -0,0 +1,18 @@
+package com.baeldung;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+/**
+ * Unit test for simple App.
+ */
+public class UnitTest {
+ /**
+ * Stub test
+ */
+ @Test
+ public void givenPreconditions_whenCondition_shouldResult() {
+ assertTrue(true);
+ }
+}
diff --git a/core-java-8/README.md b/core-java-8/README.md
index 99182da390..d11d2debce 100644
--- a/core-java-8/README.md
+++ b/core-java-8/README.md
@@ -3,7 +3,7 @@
## Core Java 8 Cookbooks and Examples
### Relevant Articles:
-- [Java 8 Collectors](http://www.baeldung.com/java-8-collectors)
+- [Guide to Java 8’s Collectors](http://www.baeldung.com/java-8-collectors)
- [Functional Interfaces in Java 8](http://www.baeldung.com/java-8-functional-interfaces)
- [Java 8 – Powerful Comparison with Lambdas](http://www.baeldung.com/java-8-sort-lambda)
- [New Features in Java 8](http://www.baeldung.com/java-8-new-features)
diff --git a/core-java-8/src/main/java/com/baeldung/Adder.java b/core-java-8/src/main/java/com/baeldung/Adder.java
deleted file mode 100644
index e3e100f121..0000000000
--- a/core-java-8/src/main/java/com/baeldung/Adder.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package com.baeldung;
-
-import java.util.function.Consumer;
-import java.util.function.Function;
-
-public interface Adder {
-
- String addWithFunction(Function f);
-
- void addWithConsumer(Consumer f);
-
-}
diff --git a/core-java-8/src/main/java/com/baeldung/AdderImpl.java b/core-java-8/src/main/java/com/baeldung/AdderImpl.java
deleted file mode 100644
index 7852934d55..0000000000
--- a/core-java-8/src/main/java/com/baeldung/AdderImpl.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package com.baeldung;
-
-
-import java.util.function.Consumer;
-import java.util.function.Function;
-
-public class AdderImpl implements Adder {
-
- @Override
- public String addWithFunction(final Function f) {
- return f.apply("Something ");
- }
-
- @Override
- public void addWithConsumer(final Consumer f) {
- }
-
-}
diff --git a/core-java-8/src/main/java/com/baeldung/Bar.java b/core-java-8/src/main/java/com/baeldung/java8/lambda/tips/Bar.java
similarity index 80%
rename from core-java-8/src/main/java/com/baeldung/Bar.java
rename to core-java-8/src/main/java/com/baeldung/java8/lambda/tips/Bar.java
index 6219bddf74..4cf0aa2399 100644
--- a/core-java-8/src/main/java/com/baeldung/Bar.java
+++ b/core-java-8/src/main/java/com/baeldung/java8/lambda/tips/Bar.java
@@ -1,4 +1,4 @@
-package com.baeldung;
+package com.baeldung.java8.lambda.tips;
@FunctionalInterface
diff --git a/core-java-8/src/main/java/com/baeldung/Baz.java b/core-java-8/src/main/java/com/baeldung/java8/lambda/tips/Baz.java
similarity index 80%
rename from core-java-8/src/main/java/com/baeldung/Baz.java
rename to core-java-8/src/main/java/com/baeldung/java8/lambda/tips/Baz.java
index 23180551ac..c7efe14c89 100644
--- a/core-java-8/src/main/java/com/baeldung/Baz.java
+++ b/core-java-8/src/main/java/com/baeldung/java8/lambda/tips/Baz.java
@@ -1,4 +1,4 @@
-package com.baeldung;
+package com.baeldung.java8.lambda.tips;
@FunctionalInterface
diff --git a/core-java-8/src/main/java/com/baeldung/Foo.java b/core-java-8/src/main/java/com/baeldung/java8/lambda/tips/Foo.java
similarity index 75%
rename from core-java-8/src/main/java/com/baeldung/Foo.java
rename to core-java-8/src/main/java/com/baeldung/java8/lambda/tips/Foo.java
index c8223727a1..b63ba61e7e 100644
--- a/core-java-8/src/main/java/com/baeldung/Foo.java
+++ b/core-java-8/src/main/java/com/baeldung/java8/lambda/tips/Foo.java
@@ -1,4 +1,4 @@
-package com.baeldung;
+package com.baeldung.java8.lambda.tips;
@FunctionalInterface
diff --git a/core-java-8/src/main/java/com/baeldung/FooExtended.java b/core-java-8/src/main/java/com/baeldung/java8/lambda/tips/FooExtended.java
similarity index 81%
rename from core-java-8/src/main/java/com/baeldung/FooExtended.java
rename to core-java-8/src/main/java/com/baeldung/java8/lambda/tips/FooExtended.java
index 8c9b21e397..9141cd8eb8 100644
--- a/core-java-8/src/main/java/com/baeldung/FooExtended.java
+++ b/core-java-8/src/main/java/com/baeldung/java8/lambda/tips/FooExtended.java
@@ -1,4 +1,4 @@
-package com.baeldung;
+package com.baeldung.java8.lambda.tips;
@FunctionalInterface
diff --git a/core-java-8/src/main/java/com/baeldung/java8/lambda/tips/Processor.java b/core-java-8/src/main/java/com/baeldung/java8/lambda/tips/Processor.java
new file mode 100644
index 0000000000..7931129cf5
--- /dev/null
+++ b/core-java-8/src/main/java/com/baeldung/java8/lambda/tips/Processor.java
@@ -0,0 +1,12 @@
+package com.baeldung.java8.lambda.tips;
+
+import java.util.concurrent.Callable;
+import java.util.function.Supplier;
+
+public interface Processor {
+
+ String processWithCallable(Callable c) throws Exception;
+
+ String processWithSupplier(Supplier s);
+
+}
diff --git a/core-java-8/src/main/java/com/baeldung/java8/lambda/tips/ProcessorImpl.java b/core-java-8/src/main/java/com/baeldung/java8/lambda/tips/ProcessorImpl.java
new file mode 100644
index 0000000000..cb1b3dcdd2
--- /dev/null
+++ b/core-java-8/src/main/java/com/baeldung/java8/lambda/tips/ProcessorImpl.java
@@ -0,0 +1,20 @@
+package com.baeldung.java8.lambda.tips;
+
+
+import java.util.concurrent.Callable;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.function.Supplier;
+
+public class ProcessorImpl implements Processor {
+
+ @Override
+ public String processWithCallable(Callable c) throws Exception {
+ return c.call();
+ }
+
+ @Override
+ public String processWithSupplier(Supplier s) {
+ return s.get();
+ }
+}
diff --git a/core-java-8/src/main/java/com/baeldung/UseFoo.java b/core-java-8/src/main/java/com/baeldung/java8/lambda/tips/UseFoo.java
similarity index 95%
rename from core-java-8/src/main/java/com/baeldung/UseFoo.java
rename to core-java-8/src/main/java/com/baeldung/java8/lambda/tips/UseFoo.java
index 950d02062d..a64d8bb920 100644
--- a/core-java-8/src/main/java/com/baeldung/UseFoo.java
+++ b/core-java-8/src/main/java/com/baeldung/java8/lambda/tips/UseFoo.java
@@ -1,4 +1,4 @@
-package com.baeldung;
+package com.baeldung.java8.lambda.tips;
import java.util.function.Function;
diff --git a/core-java-8/src/test/java/com/baeldung/java8/Java8FunctionalInteracesLambdasUnitTest.java b/core-java-8/src/test/java/com/baeldung/java8/lambda/tips/Java8FunctionalInteracesLambdasUnitTest.java
similarity index 93%
rename from core-java-8/src/test/java/com/baeldung/java8/Java8FunctionalInteracesLambdasUnitTest.java
rename to core-java-8/src/test/java/com/baeldung/java8/lambda/tips/Java8FunctionalInteracesLambdasUnitTest.java
index 13ddcc805f..b409f8e37f 100644
--- a/core-java-8/src/test/java/com/baeldung/java8/Java8FunctionalInteracesLambdasUnitTest.java
+++ b/core-java-8/src/test/java/com/baeldung/java8/lambda/tips/Java8FunctionalInteracesLambdasUnitTest.java
@@ -1,8 +1,8 @@
-package com.baeldung.java8;
+package com.baeldung.java8.lambda.tips;
-import com.baeldung.Foo;
-import com.baeldung.FooExtended;
-import com.baeldung.UseFoo;
+import com.baeldung.java8.lambda.tips.Foo;
+import com.baeldung.java8.lambda.tips.FooExtended;
+import com.baeldung.java8.lambda.tips.UseFoo;
import org.junit.Before;
import org.junit.Test;
diff --git a/core-java-9/README.md b/core-java-9/README.md
index 2477a38c00..8fdc3f6ee2 100644
--- a/core-java-9/README.md
+++ b/core-java-9/README.md
@@ -5,26 +5,21 @@
[Java 9 New Features](http://www.baeldung.com/new-java-9)
### Relevant Articles:
-- [Java 9 Stream API Improvements](http://www.baeldung.com/java-9-stream-api)
-- [Java 9 Convenience Factory Methods for Collections](http://www.baeldung.com/java-9-collections-factory-methods)
+
+- [Java 9 New Features](https://www.baeldung.com/new-java-9)
- [New Stream Collectors in Java 9](http://www.baeldung.com/java9-stream-collectors)
-- [Java 9 CompletableFuture API Improvements](http://www.baeldung.com/java-9-completablefuture)
-- [Introduction to Java 9 StackWalking API](http://www.baeldung.com/java-9-stackwalking-api)
- [Introduction to Project Jigsaw](http://www.baeldung.com/project-jigsaw-java-modularity)
-- [Java 9 Optional API Additions](http://www.baeldung.com/java-9-optional)
-- [Java 9 Reactive Streams](http://www.baeldung.com/java-9-reactive-streams)
-- [Java 9 java.util.Objects Additions](http://www.baeldung.com/java-9-objects-new)
-- [Java 9 Variable Handles Demistyfied](http://www.baeldung.com/java-variable-handles)
+- [Java 9 Variable Handles Demystified](http://www.baeldung.com/java-variable-handles)
- [Exploring the New HTTP Client in Java 9 and 11](http://www.baeldung.com/java-9-http-client)
- [Method Handles in Java](http://www.baeldung.com/java-method-handles)
- [Introduction to Chronicle Queue](http://www.baeldung.com/java-chronicle-queue)
-- [A Guide to Java 9 Modularity](http://www.baeldung.com/java-9-modularity)
- [Optional orElse Optional](http://www.baeldung.com/java-optional-or-else-optional)
-- [Java 9 java.lang.Module API](http://www.baeldung.com/java-9-module-api)
- [Iterate Through a Range of Dates in Java](https://www.baeldung.com/java-iterate-date-range)
- [Initialize a HashMap in Java](https://www.baeldung.com/java-initialize-hashmap)
-- [Java 9 Platform Logging API](https://www.baeldung.com/java-9-logging-api)
- [Immutable Set in Java](https://www.baeldung.com/java-immutable-set)
- [Multi-Release Jar Files](https://www.baeldung.com/java-multi-release-jar)
- [Ahead of Time Compilation (AoT)](https://www.baeldung.com/ahead-of-time-compilation)
+- [Java 9 Process API Improvements](https://www.baeldung.com/java-9-process-api)
+- [Guide to java.lang.Process API](https://www.baeldung.com/java-process-api)
+
diff --git a/core-java-collections-map/README.md b/core-java-collections-map/README.md
new file mode 100644
index 0000000000..da02928118
--- /dev/null
+++ b/core-java-collections-map/README.md
@@ -0,0 +1,6 @@
+=========
+
+## Core Java Collections 2
+
+### Relevant Articles:
+- Java - Copying a HashMap
diff --git a/core-java-collections-map/pom.xml b/core-java-collections-map/pom.xml
new file mode 100644
index 0000000000..8c0aef54bf
--- /dev/null
+++ b/core-java-collections-map/pom.xml
@@ -0,0 +1,78 @@
+
+ 4.0.0
+ core-java-collections-map
+ 0.1.0-SNAPSHOT
+ core-java-collections-map
+ jar
+
+
+ com.baeldung
+ parent-java
+ 0.0.1-SNAPSHOT
+ ../parent-java
+
+
+
+
+ org.apache.commons
+ commons-collections4
+ ${commons-collections4.version}
+
+
+ org.apache.commons
+ commons-lang3
+ ${commons-lang3.version}
+
+
+ org.eclipse.collections
+ eclipse-collections
+ ${eclipse.collections.version}
+
+
+ org.assertj
+ assertj-core
+ ${assertj.version}
+ test
+
+
+ org.junit.platform
+ junit-platform-runner
+ ${junit.platform.version}
+ test
+
+
+ org.openjdk.jmh
+ jmh-core
+ ${openjdk.jmh.version}
+
+
+ org.openjdk.jmh
+ jmh-generator-annprocess
+ ${openjdk.jmh.version}
+
+
+ org.apache.commons
+ commons-exec
+ ${commons-exec.version}
+
+
+ org.projectlombok
+ lombok
+ ${lombok.version}
+ provided
+
+
+
+
+ 1.19
+ 1.2.0
+ 3.8.1
+ 4.1
+ 4.01
+ 1.7.0
+ 3.11.1
+ 7.1.0
+ 1.3
+
+
diff --git a/core-java-collections-map/src/main/java/com/baeldung/copyinghashmap/CopyHashMap.java b/core-java-collections-map/src/main/java/com/baeldung/copyinghashmap/CopyHashMap.java
new file mode 100644
index 0000000000..e1649f593c
--- /dev/null
+++ b/core-java-collections-map/src/main/java/com/baeldung/copyinghashmap/CopyHashMap.java
@@ -0,0 +1,55 @@
+package com.baeldung.copyinghashmap;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.apache.commons.lang3.SerializationUtils;
+
+public class CopyHashMap {
+
+ public static HashMap copyUsingConstructor(HashMap originalMap) {
+ return new HashMap(originalMap);
+ }
+
+ public static HashMap copyUsingClone(HashMap originalMap) {
+ return (HashMap) originalMap.clone();
+ }
+
+ public static HashMap copyUsingPut(HashMap originalMap) {
+ HashMap shallowCopy = new HashMap();
+ Set> entries = originalMap.entrySet();
+ for(Map.Entry mapEntry: entries) {
+ shallowCopy.put(mapEntry.getKey(), mapEntry.getValue());
+ }
+
+ return shallowCopy;
+ }
+
+ public static HashMap copyUsingPutAll(HashMap originalMap) {
+ HashMap shallowCopy = new HashMap();
+ shallowCopy.putAll(originalMap);
+
+ return shallowCopy;
+ }
+
+ public static HashMap copyUsingJava8Stream(HashMap originalMap) {
+ Set> entries = originalMap.entrySet();
+ HashMap shallowCopy = (HashMap) entries
+ .stream()
+ .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
+
+ return shallowCopy;
+ }
+
+ public static HashMap shallowCopy(HashMap originalMap) {
+ return (HashMap) originalMap.clone();
+ }
+
+ public static HashMap deepCopy(HashMap originalMap) {
+ return SerializationUtils.clone(originalMap);
+ }
+
+}
diff --git a/core-java-collections-map/src/test/java/com/baeldung/copyinghashmap/CopyHashMapUnitTest.java b/core-java-collections-map/src/test/java/com/baeldung/copyinghashmap/CopyHashMapUnitTest.java
new file mode 100644
index 0000000000..400696d97a
--- /dev/null
+++ b/core-java-collections-map/src/test/java/com/baeldung/copyinghashmap/CopyHashMapUnitTest.java
@@ -0,0 +1,77 @@
+package com.baeldung.copyinghashmap;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableMap;
+
+public class CopyHashMapUnitTest {
+
+ @Test
+ public void givenHashMap_whenShallowCopy_thenCopyisNotSameAsOriginal() {
+
+ HashMap map = new HashMap<>();
+ Employee emp1 = new Employee("John");
+ Employee emp2 = new Employee("Norman");
+ map.put("emp1",emp1);
+ map.put("emp2",emp2);
+
+ HashMap shallowCopy = CopyHashMap.shallowCopy(map);
+
+ assertThat(shallowCopy).isNotSameAs(map);
+
+ }
+
+ @Test
+ public void givenHashMap_whenShallowCopyModifyingOriginalObject_thenCopyShouldChange() {
+
+ HashMap map = new HashMap<>();
+ Employee emp1 = new Employee("John");
+ Employee emp2 = new Employee("Norman");
+ map.put("emp1",emp1);
+ map.put("emp2",emp2);
+
+ HashMap shallowCopy = CopyHashMap.shallowCopy(map);
+
+ emp1.setName("Johny");
+
+ assertThat(shallowCopy.get("emp1")).isEqualTo(map.get("emp1"));
+
+ }
+
+ @Test
+ public void givenHashMap_whenDeepCopyModifyingOriginalObject_thenCopyShouldNotChange() {
+
+ HashMap map = new HashMap<>();
+ Employee emp1 = new Employee("John");
+ Employee emp2 = new Employee("Norman");
+ map.put("emp1",emp1);
+ map.put("emp2",emp2);
+ HashMap deepCopy = CopyHashMap.deepCopy(map);
+
+ emp1.setName("Johny");
+
+ assertThat(deepCopy.get("emp1")).isNotEqualTo(map.get("emp1"));
+
+ }
+
+ @Test
+ public void givenImmutableMap_whenCopyUsingGuava_thenCopyShouldNotChange() {
+ Employee emp1 = new Employee("John");
+ Employee emp2 = new Employee("Norman");
+
+ Map map = ImmutableMap. builder()
+ .put("emp1",emp1)
+ .put("emp2",emp2)
+ .build();
+ Map shallowCopy = ImmutableMap.copyOf(map);
+
+ assertThat(shallowCopy).isSameAs(map);
+
+ }
+
+}
diff --git a/core-java-collections-map/src/test/java/com/baeldung/copyinghashmap/Employee.java b/core-java-collections-map/src/test/java/com/baeldung/copyinghashmap/Employee.java
new file mode 100644
index 0000000000..b47fdc768e
--- /dev/null
+++ b/core-java-collections-map/src/test/java/com/baeldung/copyinghashmap/Employee.java
@@ -0,0 +1,28 @@
+package com.baeldung.copyinghashmap;
+
+import java.io.Serializable;
+
+public class Employee implements Serializable{
+
+ private String name;
+
+ public Employee(String name) {
+ super();
+ this.name = name;
+ }
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String toString() {
+ return this.name;
+ }
+
+}
+
+
diff --git a/core-java-collections/README.md b/core-java-collections/README.md
index 1e504ded65..43f5bfc384 100644
--- a/core-java-collections/README.md
+++ b/core-java-collections/README.md
@@ -3,7 +3,7 @@
## Core Java Collections Cookbooks and Examples
### Relevant Articles:
-- [Java - Combine Multiple Collections](http://www.baeldung.com/java-combine-multiple-collections)
+- [Java – Combine Multiple Collections](http://www.baeldung.com/java-combine-multiple-collections)
- [HashSet and TreeSet Comparison](http://www.baeldung.com/java-hashset-vs-treeset)
- [Collect a Java Stream to an Immutable Collection](http://www.baeldung.com/java-stream-immutable-collection)
- [Introduction to the Java ArrayDeque](http://www.baeldung.com/java-array-deque)
diff --git a/core-java-concurrency-advanced/README.md b/core-java-concurrency-advanced/README.md
index f48fd30c73..8e99858693 100644
--- a/core-java-concurrency-advanced/README.md
+++ b/core-java-concurrency-advanced/README.md
@@ -12,7 +12,7 @@
- [Guide to the Java Phaser](http://www.baeldung.com/java-phaser)
- [An Introduction to Atomic Variables in Java](http://www.baeldung.com/java-atomic-variables)
- [CyclicBarrier in Java](http://www.baeldung.com/java-cyclic-barrier)
-- [Guide to Volatile Keyword in Java](http://www.baeldung.com/java-volatile)
+- [Guide to the Volatile Keyword in Java](http://www.baeldung.com/java-volatile)
- [Semaphores in Java](http://www.baeldung.com/java-semaphore)
- [Daemon Threads in Java](http://www.baeldung.com/java-daemon-thread)
- [Priority-based Job Scheduling in Java](http://www.baeldung.com/java-priority-job-schedule)
@@ -20,6 +20,6 @@
- [Print Even and Odd Numbers Using 2 Threads](https://www.baeldung.com/java-even-odd-numbers-with-2-threads)
- [Java CyclicBarrier vs CountDownLatch](https://www.baeldung.com/java-cyclicbarrier-countdownlatch)
- [Guide to the Fork/Join Framework in Java](http://www.baeldung.com/java-fork-join)
-- [A Guide to ThreadLocalRandom in Java](http://www.baeldung.com/java-thread-local-random)
+- [Guide to ThreadLocalRandom in Java](http://www.baeldung.com/java-thread-local-random)
- [The Thread.join() Method in Java](http://www.baeldung.com/java-thread-join)
- [Passing Parameters to Java Threads](https://www.baeldung.com/java-thread-parameters)
diff --git a/core-java-concurrency-basic/README.md b/core-java-concurrency-basic/README.md
index 7d106095e7..6fa702fbe7 100644
--- a/core-java-concurrency-basic/README.md
+++ b/core-java-concurrency-basic/README.md
@@ -7,13 +7,13 @@
- [A Guide to the Java ExecutorService](http://www.baeldung.com/java-executor-service-tutorial)
- [Guide to java.util.concurrent.Future](http://www.baeldung.com/java-future)
- [Difference Between Wait and Sleep in Java](http://www.baeldung.com/java-wait-and-sleep)
-- [Guide to Synchronized Keyword in Java](http://www.baeldung.com/java-synchronized)
+- [Guide to the Synchronized Keyword in Java](http://www.baeldung.com/java-synchronized)
- [Overview of the java.util.concurrent](http://www.baeldung.com/java-util-concurrent)
- [Implementing a Runnable vs Extending a Thread](http://www.baeldung.com/java-runnable-vs-extending-thread)
- [How to Kill a Java Thread](http://www.baeldung.com/java-thread-stop)
-- [ExecutorService - Waiting for Threads to Finish](http://www.baeldung.com/java-executor-wait-for-threads)
+- [ExecutorService – Waiting for Threads to Finish](http://www.baeldung.com/java-executor-wait-for-threads)
- [wait and notify() Methods in Java](http://www.baeldung.com/java-wait-notify)
- [Life Cycle of a Thread in Java](http://www.baeldung.com/java-thread-lifecycle)
- [Runnable vs. Callable in Java](http://www.baeldung.com/java-runnable-callable)
-- [What is Thread-Safety and How to Achieve it](https://www.baeldung.com/java-thread-safety)
+- [What is Thread-Safety and How to Achieve it?](https://www.baeldung.com/java-thread-safety)
- [How to Start a Thread in Java](https://www.baeldung.com/java-start-thread)
diff --git a/core-java-io/README.md b/core-java-io/README.md
index 05b9165147..9ce39459dd 100644
--- a/core-java-io/README.md
+++ b/core-java-io/README.md
@@ -6,7 +6,7 @@
- [How to Read a Large File Efficiently with Java](http://www.baeldung.com/java-read-lines-large-file)
- [Java InputStream to String](http://www.baeldung.com/convert-input-stream-to-string)
- [Java – Write to File](http://www.baeldung.com/java-write-to-file)
-- [Java - Convert File to InputStream](http://www.baeldung.com/convert-file-to-input-stream)
+- [Java – Convert File to InputStream](http://www.baeldung.com/convert-file-to-input-stream)
- [Java Scanner](http://www.baeldung.com/java-scanner)
- [Java – Byte Array to Writer](http://www.baeldung.com/java-convert-byte-array-to-writer)
- [Java – Directory Size](http://www.baeldung.com/java-folder-size)
@@ -14,7 +14,7 @@
- [File Size in Java](http://www.baeldung.com/java-file-size)
- [Comparing getPath(), getAbsolutePath(), and getCanonicalPath() in Java](http://www.baeldung.com/java-path)
- [Using Java MappedByteBuffer](http://www.baeldung.com/java-mapped-byte-buffer)
-- [Copy a File with Java](http://www.baeldung.com/java-copy-file)
+- [How to Copy a File with Java](http://www.baeldung.com/java-copy-file)
- [Java – Append Data to a File](http://www.baeldung.com/java-append-to-file)
- [FileNotFoundException in Java](http://www.baeldung.com/java-filenotfound-exception)
- [How to Read a File in Java](http://www.baeldung.com/reading-file-in-java)
diff --git a/core-java-io/src/test/java/com/baeldung/filechannel/FileChannelUnitTest.java b/core-java-io/src/test/java/com/baeldung/filechannel/FileChannelUnitTest.java
new file mode 100644
index 0000000000..6964ba80e3
--- /dev/null
+++ b/core-java-io/src/test/java/com/baeldung/filechannel/FileChannelUnitTest.java
@@ -0,0 +1,165 @@
+package com.baeldung.filechannel;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.ByteArrayOutputStream;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.nio.ByteBuffer;
+import java.nio.MappedByteBuffer;
+import java.nio.channels.FileChannel;
+import java.nio.channels.FileLock;
+import java.nio.charset.StandardCharsets;
+
+import org.junit.Test;
+
+public class FileChannelUnitTest {
+
+ @Test
+ public void givenFile_whenReadWithFileChannelUsingRandomAccessFile_thenCorrect() throws IOException {
+
+ try (RandomAccessFile reader = new RandomAccessFile("src/test/resources/test_read.in", "r");
+ FileChannel channel = reader.getChannel();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();) {
+
+ int bufferSize = 1024;
+ if (bufferSize > channel.size()) {
+ bufferSize = (int) channel.size();
+ }
+ ByteBuffer buff = ByteBuffer.allocate(bufferSize);
+
+ while (channel.read(buff) > 0) {
+ out.write(buff.array(), 0, buff.position());
+ buff.clear();
+ }
+
+ String fileContent = new String(out.toByteArray(), StandardCharsets.UTF_8);
+
+ assertEquals("Hello world", fileContent);
+ }
+ }
+
+ @Test
+ public void givenFile_whenReadWithFileChannelUsingFileInputStream_thenCorrect() throws IOException {
+
+ try (ByteArrayOutputStream out = new ByteArrayOutputStream();
+ FileInputStream fin = new FileInputStream("src/test/resources/test_read.in");
+ FileChannel channel = fin.getChannel();) {
+
+ int bufferSize = 1024;
+ if (bufferSize > channel.size()) {
+ bufferSize = (int) channel.size();
+ }
+ ByteBuffer buff = ByteBuffer.allocate(bufferSize);
+
+ while (channel.read(buff) > 0) {
+ out.write(buff.array(), 0, buff.position());
+ buff.clear();
+ }
+ String fileContent = new String(out.toByteArray(), StandardCharsets.UTF_8);
+
+ assertEquals("Hello world", fileContent);
+ }
+ }
+
+ @Test
+ public void givenFile_whenReadAFileSectionIntoMemoryWithFileChannel_thenCorrect() throws IOException {
+
+ try (RandomAccessFile reader = new RandomAccessFile("src/test/resources/test_read.in", "r");
+ FileChannel channel = reader.getChannel();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();) {
+
+ MappedByteBuffer buff = channel.map(FileChannel.MapMode.READ_ONLY, 6, 5);
+
+ if (buff.hasRemaining()) {
+ byte[] data = new byte[buff.remaining()];
+ buff.get(data);
+ assertEquals("world", new String(data, StandardCharsets.UTF_8));
+ }
+ }
+ }
+
+ @Test
+ public void whenWriteWithFileChannelUsingRandomAccessFile_thenCorrect() throws IOException {
+ String file = "src/test/resources/test_write_using_filechannel.txt";
+ try (RandomAccessFile writer = new RandomAccessFile(file, "rw");
+ FileChannel channel = writer.getChannel();) {
+ ByteBuffer buff = ByteBuffer.wrap("Hello world".getBytes(StandardCharsets.UTF_8));
+
+ channel.write(buff);
+
+ // now we verify whether the file was written correctly
+ RandomAccessFile reader = new RandomAccessFile(file, "r");
+ assertEquals("Hello world", reader.readLine());
+ reader.close();
+ }
+ }
+
+ @Test
+ public void givenFile_whenWriteAFileUsingLockAFileSectionWithFileChannel_thenCorrect() throws IOException {
+ try (RandomAccessFile reader = new RandomAccessFile("src/test/resources/test_read.in", "rw");
+ FileChannel channel = reader.getChannel();
+ FileLock fileLock = channel.tryLock(6, 5, Boolean.FALSE);) {
+
+ assertNotNull(fileLock);
+ }
+ }
+
+ @Test
+ public void givenFile_whenReadWithFileChannelGetPosition_thenCorrect() throws IOException {
+
+ try (ByteArrayOutputStream out = new ByteArrayOutputStream();
+ RandomAccessFile reader = new RandomAccessFile("src/test/resources/test_read.in", "r");
+ FileChannel channel = reader.getChannel();) {
+
+ int bufferSize = 1024;
+ if (bufferSize > channel.size()) {
+ bufferSize = (int) channel.size();
+ }
+ ByteBuffer buff = ByteBuffer.allocate(bufferSize);
+
+ while (channel.read(buff) > 0) {
+ out.write(buff.array(), 0, buff.position());
+ buff.clear();
+ }
+
+ // the original file is 11 bytes long, so that's where the position pointer should be
+ assertEquals(11, channel.position());
+
+ channel.position(4);
+ assertEquals(4, channel.position());
+ }
+ }
+
+ @Test
+ public void whenGetFileSize_thenCorrect() throws IOException {
+
+ try (RandomAccessFile reader = new RandomAccessFile("src/test/resources/test_read.in", "r");
+ FileChannel channel = reader.getChannel();) {
+
+ // the original file is 11 bytes long, so that's where the position pointer should be
+ assertEquals(11, channel.size());
+ }
+ }
+
+ @Test
+ public void whenTruncateFile_thenCorrect() throws IOException {
+ String input = "this is a test input";
+
+ FileOutputStream fout = new FileOutputStream("src/test/resources/test_truncate.txt");
+ FileChannel channel = fout.getChannel();
+
+ ByteBuffer buff = ByteBuffer.wrap(input.getBytes());
+ channel.write(buff);
+ buff.flip();
+
+ channel = channel.truncate(5);
+ assertEquals(5, channel.size());
+
+ fout.close();
+ channel.close();
+ }
+}
diff --git a/core-java-io/src/test/resources/test_truncate.txt b/core-java-io/src/test/resources/test_truncate.txt
new file mode 100644
index 0000000000..26d3b38cdd
--- /dev/null
+++ b/core-java-io/src/test/resources/test_truncate.txt
@@ -0,0 +1 @@
+this
\ No newline at end of file
diff --git a/core-java-io/src/test/resources/test_write_using_filechannel.txt b/core-java-io/src/test/resources/test_write_using_filechannel.txt
new file mode 100644
index 0000000000..70c379b63f
--- /dev/null
+++ b/core-java-io/src/test/resources/test_write_using_filechannel.txt
@@ -0,0 +1 @@
+Hello world
\ No newline at end of file
diff --git a/core-java-jvm/README.md b/core-java-jvm/README.md
index 529453f3c4..82067ad952 100644
--- a/core-java-jvm/README.md
+++ b/core-java-jvm/README.md
@@ -3,4 +3,4 @@
## Core Java JVM Cookbooks and Examples
### Relevant Articles:
-- [Method Inlining in the JVM](http://www.baeldung.com/method-inlining-in-the-jvm/)
+- [Method Inlining in the JVM](https://www.baeldung.com/jvm-method-inlining)
diff --git a/core-java-lambdas/pom.xml b/core-java-lambdas/pom.xml
new file mode 100644
index 0000000000..25538a3524
--- /dev/null
+++ b/core-java-lambdas/pom.xml
@@ -0,0 +1,19 @@
+
+
+ 4.0.0
+ core-java-lambdas
+ 0.1.0-SNAPSHOT
+ core-java
+ jar
+
+
+ com.baeldung
+ parent-java
+ 0.0.1-SNAPSHOT
+ ../parent-java
+
+
+
+
\ No newline at end of file
diff --git a/core-java-lambdas/src/main/java/com/baeldung/lambdas/LambdaVariables.java b/core-java-lambdas/src/main/java/com/baeldung/lambdas/LambdaVariables.java
new file mode 100644
index 0000000000..5c1201150f
--- /dev/null
+++ b/core-java-lambdas/src/main/java/com/baeldung/lambdas/LambdaVariables.java
@@ -0,0 +1,88 @@
+package com.baeldung.lambdas;
+
+import java.util.Random;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.function.Supplier;
+import java.util.stream.IntStream;
+
+/**
+ * Class with examples about working with capturing lambdas.
+ */
+public class LambdaVariables {
+
+ private volatile boolean run = true;
+ private int start = 0;
+
+ private ExecutorService executor = Executors.newFixedThreadPool(3);
+
+ public static void main(String[] args) {
+ new LambdaVariables().localVariableMultithreading();
+ }
+
+ Supplier incrementer(int start) {
+ return () -> start; // can't modify start parameter inside the lambda
+ }
+
+ Supplier incrementer() {
+ return () -> start++;
+ }
+
+ public void localVariableMultithreading() {
+ boolean run = true;
+ executor.execute(() -> {
+ while (run) {
+ // do operation
+ }
+ });
+ // commented because it doesn't compile, it's just an example of non-final local variables in lambdas
+ // run = false;
+ }
+
+ public void instanceVariableMultithreading() {
+ executor.execute(() -> {
+ while (run) {
+ // do operation
+ }
+ });
+
+ run = false;
+ }
+
+ /**
+ * WARNING: always avoid this workaround!!
+ */
+ public void workaroundSingleThread() {
+ int[] holder = new int[] { 2 };
+ IntStream sums = IntStream
+ .of(1, 2, 3)
+ .map(val -> val + holder[0]);
+
+ holder[0] = 0;
+
+ System.out.println(sums.sum());
+ }
+
+ /**
+ * WARNING: always avoid this workaround!!
+ */
+ public void workaroundMultithreading() {
+ int[] holder = new int[] { 2 };
+ Runnable runnable = () -> System.out.println(IntStream
+ .of(1, 2, 3)
+ .map(val -> val + holder[0])
+ .sum());
+
+ new Thread(runnable).start();
+
+ // simulating some processing
+ try {
+ Thread.sleep(new Random().nextInt(3) * 1000L);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+
+ holder[0] = 0;
+ }
+
+}
diff --git a/core-java-lang-oop-2/.gitignore b/core-java-lang-oop-2/.gitignore
new file mode 100644
index 0000000000..36aba1c242
--- /dev/null
+++ b/core-java-lang-oop-2/.gitignore
@@ -0,0 +1,4 @@
+target/
+.idea/
+bin/
+*.iml
\ No newline at end of file
diff --git a/core-java-lang-oop-2/README.md b/core-java-lang-oop-2/README.md
new file mode 100644
index 0000000000..e309810ba2
--- /dev/null
+++ b/core-java-lang-oop-2/README.md
@@ -0,0 +1,5 @@
+=========
+
+## Core Java Lang OOP 2 Cookbooks and Examples
+
+### Relevant Articles:
diff --git a/core-java-lang-oop-2/pom.xml b/core-java-lang-oop-2/pom.xml
new file mode 100644
index 0000000000..3faf9fe6ee
--- /dev/null
+++ b/core-java-lang-oop-2/pom.xml
@@ -0,0 +1,27 @@
+
+ 4.0.0
+ com.baeldung
+ core-java-lang-oop-2
+ 0.1.0-SNAPSHOT
+ core-java-lang-oop-2
+ jar
+
+
+ com.baeldung
+ parent-java
+ 0.0.1-SNAPSHOT
+ ../parent-java
+
+
+
+ core-java-lang-oop-2
+
+
+ src/main/resources
+ true
+
+
+
+
+
diff --git a/core-java-lang-oop-2/src/main/java/com/baeldung/generics/Entry.java b/core-java-lang-oop-2/src/main/java/com/baeldung/generics/Entry.java
new file mode 100644
index 0000000000..07759ca9ba
--- /dev/null
+++ b/core-java-lang-oop-2/src/main/java/com/baeldung/generics/Entry.java
@@ -0,0 +1,38 @@
+package com.baeldung.generics;
+
+import java.io.Serializable;
+
+public class Entry {
+ private String data;
+ private int rank;
+
+ // non-generic constructor
+ public Entry(String data, int rank) {
+ this.data = data;
+ this.rank = rank;
+ }
+
+ // generic constructor
+ public Entry(E element) {
+ this.data = element.toString();
+ this.rank = element.getRank();
+ }
+
+ // getters and setters
+ public String getData() {
+ return data;
+ }
+
+ public void setData(String data) {
+ this.data = data;
+ }
+
+ public int getRank() {
+ return rank;
+ }
+
+ public void setRank(int rank) {
+ this.rank = rank;
+ }
+
+}
diff --git a/core-java-lang-oop-2/src/main/java/com/baeldung/generics/GenericEntry.java b/core-java-lang-oop-2/src/main/java/com/baeldung/generics/GenericEntry.java
new file mode 100644
index 0000000000..27d3a44069
--- /dev/null
+++ b/core-java-lang-oop-2/src/main/java/com/baeldung/generics/GenericEntry.java
@@ -0,0 +1,53 @@
+package com.baeldung.generics;
+
+import java.io.Serializable;
+import java.util.Optional;
+
+public class GenericEntry {
+ private T data;
+ private int rank;
+
+ // non-generic constructor
+ public GenericEntry(int rank) {
+ this.rank = rank;
+ }
+
+ // generic constructor
+ public GenericEntry(T data, int rank) {
+ this.data = data;
+ this.rank = rank;
+ }
+
+ // generic constructor with different type
+ public GenericEntry(E element) {
+ this.data = (T) element;
+ this.rank = element.getRank();
+ }
+
+ // generic constructor with different type and wild card
+ public GenericEntry(Optional extends Rankable> optional) {
+ if (optional.isPresent()) {
+ this.data = (T) optional.get();
+ this.rank = optional.get()
+ .getRank();
+ }
+ }
+
+ // getters and setters
+ public T getData() {
+ return data;
+ }
+
+ public void setData(T data) {
+ this.data = data;
+ }
+
+ public int getRank() {
+ return rank;
+ }
+
+ public void setRank(int rank) {
+ this.rank = rank;
+ }
+
+}
diff --git a/core-java-lang-oop-2/src/main/java/com/baeldung/generics/MapEntry.java b/core-java-lang-oop-2/src/main/java/com/baeldung/generics/MapEntry.java
new file mode 100644
index 0000000000..3d626b2fa5
--- /dev/null
+++ b/core-java-lang-oop-2/src/main/java/com/baeldung/generics/MapEntry.java
@@ -0,0 +1,34 @@
+package com.baeldung.generics;
+
+public class MapEntry {
+ private K key;
+ private V value;
+
+ public MapEntry() {
+ super();
+ }
+
+ // generic constructor with two parameters
+ public MapEntry(K key, V value) {
+ this.key = key;
+ this.value = value;
+ }
+
+ // getters and setters
+ public K getKey() {
+ return key;
+ }
+
+ public void setKey(K key) {
+ this.key = key;
+ }
+
+ public V getValue() {
+ return value;
+ }
+
+ public void setValue(V value) {
+ this.value = value;
+ }
+
+}
diff --git a/core-java-lang-oop-2/src/main/java/com/baeldung/generics/Product.java b/core-java-lang-oop-2/src/main/java/com/baeldung/generics/Product.java
new file mode 100644
index 0000000000..bfc9f63071
--- /dev/null
+++ b/core-java-lang-oop-2/src/main/java/com/baeldung/generics/Product.java
@@ -0,0 +1,50 @@
+package com.baeldung.generics;
+
+import java.io.Serializable;
+
+public class Product implements Rankable, Serializable {
+ private String name;
+ private double price;
+ private int sales;
+
+ public Product(String name, double price) {
+ this.name = name;
+ this.price = price;
+ }
+
+ @Override
+ public int getRank() {
+ return sales;
+ }
+
+ @Override
+ public String toString() {
+ return "Product [name=" + name + ", price=" + price + ", sales=" + sales + "]";
+ }
+
+ // getters and setters
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public double getPrice() {
+ return price;
+ }
+
+ public void setPrice(double price) {
+ this.price = price;
+ }
+
+ public int getSales() {
+ return sales;
+ }
+
+ public void setSales(int sales) {
+ this.sales = sales;
+ }
+
+}
diff --git a/core-java-lang-oop-2/src/main/java/com/baeldung/generics/Rankable.java b/core-java-lang-oop-2/src/main/java/com/baeldung/generics/Rankable.java
new file mode 100644
index 0000000000..72bda67d9d
--- /dev/null
+++ b/core-java-lang-oop-2/src/main/java/com/baeldung/generics/Rankable.java
@@ -0,0 +1,5 @@
+package com.baeldung.generics;
+
+public interface Rankable {
+ public int getRank();
+}
diff --git a/core-java-lang-oop-2/src/main/java/com/baeldung/supertypecompilerexception/MyClass.java b/core-java-lang-oop-2/src/main/java/com/baeldung/supertypecompilerexception/MyClass.java
new file mode 100644
index 0000000000..ccf8646f57
--- /dev/null
+++ b/core-java-lang-oop-2/src/main/java/com/baeldung/supertypecompilerexception/MyClass.java
@@ -0,0 +1,16 @@
+package com.baeldung.supertypecompilerexception;
+
+public class MyClass {
+
+ private int myField1 = 10;
+ private int myField2;
+
+ public MyClass() {
+ //uncomment this to see the supertype compiler error:
+ //this(myField1);
+ }
+
+ public MyClass(int i) {
+ myField2 = i;
+ }
+}
\ No newline at end of file
diff --git a/core-java-lang-oop-2/src/main/java/com/baeldung/supertypecompilerexception/MyClassSolution1.java b/core-java-lang-oop-2/src/main/java/com/baeldung/supertypecompilerexception/MyClassSolution1.java
new file mode 100644
index 0000000000..36fa446302
--- /dev/null
+++ b/core-java-lang-oop-2/src/main/java/com/baeldung/supertypecompilerexception/MyClassSolution1.java
@@ -0,0 +1,15 @@
+package com.baeldung.supertypecompilerexception;
+
+public class MyClassSolution1 {
+
+ private int myField1 = 10;
+ private int myField2;
+
+ public MyClassSolution1() {
+ myField2 = myField1;
+ }
+
+ public MyClassSolution1(int i) {
+ myField2 = i;
+ }
+}
diff --git a/core-java-lang-oop-2/src/main/java/com/baeldung/supertypecompilerexception/MyClassSolution2.java b/core-java-lang-oop-2/src/main/java/com/baeldung/supertypecompilerexception/MyClassSolution2.java
new file mode 100644
index 0000000000..adaea4bfbe
--- /dev/null
+++ b/core-java-lang-oop-2/src/main/java/com/baeldung/supertypecompilerexception/MyClassSolution2.java
@@ -0,0 +1,19 @@
+package com.baeldung.supertypecompilerexception;
+
+public class MyClassSolution2 {
+
+ private int myField1 = 10;
+ private int myField2;
+
+ public MyClassSolution2() {
+ setupMyFields(myField1);
+ }
+
+ public MyClassSolution2(int i) {
+ setupMyFields(i);
+ }
+
+ private void setupMyFields(int i) {
+ myField2 = i;
+ }
+}
diff --git a/core-java-lang-oop-2/src/main/java/com/baeldung/supertypecompilerexception/MyClassSolution3.java b/core-java-lang-oop-2/src/main/java/com/baeldung/supertypecompilerexception/MyClassSolution3.java
new file mode 100644
index 0000000000..04048f01db
--- /dev/null
+++ b/core-java-lang-oop-2/src/main/java/com/baeldung/supertypecompilerexception/MyClassSolution3.java
@@ -0,0 +1,15 @@
+package com.baeldung.supertypecompilerexception;
+
+public class MyClassSolution3 {
+
+ private static final int SOME_CONSTANT = 10;
+ private int myField2;
+
+ public MyClassSolution3() {
+ this(SOME_CONSTANT);
+ }
+
+ public MyClassSolution3(int i) {
+ myField2 = i;
+ }
+}
diff --git a/core-java-lang-oop-2/src/main/java/com/baeldung/supertypecompilerexception/MyException.java b/core-java-lang-oop-2/src/main/java/com/baeldung/supertypecompilerexception/MyException.java
new file mode 100644
index 0000000000..db60deb83f
--- /dev/null
+++ b/core-java-lang-oop-2/src/main/java/com/baeldung/supertypecompilerexception/MyException.java
@@ -0,0 +1,14 @@
+package com.baeldung.supertypecompilerexception;
+
+public class MyException extends RuntimeException {
+ private int errorCode = 0;
+
+ public MyException(String message) {
+ //uncomment this to see the supertype compiler error:
+ //super(message + getErrorCode());
+ }
+
+ public int getErrorCode() {
+ return errorCode;
+ }
+}
diff --git a/core-java-lang-oop-2/src/test/java/com/baeldung/generics/GenericConstructorUnitTest.java b/core-java-lang-oop-2/src/test/java/com/baeldung/generics/GenericConstructorUnitTest.java
new file mode 100644
index 0000000000..60907bbfd3
--- /dev/null
+++ b/core-java-lang-oop-2/src/test/java/com/baeldung/generics/GenericConstructorUnitTest.java
@@ -0,0 +1,76 @@
+package com.baeldung.generics;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import java.io.Serializable;
+import java.util.Optional;
+
+import org.junit.Test;
+
+public class GenericConstructorUnitTest {
+
+ @Test
+ public void givenNonGenericConstructor_whenCreateNonGenericEntry_thenOK() {
+ Entry entry = new Entry("sample", 1);
+
+ assertEquals("sample", entry.getData());
+ assertEquals(1, entry.getRank());
+ }
+
+ @Test
+ public void givenGenericConstructor_whenCreateNonGenericEntry_thenOK() {
+ Product product = new Product("milk", 2.5);
+ product.setSales(30);
+ Entry entry = new Entry(product);
+
+ assertEquals(product.toString(), entry.getData());
+ assertEquals(30, entry.getRank());
+ }
+
+ @Test
+ public void givenNonGenericConstructor_whenCreateGenericEntry_thenOK() {
+ GenericEntry entry = new GenericEntry(1);
+
+ assertNull(entry.getData());
+ assertEquals(1, entry.getRank());
+ }
+
+ @Test
+ public void givenGenericConstructor_whenCreateGenericEntry_thenOK() {
+ GenericEntry entry = new GenericEntry("sample", 1);
+
+ assertEquals("sample", entry.getData());
+ assertEquals(1, entry.getRank());
+ }
+
+ @Test
+ public void givenGenericConstructorWithDifferentType_whenCreateGenericEntry_thenOK() {
+ Product product = new Product("milk", 2.5);
+ product.setSales(30);
+ GenericEntry entry = new GenericEntry(product);
+
+ assertEquals(product, entry.getData());
+ assertEquals(30, entry.getRank());
+ }
+
+ @Test
+ public void givenGenericConstructorWithWildCard_whenCreateGenericEntry_thenOK() {
+ Product product = new Product("milk", 2.5);
+ product.setSales(30);
+ Optional optional = Optional.of(product);
+ GenericEntry entry = new GenericEntry(optional);
+
+ assertEquals(product, entry.getData());
+ assertEquals(30, entry.getRank());
+ }
+
+ @Test
+ public void givenGenericConstructor_whenCreateGenericEntryWithTwoTypes_thenOK() {
+ MapEntry entry = new MapEntry("sample", 1);
+
+ assertEquals("sample", entry.getKey());
+ assertEquals(1, entry.getValue()
+ .intValue());
+ }
+}
diff --git a/core-java-lang-oop/README.md b/core-java-lang-oop/README.md
index 970a8d44b1..c9ee9a9e94 100644
--- a/core-java-lang-oop/README.md
+++ b/core-java-lang-oop/README.md
@@ -10,7 +10,7 @@
- [How to Make a Deep Copy of an Object in Java](http://www.baeldung.com/java-deep-copy)
- [Guide to Inheritance in Java](http://www.baeldung.com/java-inheritance)
- [Object Type Casting in Java](http://www.baeldung.com/java-type-casting)
-- [The "final" Keyword in Java](http://www.baeldung.com/java-final)
+- [The “final” Keyword in Java](http://www.baeldung.com/java-final)
- [Type Erasure in Java Explained](http://www.baeldung.com/java-type-erasure)
- [Pass-By-Value as a Parameter Passing Mechanism in Java](http://www.baeldung.com/java-pass-by-value-or-pass-by-reference)
- [Variable and Method Hiding in Java](http://www.baeldung.com/java-variable-method-hiding)
diff --git a/core-java-lang/README.md b/core-java-lang/README.md
index eaedc93eed..e9169a5820 100644
--- a/core-java-lang/README.md
+++ b/core-java-lang/README.md
@@ -12,7 +12,7 @@
- [Dynamic Proxies in Java](http://www.baeldung.com/java-dynamic-proxies)
- [Java Double Brace Initialization](http://www.baeldung.com/java-double-brace-initialization)
- [Guide to the Diamond Operator in Java](http://www.baeldung.com/java-diamond-operator)
-- [Quick Example - Comparator vs Comparable in Java](http://www.baeldung.com/java-comparator-comparable)
+- [Comparator and Comparable in Java](http://www.baeldung.com/java-comparator-comparable)
- [The Java continue and break Keywords](http://www.baeldung.com/java-continue-and-break)
- [Nested Classes in Java](http://www.baeldung.com/java-nested-classes)
- [A Guide to Inner Interfaces in Java](http://www.baeldung.com/java-inner-interfaces)
diff --git a/core-java-networking/README.md b/core-java-networking/README.md
index e76f28030d..2341520df7 100644
--- a/core-java-networking/README.md
+++ b/core-java-networking/README.md
@@ -14,4 +14,5 @@
- [A Guide to Java Sockets](http://www.baeldung.com/a-guide-to-java-sockets)
- [Guide to Java URL Encoding/Decoding](http://www.baeldung.com/java-url-encoding-decoding)
- [Do a Simple HTTP Request in Java](http://www.baeldung.com/java-http-request)
-- [Difference between URL and URI](http://www.baeldung.com/java-url-vs-uri)
\ No newline at end of file
+- [Difference between URL and URI](http://www.baeldung.com/java-url-vs-uri)
+- [Read an InputStream using the Java Server Socket](https://www.baeldung.com/java-inputstream-server-socket)
diff --git a/core-java/README.md b/core-java/README.md
index cbc9251b0b..c2d1b4a06b 100644
--- a/core-java/README.md
+++ b/core-java/README.md
@@ -29,7 +29,7 @@
- [What is the serialVersionUID?](http://www.baeldung.com/java-serial-version-uid)
- [A Guide to the ResourceBundle](http://www.baeldung.com/java-resourcebundle)
- [Class Loaders in Java](http://www.baeldung.com/java-classloaders)
-- [Guide to Java Clock Class](http://www.baeldung.com/java-clock)
+- [Guide to the Java Clock Class](http://www.baeldung.com/java-clock)
- [Importance of Main Manifest Attribute in a Self-Executing JAR](http://www.baeldung.com/java-jar-executable-manifest-main-class)
- [Java Global Exception Handler](http://www.baeldung.com/java-global-exception-handler)
- [How to Get the Size of an Object in Java](http://www.baeldung.com/java-size-of-object)
diff --git a/core-kotlin-2/README.md b/core-kotlin-2/README.md
index 4ac1c2c7bb..6d0b20135d 100644
--- a/core-kotlin-2/README.md
+++ b/core-kotlin-2/README.md
@@ -2,5 +2,8 @@
- [Void Type in Kotlin](https://www.baeldung.com/kotlin-void-type)
- [How to use Kotlin Range Expressions](https://www.baeldung.com/kotlin-ranges)
+- [Creating a Kotlin Range Iterator on a Custom Object](https://www.baeldung.com/kotlin-custom-range-iterator)
+- [Kotlin Scope Functions](https://www.baeldung.com/kotlin-scope-functions)
+- [Kotlin Annotations](https://www.baeldung.com/kotlin-annotations)
- [Split a List into Parts in Kotlin](https://www.baeldung.com/kotlin-split-list-into-parts)
-- [String Comparison in Kotlin](https://www.baeldung.com/kotlin-string-comparison)
+- [String Comparison in Kotlin](https://www.baeldung.com/kotlin-string-comparison)
\ No newline at end of file
diff --git a/core-kotlin-io/.gitignore b/core-kotlin-io/.gitignore
new file mode 100644
index 0000000000..f521947850
--- /dev/null
+++ b/core-kotlin-io/.gitignore
@@ -0,0 +1,11 @@
+/bin/
+
+#ignore gradle
+.gradle/
+
+
+#ignore build and generated files
+build/
+node/
+target/
+out/
diff --git a/core-kotlin-io/README.md b/core-kotlin-io/README.md
new file mode 100644
index 0000000000..c085c0653f
--- /dev/null
+++ b/core-kotlin-io/README.md
@@ -0,0 +1,3 @@
+## Relevant articles:
+
+- [InputStream to String in Kotlin](https://www.baeldung.com/kotlin-inputstream-to-string)
diff --git a/core-kotlin-io/pom.xml b/core-kotlin-io/pom.xml
new file mode 100644
index 0000000000..2e21079d7f
--- /dev/null
+++ b/core-kotlin-io/pom.xml
@@ -0,0 +1,78 @@
+
+
+ 4.0.0
+ core-kotlin-io
+ core-kotlin-io
+ jar
+
+
+ com.baeldung
+ parent-kotlin
+ 1.0.0-SNAPSHOT
+ ../parent-kotlin
+
+
+
+
+ org.jetbrains.kotlin
+ kotlin-stdlib-jdk8
+ ${kotlin.version}
+
+
+ org.junit.platform
+ junit-platform-runner
+ ${junit.platform.version}
+ test
+
+
+ org.assertj
+ assertj-core
+ ${assertj.version}
+ test
+
+
+ org.jetbrains.kotlin
+ kotlin-test
+ ${kotlin.version}
+ test
+
+
+
+
+
+
+ org.jetbrains.kotlin
+ kotlin-maven-plugin
+ ${kotlin.version}
+
+
+ compile
+ compile
+
+ compile
+
+
+
+ test-compile
+ test-compile
+
+ test-compile
+
+
+
+
+ 1.8
+
+
+
+
+
+
+ 1.2.71
+ 1.1.1
+ 5.2.0
+ 3.10.0
+
+
+
\ No newline at end of file
diff --git a/core-kotlin-io/src/main/kotlin/com/baeldung/inputstream/InputStreamExtension.kt b/core-kotlin-io/src/main/kotlin/com/baeldung/inputstream/InputStreamExtension.kt
new file mode 100644
index 0000000000..e94a2e84ee
--- /dev/null
+++ b/core-kotlin-io/src/main/kotlin/com/baeldung/inputstream/InputStreamExtension.kt
@@ -0,0 +1,18 @@
+package com.baeldung.inputstream
+
+import java.io.InputStream
+
+fun InputStream.readUpToChar(stopChar: Char): String {
+ val stringBuilder = StringBuilder()
+ var currentChar = this.read().toChar()
+ while (currentChar != stopChar) {
+ stringBuilder.append(currentChar)
+ currentChar = this.read().toChar()
+ if (this.available() <= 0) {
+ stringBuilder.append(currentChar)
+ break
+ }
+ }
+ return stringBuilder.toString()
+}
+
diff --git a/core-kotlin-io/src/test/kotlin/com/baeldung/inputstream/InputStreamToStringTest.kt b/core-kotlin-io/src/test/kotlin/com/baeldung/inputstream/InputStreamToStringTest.kt
new file mode 100644
index 0000000000..3437ddb68a
--- /dev/null
+++ b/core-kotlin-io/src/test/kotlin/com/baeldung/inputstream/InputStreamToStringTest.kt
@@ -0,0 +1,71 @@
+package com.baeldung.inputstream
+
+import kotlinx.io.core.use
+import org.junit.Test
+import java.io.BufferedReader
+import java.io.File
+import kotlin.test.assertEquals
+
+class InputStreamToStringTest {
+ private val fileName = "src/test/resources/inputstream2string.txt"
+ private val fileFullContent = "Computer programming can be a hassle\r\n" +
+ "It's like trying to take a defended castle"
+
+ @Test
+ fun whenReadFileWithBufferedReader_thenFullFileContentIsReadAsString() {
+ val file = File(fileName)
+ val inputStream = file.inputStream()
+ val content = inputStream.bufferedReader().use(BufferedReader::readText)
+ assertEquals(fileFullContent, content)
+ }
+ @Test
+ fun whenReadFileWithBufferedReaderReadText_thenFullFileContentIsReadAsString() {
+ val file = File(fileName)
+ val inputStream = file.inputStream()
+ val reader = BufferedReader(inputStream.reader())
+ var content: String
+ try {
+ content = reader.readText()
+ } finally {
+ reader.close()
+ }
+ assertEquals(fileFullContent, content)
+ }
+ @Test
+ fun whenReadFileWithBufferedReaderManually_thenFullFileContentIsReadAsString() {
+ val file = File(fileName)
+ val inputStream = file.inputStream()
+ val reader = BufferedReader(inputStream.reader())
+ val content = StringBuilder()
+ try {
+ var line = reader.readLine()
+ while (line != null) {
+ content.append(line)
+ line = reader.readLine()
+ }
+ } finally {
+ reader.close()
+ }
+ assertEquals(fileFullContent.replace("\r\n", ""), content.toString())
+
+ }
+
+ @Test
+ fun whenReadFileUpToStopChar_thenPartBeforeStopCharIsReadAsString() {
+ val file = File(fileName)
+ val inputStream = file.inputStream()
+ val content = inputStream.use { it.readUpToChar(' ') }
+ assertEquals("Computer", content)
+ }
+
+ @Test
+ fun whenReadFileWithoutContainingStopChar_thenFullFileContentIsReadAsString() {
+ val file = File(fileName)
+ val inputStream = file.inputStream()
+ val content = inputStream.use { it.readUpToChar('-') }
+ assertEquals(fileFullContent, content)
+ }
+
+
+}
+
diff --git a/core-kotlin-io/src/test/resources/inputstream2string.txt b/core-kotlin-io/src/test/resources/inputstream2string.txt
new file mode 100644
index 0000000000..40ef9fc5f3
--- /dev/null
+++ b/core-kotlin-io/src/test/resources/inputstream2string.txt
@@ -0,0 +1,2 @@
+Computer programming can be a hassle
+It's like trying to take a defended castle
\ No newline at end of file
diff --git a/core-kotlin/README.md b/core-kotlin/README.md
index 73a78eccff..3392db9171 100644
--- a/core-kotlin/README.md
+++ b/core-kotlin/README.md
@@ -1,7 +1,7 @@
## Relevant articles:
- [Introduction to the Kotlin Language](http://www.baeldung.com/kotlin)
-- [A guide to the “when{}” block in Kotlin](http://www.baeldung.com/kotlin-when)
+- [Guide to the “when{}” Block in Kotlin](http://www.baeldung.com/kotlin-when)
- [Comprehensive Guide to Null Safety in Kotlin](http://www.baeldung.com/kotlin-null-safety)
- [Kotlin Java Interoperability](http://www.baeldung.com/kotlin-java-interoperability)
- [Difference Between “==” and “===” operators in Kotlin](http://www.baeldung.com/kotlin-equality-operators)
diff --git a/core-kotlin/src/main/kotlin/com/baeldung/kotlin/StringUtil.kt b/core-kotlin/src/main/kotlin/com/baeldung/kotlin/StringUtil.kt
new file mode 100644
index 0000000000..ca57b2965e
--- /dev/null
+++ b/core-kotlin/src/main/kotlin/com/baeldung/kotlin/StringUtil.kt
@@ -0,0 +1,9 @@
+@file:JvmName("Strings")
+package com.baeldung.kotlin
+
+fun String.escapeForXml() : String {
+ return this
+ .replace("&", "&")
+ .replace("<", "<")
+ .replace(">", ">")
+}
diff --git a/core-kotlin/src/test/java/com/baeldung/kotlin/StringUtilUnitTest.java b/core-kotlin/src/test/java/com/baeldung/kotlin/StringUtilUnitTest.java
new file mode 100644
index 0000000000..c7ef18b879
--- /dev/null
+++ b/core-kotlin/src/test/java/com/baeldung/kotlin/StringUtilUnitTest.java
@@ -0,0 +1,30 @@
+package com.baeldung.kotlin;
+
+import kotlin.text.StringsKt;
+import org.junit.Assert;
+import org.junit.Test;
+
+import static com.baeldung.kotlin.Strings.*;
+
+
+public class StringUtilUnitTest {
+
+ @Test
+ public void shouldEscapeXmlTagsInString() {
+ String xml = "hi";
+
+ String escapedXml = escapeForXml(xml);
+
+ Assert.assertEquals("<a>hi</a>", escapedXml);
+ }
+
+ @Test
+ public void callingBuiltInKotlinExtensionMethod() {
+ String name = "john";
+
+ String capitalizedName = StringsKt.capitalize(name);
+
+ Assert.assertEquals("John", capitalizedName);
+ }
+
+}
diff --git a/core-kotlin/src/test/kotlin/com/baeldung/kotlin/ExtensionMethods.kt b/core-kotlin/src/test/kotlin/com/baeldung/kotlin/ExtensionMethods.kt
index 09ce898860..44c5cd0ece 100644
--- a/core-kotlin/src/test/kotlin/com/baeldung/kotlin/ExtensionMethods.kt
+++ b/core-kotlin/src/test/kotlin/com/baeldung/kotlin/ExtensionMethods.kt
@@ -6,13 +6,6 @@ import org.junit.Test
class ExtensionMethods {
@Test
fun simpleExtensionMethod() {
- fun String.escapeForXml() : String {
- return this
- .replace("&", "&")
- .replace("<", "<")
- .replace(">", ">")
- }
-
Assert.assertEquals("Nothing", "Nothing".escapeForXml())
Assert.assertEquals("<Tag>", "".escapeForXml())
Assert.assertEquals("a&b", "a&b".escapeForXml())
diff --git a/couchbase/README.md b/couchbase/README.md
index 9b76609593..7a99ce4299 100644
--- a/couchbase/README.md
+++ b/couchbase/README.md
@@ -3,7 +3,7 @@
### Relevant Articles:
- [Introduction to Couchbase SDK for Java](http://www.baeldung.com/java-couchbase-sdk)
- [Using Couchbase in a Spring Application](http://www.baeldung.com/couchbase-sdk-spring)
-- [Asynchronous Batch Opereations in Couchbase](http://www.baeldung.com/async-batch-operations-in-couchbase)
+- [Asynchronous Batch Operations in Couchbase](http://www.baeldung.com/async-batch-operations-in-couchbase)
- [Querying Couchbase with MapReduce Views](http://www.baeldung.com/couchbase-query-mapreduce-view)
- [Querying Couchbase with N1QL](http://www.baeldung.com/n1ql-couchbase)
diff --git a/gson/README.md b/gson/README.md
index fec0506488..268116a2ac 100644
--- a/gson/README.md
+++ b/gson/README.md
@@ -11,6 +11,6 @@
- [Convert JSON to a Map Using Gson](https://www.baeldung.com/gson-json-to-map)
- [Working with Primitive Values in Gson](https://www.baeldung.com/java-gson-primitives)
- [Convert String to JsonObject with Gson](https://www.baeldung.com/gson-string-to-jsonobject)
-- [Mapping Multiple JSON Fields to One Java Field](https://www.baeldung.com/json-multiple-fields-single-java-field)
+- [Mapping Multiple JSON Fields to a Single Java Field](https://www.baeldung.com/json-multiple-fields-single-java-field)
- [Serializing and Deserializing a List with Gson](https://www.baeldung.com/gson-list)
diff --git a/guava-collections-set/.gitignore b/guava-collections-set/.gitignore
new file mode 100644
index 0000000000..83c05e60c8
--- /dev/null
+++ b/guava-collections-set/.gitignore
@@ -0,0 +1,13 @@
+*.class
+
+#folders#
+/target
+/neoDb*
+/data
+/src/main/webapp/WEB-INF/classes
+*/META-INF/*
+
+# Packaged files #
+*.jar
+*.war
+*.ear
\ No newline at end of file
diff --git a/guava-collections-set/pom.xml b/guava-collections-set/pom.xml
new file mode 100644
index 0000000000..46dcae492d
--- /dev/null
+++ b/guava-collections-set/pom.xml
@@ -0,0 +1,37 @@
+
+ 4.0.0
+ com.baeldung
+ guava-collections-set
+ 0.1.0-SNAPSHOT
+ guava-collections-set
+
+
+ com.baeldung
+ parent-java
+ 0.0.1-SNAPSHOT
+ ../parent-java
+
+
+
+
+
+ org.assertj
+ assertj-core
+ ${assertj.version}
+ test
+
+
+
+
+ guava-collections-set
+
+
+
+
+ 27.1-jre
+
+ 3.6.1
+
+
+
diff --git a/guava-collections-set/src/test/java/org/baeldung/guava/GuavaMultiSetUnitTest.java b/guava-collections-set/src/test/java/org/baeldung/guava/GuavaMultiSetUnitTest.java
new file mode 100644
index 0000000000..e74db29881
--- /dev/null
+++ b/guava-collections-set/src/test/java/org/baeldung/guava/GuavaMultiSetUnitTest.java
@@ -0,0 +1,92 @@
+package org.baeldung.guava;
+
+import com.google.common.collect.HashMultiset;
+import com.google.common.collect.Multiset;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class GuavaMultiSetUnitTest {
+
+ @Test
+ public void givenMultiSet_whenAddingValues_shouldReturnCorrectCount() {
+ Multiset bookStore = HashMultiset.create();
+ bookStore.add("Potter");
+ bookStore.add("Potter");
+ bookStore.add("Potter");
+
+ assertThat(bookStore.contains("Potter")).isTrue();
+ assertThat(bookStore.count("Potter")).isEqualTo(3);
+ }
+
+ @Test
+ public void givenMultiSet_whenRemovingValues_shouldReturnCorrectCount() {
+ Multiset bookStore = HashMultiset.create();
+ bookStore.add("Potter");
+ bookStore.add("Potter");
+
+ bookStore.remove("Potter");
+ assertThat(bookStore.contains("Potter")).isTrue();
+ assertThat(bookStore.count("Potter")).isEqualTo(1);
+ }
+
+ @Test
+ public void givenMultiSet_whenSetCount_shouldReturnCorrectCount() {
+ Multiset bookStore = HashMultiset.create();
+ bookStore.setCount("Potter", 50);
+ assertThat(bookStore.count("Potter")).isEqualTo(50);
+ }
+
+ @Test
+ public void givenMultiSet_whenSettingNegativeCount_shouldThrowException() {
+ Multiset bookStore = HashMultiset.create();
+ assertThatThrownBy(() -> bookStore.setCount("Potter", -1))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ public void givenMultiSet_whenSettingCountWithEmptySet_shouldBeSuccessful() {
+ Multiset bookStore = HashMultiset.create();
+ assertThat(bookStore.setCount("Potter", 0, 2)).isTrue();
+ }
+
+ @Test
+ public void givenMultiSet_whenSettingCountWithCorrectValue_shouldBeSuccessful() {
+ Multiset bookStore = HashMultiset.create();
+ bookStore.add("Potter");
+ bookStore.add("Potter");
+
+ assertThat(bookStore.setCount("Potter", 2, 52)).isTrue();
+ }
+
+ @Test
+ public void givenMultiSet_whenSettingCountWithIncorrectValue_shouldFail() {
+ Multiset bookStore = HashMultiset.create();
+ bookStore.add("Potter");
+ bookStore.add("Potter");
+
+ assertThat(bookStore.setCount("Potter", 5, 52)).isFalse();
+ }
+
+ @Test
+ public void givenMap_compareMultiSetOperations() {
+ Map bookStore = new HashMap<>();
+ bookStore.put("Potter", 3);
+
+ assertThat(bookStore.containsKey("Potter")).isTrue();
+ assertThat(bookStore.get("Potter")).isEqualTo(3);
+
+ bookStore.put("Potter", 2);
+ assertThat(bookStore.get("Potter")).isEqualTo(2);
+
+ bookStore.put("Potter", null);
+ assertThat(bookStore.containsKey("Potter")).isTrue();
+
+ bookStore.put("Potter", -1);
+ assertThat(bookStore.containsKey("Potter")).isTrue();
+ }
+}
\ No newline at end of file
diff --git a/guava-modules/guava-21/README.md b/guava-modules/guava-21/README.md
index 68c1ac4a8e..4e897325b6 100644
--- a/guava-modules/guava-21/README.md
+++ b/guava-modules/guava-21/README.md
@@ -1,4 +1,4 @@
### Relevant articles:
-- [New Stream, Comparator and Collector Functionality in Guava 21](http://www.baeldung.com/guava-21-new)
+- [New Stream, Comparator and Collector in Guava 21](http://www.baeldung.com/guava-21-new)
- [New in Guava 21 common.util.concurrent](http://www.baeldung.com/guava-21-util-concurrent)
- [Zipping Collections in Java](http://www.baeldung.com/java-collections-zip)
diff --git a/helidon/helidon-mp/pom.xml b/helidon/helidon-mp/pom.xml
index 1f39431886..82d52ca2ef 100644
--- a/helidon/helidon-mp/pom.xml
+++ b/helidon/helidon-mp/pom.xml
@@ -15,13 +15,18 @@
io.helidon.microprofile.bundles
helidon-microprofile-1.2
- 0.10.4
+ ${helidon-microprofile.version}
org.glassfish.jersey.media
jersey-media-json-binding
- 2.26
+ ${jersey-media-json-binding.version}
+
+ 0.10.4
+ 2.26
+
+
diff --git a/helidon/helidon-se/pom.xml b/helidon/helidon-se/pom.xml
index 8982bf048e..ae16fa16e4 100644
--- a/helidon/helidon-se/pom.xml
+++ b/helidon/helidon-se/pom.xml
@@ -12,10 +12,6 @@
1.0.0-SNAPSHOT
-
- 0.10.4
-
-
@@ -61,4 +57,8 @@
+
+ 0.10.4
+
+
\ No newline at end of file
diff --git a/httpclient/README.md b/httpclient/README.md
index 87fb38706d..c5956068c6 100644
--- a/httpclient/README.md
+++ b/httpclient/README.md
@@ -9,7 +9,7 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
- [HttpClient 4 – Send Custom Cookie](http://www.baeldung.com/httpclient-4-cookies)
- [HttpClient 4 – Get the Status Code](http://www.baeldung.com/httpclient-status-code)
-- [HttpClient 4 – Cancel / Abort Request](http://www.baeldung.com/httpclient-cancel-request)
+- [HttpClient 4 – Cancel Request](http://www.baeldung.com/httpclient-cancel-request)
- [HttpClient 4 Cookbook](http://www.baeldung.com/httpclient4)
- [Unshorten URLs with HttpClient](http://www.baeldung.com/unshorten-url-httpclient)
- [HttpClient 4 – Follow Redirects for POST](http://www.baeldung.com/httpclient-redirect-on-http-post)
diff --git a/jackson-simple/.gitignore b/jackson-simple/.gitignore
new file mode 100644
index 0000000000..83c05e60c8
--- /dev/null
+++ b/jackson-simple/.gitignore
@@ -0,0 +1,13 @@
+*.class
+
+#folders#
+/target
+/neoDb*
+/data
+/src/main/webapp/WEB-INF/classes
+*/META-INF/*
+
+# Packaged files #
+*.jar
+*.war
+*.ear
\ No newline at end of file
diff --git a/jackson-simple/README.md b/jackson-simple/README.md
new file mode 100644
index 0000000000..be647e22d5
--- /dev/null
+++ b/jackson-simple/README.md
@@ -0,0 +1,13 @@
+=========
+### Jackson Articles that are also part of the e-book
+
+###The Course
+The "REST With Spring" Classes: http://bit.ly/restwithspring
+
+### Relevant Articles:
+- [Jackson Ignore Properties on Marshalling](http://www.baeldung.com/jackson-ignore-properties-on-serialization)
+- [Jackson Unmarshalling json with Unknown Properties](http://www.baeldung.com/jackson-deserialize-json-unknown-properties)
+- [Jackson Annotation Examples](http://www.baeldung.com/jackson-annotations)
+- [Intro to the Jackson ObjectMapper](http://www.baeldung.com/jackson-object-mapper-tutorial)
+- [Ignore Null Fields with Jackson](http://www.baeldung.com/jackson-ignore-null-fields)
+- [Jackson – Change Name of Field](http://www.baeldung.com/jackson-name-of-property)
diff --git a/jackson-simple/pom.xml b/jackson-simple/pom.xml
new file mode 100644
index 0000000000..5023ad87b6
--- /dev/null
+++ b/jackson-simple/pom.xml
@@ -0,0 +1,131 @@
+
+ 4.0.0
+ jackson-simple
+ 0.1-SNAPSHOT
+ jackson-simple
+
+
+ com.baeldung
+ parent-java
+ 0.0.1-SNAPSHOT
+ ../parent-java
+
+
+
+
+
+ commons-io
+ commons-io
+ ${commons-io.version}
+
+
+
+ com.fasterxml.jackson.dataformat
+ jackson-dataformat-xml
+ ${jackson.version}
+
+
+
+ org.apache.commons
+ commons-collections4
+ ${commons-collections4.version}
+
+
+
+ org.apache.commons
+ commons-lang3
+ ${commons-lang3.version}
+
+
+
+
+
+ com.fasterxml.jackson.core
+ jackson-databind
+ ${jackson.version}
+
+
+
+ com.fasterxml.jackson.datatype
+ jackson-datatype-jsr310
+ ${jackson.version}
+
+
+
+ com.fasterxml.jackson.datatype
+ jackson-datatype-joda
+ ${jackson.version}
+
+
+
+ com.fasterxml.jackson.module
+ jackson-module-jsonSchema
+ ${jackson.version}
+
+
+
+ com.fasterxml.jackson.datatype
+ jackson-datatype-jdk8
+ ${jackson.version}
+
+
+
+ joda-time
+ joda-time
+ ${joda-time.version}
+
+
+
+ com.google.code.gson
+ gson
+ ${gson.version}
+
+
+
+
+
+ io.rest-assured
+ json-schema-validator
+ ${rest-assured.version}
+ test
+
+
+
+ io.rest-assured
+ json-path
+ ${rest-assured.version}
+ test
+
+
+
+ org.assertj
+ assertj-core
+ ${assertj.version}
+ test
+
+
+
+
+ jackson-simple
+
+
+ src/main/resources
+ true
+
+
+
+
+
+
+ 3.8
+ 2.10
+ 2.8.5
+ 4.2
+
+
+ 3.1.1
+ 3.11.0
+
+
+
diff --git a/jackson-simple/src/main/resources/logback.xml b/jackson-simple/src/main/resources/logback.xml
new file mode 100644
index 0000000000..56af2d397e
--- /dev/null
+++ b/jackson-simple/src/main/resources/logback.xml
@@ -0,0 +1,19 @@
+
+
+
+
+ %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/jackson/src/test/java/com/baeldung/jackson/annotation/AliasBean.java b/jackson-simple/src/test/java/com/baeldung/jackson/annotation/AliasBean.java
similarity index 100%
rename from jackson/src/test/java/com/baeldung/jackson/annotation/AliasBean.java
rename to jackson-simple/src/test/java/com/baeldung/jackson/annotation/AliasBean.java
diff --git a/jackson/src/test/java/com/baeldung/jackson/annotation/BeanWithCreator.java b/jackson-simple/src/test/java/com/baeldung/jackson/annotation/BeanWithCreator.java
similarity index 100%
rename from jackson/src/test/java/com/baeldung/jackson/annotation/BeanWithCreator.java
rename to jackson-simple/src/test/java/com/baeldung/jackson/annotation/BeanWithCreator.java
diff --git a/jackson/src/test/java/com/baeldung/jackson/annotation/BeanWithCustomAnnotation.java b/jackson-simple/src/test/java/com/baeldung/jackson/annotation/BeanWithCustomAnnotation.java
similarity index 100%
rename from jackson/src/test/java/com/baeldung/jackson/annotation/BeanWithCustomAnnotation.java
rename to jackson-simple/src/test/java/com/baeldung/jackson/annotation/BeanWithCustomAnnotation.java
diff --git a/jackson/src/test/java/com/baeldung/jackson/annotation/BeanWithFilter.java b/jackson-simple/src/test/java/com/baeldung/jackson/annotation/BeanWithFilter.java
similarity index 100%
rename from jackson/src/test/java/com/baeldung/jackson/annotation/BeanWithFilter.java
rename to jackson-simple/src/test/java/com/baeldung/jackson/annotation/BeanWithFilter.java
diff --git a/jackson/src/test/java/com/baeldung/jackson/annotation/BeanWithGetter.java b/jackson-simple/src/test/java/com/baeldung/jackson/annotation/BeanWithGetter.java
similarity index 100%
rename from jackson/src/test/java/com/baeldung/jackson/annotation/BeanWithGetter.java
rename to jackson-simple/src/test/java/com/baeldung/jackson/annotation/BeanWithGetter.java
diff --git a/jackson/src/test/java/com/baeldung/jackson/annotation/BeanWithIgnore.java b/jackson-simple/src/test/java/com/baeldung/jackson/annotation/BeanWithIgnore.java
similarity index 100%
rename from jackson/src/test/java/com/baeldung/jackson/annotation/BeanWithIgnore.java
rename to jackson-simple/src/test/java/com/baeldung/jackson/annotation/BeanWithIgnore.java
diff --git a/jackson/src/test/java/com/baeldung/jackson/annotation/BeanWithInject.java b/jackson-simple/src/test/java/com/baeldung/jackson/annotation/BeanWithInject.java
similarity index 100%
rename from jackson/src/test/java/com/baeldung/jackson/annotation/BeanWithInject.java
rename to jackson-simple/src/test/java/com/baeldung/jackson/annotation/BeanWithInject.java
diff --git a/jackson/src/test/java/com/baeldung/jackson/annotation/ExtendableBean.java b/jackson-simple/src/test/java/com/baeldung/jackson/annotation/ExtendableBean.java
similarity index 100%
rename from jackson/src/test/java/com/baeldung/jackson/annotation/ExtendableBean.java
rename to jackson-simple/src/test/java/com/baeldung/jackson/annotation/ExtendableBean.java
diff --git a/jackson/src/test/java/com/baeldung/jackson/annotation/MyBean.java b/jackson-simple/src/test/java/com/baeldung/jackson/annotation/MyBean.java
similarity index 100%
rename from jackson/src/test/java/com/baeldung/jackson/annotation/MyBean.java
rename to jackson-simple/src/test/java/com/baeldung/jackson/annotation/MyBean.java
diff --git a/jackson/src/test/java/com/baeldung/jackson/annotation/PrivateBean.java b/jackson-simple/src/test/java/com/baeldung/jackson/annotation/PrivateBean.java
similarity index 100%
rename from jackson/src/test/java/com/baeldung/jackson/annotation/PrivateBean.java
rename to jackson-simple/src/test/java/com/baeldung/jackson/annotation/PrivateBean.java
diff --git a/jackson/src/test/java/com/baeldung/jackson/annotation/RawBean.java b/jackson-simple/src/test/java/com/baeldung/jackson/annotation/RawBean.java
similarity index 100%
rename from jackson/src/test/java/com/baeldung/jackson/annotation/RawBean.java
rename to jackson-simple/src/test/java/com/baeldung/jackson/annotation/RawBean.java
diff --git a/jackson/src/test/java/com/baeldung/jackson/annotation/UnwrappedUser.java b/jackson-simple/src/test/java/com/baeldung/jackson/annotation/UnwrappedUser.java
similarity index 100%
rename from jackson/src/test/java/com/baeldung/jackson/annotation/UnwrappedUser.java
rename to jackson-simple/src/test/java/com/baeldung/jackson/annotation/UnwrappedUser.java
diff --git a/jackson/src/test/java/com/baeldung/jackson/annotation/UserWithIgnoreType.java b/jackson-simple/src/test/java/com/baeldung/jackson/annotation/UserWithIgnoreType.java
similarity index 100%
rename from jackson/src/test/java/com/baeldung/jackson/annotation/UserWithIgnoreType.java
rename to jackson-simple/src/test/java/com/baeldung/jackson/annotation/UserWithIgnoreType.java
diff --git a/jackson/src/test/java/com/baeldung/jackson/annotation/Zoo.java b/jackson-simple/src/test/java/com/baeldung/jackson/annotation/Zoo.java
similarity index 100%
rename from jackson/src/test/java/com/baeldung/jackson/annotation/Zoo.java
rename to jackson-simple/src/test/java/com/baeldung/jackson/annotation/Zoo.java
diff --git a/jackson-simple/src/test/java/com/baeldung/jackson/bidirection/ItemWithIdentity.java b/jackson-simple/src/test/java/com/baeldung/jackson/bidirection/ItemWithIdentity.java
new file mode 100644
index 0000000000..25de4a8f7a
--- /dev/null
+++ b/jackson-simple/src/test/java/com/baeldung/jackson/bidirection/ItemWithIdentity.java
@@ -0,0 +1,21 @@
+package com.baeldung.jackson.bidirection;
+
+import com.fasterxml.jackson.annotation.JsonIdentityInfo;
+import com.fasterxml.jackson.annotation.ObjectIdGenerators;
+
+@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
+public class ItemWithIdentity {
+ public int id;
+ public String itemName;
+ public UserWithIdentity owner;
+
+ public ItemWithIdentity() {
+ super();
+ }
+
+ public ItemWithIdentity(final int id, final String itemName, final UserWithIdentity owner) {
+ this.id = id;
+ this.itemName = itemName;
+ this.owner = owner;
+ }
+}
diff --git a/jackson-simple/src/test/java/com/baeldung/jackson/bidirection/ItemWithIgnore.java b/jackson-simple/src/test/java/com/baeldung/jackson/bidirection/ItemWithIgnore.java
new file mode 100644
index 0000000000..910ccec174
--- /dev/null
+++ b/jackson-simple/src/test/java/com/baeldung/jackson/bidirection/ItemWithIgnore.java
@@ -0,0 +1,17 @@
+package com.baeldung.jackson.bidirection;
+
+public class ItemWithIgnore {
+ public int id;
+ public String itemName;
+ public UserWithIgnore owner;
+
+ public ItemWithIgnore() {
+ super();
+ }
+
+ public ItemWithIgnore(final int id, final String itemName, final UserWithIgnore owner) {
+ this.id = id;
+ this.itemName = itemName;
+ this.owner = owner;
+ }
+}
diff --git a/jackson-simple/src/test/java/com/baeldung/jackson/bidirection/ItemWithRef.java b/jackson-simple/src/test/java/com/baeldung/jackson/bidirection/ItemWithRef.java
new file mode 100644
index 0000000000..0ca8d721e8
--- /dev/null
+++ b/jackson-simple/src/test/java/com/baeldung/jackson/bidirection/ItemWithRef.java
@@ -0,0 +1,21 @@
+package com.baeldung.jackson.bidirection;
+
+import com.fasterxml.jackson.annotation.JsonManagedReference;
+
+public class ItemWithRef {
+ public int id;
+ public String itemName;
+
+ @JsonManagedReference
+ public UserWithRef owner;
+
+ public ItemWithRef() {
+ super();
+ }
+
+ public ItemWithRef(final int id, final String itemName, final UserWithRef owner) {
+ this.id = id;
+ this.itemName = itemName;
+ this.owner = owner;
+ }
+}
diff --git a/jackson-simple/src/test/java/com/baeldung/jackson/bidirection/UserWithIdentity.java b/jackson-simple/src/test/java/com/baeldung/jackson/bidirection/UserWithIdentity.java
new file mode 100644
index 0000000000..db83a09389
--- /dev/null
+++ b/jackson-simple/src/test/java/com/baeldung/jackson/bidirection/UserWithIdentity.java
@@ -0,0 +1,28 @@
+package com.baeldung.jackson.bidirection;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.fasterxml.jackson.annotation.JsonIdentityInfo;
+import com.fasterxml.jackson.annotation.ObjectIdGenerators;
+
+@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
+public class UserWithIdentity {
+ public int id;
+ public String name;
+ public List userItems;
+
+ public UserWithIdentity() {
+ super();
+ }
+
+ public UserWithIdentity(final int id, final String name) {
+ this.id = id;
+ this.name = name;
+ userItems = new ArrayList();
+ }
+
+ public void addItem(final ItemWithIdentity item) {
+ userItems.add(item);
+ }
+}
diff --git a/jackson-simple/src/test/java/com/baeldung/jackson/bidirection/UserWithIgnore.java b/jackson-simple/src/test/java/com/baeldung/jackson/bidirection/UserWithIgnore.java
new file mode 100644
index 0000000000..857a373cc5
--- /dev/null
+++ b/jackson-simple/src/test/java/com/baeldung/jackson/bidirection/UserWithIgnore.java
@@ -0,0 +1,28 @@
+package com.baeldung.jackson.bidirection;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+
+public class UserWithIgnore {
+ public int id;
+ public String name;
+
+ @JsonIgnore
+ public List userItems;
+
+ public UserWithIgnore() {
+ super();
+ }
+
+ public UserWithIgnore(final int id, final String name) {
+ this.id = id;
+ this.name = name;
+ userItems = new ArrayList();
+ }
+
+ public void addItem(final ItemWithIgnore item) {
+ userItems.add(item);
+ }
+}
diff --git a/jackson-simple/src/test/java/com/baeldung/jackson/bidirection/UserWithRef.java b/jackson-simple/src/test/java/com/baeldung/jackson/bidirection/UserWithRef.java
new file mode 100644
index 0000000000..3de03fc651
--- /dev/null
+++ b/jackson-simple/src/test/java/com/baeldung/jackson/bidirection/UserWithRef.java
@@ -0,0 +1,28 @@
+package com.baeldung.jackson.bidirection;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.fasterxml.jackson.annotation.JsonBackReference;
+
+public class UserWithRef {
+ public int id;
+ public String name;
+
+ @JsonBackReference
+ public List userItems;
+
+ public UserWithRef() {
+ super();
+ }
+
+ public UserWithRef(final int id, final String name) {
+ this.id = id;
+ this.name = name;
+ userItems = new ArrayList();
+ }
+
+ public void addItem(final ItemWithRef item) {
+ userItems.add(item);
+ }
+}
diff --git a/jackson-simple/src/test/java/com/baeldung/jackson/date/CustomDateDeserializer.java b/jackson-simple/src/test/java/com/baeldung/jackson/date/CustomDateDeserializer.java
new file mode 100644
index 0000000000..90c7d9fbac
--- /dev/null
+++ b/jackson-simple/src/test/java/com/baeldung/jackson/date/CustomDateDeserializer.java
@@ -0,0 +1,36 @@
+package com.baeldung.jackson.date;
+
+import java.io.IOException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
+
+public class CustomDateDeserializer extends StdDeserializer {
+
+ private static final long serialVersionUID = -5451717385630622729L;
+ private SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
+
+ public CustomDateDeserializer() {
+ this(null);
+ }
+
+ public CustomDateDeserializer(final Class> vc) {
+ super(vc);
+ }
+
+ @Override
+ public Date deserialize(final JsonParser jsonparser, final DeserializationContext context) throws IOException, JsonProcessingException {
+ final String date = jsonparser.getText();
+ try {
+ return formatter.parse(date);
+ } catch (final ParseException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+}
diff --git a/jackson-simple/src/test/java/com/baeldung/jackson/date/CustomDateSerializer.java b/jackson-simple/src/test/java/com/baeldung/jackson/date/CustomDateSerializer.java
new file mode 100644
index 0000000000..d840e1940f
--- /dev/null
+++ b/jackson-simple/src/test/java/com/baeldung/jackson/date/CustomDateSerializer.java
@@ -0,0 +1,29 @@
+package com.baeldung.jackson.date;
+
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.SerializerProvider;
+import com.fasterxml.jackson.databind.ser.std.StdSerializer;
+
+public class CustomDateSerializer extends StdSerializer {
+
+ private static final long serialVersionUID = -2894356342227378312L;
+ private SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
+
+ public CustomDateSerializer() {
+ this(null);
+ }
+
+ public CustomDateSerializer(final Class t) {
+ super(t);
+ }
+
+ @Override
+ public void serialize(final Date value, final JsonGenerator gen, final SerializerProvider arg2) throws IOException, JsonProcessingException {
+ gen.writeString(formatter.format(value));
+ }
+}
diff --git a/jackson-simple/src/test/java/com/baeldung/jackson/date/EventWithFormat.java b/jackson-simple/src/test/java/com/baeldung/jackson/date/EventWithFormat.java
new file mode 100644
index 0000000000..607e694cef
--- /dev/null
+++ b/jackson-simple/src/test/java/com/baeldung/jackson/date/EventWithFormat.java
@@ -0,0 +1,29 @@
+package com.baeldung.jackson.date;
+
+import java.util.Date;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+
+public class EventWithFormat {
+ public String name;
+
+ @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy hh:mm:ss")
+ public Date eventDate;
+
+ public EventWithFormat() {
+ super();
+ }
+
+ public EventWithFormat(final String name, final Date eventDate) {
+ this.name = name;
+ this.eventDate = eventDate;
+ }
+
+ public Date getEventDate() {
+ return eventDate;
+ }
+
+ public String getName() {
+ return name;
+ }
+}
diff --git a/jackson-simple/src/test/java/com/baeldung/jackson/date/EventWithSerializer.java b/jackson-simple/src/test/java/com/baeldung/jackson/date/EventWithSerializer.java
new file mode 100644
index 0000000000..c359b5c846
--- /dev/null
+++ b/jackson-simple/src/test/java/com/baeldung/jackson/date/EventWithSerializer.java
@@ -0,0 +1,31 @@
+package com.baeldung.jackson.date;
+
+import java.util.Date;
+
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+
+public class EventWithSerializer {
+ public String name;
+
+ @JsonDeserialize(using = CustomDateDeserializer.class)
+ @JsonSerialize(using = CustomDateSerializer.class)
+ public Date eventDate;
+
+ public EventWithSerializer() {
+ super();
+ }
+
+ public EventWithSerializer(final String name, final Date eventDate) {
+ this.name = name;
+ this.eventDate = eventDate;
+ }
+
+ public Date getEventDate() {
+ return eventDate;
+ }
+
+ public String getName() {
+ return name;
+ }
+}
diff --git a/jackson-simple/src/test/java/com/baeldung/jackson/deserialization/ItemDeserializerOnClass.java b/jackson-simple/src/test/java/com/baeldung/jackson/deserialization/ItemDeserializerOnClass.java
new file mode 100644
index 0000000000..eaba9a7173
--- /dev/null
+++ b/jackson-simple/src/test/java/com/baeldung/jackson/deserialization/ItemDeserializerOnClass.java
@@ -0,0 +1,41 @@
+package com.baeldung.jackson.deserialization;
+
+import java.io.IOException;
+
+import com.baeldung.jackson.dtos.ItemWithSerializer;
+import com.baeldung.jackson.dtos.User;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
+import com.fasterxml.jackson.databind.node.IntNode;
+
+public class ItemDeserializerOnClass extends StdDeserializer {
+
+ private static final long serialVersionUID = 5579141241817332594L;
+
+ public ItemDeserializerOnClass() {
+ this(null);
+ }
+
+ public ItemDeserializerOnClass(final Class> vc) {
+ super(vc);
+ }
+
+ /**
+ * {"id":1,"itemNr":"theItem","owner":2}
+ */
+ @Override
+ public ItemWithSerializer deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException, JsonProcessingException {
+ final JsonNode node = jp.getCodec()
+ .readTree(jp);
+ final int id = (Integer) ((IntNode) node.get("id")).numberValue();
+ final String itemName = node.get("itemName")
+ .asText();
+ final int userId = (Integer) ((IntNode) node.get("owner")).numberValue();
+
+ return new ItemWithSerializer(id, itemName, new User(userId, null));
+ }
+
+}
\ No newline at end of file
diff --git a/jackson-simple/src/test/java/com/baeldung/jackson/dtos/Item.java b/jackson-simple/src/test/java/com/baeldung/jackson/dtos/Item.java
new file mode 100644
index 0000000000..6fce2bc88e
--- /dev/null
+++ b/jackson-simple/src/test/java/com/baeldung/jackson/dtos/Item.java
@@ -0,0 +1,32 @@
+package com.baeldung.jackson.dtos;
+
+public class Item {
+ public int id;
+ public String itemName;
+ public User owner;
+
+ public Item() {
+ super();
+ }
+
+ public Item(final int id, final String itemName, final User owner) {
+ this.id = id;
+ this.itemName = itemName;
+ this.owner = owner;
+ }
+
+ // API
+
+ public int getId() {
+ return id;
+ }
+
+ public String getItemName() {
+ return itemName;
+ }
+
+ public User getOwner() {
+ return owner;
+ }
+
+}
\ No newline at end of file
diff --git a/jackson-simple/src/test/java/com/baeldung/jackson/dtos/ItemWithSerializer.java b/jackson-simple/src/test/java/com/baeldung/jackson/dtos/ItemWithSerializer.java
new file mode 100644
index 0000000000..aea9aa770d
--- /dev/null
+++ b/jackson-simple/src/test/java/com/baeldung/jackson/dtos/ItemWithSerializer.java
@@ -0,0 +1,36 @@
+package com.baeldung.jackson.dtos;
+
+import com.baeldung.jackson.deserialization.ItemDeserializerOnClass;
+import com.baeldung.jackson.serialization.ItemSerializerOnClass;
+
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+
+@JsonSerialize(using = ItemSerializerOnClass.class)
+@JsonDeserialize(using = ItemDeserializerOnClass.class)
+public class ItemWithSerializer {
+ public final int id;
+ public final String itemName;
+ public final User owner;
+
+ public ItemWithSerializer(final int id, final String itemName, final User owner) {
+ this.id = id;
+ this.itemName = itemName;
+ this.owner = owner;
+ }
+
+ // API
+
+ public int getId() {
+ return id;
+ }
+
+ public String getItemName() {
+ return itemName;
+ }
+
+ public User getOwner() {
+ return owner;
+ }
+
+}
\ No newline at end of file
diff --git a/jackson-simple/src/test/java/com/baeldung/jackson/dtos/MyDto.java b/jackson-simple/src/test/java/com/baeldung/jackson/dtos/MyDto.java
new file mode 100644
index 0000000000..49cf07baea
--- /dev/null
+++ b/jackson-simple/src/test/java/com/baeldung/jackson/dtos/MyDto.java
@@ -0,0 +1,54 @@
+package com.baeldung.jackson.dtos;
+
+public class MyDto {
+
+ private String stringValue;
+ private int intValue;
+ private boolean booleanValue;
+
+ public MyDto() {
+ super();
+ }
+
+ public MyDto(final String stringValue, final int intValue, final boolean booleanValue) {
+ super();
+
+ this.stringValue = stringValue;
+ this.intValue = intValue;
+ this.booleanValue = booleanValue;
+ }
+
+ // API
+
+ public String getStringValue() {
+ return stringValue;
+ }
+
+ public void setStringValue(final String stringValue) {
+ this.stringValue = stringValue;
+ }
+
+ public int getIntValue() {
+ return intValue;
+ }
+
+ public void setIntValue(final int intValue) {
+ this.intValue = intValue;
+ }
+
+ public boolean isBooleanValue() {
+ return booleanValue;
+ }
+
+ public void setBooleanValue(final boolean booleanValue) {
+ this.booleanValue = booleanValue;
+ }
+
+ //
+
+ @Override
+ public String toString() {
+ return "MyDto [stringValue=" + stringValue + ", intValue=" + intValue + ", booleanValue=" + booleanValue + "]";
+ }
+
+}
diff --git a/jackson/src/test/java/com/baeldung/jackson/dtos/MyDtoFieldNameChanged.java b/jackson-simple/src/test/java/com/baeldung/jackson/dtos/MyDtoFieldNameChanged.java
similarity index 100%
rename from jackson/src/test/java/com/baeldung/jackson/dtos/MyDtoFieldNameChanged.java
rename to jackson-simple/src/test/java/com/baeldung/jackson/dtos/MyDtoFieldNameChanged.java
diff --git a/jackson/src/test/java/com/baeldung/jackson/dtos/MyDtoIncludeNonDefault.java b/jackson-simple/src/test/java/com/baeldung/jackson/dtos/MyDtoIncludeNonDefault.java
similarity index 100%
rename from jackson/src/test/java/com/baeldung/jackson/dtos/MyDtoIncludeNonDefault.java
rename to jackson-simple/src/test/java/com/baeldung/jackson/dtos/MyDtoIncludeNonDefault.java
diff --git a/jackson/src/test/java/com/baeldung/jackson/dtos/MyDtoNoAccessors.java b/jackson-simple/src/test/java/com/baeldung/jackson/dtos/MyDtoNoAccessors.java
similarity index 100%
rename from jackson/src/test/java/com/baeldung/jackson/dtos/MyDtoNoAccessors.java
rename to jackson-simple/src/test/java/com/baeldung/jackson/dtos/MyDtoNoAccessors.java
diff --git a/jackson/src/test/java/com/baeldung/jackson/dtos/MyDtoNoAccessorsAndFieldVisibility.java b/jackson-simple/src/test/java/com/baeldung/jackson/dtos/MyDtoNoAccessorsAndFieldVisibility.java
similarity index 100%
rename from jackson/src/test/java/com/baeldung/jackson/dtos/MyDtoNoAccessorsAndFieldVisibility.java
rename to jackson-simple/src/test/java/com/baeldung/jackson/dtos/MyDtoNoAccessorsAndFieldVisibility.java
diff --git a/jackson/src/test/java/com/baeldung/jackson/dtos/MyDtoWithFilter.java b/jackson-simple/src/test/java/com/baeldung/jackson/dtos/MyDtoWithFilter.java
similarity index 100%
rename from jackson/src/test/java/com/baeldung/jackson/dtos/MyDtoWithFilter.java
rename to jackson-simple/src/test/java/com/baeldung/jackson/dtos/MyDtoWithFilter.java
diff --git a/jackson/src/test/java/com/baeldung/jackson/dtos/MyDtoWithSpecialField.java b/jackson-simple/src/test/java/com/baeldung/jackson/dtos/MyDtoWithSpecialField.java
similarity index 100%
rename from jackson/src/test/java/com/baeldung/jackson/dtos/MyDtoWithSpecialField.java
rename to jackson-simple/src/test/java/com/baeldung/jackson/dtos/MyDtoWithSpecialField.java
diff --git a/jackson/src/test/java/com/baeldung/jackson/dtos/MyMixInForIgnoreType.java b/jackson-simple/src/test/java/com/baeldung/jackson/dtos/MyMixInForIgnoreType.java
similarity index 100%
rename from jackson/src/test/java/com/baeldung/jackson/dtos/MyMixInForIgnoreType.java
rename to jackson-simple/src/test/java/com/baeldung/jackson/dtos/MyMixInForIgnoreType.java
diff --git a/jackson-simple/src/test/java/com/baeldung/jackson/dtos/User.java b/jackson-simple/src/test/java/com/baeldung/jackson/dtos/User.java
new file mode 100644
index 0000000000..2418e8070d
--- /dev/null
+++ b/jackson-simple/src/test/java/com/baeldung/jackson/dtos/User.java
@@ -0,0 +1,26 @@
+package com.baeldung.jackson.dtos;
+
+public class User {
+ public int id;
+ public String name;
+
+ public User() {
+ super();
+ }
+
+ public User(final int id, final String name) {
+ this.id = id;
+ this.name = name;
+ }
+
+ // API
+
+ public int getId() {
+ return id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+}
\ No newline at end of file
diff --git a/jackson/src/test/java/com/baeldung/jackson/dtos/ignore/MyDtoIgnoreField.java b/jackson-simple/src/test/java/com/baeldung/jackson/dtos/ignore/MyDtoIgnoreField.java
similarity index 100%
rename from jackson/src/test/java/com/baeldung/jackson/dtos/ignore/MyDtoIgnoreField.java
rename to jackson-simple/src/test/java/com/baeldung/jackson/dtos/ignore/MyDtoIgnoreField.java
diff --git a/jackson/src/test/java/com/baeldung/jackson/dtos/ignore/MyDtoIgnoreFieldByName.java b/jackson-simple/src/test/java/com/baeldung/jackson/dtos/ignore/MyDtoIgnoreFieldByName.java
similarity index 100%
rename from jackson/src/test/java/com/baeldung/jackson/dtos/ignore/MyDtoIgnoreFieldByName.java
rename to jackson-simple/src/test/java/com/baeldung/jackson/dtos/ignore/MyDtoIgnoreFieldByName.java
diff --git a/jackson/src/test/java/com/baeldung/jackson/dtos/ignore/MyDtoIgnoreNull.java b/jackson-simple/src/test/java/com/baeldung/jackson/dtos/ignore/MyDtoIgnoreNull.java
similarity index 100%
rename from jackson/src/test/java/com/baeldung/jackson/dtos/ignore/MyDtoIgnoreNull.java
rename to jackson-simple/src/test/java/com/baeldung/jackson/dtos/ignore/MyDtoIgnoreNull.java
diff --git a/jackson-simple/src/test/java/com/baeldung/jackson/dtos/withEnum/DistanceEnumWithValue.java b/jackson-simple/src/test/java/com/baeldung/jackson/dtos/withEnum/DistanceEnumWithValue.java
new file mode 100644
index 0000000000..69c476d8a5
--- /dev/null
+++ b/jackson-simple/src/test/java/com/baeldung/jackson/dtos/withEnum/DistanceEnumWithValue.java
@@ -0,0 +1,29 @@
+package com.baeldung.jackson.dtos.withEnum;
+
+import com.fasterxml.jackson.annotation.JsonValue;
+
+public enum DistanceEnumWithValue {
+ KILOMETER("km", 1000), MILE("miles", 1609.34), METER("meters", 1), INCH("inches", 0.0254), CENTIMETER("cm", 0.01), MILLIMETER("mm", 0.001);
+
+ private String unit;
+ private final double meters;
+
+ private DistanceEnumWithValue(String unit, double meters) {
+ this.unit = unit;
+ this.meters = meters;
+ }
+
+ @JsonValue
+ public double getMeters() {
+ return meters;
+ }
+
+ public String getUnit() {
+ return unit;
+ }
+
+ public void setUnit(String unit) {
+ this.unit = unit;
+ }
+
+}
\ No newline at end of file
diff --git a/jackson-simple/src/test/java/com/baeldung/jackson/exception/UserWithRoot.java b/jackson-simple/src/test/java/com/baeldung/jackson/exception/UserWithRoot.java
new file mode 100644
index 0000000000..d879c16e6a
--- /dev/null
+++ b/jackson-simple/src/test/java/com/baeldung/jackson/exception/UserWithRoot.java
@@ -0,0 +1,18 @@
+package com.baeldung.jackson.exception;
+
+import com.fasterxml.jackson.annotation.JsonRootName;
+
+@JsonRootName(value = "user")
+public class UserWithRoot {
+ public int id;
+ public String name;
+
+ public UserWithRoot() {
+ super();
+ }
+
+ public UserWithRoot(final int id, final String name) {
+ this.id = id;
+ this.name = name;
+ }
+}
diff --git a/jackson/src/test/java/com/baeldung/jackson/exception/UserWithRootNamespace.java b/jackson-simple/src/test/java/com/baeldung/jackson/exception/UserWithRootNamespace.java
similarity index 100%
rename from jackson/src/test/java/com/baeldung/jackson/exception/UserWithRootNamespace.java
rename to jackson-simple/src/test/java/com/baeldung/jackson/exception/UserWithRootNamespace.java
diff --git a/jackson-simple/src/test/java/com/baeldung/jackson/jsonview/Item.java b/jackson-simple/src/test/java/com/baeldung/jackson/jsonview/Item.java
new file mode 100644
index 0000000000..26d20d4847
--- /dev/null
+++ b/jackson-simple/src/test/java/com/baeldung/jackson/jsonview/Item.java
@@ -0,0 +1,36 @@
+package com.baeldung.jackson.jsonview;
+
+import com.fasterxml.jackson.annotation.JsonView;
+
+public class Item {
+ @JsonView(Views.Public.class)
+ public int id;
+
+ @JsonView(Views.Public.class)
+ public String itemName;
+
+ @JsonView(Views.Internal.class)
+ public String ownerName;
+
+ public Item() {
+ super();
+ }
+
+ public Item(final int id, final String itemName, final String ownerName) {
+ this.id = id;
+ this.itemName = itemName;
+ this.ownerName = ownerName;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public String getItemName() {
+ return itemName;
+ }
+
+ public String getOwnerName() {
+ return ownerName;
+ }
+}
diff --git a/jackson-simple/src/test/java/com/baeldung/jackson/jsonview/Views.java b/jackson-simple/src/test/java/com/baeldung/jackson/jsonview/Views.java
new file mode 100644
index 0000000000..65950b7f9f
--- /dev/null
+++ b/jackson-simple/src/test/java/com/baeldung/jackson/jsonview/Views.java
@@ -0,0 +1,9 @@
+package com.baeldung.jackson.jsonview;
+
+public class Views {
+ public static class Public {
+ }
+
+ public static class Internal extends Public {
+ }
+}
diff --git a/jackson/src/test/java/com/baeldung/jackson/objectmapper/CustomCarDeserializer.java b/jackson-simple/src/test/java/com/baeldung/jackson/objectmapper/CustomCarDeserializer.java
similarity index 100%
rename from jackson/src/test/java/com/baeldung/jackson/objectmapper/CustomCarDeserializer.java
rename to jackson-simple/src/test/java/com/baeldung/jackson/objectmapper/CustomCarDeserializer.java
diff --git a/jackson/src/test/java/com/baeldung/jackson/objectmapper/CustomCarSerializer.java b/jackson-simple/src/test/java/com/baeldung/jackson/objectmapper/CustomCarSerializer.java
similarity index 100%
rename from jackson/src/test/java/com/baeldung/jackson/objectmapper/CustomCarSerializer.java
rename to jackson-simple/src/test/java/com/baeldung/jackson/objectmapper/CustomCarSerializer.java
diff --git a/jackson/src/test/java/com/baeldung/jackson/objectmapper/JavaReadWriteJsonExampleUnitTest.java b/jackson-simple/src/test/java/com/baeldung/jackson/objectmapper/JavaReadWriteJsonExampleUnitTest.java
similarity index 100%
rename from jackson/src/test/java/com/baeldung/jackson/objectmapper/JavaReadWriteJsonExampleUnitTest.java
rename to jackson-simple/src/test/java/com/baeldung/jackson/objectmapper/JavaReadWriteJsonExampleUnitTest.java
diff --git a/jackson/src/test/java/com/baeldung/jackson/objectmapper/SerializationDeserializationFeatureUnitTest.java b/jackson-simple/src/test/java/com/baeldung/jackson/objectmapper/SerializationDeserializationFeatureUnitTest.java
similarity index 100%
rename from jackson/src/test/java/com/baeldung/jackson/objectmapper/SerializationDeserializationFeatureUnitTest.java
rename to jackson-simple/src/test/java/com/baeldung/jackson/objectmapper/SerializationDeserializationFeatureUnitTest.java
diff --git a/jackson/src/test/java/com/baeldung/jackson/objectmapper/dto/Car.java b/jackson-simple/src/test/java/com/baeldung/jackson/objectmapper/dto/Car.java
similarity index 100%
rename from jackson/src/test/java/com/baeldung/jackson/objectmapper/dto/Car.java
rename to jackson-simple/src/test/java/com/baeldung/jackson/objectmapper/dto/Car.java
diff --git a/jackson/src/test/java/com/baeldung/jackson/objectmapper/dto/Request.java b/jackson-simple/src/test/java/com/baeldung/jackson/objectmapper/dto/Request.java
similarity index 100%
rename from jackson/src/test/java/com/baeldung/jackson/objectmapper/dto/Request.java
rename to jackson-simple/src/test/java/com/baeldung/jackson/objectmapper/dto/Request.java
diff --git a/jackson/src/test/java/com/baeldung/jackson/serialization/ItemSerializer.java b/jackson-simple/src/test/java/com/baeldung/jackson/serialization/ItemSerializer.java
similarity index 100%
rename from jackson/src/test/java/com/baeldung/jackson/serialization/ItemSerializer.java
rename to jackson-simple/src/test/java/com/baeldung/jackson/serialization/ItemSerializer.java
diff --git a/jackson-simple/src/test/java/com/baeldung/jackson/serialization/ItemSerializerOnClass.java b/jackson-simple/src/test/java/com/baeldung/jackson/serialization/ItemSerializerOnClass.java
new file mode 100644
index 0000000000..1fdf44e17c
--- /dev/null
+++ b/jackson-simple/src/test/java/com/baeldung/jackson/serialization/ItemSerializerOnClass.java
@@ -0,0 +1,32 @@
+package com.baeldung.jackson.serialization;
+
+import java.io.IOException;
+
+import com.baeldung.jackson.dtos.ItemWithSerializer;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.SerializerProvider;
+import com.fasterxml.jackson.databind.ser.std.StdSerializer;
+
+public class ItemSerializerOnClass extends StdSerializer {
+
+ private static final long serialVersionUID = -1760959597313610409L;
+
+ public ItemSerializerOnClass() {
+ this(null);
+ }
+
+ public ItemSerializerOnClass(final Class t) {
+ super(t);
+ }
+
+ @Override
+ public final void serialize(final ItemWithSerializer value, final JsonGenerator jgen, final SerializerProvider provider) throws IOException, JsonProcessingException {
+ jgen.writeStartObject();
+ jgen.writeNumberField("id", value.id);
+ jgen.writeStringField("itemName", value.itemName);
+ jgen.writeNumberField("owner", value.owner.id);
+ jgen.writeEndObject();
+ }
+
+}
\ No newline at end of file
diff --git a/jackson/src/test/java/com/baeldung/jackson/serialization/MyDtoNullKeySerializer.java b/jackson-simple/src/test/java/com/baeldung/jackson/serialization/MyDtoNullKeySerializer.java
similarity index 100%
rename from jackson/src/test/java/com/baeldung/jackson/serialization/MyDtoNullKeySerializer.java
rename to jackson-simple/src/test/java/com/baeldung/jackson/serialization/MyDtoNullKeySerializer.java
diff --git a/jackson/src/test/java/com/baeldung/jackson/test/JacksonAnnotationUnitTest.java b/jackson-simple/src/test/java/com/baeldung/jackson/test/JacksonAnnotationUnitTest.java
similarity index 100%
rename from jackson/src/test/java/com/baeldung/jackson/test/JacksonAnnotationUnitTest.java
rename to jackson-simple/src/test/java/com/baeldung/jackson/test/JacksonAnnotationUnitTest.java
diff --git a/jackson/src/test/java/com/baeldung/jackson/test/JacksonSerializationIgnoreUnitTest.java b/jackson-simple/src/test/java/com/baeldung/jackson/test/JacksonSerializationIgnoreUnitTest.java
similarity index 100%
rename from jackson/src/test/java/com/baeldung/jackson/test/JacksonSerializationIgnoreUnitTest.java
rename to jackson-simple/src/test/java/com/baeldung/jackson/test/JacksonSerializationIgnoreUnitTest.java
diff --git a/jackson/src/test/java/com/baeldung/jackson/test/JacksonSerializationUnitTest.java b/jackson-simple/src/test/java/com/baeldung/jackson/test/JacksonSerializationUnitTest.java
similarity index 100%
rename from jackson/src/test/java/com/baeldung/jackson/test/JacksonSerializationUnitTest.java
rename to jackson-simple/src/test/java/com/baeldung/jackson/test/JacksonSerializationUnitTest.java
diff --git a/jackson-simple/src/test/resources/.gitignore b/jackson-simple/src/test/resources/.gitignore
new file mode 100644
index 0000000000..83c05e60c8
--- /dev/null
+++ b/jackson-simple/src/test/resources/.gitignore
@@ -0,0 +1,13 @@
+*.class
+
+#folders#
+/target
+/neoDb*
+/data
+/src/main/webapp/WEB-INF/classes
+*/META-INF/*
+
+# Packaged files #
+*.jar
+*.war
+*.ear
\ No newline at end of file
diff --git a/jackson/README.md b/jackson/README.md
index e9cf6f212c..794ddc04d9 100644
--- a/jackson/README.md
+++ b/jackson/README.md
@@ -6,9 +6,7 @@
The "REST With Spring" Classes: http://bit.ly/restwithspring
### Relevant Articles:
-- [Jackson Ignore Properties on Marshalling](http://www.baeldung.com/jackson-ignore-properties-on-serialization)
- [Jackson – Unmarshall to Collection/Array](http://www.baeldung.com/jackson-collection-array)
-- [Jackson Unmarshalling json with Unknown Properties](http://www.baeldung.com/jackson-deserialize-json-unknown-properties)
- [Jackson – Custom Serializer](http://www.baeldung.com/jackson-custom-serialization)
- [Getting Started with Custom Deserialization in Jackson](http://www.baeldung.com/jackson-deserialization)
- [Jackson Exceptions – Problems and Solutions](http://www.baeldung.com/jackson-exception)
@@ -16,11 +14,9 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
- [Jackson – Bidirectional Relationships](http://www.baeldung.com/jackson-bidirectional-relationships-and-infinite-recursion)
- [Jackson JSON Tutorial](http://www.baeldung.com/jackson)
- [Jackson – Working with Maps and nulls](http://www.baeldung.com/jackson-map-null-values-or-null-key)
-- [Jackson – Decide What Fields Get Serialized/Deserializaed](http://www.baeldung.com/jackson-field-serializable-deserializable-or-not)
-- [Jackson Annotation Examples](http://www.baeldung.com/jackson-annotations)
+- [Jackson – Decide What Fields Get Serialized/Deserialized](http://www.baeldung.com/jackson-field-serializable-deserializable-or-not)
- [Working with Tree Model Nodes in Jackson](http://www.baeldung.com/jackson-json-node-tree-model)
- [Jackson vs Gson](http://www.baeldung.com/jackson-vs-gson)
-- [Intro to the Jackson ObjectMapper](http://www.baeldung.com/jackson-object-mapper-tutorial)
- [XML Serialization and Deserialization with Jackson](http://www.baeldung.com/jackson-xml-serialization-and-deserialization)
- [More Jackson Annotations](http://www.baeldung.com/jackson-advanced-annotations)
- [Inheritance with Jackson](http://www.baeldung.com/jackson-inheritance)
@@ -31,9 +27,7 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
- [Jackson – JsonMappingException (No serializer found for class)](http://www.baeldung.com/jackson-jsonmappingexception)
- [How To Serialize Enums as JSON Objects with Jackson](http://www.baeldung.com/jackson-serialize-enums)
- [Jackson – Marshall String to JsonNode](http://www.baeldung.com/jackson-json-to-jsonnode)
-- [Ignore Null Fields with Jackson](http://www.baeldung.com/jackson-ignore-null-fields)
- [Jackson – Unmarshall to Collection/Array](http://www.baeldung.com/jackson-collection-array)
-- [Jackson – Change Name of Field](http://www.baeldung.com/jackson-name-of-property)
- [Serialize Only Fields that meet a Custom Criteria with Jackson](http://www.baeldung.com/jackson-serialize-field-custom-criteria)
- [Mapping Nested Values with Jackson](http://www.baeldung.com/jackson-nested-values)
- [Convert XML to JSON Using Jackson](https://www.baeldung.com/jackson-convert-xml-json)
diff --git a/jackson/src/test/java/com/baeldung/jackson/test/UnitTestSuite.java b/jackson/src/test/java/com/baeldung/jackson/test/UnitTestSuite.java
index 6be2f29baa..e783c67f5b 100644
--- a/jackson/src/test/java/com/baeldung/jackson/test/UnitTestSuite.java
+++ b/jackson/src/test/java/com/baeldung/jackson/test/UnitTestSuite.java
@@ -12,8 +12,6 @@ import org.junit.runners.Suite;
,JacksonDeserializationUnitTest.class
,JacksonDeserializationUnitTest.class
,JacksonPrettyPrintUnitTest.class
- ,JacksonSerializationIgnoreUnitTest.class
- ,JacksonSerializationUnitTest.class
,SandboxUnitTest.class
,JacksonFieldUnitTest.class
}) // @formatter:on
diff --git a/java-collections-maps-2/README.md b/java-collections-maps-2/README.md
new file mode 100644
index 0000000000..8bcafccfe8
--- /dev/null
+++ b/java-collections-maps-2/README.md
@@ -0,0 +1,2 @@
+## Relevant Articles:
+- [Map of Primitives in Java](https://www.baeldung.com/java-map-primitives)
diff --git a/java-collections-maps-2/pom.xml b/java-collections-maps-2/pom.xml
index b025c5e32d..4ab94a7ae3 100644
--- a/java-collections-maps-2/pom.xml
+++ b/java-collections-maps-2/pom.xml
@@ -24,22 +24,25 @@
net.sf.trove4j
trove4j
- 3.0.2
+ ${trove4j.version}
it.unimi.dsi
fastutil
- 8.1.0
+ ${fastutil.version}
colt
colt
- 1.2.0
+ ${colt.version}
8.2.0
+ 3.0.2
+ 8.1.0
+ 1.2.0
\ No newline at end of file
diff --git a/java-dates-2/README.md b/java-dates-2/README.md
new file mode 100644
index 0000000000..a6b5c8e574
--- /dev/null
+++ b/java-dates-2/README.md
@@ -0,0 +1,2 @@
+## Relevant Articles:
+- [Converting Between LocalDate and XMLGregorianCalendar](https://www.baeldung.com/java-localdate-to-xmlgregoriancalendar)
diff --git a/java-math/.gitignore b/java-math/.gitignore
new file mode 100644
index 0000000000..30b2b7442c
--- /dev/null
+++ b/java-math/.gitignore
@@ -0,0 +1,4 @@
+/target/
+.settings/
+.classpath
+.project
\ No newline at end of file
diff --git a/java-math/README.md b/java-math/README.md
new file mode 100644
index 0000000000..d821348204
--- /dev/null
+++ b/java-math/README.md
@@ -0,0 +1,10 @@
+## Relevant articles:
+
+- [Calculate Factorial in Java](https://www.baeldung.com/java-calculate-factorial)
+- [Generate Combinations in Java](https://www.baeldung.com/java-combinations-algorithm)
+- [Check If Two Rectangles Overlap In Java](https://www.baeldung.com/java-check-if-two-rectangles-overlap)
+- [Calculate the Distance Between Two Points in Java](https://www.baeldung.com/java-distance-between-two-points)
+- [Find the Intersection of Two Lines in Java](https://www.baeldung.com/java-intersection-of-two-lines)
+- [Round Up to the Nearest Hundred](https://www.baeldung.com/java-round-up-nearest-hundred)
+- [Calculate Percentage in Java](https://www.baeldung.com/java-calculate-percentage)
+- [Convert Latitude and Longitude to a 2D Point in Java](https://www.baeldung.com/java-convert-latitude-longitude)
\ No newline at end of file
diff --git a/java-math/pom.xml b/java-math/pom.xml
new file mode 100644
index 0000000000..159d053df3
--- /dev/null
+++ b/java-math/pom.xml
@@ -0,0 +1,68 @@
+
+ 4.0.0
+ java-math
+ 0.0.1-SNAPSHOT
+ java-math
+
+
+ com.baeldung
+ parent-modules
+ 1.0.0-SNAPSHOT
+
+
+
+
+ org.apache.commons
+ commons-math3
+ ${commons-math3.version}
+
+
+ com.google.guava
+ guava
+ ${guava.version}
+
+
+ commons-codec
+ commons-codec
+ ${commons-codec.version}
+
+
+ org.projectlombok
+ lombok
+ ${lombok.version}
+ provided
+
+
+ org.assertj
+ assertj-core
+ ${org.assertj.core.version}
+ test
+
+
+ com.github.dpaukov
+ combinatoricslib3
+ 3.3.0
+
+
+
+
+
+
+
+ org.codehaus.mojo
+ exec-maven-plugin
+ ${exec-maven-plugin.version}
+
+
+
+
+
+
+ 3.6.1
+ 3.9.0
+ 1.11
+ 27.0.1-jre
+
+
+
\ No newline at end of file
diff --git a/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/ApacheCommonsCombinationGenerator.java b/java-math/src/main/java/com/baeldung/algorithms/combination/ApacheCommonsCombinationGenerator.java
similarity index 100%
rename from algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/ApacheCommonsCombinationGenerator.java
rename to java-math/src/main/java/com/baeldung/algorithms/combination/ApacheCommonsCombinationGenerator.java
diff --git a/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/CombinatoricsLibCombinationGenerator.java b/java-math/src/main/java/com/baeldung/algorithms/combination/CombinatoricsLibCombinationGenerator.java
similarity index 100%
rename from algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/CombinatoricsLibCombinationGenerator.java
rename to java-math/src/main/java/com/baeldung/algorithms/combination/CombinatoricsLibCombinationGenerator.java
diff --git a/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/GuavaCombinationsGenerator.java b/java-math/src/main/java/com/baeldung/algorithms/combination/GuavaCombinationsGenerator.java
similarity index 100%
rename from algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/GuavaCombinationsGenerator.java
rename to java-math/src/main/java/com/baeldung/algorithms/combination/GuavaCombinationsGenerator.java
diff --git a/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/IterativeCombinationGenerator.java b/java-math/src/main/java/com/baeldung/algorithms/combination/IterativeCombinationGenerator.java
similarity index 100%
rename from algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/IterativeCombinationGenerator.java
rename to java-math/src/main/java/com/baeldung/algorithms/combination/IterativeCombinationGenerator.java
diff --git a/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/SelectionRecursiveCombinationGenerator.java b/java-math/src/main/java/com/baeldung/algorithms/combination/SelectionRecursiveCombinationGenerator.java
similarity index 100%
rename from algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/SelectionRecursiveCombinationGenerator.java
rename to java-math/src/main/java/com/baeldung/algorithms/combination/SelectionRecursiveCombinationGenerator.java
diff --git a/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/SetRecursiveCombinationGenerator.java b/java-math/src/main/java/com/baeldung/algorithms/combination/SetRecursiveCombinationGenerator.java
similarity index 100%
rename from algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/SetRecursiveCombinationGenerator.java
rename to java-math/src/main/java/com/baeldung/algorithms/combination/SetRecursiveCombinationGenerator.java
diff --git a/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsService.java b/java-math/src/main/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsService.java
similarity index 100%
rename from algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsService.java
rename to java-math/src/main/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsService.java
diff --git a/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/factorial/Factorial.java b/java-math/src/main/java/com/baeldung/algorithms/factorial/Factorial.java
similarity index 100%
rename from algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/factorial/Factorial.java
rename to java-math/src/main/java/com/baeldung/algorithms/factorial/Factorial.java
diff --git a/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/linesintersection/LinesIntersectionService.java b/java-math/src/main/java/com/baeldung/algorithms/linesintersection/LinesIntersectionService.java
similarity index 100%
rename from algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/linesintersection/LinesIntersectionService.java
rename to java-math/src/main/java/com/baeldung/algorithms/linesintersection/LinesIntersectionService.java
diff --git a/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/mercator/EllipticalMercator.java b/java-math/src/main/java/com/baeldung/algorithms/mercator/EllipticalMercator.java
similarity index 100%
rename from algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/mercator/EllipticalMercator.java
rename to java-math/src/main/java/com/baeldung/algorithms/mercator/EllipticalMercator.java
diff --git a/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/mercator/Mercator.java b/java-math/src/main/java/com/baeldung/algorithms/mercator/Mercator.java
similarity index 100%
rename from algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/mercator/Mercator.java
rename to java-math/src/main/java/com/baeldung/algorithms/mercator/Mercator.java
diff --git a/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/mercator/SphericalMercator.java b/java-math/src/main/java/com/baeldung/algorithms/mercator/SphericalMercator.java
similarity index 100%
rename from algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/mercator/SphericalMercator.java
rename to java-math/src/main/java/com/baeldung/algorithms/mercator/SphericalMercator.java
diff --git a/java-numbers/src/main/java/com/baeldung/percentage/PercentageCalculator.java b/java-math/src/main/java/com/baeldung/algorithms/percentage/PercentageCalculator.java
similarity index 93%
rename from java-numbers/src/main/java/com/baeldung/percentage/PercentageCalculator.java
rename to java-math/src/main/java/com/baeldung/algorithms/percentage/PercentageCalculator.java
index e74de2cc67..f69b23146e 100644
--- a/java-numbers/src/main/java/com/baeldung/percentage/PercentageCalculator.java
+++ b/java-math/src/main/java/com/baeldung/algorithms/percentage/PercentageCalculator.java
@@ -1,4 +1,4 @@
-package com.baeldung.percentage;
+package com.baeldung.algorithms.percentage;
import java.util.Scanner;
diff --git a/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Point.java b/java-math/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Point.java
similarity index 100%
rename from algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Point.java
rename to java-math/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Point.java
diff --git a/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Rectangle.java b/java-math/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Rectangle.java
similarity index 100%
rename from algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Rectangle.java
rename to java-math/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Rectangle.java
diff --git a/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/roundedup/RoundUpToHundred.java b/java-math/src/main/java/com/baeldung/algorithms/roundedup/RoundUpToHundred.java
similarity index 100%
rename from algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/roundedup/RoundUpToHundred.java
rename to java-math/src/main/java/com/baeldung/algorithms/roundedup/RoundUpToHundred.java
diff --git a/spring-cloud/spring-cloud-kubernetes-2/client-service/src/main/resources/logback.xml b/java-math/src/main/resources/logback.xml
similarity index 100%
rename from spring-cloud/spring-cloud-kubernetes-2/client-service/src/main/resources/logback.xml
rename to java-math/src/main/resources/logback.xml
diff --git a/algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/combination/CombinationUnitTest.java b/java-math/src/test/java/com/baeldung/algorithms/combination/CombinationUnitTest.java
similarity index 100%
rename from algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/combination/CombinationUnitTest.java
rename to java-math/src/test/java/com/baeldung/algorithms/combination/CombinationUnitTest.java
diff --git a/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsServiceUnitTest.java b/java-math/src/test/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsServiceUnitTest.java
similarity index 93%
rename from algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsServiceUnitTest.java
rename to java-math/src/test/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsServiceUnitTest.java
index 785afdbb2b..784681a807 100644
--- a/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsServiceUnitTest.java
+++ b/java-math/src/test/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsServiceUnitTest.java
@@ -2,8 +2,6 @@ package com.baeldung.algorithms.distancebetweenpoints;
import org.junit.Test;
-import com.baeldung.algorithms.distancebetweenpoints.DistanceBetweenPointsService;
-
import static org.junit.Assert.assertEquals;
public class DistanceBetweenPointsServiceUnitTest {
diff --git a/algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/factorial/FactorialUnitTest.java b/java-math/src/test/java/com/baeldung/algorithms/factorial/FactorialUnitTest.java
similarity index 100%
rename from algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/factorial/FactorialUnitTest.java
rename to java-math/src/test/java/com/baeldung/algorithms/factorial/FactorialUnitTest.java
diff --git a/algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/linesintersection/LinesIntersectionServiceUnitTest.java b/java-math/src/test/java/com/baeldung/algorithms/linesintersection/LinesIntersectionServiceUnitTest.java
similarity index 100%
rename from algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/linesintersection/LinesIntersectionServiceUnitTest.java
rename to java-math/src/test/java/com/baeldung/algorithms/linesintersection/LinesIntersectionServiceUnitTest.java
diff --git a/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/mercator/EllipticalMercatorUnitTest.java b/java-math/src/test/java/com/baeldung/algorithms/mercator/EllipticalMercatorUnitTest.java
similarity index 100%
rename from algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/mercator/EllipticalMercatorUnitTest.java
rename to java-math/src/test/java/com/baeldung/algorithms/mercator/EllipticalMercatorUnitTest.java
diff --git a/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/mercator/SphericalMercatorUnitTest.java b/java-math/src/test/java/com/baeldung/algorithms/mercator/SphericalMercatorUnitTest.java
similarity index 100%
rename from algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/mercator/SphericalMercatorUnitTest.java
rename to java-math/src/test/java/com/baeldung/algorithms/mercator/SphericalMercatorUnitTest.java
diff --git a/java-numbers/src/test/java/com/baeldung/percentage/PercentageCalculatorUnitTest.java b/java-math/src/test/java/com/baeldung/algorithms/percentage/PercentageCalculatorUnitTest.java
similarity index 95%
rename from java-numbers/src/test/java/com/baeldung/percentage/PercentageCalculatorUnitTest.java
rename to java-math/src/test/java/com/baeldung/algorithms/percentage/PercentageCalculatorUnitTest.java
index 202d4f8112..e49acc0c4b 100644
--- a/java-numbers/src/test/java/com/baeldung/percentage/PercentageCalculatorUnitTest.java
+++ b/java-math/src/test/java/com/baeldung/algorithms/percentage/PercentageCalculatorUnitTest.java
@@ -1,4 +1,4 @@
-package com.baeldung.percentage;
+package com.baeldung.algorithms.percentage;
import org.junit.Assert;
import org.junit.Test;
diff --git a/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/rectanglesoverlap/RectangleUnitTest.java b/java-math/src/test/java/com/baeldung/algorithms/rectanglesoverlap/RectangleUnitTest.java
similarity index 93%
rename from algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/rectanglesoverlap/RectangleUnitTest.java
rename to java-math/src/test/java/com/baeldung/algorithms/rectanglesoverlap/RectangleUnitTest.java
index 6707b34477..e4bb614b48 100644
--- a/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/rectanglesoverlap/RectangleUnitTest.java
+++ b/java-math/src/test/java/com/baeldung/algorithms/rectanglesoverlap/RectangleUnitTest.java
@@ -4,9 +4,6 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import org.junit.Test;
-import com.baeldung.algorithms.rectanglesoverlap.Point;
-import com.baeldung.algorithms.rectanglesoverlap.Rectangle;
-
public class RectangleUnitTest {
@Test
diff --git a/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/roundedup/RoundUpToHundredUnitTest.java b/java-math/src/test/java/com/baeldung/algorithms/roundedup/RoundUpToHundredUnitTest.java
similarity index 100%
rename from algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/roundedup/RoundUpToHundredUnitTest.java
rename to java-math/src/test/java/com/baeldung/algorithms/roundedup/RoundUpToHundredUnitTest.java
diff --git a/java-streams-2/pom.xml b/java-streams-2/pom.xml
index cd89a1a80f..5004249352 100644
--- a/java-streams-2/pom.xml
+++ b/java-streams-2/pom.xml
@@ -4,36 +4,47 @@
com.baeldung.javastreams2
javastreams2
1.0
+ Stream Reduce
jar
+
+
+ com.baeldung
+ parent-java
+ 0.0.1-SNAPSHOT
+ ../parent-java
+
+
org.openjdk.jmh
jmh-core
- 1.21
+ ${jmh.version}
org.openjdk.jmh
jmh-generator-annprocess
- 1.21
+ ${jmh.version}
junit
junit
- 4.12
+ ${junit.version}
test
jar
org.assertj
assertj-core
- 3.11.1
+ ${assertj.version}
test
- Stream Reduce
+
UTF-8
1.8
1.8
+ 1.21
+ 3.11.1
\ No newline at end of file
diff --git a/java-streams/README.md b/java-streams/README.md
index e294e5aee1..0c9588c47e 100644
--- a/java-streams/README.md
+++ b/java-streams/README.md
@@ -8,7 +8,7 @@
- [Java 8 and Infinite Streams](http://www.baeldung.com/java-inifinite-streams)
- [Java 8 Stream findFirst() vs. findAny()](http://www.baeldung.com/java-stream-findfirst-vs-findany)
- [How to Get the Last Element of a Stream in Java?](http://www.baeldung.com/java-stream-last-element)
-- [”Stream has already been operated upon or closed” Exception in Java](http://www.baeldung.com/java-stream-operated-upon-or-closed-exception)
+- [“Stream has already been operated upon or closed” Exception in Java](http://www.baeldung.com/java-stream-operated-upon-or-closed-exception)
- [Iterable to Stream in Java](http://www.baeldung.com/java-iterable-to-stream)
- [How to Iterate Over a Stream With Indices](http://www.baeldung.com/java-stream-indices)
- [Primitive Type Streams in Java 8](http://www.baeldung.com/java-8-primitive-streams)
diff --git a/jhipster-5/bookstore-monolith/pom.xml b/jhipster-5/bookstore-monolith/pom.xml
index e46804a04c..60fc1acf92 100644
--- a/jhipster-5/bookstore-monolith/pom.xml
+++ b/jhipster-5/bookstore-monolith/pom.xml
@@ -18,91 +18,6 @@
-
-
- 3.0.0
- 1.8
- 2.12.6
- v10.15.0
- 6.4.1
- UTF-8
- UTF-8
- ${project.build.directory}/test-results
- yyyyMMddHHmmss
- ${java.version}
- ${java.version}
- -Djava.security.egd=file:/dev/./urandom -Xmx256m
- jdt_apt
- false
-
-
-
-
-
-
- 2.1.1
-
- 2.0.8.RELEASE
-
- 5.2.17.Final
-
- 3.22.0-GA
-
- 3.5.5
- 3.6
- 2.0.1.Final
- 1.2.0.Final
-
-
- 3.1.0
- 3.8.0
- 2.10
- 3.0.0-M2
- 2.2.1
- 3.1.0
- 2.22.1
- 3.2.2
- 0.9.11
- 1.6
- 0.8.2
- 1.0.0
- 3.4.2
- 3.5.0.1254
- 2.2.5
-
-
- http://localhost:9001
- src/main/webapp/content/**/*.*, src/main/webapp/i18n/*.js, target/www/**/*.*
- S3437,S4502,S4684,UndocumentedApi,BoldAndItalicTagsCheck
-
- src/main/webapp/app/**/*.*
- Web:BoldAndItalicTagsCheck
-
- src/main/java/**/*
- squid:S3437
-
- src/main/java/**/*
- squid:UndocumentedApi
-
- src/main/java/**/*
- squid:S4502
-
- src/main/java/**/*
- squid:S4684
- ${project.testresult.directory}/coverage/jacoco/jacoco.exec
- jacoco
- ${project.testresult.directory}/lcov.info
- ${project.basedir}/src/main/
- ${project.testresult.directory}
- ${project.basedir}/src/test/
-
-
-
-
@@ -1082,4 +997,89 @@
+
+
+
+ 3.0.0
+ 1.8
+ 2.12.6
+ v10.15.0
+ 6.4.1
+ UTF-8
+ UTF-8
+ ${project.build.directory}/test-results
+ yyyyMMddHHmmss
+ ${java.version}
+ ${java.version}
+ -Djava.security.egd=file:/dev/./urandom -Xmx256m
+ jdt_apt
+ false
+
+
+
+
+
+
+ 2.1.1
+
+ 2.0.8.RELEASE
+
+ 5.2.17.Final
+
+ 3.22.0-GA
+
+ 3.5.5
+ 3.6
+ 2.0.1.Final
+ 1.2.0.Final
+
+
+ 3.1.0
+ 3.8.0
+ 2.10
+ 3.0.0-M2
+ 2.2.1
+ 3.1.0
+ 2.22.1
+ 3.2.2
+ 0.9.11
+ 1.6
+ 0.8.2
+ 1.0.0
+ 3.4.2
+ 3.5.0.1254
+ 2.2.5
+
+
+ http://localhost:9001
+ src/main/webapp/content/**/*.*, src/main/webapp/i18n/*.js, target/www/**/*.*
+ S3437,S4502,S4684,UndocumentedApi,BoldAndItalicTagsCheck
+
+ src/main/webapp/app/**/*.*
+ Web:BoldAndItalicTagsCheck
+
+ src/main/java/**/*
+ squid:S3437
+
+ src/main/java/**/*
+ squid:UndocumentedApi
+
+ src/main/java/**/*
+ squid:S4502
+
+ src/main/java/**/*
+ squid:S4684
+ ${project.testresult.directory}/coverage/jacoco/jacoco.exec
+ jacoco
+ ${project.testresult.directory}/lcov.info
+ ${project.basedir}/src/main/
+ ${project.testresult.directory}
+ ${project.basedir}/src/test/
+
+
+
diff --git a/kotlin-libraries/README.md b/kotlin-libraries/README.md
index 5e2526e64e..94359193b6 100644
--- a/kotlin-libraries/README.md
+++ b/kotlin-libraries/README.md
@@ -10,3 +10,5 @@
- [Introduction to Arrow in Kotlin](https://www.baeldung.com/kotlin-arrow)
- [Kotlin with Ktor](https://www.baeldung.com/kotlin-ktor)
- [REST API With Kotlin and Kovert](https://www.baeldung.com/kotlin-kovert)
+- [MockK: A Mocking Library for Kotlin](https://www.baeldung.com/kotlin-mockk)
+- [Kotlin Immutable Collections](https://www.baeldung.com/kotlin-immutable-collections)
\ No newline at end of file
diff --git a/libraries2/pom.xml b/libraries-2/pom.xml
similarity index 100%
rename from libraries2/pom.xml
rename to libraries-2/pom.xml
index 84f19b359d..a839f56b56 100644
--- a/libraries2/pom.xml
+++ b/libraries-2/pom.xml
@@ -13,10 +13,6 @@
1.0.0-SNAPSHOT
-
- 6.0.0.Final
-
-
jboss-public-repository-group
@@ -40,4 +36,8 @@
${jbpm.version}
+
+
+ 6.0.0.Final
+
diff --git a/libraries2/src/main/java/com/baeldung/jbpm/WorkflowProcessMain.java b/libraries-2/src/main/java/com/baeldung/jbpm/WorkflowProcessMain.java
similarity index 100%
rename from libraries2/src/main/java/com/baeldung/jbpm/WorkflowProcessMain.java
rename to libraries-2/src/main/java/com/baeldung/jbpm/WorkflowProcessMain.java
diff --git a/libraries2/src/main/java/com/baeldung/jbpm/engine/WorkflowEngine.java b/libraries-2/src/main/java/com/baeldung/jbpm/engine/WorkflowEngine.java
similarity index 100%
rename from libraries2/src/main/java/com/baeldung/jbpm/engine/WorkflowEngine.java
rename to libraries-2/src/main/java/com/baeldung/jbpm/engine/WorkflowEngine.java
diff --git a/libraries2/src/main/java/com/baeldung/jbpm/engine/WorkflowEngineImpl.java b/libraries-2/src/main/java/com/baeldung/jbpm/engine/WorkflowEngineImpl.java
similarity index 100%
rename from libraries2/src/main/java/com/baeldung/jbpm/engine/WorkflowEngineImpl.java
rename to libraries-2/src/main/java/com/baeldung/jbpm/engine/WorkflowEngineImpl.java
diff --git a/libraries2/src/main/resources/META-INF/kmodule.xml b/libraries-2/src/main/resources/META-INF/kmodule.xml
similarity index 100%
rename from libraries2/src/main/resources/META-INF/kmodule.xml
rename to libraries-2/src/main/resources/META-INF/kmodule.xml
diff --git a/libraries2/src/main/resources/com/baeldung/process/helloworld.bpmn b/libraries-2/src/main/resources/com/baeldung/process/helloworld.bpmn
similarity index 100%
rename from libraries2/src/main/resources/com/baeldung/process/helloworld.bpmn
rename to libraries-2/src/main/resources/com/baeldung/process/helloworld.bpmn
diff --git a/libraries2/src/test/java/com/baeldung/jbpm/WorkflowEngineIntegrationTest.java b/libraries-2/src/test/java/com/baeldung/jbpm/WorkflowEngineIntegrationTest.java
similarity index 100%
rename from libraries2/src/test/java/com/baeldung/jbpm/WorkflowEngineIntegrationTest.java
rename to libraries-2/src/test/java/com/baeldung/jbpm/WorkflowEngineIntegrationTest.java
diff --git a/libraries-security/pom.xml b/libraries-security/pom.xml
index 9f125361ba..17d57fe203 100644
--- a/libraries-security/pom.xml
+++ b/libraries-security/pom.xml
@@ -32,6 +32,12 @@
${scribejava.version}
+
+ com.google.crypto.tink
+ tink
+ ${tink.version}
+
+
junit
junit
@@ -55,6 +61,7 @@
5.6.0
2.3.3.RELEASE
1.3.1
+ 1.2.2
1.2.2
diff --git a/libraries-security/src/test/java/com/baeldung/tink/TinkUnitTest.java b/libraries-security/src/test/java/com/baeldung/tink/TinkUnitTest.java
new file mode 100644
index 0000000000..b98c698016
--- /dev/null
+++ b/libraries-security/src/test/java/com/baeldung/tink/TinkUnitTest.java
@@ -0,0 +1,101 @@
+package com.baeldung.tink;
+
+import com.google.crypto.tink.*;
+import com.google.crypto.tink.aead.AeadConfig;
+import com.google.crypto.tink.aead.AeadFactory;
+import com.google.crypto.tink.aead.AeadKeyTemplates;
+import com.google.crypto.tink.config.TinkConfig;
+import com.google.crypto.tink.hybrid.HybridDecryptFactory;
+import com.google.crypto.tink.hybrid.HybridEncryptFactory;
+import com.google.crypto.tink.hybrid.HybridKeyTemplates;
+import com.google.crypto.tink.mac.MacFactory;
+import com.google.crypto.tink.mac.MacKeyTemplates;
+import com.google.crypto.tink.signature.PublicKeySignFactory;
+import com.google.crypto.tink.signature.PublicKeyVerifyFactory;
+import com.google.crypto.tink.signature.SignatureKeyTemplates;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.security.GeneralSecurityException;
+
+public class TinkUnitTest {
+
+ private static final String PLAINTEXT = "BAELDUNG";
+ private static final String DATA = "TINK";
+
+ @Test
+ public void givenPlaintext_whenEncryptWithAead_thenPlaintextIsEncrypted() throws GeneralSecurityException {
+
+ AeadConfig.register();
+
+ KeysetHandle keysetHandle = KeysetHandle.generateNew(
+ AeadKeyTemplates.AES256_GCM);
+
+ Aead aead = AeadFactory.getPrimitive(keysetHandle);
+
+ byte[] ciphertext = aead.encrypt(PLAINTEXT.getBytes(),
+ DATA.getBytes());
+
+ Assert.assertNotEquals(PLAINTEXT, new String(ciphertext));
+ }
+
+ @Test
+ public void givenData_whenComputeMAC_thenVerifyMAC() throws GeneralSecurityException {
+
+ TinkConfig.register();
+
+ KeysetHandle keysetHandle = KeysetHandle.generateNew(
+ MacKeyTemplates.HMAC_SHA256_128BITTAG);
+
+ Mac mac = MacFactory.getPrimitive(keysetHandle);
+
+ byte[] tag = mac.computeMac(DATA.getBytes());
+
+ mac.verifyMac(tag, DATA.getBytes());
+ }
+
+ @Test
+ public void givenData_whenSignData_thenVerifySignature() throws GeneralSecurityException {
+
+ TinkConfig.register();
+
+ KeysetHandle privateKeysetHandle = KeysetHandle.generateNew(
+ SignatureKeyTemplates.ECDSA_P256);
+
+ PublicKeySign signer = PublicKeySignFactory.getPrimitive(privateKeysetHandle);
+
+ byte[] signature = signer.sign(DATA.getBytes());
+
+ KeysetHandle publicKeysetHandle =
+ privateKeysetHandle.getPublicKeysetHandle();
+
+ PublicKeyVerify verifier = PublicKeyVerifyFactory.getPrimitive(publicKeysetHandle);
+
+ verifier.verify(signature, DATA.getBytes());
+ }
+
+ @Test
+ public void givenPlaintext_whenEncryptWithHybridEncryption_thenVerifyDecryptedIsEqual() throws GeneralSecurityException {
+
+ TinkConfig.register();
+
+ KeysetHandle privateKeysetHandle = KeysetHandle.generateNew(
+ HybridKeyTemplates.ECIES_P256_HKDF_HMAC_SHA256_AES128_CTR_HMAC_SHA256);
+
+ KeysetHandle publicKeysetHandle = privateKeysetHandle.getPublicKeysetHandle();
+
+ HybridEncrypt hybridEncrypt = HybridEncryptFactory.getPrimitive(publicKeysetHandle);
+
+ HybridDecrypt hybridDecrypt = HybridDecryptFactory.getPrimitive(privateKeysetHandle);
+
+ String contextInfo = "Tink";
+
+ byte[] ciphertext = hybridEncrypt.encrypt(PLAINTEXT.getBytes(), contextInfo.getBytes());
+
+ byte[] plaintextDecrypted = hybridDecrypt.decrypt(ciphertext, contextInfo.getBytes());
+
+ Assert.assertEquals(PLAINTEXT,new String(plaintextDecrypted));
+ }
+}
+
+
diff --git a/libraries-server/README.md b/libraries-server/README.md
index 75c12fd61a..dc6bcd0716 100644
--- a/libraries-server/README.md
+++ b/libraries-server/README.md
@@ -3,7 +3,7 @@
- [Embedded Jetty Server in Java](http://www.baeldung.com/jetty-embedded)
- [Introduction to Netty](http://www.baeldung.com/netty)
- [Exceptions in Netty](http://www.baeldung.com/netty-exception-handling)
-- [Programatically Create, Configure, and Run a Tomcat Server](http://www.baeldung.com/tomcat-programmatic-setup)
+- [Programmatically Create, Configure and Run a Tomcat Server](http://www.baeldung.com/tomcat-programmatic-setup)
- [Creating and Configuring Jetty 9 Server in Java](http://www.baeldung.com/jetty-java-programmatic)
- [Testing Netty with EmbeddedChannel](http://www.baeldung.com/testing-netty-embedded-channel)
- [MQTT Client in Java](https://www.baeldung.com/java-mqtt-client)
diff --git a/libraries/README.md b/libraries/README.md
index 57f22631f1..f6a39daef1 100644
--- a/libraries/README.md
+++ b/libraries/README.md
@@ -6,7 +6,7 @@
- [Introduction to Apache Flink with Java](http://www.baeldung.com/apache-flink)
- [Introduction to JSONassert](http://www.baeldung.com/jsonassert)
- [Intro to JaVers](http://www.baeldung.com/javers)
-- [Intro to Serenity BDD](http://www.baeldung.com/serenity-bdd)
+- [Introduction to Serenity BDD](http://www.baeldung.com/serenity-bdd)
- [Merging Streams in Java](http://www.baeldung.com/java-merge-streams)
- [Serenity BDD and Screenplay](http://www.baeldung.com/serenity-screenplay)
- [Introduction to Quartz](http://www.baeldung.com/quartz)
@@ -14,14 +14,14 @@
- [Software Transactional Memory in Java Using Multiverse](http://www.baeldung.com/java-multiverse-stm)
- [Serenity BDD with Spring and JBehave](http://www.baeldung.com/serenity-spring-jbehave)
- [Locality-Sensitive Hashing in Java Using Java-LSH](http://www.baeldung.com/locality-sensitive-hashing)
-- [Introduction to Awaitility](http://www.baeldung.com/awaitlity-testing)
+- [Introduction to Awaitlity](http://www.baeldung.com/awaitlity-testing)
- [Guide to the HyperLogLog Algorithm](http://www.baeldung.com/java-hyperloglog)
- [Introduction to Neuroph](http://www.baeldung.com/neuroph)
- [Quick Guide to RSS with Rome](http://www.baeldung.com/rome-rss)
- [Introduction to PCollections](http://www.baeldung.com/java-pcollections)
- [Introduction to Hoverfly in Java](http://www.baeldung.com/hoverfly)
- [Introduction to Eclipse Collections](http://www.baeldung.com/eclipse-collections)
-- [DistinctBy in Java Stream API](http://www.baeldung.com/java-streams-distinct-by)
+- [DistinctBy in the Java Stream API](http://www.baeldung.com/java-streams-distinct-by)
- [Introduction to NoException](http://www.baeldung.com/no-exception)
- [Introduction to Conflict-Free Replicated Data Types](http://www.baeldung.com/java-conflict-free-replicated-data-types)
- [Introduction to javax.measure](http://www.baeldung.com/javax-measure)
@@ -36,7 +36,7 @@
- [Introduction To Docx4J](http://www.baeldung.com/docx4j)
- [Introduction to StreamEx](http://www.baeldung.com/streamex)
- [Introduction to BouncyCastle with Java](http://www.baeldung.com/java-bouncy-castle)
-- [Guide to google-http-client](http://www.baeldung.com/google-http-client)
+- [A Guide to Google-Http-Client](http://www.baeldung.com/google-http-client)
- [Interact with Google Sheets from Java](http://www.baeldung.com/google-sheets-java-client)
- [A Docker Guide for Java](http://www.baeldung.com/docker-java-api)
- [Introduction To OpenCSV](http://www.baeldung.com/opencsv)
diff --git a/logging-modules/README.md b/logging-modules/README.md
index 0f12d7eb22..17405847b1 100644
--- a/logging-modules/README.md
+++ b/logging-modules/README.md
@@ -4,5 +4,4 @@
### Relevant Articles:
- [Creating a Custom Logback Appender](http://www.baeldung.com/custom-logback-appender)
-- [Get Log Output in JSON Format](http://www.baeldung.com/java-log-json-output)
- [A Guide To Logback](http://www.baeldung.com/logback)
diff --git a/logging-modules/log4j2/README.md b/logging-modules/log4j2/README.md
index 2cf6f9768f..dd326bc7a1 100644
--- a/logging-modules/log4j2/README.md
+++ b/logging-modules/log4j2/README.md
@@ -4,3 +4,4 @@
- [Log4j 2 and Lambda Expressions](http://www.baeldung.com/log4j-2-lazy-logging)
- [Programmatic Configuration with Log4j 2](http://www.baeldung.com/log4j2-programmatic-config)
- [Creating a Custom Log4j2 Appender](https://www.baeldung.com/log4j2-custom-appender)
+- [Get Log Output in JSON](http://www.baeldung.com/java-log-json-output)
diff --git a/logging-modules/logback/README.md b/logging-modules/logback/README.md
index e69de29bb2..df55492b69 100644
--- a/logging-modules/logback/README.md
+++ b/logging-modules/logback/README.md
@@ -0,0 +1,3 @@
+### Relevant Articles:
+
+- [Get Log Output in JSON](https://www.baeldung.com/java-log-json-output)
diff --git a/logging-modules/logback/pom.xml b/logging-modules/logback/pom.xml
index 845424af0c..41a28ffd17 100644
--- a/logging-modules/logback/pom.xml
+++ b/logging-modules/logback/pom.xml
@@ -37,12 +37,29 @@
jackson-databind
${jackson.version}
+
+ org.docx4j
+ docx4j
+ ${docx4j.version}
+
+
+ org.slf4j
+ slf4j-log4j12
+
+
+ log4j
+ log4j
+
+
+
+
1.2.3
0.1.5
2.9.7
+ 3.3.5
diff --git a/maven/custom-rule/pom.xml b/maven/custom-rule/pom.xml
index 25a3489fb9..2fbeb18922 100644
--- a/maven/custom-rule/pom.xml
+++ b/maven/custom-rule/pom.xml
@@ -2,20 +2,15 @@
+ 4.0.0
+ custom-rule
+ custom-rule
+
maven
com.baeldung
0.0.1-SNAPSHOT
- 4.0.0
- custom-rule
- custom-rule
-
-
- 3.0.0-M2
- 2.0.9
-
-
@@ -47,7 +42,7 @@
org.codehaus.plexus
plexus-container-default
- 1.0-alpha-9
+ ${plexus-container-default.version}
@@ -64,7 +59,9 @@
-
-
-
-
\ No newline at end of file
+
+ 3.0.0-M2
+ 2.0.9
+ 1.0-alpha-9
+
+
diff --git a/maven/maven-enforcer/pom.xml b/maven/maven-enforcer/pom.xml
index 9826beb0d9..b18be4f43d 100644
--- a/maven/maven-enforcer/pom.xml
+++ b/maven/maven-enforcer/pom.xml
@@ -2,14 +2,15 @@
+ 4.0.0
+ maven-enforcer
+ maven-enforcer
+
maven
com.baeldung
0.0.1-SNAPSHOT
- 4.0.0
- maven-enforcer
- maven-enforcer
diff --git a/maven/maven-war-plugin/pom.xml b/maven/maven-war-plugin/pom.xml
index 5169a21e78..517c08978f 100644
--- a/maven/maven-war-plugin/pom.xml
+++ b/maven/maven-war-plugin/pom.xml
@@ -7,11 +7,6 @@
0.0.1-SNAPSHOT
war
maven-war-plugin-property
-
-
-
- false
-
@@ -26,4 +21,9 @@
+
+
+
+ false
+
\ No newline at end of file
diff --git a/patterns/README.md b/patterns/README.md
index 1c9a59ea21..f627251aa4 100644
--- a/patterns/README.md
+++ b/patterns/README.md
@@ -2,3 +2,5 @@
- [A Guide to the Front Controller Pattern in Java](http://www.baeldung.com/java-front-controller-pattern)
- [Introduction to Intercepting Filter Pattern in Java](http://www.baeldung.com/intercepting-filter-pattern-in-java)
- [Introduction to the Null Object Pattern](https://www.baeldung.com/java-null-object-pattern)
+- [The Dependency Inversion Principle in Java](https://www.baeldung.com/java-dependency-inversion-principle)
+- [Avoid Check for Null Statement in Java](https://www.baeldung.com/java-avoid-null-check)
diff --git a/patterns/design-patterns-2/src/main/java/com/baeldung/nulls/UsingOptional.java b/patterns/design-patterns-2/src/main/java/com/baeldung/nulls/UsingOptional.java
index 6c17290a72..d5dd56e760 100644
--- a/patterns/design-patterns-2/src/main/java/com/baeldung/nulls/UsingOptional.java
+++ b/patterns/design-patterns-2/src/main/java/com/baeldung/nulls/UsingOptional.java
@@ -8,11 +8,7 @@ public class UsingOptional {
String response = doSomething(processed);
- if (response == null) {
- return Optional.empty();
- }
-
- return Optional.of(response);
+ return Optional.ofNullable(response);
}
private String doSomething(boolean processed) {
diff --git a/patterns/design-patterns/README.md b/patterns/design-patterns/README.md
index c43ea48505..605fdc0d6e 100644
--- a/patterns/design-patterns/README.md
+++ b/patterns/design-patterns/README.md
@@ -19,4 +19,4 @@
- [The Command Pattern in Java](http://www.baeldung.com/java-command-pattern)
- [Java Constructors vs Static Factory Methods](https://www.baeldung.com/java-constructors-vs-static-factory-methods)
- [The Adapter Pattern in Java](https://www.baeldung.com/java-adapter-pattern)
-- [Currying in Java](https://baeldung.com/currying-in-java)
+- [Currying in Java](https://www.baeldung.com/java-currying)
diff --git a/patterns/principles/solid/README.md b/patterns/principles/solid/README.md
index e2d72ecd28..ddd2f78b7e 100644
--- a/patterns/principles/solid/README.md
+++ b/patterns/principles/solid/README.md
@@ -1,5 +1,5 @@
### Relevant Articles:
-- [A Guide to Solid Principles](https://www.baeldung.com/solid-principles)
+- [A Solid Guide to Solid Principles](https://www.baeldung.com/solid-principles)
diff --git a/patterns/solid/pom.xml b/patterns/solid/pom.xml
index 146a9903cf..faf8bdc8d9 100644
--- a/patterns/solid/pom.xml
+++ b/patterns/solid/pom.xml
@@ -8,7 +8,7 @@
solid
1.0-SNAPSHOT
-
+
com.baeldung
patterns
1.0.0-SNAPSHOT
diff --git a/persistence-modules/README.md b/persistence-modules/README.md
index 87dc9522fd..2fbaf25f2f 100644
--- a/persistence-modules/README.md
+++ b/persistence-modules/README.md
@@ -11,3 +11,5 @@
- [Pessimistic Locking in JPA](http://www.baeldung.com/jpa-pessimistic-locking)
- [Get All Data from a Table with Hibernate](https://www.baeldung.com/hibernate-select-all)
- [Spring Data with Reactive Cassandra](https://www.baeldung.com/spring-data-cassandra-reactive)
+- [Spring Data JPA – Derived Delete Methods](https://www.baeldung.com/spring-data-jpa-deleteby)
+- [Difference Between save() and saveAndFlush() in Spring Data JPA](https://www.baeldung.com/spring-data-jpa-save-saveandflush)
diff --git a/persistence-modules/core-java-persistence/pom.xml b/persistence-modules/core-java-persistence/pom.xml
index a777eeb73f..2ad2083fec 100644
--- a/persistence-modules/core-java-persistence/pom.xml
+++ b/persistence-modules/core-java-persistence/pom.xml
@@ -6,15 +6,21 @@
0.1.0-SNAPSHOT
core-java-persistence
jar
-
+
com.baeldung
parent-java
0.0.1-SNAPSHOT
../../parent-java
-
+
+
+ org.postgresql
+ postgresql
+ ${postgresql.version}
+ test
+
org.assertj
assertj-core
@@ -52,7 +58,7 @@
${springframework.boot.spring-boot-starter.version}
-
+
core-java-persistence
@@ -62,8 +68,10 @@
-
+
+ 42.2.5.jre7
+ 8.0.15
3.10.0
1.4.197
2.4.0
@@ -72,5 +80,5 @@
1.5.8.RELEASE
4.3.4.RELEASE
-
+
\ No newline at end of file
diff --git a/persistence-modules/core-java-persistence/src/main/java/com/baeldung/jdbc/joins/ArticleWithAuthor.java b/persistence-modules/core-java-persistence/src/main/java/com/baeldung/jdbc/joins/ArticleWithAuthor.java
new file mode 100644
index 0000000000..5ce196ee47
--- /dev/null
+++ b/persistence-modules/core-java-persistence/src/main/java/com/baeldung/jdbc/joins/ArticleWithAuthor.java
@@ -0,0 +1,41 @@
+package com.baeldung.jdbc.joins;
+
+class ArticleWithAuthor {
+
+ private String title;
+
+ private String authorFirstName;
+
+ private String authorLastName;
+
+ public ArticleWithAuthor(String title, String authorFirstName, String authorLastName) {
+ this.title = title;
+ this.authorFirstName = authorFirstName;
+ this.authorLastName = authorLastName;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public String getAuthorFirstName() {
+ return authorFirstName;
+ }
+
+ public void setAuthorFirstName(String authorFirstName) {
+ this.authorFirstName = authorFirstName;
+ }
+
+ public String getAuthorLastName() {
+ return authorLastName;
+ }
+
+ public void setAuthorLastName(String authorLastName) {
+ this.authorLastName = authorLastName;
+ }
+
+}
diff --git a/persistence-modules/core-java-persistence/src/main/java/com/baeldung/jdbc/joins/ArticleWithAuthorDAO.java b/persistence-modules/core-java-persistence/src/main/java/com/baeldung/jdbc/joins/ArticleWithAuthorDAO.java
new file mode 100644
index 0000000000..55f03d99ec
--- /dev/null
+++ b/persistence-modules/core-java-persistence/src/main/java/com/baeldung/jdbc/joins/ArticleWithAuthorDAO.java
@@ -0,0 +1,61 @@
+package com.baeldung.jdbc.joins;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+
+class ArticleWithAuthorDAO {
+
+ private static final String QUERY_TEMPLATE = "SELECT ARTICLE.TITLE, AUTHOR.LAST_NAME, AUTHOR.FIRST_NAME FROM ARTICLE %s AUTHOR ON AUTHOR.id=ARTICLE.AUTHOR_ID";
+ private final Connection connection;
+
+ ArticleWithAuthorDAO(Connection connection) {
+ this.connection = connection;
+ }
+
+ List articleInnerJoinAuthor() {
+ String query = String.format(QUERY_TEMPLATE, "INNER JOIN");
+ return executeQuery(query);
+ }
+
+ List articleLeftJoinAuthor() {
+ String query = String.format(QUERY_TEMPLATE, "LEFT JOIN");
+ return executeQuery(query);
+ }
+
+ List articleRightJoinAuthor() {
+ String query = String.format(QUERY_TEMPLATE, "RIGHT JOIN");
+ return executeQuery(query);
+ }
+
+ List articleFullJoinAuthor() {
+ String query = String.format(QUERY_TEMPLATE, "FULL JOIN");
+ return executeQuery(query);
+ }
+
+ private List executeQuery(String query) {
+ try (Statement statement = connection.createStatement()) {
+ ResultSet resultSet = statement.executeQuery(query);
+ return mapToList(resultSet);
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ private List mapToList(ResultSet resultSet) throws SQLException {
+ List list = new ArrayList<>();
+ while (resultSet.next()) {
+ ArticleWithAuthor articleWithAuthor = new ArticleWithAuthor(
+ resultSet.getString("TITLE"),
+ resultSet.getString("FIRST_NAME"),
+ resultSet.getString("LAST_NAME")
+ );
+ list.add(articleWithAuthor);
+ }
+ return list;
+ }
+}
diff --git a/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/joins/ArticleWithAuthorDAOIntegrationTest.java b/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/joins/ArticleWithAuthorDAOIntegrationTest.java
new file mode 100644
index 0000000000..5c20b6bf1e
--- /dev/null
+++ b/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/joins/ArticleWithAuthorDAOIntegrationTest.java
@@ -0,0 +1,89 @@
+package com.baeldung.jdbc.joins;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.List;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class ArticleWithAuthorDAOIntegrationTest {
+ private Connection connection;
+
+ private ArticleWithAuthorDAO articleWithAuthorDAO;
+
+ @Before
+ public void setup() throws ClassNotFoundException, SQLException {
+ Class.forName("org.postgresql.Driver");
+ connection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/myDb", "user", "pass");
+ articleWithAuthorDAO = new ArticleWithAuthorDAO(connection);
+ Statement statement = connection.createStatement();
+ String createAuthorSql = "CREATE TABLE IF NOT EXISTS AUTHOR (ID int NOT NULL PRIMARY KEY, FIRST_NAME varchar(255), LAST_NAME varchar(255));";
+ String createArticleSql = "CREATE TABLE IF NOT EXISTS ARTICLE (ID int NOT NULL PRIMARY KEY, TITLE varchar(255) NOT NULL, AUTHOR_ID int, FOREIGN KEY(AUTHOR_ID) REFERENCES AUTHOR(ID));";
+ statement.execute(createAuthorSql);
+ statement.execute(createArticleSql);
+
+ insertTestData(statement);
+ }
+
+ @Test
+ public void whenQueryWithInnerJoin_thenShouldReturnProperRows() {
+ List articleWithAuthorList = articleWithAuthorDAO.articleInnerJoinAuthor();
+
+ assertThat(articleWithAuthorList).hasSize(4);
+ assertThat(articleWithAuthorList).noneMatch(row -> row.getAuthorFirstName() == null || row.getTitle() == null);
+ }
+
+ @Test
+ public void whenQueryWithLeftJoin_thenShouldReturnProperRows() {
+ List articleWithAuthorList = articleWithAuthorDAO.articleLeftJoinAuthor();
+
+ assertThat(articleWithAuthorList).hasSize(5);
+ assertThat(articleWithAuthorList).anyMatch(row -> row.getAuthorFirstName() == null);
+ }
+
+ @Test
+ public void whenQueryWithRightJoin_thenShouldReturnProperRows() {
+ List articleWithAuthorList = articleWithAuthorDAO.articleRightJoinAuthor();
+
+ assertThat(articleWithAuthorList).hasSize(5);
+ assertThat(articleWithAuthorList).anyMatch(row -> row.getTitle() == null);
+ }
+
+ @Test
+ public void whenQueryWithFullJoin_thenShouldReturnProperRows() {
+ List articleWithAuthorList = articleWithAuthorDAO.articleFullJoinAuthor();
+
+ assertThat(articleWithAuthorList).hasSize(6);
+ assertThat(articleWithAuthorList).anyMatch(row -> row.getTitle() == null);
+ assertThat(articleWithAuthorList).anyMatch(row -> row.getAuthorFirstName() == null);
+ }
+
+ @After
+ public void cleanup() throws SQLException {
+ connection.createStatement().execute("DROP TABLE ARTICLE");
+ connection.createStatement().execute("DROP TABLE AUTHOR");
+ connection.close();
+ }
+
+ public void insertTestData(Statement statement) throws SQLException {
+ String insertAuthors = "INSERT INTO AUTHOR VALUES "
+ + "(1, 'Siena', 'Kerr'),"
+ + "(2, 'Daniele', 'Ferguson'),"
+ + "(3, 'Luciano', 'Wise'),"
+ + "(4, 'Jonas', 'Lugo');";
+ String insertArticles = "INSERT INTO ARTICLE VALUES "
+ + "(1, 'First steps in Java', 1),"
+ + "(2, 'SpringBoot tutorial', 1),"
+ + "(3, 'Java 12 insights', null),"
+ + "(4, 'SQL JOINS', 2),"
+ + "(5, 'Introduction to Spring Security', 3);";
+ statement.execute(insertAuthors);
+ statement.execute(insertArticles);
+ }
+}
diff --git a/persistence-modules/hibernate5/README.md b/persistence-modules/hibernate5/README.md
index a37720a428..68008bc8fe 100644
--- a/persistence-modules/hibernate5/README.md
+++ b/persistence-modules/hibernate5/README.md
@@ -32,3 +32,4 @@
- [Common Hibernate Exceptions](https://www.baeldung.com/hibernate-exceptions)
- [Hibernate Aggregate Functions](https://www.baeldung.com/hibernate-aggregate-functions)
- [Hibernate Query Plan Cache](https://www.baeldung.com/hibernate-query-plan-cache)
+- [TransactionRequiredException Error](https://www.baeldung.com/jpa-transaction-required-exception)
diff --git a/persistence-modules/java-jpa/README.md b/persistence-modules/java-jpa/README.md
index 2424999fb3..5be1015942 100644
--- a/persistence-modules/java-jpa/README.md
+++ b/persistence-modules/java-jpa/README.md
@@ -2,7 +2,7 @@
- [A Guide to SqlResultSetMapping](http://www.baeldung.com/jpa-sql-resultset-mapping)
- [A Guide to Stored Procedures with JPA](http://www.baeldung.com/jpa-stored-procedures)
-- [Fixing the JPA error “java.lang.String cannot be cast to Ljava.lang.String;”](https://www.baeldung.com/jpa-error-java-lang-string-cannot-be-cast)
+- [Fixing the JPA error “java.lang.String cannot be cast to [Ljava.lang.String;”]](https://www.baeldung.com/jpa-error-java-lang-string-cannot-be-cast)
- [JPA Entity Graph](https://www.baeldung.com/jpa-entity-graph)
- [JPA 2.2 Support for Java 8 Date/Time Types](https://www.baeldung.com/jpa-java-time)
- [Converting Between LocalDate and SQL Date](https://www.baeldung.com/java-convert-localdate-sql-date)
diff --git a/persistence-modules/jnosql/jnosql-artemis/pom.xml b/persistence-modules/jnosql/jnosql-artemis/pom.xml
index a07f26c6ee..09d6af13df 100644
--- a/persistence-modules/jnosql/jnosql-artemis/pom.xml
+++ b/persistence-modules/jnosql/jnosql-artemis/pom.xml
@@ -17,7 +17,7 @@
javax
javaee-web-api
- 8.0
+ ${javaee-web-api.version}
provided
@@ -80,6 +80,7 @@
2.4.2
false
+ 8.0
diff --git a/persistence-modules/jnosql/jnosql-diana/pom.xml b/persistence-modules/jnosql/jnosql-diana/pom.xml
index b52c808cf5..a4951761d8 100644
--- a/persistence-modules/jnosql/jnosql-diana/pom.xml
+++ b/persistence-modules/jnosql/jnosql-diana/pom.xml
@@ -18,36 +18,36 @@
org.jnosql.diana
diana-document
- 0.0.5
+ ${jnosql.version}
org.jnosql.diana
mongodb-driver
- 0.0.5
+ ${jnosql.version}
org.jnosql.diana
diana-column
- 0.0.5
+ ${jnosql.version}
org.jnosql.diana
cassandra-driver
- 0.0.5
+ ${jnosql.version}
org.jnosql.diana
diana-key-value
- 0.0.5
+ ${jnosql.version}
org.jnosql.diana
hazelcast-driver
- 0.0.5
+ ${jnosql.version}
diff --git a/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/springboot/SpringBootH2Application.java b/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/springboot/SpringBootH2Application.java
new file mode 100644
index 0000000000..378093cfa9
--- /dev/null
+++ b/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/springboot/SpringBootH2Application.java
@@ -0,0 +1,12 @@
+package com.baeldung.h2db.springboot;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class SpringBootH2Application {
+
+ public static void main(String... args) {
+ SpringApplication.run(SpringBootH2Application.class, args);
+ }
+}
diff --git a/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/springboot/daos/UserRepository.java b/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/springboot/daos/UserRepository.java
new file mode 100644
index 0000000000..35e496e910
--- /dev/null
+++ b/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/springboot/daos/UserRepository.java
@@ -0,0 +1,10 @@
+package com.baeldung.h2db.springboot.daos;
+
+
+
+
+import com.baeldung.h2db.springboot.models.User;
+import org.springframework.data.repository.CrudRepository;
+
+public interface UserRepository extends CrudRepository {
+}
diff --git a/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/springboot/models/User.java b/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/springboot/models/User.java
new file mode 100644
index 0000000000..fa3c01c035
--- /dev/null
+++ b/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/springboot/models/User.java
@@ -0,0 +1,54 @@
+package com.baeldung.h2db.springboot.models;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Table(name = "users")
+@Entity
+public class User {
+
+ @Id
+ @GeneratedValue
+ private int id;
+
+ private String firstName;
+
+ private String lastName;
+
+ public User() { }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+ @Override
+ public String toString() {
+ return "User{" +
+ "id=" + id +
+ ", firstName='" + firstName + '\'' +
+ ", lastName='" + lastName + '\'' +
+ '}';
+ }
+}
diff --git a/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/resources/application.properties b/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/resources/application.properties
index 5e425a3550..109b389b58 100644
--- a/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/resources/application.properties
+++ b/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/resources/application.properties
@@ -2,7 +2,7 @@ spring.datasource.url=jdbc:h2:mem:mydb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
-spring.jpa.hibernate.ddl-auto=create
+spring.jpa.hibernate.ddl-auto=create-drop
spring.h2.console.enabled=true
spring.h2.console.path=/h2-console
debug=true
\ No newline at end of file
diff --git a/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/resources/data.sql b/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/resources/data.sql
new file mode 100644
index 0000000000..2d7b446005
--- /dev/null
+++ b/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/resources/data.sql
@@ -0,0 +1,13 @@
+DROP TABLE IF EXISTS billionaires;
+
+CREATE TABLE billionaires (
+ id INT AUTO_INCREMENT PRIMARY KEY,
+ first_name VARCHAR(250) NOT NULL,
+ last_name VARCHAR(250) NOT NULL,
+ career VARCHAR(250) DEFAULT NULL
+);
+
+INSERT INTO billionaires (first_name, last_name, career) VALUES
+('Aliko', 'Dangote', 'Billionaire Industrialist'),
+('Bill', 'Gates', 'Billionaire Tech Entrepreneur'),
+('Folrunsho', 'Alakija', 'Billionaire Oil Magnate');
\ No newline at end of file
diff --git a/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/test/java/com/baeldung/SpringBootH2IntegrationTest.java b/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/test/java/com/baeldung/SpringBootH2IntegrationTest.java
new file mode 100644
index 0000000000..aecc63c599
--- /dev/null
+++ b/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/test/java/com/baeldung/SpringBootH2IntegrationTest.java
@@ -0,0 +1,50 @@
+package com.baeldung;
+
+import com.baeldung.h2db.springboot.SpringBootH2Application;
+import com.baeldung.h2db.springboot.daos.UserRepository;
+import com.baeldung.h2db.springboot.models.User;
+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 java.util.List;
+
+import static org.junit.Assert.*;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = SpringBootH2Application.class)
+public class SpringBootH2IntegrationTest {
+
+ @Autowired
+ private UserRepository userRepository;
+
+ @Test
+ public void contextLoads() { }
+
+ @Test
+ public void givenUserProfile_whenAddUser_thenCreateNewUser() {
+ User user = new User();
+ user.setFirstName("John");
+ user.setLastName("Doe");
+ userRepository.save(user);
+ List users = (List) userRepository.findAll();
+ assertFalse(users.isEmpty());
+
+ String firstName = "Aliko";
+ String lastName = "Dangote";
+ User user1 = userRepository.findById(users.get(0).getId()).get();
+ user1.setLastName(lastName);
+ user1.setFirstName(firstName);
+ userRepository.save(user1);
+
+ user = userRepository.findById(user.getId()).get();
+ assertEquals(user.getFirstName(), firstName);
+ assertEquals(user.getLastName(), lastName);
+
+ userRepository.deleteById(user.getId());
+ assertTrue( ((List) userRepository.findAll()).isEmpty());
+ }
+
+}
diff --git a/persistence-modules/spring-boot-persistence/README.MD b/persistence-modules/spring-boot-persistence/README.MD
index ee7c2e298e..709f505ea9 100644
--- a/persistence-modules/spring-boot-persistence/README.MD
+++ b/persistence-modules/spring-boot-persistence/README.MD
@@ -8,3 +8,4 @@
- [Integrating Spring Boot with HSQLDB](https://www.baeldung.com/spring-boot-hsqldb)
- [Configuring a DataSource Programmatically in Spring Boot](https://www.baeldung.com/spring-boot-configure-data-source-programmatic)
- [Resolving “Failed to Configure a DataSource” Error](https://www.baeldung.com/spring-boot-failed-to-configure-data-source)
+- [Spring Boot with Hibernate](https://www.baeldung.com/spring-boot-hibernate)
diff --git a/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/boot/config/H2JpaConfig.java b/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/boot/config/H2JpaConfig.java
index 547a905d91..c5c77be56f 100644
--- a/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/boot/config/H2JpaConfig.java
+++ b/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/boot/config/H2JpaConfig.java
@@ -1,13 +1,9 @@
package com.baeldung.boot.config;
-import java.util.Properties;
-
-import javax.persistence.EntityManagerFactory;
-import javax.sql.DataSource;
-
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Profile;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
@@ -17,10 +13,17 @@ import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.annotation.EnableTransactionManagement;
+import javax.persistence.EntityManagerFactory;
+import javax.sql.DataSource;
+import java.util.Properties;
+
@Configuration
@EnableJpaRepositories(basePackages = { "com.baeldung.boot.repository", "com.baeldung.repository" })
@PropertySource("classpath:persistence-generic-entity.properties")
@EnableTransactionManagement
+@Profile("default") //only required to allow H2JpaConfig and H2TestProfileJPAConfig to coexist in same project
+ //this demo project is showcasing several ways to achieve the same end, and class-level
+ //Profile annotations are only necessary because the different techniques are sharing a project
public class H2JpaConfig {
@Autowired
diff --git a/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/SpringBootProfileIntegrationTest.java b/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/SpringBootProfileIntegrationTest.java
index 0227458987..d7bb44e133 100644
--- a/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/SpringBootProfileIntegrationTest.java
+++ b/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/SpringBootProfileIntegrationTest.java
@@ -1,8 +1,9 @@
package com.baeldung;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
+import com.baeldung.boot.Application;
+import com.baeldung.boot.domain.GenericEntity;
+import com.baeldung.boot.repository.GenericEntityRepository;
+import com.baeldung.config.H2TestProfileJPAConfig;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -10,13 +11,11 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
-import com.baeldung.boot.Application;
-import com.baeldung.boot.config.H2JpaConfig;
-import com.baeldung.boot.domain.GenericEntity;
-import com.baeldung.boot.repository.GenericEntityRepository;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
@RunWith(SpringRunner.class)
-@SpringBootTest(classes = { Application.class, H2JpaConfig.class })
+@SpringBootTest(classes = { Application.class, H2TestProfileJPAConfig.class })
@ActiveProfiles("test")
public class SpringBootProfileIntegrationTest {
@Autowired
diff --git a/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/config/H2TestProfileJPAConfig.java b/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/config/H2TestProfileJPAConfig.java
index e0678bcf47..f73000a10e 100644
--- a/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/config/H2TestProfileJPAConfig.java
+++ b/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/config/H2TestProfileJPAConfig.java
@@ -1,10 +1,5 @@
package com.baeldung.config;
-import java.util.Properties;
-
-import javax.persistence.EntityManagerFactory;
-import javax.sql.DataSource;
-
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -17,9 +12,16 @@ import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.annotation.EnableTransactionManagement;
+import javax.persistence.EntityManagerFactory;
+import javax.sql.DataSource;
+import java.util.Properties;
+
@Configuration
@EnableJpaRepositories(basePackages = { "com.baeldung.repository", "com.baeldung.boot.repository" })
@EnableTransactionManagement
+@Profile("test") //only required to allow H2JpaConfig and H2TestProfileJPAConfig to coexist in same project
+ //this demo project is showcasing several ways to achieve the same end, and class-level
+ //Profile annotations are only necessary because the different techniques are sharing a project
public class H2TestProfileJPAConfig {
@Autowired
diff --git a/persistence-modules/spring-data-cassandra-reactive/pom.xml b/persistence-modules/spring-data-cassandra-reactive/pom.xml
index d2bc574ee9..bc8f49862d 100644
--- a/persistence-modules/spring-data-cassandra-reactive/pom.xml
+++ b/persistence-modules/spring-data-cassandra-reactive/pom.xml
@@ -21,7 +21,7 @@
org.springframework.data
spring-data-cassandra
- 2.1.2.RELEASE
+ ${spring-data-cassandra.version}
io.projectreactor
@@ -53,6 +53,7 @@
UTF-8
1.8
+ 2.1.2.RELEASE
diff --git a/persistence-modules/spring-data-couchbase-2/README.md b/persistence-modules/spring-data-couchbase-2/README.md
index 2b6a1faddf..3145fc653a 100644
--- a/persistence-modules/spring-data-couchbase-2/README.md
+++ b/persistence-modules/spring-data-couchbase-2/README.md
@@ -2,7 +2,7 @@
### Relevant Articles:
- [Intro to Spring Data Couchbase](http://www.baeldung.com/spring-data-couchbase)
-- [Entity Validation, Query Consistency, and Optimistic Locking in Spring Data Couchbase](http://www.baeldung.com/entity-validation-locking-and-query-consistency-in-spring-data-couchbase)
+- [Entity Validation, Optimistic Locking, and Query Consistency in Spring Data Couchbase](http://www.baeldung.com/entity-validation-locking-and-query-consistency-in-spring-data-couchbase)
- [Multiple Buckets and Spatial View Queries in Spring Data Couchbase](http://www.baeldung.com/spring-data-couchbase-buckets-and-spatial-view-queries)
### Overview
diff --git a/persistence-modules/spring-data-jpa-2/README.md b/persistence-modules/spring-data-jpa-2/README.md
index 295a434d17..41381ab82a 100644
--- a/persistence-modules/spring-data-jpa-2/README.md
+++ b/persistence-modules/spring-data-jpa-2/README.md
@@ -3,3 +3,4 @@
## Spring Data JPA Example Project
### Relevant Articles:
+- [Spring Data JPA – Derived Delete Methods](https://www.baeldung.com/spring-data-jpa-deleteby)
diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/datajpadelete/entity/Book.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/datajpadelete/entity/Book.java
new file mode 100644
index 0000000000..deac24548a
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/datajpadelete/entity/Book.java
@@ -0,0 +1,51 @@
+package com.baeldung.datajpadelete.entity;
+
+import javax.persistence.*;
+
+@Entity
+public class Book {
+
+ @Id
+ @GeneratedValue
+ private Long id;
+ private String title;
+
+ @ManyToOne
+ private Category category;
+
+ public Book() {
+ }
+
+ public Book(String title) {
+ this.title = title;
+ }
+
+ public Book(String title, Category category) {
+ this.title = title;
+ this.category = category;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public Category getCategory() {
+ return category;
+ }
+
+ public void setCategory(Category category) {
+ this.category = category;
+ }
+}
\ No newline at end of file
diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/datajpadelete/entity/Category.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/datajpadelete/entity/Category.java
new file mode 100644
index 0000000000..16f1a4157f
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/datajpadelete/entity/Category.java
@@ -0,0 +1,60 @@
+package com.baeldung.datajpadelete.entity;
+
+import javax.persistence.*;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+@Entity
+public class Category {
+
+ @Id
+ @GeneratedValue
+ private Long id;
+ private String name;
+
+ @OneToMany(mappedBy = "category", cascade = CascadeType.ALL, orphanRemoval = true)
+ private List books;
+
+ public Category() {
+ }
+
+ public Category(String name) {
+ this.name = name;
+ }
+
+ public Category(String name, Book... books) {
+ this.name = name;
+ this.books = Stream.of(books).collect(Collectors.toList());
+ this.books.forEach(x -> x.setCategory(this));
+ }
+
+ public Category(String name, List books) {
+ this.name = name;
+ this.books = books;
+ }
+
+ 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 List getBooks() {
+ return books;
+ }
+
+ public void setBooks(List books) {
+ this.books = books;
+ }
+}
diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/datajpadelete/repository/BookRepository.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/datajpadelete/repository/BookRepository.java
new file mode 100644
index 0000000000..5d0f45f127
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/datajpadelete/repository/BookRepository.java
@@ -0,0 +1,19 @@
+package com.baeldung.datajpadelete.repository;
+
+import com.baeldung.datajpadelete.entity.Book;
+import org.springframework.data.jpa.repository.Modifying;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.CrudRepository;
+import org.springframework.data.repository.query.Param;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface BookRepository extends CrudRepository {
+
+ long deleteByTitle(String title);
+
+ @Modifying
+ @Query("delete from Book b where b.title=:title")
+ void deleteBooks(@Param("title") String title);
+
+}
\ No newline at end of file
diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/datajpadelete/repository/CategoryRepository.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/datajpadelete/repository/CategoryRepository.java
new file mode 100644
index 0000000000..6fe7058a78
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/datajpadelete/repository/CategoryRepository.java
@@ -0,0 +1,9 @@
+package com.baeldung.datajpadelete.repository;
+
+import com.baeldung.datajpadelete.entity.Category;
+import org.springframework.data.repository.CrudRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface CategoryRepository extends CrudRepository {
+}
diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/embeddable/model/Company.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/embeddable/model/Company.java
new file mode 100644
index 0000000000..203cff1e35
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/embeddable/model/Company.java
@@ -0,0 +1,71 @@
+package com.baeldung.embeddable.model;
+
+import javax.persistence.AttributeOverride;
+import javax.persistence.AttributeOverrides;
+import javax.persistence.Column;
+import javax.persistence.Embedded;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+@Entity
+public class Company {
+
+ @Id
+ @GeneratedValue
+ private Integer id;
+
+ private String name;
+
+ private String address;
+
+ private String phone;
+
+ @Embedded
+ @AttributeOverrides(value = {
+ @AttributeOverride( name = "firstName", column = @Column(name = "contact_first_name")),
+ @AttributeOverride( name = "lastName", column = @Column(name = "contact_last_name")),
+ @AttributeOverride( name = "phone", column = @Column(name = "contact_phone"))
+ })
+ private ContactPerson contactPerson;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getAddress() {
+ return address;
+ }
+
+ public void setAddress(String address) {
+ this.address = address;
+ }
+
+ public String getPhone() {
+ return phone;
+ }
+
+ public void setPhone(String phone) {
+ this.phone = phone;
+ }
+
+ public ContactPerson getContactPerson() {
+ return contactPerson;
+ }
+
+ public void setContactPerson(ContactPerson contactPerson) {
+ this.contactPerson = contactPerson;
+ }
+}
diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/embeddable/model/ContactPerson.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/embeddable/model/ContactPerson.java
new file mode 100644
index 0000000000..561da80878
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/embeddable/model/ContactPerson.java
@@ -0,0 +1,38 @@
+package com.baeldung.embeddable.model;
+
+import javax.persistence.Embeddable;
+
+@Embeddable
+public class ContactPerson {
+
+ private String firstName;
+
+ private String lastName;
+
+ private String phone;
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+ public String getPhone() {
+ return phone;
+ }
+
+ public void setPhone(String phone) {
+ this.phone = phone;
+ }
+
+}
diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/embeddable/repositories/CompanyRepository.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/embeddable/repositories/CompanyRepository.java
new file mode 100644
index 0000000000..f456b15652
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/embeddable/repositories/CompanyRepository.java
@@ -0,0 +1,18 @@
+package com.baeldung.embeddable.repositories;
+
+import com.baeldung.embeddable.model.Company;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+
+import java.util.List;
+
+public interface CompanyRepository extends JpaRepository {
+
+ List findByContactPersonFirstName(String firstName);
+
+ @Query("SELECT C FROM Company C WHERE C.contactPerson.firstName = ?1")
+ List findByContactPersonFirstNameWithJPQL(String firstName);
+
+ @Query(value = "SELECT * FROM company WHERE contact_first_name = ?1", nativeQuery = true)
+ List findByContactPersonFirstNameWithNativeQuery(String firstName);
+}
diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entity/Customer.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entity/Customer.java
new file mode 100644
index 0000000000..efcae73853
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entity/Customer.java
@@ -0,0 +1,37 @@
+package com.baeldung.entity;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+@Entity
+public class Customer {
+
+ @Id
+ @GeneratedValue
+ private long id;
+ private String name;
+ private String email;
+
+ public Customer(String name, String email) {
+ this.name = name;
+ this.email = email;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+}
diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entity/Passenger.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entity/Passenger.java
new file mode 100644
index 0000000000..3aafbe9afa
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entity/Passenger.java
@@ -0,0 +1,78 @@
+package com.baeldung.entity;
+
+import javax.persistence.Basic;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import java.util.Objects;
+
+@Entity
+public class Passenger {
+
+ @Id
+ @GeneratedValue
+ @Column(nullable = false)
+ private Long id;
+
+ @Basic(optional = false)
+ @Column(nullable = false)
+ private String firstName;
+
+ @Basic(optional = false)
+ @Column(nullable = false)
+ private String lastName;
+
+ private Passenger(String firstName, String lastName) {
+ this.firstName = firstName;
+ this.lastName = lastName;
+ }
+
+ public static Passenger from(String firstName, String lastName) {
+ return new Passenger(firstName, lastName);
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+ @Override
+ public String toString() {
+ return "Passenger{" + "id=" + id + ", firstName='" + firstName + '\'' + ", lastName='" + lastName + '\'' + '}';
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (o == null || getClass() != o.getClass())
+ return false;
+ Passenger passenger = (Passenger) o;
+ return Objects.equals(firstName, passenger.firstName) && Objects.equals(lastName, passenger.lastName);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(firstName, lastName);
+ }
+}
diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/exists/Car.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/exists/Car.java
new file mode 100644
index 0000000000..bf09caf6ff
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/exists/Car.java
@@ -0,0 +1,48 @@
+package com.baeldung.exists;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+/**
+ * @author paullatzelsperger
+ * @since 2019-03-20
+ */
+@Entity
+public class Car {
+
+ @Id
+ @GeneratedValue
+ private int id;
+ private Integer power;
+ private String model;
+
+ Car() {
+
+ }
+
+ public Car(int power, String model) {
+ this.power = power;
+ this.model = model;
+ }
+
+ public Integer getPower() {
+ return power;
+ }
+
+ public void setPower(Integer power) {
+ this.power = power;
+ }
+
+ public String getModel() {
+ return model;
+ }
+
+ public void setModel(String model) {
+ this.model = model;
+ }
+
+ public int getId() {
+ return id;
+ }
+}
diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/exists/CarRepository.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/exists/CarRepository.java
new file mode 100644
index 0000000000..a54f19f4cd
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/exists/CarRepository.java
@@ -0,0 +1,24 @@
+package com.baeldung.exists;
+
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
+import org.springframework.stereotype.Repository;
+
+/**
+ * @author paullatzelsperger
+ * @since 2019-03-20
+ */
+@Repository
+public interface CarRepository extends JpaRepository {
+
+ boolean existsCarByPower(int power);
+
+ boolean existsCarByModel(String model);
+
+ @Query("select case when count(c)> 0 then true else false end from Car c where c.model = :model")
+ boolean existsCarExactCustomQuery(@Param("model") String model);
+
+ @Query("select case when count(c)> 0 then true else false end from Car c where lower(c.model) like lower(:model)")
+ boolean existsCarLikeCustomQuery(@Param("model") String model);
+}
diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/joins/model/Department.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/joins/model/Department.java
new file mode 100644
index 0000000000..439f7532f5
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/joins/model/Department.java
@@ -0,0 +1,45 @@
+package com.baeldung.joins.model;
+
+import java.util.List;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+
+@Entity
+public class Department {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ private long id;
+
+ private String name;
+
+ @OneToMany(mappedBy = "department")
+ private List employees;
+
+ 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 List getEmployees() {
+ return employees;
+ }
+
+ public void setEmployees(List employees) {
+ this.employees = employees;
+ }
+}
diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/joins/model/Employee.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/joins/model/Employee.java
new file mode 100644
index 0000000000..277274e61c
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/joins/model/Employee.java
@@ -0,0 +1,69 @@
+package com.baeldung.joins.model;
+
+import java.util.List;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+
+@Entity
+@Table(name = "joins_employee")
+public class Employee {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private long id;
+
+ private String name;
+
+ private int age;
+
+ @ManyToOne
+ private Department department;
+
+ @OneToMany(mappedBy = "employee")
+ private List phones;
+
+ 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 int getAge() {
+ return age;
+ }
+
+ public void setAge(int age) {
+ this.age = age;
+ }
+
+ public Department getDepartment() {
+ return department;
+ }
+
+ public void setDepartment(Department department) {
+ this.department = department;
+ }
+
+ public List getPhones() {
+ return phones;
+ }
+
+ public void setPhones(List phones) {
+ this.phones = phones;
+ }
+}
diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/joins/model/Phone.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/joins/model/Phone.java
new file mode 100644
index 0000000000..41382915b1
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/joins/model/Phone.java
@@ -0,0 +1,44 @@
+package com.baeldung.joins.model;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+
+@Entity
+public class Phone {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private long id;
+
+ private String number;
+
+ @ManyToOne
+ private Employee employee;
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getNumber() {
+ return number;
+ }
+
+ public void setNumber(String number) {
+ this.number = number;
+ }
+
+ public Employee getEmployee() {
+ return employee;
+ }
+
+ public void setEmployee(Employee employee) {
+ this.employee = employee;
+ }
+}
diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/model/Address.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/model/Address.java
new file mode 100644
index 0000000000..0c5a3eac60
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/model/Address.java
@@ -0,0 +1,57 @@
+package com.baeldung.projection.model;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.OneToOne;
+
+@Entity
+public class Address {
+ @Id
+ private Long id;
+ @OneToOne
+ private Person person;
+ private String state;
+ private String city;
+ private String street;
+ private String zipCode;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getState() {
+ return state;
+ }
+
+ public void setState(String state) {
+ this.state = state;
+ }
+
+ public String getCity() {
+ return city;
+ }
+
+ public void setCity(String city) {
+ this.city = city;
+ }
+
+ public String getStreet() {
+ return street;
+ }
+
+ public void setStreet(String street) {
+ this.street = street;
+ }
+
+ public String getZipCode() {
+ return zipCode;
+ }
+
+ public void setZipCode(String zipCode) {
+ this.zipCode = zipCode;
+ }
+}
diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/model/Person.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/model/Person.java
new file mode 100644
index 0000000000..d18bd1c72d
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/model/Person.java
@@ -0,0 +1,47 @@
+package com.baeldung.projection.model;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.OneToOne;
+
+@Entity
+public class Person {
+ @Id
+ private Long id;
+ private String firstName;
+ private String lastName;
+ @OneToOne(mappedBy = "person")
+ private Address address;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+ public Address getAddress() {
+ return address;
+ }
+
+ public void setAddress(Address address) {
+ this.address = address;
+ }
+}
diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/repository/AddressRepository.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/repository/AddressRepository.java
new file mode 100644
index 0000000000..c1053f4867
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/repository/AddressRepository.java
@@ -0,0 +1,11 @@
+package com.baeldung.projection.repository;
+
+import com.baeldung.projection.view.AddressView;
+import com.baeldung.projection.model.Address;
+import org.springframework.data.repository.Repository;
+
+import java.util.List;
+
+public interface AddressRepository extends Repository {
+ List getAddressByState(String state);
+}
diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/repository/PersonRepository.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/repository/PersonRepository.java
new file mode 100644
index 0000000000..64bc7471e6
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/repository/PersonRepository.java
@@ -0,0 +1,14 @@
+package com.baeldung.projection.repository;
+
+import com.baeldung.projection.model.Person;
+import com.baeldung.projection.view.PersonDto;
+import com.baeldung.projection.view.PersonView;
+import org.springframework.data.repository.Repository;
+
+public interface PersonRepository extends Repository {
+ PersonView findByLastName(String lastName);
+
+ PersonDto findByFirstName(String firstName);
+
+ T findByLastName(String lastName, Class type);
+}
diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/view/AddressView.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/view/AddressView.java
new file mode 100644
index 0000000000..7a24a1e9b9
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/view/AddressView.java
@@ -0,0 +1,7 @@
+package com.baeldung.projection.view;
+
+public interface AddressView {
+ String getZipCode();
+
+ PersonView getPerson();
+}
diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/view/PersonDto.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/view/PersonDto.java
new file mode 100644
index 0000000000..1fd924450b
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/view/PersonDto.java
@@ -0,0 +1,34 @@
+package com.baeldung.projection.view;
+
+import java.util.Objects;
+
+public class PersonDto {
+ private final String firstName;
+ private final String lastName;
+
+ public PersonDto(String firstName, String lastName) {
+ this.firstName = firstName;
+ this.lastName = lastName;
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ PersonDto personDto = (PersonDto) o;
+ return Objects.equals(firstName, personDto.firstName) && Objects.equals(lastName, personDto.lastName);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(firstName, lastName);
+ }
+}
diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/view/PersonView.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/view/PersonView.java
new file mode 100644
index 0000000000..36777ec26f
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/view/PersonView.java
@@ -0,0 +1,12 @@
+package com.baeldung.projection.view;
+
+import org.springframework.beans.factory.annotation.Value;
+
+public interface PersonView {
+ String getFirstName();
+
+ String getLastName();
+
+ @Value("#{target.firstName + ' ' + target.lastName}")
+ String getFullName();
+}
diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/repository/CustomerRepository.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/repository/CustomerRepository.java
new file mode 100644
index 0000000000..65b22bbd84
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/repository/CustomerRepository.java
@@ -0,0 +1,19 @@
+package com.baeldung.repository;
+
+import com.baeldung.entity.Customer;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
+
+import java.util.List;
+
+public interface CustomerRepository extends JpaRepository {
+
+ List findByName(String name);
+
+ List findByNameAndEmail(String name, String email);
+
+ @Query("SELECT c FROM Customer c WHERE (:name is null or c.name = :name) and (:email is null or c.email = :email)")
+ List findCustomerByNameAndEmail(@Param("name") String name, @Param("email") String email);
+
+}
diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/repository/PassengerRepository.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/repository/PassengerRepository.java
new file mode 100644
index 0000000000..a295a74f1b
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/repository/PassengerRepository.java
@@ -0,0 +1,14 @@
+package com.baeldung.repository;
+
+import com.baeldung.entity.Passenger;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+@Repository
+interface PassengerRepository extends JpaRepository {
+
+ List findByFirstNameIgnoreCase(String firstName);
+
+}
diff --git a/persistence-modules/spring-data-jpa-2/src/main/resources/application-joins.properties b/persistence-modules/spring-data-jpa-2/src/main/resources/application-joins.properties
new file mode 100644
index 0000000000..fe2270293b
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/main/resources/application-joins.properties
@@ -0,0 +1 @@
+spring.datasource.data=classpath:db/import_joins.sql
diff --git a/persistence-modules/spring-data-jpa-2/src/main/resources/db/import_joins.sql b/persistence-modules/spring-data-jpa-2/src/main/resources/db/import_joins.sql
new file mode 100644
index 0000000000..e4772d6ff2
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/main/resources/db/import_joins.sql
@@ -0,0 +1,13 @@
+INSERT INTO department (id, name) VALUES (1, 'Infra');
+INSERT INTO department (id, name) VALUES (2, 'Accounting');
+INSERT INTO department (id, name) VALUES (3, 'Management');
+
+INSERT INTO joins_employee (id, name, age, department_id) VALUES (1, 'Baeldung', '35', 1);
+INSERT INTO joins_employee (id, name, age, department_id) VALUES (2, 'John', '35', 2);
+INSERT INTO joins_employee (id, name, age, department_id) VALUES (3, 'Jane', '35', 2);
+
+INSERT INTO phone (id, number, employee_id) VALUES (1, '111', 1);
+INSERT INTO phone (id, number, employee_id) VALUES (2, '222', 1);
+INSERT INTO phone (id, number, employee_id) VALUES (3, '333', 1);
+
+COMMIT;
diff --git a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/datajpadelete/DeleteFromRepositoryUnitTest.java b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/datajpadelete/DeleteFromRepositoryUnitTest.java
new file mode 100644
index 0000000000..9e7e516735
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/datajpadelete/DeleteFromRepositoryUnitTest.java
@@ -0,0 +1,72 @@
+package com.baeldung.datajpadelete;
+
+import com.baeldung.Application;
+import com.baeldung.datajpadelete.entity.Book;
+import com.baeldung.datajpadelete.repository.BookRepository;
+import org.junit.After;
+import org.junit.Before;
+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 org.springframework.transaction.annotation.Transactional;
+
+import java.util.Arrays;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = {Application.class})
+public class DeleteFromRepositoryUnitTest {
+
+ @Autowired
+ private BookRepository repository;
+
+ Book book1;
+ Book book2;
+
+ @Before
+ public void setup() {
+ book1 = new Book("The Hobbit");
+ book2 = new Book("All Quiet on the Western Front");
+
+ repository.saveAll(Arrays.asList(book1, book2));
+ }
+
+ @After
+ public void teardown() {
+ repository.deleteAll();
+ }
+
+ @Test
+ public void whenDeleteByIdFromRepository_thenDeletingShouldBeSuccessful() {
+ repository.deleteById(book1.getId());
+
+ assertThat(repository.count() == 1).isTrue();
+ }
+
+ @Test
+ public void whenDeleteAllFromRepository_thenRepositoryShouldBeEmpty() {
+ repository.deleteAll();
+
+ assertThat(repository.count() == 0).isTrue();
+ }
+
+ @Test
+ @Transactional
+ public void whenDeleteFromDerivedQuery_thenDeletingShouldBeSuccessful() {
+ repository.deleteByTitle("The Hobbit");
+
+ assertThat(repository.count() == 1).isTrue();
+ }
+
+ @Test
+ @Transactional
+ public void whenDeleteFromCustomQuery_thenDeletingShouldBeSuccessful() {
+ repository.deleteBooks("The Hobbit");
+
+ assertThat(repository.count() == 1).isTrue();
+ }
+
+}
\ No newline at end of file
diff --git a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/datajpadelete/DeleteInRelationshipsUnitTest.java b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/datajpadelete/DeleteInRelationshipsUnitTest.java
new file mode 100644
index 0000000000..56de8749b2
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/datajpadelete/DeleteInRelationshipsUnitTest.java
@@ -0,0 +1,60 @@
+package com.baeldung.datajpadelete;
+
+import com.baeldung.Application;
+import com.baeldung.datajpadelete.entity.Book;
+import com.baeldung.datajpadelete.entity.Category;
+import com.baeldung.datajpadelete.repository.BookRepository;
+import com.baeldung.datajpadelete.repository.CategoryRepository;
+import org.junit.After;
+import org.junit.Before;
+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.assertj.core.api.Assertions.assertThat;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = {Application.class})
+public class DeleteInRelationshipsUnitTest {
+
+ @Autowired
+ private BookRepository bookRepository;
+
+ @Autowired
+ private CategoryRepository categoryRepository;
+
+ @Before
+ public void setup() {
+ Book book1 = new Book("The Hobbit");
+ Category category1 = new Category("Cat1", book1);
+ categoryRepository.save(category1);
+
+ Book book2 = new Book("All Quiet on the Western Front");
+ Category category2 = new Category("Cat2", book2);
+ categoryRepository.save(category2);
+ }
+
+ @After
+ public void teardown() {
+ bookRepository.deleteAll();
+ categoryRepository.deleteAll();
+ }
+
+ @Test
+ public void whenDeletingCategories_thenBooksShouldAlsoBeDeleted() {
+ categoryRepository.deleteAll();
+
+ assertThat(bookRepository.count() == 0).isTrue();
+ assertThat(categoryRepository.count() == 0).isTrue();
+ }
+
+ @Test
+ public void whenDeletingBooks_thenCategoriesShouldAlsoBeDeleted() {
+ bookRepository.deleteAll();
+
+ assertThat(bookRepository.count() == 0).isTrue();
+ assertThat(categoryRepository.count() == 2).isTrue();
+ }
+}
\ No newline at end of file
diff --git a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/embeddable/EmbeddableIntegrationTest.java b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/embeddable/EmbeddableIntegrationTest.java
new file mode 100644
index 0000000000..b4c365a2d9
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/embeddable/EmbeddableIntegrationTest.java
@@ -0,0 +1,125 @@
+package com.baeldung.embeddable;
+
+import com.baeldung.Application;
+import com.baeldung.embeddable.model.Company;
+import com.baeldung.embeddable.model.ContactPerson;
+import com.baeldung.embeddable.repositories.CompanyRepository;
+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 org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = {Application.class})
+public class EmbeddableIntegrationTest {
+
+ @Autowired
+ private CompanyRepository companyRepository;
+
+ @Test
+ @Transactional
+ public void whenInsertingCompany_thenEmbeddedContactPersonDetailsAreMapped() {
+ ContactPerson contactPerson = new ContactPerson();
+ contactPerson.setFirstName("First");
+ contactPerson.setLastName("Last");
+ contactPerson.setPhone("123-456-789");
+
+ Company company = new Company();
+ company.setName("Company");
+ company.setAddress("1st street");
+ company.setPhone("987-654-321");
+ company.setContactPerson(contactPerson);
+
+ companyRepository.save(company);
+
+ Company result = companyRepository.getOne(company.getId());
+
+ assertEquals("Company", result.getName());
+ assertEquals("1st street", result.getAddress());
+ assertEquals("987-654-321", result.getPhone());
+ assertEquals("First", result.getContactPerson().getFirstName());
+ assertEquals("Last", result.getContactPerson().getLastName());
+ assertEquals("123-456-789", result.getContactPerson().getPhone());
+ }
+
+ @Test
+ @Transactional
+ public void whenFindingCompanyByContactPersonAttribute_thenCompanyIsReturnedProperly() {
+ ContactPerson contactPerson = new ContactPerson();
+ contactPerson.setFirstName("Name");
+ contactPerson.setLastName("Last");
+ contactPerson.setPhone("123-456-789");
+
+ Company company = new Company();
+ company.setName("Company");
+ company.setAddress("1st street");
+ company.setPhone("987-654-321");
+ company.setContactPerson(contactPerson);
+
+ companyRepository.save(company);
+
+ List result = companyRepository.findByContactPersonFirstName("Name");
+
+ assertEquals(1, result.size());
+
+ result = companyRepository.findByContactPersonFirstName("FirstName");
+
+ assertEquals(0, result.size());
+ }
+
+ @Test
+ @Transactional
+ public void whenFindingCompanyByContactPersonAttributeWithJPQL_thenCompanyIsReturnedProperly() {
+ ContactPerson contactPerson = new ContactPerson();
+ contactPerson.setFirstName("@QueryName");
+ contactPerson.setLastName("Last");
+ contactPerson.setPhone("123-456-789");
+
+ Company company = new Company();
+ company.setName("Company");
+ company.setAddress("1st street");
+ company.setPhone("987-654-321");
+ company.setContactPerson(contactPerson);
+
+ companyRepository.save(company);
+
+ List result = companyRepository.findByContactPersonFirstNameWithJPQL("@QueryName");
+
+ assertEquals(1, result.size());
+
+ result = companyRepository.findByContactPersonFirstNameWithJPQL("FirstName");
+
+ assertEquals(0, result.size());
+ }
+
+ @Test
+ @Transactional
+ public void whenFindingCompanyByContactPersonAttributeWithNativeQuery_thenCompanyIsReturnedProperly() {
+ ContactPerson contactPerson = new ContactPerson();
+ contactPerson.setFirstName("NativeQueryName");
+ contactPerson.setLastName("Last");
+ contactPerson.setPhone("123-456-789");
+
+ Company company = new Company();
+ company.setName("Company");
+ company.setAddress("1st street");
+ company.setPhone("987-654-321");
+ company.setContactPerson(contactPerson);
+
+ companyRepository.save(company);
+
+ List result = companyRepository.findByContactPersonFirstNameWithNativeQuery("NativeQueryName");
+
+ assertEquals(1, result.size());
+
+ result = companyRepository.findByContactPersonFirstNameWithNativeQuery("FirstName");
+
+ assertEquals(0, result.size());
+ }
+}
diff --git a/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/exists/CarRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/exists/CarRepositoryIntegrationTest.java
similarity index 95%
rename from persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/exists/CarRepositoryIntegrationTest.java
rename to persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/exists/CarRepositoryIntegrationTest.java
index f9a48a7e66..d99f6671a3 100644
--- a/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/exists/CarRepositoryIntegrationTest.java
+++ b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/exists/CarRepositoryIntegrationTest.java
@@ -1,8 +1,6 @@
package com.baeldung.exists;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.ignoreCase;
-
+import com.baeldung.Application;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -13,13 +11,12 @@ import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.test.context.junit4.SpringRunner;
-import com.baeldung.boot.Application;
-import com.baeldung.boot.domain.Car;
-import com.baeldung.boot.repository.CarRepository;
-
import java.util.Arrays;
import java.util.List;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.ignoreCase;
+
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {Application.class})
public class CarRepositoryIntegrationTest {
diff --git a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/joins/JpaJoinsIntegrationTest.java b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/joins/JpaJoinsIntegrationTest.java
new file mode 100644
index 0000000000..9b0d23f3e4
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/joins/JpaJoinsIntegrationTest.java
@@ -0,0 +1,142 @@
+package com.baeldung.joins;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import com.baeldung.joins.model.Department;
+import com.baeldung.joins.model.Phone;
+import java.util.Collection;
+import java.util.List;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.TypedQuery;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@DataJpaTest
+@ActiveProfiles("joins")
+public class JpaJoinsIntegrationTest {
+
+ @PersistenceContext
+ private EntityManager entityManager;
+
+ @Test
+ public void whenPathExpressionIsUsedForSingleValuedAssociation_thenCreatesImplicitInnerJoin() {
+ TypedQuery query = entityManager.createQuery("SELECT e.department FROM Employee e", Department.class);
+
+ List resultList = query.getResultList();
+
+ assertThat(resultList).hasSize(3);
+ assertThat(resultList).extracting("name")
+ .containsOnly("Infra", "Accounting", "Accounting");
+ }
+
+ @Test
+ public void whenJoinKeywordIsUsed_thenCreatesExplicitInnerJoin() {
+ TypedQuery query = entityManager.createQuery("SELECT d FROM Employee e JOIN e.department d", Department.class);
+
+ List resultList = query.getResultList();
+
+ assertThat(resultList).hasSize(3);
+ assertThat(resultList).extracting("name")
+ .containsOnly("Infra", "Accounting", "Accounting");
+ }
+
+ @Test
+ public void whenInnerJoinKeywordIsUsed_thenCreatesExplicitInnerJoin() {
+ TypedQuery query = entityManager.createQuery("SELECT d FROM Employee e INNER JOIN e.department d", Department.class);
+
+ List resultList = query.getResultList();
+
+ assertThat(resultList).hasSize(3);
+ assertThat(resultList).extracting("name")
+ .containsOnly("Infra", "Accounting", "Accounting");
+ }
+
+ @Test
+ public void whenEntitiesAreListedInFromAndMatchedInWhere_ThenCreatesJoin() {
+ TypedQuery query = entityManager.createQuery("SELECT d FROM Employee e, Department d WHERE e.department = d", Department.class);
+
+ List resultList = query.getResultList();
+
+ assertThat(resultList).hasSize(3);
+ assertThat(resultList).extracting("name")
+ .containsOnly("Infra", "Accounting", "Accounting");
+ }
+
+ @Test
+ public void whenEntitiesAreListedInFrom_ThenCreatesCartesianProduct() {
+ TypedQuery query = entityManager.createQuery("SELECT d FROM Employee e, Department d", Department.class);
+
+ List resultList = query.getResultList();
+
+ assertThat(resultList).hasSize(9);
+ assertThat(resultList).extracting("name")
+ .containsOnly("Infra", "Accounting", "Management", "Infra", "Accounting", "Management", "Infra", "Accounting", "Management");
+ }
+
+ @Test
+ public void whenCollectionValuedAssociationIsJoined_ThenCanSelect() {
+ TypedQuery query = entityManager.createQuery("SELECT ph FROM Employee e JOIN e.phones ph WHERE ph LIKE '1%'", Phone.class);
+
+ List resultList = query.getResultList();
+
+ assertThat(resultList).hasSize(1);
+ }
+
+ @Test
+ public void whenMultipleEntitiesAreListedWithJoin_ThenCreatesMultipleJoins() {
+ TypedQuery query = entityManager.createQuery("SELECT ph FROM Employee e JOIN e.department d JOIN e.phones ph WHERE d.name IS NOT NULL", Phone.class);
+
+ List resultList = query.getResultList();
+
+ assertThat(resultList).hasSize(3);
+ assertThat(resultList).extracting("number")
+ .containsOnly("111", "222", "333");
+ }
+
+ @Test
+ public void whenLeftKeywordIsSpecified_thenCreatesOuterJoinAndIncludesNonMatched() {
+ TypedQuery query = entityManager.createQuery("SELECT DISTINCT d FROM Department d LEFT JOIN d.employees e", Department.class);
+
+ List resultList = query.getResultList();
+
+ assertThat(resultList).hasSize(3);
+ assertThat(resultList).extracting("name")
+ .containsOnly("Infra", "Accounting", "Management");
+ }
+
+ @Test
+ public void whenFetchKeywordIsSpecified_ThenCreatesFetchJoin() {
+ TypedQuery query = entityManager.createQuery("SELECT d FROM Department d JOIN FETCH d.employees", Department.class);
+
+ List resultList = query.getResultList();
+
+ assertThat(resultList).hasSize(3);
+ assertThat(resultList).extracting("name")
+ .containsOnly("Infra", "Accounting", "Accounting");
+ }
+
+ @Test
+ public void whenLeftAndFetchKeywordsAreSpecified_ThenCreatesOuterFetchJoin() {
+ TypedQuery query = entityManager.createQuery("SELECT d FROM Department d LEFT JOIN FETCH d.employees", Department.class);
+
+ List resultList = query.getResultList();
+
+ assertThat(resultList).hasSize(4);
+ assertThat(resultList).extracting("name")
+ .containsOnly("Infra", "Accounting", "Accounting", "Management");
+ }
+
+ @Test
+ public void whenCollectionValuedAssociationIsSpecifiedInSelect_ThenReturnsCollections() {
+ TypedQuery query = entityManager.createQuery("SELECT e.phones FROM Employee e", Collection.class);
+
+ List resultList = query.getResultList();
+
+ assertThat(resultList).extracting("number").containsOnly("111", "222", "333");
+ }
+}
diff --git a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/projection/JpaProjectionIntegrationTest.java b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/projection/JpaProjectionIntegrationTest.java
new file mode 100644
index 0000000000..96eaf4ed07
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/projection/JpaProjectionIntegrationTest.java
@@ -0,0 +1,63 @@
+package com.baeldung.projection;
+
+import com.baeldung.projection.model.Person;
+import com.baeldung.projection.repository.AddressRepository;
+import com.baeldung.projection.repository.PersonRepository;
+import com.baeldung.projection.view.AddressView;
+import com.baeldung.projection.view.PersonDto;
+import com.baeldung.projection.view.PersonView;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
+import org.springframework.test.context.jdbc.Sql;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TEST_METHOD;
+
+@DataJpaTest
+@RunWith(SpringRunner.class)
+@Sql(scripts = "/projection-insert-data.sql")
+@Sql(scripts = "/projection-clean-up-data.sql", executionPhase = AFTER_TEST_METHOD)
+public class JpaProjectionIntegrationTest {
+ @Autowired
+ private AddressRepository addressRepository;
+
+ @Autowired
+ private PersonRepository personRepository;
+
+ @Test
+ public void whenUsingClosedProjections_thenViewWithRequiredPropertiesIsReturned() {
+ AddressView addressView = addressRepository.getAddressByState("CA").get(0);
+ assertThat(addressView.getZipCode()).isEqualTo("90001");
+
+ PersonView personView = addressView.getPerson();
+ assertThat(personView.getFirstName()).isEqualTo("John");
+ assertThat(personView.getLastName()).isEqualTo("Doe");
+ }
+
+ @Test
+ public void whenUsingOpenProjections_thenViewWithRequiredPropertiesIsReturned() {
+ PersonView personView = personRepository.findByLastName("Doe");
+ assertThat(personView.getFullName()).isEqualTo("John Doe");
+ }
+
+ @Test
+ public void whenUsingClassBasedProjections_thenDtoWithRequiredPropertiesIsReturned() {
+ PersonDto personDto = personRepository.findByFirstName("John");
+ assertThat(personDto.getFirstName()).isEqualTo("John");
+ assertThat(personDto.getLastName()).isEqualTo("Doe");
+ }
+
+ @Test
+ public void whenUsingDynamicProjections_thenObjectWithRequiredPropertiesIsReturned() {
+ Person person = personRepository.findByLastName("Doe", Person.class);
+ PersonView personView = personRepository.findByLastName("Doe", PersonView.class);
+ PersonDto personDto = personRepository.findByLastName("Doe", PersonDto.class);
+
+ assertThat(person.getFirstName()).isEqualTo("John");
+ assertThat(personView.getFirstName()).isEqualTo("John");
+ assertThat(personDto.getFirstName()).isEqualTo("John");
+ }
+}
diff --git a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/repository/CustomerRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/repository/CustomerRepositoryIntegrationTest.java
new file mode 100644
index 0000000000..5d6457ce30
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/repository/CustomerRepositoryIntegrationTest.java
@@ -0,0 +1,64 @@
+package com.baeldung.repository;
+
+import com.baeldung.entity.Customer;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+@DataJpaTest
+@RunWith(SpringRunner.class)
+public class CustomerRepositoryIntegrationTest {
+
+ @PersistenceContext
+ private EntityManager entityManager;
+
+ @Autowired
+ private CustomerRepository repository;
+
+ @Before
+ public void before() {
+ entityManager.persist(new Customer("A", "A@example.com"));
+ entityManager.persist(new Customer("D", null));
+ entityManager.persist(new Customer("D", "D@example.com"));
+ }
+
+ @Test
+ public void givenQueryMethod_whenEmailIsNull_thenFoundByNullEmail() {
+ List customers = repository.findByNameAndEmail("D", null);
+
+ assertEquals(1, customers.size());
+ Customer actual = customers.get(0);
+
+ assertEquals(null, actual.getEmail());
+ assertEquals("D", actual.getName());
+ }
+
+ @Test
+ public void givenQueryMethod_whenEmailIsAbsent_thenIgnoreEmail() {
+ List customers = repository.findByName("D");
+
+ assertEquals(2, customers.size());
+ }
+
+ @Test
+ public void givenQueryAnnotation_whenEmailIsNull_thenIgnoreEmail() {
+ List customers = repository.findCustomerByNameAndEmail("D", null);
+
+ assertEquals(2, customers.size());
+ }
+
+ @After
+ public void cleanUp() {
+ repository.deleteAll();
+ }
+}
\ No newline at end of file
diff --git a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/repository/PassengerRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/repository/PassengerRepositoryIntegrationTest.java
new file mode 100644
index 0000000000..f96f0249d7
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/repository/PassengerRepositoryIntegrationTest.java
@@ -0,0 +1,54 @@
+package com.baeldung.repository;
+
+import com.baeldung.entity.Passenger;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import java.util.List;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.core.IsNot.not;
+
+@DataJpaTest
+@RunWith(SpringRunner.class)
+public class PassengerRepositoryIntegrationTest {
+
+ @PersistenceContext
+ private EntityManager entityManager;
+ @Autowired
+ private PassengerRepository repository;
+
+ @Before
+ public void before() {
+ entityManager.persist(Passenger.from("Jill", "Smith"));
+ entityManager.persist(Passenger.from("Eve", "Jackson"));
+ entityManager.persist(Passenger.from("Fred", "Bloggs"));
+ entityManager.persist(Passenger.from("Ricki", "Bobbie"));
+ entityManager.persist(Passenger.from("Siya", "Kolisi"));
+ }
+
+ @Test
+ public void givenPassengers_whenMatchingIgnoreCase_thenExpectedReturned() {
+ Passenger jill = Passenger.from("Jill", "Smith");
+ Passenger eve = Passenger.from("Eve", "Jackson");
+ Passenger fred = Passenger.from("Fred", "Bloggs");
+ Passenger siya = Passenger.from("Siya", "Kolisi");
+ Passenger ricki = Passenger.from("Ricki", "Bobbie");
+
+ List passengers = repository.findByFirstNameIgnoreCase("FRED");
+
+ assertThat(passengers, contains(fred));
+ assertThat(passengers, not(contains(eve)));
+ assertThat(passengers, not(contains(siya)));
+ assertThat(passengers, not(contains(jill)));
+ assertThat(passengers, not(contains(ricki)));
+
+ }
+}
diff --git a/persistence-modules/spring-data-jpa-2/src/test/resources/projection-clean-up-data.sql b/persistence-modules/spring-data-jpa-2/src/test/resources/projection-clean-up-data.sql
new file mode 100644
index 0000000000..d34f6f0636
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/test/resources/projection-clean-up-data.sql
@@ -0,0 +1,2 @@
+DELETE FROM address;
+DELETE FROM person;
\ No newline at end of file
diff --git a/persistence-modules/spring-data-jpa-2/src/test/resources/projection-insert-data.sql b/persistence-modules/spring-data-jpa-2/src/test/resources/projection-insert-data.sql
new file mode 100644
index 0000000000..544dcc4b88
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/test/resources/projection-insert-data.sql
@@ -0,0 +1,2 @@
+INSERT INTO person(id,first_name,last_name) VALUES (1,'John','Doe');
+INSERT INTO address(id,person_id,state,city,street,zip_code) VALUES (1,1,'CA', 'Los Angeles', 'Standford Ave', '90001');
\ No newline at end of file
diff --git a/persistence-modules/spring-data-jpa/README.md b/persistence-modules/spring-data-jpa/README.md
index 48c3180262..4e390c2faf 100644
--- a/persistence-modules/spring-data-jpa/README.md
+++ b/persistence-modules/spring-data-jpa/README.md
@@ -5,7 +5,7 @@
### Relevant Articles:
- [Spring JPA – Multiple Databases](http://www.baeldung.com/spring-data-jpa-multiple-databases)
- [Spring Data JPA – Adding a Method in All Repositories](http://www.baeldung.com/spring-data-jpa-method-in-all-repositories)
-- [Advanced Tagging Implementation with JPA](http://www.baeldung.com/jpa-tagging-advanced)
+- [An Advanced Tagging Implementation with JPA](http://www.baeldung.com/jpa-tagging-advanced)
- [Spring Data JPA @Query](http://www.baeldung.com/spring-data-jpa-query)
- [Spring Data Annotations](http://www.baeldung.com/spring-data-annotations)
- [Spring Data Java 8 Support](http://www.baeldung.com/spring-data-java-8)
diff --git a/pom.xml b/pom.xml
index e785f1461f..3bfa182d72 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,11 +7,12 @@
com.baeldung
parent-modules
1.0.0-SNAPSHOT
+ parent-modules
+ pom
+
lombok-custom
- parent-modules
- pom
@@ -232,7 +233,7 @@
${maven-war-plugin.version}
-
+
com.vackosar.gitflowincrementalbuilder
@@ -332,7 +333,7 @@
parent-spring-5
parent-java
parent-kotlin
-
+
akka-streams
algorithms-genetic
algorithms-miscellaneous-1
@@ -376,13 +377,16 @@
checker-plugin
core-groovy
-
+
core-java-8
+ core-java-8-2
+ core-java-lambdas
core-java-arrays
core-java-collections
+ core-java-collections-map
core-java-collections-list
core-java-concurrency-basic
core-java-concurrency-collections
@@ -391,6 +395,7 @@
core-java-lang-syntax
core-java-lang
core-java-lang-oop
+ core-java-lang-oop-2
core-java-networking
core-java-perf
core-java-sun
@@ -399,7 +404,7 @@
core-scala
couchbase
custom-pmd
-
+
dagger
data-structures
ddd
@@ -407,13 +412,13 @@
disruptor
dozer
drools
- dubbo
-
+ dubbo
+
ethereum
-
+
feign
flyway-cdi-extension
-
+
geotools
google-cloud
google-web-toolkit
@@ -427,19 +432,21 @@
guava-modules
guice
-
+
hazelcast
helidon
httpclient
hystrix
-
+
image-processing
immutables
jackson
jackson-2
+ jackson-simple
java-collections-conversions
java-collections-maps
+ java-collections-maps-2
@@ -448,6 +455,7 @@
java-rmi
java-spi
java-streams
+ java-streams-2
java-strings
java-vavr-stream
java-websocket
@@ -477,10 +485,10 @@
kotlin-libraries
-
+
libraries
- libraries2
+ libraries-2
libraries-data
libraries-apache-commons
libraries-security
@@ -504,8 +512,8 @@
mustache
mybatis
-
-
+
+
optaplanner
orika
osgi
@@ -515,9 +523,9 @@
performance-tests
protobuffer
-
+
persistence-modules
-
+
rabbitmq
ratpack
@@ -529,15 +537,17 @@
rule-engines
rsocket
rxjava
- rxjava-2
+ rxjava-2
software-security/sql-injection-samples
-
+
tensorflow-java
-
+ spring-boot-flowable
+ spring-security-kerberos
+
-
+
default-second
@@ -571,14 +581,15 @@
parent-spring-5
parent-java
parent-kotlin
-
+
saas
spark-java
-
+
spring-4
-
+
spring-5
spring-5-webflux
+ spring-5-data-reactive
spring-5-mvc
spring-5-reactive
spring-5-reactive-client
@@ -586,16 +597,17 @@
spring-5-reactive-security
spring-5-security
spring-5-security-oauth
-
+
spring-activiti
spring-akka
spring-all
spring-amqp
+ spring-amqp-simple
spring-aop
spring-apache-camel
spring-batch
spring-bom
-
+
spring-boot
spring-boot-admin
spring-boot-angular
@@ -605,6 +617,7 @@
spring-boot-camel
spring-boot-client
+ spring-boot-configuration
spring-boot-crud
spring-boot-ctx-fluent
spring-boot-custom-starter
@@ -614,48 +627,50 @@
spring-boot-keycloak
spring-boot-logging-log4j2
spring-boot-mvc
+ spring-boot-mvc-birt
spring-boot-ops
spring-boot-rest
+ spring-boot-data
spring-boot-property-exp
spring-boot-security
spring-boot-testing
spring-boot-vue
spring-boot-libraries
-
+
spring-cloud
spring-cloud-bus
spring-cloud-data-flow
-
+
spring-core
spring-cucumber
-
+
spring-data-rest
spring-data-rest-querydsl
spring-dispatcher-servlet
spring-drools
-
+
spring-ehcache
spring-ejb
spring-exceptions
-
+
spring-freemarker
-
+
spring-groovy
-
+
spring-integration
-
+
spring-jenkins-pipeline
spring-jersey
spring-jinq
spring-jms
spring-jooq
-
+
spring-kafka
spring-katharsis
-
+
spring-ldap
-
+
spring-mobile
spring-mockito
spring-mvc-forms-jsp
@@ -663,14 +678,16 @@
spring-mvc-java
spring-mvc-kotlin
spring-mvc-simple
+ spring-mvc-simple-2
spring-mvc-velocity
spring-mvc-webflow
spring-mvc-xml
-
+
spring-protobuf
-
+
+
spring-quartz
-
+
spring-reactive-kotlin
spring-reactor
spring-remoting
@@ -686,9 +703,9 @@
spring-security-acl
spring-security-angular/server
spring-security-cache-control
-
+
spring-security-client
-
+
spring-security-core
spring-security-mvc-boot
spring-security-mvc-custom
@@ -716,48 +733,50 @@
spring-state-machine
spring-static-resources
spring-swagger-codegen
-
+
spring-thymeleaf
-
+
spring-userservice
-
+
spring-vault
spring-vertx
-
+
spring-webflux-amqp
-
+
spring-zuul
-
+
static-analysis
stripe
structurizr
struts-2
-
+
testing-modules
-
+
twilio
Twitter4J
-
+
undertow
-
+
vavr
vertx
vertx-and-rxjava
video-tutorials
vraptor
-
+
wicket
-
+
xml
xmlunit-2
xstream
-
+
tensorflow-java
-
+ spring-boot-flowable
+ spring-security-kerberos
+
-
+
spring-context
@@ -799,6 +818,7 @@
spring-boot-bootstrap
spring-boot-camel
spring-boot-client
+ spring-boot-configuration
spring-boot-custom-starter
greeter-spring-boot-autoconfigure
greeter-spring-boot-sample-app
@@ -895,6 +915,9 @@
persistence-modules/spring-data-eclipselink
persistence-modules/spring-data-solr
persistence-modules/spring-hibernate-5
+
+ spring-boot-flowable
+ spring-security-kerberos
@@ -932,10 +955,11 @@
parent-spring-5
parent-java
parent-kotlin
-
+
core-java-concurrency-advanced
core-kotlin
core-kotlin-2
+ core-kotlin-io
jenkins/hello-world
jws
@@ -945,15 +969,12 @@
persistence-modules/hibernate5
persistence-modules/java-jpa
persistence-modules/java-mongodb
- persistence-modules/jnosql
+ persistence-modules/jnosql
- spring-5-data-reactive
- spring-amqp-simple
-
- vaadin
+ vaadin
-
+
integration-lite-first
@@ -983,7 +1004,7 @@
parent-spring-5
parent-java
parent-kotlin
-
+
akka-streams
algorithms-genetic
algorithms-miscellaneous-1
@@ -1024,13 +1045,16 @@
cdi
checker-plugin
core-groovy
+ core-groovy-2
-
+
core-java-8
+ core-java-8-2
core-java-arrays
core-java-collections
+ core-java-collections-map
core-java-collections-list
core-java-concurrency-basic
core-java-concurrency-collections
@@ -1039,13 +1063,14 @@
core-java-lang-syntax
core-java-lang
core-java-lang-oop
+ core-java-lang-oop-2
core-java-networking
core-java-perf
core-java-sun
core-scala
couchbase
custom-pmd
-
+
dagger
data-structures
ddd
@@ -1053,13 +1078,13 @@
disruptor
dozer
drools
- dubbo
-
+ dubbo
+
ethereum
-
+
feign
flyway-cdi-extension
-
+
geotools
google-cloud
google-web-toolkit
@@ -1073,19 +1098,21 @@
guava-modules
guice
-
+
hazelcast
helidon
httpclient
hystrix
-
+
image-processing
immutables
jackson
jackson-2
+ jackson-simple
java-collections-conversions
java-collections-maps
+ java-collections-maps-2
java-ee-8-security-api
java-lite
@@ -1093,6 +1120,7 @@
java-rmi
java-spi
java-streams
+ java-streams-2
java-strings
java-vavr-stream
java-websocket
@@ -1122,7 +1150,7 @@
kotlin-libraries
-
+
libraries
libraries-data
@@ -1148,8 +1176,8 @@
mustache
mybatis
-
-
+
+
optaplanner
orika
osgi
@@ -1159,9 +1187,9 @@
performance-tests
protobuffer
-
+
persistence-modules
-
+
rabbitmq
ratpack
@@ -1173,8 +1201,8 @@
rule-engines
rsocket
rxjava
- rxjava-2
-
+ rxjava-2
+
@@ -1208,13 +1236,14 @@
parent-spring-5
parent-java
parent-kotlin
-
+
saas
spark-java
-
+
spring-4
-
+
spring-5
+ spring-5-data-reactive
spring-5-mvc
spring-5-reactive
spring-5-reactive-client
@@ -1222,16 +1251,17 @@
spring-5-reactive-security
spring-5-security
spring-5-security-oauth
-
+
spring-activiti
spring-akka
spring-all
spring-amqp
+ spring-amqp-simple
spring-aop
spring-apache-camel
spring-batch
spring-bom
-
+
spring-boot
spring-boot-admin
spring-boot-angular
@@ -1241,6 +1271,7 @@
spring-boot-camel
spring-boot-client
+ spring-boot-configuration
spring-boot-crud
spring-boot-ctx-fluent
spring-boot-custom-starter
@@ -1250,46 +1281,48 @@
spring-boot-keycloak
spring-boot-logging-log4j2
spring-boot-mvc
+ spring-boot-mvc-birt
spring-boot-ops
spring-boot-rest
+ spring-boot-data
spring-boot-property-exp
spring-boot-security
spring-boot-vue
-
+
spring-cloud
spring-cloud-bus
spring-cloud-data-flow
-
+
spring-core
spring-cucumber
-
+
spring-data-rest
spring-data-rest-querydsl
spring-dispatcher-servlet
spring-drools
-
- spring-ehcache
+
+ spring-ehcache
spring-ejb
spring-exceptions
-
+
spring-freemarker
-
+
spring-groovy
-
+
spring-integration
-
+
spring-jenkins-pipeline
spring-jersey
spring-jinq
spring-jms
spring-jooq
-
+
spring-kafka
spring-katharsis
-
+
spring-ldap
-
+
spring-mobile
spring-mockito
spring-mvc-forms-jsp
@@ -1297,14 +1330,16 @@
spring-mvc-java
spring-mvc-kotlin
spring-mvc-simple
+ spring-mvc-simple-2
spring-mvc-velocity
spring-mvc-webflow
spring-mvc-xml
-
+
spring-protobuf
-
+
+
spring-quartz
-
+
spring-reactive-kotlin
spring-reactor
spring-remoting
@@ -1317,13 +1352,13 @@
spring-rest-simple
spring-resttemplate
spring-roo
-
+
spring-security-acl
spring-security-angular/server
spring-security-cache-control
-
+
spring-security-client
-
+
spring-security-core
spring-security-mvc-boot
spring-security-mvc-custom
@@ -1350,42 +1385,42 @@
spring-state-machine
spring-static-resources
spring-swagger-codegen
-
+
spring-thymeleaf
-
+
spring-userservice
-
+
spring-vault
spring-vertx
-
+
spring-webflux-amqp
-
+
spring-zuul
-
+
static-analysis
stripe
structurizr
struts-2
-
+
testing-modules
-
+
twilio
Twitter4J
-
+
undertow
-
+
vavr
vertx
vertx-and-rxjava
video-tutorials
vraptor
-
+
wicket
-
+
xml
xmlunit-2
xstream
-
+
@@ -1419,8 +1454,8 @@
parent-spring-5
parent-java
parent-kotlin
-
- core-java
+
+ core-java
core-java-concurrency-advanced
core-kotlin
core-kotlin-2
@@ -1433,12 +1468,9 @@
persistence-modules/hibernate5
persistence-modules/java-jpa
persistence-modules/java-mongodb
- persistence-modules/jnosql
+ persistence-modules/jnosql
- spring-5-data-reactive
- spring-amqp-simple
-
- vaadin
+ vaadin
@@ -1464,15 +1496,15 @@
false
false
false
-
+
4.12
1.3
2.21.0
-
+
1.7.21
1.1.7
-
+
2.21.0
3.7.0
diff --git a/rxjava-2/README.md b/rxjava-2/README.md
index d0bdeec684..4182f3fa00 100644
--- a/rxjava-2/README.md
+++ b/rxjava-2/README.md
@@ -2,8 +2,8 @@
- [RxJava and Error Handling](http://www.baeldung.com/rxjava-error-handling)
- [RxJava 2 – Flowable](http://www.baeldung.com/rxjava-2-flowable)
-- [RxJava 2 - Completable](http://www.baeldung.com/rxjava-completable)
- [RxJava Maybe](http://www.baeldung.com/rxjava-maybe)
- [Introduction to RxRelay for RxJava](http://www.baeldung.com/rx-relay)
- [Combining RxJava Completables](https://www.baeldung.com/rxjava-completable)
- [Converting Synchronous and Asynchronous APIs to Observables using RxJava2](https://www.baeldung.com/rxjava-apis-to-observables)
+- [RxJava Hooks](https://www.baeldung.com/rxjava-hooks)
diff --git a/software-security/sql-injection-samples/pom.xml b/software-security/sql-injection-samples/pom.xml
index 5b33c674d4..0a28a96a07 100644
--- a/software-security/sql-injection-samples/pom.xml
+++ b/software-security/sql-injection-samples/pom.xml
@@ -17,7 +17,6 @@
-
org.springframework.boot
spring-boot-starter-jdbc
@@ -54,7 +53,6 @@
hibernate-jpamodelgen
-
diff --git a/spring-5-data-reactive/src/test/java/com/baeldung/reactive/repository/AccountCrudRepositoryIntegrationTest.java b/spring-5-data-reactive/src/test/java/com/baeldung/reactive/repository/AccountCrudRepositoryManualTest.java
similarity index 97%
rename from spring-5-data-reactive/src/test/java/com/baeldung/reactive/repository/AccountCrudRepositoryIntegrationTest.java
rename to spring-5-data-reactive/src/test/java/com/baeldung/reactive/repository/AccountCrudRepositoryManualTest.java
index f425826dce..d4b1d0eeda 100644
--- a/spring-5-data-reactive/src/test/java/com/baeldung/reactive/repository/AccountCrudRepositoryIntegrationTest.java
+++ b/spring-5-data-reactive/src/test/java/com/baeldung/reactive/repository/AccountCrudRepositoryManualTest.java
@@ -17,7 +17,7 @@ import static org.junit.Assert.assertNotNull;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Spring5ReactiveApplication.class)
-public class AccountCrudRepositoryIntegrationTest {
+public class AccountCrudRepositoryManualTest {
@Autowired
AccountCrudRepository repository;
diff --git a/spring-5-data-reactive/src/test/java/com/baeldung/reactive/repository/AccountMongoRepositoryIntegrationTest.java b/spring-5-data-reactive/src/test/java/com/baeldung/reactive/repository/AccountMongoRepositoryManualTest.java
similarity index 97%
rename from spring-5-data-reactive/src/test/java/com/baeldung/reactive/repository/AccountMongoRepositoryIntegrationTest.java
rename to spring-5-data-reactive/src/test/java/com/baeldung/reactive/repository/AccountMongoRepositoryManualTest.java
index bfa6a789b2..2ca075aa5e 100644
--- a/spring-5-data-reactive/src/test/java/com/baeldung/reactive/repository/AccountMongoRepositoryIntegrationTest.java
+++ b/spring-5-data-reactive/src/test/java/com/baeldung/reactive/repository/AccountMongoRepositoryManualTest.java
@@ -19,7 +19,7 @@ import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatc
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Spring5ReactiveApplication.class)
-public class AccountMongoRepositoryIntegrationTest {
+public class AccountMongoRepositoryManualTest {
@Autowired
AccountMongoRepository repository;
diff --git a/spring-5-data-reactive/src/test/java/com/baeldung/reactive/repository/AccountRxJavaRepositoryIntegrationTest.java b/spring-5-data-reactive/src/test/java/com/baeldung/reactive/repository/AccountRxJavaRepositoryManualTest.java
similarity index 97%
rename from spring-5-data-reactive/src/test/java/com/baeldung/reactive/repository/AccountRxJavaRepositoryIntegrationTest.java
rename to spring-5-data-reactive/src/test/java/com/baeldung/reactive/repository/AccountRxJavaRepositoryManualTest.java
index e9b3eb1c40..d91acd24e2 100644
--- a/spring-5-data-reactive/src/test/java/com/baeldung/reactive/repository/AccountRxJavaRepositoryIntegrationTest.java
+++ b/spring-5-data-reactive/src/test/java/com/baeldung/reactive/repository/AccountRxJavaRepositoryManualTest.java
@@ -15,7 +15,7 @@ import static org.junit.Assert.assertNotNull;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Spring5ReactiveApplication.class)
-public class AccountRxJavaRepositoryIntegrationTest {
+public class AccountRxJavaRepositoryManualTest {
@Autowired
AccountRxJavaRepository repository;
diff --git a/spring-5-data-reactive/src/test/java/com/baeldung/reactive/template/AccountTemplateOperationsIntegrationTest.java b/spring-5-data-reactive/src/test/java/com/baeldung/reactive/template/AccountTemplateOperationsManualTest.java
similarity index 97%
rename from spring-5-data-reactive/src/test/java/com/baeldung/reactive/template/AccountTemplateOperationsIntegrationTest.java
rename to spring-5-data-reactive/src/test/java/com/baeldung/reactive/template/AccountTemplateOperationsManualTest.java
index 373da0e393..5fa0e39317 100644
--- a/spring-5-data-reactive/src/test/java/com/baeldung/reactive/template/AccountTemplateOperationsIntegrationTest.java
+++ b/spring-5-data-reactive/src/test/java/com/baeldung/reactive/template/AccountTemplateOperationsManualTest.java
@@ -16,7 +16,7 @@ import static org.junit.jupiter.api.Assertions.*;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Spring5ReactiveApplication.class)
-public class AccountTemplateOperationsIntegrationTest {
+public class AccountTemplateOperationsManualTest {
@Autowired
AccountTemplateOperations accountTemplate;
diff --git a/spring-5-security-oauth/README.md b/spring-5-security-oauth/README.md
index 5a444d4784..a5cec370c7 100644
--- a/spring-5-security-oauth/README.md
+++ b/spring-5-security-oauth/README.md
@@ -1,5 +1,5 @@
## Relevant articles:
-- [Spring Security 5 -OAuth2 Login](http://www.baeldung.com/spring-security-5-oauth2-login)
+- [Spring Security 5 – OAuth2 Login](http://www.baeldung.com/spring-security-5-oauth2-login)
- [Extracting Principal and Authorities using Spring Security OAuth](https://www.baeldung.com/spring-security-oauth-principal-authorities-extractor)
- [Customizing Authorization and Token Requests with Spring Security 5.1 Client](https://www.baeldung.com/spring-security-custom-oauth-requests)
diff --git a/spring-5-webflux/README.md b/spring-5-webflux/README.md
new file mode 100644
index 0000000000..84c3d5a4ca
--- /dev/null
+++ b/spring-5-webflux/README.md
@@ -0,0 +1,4 @@
+## Relevant articles:
+
+- [Spring Boot Reactor Netty Configuration](https://www.baeldung.com/spring-boot-reactor-netty)
+- [How to Return 404 with Spring WebFlux](https://www.baeldung.com/spring-webflux-404)
diff --git a/spring-akka/pom.xml b/spring-akka/pom.xml
index 92b3f1162d..d8b943b5ae 100644
--- a/spring-akka/pom.xml
+++ b/spring-akka/pom.xml
@@ -19,7 +19,7 @@
com.typesafe.akka
- akka-actor_2.11
+ akka-actor_${scala.version}
${akka.version}
@@ -44,6 +44,7 @@
4.3.4.RELEASE
2.4.14
+ 2.11
\ No newline at end of file
diff --git a/spring-all/README.md b/spring-all/README.md
index a111d2e542..b0805e5477 100644
--- a/spring-all/README.md
+++ b/spring-all/README.md
@@ -14,7 +14,7 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
- [Properties with Spring and Spring Boot](http://www.baeldung.com/properties-with-spring) - checkout the `org.baeldung.properties` package for all scenarios of properties injection and usage
- [Spring Profiles](http://www.baeldung.com/spring-profiles)
- [A Spring Custom Annotation for a Better DAO](http://www.baeldung.com/spring-annotation-bean-pre-processor)
-- [What's New in Spring 4.3?](http://www.baeldung.com/whats-new-in-spring-4-3)
+- [What’s New in Spring 4.3?](http://www.baeldung.com/whats-new-in-spring-4-3)
- [Running Setup Data on Startup in Spring](http://www.baeldung.com/running-setup-logic-on-startup-in-spring)
- [Quick Guide to Spring Controllers](http://www.baeldung.com/spring-controllers)
- [Quick Guide to Spring Bean Scopes](http://www.baeldung.com/spring-bean-scopes)
@@ -34,3 +34,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
- [Spring Events](https://www.baeldung.com/spring-events)
- [Spring Null-Safety Annotations](https://www.baeldung.com/spring-null-safety-annotations)
- [Spring JDBC](https://www.baeldung.com/spring-jdbc-jdbctemplate)
+- [Using @Autowired in Abstract Classes](https://www.baeldung.com/spring-autowired-abstract-class)
diff --git a/spring-batch/README.md b/spring-batch/README.md
index 737e7e13f5..ddd830cd47 100644
--- a/spring-batch/README.md
+++ b/spring-batch/README.md
@@ -6,5 +6,5 @@
### Relevant Articles:
- [Introduction to Spring Batch](http://www.baeldung.com/introduction-to-spring-batch)
- [Spring Batch using Partitioner](http://www.baeldung.com/spring-batch-partitioner)
-- [Spring Batch Tasklets vs Chunks Approach](http://www.baeldung.com/spring-batch-tasklet-chunk)
+- [Spring Batch – Tasklets vs Chunks](http://www.baeldung.com/spring-batch-tasklet-chunk)
- [How to Trigger and Stop a Scheduled Spring Batch Job](http://www.baeldung.com/spring-batch-start-stop-job)
diff --git a/spring-boot-angular/src/main/java/com/baeldung/pom.xml b/spring-boot-angular/src/main/java/com/baeldung/pom.xml
index d4ebc870b4..ac86f932b4 100644
--- a/spring-boot-angular/src/main/java/com/baeldung/pom.xml
+++ b/spring-boot-angular/src/main/java/com/baeldung/pom.xml
@@ -6,15 +6,13 @@
1.0
jar
Spring Boot Angular Application
+
org.springframework.boot
spring-boot-starter-parent
2.1.3.RELEASE
-
- 1.8
-
@@ -46,4 +44,7 @@
+
+ 1.8
+
\ No newline at end of file
diff --git a/spring-boot-configuration/.gitignore b/spring-boot-configuration/.gitignore
new file mode 100644
index 0000000000..153c9335eb
--- /dev/null
+++ b/spring-boot-configuration/.gitignore
@@ -0,0 +1,29 @@
+HELP.md
+/target/
+!.mvn/wrapper/maven-wrapper.jar
+
+### STS ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### IntelliJ IDEA ###
+.idea
+*.iws
+*.iml
+*.ipr
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+/build/
+
+### VS Code ###
+.vscode/
diff --git a/spring-boot-configuration/README.MD b/spring-boot-configuration/README.MD
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/spring-boot-configuration/pom.xml b/spring-boot-configuration/pom.xml
new file mode 100644
index 0000000000..2ecef7bb02
--- /dev/null
+++ b/spring-boot-configuration/pom.xml
@@ -0,0 +1,41 @@
+
+
+ 4.0.0
+
+
+ parent-boot-2
+ com.baeldung
+ 0.0.1-SNAPSHOT
+ ../parent-boot-2
+
+
+ com.baeldung
+ spring-boot-configuration
+ 0.0.1-SNAPSHOT
+ spring-boot-configuration
+ Demo project for Spring Boot configuration
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+
+
diff --git a/spring-boot-configuration/src/main/java/com/baeldung/springbootconfiguration/SpringBootConfigurationApplication.java b/spring-boot-configuration/src/main/java/com/baeldung/springbootconfiguration/SpringBootConfigurationApplication.java
new file mode 100644
index 0000000000..b4f5681475
--- /dev/null
+++ b/spring-boot-configuration/src/main/java/com/baeldung/springbootconfiguration/SpringBootConfigurationApplication.java
@@ -0,0 +1,13 @@
+package com.baeldung.springbootconfiguration;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class SpringBootConfigurationApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(SpringBootConfigurationApplication.class, args);
+ }
+
+}
diff --git a/spring-boot-configuration/src/main/resources/application-tomcat.properties b/spring-boot-configuration/src/main/resources/application-tomcat.properties
new file mode 100644
index 0000000000..d7c1ba9ac3
--- /dev/null
+++ b/spring-boot-configuration/src/main/resources/application-tomcat.properties
@@ -0,0 +1,23 @@
+# server configuration
+server.port=80
+server.address=127.0.0.1
+
+## Error handling configuration
+server.error.whitelabel.enabled=true
+server.error.path=/user-error
+server.error.include-exception=true
+server.error.include-stacktrace=always
+
+## Server connections configuration
+server.tomcat.max-threads=200
+server.connection-timeout=5s
+server.max-http-header-size=8KB
+server.tomcat.max-swallow-size=2MB
+server.tomcat.max-http-post-size=2MB
+
+## Access logs configuration
+server.tomcat.accesslog.enabled=true
+server.tomcat.accesslog.directory=logs
+server.tomcat.accesslog.file-date-format=yyyy-MM-dd
+server.tomcat.accesslog.prefix=access_log
+server.tomcat.accesslog.suffix=.log
diff --git a/spring-boot-configuration/src/main/resources/application.properties b/spring-boot-configuration/src/main/resources/application.properties
new file mode 100644
index 0000000000..8b13789179
--- /dev/null
+++ b/spring-boot-configuration/src/main/resources/application.properties
@@ -0,0 +1 @@
+
diff --git a/spring-boot-configuration/src/test/java/com/baeldung/springbootconfiguration/SpringContextIntegrationTest.java b/spring-boot-configuration/src/test/java/com/baeldung/springbootconfiguration/SpringContextIntegrationTest.java
new file mode 100644
index 0000000000..d6b2b50a2f
--- /dev/null
+++ b/spring-boot-configuration/src/test/java/com/baeldung/springbootconfiguration/SpringContextIntegrationTest.java
@@ -0,0 +1,16 @@
+package com.baeldung.springbootconfiguration;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class SpringContextIntegrationTest {
+
+ @Test
+ public void contextLoads() {
+ }
+
+}
diff --git a/spring-boot-data/README.md b/spring-boot-data/README.md
index 21f7303c48..d93b8c3e93 100644
--- a/spring-boot-data/README.md
+++ b/spring-boot-data/README.md
@@ -1,2 +1,2 @@
### Relevant Articles:
-- [Formatting JSON Dates in Spring ](https://www.baeldung.com/spring-boot-formatting-json-dates)
\ No newline at end of file
+- [Formatting JSON Dates in Spring Boot](https://www.baeldung.com/spring-boot-formatting-json-dates)
diff --git a/spring-boot-flowable/README.md b/spring-boot-flowable/README.md
new file mode 100644
index 0000000000..8fb90d953b
--- /dev/null
+++ b/spring-boot-flowable/README.md
@@ -0,0 +1,3 @@
+### Relevant articles
+
+- [Introduction to Flowable](http://www.baeldung.com/flowable)
diff --git a/spring-boot-flowable/pom.xml b/spring-boot-flowable/pom.xml
new file mode 100644
index 0000000000..f9531a1e6a
--- /dev/null
+++ b/spring-boot-flowable/pom.xml
@@ -0,0 +1,58 @@
+
+
+ 4.0.0
+ spring-boot-flowable
+ war
+ spring-boot-flowable
+ Spring Boot Flowable Module
+
+ parent-boot-2
+ com.baeldung
+ 0.0.1-SNAPSHOT
+ ../parent-boot-2
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ com.h2database
+ h2
+ runtime
+
+
+ org.flowable
+ flowable-spring-boot-starter-rest
+ ${flowable.version}
+
+
+ org.flowable
+ flowable-spring-boot-starter-actuator
+ ${flowable.version}
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ test
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+
+ 6.4.1
+
+
\ No newline at end of file
diff --git a/spring-boot-flowable/src/main/java/com/baeldung/Application.java b/spring-boot-flowable/src/main/java/com/baeldung/Application.java
new file mode 100644
index 0000000000..37dbe7dab8
--- /dev/null
+++ b/spring-boot-flowable/src/main/java/com/baeldung/Application.java
@@ -0,0 +1,13 @@
+package com.baeldung;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class Application {
+
+ public static void main(String[] args) {
+ SpringApplication.run(Application.class, args);
+ }
+
+}
diff --git a/spring-boot-flowable/src/main/java/com/baeldung/controller/ArticleWorkflowController.java b/spring-boot-flowable/src/main/java/com/baeldung/controller/ArticleWorkflowController.java
new file mode 100644
index 0000000000..3087d30af4
--- /dev/null
+++ b/spring-boot-flowable/src/main/java/com/baeldung/controller/ArticleWorkflowController.java
@@ -0,0 +1,32 @@
+package com.baeldung.controller;
+
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import com.baeldung.domain.Approval;
+import com.baeldung.domain.Article;
+import com.baeldung.service.ArticleWorkflowService;
+
+@RestController
+public class ArticleWorkflowController {
+ @Autowired
+ private ArticleWorkflowService service;
+ @PostMapping("/submit")
+ public void submit(@RequestBody Article article) {
+ service.startProcess(article);
+ }
+ @GetMapping("/tasks")
+ public List getTasks(@RequestParam String assignee) {
+ return service.getTasks(assignee);
+ }
+ @PostMapping("/review")
+ public void review(@RequestBody Approval approval) {
+ service.submitReview(approval);
+ }
+}
\ No newline at end of file
diff --git a/spring-boot-flowable/src/main/java/com/baeldung/domain/Approval.java b/spring-boot-flowable/src/main/java/com/baeldung/domain/Approval.java
new file mode 100644
index 0000000000..b0c9c99437
--- /dev/null
+++ b/spring-boot-flowable/src/main/java/com/baeldung/domain/Approval.java
@@ -0,0 +1,24 @@
+package com.baeldung.domain;
+
+public class Approval {
+
+ private String id;
+ private boolean status;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public boolean isStatus() {
+ return status;
+ }
+
+ public void setStatus(boolean status) {
+ this.status = status;
+ }
+
+}
diff --git a/spring-boot-flowable/src/main/java/com/baeldung/domain/Article.java b/spring-boot-flowable/src/main/java/com/baeldung/domain/Article.java
new file mode 100644
index 0000000000..efa2eb431e
--- /dev/null
+++ b/spring-boot-flowable/src/main/java/com/baeldung/domain/Article.java
@@ -0,0 +1,52 @@
+package com.baeldung.domain;
+
+public class Article {
+
+ private String id;
+ private String author;
+ private String url;
+
+ public Article() {
+ }
+
+ public Article(String author, String url) {
+ this.author = author;
+ this.url = url;
+ }
+
+ public Article(String id, String author, String url) {
+ this.id = id;
+ this.author = author;
+ this.url = url;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getAuthor() {
+ return author;
+ }
+
+ public void setAuthor(String author) {
+ this.author = author;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ @Override
+ public String toString() {
+ return ("[" + this.author + " " + this.url + "]");
+ }
+
+}
diff --git a/spring-boot-flowable/src/main/java/com/baeldung/service/ArticleWorkflowService.java b/spring-boot-flowable/src/main/java/com/baeldung/service/ArticleWorkflowService.java
new file mode 100644
index 0000000000..b1e2a92354
--- /dev/null
+++ b/spring-boot-flowable/src/main/java/com/baeldung/service/ArticleWorkflowService.java
@@ -0,0 +1,55 @@
+package com.baeldung.service;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import org.flowable.engine.RuntimeService;
+import org.flowable.engine.TaskService;
+import org.flowable.task.api.Task;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import com.baeldung.domain.Approval;
+import com.baeldung.domain.Article;
+
+@Service
+public class ArticleWorkflowService {
+ @Autowired
+ private RuntimeService runtimeService;
+ @Autowired
+ private TaskService taskService;
+
+ @Transactional
+ public void startProcess(Article article) {
+ Map variables = new HashMap();
+ variables.put("author", article.getAuthor());
+ variables.put("url", article.getUrl());
+ runtimeService.startProcessInstanceByKey("articleReview", variables);
+ }
+
+ @Transactional
+ public List getTasks(String assignee) {
+ List tasks = taskService.createTaskQuery()
+ .taskCandidateGroup(assignee)
+ .list();
+
+ List articles = tasks.stream()
+ .map(task -> {
+ Map variables = taskService.getVariables(task.getId());
+ return new Article(
+ task.getId(), (String) variables.get("author"), (String) variables.get("url"));
+ })
+ .collect(Collectors.toList());
+ return articles;
+ }
+
+ @Transactional
+ public void submitReview(Approval approval) {
+ Map variables = new HashMap();
+ variables.put("approved", approval.isStatus());
+ taskService.complete(approval.getId(), variables);
+ }
+}
\ No newline at end of file
diff --git a/spring-boot-flowable/src/main/java/com/baeldung/service/PublishArticleService.java b/spring-boot-flowable/src/main/java/com/baeldung/service/PublishArticleService.java
new file mode 100644
index 0000000000..b43f1dccdb
--- /dev/null
+++ b/spring-boot-flowable/src/main/java/com/baeldung/service/PublishArticleService.java
@@ -0,0 +1,10 @@
+package com.baeldung.service;
+
+import org.flowable.engine.delegate.DelegateExecution;
+import org.flowable.engine.delegate.JavaDelegate;
+
+public class PublishArticleService implements JavaDelegate {
+ public void execute(DelegateExecution execution) {
+ System.out.println("Publishing the approved article.");
+ }
+}
diff --git a/spring-boot-flowable/src/main/java/com/baeldung/service/SendMailService.java b/spring-boot-flowable/src/main/java/com/baeldung/service/SendMailService.java
new file mode 100644
index 0000000000..f80b16748f
--- /dev/null
+++ b/spring-boot-flowable/src/main/java/com/baeldung/service/SendMailService.java
@@ -0,0 +1,10 @@
+package com.baeldung.service;
+
+import org.flowable.engine.delegate.DelegateExecution;
+import org.flowable.engine.delegate.JavaDelegate;
+
+public class SendMailService implements JavaDelegate {
+ public void execute(DelegateExecution execution) {
+ System.out.println("Sending rejection mail to author.");
+ }
+}
diff --git a/spring-boot-flowable/src/main/resources/application.properties b/spring-boot-flowable/src/main/resources/application.properties
new file mode 100644
index 0000000000..c3afcaa0b5
--- /dev/null
+++ b/spring-boot-flowable/src/main/resources/application.properties
@@ -0,0 +1 @@
+management.endpoint.flowable.enabled=true
\ No newline at end of file
diff --git a/spring-boot-flowable/src/main/resources/processes/article-workflow.bpmn20.xml b/spring-boot-flowable/src/main/resources/processes/article-workflow.bpmn20.xml
new file mode 100644
index 0000000000..6bf210dcee
--- /dev/null
+++ b/spring-boot-flowable/src/main/resources/processes/article-workflow.bpmn20.xml
@@ -0,0 +1,51 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/spring-boot-flowable/src/test/java/com/baeldung/processes/ArticleWorkflowUnitTest.java b/spring-boot-flowable/src/test/java/com/baeldung/processes/ArticleWorkflowUnitTest.java
new file mode 100644
index 0000000000..ef5453623a
--- /dev/null
+++ b/spring-boot-flowable/src/test/java/com/baeldung/processes/ArticleWorkflowUnitTest.java
@@ -0,0 +1,40 @@
+package com.baeldung.processes;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.flowable.engine.RuntimeService;
+import org.flowable.engine.TaskService;
+import org.flowable.engine.test.Deployment;
+import org.flowable.spring.impl.test.FlowableSpringExtension;
+import org.flowable.task.api.Task;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+
+@ExtendWith(FlowableSpringExtension.class)
+@ExtendWith(SpringExtension.class)
+public class ArticleWorkflowUnitTest {
+ @Autowired
+ private RuntimeService runtimeService;
+ @Autowired
+ private TaskService taskService;
+ @Test
+ @Deployment(resources = { "processes/article-workflow.bpmn20.xml" })
+ void articleApprovalTest() {
+ Map variables = new HashMap();
+ variables.put("author", "test@baeldung.com");
+ variables.put("url", "http://baeldung.com/dummy");
+ runtimeService.startProcessInstanceByKey("articleReview", variables);
+ Task task = taskService.createTaskQuery()
+ .singleResult();
+ assertEquals("Review the submitted tutorial", task.getName());
+ variables.put("approved", true);
+ taskService.complete(task.getId(), variables);
+ assertEquals(0, runtimeService.createProcessInstanceQuery()
+ .count());
+ }
+}
\ No newline at end of file
diff --git a/spring-boot-mvc-birt/pom.xml b/spring-boot-mvc-birt/pom.xml
new file mode 100644
index 0000000000..05d3f3865a
--- /dev/null
+++ b/spring-boot-mvc-birt/pom.xml
@@ -0,0 +1,83 @@
+
+
+ 4.0.0
+ com.baeldung
+ spring-boot-mvc-birt
+ spring-boot-mvc-birt
+ 0.0.1-SNAPSHOT
+ jar
+ Module For Spring Boot Integration with BIRT
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.1.1.RELEASE
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+ org.springframework.boot
+ spring-boot-starter-logging
+
+
+ ch.qos.logback
+ logback-classic
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+
+ com.innoventsolutions.birt.runtime
+ org.eclipse.birt.runtime_4.8.0-20180626
+ 4.8.0
+
+
+
+ log4j
+ log4j
+ 1.2.17
+
+
+
+ org.projectlombok
+ lombok
+ 1.18.6
+ provided
+
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+
+
+ 2.1.1.RELEASE
+ com.baeldung.springbootmvc.SpringBootMvcApplication
+ 1.8
+ 1.8
+
+
+
diff --git a/spring-boot-mvc-birt/reports/csv_data_report.rptdesign b/spring-boot-mvc-birt/reports/csv_data_report.rptdesign
new file mode 100644
index 0000000000..f390c5e69b
--- /dev/null
+++ b/spring-boot-mvc-birt/reports/csv_data_report.rptdesign
@@ -0,0 +1,2032 @@
+
+
+ Eclipse BIRT Designer Version 4.7.0.v201706222054
+ new_report
+
+
+ queryText
+ 5
+
+
+ HOME
+ 4
+
+
+ URI
+ 4
+
+
+ DELIMTYPE
+ 4
+
+
+ CHARSET
+ 4
+
+
+ INCLCOLUMNNAME
+ 4
+
+
+ INCLTYPELINE
+ 4
+
+
+ TRAILNULLCOLS
+ 4
+
+
+ OdaConnProfileName
+ 4
+
+
+ OdaConnProfileStorePath
+ 4
+
+
+ in
+ /templates/blank_report.gif
+ ltr
+ 96
+
+
+ reports/data.csv
+ COMMA
+ UTF-8
+ YES
+ NO
+ NO
+
+
+
+
+ nulls lowest
+
+
+ Student
+ dimension
+ Student
+
+
+ Math
+ measure
+ Math
+
+
+ Geography
+ measure
+ Geography
+
+
+ History
+ measure
+ History
+
+
+
+
+
+
+ 1
+ Student
+ string
+
+
+ 2
+ Math
+ integer
+
+
+ 3
+ Geography
+ integer
+
+
+ 4
+ History
+ integer
+
+
+
+ Data Source
+
+
+ 1
+ Student
+ Student
+ string
+ 12
+
+
+ 2
+ Math
+ Math
+ integer
+ 12
+
+
+ 3
+ Geography
+ Geography
+ integer
+ 12
+
+
+ 4
+ History
+ History
+ integer
+ 12
+
+
+
+
+
+ 2.0
+
+
+
+
+
+
+ Studen
+ 1
+
+ 12
+ -1
+ -1
+ Unknown
+
+
+ Studen
+
+
+
+
+
+
+ Math
+ 2
+
+ 12
+ -1
+ -1
+ Unknown
+
+
+ Math
+
+
+
+
+
+
+ Geography
+ 3
+
+ 12
+ -1
+ -1
+ Unknown
+
+
+ Geography
+
+
+
+
+
+
+ History
+ 4
+
+ 12
+ -1
+ -1
+ Unknown
+
+
+ History
+
+
+
+
+
+
+
+]]>
+
+
+
+
+
+
+
+
+
+
+
+ 7.947916666666667in
+
+ 2.15625in
+
+
+
+
+ 2
+ 1
+
+
+ 2.6.1
+ Bar Chart
+ Side-by-side
+
+
+
+ 0.0
+ 0.0
+ 0.0
+ 0.0
+
+
+ 3.0
+ 3.0
+ 3.0
+ 3.0
+
+ -1
+ -1
+ -1
+ -1
+
+
+ 1
+
+ 255
+ 0
+ 0
+ 0
+
+ false
+
+ true
+
+
+
+
+ 0.0
+ 0.0
+ 0.0
+ 0.0
+
+
+ 3.0
+ 3.0
+ 3.0
+ 3.0
+
+ -1
+ -1
+ -1
+ -1
+
+
+ 1
+
+ 255
+ 0
+ 0
+ 0
+
+ false
+
+ true
+ 5
+ 5
+
+
+
+ 0
+
+ 255
+ 0
+ 0
+ 0
+
+ false
+
+
+ 0.0
+ 0.0
+ 0.0
+ 0.0
+
+
+
+
+
+ 0.0
+ 0.0
+ 0.0
+ 0.0
+
+
+ 3.0
+ 3.0
+ 3.0
+ 3.0
+
+ -1
+ -1
+ -1
+ -1
+
+
+ 1
+
+ 255
+ 0
+ 0
+ 0
+
+ false
+
+ true
+
+
+
+ 0
+
+ 255
+ 0
+ 0
+ 0
+
+ false
+
+
+ 2.0
+ 2.0
+ 2.0
+ 2.0
+
+
+
+
+
+
+
+
+ Vertical
+ Top_Bottom
+
+
+ 1
+
+ 255
+ 0
+ 0
+ 0
+
+ true
+
+ Right
+ Series
+
+
+
+
+
+
+
+
+ 0
+ 255
+ 255
+ 255
+
+
+
+ 1
+
+ 255
+ 0
+ 0
+ 0
+
+ false
+
+
+ 0.0
+ 2.0
+ 0.0
+ 3.0
+
+ false
+
+ Above
+ false
+
+
+ 0.0
+ 0.0
+ 572.25
+ 286.125
+
+
+ 3.0
+ 3.0
+ 3.0
+ 3.0
+
+ -1
+ -1
+ -1
+ -1
+
+
+ 1
+
+ 255
+ 0
+ 0
+ 0
+
+ false
+
+ true
+
+ Two_Dimensional
+ Points
+ 10.0
+
+ enable.area.alt
+ false
+
+
+
+ A, B, C
+
+
+ 5,4,12
+ 0
+
+
+ 10.0,8.0,24.0
+ 1
+
+
+ 15.0,12.0,36.0
+ 2
+
+
+
+ ToggleSerieVisibility
+
+
+
+ This chart contains no data.
+
+
+ Center
+ Center
+
+
+
+
+ 64
+ 127
+ 127
+ 127
+
+
+
+ 128
+ 127
+ 127
+ 127
+
+ true
+
+
+ 10.0
+ 10.0
+ 10.0
+ 10.0
+
+ false
+
+
+ Text
+
+
+ X-Axis Title
+
+ 14.0
+ true
+
+ Center
+ Center
+
+
+
+
+ 0
+ 255
+ 255
+ 255
+
+
+
+ 1
+
+ 255
+ 0
+ 0
+ 0
+
+
+
+ 0.0
+ 2.0
+ 0.0
+ 3.0
+
+ false
+
+ Below
+
+ Linear
+
+
+ Y-Axis Title
+
+ 14.0
+ true
+
+ Center
+ Center
+
+
+
+
+ 0
+ 255
+ 255
+ 255
+
+
+
+ 1
+
+ 255
+ 0
+ 0
+ 0
+
+
+
+ 0.0
+ 2.0
+ 0.0
+ 3.0
+
+ false
+
+ Left
+
+
+
+
+ Numeric
+
+
+
+
+ 255
+ 80
+ 166
+ 218
+
+
+ 255
+ 242
+ 88
+ 106
+
+
+ 255
+ 232
+ 172
+ 57
+
+
+ 255
+ 128
+ 255
+ 128
+
+
+ 255
+ 64
+ 128
+ 128
+
+
+ 255
+ 128
+ 128
+ 192
+
+
+ 255
+ 170
+ 85
+ 85
+
+
+ 255
+ 128
+ 128
+ 0
+
+
+ 255
+ 192
+ 192
+ 192
+
+
+ 255
+ 255
+ 255
+ 128
+
+
+ 255
+ 128
+ 192
+ 128
+
+
+ 255
+ 7
+ 146
+ 94
+
+
+ 255
+ 0
+ 128
+ 255
+
+
+ 255
+ 255
+ 128
+ 192
+
+
+ 255
+ 0
+ 255
+ 255
+
+
+ 255
+ 255
+ 128
+ 128
+
+
+ 255
+ 0
+ 128
+ 192
+
+
+ 255
+ 255
+ 0
+ 255
+
+
+ 255
+ 128
+ 64
+ 64
+
+
+ 255
+ 255
+ 128
+ 64
+
+
+ 255
+ 80
+ 240
+ 120
+
+
+ 255
+ 0
+ 64
+ 128
+
+
+ 255
+ 128
+ 0
+ 64
+
+
+ 255
+ 255
+ 0
+ 128
+
+
+ 255
+ 128
+ 128
+ 64
+
+
+ 255
+ 128
+ 128
+ 128
+
+
+ 255
+ 255
+ 128
+ 255
+
+
+ 255
+ 0
+ 64
+ 0
+
+
+ 255
+ 0
+ 0
+ 0
+
+
+ 255
+ 255
+ 255
+ 255
+
+
+ 255
+ 255
+ 128
+ 0
+
+
+
+ true
+
+
+ row["Geography"]
+
+ Text
+ Sum
+
+
+ Geo
+
+
+ Orthogonal_Value
+
+ ,
+
+ Outside
+ false
+
+ onmouseover
+
+ Show_Tooltip
+
+
+ 200
+
+
+
+ Rectangle
+
+
+ Text
+ Sum
+
+
+
+
+
+
+ Numeric
+
+
+
+
+ 255
+ 242
+ 88
+ 106
+
+
+ 255
+ 232
+ 172
+ 57
+
+
+ 255
+ 128
+ 255
+ 128
+
+
+ 255
+ 64
+ 128
+ 128
+
+
+ 255
+ 128
+ 128
+ 192
+
+
+ 255
+ 170
+ 85
+ 85
+
+
+ 255
+ 128
+ 128
+ 0
+
+
+ 255
+ 192
+ 192
+ 192
+
+
+ 255
+ 255
+ 255
+ 128
+
+
+ 255
+ 128
+ 192
+ 128
+
+
+ 255
+ 7
+ 146
+ 94
+
+
+ 255
+ 0
+ 128
+ 255
+
+
+ 255
+ 255
+ 128
+ 192
+
+
+ 255
+ 0
+ 255
+ 255
+
+
+ 255
+ 255
+ 128
+ 128
+
+
+ 255
+ 0
+ 128
+ 192
+
+
+ 255
+ 255
+ 0
+ 255
+
+
+ 255
+ 128
+ 64
+ 64
+
+
+ 255
+ 255
+ 128
+ 64
+
+
+ 255
+ 80
+ 240
+ 120
+
+
+ 255
+ 0
+ 64
+ 128
+
+
+ 255
+ 128
+ 0
+ 64
+
+
+ 255
+ 255
+ 0
+ 128
+
+
+ 255
+ 128
+ 128
+ 64
+
+
+ 255
+ 128
+ 128
+ 128
+
+
+ 255
+ 255
+ 128
+ 255
+
+
+ 255
+ 0
+ 64
+ 0
+
+
+ 255
+ 0
+ 0
+ 0
+
+
+ 255
+ 255
+ 255
+ 255
+
+
+ 255
+ 255
+ 128
+ 0
+
+
+ 255
+ 80
+ 166
+ 218
+
+
+
+ true
+
+
+ row["History"]
+
+ false
+ Text
+ Sum
+
+
+ History
+
+
+ Orthogonal_Value
+
+ ,
+
+ Outside
+ false
+
+ onmouseover
+
+ Show_Tooltip
+
+
+ 200
+
+
+
+ Rectangle
+
+
+ Text
+ Sum
+
+
+
+
+
+
+ Numeric
+
+
+
+
+ 255
+ 232
+ 172
+ 57
+
+
+ 255
+ 128
+ 255
+ 128
+
+
+ 255
+ 64
+ 128
+ 128
+
+
+ 255
+ 128
+ 128
+ 192
+
+
+ 255
+ 170
+ 85
+ 85
+
+
+ 255
+ 128
+ 128
+ 0
+
+
+ 255
+ 192
+ 192
+ 192
+
+
+ 255
+ 255
+ 255
+ 128
+
+
+ 255
+ 128
+ 192
+ 128
+
+
+ 255
+ 7
+ 146
+ 94
+
+
+ 255
+ 0
+ 128
+ 255
+
+
+ 255
+ 255
+ 128
+ 192
+
+
+ 255
+ 0
+ 255
+ 255
+
+
+ 255
+ 255
+ 128
+ 128
+
+
+ 255
+ 0
+ 128
+ 192
+
+
+ 255
+ 255
+ 0
+ 255
+
+
+ 255
+ 128
+ 64
+ 64
+
+
+ 255
+ 255
+ 128
+ 64
+
+
+ 255
+ 80
+ 240
+ 120
+
+
+ 255
+ 0
+ 64
+ 128
+
+
+ 255
+ 128
+ 0
+ 64
+
+
+ 255
+ 255
+ 0
+ 128
+
+
+ 255
+ 128
+ 128
+ 64
+
+
+ 255
+ 128
+ 128
+ 128
+
+
+ 255
+ 255
+ 128
+ 255
+
+
+ 255
+ 0
+ 64
+ 0
+
+
+ 255
+ 0
+ 0
+ 0
+
+
+ 255
+ 255
+ 255
+ 255
+
+
+ 255
+ 255
+ 128
+ 0
+
+
+ 255
+ 80
+ 166
+ 218
+
+
+ 255
+ 242
+ 88
+ 106
+
+
+
+ true
+
+
+ row["Math"]
+
+ false
+ Text
+ Sum
+
+
+ Math
+
+
+ Orthogonal_Value
+
+ ,
+
+ Outside
+ false
+
+ onmouseover
+
+ Show_Tooltip
+
+
+ 200
+
+
+
+ Rectangle
+
+
+ Text
+ Sum
+
+
+ Vertical
+
+
+ 1
+
+ 255
+ 0
+ 0
+ 0
+
+ true
+
+
+ Left
+
+
+
+ 1
+
+ 255
+ 196
+ 196
+ 196
+
+ false
+
+ Across
+
+
+ 1
+
+ 255
+ 196
+ 196
+ 196
+
+ true
+
+
+
+
+
+ 1
+
+ 255
+ 225
+ 225
+ 225
+
+ false
+
+ Across
+
+
+ 1
+
+ 255
+ 225
+ 225
+ 225
+
+ false
+
+
+
+ 5
+
+
+ Min
+
+ 0.0
+
+
+ true
+ false
+
+
+
+
+
+
+
+ 255
+ 80
+ 166
+ 218
+
+
+ 255
+ 242
+ 88
+ 106
+
+
+ 255
+ 232
+ 172
+ 57
+
+
+ 255
+ 128
+ 255
+ 128
+
+
+ 255
+ 64
+ 128
+ 128
+
+
+ 255
+ 128
+ 128
+ 192
+
+
+ 255
+ 170
+ 85
+ 85
+
+
+ 255
+ 128
+ 128
+ 0
+
+
+ 255
+ 192
+ 192
+ 192
+
+
+ 255
+ 255
+ 255
+ 128
+
+
+ 255
+ 128
+ 192
+ 128
+
+
+ 255
+ 7
+ 146
+ 94
+
+
+ 255
+ 0
+ 128
+ 255
+
+
+ 255
+ 255
+ 128
+ 192
+
+
+ 255
+ 0
+ 255
+ 255
+
+
+ 255
+ 255
+ 128
+ 128
+
+
+ 255
+ 0
+ 128
+ 192
+
+
+ 255
+ 255
+ 0
+ 255
+
+
+ 255
+ 128
+ 64
+ 64
+
+
+ 255
+ 255
+ 128
+ 64
+
+
+ 255
+ 80
+ 240
+ 120
+
+
+ 255
+ 0
+ 64
+ 128
+
+
+ 255
+ 128
+ 0
+ 64
+
+
+ 255
+ 255
+ 0
+ 128
+
+
+ 255
+ 128
+ 128
+ 64
+
+
+ 255
+ 128
+ 128
+ 128
+
+
+ 255
+ 255
+ 128
+ 255
+
+
+ 255
+ 0
+ 64
+ 0
+
+
+ 255
+ 0
+ 0
+ 0
+
+
+ 255
+ 255
+ 255
+ 255
+
+
+ 255
+ 255
+ 128
+ 0
+
+
+
+ true
+
+
+ row["Student"]
+
+
+
+
+ Orthogonal_Value
+
+ ,
+
+ Outside
+ false
+
+
+ true
+ Text
+ Sum
+
+
+ Horizontal
+
+
+ 1
+
+ 255
+ 0
+ 0
+ 0
+
+ true
+
+
+ Below
+
+
+
+ 1
+
+ 255
+ 196
+ 196
+ 196
+
+ false
+
+ Across
+
+
+ 1
+
+ 255
+ 196
+ 196
+ 196
+
+ true
+
+
+
+
+
+ 1
+
+ 255
+ 225
+ 225
+ 225
+
+ false
+
+ Across
+
+
+ 1
+
+ 255
+ 225
+ 225
+ 225
+
+ false
+
+
+
+ 5
+
+
+ Min
+
+ 0.0
+
+
+ true
+ true
+ false
+
+ Vertical
+ 50.0
+
+
+ -20.0
+ 45.0
+ 0.0
+ None
+
+
+
+]]>
+ SVG
+ true
+ 286.125pt
+ 572.25pt
+ Data Set
+
+
+ Student
+ Student
+ dataSetRow["Student"]
+ string
+
+
+ Math
+ Math
+ dataSetRow["Math"]
+ integer
+
+
+ Geography
+ Geography
+ dataSetRow["Geography"]
+ integer
+
+
+ History
+ History
+ dataSetRow["History"]
+ integer
+
+
+
+ |
+
+
+
+ 2
+ 1
+
+ Data Set
+
+
+ Student
+ Student
+ dataSetRow["Student"]
+ string
+
+
+ Math
+ Math
+ dataSetRow["Math"]
+ integer
+
+
+ Geography
+ Geography
+ dataSetRow["Geography"]
+ integer
+
+
+ History
+ History
+ dataSetRow["History"]
+ integer
+
+
+
+
+
+
+
+
+
+
+ |
+
+
+ |
+
+
+ |
+
+
+ |
+
+
+
+
+
+
+ Student
+
+ |
+
+
+ Math
+
+ |
+
+
+ Geography
+
+ |
+
+
+ History
+
+ |
+
+
+
+
+ |
+
+
+
+
diff --git a/spring-boot-mvc-birt/reports/data.csv b/spring-boot-mvc-birt/reports/data.csv
new file mode 100644
index 0000000000..d05e58415e
--- /dev/null
+++ b/spring-boot-mvc-birt/reports/data.csv
@@ -0,0 +1,4 @@
+Student, Math, Geography, History
+Bill, 10,3,8
+Tom, 5,6,5
+Anne, 7, 4,9
\ No newline at end of file
diff --git a/spring-boot-mvc-birt/reports/static_report.rptdesign b/spring-boot-mvc-birt/reports/static_report.rptdesign
new file mode 100644
index 0000000000..d96ff76856
--- /dev/null
+++ b/spring-boot-mvc-birt/reports/static_report.rptdesign
@@ -0,0 +1,27 @@
+
+
+ Sample Report
+
+
+
+
+
+ 100%
+
+
+
+
+
+ url
+ "https://www.baeldung.com/wp-content/themes/baeldung/favicon/favicon-96x96.png"
+
+ |
+
+
+ |
+
+
+
+
diff --git a/spring-boot-mvc-birt/src/main/java/com/baeldung/birt/designer/ReportDesignApplication.java b/spring-boot-mvc-birt/src/main/java/com/baeldung/birt/designer/ReportDesignApplication.java
new file mode 100644
index 0000000000..f1e1619a58
--- /dev/null
+++ b/spring-boot-mvc-birt/src/main/java/com/baeldung/birt/designer/ReportDesignApplication.java
@@ -0,0 +1,93 @@
+package com.baeldung.birt.designer;
+
+import com.ibm.icu.util.ULocale;
+import org.apache.log4j.Logger;
+import org.eclipse.birt.core.exception.BirtException;
+import org.eclipse.birt.core.framework.Platform;
+import org.eclipse.birt.report.model.api.*;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.boot.WebApplicationType;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.builder.SpringApplicationBuilder;
+
+import java.io.File;
+import java.io.IOException;
+
+@SpringBootApplication
+public class ReportDesignApplication implements CommandLineRunner {
+
+ private static final Logger log = Logger.getLogger(ReportDesignApplication.class);
+
+ @Value("${reports.relative.path}")
+ private String REPORTS_FOLDER;
+
+ public static void main(String[] args) {
+ new SpringApplicationBuilder(ReportDesignApplication.class).web(WebApplicationType.NONE).build().run(args);
+ }
+
+ @Override public void run(String... args) throws Exception {
+ buildReport();
+ }
+
+ private void buildReport() throws IOException, BirtException {
+ final DesignConfig config = new DesignConfig();
+
+ final IDesignEngine engine;
+ try {
+ Platform.startup(config);
+ IDesignEngineFactory factory = (IDesignEngineFactory) Platform
+ .createFactoryObject(IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY);
+ engine = factory.createDesignEngine(config);
+
+ } catch (Exception ex) {
+ log.error("Exception during creation of DesignEngine", ex);
+ throw ex;
+ }
+
+ SessionHandle session = engine.newSessionHandle(ULocale.ENGLISH);
+
+ ReportDesignHandle design = session.createDesign();
+ design.setTitle("Sample Report");
+
+ // The element factory creates instances of the various BIRT elements.
+ ElementFactory factory = design.getElementFactory();
+
+ // Create a simple master page that describes how the report will
+ // appear when printed.
+ //
+ // Note: The report will fail to load in the BIRT designer
+ // unless you create a master page.
+
+ DesignElementHandle element = factory.newSimpleMasterPage("Page Master"); //$NON-NLS-1$
+ design.getMasterPages().add(element);
+
+ // Create a grid
+ GridHandle grid = factory.newGridItem(null, 2 /* cols */, 1 /* row */);
+ design.getBody().add(grid);
+ grid.setWidth("100%");
+
+ RowHandle row0 = (RowHandle) grid.getRows().get(0);
+
+ // Create an image and add it to the first cell.
+ ImageHandle image = factory.newImage(null);
+ CellHandle cell = (CellHandle) row0.getCells().get(0);
+ cell.getContent().add(image);
+ image.setURL("\"https://www.baeldung.com/wp-content/themes/baeldung/favicon/favicon-96x96.png\"");
+
+ // Create a label and add it to the second cell.
+ LabelHandle label = factory.newLabel(null);
+ cell = (CellHandle) row0.getCells().get(1);
+ cell.getContent().add(label);
+ label.setText("Hello, Baeldung world!");
+
+ // Save the design and close it.
+ File report = new File(REPORTS_FOLDER);
+ report.mkdirs();
+
+ design.saveAs(new File(report, "static_report.rptdesign").getAbsolutePath());
+ design.close();
+ log.info("Report generated");
+ }
+
+}
diff --git a/spring-boot-mvc-birt/src/main/java/com/baeldung/birt/engine/ReportEngineApplication.java b/spring-boot-mvc-birt/src/main/java/com/baeldung/birt/engine/ReportEngineApplication.java
new file mode 100644
index 0000000000..6d72017c9d
--- /dev/null
+++ b/spring-boot-mvc-birt/src/main/java/com/baeldung/birt/engine/ReportEngineApplication.java
@@ -0,0 +1,29 @@
+package com.baeldung.birt.engine;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.web.servlet.config.annotation.EnableWebMvc;
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+@SpringBootApplication
+@EnableWebMvc
+public class ReportEngineApplication implements WebMvcConfigurer {
+ @Value("${reports.relative.path}")
+ private String reportsPath;
+ @Value("${images.relative.path}")
+ private String imagesPath;
+
+ public static void main(final String[] args) {
+ SpringApplication.run(ReportEngineApplication.class, args);
+ }
+
+ @Override
+ public void addResourceHandlers(ResourceHandlerRegistry registry) {
+ registry
+ .addResourceHandler(reportsPath + imagesPath + "/**")
+ .addResourceLocations("file:///" + System.getProperty("user.dir") + "/" + reportsPath + imagesPath);
+ }
+
+}
\ No newline at end of file
diff --git a/spring-boot-mvc-birt/src/main/java/com/baeldung/birt/engine/controller/BirtReportController.java b/spring-boot-mvc-birt/src/main/java/com/baeldung/birt/engine/controller/BirtReportController.java
new file mode 100644
index 0000000000..e2405d02ec
--- /dev/null
+++ b/spring-boot-mvc-birt/src/main/java/com/baeldung/birt/engine/controller/BirtReportController.java
@@ -0,0 +1,51 @@
+package com.baeldung.birt.engine.controller;
+
+import com.baeldung.birt.engine.dto.OutputType;
+import com.baeldung.birt.engine.dto.Report;
+import com.baeldung.birt.engine.service.BirtReportService;
+import org.apache.log4j.Logger;
+import org.eclipse.birt.report.engine.api.EngineException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.List;
+
+@Controller
+public class BirtReportController {
+ private static final Logger log = Logger.getLogger(BirtReportController.class);
+
+ @Autowired
+ private BirtReportService reportService;
+
+ @RequestMapping(produces = "application/json", method = RequestMethod.GET, value = "/report")
+ @ResponseBody
+ public List listReports() {
+ return reportService.getReports();
+ }
+
+ @RequestMapping(produces = "application/json", method = RequestMethod.GET, value = "/report/reload")
+ @ResponseBody
+ public ResponseEntity reloadReports(HttpServletResponse response) {
+ try {
+ log.info("Reloading reports");
+ reportService.loadReports();
+ } catch (EngineException e) {
+ log.error("There was an error reloading the reports in memory: ", e);
+ return ResponseEntity.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR).build();
+ }
+ return ResponseEntity.ok().build();
+ }
+
+ @RequestMapping(method = RequestMethod.GET, value = "/report/{name}")
+ @ResponseBody
+ public void generateFullReport(HttpServletResponse response, HttpServletRequest request,
+ @PathVariable("name") String name, @RequestParam("output") String output) {
+ log.info("Generating full report: " + name + "; format: " + output);
+ OutputType format = OutputType.from(output);
+ reportService.generateMainReport(name, format, response, request);
+ }
+}
diff --git a/spring-boot-mvc-birt/src/main/java/com/baeldung/birt/engine/dto/OutputType.java b/spring-boot-mvc-birt/src/main/java/com/baeldung/birt/engine/dto/OutputType.java
new file mode 100644
index 0000000000..3180a347ba
--- /dev/null
+++ b/spring-boot-mvc-birt/src/main/java/com/baeldung/birt/engine/dto/OutputType.java
@@ -0,0 +1,21 @@
+package com.baeldung.birt.engine.dto;
+
+import org.eclipse.birt.report.engine.api.IRenderOption;
+
+public enum OutputType {
+ HTML(IRenderOption.OUTPUT_FORMAT_HTML),
+ PDF(IRenderOption.OUTPUT_FORMAT_PDF),
+ INVALID("invalid");
+
+ String val;
+ OutputType(String val) {
+ this.val = val;
+ }
+
+ public static OutputType from(String text) {
+ for (OutputType output : values()) {
+ if(output.val.equalsIgnoreCase(text)) return output;
+ }
+ return INVALID;
+ }
+}
diff --git a/spring-boot-mvc-birt/src/main/java/com/baeldung/birt/engine/dto/Report.java b/spring-boot-mvc-birt/src/main/java/com/baeldung/birt/engine/dto/Report.java
new file mode 100644
index 0000000000..a2d2444b80
--- /dev/null
+++ b/spring-boot-mvc-birt/src/main/java/com/baeldung/birt/engine/dto/Report.java
@@ -0,0 +1,37 @@
+package com.baeldung.birt.engine.dto;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.List;
+
+/**
+ * Report DTO class
+ */
+@Data
+@NoArgsConstructor
+public class Report {
+ private String title;
+ private String name;
+ private List parameters;
+
+ public Report(String title, String name) {
+ this.title = title;
+ this.name = name;
+ }
+
+ @Data
+ @NoArgsConstructor
+ @AllArgsConstructor
+ public static class Parameter {
+ private String title;
+ private String name;
+ private ParameterType type;
+
+ }
+
+ public enum ParameterType {
+ INT, STRING
+ }
+}
diff --git a/spring-boot-mvc-birt/src/main/java/com/baeldung/birt/engine/service/BirtReportService.java b/spring-boot-mvc-birt/src/main/java/com/baeldung/birt/engine/service/BirtReportService.java
new file mode 100644
index 0000000000..540bbbb530
--- /dev/null
+++ b/spring-boot-mvc-birt/src/main/java/com/baeldung/birt/engine/service/BirtReportService.java
@@ -0,0 +1,168 @@
+package com.baeldung.birt.engine.service;
+
+import com.baeldung.birt.engine.dto.OutputType;
+import com.baeldung.birt.engine.dto.Report;
+import org.eclipse.birt.core.exception.BirtException;
+import org.eclipse.birt.core.framework.Platform;
+import org.eclipse.birt.report.engine.api.*;
+import org.springframework.beans.factory.DisposableBean;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.core.io.ResourceLoader;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.PostConstruct;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+import java.util.*;
+
+@Service
+public class BirtReportService implements ApplicationContextAware, DisposableBean {
+ @Value("${reports.relative.path}")
+ private String reportsPath;
+ @Value("${images.relative.path}")
+ private String imagesPath;
+
+ private HTMLServerImageHandler htmlImageHandler = new HTMLServerImageHandler();
+
+ @Autowired
+ private ResourceLoader resourceLoader;
+ @Autowired
+ private ServletContext servletContext;
+
+ private IReportEngine birtEngine;
+ private ApplicationContext context;
+ private String imageFolder;
+
+ private Map reports = new HashMap<>();
+
+ @SuppressWarnings("unchecked")
+ @PostConstruct
+ protected void initialize() throws BirtException {
+ EngineConfig config = new EngineConfig();
+ config.getAppContext().put("spring", this.context);
+ Platform.startup(config);
+ IReportEngineFactory factory = (IReportEngineFactory) Platform
+ .createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
+ birtEngine = factory.createReportEngine(config);
+ imageFolder = System.getProperty("user.dir") + File.separatorChar + reportsPath + imagesPath;
+ loadReports();
+ }
+
+ @Override
+ public void setApplicationContext(ApplicationContext context) {
+ this.context = context;
+ }
+
+ /**
+ * Load report files to memory
+ *
+ */
+ public void loadReports() throws EngineException {
+ File folder = new File(reportsPath);
+ for (String file : Objects.requireNonNull(folder.list())) {
+ if (!file.endsWith(".rptdesign")) {
+ continue;
+ }
+
+ reports.put(file.replace(".rptdesign", ""),
+ birtEngine.openReportDesign(folder.getAbsolutePath() + File.separator + file));
+
+ }
+ }
+
+ public List getReports() {
+ List response = new ArrayList<>();
+ for (Map.Entry entry : reports.entrySet()) {
+ IReportRunnable report = reports.get(entry.getKey());
+ IGetParameterDefinitionTask task = birtEngine.createGetParameterDefinitionTask(report);
+ Report reportItem = new Report(report.getDesignHandle().getProperty("title").toString(), entry.getKey());
+ for (Object h : task.getParameterDefns(false)) {
+ IParameterDefn def = (IParameterDefn) h;
+ reportItem.getParameters()
+ .add(new Report.Parameter(def.getPromptText(), def.getName(), getParameterType(def)));
+ }
+ response.add(reportItem);
+ }
+ return response;
+ }
+
+ private Report.ParameterType getParameterType(IParameterDefn param) {
+ if (IParameterDefn.TYPE_INTEGER == param.getDataType()) {
+ return Report.ParameterType.INT;
+ }
+ return Report.ParameterType.STRING;
+ }
+
+ public void generateMainReport(String reportName, OutputType output, HttpServletResponse response, HttpServletRequest request) {
+ switch (output) {
+ case HTML:
+ generateHTMLReport(reports.get(reportName), response, request);
+ break;
+ case PDF:
+ generatePDFReport(reports.get(reportName), response, request);
+ break;
+ default:
+ throw new IllegalArgumentException("Output type not recognized:" + output);
+ }
+ }
+
+ /**
+ * Generate a report as HTML
+ */
+ @SuppressWarnings("unchecked")
+ private void generateHTMLReport(IReportRunnable report, HttpServletResponse response, HttpServletRequest request) {
+ IRunAndRenderTask runAndRenderTask = birtEngine.createRunAndRenderTask(report);
+ response.setContentType(birtEngine.getMIMEType("html"));
+ IRenderOption options = new RenderOption();
+ HTMLRenderOption htmlOptions = new HTMLRenderOption(options);
+ htmlOptions.setOutputFormat("html");
+ htmlOptions.setBaseImageURL("/" + reportsPath + imagesPath);
+ htmlOptions.setImageDirectory(imageFolder);
+ htmlOptions.setImageHandler(htmlImageHandler);
+ runAndRenderTask.setRenderOption(htmlOptions);
+ runAndRenderTask.getAppContext().put(EngineConstants.APPCONTEXT_BIRT_VIEWER_HTTPSERVET_REQUEST, request);
+
+ try {
+ htmlOptions.setOutputStream(response.getOutputStream());
+ runAndRenderTask.run();
+ } catch (Exception e) {
+ throw new RuntimeException(e.getMessage(), e);
+ } finally {
+ runAndRenderTask.close();
+ }
+ }
+
+ /**
+ * Generate a report as PDF
+ */
+ @SuppressWarnings("unchecked")
+ private void generatePDFReport(IReportRunnable report, HttpServletResponse response, HttpServletRequest request) {
+ IRunAndRenderTask runAndRenderTask = birtEngine.createRunAndRenderTask(report);
+ response.setContentType(birtEngine.getMIMEType("pdf"));
+ IRenderOption options = new RenderOption();
+ PDFRenderOption pdfRenderOption = new PDFRenderOption(options);
+ pdfRenderOption.setOutputFormat("pdf");
+ runAndRenderTask.setRenderOption(pdfRenderOption);
+ runAndRenderTask.getAppContext().put(EngineConstants.APPCONTEXT_PDF_RENDER_CONTEXT, request);
+
+ try {
+ pdfRenderOption.setOutputStream(response.getOutputStream());
+ runAndRenderTask.run();
+ } catch (Exception e) {
+ throw new RuntimeException(e.getMessage(), e);
+ } finally {
+ runAndRenderTask.close();
+ }
+ }
+
+ @Override
+ public void destroy() {
+ birtEngine.destroy();
+ Platform.shutdown();
+ }
+}
diff --git a/spring-boot-mvc-birt/src/main/resources/application.properties b/spring-boot-mvc-birt/src/main/resources/application.properties
new file mode 100644
index 0000000000..5b015c70b1
--- /dev/null
+++ b/spring-boot-mvc-birt/src/main/resources/application.properties
@@ -0,0 +1,2 @@
+reports.relative.path=reports/
+images.relative.path=images/
\ No newline at end of file
diff --git a/spring-boot/src/main/java/com/baeldung/environmentpostprocessor/PriceCalculationApplication.java b/spring-boot-ops/src/main/java/com/baeldung/environmentpostprocessor/PriceCalculationApplication.java
similarity index 96%
rename from spring-boot/src/main/java/com/baeldung/environmentpostprocessor/PriceCalculationApplication.java
rename to spring-boot-ops/src/main/java/com/baeldung/environmentpostprocessor/PriceCalculationApplication.java
index 01be08d6ae..ed912d8c0a 100644
--- a/spring-boot/src/main/java/com/baeldung/environmentpostprocessor/PriceCalculationApplication.java
+++ b/spring-boot-ops/src/main/java/com/baeldung/environmentpostprocessor/PriceCalculationApplication.java
@@ -35,7 +35,7 @@ public class PriceCalculationApplication implements CommandLineRunner {
int quantity = Integer.valueOf(params.get(1));
priceCalculationService.productTotalPrice(singlePrice, quantity);
} else {
- logger.error("Invalid arguments " + params.toString());
+ logger.warn("Invalid arguments " + params.toString());
}
}
diff --git a/spring-boot/src/main/java/com/baeldung/environmentpostprocessor/PriceCalculationEnvironmentPostProcessor.java b/spring-boot-ops/src/main/java/com/baeldung/environmentpostprocessor/PriceCalculationEnvironmentPostProcessor.java
similarity index 100%
rename from spring-boot/src/main/java/com/baeldung/environmentpostprocessor/PriceCalculationEnvironmentPostProcessor.java
rename to spring-boot-ops/src/main/java/com/baeldung/environmentpostprocessor/PriceCalculationEnvironmentPostProcessor.java
diff --git a/spring-boot/src/main/java/com/baeldung/environmentpostprocessor/autoconfig/PriceCalculationAutoConfig.java b/spring-boot-ops/src/main/java/com/baeldung/environmentpostprocessor/autoconfig/PriceCalculationAutoConfig.java
similarity index 100%
rename from spring-boot/src/main/java/com/baeldung/environmentpostprocessor/autoconfig/PriceCalculationAutoConfig.java
rename to spring-boot-ops/src/main/java/com/baeldung/environmentpostprocessor/autoconfig/PriceCalculationAutoConfig.java
diff --git a/spring-boot/src/main/java/com/baeldung/environmentpostprocessor/calculator/GrossPriceCalculator.java b/spring-boot-ops/src/main/java/com/baeldung/environmentpostprocessor/calculator/GrossPriceCalculator.java
similarity index 100%
rename from spring-boot/src/main/java/com/baeldung/environmentpostprocessor/calculator/GrossPriceCalculator.java
rename to spring-boot-ops/src/main/java/com/baeldung/environmentpostprocessor/calculator/GrossPriceCalculator.java
diff --git a/spring-boot/src/main/java/com/baeldung/environmentpostprocessor/calculator/NetPriceCalculator.java b/spring-boot-ops/src/main/java/com/baeldung/environmentpostprocessor/calculator/NetPriceCalculator.java
similarity index 100%
rename from spring-boot/src/main/java/com/baeldung/environmentpostprocessor/calculator/NetPriceCalculator.java
rename to spring-boot-ops/src/main/java/com/baeldung/environmentpostprocessor/calculator/NetPriceCalculator.java
diff --git a/spring-boot/src/main/java/com/baeldung/environmentpostprocessor/calculator/PriceCalculator.java b/spring-boot-ops/src/main/java/com/baeldung/environmentpostprocessor/calculator/PriceCalculator.java
similarity index 100%
rename from spring-boot/src/main/java/com/baeldung/environmentpostprocessor/calculator/PriceCalculator.java
rename to spring-boot-ops/src/main/java/com/baeldung/environmentpostprocessor/calculator/PriceCalculator.java
diff --git a/spring-boot/src/main/java/com/baeldung/environmentpostprocessor/service/PriceCalculationService.java b/spring-boot-ops/src/main/java/com/baeldung/environmentpostprocessor/service/PriceCalculationService.java
similarity index 100%
rename from spring-boot/src/main/java/com/baeldung/environmentpostprocessor/service/PriceCalculationService.java
rename to spring-boot-ops/src/main/java/com/baeldung/environmentpostprocessor/service/PriceCalculationService.java
diff --git a/spring-boot-ops/src/main/resources/META-INF/spring.factories b/spring-boot-ops/src/main/resources/META-INF/spring.factories
new file mode 100644
index 0000000000..c36b67f8d7
--- /dev/null
+++ b/spring-boot-ops/src/main/resources/META-INF/spring.factories
@@ -0,0 +1,6 @@
+org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
+com.baeldung.environmentpostprocessor.autoconfig.PriceCalculationAutoConfig
+
+org.springframework.boot.env.EnvironmentPostProcessor=\
+com.baeldung.environmentpostprocessor.PriceCalculationEnvironmentPostProcessor
+
diff --git a/spring-boot/src/test/java/com/baeldung/environmentpostprocessor/PriceCalculationEnvironmentPostProcessorLiveTest.java b/spring-boot-ops/src/test/java/com/baeldung/environmentpostprocessor/PriceCalculationEnvironmentPostProcessorLiveTest.java
similarity index 100%
rename from spring-boot/src/test/java/com/baeldung/environmentpostprocessor/PriceCalculationEnvironmentPostProcessorLiveTest.java
rename to spring-boot-ops/src/test/java/com/baeldung/environmentpostprocessor/PriceCalculationEnvironmentPostProcessorLiveTest.java
diff --git a/spring-boot-rest/README.md b/spring-boot-rest/README.md
index af372077f0..5b7bbdac60 100644
--- a/spring-boot-rest/README.md
+++ b/spring-boot-rest/README.md
@@ -1,13 +1,18 @@
Module for the articles that are part of the Spring REST E-book:
1. [Bootstrap a Web Application with Spring 5](https://www.baeldung.com/bootstraping-a-web-application-with-spring-and-java-based-configuration)
-2. [Error Handling for REST with Spring](http://www.baeldung.com/exception-handling-for-rest-with-spring)
-3. [REST Pagination in Spring](http://www.baeldung.com/rest-api-pagination-in-spring)
-4. [Build a REST API with Spring and Java Config](http://www.baeldung.com/building-a-restful-web-service-with-spring-and-java-based-configuration)
-5. [HATEOAS for a Spring REST Service](http://www.baeldung.com/rest-api-discoverability-with-spring)
-6. [REST API Discoverability and HATEOAS](http://www.baeldung.com/restful-web-service-discoverability)
-7. [Versioning a REST API](http://www.baeldung.com/rest-versioning)
-8. [Http Message Converters with the Spring Framework](http://www.baeldung.com/spring-httpmessageconverter-rest)
-9. [ETags for REST with Spring](http://www.baeldung.com/etags-for-rest-with-spring)
-10. [Testing REST with multiple MIME types](http://www.baeldung.com/testing-rest-api-with-multiple-media-types)
-11. [Testing Web APIs with Postman Collections](https://www.baeldung.com/postman-testing-collections)
+2. [Build a REST API with Spring and Java Config](http://www.baeldung.com/building-a-restful-web-service-with-spring-and-java-based-configuration)
+3. [Http Message Converters with the Spring Framework](http://www.baeldung.com/spring-httpmessageconverter-rest)
+4. [Spring’s RequestBody and ResponseBody Annotations](https://www.baeldung.com/spring-request-response-body)
+5. [Entity To DTO Conversion for a Spring REST API](https://www.baeldung.com/entity-to-and-from-dto-for-a-java-spring-application)
+6. [Error Handling for REST with Spring](http://www.baeldung.com/exception-handling-for-rest-with-spring)
+7. [REST API Discoverability and HATEOAS](http://www.baeldung.com/restful-web-service-discoverability)
+8.
+9. [REST Pagination in Spring](http://www.baeldung.com/rest-api-pagination-in-spring)
+10. [Test a REST API with Java](http://www.baeldung.com/integration-testing-a-rest-api)
+
+- [HATEOAS for a Spring REST Service](http://www.baeldung.com/rest-api-discoverability-with-spring)
+- [Versioning a REST API](http://www.baeldung.com/rest-versioning)
+- [ETags for REST with Spring](http://www.baeldung.com/etags-for-rest-with-spring)
+- [Testing REST with multiple MIME types](http://www.baeldung.com/testing-rest-api-with-multiple-media-types)
+- [Testing Web APIs with Postman Collections](https://www.baeldung.com/postman-testing-collections)
diff --git a/spring-boot-rest/pom.xml b/spring-boot-rest/pom.xml
index decaccd148..2bf7c0181f 100644
--- a/spring-boot-rest/pom.xml
+++ b/spring-boot-rest/pom.xml
@@ -63,6 +63,11 @@
htmlunit
test
+
+ org.modelmapper
+ modelmapper
+ ${modelmapper.version}
+
@@ -78,5 +83,6 @@
com.baeldung.SpringBootRestApplication
27.0.1-jre
1.4.11.1
+ 2.3.3
diff --git a/spring-boot-rest/src/main/java/com/baeldung/SpringBootRestApplication.java b/spring-boot-rest/src/main/java/com/baeldung/SpringBootRestApplication.java
index 62aae7619d..1c0d0d19e8 100644
--- a/spring-boot-rest/src/main/java/com/baeldung/SpringBootRestApplication.java
+++ b/spring-boot-rest/src/main/java/com/baeldung/SpringBootRestApplication.java
@@ -1,7 +1,9 @@
package com.baeldung;
+import org.modelmapper.ModelMapper;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.Bean;
@SpringBootApplication
public class SpringBootRestApplication {
@@ -9,5 +11,10 @@ public class SpringBootRestApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootRestApplication.class, args);
}
+
+ @Bean
+ public ModelMapper modelMapper() {
+ return new ModelMapper();
+ }
}
diff --git a/spring-boot/src/main/java/com/baeldung/modelmapper/controller/PostRestController.java b/spring-boot-rest/src/main/java/com/baeldung/modelmapper/controller/PostRestController.java
similarity index 100%
rename from spring-boot/src/main/java/com/baeldung/modelmapper/controller/PostRestController.java
rename to spring-boot-rest/src/main/java/com/baeldung/modelmapper/controller/PostRestController.java
diff --git a/spring-boot/src/main/java/com/baeldung/modelmapper/dto/PostDto.java b/spring-boot-rest/src/main/java/com/baeldung/modelmapper/dto/PostDto.java
similarity index 100%
rename from spring-boot/src/main/java/com/baeldung/modelmapper/dto/PostDto.java
rename to spring-boot-rest/src/main/java/com/baeldung/modelmapper/dto/PostDto.java
diff --git a/spring-boot/src/main/java/com/baeldung/modelmapper/dto/UserDto.java b/spring-boot-rest/src/main/java/com/baeldung/modelmapper/dto/UserDto.java
similarity index 100%
rename from spring-boot/src/main/java/com/baeldung/modelmapper/dto/UserDto.java
rename to spring-boot-rest/src/main/java/com/baeldung/modelmapper/dto/UserDto.java
diff --git a/spring-boot/src/main/java/com/baeldung/modelmapper/model/Post.java b/spring-boot-rest/src/main/java/com/baeldung/modelmapper/model/Post.java
similarity index 100%
rename from spring-boot/src/main/java/com/baeldung/modelmapper/model/Post.java
rename to spring-boot-rest/src/main/java/com/baeldung/modelmapper/model/Post.java
diff --git a/spring-boot/src/main/java/com/baeldung/modelmapper/model/Preference.java b/spring-boot-rest/src/main/java/com/baeldung/modelmapper/model/Preference.java
similarity index 100%
rename from spring-boot/src/main/java/com/baeldung/modelmapper/model/Preference.java
rename to spring-boot-rest/src/main/java/com/baeldung/modelmapper/model/Preference.java
diff --git a/spring-boot/src/main/java/com/baeldung/modelmapper/model/User.java b/spring-boot-rest/src/main/java/com/baeldung/modelmapper/model/User.java
similarity index 100%
rename from spring-boot/src/main/java/com/baeldung/modelmapper/model/User.java
rename to spring-boot-rest/src/main/java/com/baeldung/modelmapper/model/User.java
diff --git a/spring-boot/src/main/java/com/baeldung/modelmapper/repository/PostRepository.java b/spring-boot-rest/src/main/java/com/baeldung/modelmapper/repository/PostRepository.java
similarity index 100%
rename from spring-boot/src/main/java/com/baeldung/modelmapper/repository/PostRepository.java
rename to spring-boot-rest/src/main/java/com/baeldung/modelmapper/repository/PostRepository.java
diff --git a/spring-boot/src/main/java/com/baeldung/modelmapper/service/IPostService.java b/spring-boot-rest/src/main/java/com/baeldung/modelmapper/service/IPostService.java
similarity index 100%
rename from spring-boot/src/main/java/com/baeldung/modelmapper/service/IPostService.java
rename to spring-boot-rest/src/main/java/com/baeldung/modelmapper/service/IPostService.java
diff --git a/spring-boot/src/main/java/com/baeldung/modelmapper/service/IUserService.java b/spring-boot-rest/src/main/java/com/baeldung/modelmapper/service/IUserService.java
similarity index 100%
rename from spring-boot/src/main/java/com/baeldung/modelmapper/service/IUserService.java
rename to spring-boot-rest/src/main/java/com/baeldung/modelmapper/service/IUserService.java
diff --git a/spring-boot/src/main/java/com/baeldung/modelmapper/service/PostService.java b/spring-boot-rest/src/main/java/com/baeldung/modelmapper/service/PostService.java
similarity index 100%
rename from spring-boot/src/main/java/com/baeldung/modelmapper/service/PostService.java
rename to spring-boot-rest/src/main/java/com/baeldung/modelmapper/service/PostService.java
diff --git a/spring-boot/src/main/java/com/baeldung/modelmapper/service/UserService.java b/spring-boot-rest/src/main/java/com/baeldung/modelmapper/service/UserService.java
similarity index 100%
rename from spring-boot/src/main/java/com/baeldung/modelmapper/service/UserService.java
rename to spring-boot-rest/src/main/java/com/baeldung/modelmapper/service/UserService.java
diff --git a/spring-rest/src/main/java/com/baeldung/services/ExampleService.java b/spring-boot-rest/src/main/java/com/baeldung/services/ExampleService.java
similarity index 100%
rename from spring-rest/src/main/java/com/baeldung/services/ExampleService.java
rename to spring-boot-rest/src/main/java/com/baeldung/services/ExampleService.java
diff --git a/spring-boot-rest/src/main/java/com/baeldung/spring/PersistenceConfig.java b/spring-boot-rest/src/main/java/com/baeldung/spring/PersistenceConfig.java
index 5179c66978..2e967751ad 100644
--- a/spring-boot-rest/src/main/java/com/baeldung/spring/PersistenceConfig.java
+++ b/spring-boot-rest/src/main/java/com/baeldung/spring/PersistenceConfig.java
@@ -24,8 +24,8 @@ import com.google.common.base.Preconditions;
@Configuration
@EnableTransactionManagement
@PropertySource({ "classpath:persistence-${envTarget:h2}.properties" })
-@ComponentScan({ "com.baeldung.persistence" })
-@EnableJpaRepositories(basePackages = "com.baeldung.persistence.dao")
+@ComponentScan(basePackages = { "com.baeldung.persistence", "com.baeldung.modelmapper" })
+@EnableJpaRepositories(basePackages = {"com.baeldung.persistence.dao", "com.baeldung.modelmapper.repository"})
public class PersistenceConfig {
@Autowired
@@ -39,7 +39,7 @@ public class PersistenceConfig {
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource());
- em.setPackagesToScan(new String[] { "com.baeldung.persistence.model" });
+ em.setPackagesToScan(new String[] { "com.baeldung.persistence.model", "com.baeldung.modelmapper.model" });
final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
// vendorAdapter.set
diff --git a/spring-boot-rest/src/main/java/com/baeldung/transfer/LoginForm.java b/spring-boot-rest/src/main/java/com/baeldung/transfer/LoginForm.java
new file mode 100644
index 0000000000..caafcdb500
--- /dev/null
+++ b/spring-boot-rest/src/main/java/com/baeldung/transfer/LoginForm.java
@@ -0,0 +1,31 @@
+package com.baeldung.transfer;
+
+public class LoginForm {
+ private String username;
+ private String password;
+
+ public LoginForm() {
+ }
+
+ public LoginForm(String username, String password) {
+ super();
+ this.username = username;
+ this.password = password;
+ }
+
+ 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-rest/src/main/java/com/baeldung/transfer/ResponseTransfer.java b/spring-boot-rest/src/main/java/com/baeldung/transfer/ResponseTransfer.java
similarity index 100%
rename from spring-rest/src/main/java/com/baeldung/transfer/ResponseTransfer.java
rename to spring-boot-rest/src/main/java/com/baeldung/transfer/ResponseTransfer.java
diff --git a/spring-rest/src/main/java/com/baeldung/controllers/ExamplePostController.java b/spring-boot-rest/src/main/java/com/baeldung/web/controller/ExamplePostController.java
similarity index 97%
rename from spring-rest/src/main/java/com/baeldung/controllers/ExamplePostController.java
rename to spring-boot-rest/src/main/java/com/baeldung/web/controller/ExamplePostController.java
index 93f96756b4..1519d95d4d 100644
--- a/spring-rest/src/main/java/com/baeldung/controllers/ExamplePostController.java
+++ b/spring-boot-rest/src/main/java/com/baeldung/web/controller/ExamplePostController.java
@@ -1,4 +1,4 @@
-package com.baeldung.controllers;
+package com.baeldung.web.controller;
import com.baeldung.services.ExampleService;
import com.baeldung.transfer.ResponseTransfer;
diff --git a/spring-boot-rest/src/test/java/com/baeldung/SpringContextIntegrationTest.java b/spring-boot-rest/src/test/java/com/baeldung/SpringContextIntegrationTest.java
index 25fbc4cc02..3db1ecb462 100644
--- a/spring-boot-rest/src/test/java/com/baeldung/SpringContextIntegrationTest.java
+++ b/spring-boot-rest/src/test/java/com/baeldung/SpringContextIntegrationTest.java
@@ -6,7 +6,7 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
-@SpringBootTest
+@SpringBootTest(classes = {SpringBootRestApplication.class})
public class SpringContextIntegrationTest {
@Test
diff --git a/spring-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerRequestIntegrationTest.java b/spring-boot-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerRequestIntegrationTest.java
similarity index 92%
rename from spring-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerRequestIntegrationTest.java
rename to spring-boot-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerRequestIntegrationTest.java
index 94b8bf40e7..fc533072c8 100644
--- a/spring-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerRequestIntegrationTest.java
+++ b/spring-boot-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerRequestIntegrationTest.java
@@ -1,8 +1,10 @@
package com.baeldung.controllers;
-import com.baeldung.sampleapp.config.MainApplication;
-import com.baeldung.services.ExampleService;
-import com.baeldung.transfer.LoginForm;
+import static org.mockito.Mockito.when;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
+import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -14,13 +16,13 @@ import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
-import static org.mockito.Mockito.when;
-import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
-import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
-import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+import com.baeldung.SpringBootRestApplication;
+import com.baeldung.services.ExampleService;
+import com.baeldung.transfer.LoginForm;
+import com.baeldung.web.controller.ExamplePostController;
@RunWith(SpringRunner.class)
-@SpringBootTest(classes = MainApplication.class)
+@SpringBootTest(classes = SpringBootRestApplication.class)
public class ExamplePostControllerRequestIntegrationTest {
MockMvc mockMvc;
diff --git a/spring-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerResponseIntegrationTest.java b/spring-boot-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerResponseIntegrationTest.java
similarity index 92%
rename from spring-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerResponseIntegrationTest.java
rename to spring-boot-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerResponseIntegrationTest.java
index 5743ad450b..cbe21b1d90 100644
--- a/spring-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerResponseIntegrationTest.java
+++ b/spring-boot-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerResponseIntegrationTest.java
@@ -1,8 +1,11 @@
package com.baeldung.controllers;
-import com.baeldung.sampleapp.config.MainApplication;
-import com.baeldung.services.ExampleService;
-import com.baeldung.transfer.LoginForm;
+import static org.mockito.Mockito.when;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
+import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -11,18 +14,16 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
-
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
-import static org.mockito.Mockito.when;
-import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
-import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
-import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
-import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+import com.baeldung.SpringBootRestApplication;
+import com.baeldung.services.ExampleService;
+import com.baeldung.transfer.LoginForm;
+import com.baeldung.web.controller.ExamplePostController;
@RunWith(SpringRunner.class)
-@SpringBootTest(classes = MainApplication.class)
+@SpringBootTest(classes = SpringBootRestApplication.class)
public class ExamplePostControllerResponseIntegrationTest {
MockMvc mockMvc;
diff --git a/spring-boot/src/test/java/com/baeldung/modelmapper/PostDtoUnitTest.java b/spring-boot-rest/src/test/java/com/baeldung/modelmapper/PostDtoUnitTest.java
similarity index 100%
rename from spring-boot/src/test/java/com/baeldung/modelmapper/PostDtoUnitTest.java
rename to spring-boot-rest/src/test/java/com/baeldung/modelmapper/PostDtoUnitTest.java
diff --git a/spring-boot-rest/src/test/java/com/baeldung/rest/GitHubUser.java b/spring-boot-rest/src/test/java/com/baeldung/rest/GitHubUser.java
new file mode 100644
index 0000000000..da5085ab12
--- /dev/null
+++ b/spring-boot-rest/src/test/java/com/baeldung/rest/GitHubUser.java
@@ -0,0 +1,21 @@
+package com.baeldung.rest;
+
+public class GitHubUser {
+
+ private String login;
+
+ public GitHubUser() {
+ super();
+ }
+
+ // API
+
+ public String getLogin() {
+ return login;
+ }
+
+ public void setLogin(final String login) {
+ this.login = login;
+ }
+
+}
diff --git a/testing-modules/rest-testing/src/test/java/org/baeldung/rest/GithubBasicLiveTest.java b/spring-boot-rest/src/test/java/com/baeldung/rest/GithubBasicLiveTest.java
similarity index 98%
rename from testing-modules/rest-testing/src/test/java/org/baeldung/rest/GithubBasicLiveTest.java
rename to spring-boot-rest/src/test/java/com/baeldung/rest/GithubBasicLiveTest.java
index acac82c8f4..3082b34421 100644
--- a/testing-modules/rest-testing/src/test/java/org/baeldung/rest/GithubBasicLiveTest.java
+++ b/spring-boot-rest/src/test/java/com/baeldung/rest/GithubBasicLiveTest.java
@@ -1,4 +1,4 @@
-package org.baeldung.rest;
+package com.baeldung.rest;
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
import static org.hamcrest.Matchers.equalTo;
diff --git a/spring-boot-rest/src/test/java/com/baeldung/rest/RetrieveUtil.java b/spring-boot-rest/src/test/java/com/baeldung/rest/RetrieveUtil.java
new file mode 100644
index 0000000000..0ec36bc3ae
--- /dev/null
+++ b/spring-boot-rest/src/test/java/com/baeldung/rest/RetrieveUtil.java
@@ -0,0 +1,21 @@
+package com.baeldung.rest;
+
+import java.io.IOException;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.util.EntityUtils;
+
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+public class RetrieveUtil {
+
+ // API
+
+ public static T retrieveResourceFromResponse(final HttpResponse response, final Class clazz) throws IOException {
+ final String jsonFromResponse = EntityUtils.toString(response.getEntity());
+ final ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ return mapper.readValue(jsonFromResponse, clazz);
+ }
+
+}
diff --git a/spring-boot-security/src/main/java/com/baeldung/integrationtesting/WebSecurityConfigurer.java b/spring-boot-security/src/main/java/com/baeldung/integrationtesting/WebSecurityConfigurer.java
index 16ce8e6fc6..1437440668 100644
--- a/spring-boot-security/src/main/java/com/baeldung/integrationtesting/WebSecurityConfigurer.java
+++ b/spring-boot-security/src/main/java/com/baeldung/integrationtesting/WebSecurityConfigurer.java
@@ -1,18 +1,24 @@
package com.baeldung.integrationtesting;
+import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
@Configuration
public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
+
+ BCryptPasswordEncoder encoder = passwordEncoder();
+
auth.inMemoryAuthentication()
+ .passwordEncoder(encoder)
.withUser("spring")
- .password("{noop}secret")
+ .password(encoder.encode("secret"))
.roles("USER");
}
@@ -27,5 +33,8 @@ public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter {
.httpBasic();
}
-
+ @Bean
+ public BCryptPasswordEncoder passwordEncoder() {
+ return new BCryptPasswordEncoder();
+ }
}
diff --git a/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2server/config/AuthenticationMananagerConfig.java b/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2server/config/AuthenticationMananagerConfig.java
new file mode 100644
index 0000000000..2b4135f36d
--- /dev/null
+++ b/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2server/config/AuthenticationMananagerConfig.java
@@ -0,0 +1,18 @@
+package com.baeldung.springbootsecurity.oauth2server.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Profile;
+import org.springframework.security.authentication.AuthenticationManager;
+import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
+
+@Configuration
+@Profile("authz")
+public class AuthenticationMananagerConfig extends WebSecurityConfigurerAdapter {
+
+ @Bean
+ @Override
+ public AuthenticationManager authenticationManagerBean() throws Exception {
+ return super.authenticationManagerBean();
+ }
+}
\ No newline at end of file
diff --git a/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2server/config/AuthorizationServerConfig.java b/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2server/config/AuthorizationServerConfig.java
index 4686100638..6e21987a89 100644
--- a/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2server/config/AuthorizationServerConfig.java
+++ b/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2server/config/AuthorizationServerConfig.java
@@ -1,9 +1,11 @@
package com.baeldung.springbootsecurity.oauth2server.config;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.security.authentication.AuthenticationManager;
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
@@ -25,15 +27,20 @@ public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdap
clients
.inMemory()
.withClient("baeldung")
- .secret("{noop}baeldung")
+ .secret(passwordEncoder().encode("baeldung"))
.authorizedGrantTypes("client_credentials", "password", "authorization_code")
.scopes("openid", "read")
.autoApprove(true)
.and()
.withClient("baeldung-admin")
- .secret("{noop}baeldung")
+ .secret(passwordEncoder().encode("baeldung"))
.authorizedGrantTypes("authorization_code", "client_credentials", "refresh_token")
.scopes("read", "write")
.autoApprove(true);
}
+
+ @Bean
+ public BCryptPasswordEncoder passwordEncoder() {
+ return new BCryptPasswordEncoder();
+ }
}
diff --git a/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2server/config/WebSecurityConfiguration.java b/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2server/config/WebSecurityConfiguration.java
index f2540c01b8..3a8c073870 100644
--- a/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2server/config/WebSecurityConfiguration.java
+++ b/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2server/config/WebSecurityConfiguration.java
@@ -2,10 +2,12 @@ package com.baeldung.springbootsecurity.oauth2server.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Profile;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@Configuration
+@Profile("!authz")
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
@Bean
diff --git a/spring-boot-security/src/main/java/com/baeldung/springsecuritytaglibs/config/SpringBootSecurityTagLibsConfig.java b/spring-boot-security/src/main/java/com/baeldung/springsecuritytaglibs/config/SpringBootSecurityTagLibsConfig.java
index 59ae2885ad..75bc613bd1 100644
--- a/spring-boot-security/src/main/java/com/baeldung/springsecuritytaglibs/config/SpringBootSecurityTagLibsConfig.java
+++ b/spring-boot-security/src/main/java/com/baeldung/springsecuritytaglibs/config/SpringBootSecurityTagLibsConfig.java
@@ -1,10 +1,12 @@
package com.baeldung.springsecuritytaglibs.config;
+import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
@Configuration
@EnableWebSecurity
@@ -12,9 +14,11 @@ public class SpringBootSecurityTagLibsConfig extends WebSecurityConfigurerAdapte
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
+ BCryptPasswordEncoder encoder = passwordEncoder();
auth.inMemoryAuthentication()
+ .passwordEncoder(encoder)
.withUser("testUser")
- .password("{noop}password")
+ .password(encoder.encode("password"))
.roles("ADMIN");
}
@@ -28,4 +32,9 @@ public class SpringBootSecurityTagLibsConfig extends WebSecurityConfigurerAdapte
.anyRequest().permitAll().and().httpBasic();
// @formatter:on
}
+
+ @Bean
+ public BCryptPasswordEncoder passwordEncoder() {
+ return new BCryptPasswordEncoder();
+ }
}
\ No newline at end of file
diff --git a/spring-boot-security/src/test/java/com/baeldung/springbootsecurity/basic_auth/BasicAuthConfigurationIntegrationTest.java b/spring-boot-security/src/test/java/com/baeldung/springbootsecurity/basic_auth/BasicAuthConfigurationIntegrationTest.java
index dd9c511361..c091aa6d75 100644
--- a/spring-boot-security/src/test/java/com/baeldung/springbootsecurity/basic_auth/BasicAuthConfigurationIntegrationTest.java
+++ b/spring-boot-security/src/test/java/com/baeldung/springbootsecurity/basic_auth/BasicAuthConfigurationIntegrationTest.java
@@ -16,6 +16,7 @@ import java.net.MalformedURLException;
import java.net.URL;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
@RunWith(SpringRunner.class)
@@ -49,6 +50,6 @@ public class BasicAuthConfigurationIntegrationTest {
ResponseEntity response = restTemplate.getForEntity(base.toString(), String.class);
assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());
- Assert.assertNull(response.getBody());
+ assertNull(response.getBody());
}
}
diff --git a/spring-boot-testing/pom.xml b/spring-boot-testing/pom.xml
index caf48276b6..84107070bd 100644
--- a/spring-boot-testing/pom.xml
+++ b/spring-boot-testing/pom.xml
@@ -101,7 +101,7 @@
org.codehaus.gmavenplus
gmavenplus-plugin
- 1.6
+ ${gmavenplus-plugin.version}
@@ -119,6 +119,7 @@
com.baeldung.boot.Application
2.2.4
1.2-groovy-2.4
+ 1.6
diff --git a/spring-boot-testing/src/main/java/com/baeldung/component/OtherComponent.java b/spring-boot-testing/src/main/java/com/baeldung/component/OtherComponent.java
new file mode 100644
index 0000000000..97f001a9e5
--- /dev/null
+++ b/spring-boot-testing/src/main/java/com/baeldung/component/OtherComponent.java
@@ -0,0 +1,19 @@
+package com.baeldung.component;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+@Component
+public class OtherComponent {
+
+ private static final Logger LOG = LoggerFactory.getLogger(OtherComponent.class);
+
+ public void processData() {
+ LOG.trace("This is a TRACE log from another package");
+ LOG.debug("This is a DEBUG log from another package");
+ LOG.info("This is an INFO log from another package");
+ LOG.error("This is an ERROR log from another package");
+ }
+
+}
diff --git a/spring-boot-testing/src/main/java/com/baeldung/testloglevel/TestLogLevelApplication.java b/spring-boot-testing/src/main/java/com/baeldung/testloglevel/TestLogLevelApplication.java
new file mode 100644
index 0000000000..ed8218c6a3
--- /dev/null
+++ b/spring-boot-testing/src/main/java/com/baeldung/testloglevel/TestLogLevelApplication.java
@@ -0,0 +1,15 @@
+package com.baeldung.testloglevel;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+import com.baeldung.boot.Application;
+
+@SpringBootApplication(scanBasePackages = {"com.baeldung.testloglevel", "com.baeldung.component"})
+public class TestLogLevelApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(Application.class, args);
+ }
+
+}
diff --git a/spring-boot-testing/src/main/java/com/baeldung/testloglevel/TestLogLevelController.java b/spring-boot-testing/src/main/java/com/baeldung/testloglevel/TestLogLevelController.java
new file mode 100644
index 0000000000..22078562b4
--- /dev/null
+++ b/spring-boot-testing/src/main/java/com/baeldung/testloglevel/TestLogLevelController.java
@@ -0,0 +1,31 @@
+package com.baeldung.testloglevel;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import com.baeldung.component.OtherComponent;
+
+@RestController
+public class TestLogLevelController {
+
+ private static final Logger LOG = LoggerFactory.getLogger(TestLogLevelController.class);
+
+ @Autowired
+ private OtherComponent otherComponent;
+
+ @GetMapping("/testLogLevel")
+ public String testLogLevel() {
+ LOG.trace("This is a TRACE log");
+ LOG.debug("This is a DEBUG log");
+ LOG.info("This is an INFO log");
+ LOG.error("This is an ERROR log");
+
+ otherComponent.processData();
+
+ return "Added some log output to console...";
+ }
+
+}
diff --git a/spring-boot-testing/src/test/java/com/baeldung/testloglevel/LogbackMultiProfileTestLogLevelIntegrationTest.java b/spring-boot-testing/src/test/java/com/baeldung/testloglevel/LogbackMultiProfileTestLogLevelIntegrationTest.java
new file mode 100644
index 0000000000..7a1eb4adbe
--- /dev/null
+++ b/spring-boot-testing/src/test/java/com/baeldung/testloglevel/LogbackMultiProfileTestLogLevelIntegrationTest.java
@@ -0,0 +1,70 @@
+package com.baeldung.testloglevel;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
+import org.springframework.boot.test.rule.OutputCapture;
+import org.springframework.boot.test.web.client.TestRestTemplate;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = TestLogLevelApplication.class)
+@EnableAutoConfiguration(exclude = SecurityAutoConfiguration.class)
+@ActiveProfiles("logback-test2")
+public class LogbackMultiProfileTestLogLevelIntegrationTest {
+
+ @Autowired
+ private TestRestTemplate restTemplate;
+
+ @Rule
+ public OutputCapture outputCapture = new OutputCapture();
+
+ private String baseUrl = "/testLogLevel";
+
+ @Test
+ public void givenErrorRootLevelAndTraceLevelForOurPackage_whenCall_thenPrintTraceLogsForOurPackage() {
+ ResponseEntity response = restTemplate.getForEntity(baseUrl, String.class);
+
+ assertThat(response.getStatusCode().value()).isEqualTo(200);
+ assertThatOutputContainsLogForOurPackage("TRACE");
+ }
+
+ @Test
+ public void givenErrorRootLevelAndTraceLevelForOurPackage_whenCall_thenNoTraceLogsForOtherPackages() {
+ ResponseEntity response = restTemplate.getForEntity(baseUrl, String.class);
+
+ assertThat(response.getStatusCode().value()).isEqualTo(200);
+ assertThatOutputDoesntContainLogForOtherPackages("TRACE");
+ }
+
+ @Test
+ public void givenErrorRootLevelAndTraceLevelForOurPackage_whenCall_thenPrintErrorLogs() {
+ ResponseEntity response = restTemplate.getForEntity(baseUrl, String.class);
+
+ assertThat(response.getStatusCode().value()).isEqualTo(200);
+ assertThatOutputContainsLogForOurPackage("ERROR");
+ assertThatOutputContainsLogForOtherPackages("ERROR");
+ }
+
+ private void assertThatOutputContainsLogForOurPackage(String level) {
+ assertThat(outputCapture.toString()).containsPattern("TestLogLevelController.*" + level + ".*");
+ }
+
+ private void assertThatOutputDoesntContainLogForOtherPackages(String level) {
+ assertThat(outputCapture.toString().replaceAll("(?m)^.*TestLogLevelController.*$", "")).doesNotContain(level);
+ }
+
+ private void assertThatOutputContainsLogForOtherPackages(String level) {
+ assertThat(outputCapture.toString().replaceAll("(?m)^.*TestLogLevelController.*$", "")).contains(level);
+ }
+
+}
diff --git a/spring-boot-testing/src/test/java/com/baeldung/testloglevel/LogbackTestLogLevelIntegrationTest.java b/spring-boot-testing/src/test/java/com/baeldung/testloglevel/LogbackTestLogLevelIntegrationTest.java
new file mode 100644
index 0000000000..af3bafdc2e
--- /dev/null
+++ b/spring-boot-testing/src/test/java/com/baeldung/testloglevel/LogbackTestLogLevelIntegrationTest.java
@@ -0,0 +1,70 @@
+package com.baeldung.testloglevel;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
+import org.springframework.boot.test.rule.OutputCapture;
+import org.springframework.boot.test.web.client.TestRestTemplate;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = TestLogLevelApplication.class)
+@EnableAutoConfiguration(exclude = SecurityAutoConfiguration.class)
+@ActiveProfiles("logback-test")
+public class LogbackTestLogLevelIntegrationTest {
+
+ @Autowired
+ private TestRestTemplate restTemplate;
+
+ @Rule
+ public OutputCapture outputCapture = new OutputCapture();
+
+ private String baseUrl = "/testLogLevel";
+
+ @Test
+ public void givenErrorRootLevelAndDebugLevelForOurPackage_whenCall_thenPrintDebugLogsForOurPackage() {
+ ResponseEntity response = restTemplate.getForEntity(baseUrl, String.class);
+
+ assertThat(response.getStatusCode().value()).isEqualTo(200);
+ assertThatOutputContainsLogForOurPackage("DEBUG");
+ }
+
+ @Test
+ public void givenErrorRootLevelAndDebugLevelForOurPackage_whenCall_thenNoDebugLogsForOtherPackages() {
+ ResponseEntity response = restTemplate.getForEntity(baseUrl, String.class);
+
+ assertThat(response.getStatusCode().value()).isEqualTo(200);
+ assertThatOutputDoesntContainLogForOtherPackages("DEBUG");
+ }
+
+ @Test
+ public void givenErrorRootLevelAndDebugLevelForOurPackage_whenCall_thenPrintErrorLogs() {
+ ResponseEntity response = restTemplate.getForEntity(baseUrl, String.class);
+
+ assertThat(response.getStatusCode().value()).isEqualTo(200);
+ assertThatOutputContainsLogForOurPackage("ERROR");
+ assertThatOutputContainsLogForOtherPackages("ERROR");
+ }
+
+ private void assertThatOutputContainsLogForOurPackage(String level) {
+ assertThat(outputCapture.toString()).containsPattern("TestLogLevelController.*" + level + ".*");
+ }
+
+ private void assertThatOutputDoesntContainLogForOtherPackages(String level) {
+ assertThat(outputCapture.toString().replaceAll("(?m)^.*TestLogLevelController.*$", "")).doesNotContain(level);
+ }
+
+ private void assertThatOutputContainsLogForOtherPackages(String level) {
+ assertThat(outputCapture.toString().replaceAll("(?m)^.*TestLogLevelController.*$", "")).contains(level);
+ }
+
+}
diff --git a/spring-boot-testing/src/test/java/com/baeldung/testloglevel/TestLogLevelWithProfileIntegrationTest.java b/spring-boot-testing/src/test/java/com/baeldung/testloglevel/TestLogLevelWithProfileIntegrationTest.java
new file mode 100644
index 0000000000..5609ce6c01
--- /dev/null
+++ b/spring-boot-testing/src/test/java/com/baeldung/testloglevel/TestLogLevelWithProfileIntegrationTest.java
@@ -0,0 +1,70 @@
+package com.baeldung.testloglevel;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
+import org.springframework.boot.test.rule.OutputCapture;
+import org.springframework.boot.test.web.client.TestRestTemplate;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = TestLogLevelApplication.class)
+@EnableAutoConfiguration(exclude = SecurityAutoConfiguration.class)
+@ActiveProfiles("logging-test")
+public class TestLogLevelWithProfileIntegrationTest {
+
+ @Autowired
+ private TestRestTemplate restTemplate;
+
+ @Rule
+ public OutputCapture outputCapture = new OutputCapture();
+
+ private String baseUrl = "/testLogLevel";
+
+ @Test
+ public void givenInfoRootLevelAndDebugLevelForOurPackage_whenCall_thenPrintDebugLogsForOurPackage() {
+ ResponseEntity response = restTemplate.getForEntity(baseUrl, String.class);
+
+ assertThat(response.getStatusCode().value()).isEqualTo(200);
+ assertThatOutputContainsLogForOurPackage("DEBUG");
+ }
+
+ @Test
+ public void givenInfoRootLevelAndDebugLevelForOurPackage_whenCall_thenNoDebugLogsForOtherPackages() {
+ ResponseEntity response = restTemplate.getForEntity(baseUrl, String.class);
+
+ assertThat(response.getStatusCode().value()).isEqualTo(200);
+ assertThatOutputDoesntContainLogForOtherPackages("DEBUG");
+ }
+
+ @Test
+ public void givenInfoRootLevelAndDebugLevelForOurPackage_whenCall_thenPrintInfoLogs() {
+ ResponseEntity response = restTemplate.getForEntity(baseUrl, String.class);
+
+ assertThat(response.getStatusCode().value()).isEqualTo(200);
+ assertThatOutputContainsLogForOurPackage("INFO");
+ assertThatOutputContainsLogForOtherPackages("INFO");
+ }
+
+ private void assertThatOutputContainsLogForOurPackage(String level) {
+ assertThat(outputCapture.toString()).containsPattern("TestLogLevelController.*" + level + ".*");
+ }
+
+ private void assertThatOutputDoesntContainLogForOtherPackages(String level) {
+ assertThat(outputCapture.toString().replaceAll("(?m)^.*TestLogLevelController.*$", "")).doesNotContain(level);
+ }
+
+ private void assertThatOutputContainsLogForOtherPackages(String level) {
+ assertThat(outputCapture.toString().replaceAll("(?m)^.*TestLogLevelController.*$", "")).contains(level);
+ }
+
+}
diff --git a/spring-boot-testing/src/test/resources/application-logback-test.properties b/spring-boot-testing/src/test/resources/application-logback-test.properties
new file mode 100644
index 0000000000..587302fa01
--- /dev/null
+++ b/spring-boot-testing/src/test/resources/application-logback-test.properties
@@ -0,0 +1 @@
+logging.config=classpath:logback-test.xml
diff --git a/spring-boot-testing/src/test/resources/application-logback-test2.properties b/spring-boot-testing/src/test/resources/application-logback-test2.properties
new file mode 100644
index 0000000000..aeed46e3ca
--- /dev/null
+++ b/spring-boot-testing/src/test/resources/application-logback-test2.properties
@@ -0,0 +1 @@
+logging.config=classpath:logback-multiprofile.xml
\ No newline at end of file
diff --git a/spring-boot-testing/src/test/resources/application-logging-test.properties b/spring-boot-testing/src/test/resources/application-logging-test.properties
new file mode 100644
index 0000000000..b5adb4cc11
--- /dev/null
+++ b/spring-boot-testing/src/test/resources/application-logging-test.properties
@@ -0,0 +1,2 @@
+logging.level.com.baeldung.testloglevel=DEBUG
+logging.level.root=INFO
\ No newline at end of file
diff --git a/spring-boot-testing/src/test/resources/logback-multiprofile.xml b/spring-boot-testing/src/test/resources/logback-multiprofile.xml
new file mode 100644
index 0000000000..be790234f2
--- /dev/null
+++ b/spring-boot-testing/src/test/resources/logback-multiprofile.xml
@@ -0,0 +1,18 @@
+
+
+
+
+ %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/spring-boot-testing/src/test/resources/logback-test.xml b/spring-boot-testing/src/test/resources/logback-test.xml
new file mode 100644
index 0000000000..0528aa88f3
--- /dev/null
+++ b/spring-boot-testing/src/test/resources/logback-test.xml
@@ -0,0 +1,13 @@
+
+
+
+
+ %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
+
+
+
+
+
+
+
+
diff --git a/spring-boot/README.MD b/spring-boot/README.MD
index 7d270c9c25..c0392d38de 100644
--- a/spring-boot/README.MD
+++ b/spring-boot/README.MD
@@ -6,12 +6,12 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
- [A Guide to Spring in Eclipse STS](http://www.baeldung.com/eclipse-sts-spring)
- [The @ServletComponentScan Annotation in Spring Boot](http://www.baeldung.com/spring-servletcomponentscan)
- [Intro to Building an Application with Spring Boot](http://www.baeldung.com/intro-to-spring-boot)
-- [How to Register a Servlet in a Java Web Application](http://www.baeldung.com/register-servlet)
+- [How to Register a Servlet in Java](http://www.baeldung.com/register-servlet)
- [Guide to Spring WebUtils and ServletRequestUtils](http://www.baeldung.com/spring-webutils-servletrequestutils)
- [Using Custom Banners in Spring Boot](http://www.baeldung.com/spring-boot-custom-banners)
- [Guide to Internationalization in Spring Boot](http://www.baeldung.com/spring-boot-internationalization)
- [Create a Custom FailureAnalyzer with Spring Boot](http://www.baeldung.com/spring-boot-failure-analyzer)
-- [Dynamic DTO Validation Config Retrieved from DB](http://www.baeldung.com/spring-dynamic-dto-validation)
+- [Dynamic DTO Validation Config Retrieved from the Database](http://www.baeldung.com/spring-dynamic-dto-validation)
- [Custom Information in Spring Boot Info Endpoint](http://www.baeldung.com/spring-boot-info-actuator-custom)
- [Using @JsonComponent in Spring Boot](http://www.baeldung.com/spring-boot-jsoncomponent)
- [Testing in Spring Boot](http://www.baeldung.com/spring-boot-testing)
@@ -21,7 +21,7 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
- [Getting Started with GraphQL and Spring Boot](http://www.baeldung.com/spring-graphql)
- [Guide to Spring Type Conversions](http://www.baeldung.com/spring-type-conversions)
- [An Introduction to Kong](http://www.baeldung.com/kong)
-- [Spring Boot Customize Whitelabel Error Page](http://www.baeldung.com/spring-boot-custom-error-page)
+- [Spring Boot: Customize Whitelabel Error Page](http://www.baeldung.com/spring-boot-custom-error-page)
- [Spring Boot: Configuring a Main Class](http://www.baeldung.com/spring-boot-main-class)
- [A Quick Intro to the SpringBootServletInitializer](http://www.baeldung.com/spring-boot-servlet-initializer)
- [How to Define a Spring Boot Filter?](http://www.baeldung.com/spring-boot-add-filter)
@@ -35,5 +35,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
- [Display Auto-Configuration Report in Spring Boot](https://www.baeldung.com/spring-boot-auto-configuration-report)
- [Injecting Git Information Into Spring](https://www.baeldung.com/spring-git-information)
- [Validation in Spring Boot](https://www.baeldung.com/spring-boot-bean-validation)
-- [Entity To DTO Conversion for a Spring REST API](https://www.baeldung.com/entity-to-and-from-dto-for-a-java-spring-application)
- [Guide to Creating and Running a Jar File in Java](https://www.baeldung.com/java-create-jar)
diff --git a/spring-boot/pom.xml b/spring-boot/pom.xml
index ed2d8259df..401e0289e8 100644
--- a/spring-boot/pom.xml
+++ b/spring-boot/pom.xml
@@ -153,12 +153,6 @@
javax.validation
validation-api
-
-
- org.modelmapper
- modelmapper
- ${modelmapper.version}
-
@@ -256,7 +250,6 @@
5.2.4
18.0
2.2.4
- 2.3.2
diff --git a/spring-boot/src/main/java/com/baeldung/modelmapper/PostApplication.java b/spring-boot/src/main/java/com/baeldung/modelmapper/PostApplication.java
deleted file mode 100644
index 7684c43648..0000000000
--- a/spring-boot/src/main/java/com/baeldung/modelmapper/PostApplication.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.baeldung.modelmapper;
-
-import org.modelmapper.ModelMapper;
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.context.annotation.Bean;
-
-@SpringBootApplication
-public class PostApplication {
-
- public static void main(String[] args) {
- SpringApplication.run(PostApplication.class, args);
- }
-
- @Bean
- public ModelMapper modelMapper() {
- return new ModelMapper();
- }
-
-}
diff --git a/spring-boot/src/main/resources/META-INF/spring.factories b/spring-boot/src/main/resources/META-INF/spring.factories
index d8a01bbf82..336477df96 100644
--- a/spring-boot/src/main/resources/META-INF/spring.factories
+++ b/spring-boot/src/main/resources/META-INF/spring.factories
@@ -1,7 +1,2 @@
org.springframework.boot.diagnostics.FailureAnalyzer=com.baeldung.failureanalyzer.MyBeanNotOfRequiredTypeFailureAnalyzer
-org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
-com.baeldung.environmentpostprocessor.autoconfig.PriceCalculationAutoConfig
-
-org.springframework.boot.env.EnvironmentPostProcessor=\
-com.baeldung.environmentpostprocessor.PriceCalculationEnvironmentPostProcessor
diff --git a/spring-cloud-data-flow/apache-spark-job/pom.xml b/spring-cloud-data-flow/apache-spark-job/pom.xml
index 390b7ebdc6..671e8ed71a 100644
--- a/spring-cloud-data-flow/apache-spark-job/pom.xml
+++ b/spring-cloud-data-flow/apache-spark-job/pom.xml
@@ -2,24 +2,25 @@
+ 4.0.0
+ apache-spark-job
+
spring-cloud-data-flow
com.baeldung
0.0.1-SNAPSHOT
- 4.0.0
-
- apache-spark-job
+
org.springframework.cloud
spring-cloud-task-core
- 2.0.0.RELEASE
+ ${spring-cloud-task-core.version}
org.apache.spark
- spark-core_2.10
- 1.6.2
+ spark-core_${scala.version}
+ ${spark.version}
log4j
@@ -33,4 +34,10 @@
+
+ 1.6.2
+ 2.10
+ 2.0.0.RELEASE
+
+
\ No newline at end of file
diff --git a/spring-cloud/pom.xml b/spring-cloud/pom.xml
index bf70e0284c..baf86a4386 100644
--- a/spring-cloud/pom.xml
+++ b/spring-cloud/pom.xml
@@ -32,7 +32,6 @@
spring-cloud-zuul-eureka-integration
spring-cloud-contract
spring-cloud-kubernetes
- spring-cloud-kubernetes-2
spring-cloud-archaius
spring-cloud-functions
spring-cloud-vault
diff --git a/spring-cloud/spring-cloud-archaius/additional-sources-simple/src/main/java/com/baeldung/spring/cloud/archaius/additionalsources/config/ApplicationPropertiesConfigurations.java b/spring-cloud/spring-cloud-archaius/additional-sources-simple/src/main/java/com/baeldung/spring/cloud/archaius/additionalsources/config/ApplicationPropertiesConfigurations.java
index f2d8ca2638..04d49d967f 100644
--- a/spring-cloud/spring-cloud-archaius/additional-sources-simple/src/main/java/com/baeldung/spring/cloud/archaius/additionalsources/config/ApplicationPropertiesConfigurations.java
+++ b/spring-cloud/spring-cloud-archaius/additional-sources-simple/src/main/java/com/baeldung/spring/cloud/archaius/additionalsources/config/ApplicationPropertiesConfigurations.java
@@ -1,8 +1,12 @@
package com.baeldung.spring.cloud.archaius.additionalsources.config;
+import java.io.IOException;
+import java.net.URL;
+
import org.apache.commons.configuration.AbstractConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.core.io.ClassPathResource;
import com.netflix.config.DynamicConfiguration;
import com.netflix.config.FixedDelayPollingScheduler;
@@ -13,8 +17,9 @@ import com.netflix.config.sources.URLConfigurationSource;
public class ApplicationPropertiesConfigurations {
@Bean
- public AbstractConfiguration addApplicationPropertiesSource() {
- PolledConfigurationSource source = new URLConfigurationSource("classpath:other-config.properties");
+ public AbstractConfiguration addApplicationPropertiesSource() throws IOException {
+ URL configPropertyURL = (new ClassPathResource("other-config.properties")).getURL();
+ PolledConfigurationSource source = new URLConfigurationSource(configPropertyURL);
return new DynamicConfiguration(source, new FixedDelayPollingScheduler());
}
diff --git a/spring-cloud/spring-cloud-archaius/additional-sources-simple/src/test/java/org/baeldung/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-archaius/additional-sources-simple/src/test/java/com/baeldung/spring/cloud/archaius/additionalsources/SpringContextIntegrationTest.java
similarity index 77%
rename from spring-cloud/spring-cloud-archaius/additional-sources-simple/src/test/java/org/baeldung/SpringContextIntegrationTest.java
rename to spring-cloud/spring-cloud-archaius/additional-sources-simple/src/test/java/com/baeldung/spring/cloud/archaius/additionalsources/SpringContextIntegrationTest.java
index e5ebbce1aa..4811ebaa13 100644
--- a/spring-cloud/spring-cloud-archaius/additional-sources-simple/src/test/java/org/baeldung/SpringContextIntegrationTest.java
+++ b/spring-cloud/spring-cloud-archaius/additional-sources-simple/src/test/java/com/baeldung/spring/cloud/archaius/additionalsources/SpringContextIntegrationTest.java
@@ -1,12 +1,10 @@
-package org.baeldung;
+package com.baeldung.spring.cloud.archaius.additionalsources;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
-import com.baeldung.spring.cloud.archaius.additionalsources.AdditionalSourcesSimpleApplication;
-
@RunWith(SpringRunner.class)
@SpringBootTest(classes = AdditionalSourcesSimpleApplication.class)
public class SpringContextIntegrationTest {
diff --git a/spring-cloud/spring-cloud-archaius/extra-configs/pom.xml b/spring-cloud/spring-cloud-archaius/extra-configs/pom.xml
index c3c830f197..f7e5807f43 100644
--- a/spring-cloud/spring-cloud-archaius/extra-configs/pom.xml
+++ b/spring-cloud/spring-cloud-archaius/extra-configs/pom.xml
@@ -37,6 +37,7 @@
+
2.0.1.RELEASE
diff --git a/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/SpringContextIntegrationTest.java
new file mode 100644
index 0000000000..e0026ce441
--- /dev/null
+++ b/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/SpringContextIntegrationTest.java
@@ -0,0 +1,15 @@
+package com.baeldung.spring.cloud.aws;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = SpringCloudAwsApplication.class)
+public class SpringContextIntegrationTest {
+
+ @Test
+ public void whenSpringContextIsBootstrapped_thenNoExceptions() {
+ }
+}
diff --git a/spring-cloud/spring-cloud-config/client/src/test/java/org/baeldung/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-config/client/src/test/java/com/baeldung/spring/cloud/config/client/SpringContextLiveTest.java
similarity index 69%
rename from spring-cloud/spring-cloud-config/client/src/test/java/org/baeldung/SpringContextIntegrationTest.java
rename to spring-cloud/spring-cloud-config/client/src/test/java/com/baeldung/spring/cloud/config/client/SpringContextLiveTest.java
index d727772cf9..3fb43b169d 100644
--- a/spring-cloud/spring-cloud-config/client/src/test/java/org/baeldung/SpringContextIntegrationTest.java
+++ b/spring-cloud/spring-cloud-config/client/src/test/java/com/baeldung/spring/cloud/config/client/SpringContextLiveTest.java
@@ -1,4 +1,4 @@
-package org.baeldung;
+package com.baeldung.spring.cloud.config.client;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -6,12 +6,15 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
-import com.baeldung.spring.cloud.config.client.ConfigClient;
-
+/**
+ *
+ * The app needs the server running on port 8888. Can be started with docker
+ *
+ */
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = ConfigClient.class)
@WebAppConfiguration
-public class SpringContextIntegrationTest {
+public class SpringContextLiveTest {
@Test
public void contextLoads() {
}
diff --git a/spring-cloud/spring-cloud-config/server/src/test/java/com/baeldung/spring/cloud/config/server/ConfigServerListIntegrationTest.java b/spring-cloud/spring-cloud-config/server/src/test/java/com/baeldung/spring/cloud/config/server/SpringContextIntegrationTest.java
similarity index 79%
rename from spring-cloud/spring-cloud-config/server/src/test/java/com/baeldung/spring/cloud/config/server/ConfigServerListIntegrationTest.java
rename to spring-cloud/spring-cloud-config/server/src/test/java/com/baeldung/spring/cloud/config/server/SpringContextIntegrationTest.java
index c521a0d2ef..b2c6ef85ea 100644
--- a/spring-cloud/spring-cloud-config/server/src/test/java/com/baeldung/spring/cloud/config/server/ConfigServerListIntegrationTest.java
+++ b/spring-cloud/spring-cloud-config/server/src/test/java/com/baeldung/spring/cloud/config/server/SpringContextIntegrationTest.java
@@ -1,6 +1,5 @@
package com.baeldung.spring.cloud.config.server;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
@@ -10,9 +9,8 @@ import org.springframework.test.context.web.WebAppConfiguration;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = ConfigServer.class)
@WebAppConfiguration
-@Ignore
-public class ConfigServerListIntegrationTest {
+public class SpringContextIntegrationTest {
@Test
- public void contextLoads() {
+ public void whenSpringContextIsBootstrapped_thenNoExceptions() {
}
}
diff --git a/spring-cloud/spring-cloud-config/server/src/test/resources/application.properties b/spring-cloud/spring-cloud-config/server/src/test/resources/application.properties
new file mode 100644
index 0000000000..67cc81ff67
--- /dev/null
+++ b/spring-cloud/spring-cloud-config/server/src/test/resources/application.properties
@@ -0,0 +1,2 @@
+### This should be provided by the docker config
+spring.cloud.config.server.git.uri=classpath:.
diff --git a/spring-cloud/spring-cloud-connectors-heroku/src/main/resources/application.properties b/spring-cloud/spring-cloud-connectors-heroku/src/main/resources/application.properties
index d2f1c89dc5..571f325824 100644
--- a/spring-cloud/spring-cloud-connectors-heroku/src/main/resources/application.properties
+++ b/spring-cloud/spring-cloud-connectors-heroku/src/main/resources/application.properties
@@ -4,5 +4,6 @@ spring.datasource.maxIdle=5
spring.datasource.minIdle=2
spring.datasource.initialSize=5
spring.datasource.removeAbandoned=true
+spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto=update
\ No newline at end of file
diff --git a/spring-cloud/spring-cloud-connectors-heroku/src/test/java/org/baeldung/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-connectors-heroku/src/test/java/com/baeldung/spring/cloud/connectors/heroku/SpringContextIntegrationTest.java
similarity index 90%
rename from spring-cloud/spring-cloud-connectors-heroku/src/test/java/org/baeldung/SpringContextIntegrationTest.java
rename to spring-cloud/spring-cloud-connectors-heroku/src/test/java/com/baeldung/spring/cloud/connectors/heroku/SpringContextIntegrationTest.java
index a705f18bc6..dca4c25c71 100644
--- a/spring-cloud/spring-cloud-connectors-heroku/src/test/java/org/baeldung/SpringContextIntegrationTest.java
+++ b/spring-cloud/spring-cloud-connectors-heroku/src/test/java/com/baeldung/spring/cloud/connectors/heroku/SpringContextIntegrationTest.java
@@ -1,4 +1,4 @@
-package org.baeldung;
+package com.baeldung.spring.cloud.connectors.heroku;
import org.junit.Test;
import org.junit.runner.RunWith;
diff --git a/spring-cloud/spring-cloud-connectors-heroku/src/test/resources/application.properties b/spring-cloud/spring-cloud-connectors-heroku/src/test/resources/application.properties
new file mode 100644
index 0000000000..7b139ae07d
--- /dev/null
+++ b/spring-cloud/spring-cloud-connectors-heroku/src/test/resources/application.properties
@@ -0,0 +1,2 @@
+spring.jpa.hibernate.ddl-auto=create
+spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
\ No newline at end of file
diff --git a/spring-cloud/spring-cloud-consul/pom.xml b/spring-cloud/spring-cloud-consul/pom.xml
index 1ca3d703b5..456a7ec302 100644
--- a/spring-cloud/spring-cloud-consul/pom.xml
+++ b/spring-cloud/spring-cloud-consul/pom.xml
@@ -29,13 +29,14 @@
org.springframework.boot
spring-boot-starter-test
- 1.5.10.RELEASE
+ ${spring-boot-starter-test.version}
test
1.3.0.RELEASE
+ 1.5.10.RELEASE
diff --git a/spring-cloud/spring-cloud-consul/src/test/java/org/baeldung/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-consul/src/test/java/com/baeldung/spring/cloud/consul/SpringContextLiveTest.java
similarity index 74%
rename from spring-cloud/spring-cloud-consul/src/test/java/org/baeldung/SpringContextIntegrationTest.java
rename to spring-cloud/spring-cloud-consul/src/test/java/com/baeldung/spring/cloud/consul/SpringContextLiveTest.java
index 6290ccc03e..7c87add43e 100644
--- a/spring-cloud/spring-cloud-consul/src/test/java/org/baeldung/SpringContextIntegrationTest.java
+++ b/spring-cloud/spring-cloud-consul/src/test/java/com/baeldung/spring/cloud/consul/SpringContextLiveTest.java
@@ -1,4 +1,4 @@
-package org.baeldung;
+package com.baeldung.spring.cloud.consul;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -9,10 +9,18 @@ import com.baeldung.spring.cloud.consul.discovery.DiscoveryClientApplication;
import com.baeldung.spring.cloud.consul.health.ServiceDiscoveryApplication;
import com.baeldung.spring.cloud.consul.properties.DistributedPropertiesApplication;
+
+/**
+ *
+ * This Live test requires:
+ * * a Consul instance running on port 8500
+ * * Consul configured with particular properties (e.g. 'my.prop')
+ *
+ */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = { DiscoveryClientApplication.class, ServiceDiscoveryApplication.class,
DistributedPropertiesApplication.class })
-public class SpringContextIntegrationTest {
+public class SpringContextLiveTest {
@Test
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
diff --git a/spring-cloud/spring-cloud-contract/spring-cloud-contract-consumer/pom.xml b/spring-cloud/spring-cloud-contract/spring-cloud-contract-consumer/pom.xml
index 7d00a9f463..8ecda40d0a 100644
--- a/spring-cloud/spring-cloud-contract/spring-cloud-contract-consumer/pom.xml
+++ b/spring-cloud/spring-cloud-contract/spring-cloud-contract-consumer/pom.xml
@@ -20,24 +20,24 @@
org.springframework.cloud
spring-cloud-contract-wiremock
- 1.2.2.RELEASE
+ ${spring-cloud.version}
test
org.springframework.cloud
spring-cloud-contract-stub-runner
- 1.2.2.RELEASE
+ ${spring-cloud.version}
test
org.springframework.boot
spring-boot-starter-web
- 1.5.9.RELEASE
+ ${spring-boot.version}
org.springframework.boot
spring-boot-starter-data-rest
- 1.5.9.RELEASE
+ ${spring-boot.version}
com.baeldung.spring.cloud
@@ -51,5 +51,7 @@
UTF-8
UTF-8
1.8
+ 1.2.2.RELEASE
+ 1.5.9.RELEASE
diff --git a/spring-cloud/spring-cloud-contract/spring-cloud-contract-producer/pom.xml b/spring-cloud/spring-cloud-contract/spring-cloud-contract-producer/pom.xml
index a6bd4e1be4..47759a818a 100644
--- a/spring-cloud/spring-cloud-contract/spring-cloud-contract-producer/pom.xml
+++ b/spring-cloud/spring-cloud-contract/spring-cloud-contract-producer/pom.xml
@@ -25,12 +25,12 @@
org.springframework.boot
spring-boot-starter-web
- 1.5.9.RELEASE
+ ${spring-boot.version}
org.springframework.boot
spring-boot-starter-data-rest
- 1.5.9.RELEASE
+ ${spring-boot.version}
@@ -66,6 +66,7 @@
UTF-8
1.8
Edgware.SR1
+ 1.5.9.RELEASE
diff --git a/spring-cloud/spring-cloud-eureka/pom.xml b/spring-cloud/spring-cloud-eureka/pom.xml
index b59b415ee2..924981765c 100644
--- a/spring-cloud/spring-cloud-eureka/pom.xml
+++ b/spring-cloud/spring-cloud-eureka/pom.xml
@@ -21,6 +21,15 @@
1.0.0-SNAPSHOT
..
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ ${spring-boot.version}
+ test
+
+
2.0.1.RELEASE
diff --git a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-client/pom.xml b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-client/pom.xml
index c2d64ce237..85fa6606d2 100644
--- a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-client/pom.xml
+++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-client/pom.xml
@@ -26,12 +26,6 @@
spring-boot-starter-web
${spring-boot.version}
-
- org.springframework.boot
- spring-boot-starter-test
- ${spring-boot.version}
- test
-
diff --git a/spring-cloud/spring-cloud-rest/spring-cloud-rest-books-api/src/test/java/org/baeldung/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-client/src/test/java/com/baeldung/spring/cloud/eureka/client/SpringContextIntegrationTest.java
similarity index 81%
rename from spring-cloud/spring-cloud-rest/spring-cloud-rest-books-api/src/test/java/org/baeldung/SpringContextIntegrationTest.java
rename to spring-cloud/spring-cloud-eureka/spring-cloud-eureka-client/src/test/java/com/baeldung/spring/cloud/eureka/client/SpringContextIntegrationTest.java
index 24e758ff82..8e379fd5a0 100644
--- a/spring-cloud/spring-cloud-rest/spring-cloud-rest-books-api/src/test/java/org/baeldung/SpringContextIntegrationTest.java
+++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-client/src/test/java/com/baeldung/spring/cloud/eureka/client/SpringContextIntegrationTest.java
@@ -1,4 +1,4 @@
-package org.baeldung;
+package com.baeldung.spring.cloud.eureka.client;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -6,10 +6,11 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
-@SpringBootTest(classes = BooksApiApplication.class)
+@SpringBootTest
public class SpringContextIntegrationTest {
-
+
@Test
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
}
+
}
diff --git a/spring-cloud/spring-cloud-rest/spring-cloud-rest-reviews-api/src/test/java/org/baeldung/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client/src/test/java/com/baeldung/spring/cloud/feign/client/SpringContextIntegrationTest.java
similarity index 80%
rename from spring-cloud/spring-cloud-rest/spring-cloud-rest-reviews-api/src/test/java/org/baeldung/SpringContextIntegrationTest.java
rename to spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client/src/test/java/com/baeldung/spring/cloud/feign/client/SpringContextIntegrationTest.java
index 07d7db0505..ff742735b3 100644
--- a/spring-cloud/spring-cloud-rest/spring-cloud-rest-reviews-api/src/test/java/org/baeldung/SpringContextIntegrationTest.java
+++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client/src/test/java/com/baeldung/spring/cloud/feign/client/SpringContextIntegrationTest.java
@@ -1,4 +1,4 @@
-package org.baeldung;
+package com.baeldung.spring.cloud.feign.client;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -6,10 +6,11 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
-@SpringBootTest(classes = BookReviewsApiApplication.class)
+@SpringBootTest
public class SpringContextIntegrationTest {
@Test
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
}
+
}
diff --git a/spring-cloud/spring-cloud-rest/spring-cloud-rest-discovery-server/src/test/java/org/baeldung/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-server/src/test/java/com/baeldung/spring/cloud/eureka/server/SpringContextIntegrationTest.java
similarity index 79%
rename from spring-cloud/spring-cloud-rest/spring-cloud-rest-discovery-server/src/test/java/org/baeldung/SpringContextIntegrationTest.java
rename to spring-cloud/spring-cloud-eureka/spring-cloud-eureka-server/src/test/java/com/baeldung/spring/cloud/eureka/server/SpringContextIntegrationTest.java
index e22359a016..f03913b474 100644
--- a/spring-cloud/spring-cloud-rest/spring-cloud-rest-discovery-server/src/test/java/org/baeldung/SpringContextIntegrationTest.java
+++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-server/src/test/java/com/baeldung/spring/cloud/eureka/server/SpringContextIntegrationTest.java
@@ -1,4 +1,4 @@
-package org.baeldung;
+package com.baeldung.spring.cloud.eureka.server;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -6,10 +6,11 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
-@SpringBootTest(classes = SpringCloudRestServerApplication.class)
+@SpringBootTest
public class SpringContextIntegrationTest {
@Test
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
}
+
}
diff --git a/spring-cloud/spring-cloud-hystrix/feign-rest-consumer/src/test/java/com/baeldung/spring/cloud/hystrix/rest/consumer/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-hystrix/feign-rest-consumer/src/test/java/com/baeldung/spring/cloud/hystrix/rest/consumer/SpringContextIntegrationTest.java
new file mode 100644
index 0000000000..47ee5dcd49
--- /dev/null
+++ b/spring-cloud/spring-cloud-hystrix/feign-rest-consumer/src/test/java/com/baeldung/spring/cloud/hystrix/rest/consumer/SpringContextIntegrationTest.java
@@ -0,0 +1,18 @@
+package com.baeldung.spring.cloud.hystrix.rest.consumer;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(classes = RestConsumerFeignApplication.class)
+@WebAppConfiguration
+public class SpringContextIntegrationTest {
+
+ @Test
+ public void whenSpringContextIsBootstrapped_thenNoExceptions() {
+ }
+
+}
diff --git a/spring-cloud/spring-cloud-hystrix/rest-consumer/pom.xml b/spring-cloud/spring-cloud-hystrix/rest-consumer/pom.xml
index ec2f6d1e55..43ccfcc26d 100644
--- a/spring-cloud/spring-cloud-hystrix/rest-consumer/pom.xml
+++ b/spring-cloud/spring-cloud-hystrix/rest-consumer/pom.xml
@@ -40,6 +40,13 @@
spring-boot-starter-actuator
${spring-boot-starter-web.version}
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+ ${spring-boot-starter-web.version}
+
@@ -53,5 +60,10 @@
+
+
+
+ 1.10.19
+
diff --git a/spring-cloud/spring-cloud-config/server/src/test/java/org/baeldung/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-hystrix/rest-consumer/src/test/java/com/baeldung/spring/cloud/hystrix/rest/consumer/SpringContextIntegrationTest.java
similarity index 55%
rename from spring-cloud/spring-cloud-config/server/src/test/java/org/baeldung/SpringContextIntegrationTest.java
rename to spring-cloud/spring-cloud-hystrix/rest-consumer/src/test/java/com/baeldung/spring/cloud/hystrix/rest/consumer/SpringContextIntegrationTest.java
index cd30392d4f..3af30acc51 100644
--- a/spring-cloud/spring-cloud-config/server/src/test/java/org/baeldung/SpringContextIntegrationTest.java
+++ b/spring-cloud/spring-cloud-hystrix/rest-consumer/src/test/java/com/baeldung/spring/cloud/hystrix/rest/consumer/SpringContextIntegrationTest.java
@@ -1,18 +1,18 @@
-package org.baeldung;
+package com.baeldung.spring.cloud.hystrix.rest.consumer;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
-import com.baeldung.spring.cloud.config.server.ConfigServer;
-
@RunWith(SpringJUnit4ClassRunner.class)
-@SpringBootTest(classes = ConfigServer.class)
+@ContextConfiguration(classes = RestConsumerApplication.class)
@WebAppConfiguration
public class SpringContextIntegrationTest {
+
@Test
- public void contextLoads() {
+ public void whenSpringContextIsBootstrapped_thenNoExceptions() {
}
+
}
diff --git a/spring-cloud/spring-cloud-hystrix/rest-producer/pom.xml b/spring-cloud/spring-cloud-hystrix/rest-producer/pom.xml
index 0f84fb7e23..07437634f5 100644
--- a/spring-cloud/spring-cloud-hystrix/rest-producer/pom.xml
+++ b/spring-cloud/spring-cloud-hystrix/rest-producer/pom.xml
@@ -20,6 +20,18 @@
spring-boot-starter-web
${spring-boot-starter-web.version}
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ ${spring-boot-starter-web.version}
+ test
+
+
+
+
+ 1.10.19
+
diff --git a/spring-cloud/spring-cloud-aws/src/test/java/org/baeldung/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-hystrix/rest-producer/src/test/java/com/baeldung/spring/cloud/hystrix/rest/producer/SpringContextIntegrationTest.java
similarity index 69%
rename from spring-cloud/spring-cloud-aws/src/test/java/org/baeldung/SpringContextIntegrationTest.java
rename to spring-cloud/spring-cloud-hystrix/rest-producer/src/test/java/com/baeldung/spring/cloud/hystrix/rest/producer/SpringContextIntegrationTest.java
index fcba9c4132..de696dc2b1 100644
--- a/spring-cloud/spring-cloud-aws/src/test/java/org/baeldung/SpringContextIntegrationTest.java
+++ b/spring-cloud/spring-cloud-hystrix/rest-producer/src/test/java/com/baeldung/spring/cloud/hystrix/rest/producer/SpringContextIntegrationTest.java
@@ -1,17 +1,16 @@
-package org.baeldung;
+package com.baeldung.spring.cloud.hystrix.rest.producer;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
-import com.baeldung.spring.cloud.aws.InstanceProfileAwsApplication;
-
@RunWith(SpringRunner.class)
-@SpringBootTest(classes = InstanceProfileAwsApplication.class)
+@SpringBootTest
public class SpringContextIntegrationTest {
@Test
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
}
+
}
diff --git a/spring-cloud/spring-cloud-kubernetes-2/pom.xml b/spring-cloud/spring-cloud-kubernetes-2/pom.xml
deleted file mode 100644
index d501e8102f..0000000000
--- a/spring-cloud/spring-cloud-kubernetes-2/pom.xml
+++ /dev/null
@@ -1,32 +0,0 @@
-
-
- 4.0.0
- com.baeldung.spring.cloud
- spring-cloud-kubernetes-2
- 1.0-SNAPSHOT
- spring-cloud-kubernetes-2
- pom
-
-
- 2.0.6.RELEASE
-
-
-
-
-
- org.springframework.boot
- spring-boot-dependencies
- ${spring-boot.version}
- pom
- import
-
-
-
-
-
- client-service
- travel-agency-service
-
-
-
diff --git a/spring-cloud/spring-cloud-kubernetes-2/travel-agency-service/travel-agency-config.yaml b/spring-cloud/spring-cloud-kubernetes-2/travel-agency-service/travel-agency-config.yaml
deleted file mode 100644
index 93a67e3777..0000000000
--- a/spring-cloud/spring-cloud-kubernetes-2/travel-agency-service/travel-agency-config.yaml
+++ /dev/null
@@ -1,8 +0,0 @@
-apiVersion: v1
-kind: Secret
-metadata:
- name: travel-agency-service
-data:
- application.properties: |-
- bean.message=Testing reload ! Message from backend is: %s
Services : %s
-
diff --git a/spring-cloud/spring-cloud-kubernetes-2/client-service/.gitignore b/spring-cloud/spring-cloud-kubernetes/client-service/.gitignore
similarity index 100%
rename from spring-cloud/spring-cloud-kubernetes-2/client-service/.gitignore
rename to spring-cloud/spring-cloud-kubernetes/client-service/.gitignore
diff --git a/spring-cloud/spring-cloud-kubernetes-2/client-service/Dockerfile b/spring-cloud/spring-cloud-kubernetes/client-service/Dockerfile
similarity index 100%
rename from spring-cloud/spring-cloud-kubernetes-2/client-service/Dockerfile
rename to spring-cloud/spring-cloud-kubernetes/client-service/Dockerfile
diff --git a/spring-cloud/spring-cloud-kubernetes-2/client-service/client-config.yaml b/spring-cloud/spring-cloud-kubernetes/client-service/client-config.yaml
similarity index 100%
rename from spring-cloud/spring-cloud-kubernetes-2/client-service/client-config.yaml
rename to spring-cloud/spring-cloud-kubernetes/client-service/client-config.yaml
diff --git a/spring-cloud/spring-cloud-kubernetes-2/client-service/client-service-deployment.yaml b/spring-cloud/spring-cloud-kubernetes/client-service/client-service-deployment.yaml
similarity index 100%
rename from spring-cloud/spring-cloud-kubernetes-2/client-service/client-service-deployment.yaml
rename to spring-cloud/spring-cloud-kubernetes/client-service/client-service-deployment.yaml
diff --git a/spring-cloud/spring-cloud-kubernetes-2/client-service/pom.xml b/spring-cloud/spring-cloud-kubernetes/client-service/pom.xml
similarity index 97%
rename from spring-cloud/spring-cloud-kubernetes-2/client-service/pom.xml
rename to spring-cloud/spring-cloud-kubernetes/client-service/pom.xml
index 908a545242..a4de796ee3 100644
--- a/spring-cloud/spring-cloud-kubernetes-2/client-service/pom.xml
+++ b/spring-cloud/spring-cloud-kubernetes/client-service/pom.xml
@@ -3,21 +3,15 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
client-service
- client-service
+ client-service
1.0-SNAPSHOT
com.baeldung.spring.cloud
- spring-cloud-kubernetes-2
+ spring-cloud-kubernetes
1.0-SNAPSHOT
-
- 1.8
- Finchley.SR2
- 1.0.0.RELEASE
-
-
@@ -93,4 +87,10 @@
+
+ 1.8
+ Finchley.SR2
+ 1.0.0.RELEASE
+
+
diff --git a/spring-cloud/spring-cloud-kubernetes-2/client-service/src/main/java/com/baeldung/spring/cloud/kubernetes/client/Application.java b/spring-cloud/spring-cloud-kubernetes/client-service/src/main/java/com/baeldung/spring/cloud/kubernetes/client/Application.java
similarity index 100%
rename from spring-cloud/spring-cloud-kubernetes-2/client-service/src/main/java/com/baeldung/spring/cloud/kubernetes/client/Application.java
rename to spring-cloud/spring-cloud-kubernetes/client-service/src/main/java/com/baeldung/spring/cloud/kubernetes/client/Application.java
diff --git a/spring-cloud/spring-cloud-kubernetes-2/client-service/src/main/java/com/baeldung/spring/cloud/kubernetes/client/ClientConfig.java b/spring-cloud/spring-cloud-kubernetes/client-service/src/main/java/com/baeldung/spring/cloud/kubernetes/client/ClientConfig.java
similarity index 100%
rename from spring-cloud/spring-cloud-kubernetes-2/client-service/src/main/java/com/baeldung/spring/cloud/kubernetes/client/ClientConfig.java
rename to spring-cloud/spring-cloud-kubernetes/client-service/src/main/java/com/baeldung/spring/cloud/kubernetes/client/ClientConfig.java
diff --git a/spring-cloud/spring-cloud-kubernetes-2/client-service/src/main/java/com/baeldung/spring/cloud/kubernetes/client/ClientController.java b/spring-cloud/spring-cloud-kubernetes/client-service/src/main/java/com/baeldung/spring/cloud/kubernetes/client/ClientController.java
similarity index 100%
rename from spring-cloud/spring-cloud-kubernetes-2/client-service/src/main/java/com/baeldung/spring/cloud/kubernetes/client/ClientController.java
rename to spring-cloud/spring-cloud-kubernetes/client-service/src/main/java/com/baeldung/spring/cloud/kubernetes/client/ClientController.java
diff --git a/spring-cloud/spring-cloud-kubernetes-2/client-service/src/main/java/com/baeldung/spring/cloud/kubernetes/client/RibbonConfiguration.java b/spring-cloud/spring-cloud-kubernetes/client-service/src/main/java/com/baeldung/spring/cloud/kubernetes/client/RibbonConfiguration.java
similarity index 100%
rename from spring-cloud/spring-cloud-kubernetes-2/client-service/src/main/java/com/baeldung/spring/cloud/kubernetes/client/RibbonConfiguration.java
rename to spring-cloud/spring-cloud-kubernetes/client-service/src/main/java/com/baeldung/spring/cloud/kubernetes/client/RibbonConfiguration.java
diff --git a/spring-cloud/spring-cloud-kubernetes-2/client-service/src/main/java/com/baeldung/spring/cloud/kubernetes/client/TravelAgencyService.java b/spring-cloud/spring-cloud-kubernetes/client-service/src/main/java/com/baeldung/spring/cloud/kubernetes/client/TravelAgencyService.java
similarity index 100%
rename from spring-cloud/spring-cloud-kubernetes-2/client-service/src/main/java/com/baeldung/spring/cloud/kubernetes/client/TravelAgencyService.java
rename to spring-cloud/spring-cloud-kubernetes/client-service/src/main/java/com/baeldung/spring/cloud/kubernetes/client/TravelAgencyService.java
diff --git a/spring-cloud/spring-cloud-kubernetes-2/client-service/src/main/resources/application.yaml b/spring-cloud/spring-cloud-kubernetes/client-service/src/main/resources/application.yaml
similarity index 100%
rename from spring-cloud/spring-cloud-kubernetes-2/client-service/src/main/resources/application.yaml
rename to spring-cloud/spring-cloud-kubernetes/client-service/src/main/resources/application.yaml
diff --git a/spring-cloud/spring-cloud-kubernetes/client-service/src/main/resources/logback.xml b/spring-cloud/spring-cloud-kubernetes/client-service/src/main/resources/logback.xml
new file mode 100644
index 0000000000..7d900d8ea8
--- /dev/null
+++ b/spring-cloud/spring-cloud-kubernetes/client-service/src/main/resources/logback.xml
@@ -0,0 +1,13 @@
+
+
+
+
+ %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/spring-cloud/spring-cloud-kubernetes-2/client-service/src/test/java/org/baeldung/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-kubernetes/client-service/src/test/java/org/baeldung/SpringContextIntegrationTest.java
similarity index 100%
rename from spring-cloud/spring-cloud-kubernetes-2/client-service/src/test/java/org/baeldung/SpringContextIntegrationTest.java
rename to spring-cloud/spring-cloud-kubernetes/client-service/src/test/java/org/baeldung/SpringContextIntegrationTest.java
diff --git a/spring-cloud/spring-cloud-kubernetes-2/deployment-all.sh b/spring-cloud/spring-cloud-kubernetes/deployment-travel-client.sh
similarity index 72%
rename from spring-cloud/spring-cloud-kubernetes-2/deployment-all.sh
rename to spring-cloud/spring-cloud-kubernetes/deployment-travel-client.sh
index 9c088b7422..90f92f31a6 100755
--- a/spring-cloud/spring-cloud-kubernetes-2/deployment-all.sh
+++ b/spring-cloud/spring-cloud-kubernetes/deployment-travel-client.sh
@@ -1,9 +1,9 @@
-### build the repository
-mvn clean install
-
### set docker env
eval $(minikube docker-env)
+### build the repository
+#mvn clean install
+
### build the docker images on minikube
cd travel-agency-service
docker build -t travel-agency-service .
@@ -12,11 +12,11 @@ docker build -t client-service .
cd ..
### secret and mongodb
-kubectl delete -f secret.yaml
-kubectl delete -f mongo-deployment.yaml
+kubectl delete -f travel-agency-service/secret.yaml
+kubectl delete -f travel-agency-service/mongo-deployment.yaml
-kubectl create -f secret.yaml
-kubectl create -f mongo-deployment.yaml
+kubectl create -f travel-agency-service/secret.yaml
+kubectl create -f travel-agency-service/mongo-deployment.yaml
### travel-agency-service
kubectl delete -f travel-agency-service/travel-agency-deployment.yaml
@@ -31,4 +31,4 @@ kubectl create -f client-service/client-config.yaml
kubectl create -f client-service/client-service-deployment.yaml
# Check that the pods are running
-kubectl get pods
\ No newline at end of file
+kubectl get pods
diff --git a/spring-cloud/spring-cloud-kubernetes/pom.xml b/spring-cloud/spring-cloud-kubernetes/pom.xml
index 51e1456358..a9563fc582 100644
--- a/spring-cloud/spring-cloud-kubernetes/pom.xml
+++ b/spring-cloud/spring-cloud-kubernetes/pom.xml
@@ -9,17 +9,19 @@
pom
- parent-boot-1
+ parent-boot-2
com.baeldung
0.0.1-SNAPSHOT
- ../../parent-boot-1
+ ../../parent-boot-2
-
+
demo-frontend
demo-backend
liveness-example
readiness-example
+ client-service
+ travel-agency-service
\ No newline at end of file
diff --git a/spring-cloud/spring-cloud-kubernetes-2/travel-agency-service/Dockerfile b/spring-cloud/spring-cloud-kubernetes/travel-agency-service/Dockerfile
similarity index 100%
rename from spring-cloud/spring-cloud-kubernetes-2/travel-agency-service/Dockerfile
rename to spring-cloud/spring-cloud-kubernetes/travel-agency-service/Dockerfile
diff --git a/spring-cloud/spring-cloud-kubernetes-2/mongo-deployment.yaml b/spring-cloud/spring-cloud-kubernetes/travel-agency-service/mongo-deployment.yaml
similarity index 100%
rename from spring-cloud/spring-cloud-kubernetes-2/mongo-deployment.yaml
rename to spring-cloud/spring-cloud-kubernetes/travel-agency-service/mongo-deployment.yaml
diff --git a/spring-cloud/spring-cloud-kubernetes-2/travel-agency-service/pom.xml b/spring-cloud/spring-cloud-kubernetes/travel-agency-service/pom.xml
similarity index 97%
rename from spring-cloud/spring-cloud-kubernetes-2/travel-agency-service/pom.xml
rename to spring-cloud/spring-cloud-kubernetes/travel-agency-service/pom.xml
index a375264533..19eea2612c 100755
--- a/spring-cloud/spring-cloud-kubernetes-2/travel-agency-service/pom.xml
+++ b/spring-cloud/spring-cloud-kubernetes/travel-agency-service/pom.xml
@@ -6,16 +6,10 @@
com.baeldung.spring.cloud
- spring-cloud-kubernetes-2
+ spring-cloud-kubernetes
1.0-SNAPSHOT
-
- 1.8
- Finchley.SR2
-
-
-
@@ -73,4 +67,9 @@
+
+ 1.8
+ Finchley.SR2
+
+
\ No newline at end of file
diff --git a/spring-cloud/spring-cloud-kubernetes-2/secret.yaml b/spring-cloud/spring-cloud-kubernetes/travel-agency-service/secret.yaml
similarity index 100%
rename from spring-cloud/spring-cloud-kubernetes-2/secret.yaml
rename to spring-cloud/spring-cloud-kubernetes/travel-agency-service/secret.yaml
diff --git a/spring-cloud/spring-cloud-kubernetes-2/travel-agency-service/src/main/java/com/baeldung/spring/cloud/kubernetes/travelagency/Application.java b/spring-cloud/spring-cloud-kubernetes/travel-agency-service/src/main/java/com/baeldung/spring/cloud/kubernetes/travelagency/Application.java
similarity index 100%
rename from spring-cloud/spring-cloud-kubernetes-2/travel-agency-service/src/main/java/com/baeldung/spring/cloud/kubernetes/travelagency/Application.java
rename to spring-cloud/spring-cloud-kubernetes/travel-agency-service/src/main/java/com/baeldung/spring/cloud/kubernetes/travelagency/Application.java
diff --git a/spring-cloud/spring-cloud-kubernetes-2/travel-agency-service/src/main/java/com/baeldung/spring/cloud/kubernetes/travelagency/controller/TravelAgencyController.java b/spring-cloud/spring-cloud-kubernetes/travel-agency-service/src/main/java/com/baeldung/spring/cloud/kubernetes/travelagency/controller/TravelAgencyController.java
similarity index 100%
rename from spring-cloud/spring-cloud-kubernetes-2/travel-agency-service/src/main/java/com/baeldung/spring/cloud/kubernetes/travelagency/controller/TravelAgencyController.java
rename to spring-cloud/spring-cloud-kubernetes/travel-agency-service/src/main/java/com/baeldung/spring/cloud/kubernetes/travelagency/controller/TravelAgencyController.java
diff --git a/spring-cloud/spring-cloud-kubernetes-2/travel-agency-service/src/main/java/com/baeldung/spring/cloud/kubernetes/travelagency/model/TravelDeal.java b/spring-cloud/spring-cloud-kubernetes/travel-agency-service/src/main/java/com/baeldung/spring/cloud/kubernetes/travelagency/model/TravelDeal.java
similarity index 100%
rename from spring-cloud/spring-cloud-kubernetes-2/travel-agency-service/src/main/java/com/baeldung/spring/cloud/kubernetes/travelagency/model/TravelDeal.java
rename to spring-cloud/spring-cloud-kubernetes/travel-agency-service/src/main/java/com/baeldung/spring/cloud/kubernetes/travelagency/model/TravelDeal.java
diff --git a/spring-cloud/spring-cloud-kubernetes-2/travel-agency-service/src/main/java/com/baeldung/spring/cloud/kubernetes/travelagency/repository/TravelDealRepository.java b/spring-cloud/spring-cloud-kubernetes/travel-agency-service/src/main/java/com/baeldung/spring/cloud/kubernetes/travelagency/repository/TravelDealRepository.java
similarity index 100%
rename from spring-cloud/spring-cloud-kubernetes-2/travel-agency-service/src/main/java/com/baeldung/spring/cloud/kubernetes/travelagency/repository/TravelDealRepository.java
rename to spring-cloud/spring-cloud-kubernetes/travel-agency-service/src/main/java/com/baeldung/spring/cloud/kubernetes/travelagency/repository/TravelDealRepository.java
diff --git a/spring-cloud/spring-cloud-kubernetes-2/travel-agency-service/src/main/resources/application.properties b/spring-cloud/spring-cloud-kubernetes/travel-agency-service/src/main/resources/application.properties
similarity index 100%
rename from spring-cloud/spring-cloud-kubernetes-2/travel-agency-service/src/main/resources/application.properties
rename to spring-cloud/spring-cloud-kubernetes/travel-agency-service/src/main/resources/application.properties
diff --git a/spring-cloud/spring-cloud-kubernetes-2/travel-agency-service/src/main/resources/logback-spring.xml b/spring-cloud/spring-cloud-kubernetes/travel-agency-service/src/main/resources/logback-spring.xml
similarity index 100%
rename from spring-cloud/spring-cloud-kubernetes-2/travel-agency-service/src/main/resources/logback-spring.xml
rename to spring-cloud/spring-cloud-kubernetes/travel-agency-service/src/main/resources/logback-spring.xml
diff --git a/spring-cloud/spring-cloud-kubernetes-2/travel-agency-service/src/main/resources/logback.xml b/spring-cloud/spring-cloud-kubernetes/travel-agency-service/src/main/resources/logback.xml
similarity index 100%
rename from spring-cloud/spring-cloud-kubernetes-2/travel-agency-service/src/main/resources/logback.xml
rename to spring-cloud/spring-cloud-kubernetes/travel-agency-service/src/main/resources/logback.xml
diff --git a/spring-cloud/spring-cloud-kubernetes-2/travel-agency-service/travel-agency-deployment.yaml b/spring-cloud/spring-cloud-kubernetes/travel-agency-service/travel-agency-deployment.yaml
similarity index 100%
rename from spring-cloud/spring-cloud-kubernetes-2/travel-agency-service/travel-agency-deployment.yaml
rename to spring-cloud/spring-cloud-kubernetes/travel-agency-service/travel-agency-deployment.yaml
diff --git a/spring-cloud/spring-cloud-rest/spring-cloud-rest-books-api/src/test/java/org/baeldung/SpringContextLiveTest.java b/spring-cloud/spring-cloud-rest/spring-cloud-rest-books-api/src/test/java/org/baeldung/SpringContextLiveTest.java
new file mode 100644
index 0000000000..eb56c16c6a
--- /dev/null
+++ b/spring-cloud/spring-cloud-rest/spring-cloud-rest-books-api/src/test/java/org/baeldung/SpringContextLiveTest.java
@@ -0,0 +1,21 @@
+package org.baeldung;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+/**
+ *
+ * This Live Test requires:
+ * * A Redis instance running in port 6379 (e.g. using `docker run --name some-redis -p 6379:6379 -d redis`)
+ *
+ */
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = BooksApiApplication.class)
+public class SpringContextLiveTest {
+
+ @Test
+ public void whenSpringContextIsBootstrapped_thenNoExceptions() {
+ }
+}
diff --git a/spring-cloud/spring-cloud-rest/spring-cloud-rest-discovery-server/src/test/java/org/baeldung/SpringContextLiveTest.java b/spring-cloud/spring-cloud-rest/spring-cloud-rest-discovery-server/src/test/java/org/baeldung/SpringContextLiveTest.java
new file mode 100644
index 0000000000..01266a3bda
--- /dev/null
+++ b/spring-cloud/spring-cloud-rest/spring-cloud-rest-discovery-server/src/test/java/org/baeldung/SpringContextLiveTest.java
@@ -0,0 +1,21 @@
+package org.baeldung;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+/**
+ *
+ * This Live Test requires:
+ * * A Redis instance running in port 6379 (e.g. using `docker run --name some-redis -p 6379:6379 -d redis`)
+ *
+ */
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = SpringCloudRestServerApplication.class)
+public class SpringContextLiveTest {
+
+ @Test
+ public void whenSpringContextIsBootstrapped_thenNoExceptions() {
+ }
+}
diff --git a/spring-cloud/spring-cloud-rest/spring-cloud-rest-reviews-api/src/test/java/org/baeldung/SpringContextLiveTest.java b/spring-cloud/spring-cloud-rest/spring-cloud-rest-reviews-api/src/test/java/org/baeldung/SpringContextLiveTest.java
new file mode 100644
index 0000000000..070abd246f
--- /dev/null
+++ b/spring-cloud/spring-cloud-rest/spring-cloud-rest-reviews-api/src/test/java/org/baeldung/SpringContextLiveTest.java
@@ -0,0 +1,21 @@
+package org.baeldung;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+/**
+ *
+ * This Live Test requires:
+ * * A Redis instance running in port 6379 (e.g. using `docker run --name some-redis -p 6379:6379 -d redis`)
+ *
+ */
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = BookReviewsApiApplication.class)
+public class SpringContextLiveTest {
+
+ @Test
+ public void whenSpringContextIsBootstrapped_thenNoExceptions() {
+ }
+}
diff --git a/spring-cloud/spring-cloud-stream-starters/twitterhdfs/src/test/java/com/baeldung/twitterhdfs/aggregate/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-stream-starters/twitterhdfs/src/test/java/com/baeldung/twitterhdfs/aggregate/SpringContextIntegrationTest.java
new file mode 100644
index 0000000000..b5cef1b5ed
--- /dev/null
+++ b/spring-cloud/spring-cloud-stream-starters/twitterhdfs/src/test/java/com/baeldung/twitterhdfs/aggregate/SpringContextIntegrationTest.java
@@ -0,0 +1,15 @@
+package com.baeldung.twitterhdfs.aggregate;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = AggregateApp.class)
+public class SpringContextIntegrationTest {
+
+ @Test
+ public void whenSpringContextIsBootstrapped_thenNoExceptions() {
+ }
+}
diff --git a/spring-cloud/spring-cloud-stream-starters/twitterhdfs/src/test/java/org/baeldung/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-stream-starters/twitterhdfs/src/test/java/org/baeldung/SpringContextIntegrationTest.java
deleted file mode 100644
index 3d370e7b48..0000000000
--- a/spring-cloud/spring-cloud-stream-starters/twitterhdfs/src/test/java/org/baeldung/SpringContextIntegrationTest.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package org.baeldung;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.test.context.junit4.SpringRunner;
-
-import com.baeldung.twitterhdfs.aggregate.AggregateApp;
-import com.baeldung.twitterhdfs.processor.ProcessorApp;
-import com.baeldung.twitterhdfs.sink.SinkApp;
-import com.baeldung.twitterhdfs.source.SourceApp;
-
-@RunWith(SpringRunner.class)
-@SpringBootTest(classes = {AggregateApp.class, ProcessorApp.class, SinkApp.class, SourceApp.class})
-public class SpringContextIntegrationTest {
-
- @Test
- public void whenSpringContextIsBootstrapped_thenNoExceptions() {
- }
-}
diff --git a/spring-cloud/spring-cloud-zookeeper/README.md b/spring-cloud/spring-cloud-zookeeper/README.md
index a639833452..a49a448833 100644
--- a/spring-cloud/spring-cloud-zookeeper/README.md
+++ b/spring-cloud/spring-cloud-zookeeper/README.md
@@ -1,2 +1,2 @@
### Relevant Articles:
-- [An Introduction to Spring Cloud Zookeeper](http://www.baeldung.com/spring-cloud-zookeeper)
+- [An Intro to Spring Cloud Zookeeper](http://www.baeldung.com/spring-cloud-zookeeper)
diff --git a/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-client/pom.xml b/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-client/pom.xml
index 0b479ec226..af7df71d17 100644
--- a/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-client/pom.xml
+++ b/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-client/pom.xml
@@ -25,6 +25,13 @@
spring-boot-starter-web
${spring-boot-starter-web.version}
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ ${spring-boot-starter-web.version}
+ test
+
diff --git a/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-client/src/test/java/com/baeldung/spring/cloud/eureka/client/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-client/src/test/java/com/baeldung/spring/cloud/eureka/client/SpringContextIntegrationTest.java
new file mode 100644
index 0000000000..9eaff8f510
--- /dev/null
+++ b/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-client/src/test/java/com/baeldung/spring/cloud/eureka/client/SpringContextIntegrationTest.java
@@ -0,0 +1,16 @@
+package com.baeldung.spring.cloud.eureka.client;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class SpringContextIntegrationTest {
+
+ @Test
+ public void whenSpringContextIsBootstrapped_thenNoExceptions() {
+ }
+
+}
diff --git a/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-server/pom.xml b/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-server/pom.xml
index eea22779a6..d1f618507f 100644
--- a/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-server/pom.xml
+++ b/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-server/pom.xml
@@ -25,7 +25,13 @@
commons-configuration
${commons-config.version}
-
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ ${spring-boot-starter-web.version}
+ test
+
diff --git a/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-server/src/test/java/com/baeldung/spring/cloud/eureka/server/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-server/src/test/java/com/baeldung/spring/cloud/eureka/server/SpringContextIntegrationTest.java
new file mode 100644
index 0000000000..f03913b474
--- /dev/null
+++ b/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-server/src/test/java/com/baeldung/spring/cloud/eureka/server/SpringContextIntegrationTest.java
@@ -0,0 +1,16 @@
+package com.baeldung.spring.cloud.eureka.server;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class SpringContextIntegrationTest {
+
+ @Test
+ public void whenSpringContextIsBootstrapped_thenNoExceptions() {
+ }
+
+}
diff --git a/spring-cloud/spring-cloud-zuul-eureka-integration/zuul-server/pom.xml b/spring-cloud/spring-cloud-zuul-eureka-integration/zuul-server/pom.xml
index 39f94efdf0..57a11f3385 100644
--- a/spring-cloud/spring-cloud-zuul-eureka-integration/zuul-server/pom.xml
+++ b/spring-cloud/spring-cloud-zuul-eureka-integration/zuul-server/pom.xml
@@ -33,6 +33,13 @@
rxjava
${rxjava.version}
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ ${spring-boot-starter-web.version}
+ test
+
diff --git a/spring-cloud/spring-cloud-zuul-eureka-integration/zuul-server/src/test/java/com/baeldung/spring/cloud/zuul/config/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-zuul-eureka-integration/zuul-server/src/test/java/com/baeldung/spring/cloud/zuul/config/SpringContextIntegrationTest.java
new file mode 100644
index 0000000000..cfd362edf8
--- /dev/null
+++ b/spring-cloud/spring-cloud-zuul-eureka-integration/zuul-server/src/test/java/com/baeldung/spring/cloud/zuul/config/SpringContextIntegrationTest.java
@@ -0,0 +1,16 @@
+package com.baeldung.spring.cloud.zuul.config;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class SpringContextIntegrationTest {
+
+ @Test
+ public void whenSpringContextIsBootstrapped_thenNoExceptions() {
+ }
+
+}
diff --git a/spring-core/pom.xml b/spring-core/pom.xml
index d348d742e7..814addecdd 100644
--- a/spring-core/pom.xml
+++ b/spring-core/pom.xml
@@ -10,9 +10,9 @@
com.baeldung
- parent-spring-4
+ parent-spring-5
0.0.1-SNAPSHOT
- ../parent-spring-4
+ ../parent-spring-5
diff --git a/spring-data-rest/pom.xml b/spring-data-rest/pom.xml
index e563a6a3b5..525c88c9d8 100644
--- a/spring-data-rest/pom.xml
+++ b/spring-data-rest/pom.xml
@@ -1,9 +1,8 @@
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
spring-data-rest
-
1.0
spring-data-rest
jar
@@ -21,6 +20,10 @@
org.springframework.boot
spring-boot-starter
+
+ org.springframework.boot
+ spring-boot-starter-web
+
org.springframework.boot
spring-boot-starter-data-rest
@@ -30,12 +33,21 @@
spring-boot-starter-data-jpa
- com.h2database
- h2
+ org.springframework.boot
+ spring-boot-autoconfigure
org.springframework.boot
- spring-boot-autoconfigure
+ spring-boot-starter-test
+ test
+
+
+ com.querydsl
+ querydsl-apt
+
+
+ com.querydsl
+ querydsl-jpa
org.xerial
@@ -45,9 +57,33 @@
${project.artifactId}
+
+
+ com.mysema.maven
+ maven-apt-plugin
+ 1.0
+
+
+ generate-sources
+
+ process
+
+
+ target/generated-sources
+ com.querydsl.apt.jpa.JPAAnnotationProcessor
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+ UTF-8
com.baeldung.SpringDataRestApplication
diff --git a/spring-data-rest/src/main/java/com/baeldung/springdatawebsupport/application/Application.java b/spring-data-rest/src/main/java/com/baeldung/springdatawebsupport/application/Application.java
new file mode 100644
index 0000000000..fe2f996d37
--- /dev/null
+++ b/spring-data-rest/src/main/java/com/baeldung/springdatawebsupport/application/Application.java
@@ -0,0 +1,28 @@
+package com.baeldung.springdatawebsupport.application;
+
+import com.baeldung.springdatawebsupport.application.entities.User;
+import com.baeldung.springdatawebsupport.application.repositories.UserRepository;
+import java.util.stream.Stream;
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.Bean;
+
+@SpringBootApplication
+public class Application {
+
+ public static void main(String[] args) {
+ SpringApplication.run(Application.class, args);
+ }
+
+ @Bean
+ CommandLineRunner initialize(UserRepository userRepository) {
+ return args -> {
+ Stream.of("John", "Robert", "Nataly", "Helen", "Mary").forEach(name -> {
+ User user = new User(name);
+ userRepository.save(user);
+ });
+ userRepository.findAll().forEach(System.out::println);
+ };
+ }
+}
diff --git a/spring-data-rest/src/main/java/com/baeldung/springdatawebsupport/application/controllers/UserController.java b/spring-data-rest/src/main/java/com/baeldung/springdatawebsupport/application/controllers/UserController.java
new file mode 100644
index 0000000000..8258c3b7aa
--- /dev/null
+++ b/spring-data-rest/src/main/java/com/baeldung/springdatawebsupport/application/controllers/UserController.java
@@ -0,0 +1,47 @@
+package com.baeldung.springdatawebsupport.application.controllers;
+
+import com.baeldung.springdatawebsupport.application.entities.User;
+import com.baeldung.springdatawebsupport.application.repositories.UserRepository;
+import com.querydsl.core.types.Predicate;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.querydsl.binding.QuerydslPredicate;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+public class UserController {
+
+ private final UserRepository userRepository;
+
+ @Autowired
+ public UserController(UserRepository userRepository) {
+ this.userRepository = userRepository;
+ }
+
+ @GetMapping("/users/{id}")
+ public User findUserById(@PathVariable("id") User user) {
+ return user;
+ }
+
+ @GetMapping("/users")
+ public Page findAllUsers(Pageable pageable) {
+ return userRepository.findAll(pageable);
+ }
+
+ @GetMapping("/sortedusers")
+ public Page findAllUsersSortedByName() {
+ Pageable pageable = PageRequest.of(0, 5, Sort.by("name"));
+ return userRepository.findAll(pageable);
+ }
+
+ @GetMapping("/filteredusers")
+ public Iterable getUsersByQuerydslPredicate(@QuerydslPredicate(root = User.class) Predicate predicate) {
+ return userRepository.findAll(predicate);
+ }
+}
diff --git a/spring-data-rest/src/main/java/com/baeldung/springdatawebsupport/application/entities/User.java b/spring-data-rest/src/main/java/com/baeldung/springdatawebsupport/application/entities/User.java
new file mode 100644
index 0000000000..e9aaeb119a
--- /dev/null
+++ b/spring-data-rest/src/main/java/com/baeldung/springdatawebsupport/application/entities/User.java
@@ -0,0 +1,38 @@
+package com.baeldung.springdatawebsupport.application.entities;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name = "users")
+public class User {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ private long id;
+ private final String name;
+
+ public User() {
+ this.name = "";
+ }
+
+ public User(String name) {
+ this.name = name;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public String toString() {
+ return "User{" + "id=" + id + ", name=" + name + '}';
+ }
+}
diff --git a/spring-data-rest/src/main/java/com/baeldung/springdatawebsupport/application/repositories/UserRepository.java b/spring-data-rest/src/main/java/com/baeldung/springdatawebsupport/application/repositories/UserRepository.java
new file mode 100644
index 0000000000..41d7ed9d98
--- /dev/null
+++ b/spring-data-rest/src/main/java/com/baeldung/springdatawebsupport/application/repositories/UserRepository.java
@@ -0,0 +1,14 @@
+package com.baeldung.springdatawebsupport.application.repositories;
+
+import com.baeldung.springdatawebsupport.application.entities.User;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.querydsl.QuerydslPredicateExecutor;
+import org.springframework.data.repository.PagingAndSortingRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface UserRepository extends PagingAndSortingRepository,
+ QuerydslPredicateExecutor {
+
+}
diff --git a/spring-data-rest/src/test/java/com/baeldung/springdatawebsupport/application/test/UserControllerIntegrationTest.java b/spring-data-rest/src/test/java/com/baeldung/springdatawebsupport/application/test/UserControllerIntegrationTest.java
new file mode 100644
index 0000000000..db522b1413
--- /dev/null
+++ b/spring-data-rest/src/test/java/com/baeldung/springdatawebsupport/application/test/UserControllerIntegrationTest.java
@@ -0,0 +1,74 @@
+package com.baeldung.springdatawebsupport.application.test;
+
+import com.baeldung.springdatawebsupport.application.controllers.UserController;
+import static org.assertj.core.api.Assertions.assertThat;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.http.MediaType;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
+import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+@AutoConfigureMockMvc
+public class UserControllerIntegrationTest {
+
+ @Autowired
+ private UserController userController;
+
+ @Autowired
+ private MockMvc mockMvc;
+
+ @Test
+ public void whenUserControllerInjected_thenNotNull() throws Exception {
+ assertThat(userController).isNotNull();
+ }
+
+ @Test
+ public void whenGetRequestToUsersEndPointWithIdPathVariable_thenCorrectResponse() throws Exception {
+ mockMvc.perform(MockMvcRequestBuilders.get("/users/{id}", "1")
+ .contentType(MediaType.APPLICATION_JSON_UTF8))
+ .andExpect(MockMvcResultMatchers.status().isOk())
+ .andExpect(MockMvcResultMatchers.jsonPath("$.id").value("1"));
+ }
+
+ @Test
+ public void whenGetRequestToUsersEndPoint_thenCorrectResponse() throws Exception {
+ mockMvc.perform(MockMvcRequestBuilders.get("/users")
+ .contentType(MediaType.APPLICATION_JSON_UTF8))
+ .andExpect(MockMvcResultMatchers.status().isOk())
+ .andExpect(MockMvcResultMatchers.jsonPath("$['pageable']['paged']").value("true"));
+
+ }
+
+ @Test
+ public void whenGetRequestToUserEndPointWithNameRequestParameter_thenCorrectResponse() throws Exception {
+ mockMvc.perform(MockMvcRequestBuilders.get("/user")
+ .param("name", "John")
+ .contentType(MediaType.APPLICATION_JSON_UTF8))
+ .andExpect(MockMvcResultMatchers.status().isOk())
+ .andExpect(MockMvcResultMatchers.jsonPath("$['content'][0].['name']").value("John"));
+ }
+
+ @Test
+ public void whenGetRequestToSorteredUsersEndPoint_thenCorrectResponse() throws Exception {
+ mockMvc.perform(MockMvcRequestBuilders.get("/sortedusers")
+ .contentType(MediaType.APPLICATION_JSON_UTF8))
+ .andExpect(MockMvcResultMatchers.status().isOk())
+ .andExpect(MockMvcResultMatchers.jsonPath("$['sort']['sorted']").value("true"));
+ }
+
+ @Test
+ public void whenGetRequestToFilteredUsersEndPoint_thenCorrectResponse() throws Exception {
+ mockMvc.perform(MockMvcRequestBuilders.get("/filteredusers")
+ .param("name", "John")
+ .contentType(MediaType.APPLICATION_JSON_UTF8))
+ .andExpect(MockMvcResultMatchers.status().isOk())
+ .andExpect(MockMvcResultMatchers.jsonPath("$[0].name").value("John"));
+ }
+}
diff --git a/spring-freemarker/pom.xml b/spring-freemarker/pom.xml
index c71643dc39..40558476ef 100644
--- a/spring-freemarker/pom.xml
+++ b/spring-freemarker/pom.xml
@@ -48,7 +48,7 @@
org.springframework.boot
spring-boot-starter-test
- 1.5.10.RELEASE
+ ${spring-boot.version}
test
@@ -59,6 +59,7 @@
2.3.28
3.1.0
false
+ 1.5.10.RELEASE
diff --git a/spring-jersey/pom.xml b/spring-jersey/pom.xml
index c12f6a1241..5a12d27180 100644
--- a/spring-jersey/pom.xml
+++ b/spring-jersey/pom.xml
@@ -95,28 +95,28 @@
com.github.tomakehurst
wiremock
- 1.58
+ ${wiremock.version}
test
com.fasterxml.jackson.jaxrs
jackson-jaxrs-json-provider
- 2.9.7
+ ${jackson.version}
com.fasterxml.jackson.core
jackson-databind
- 2.9.7
+ ${jackson.version}
org.slf4j
slf4j-jdk14
- 1.7.25
+ ${org.slf4j.version}
org.assertj
assertj-core
- 3.10.0
+ ${assertj-core.version}
test
@@ -124,7 +124,7 @@
org.springframework.boot
spring-boot-starter-test
- 1.5.10.RELEASE
+ ${spring-boot.version}
test
@@ -228,6 +228,9 @@
4.4.9
4.5.5
4.0.0
+ 1.58
+ 3.10.0
+ 1.5.10.RELEASE
diff --git a/spring-mvc-java/README.md b/spring-mvc-java/README.md
index 497b0f4c1f..3deeb21afc 100644
--- a/spring-mvc-java/README.md
+++ b/spring-mvc-java/README.md
@@ -19,7 +19,7 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
- [Introduction to HtmlUnit](http://www.baeldung.com/htmlunit)
- [Spring @RequestMapping New Shortcut Annotations](http://www.baeldung.com/spring-new-requestmapping-shortcuts)
- [Guide to Spring Handler Mappings](http://www.baeldung.com/spring-handler-mappings)
-- [Uploading and Displaying Excel Files with Spring MVC](http://www.baeldung.com/spring-mvc-excel-files)
+- [Upload and Display Excel Files with Spring MVC](http://www.baeldung.com/spring-mvc-excel-files)
- [Spring MVC Custom Validation](http://www.baeldung.com/spring-mvc-custom-validator)
- [web.xml vs Initializer with Spring](http://www.baeldung.com/spring-xml-vs-java-config)
- [The HttpMediaTypeNotAcceptableException in Spring MVC](http://www.baeldung.com/spring-httpmediatypenotacceptable)
@@ -31,3 +31,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
- [Using Spring @ResponseStatus to Set HTTP Status Code](http://www.baeldung.com/spring-response-status)
- [Spring MVC Tutorial](https://www.baeldung.com/spring-mvc-tutorial)
- [Working with Date Parameters in Spring](https://www.baeldung.com/spring-date-parameters)
+- [A Java Web Application Without a web.xml](https://www.baeldung.com/java-web-app-without-web-xml)
diff --git a/javax-servlets/src/main/java/com/baeldung/filters/EmptyParamFilter.java b/spring-mvc-java/src/main/java/com/baeldung/filters/EmptyParamFilter.java
similarity index 100%
rename from javax-servlets/src/main/java/com/baeldung/filters/EmptyParamFilter.java
rename to spring-mvc-java/src/main/java/com/baeldung/filters/EmptyParamFilter.java
diff --git a/javax-servlets/src/main/java/com/baeldung/listeners/AppListener.java b/spring-mvc-java/src/main/java/com/baeldung/listeners/AppListener.java
similarity index 100%
rename from javax-servlets/src/main/java/com/baeldung/listeners/AppListener.java
rename to spring-mvc-java/src/main/java/com/baeldung/listeners/AppListener.java
diff --git a/javax-servlets/src/main/java/com/baeldung/listeners/RequestListener.java b/spring-mvc-java/src/main/java/com/baeldung/listeners/RequestListener.java
similarity index 100%
rename from javax-servlets/src/main/java/com/baeldung/listeners/RequestListener.java
rename to spring-mvc-java/src/main/java/com/baeldung/listeners/RequestListener.java
diff --git a/javax-servlets/src/main/java/com/baeldung/servlets/CounterServlet.java b/spring-mvc-java/src/main/java/com/baeldung/servlets/CounterServlet.java
similarity index 100%
rename from javax-servlets/src/main/java/com/baeldung/servlets/CounterServlet.java
rename to spring-mvc-java/src/main/java/com/baeldung/servlets/CounterServlet.java
diff --git a/javax-servlets/src/main/java/com/baeldung/servlets/UppercaseServlet.java b/spring-mvc-java/src/main/java/com/baeldung/servlets/UppercaseServlet.java
similarity index 100%
rename from javax-servlets/src/main/java/com/baeldung/servlets/UppercaseServlet.java
rename to spring-mvc-java/src/main/java/com/baeldung/servlets/UppercaseServlet.java
diff --git a/spring-mvc-simple-2/pom.xml b/spring-mvc-simple-2/pom.xml
new file mode 100644
index 0000000000..74302cff78
--- /dev/null
+++ b/spring-mvc-simple-2/pom.xml
@@ -0,0 +1,37 @@
+
+
+ 4.0.0
+ spring-mvc-simple-2
+ war
+ spring-mvc-simple-2
+
+
+ com.baeldung
+ parent-boot-2
+ 0.0.1-SNAPSHOT
+ ../parent-boot-2
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+
+ 1.8
+ 1.8
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-war-plugin
+
+
+ spring-mvc-simple2
+
+
diff --git a/spring-mvc-simple-2/src/main/java/com/baeldung/spring/Application.java b/spring-mvc-simple-2/src/main/java/com/baeldung/spring/Application.java
new file mode 100644
index 0000000000..40a0a55761
--- /dev/null
+++ b/spring-mvc-simple-2/src/main/java/com/baeldung/spring/Application.java
@@ -0,0 +1,11 @@
+package com.baeldung.spring;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class Application {
+ public static void main(String[] args) {
+ SpringApplication.run(Application.class, args);
+ }
+}
diff --git a/spring-mvc-simple-2/src/main/java/com/baeldung/spring/headers/controller/ReadHeaderRestController.java b/spring-mvc-simple-2/src/main/java/com/baeldung/spring/headers/controller/ReadHeaderRestController.java
new file mode 100644
index 0000000000..6a0f3b6a0d
--- /dev/null
+++ b/spring-mvc-simple-2/src/main/java/com/baeldung/spring/headers/controller/ReadHeaderRestController.java
@@ -0,0 +1,97 @@
+package com.baeldung.spring.headers.controller;
+
+import java.net.InetSocketAddress;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.util.MultiValueMap;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestHeader;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+public class ReadHeaderRestController {
+ private static final Log LOG = LogFactory.getLog(ReadHeaderRestController.class);
+
+ @GetMapping("/")
+ public ResponseEntity index() {
+ return new ResponseEntity("Index", HttpStatus.OK);
+ }
+
+ @GetMapping("/greeting")
+ public ResponseEntity greeting(@RequestHeader(value = "accept-language") String language) {
+ String greeting = "";
+ String firstLanguage = (language.length() > 1 ? language.substring(0, 2) : language);
+ switch (firstLanguage) {
+ case "es":
+ greeting = "Hola!";
+ break;
+ case "de":
+ greeting = "Hallo!";
+ break;
+ case "fr":
+ greeting = "Bonjour!";
+ break;
+ case "en":
+ default:
+ greeting = "Hello!";
+ break;
+ }
+
+ return new ResponseEntity(greeting, HttpStatus.OK);
+ }
+
+ @GetMapping("/double")
+ public ResponseEntity doubleNumber(@RequestHeader("my-number") int myNumber) {
+ return new ResponseEntity(
+ String.format("%d * 2 = %d", myNumber, (myNumber * 2)),
+ HttpStatus.OK);
+ }
+
+ @GetMapping("/listHeaders")
+ public ResponseEntity listAllHeaders(@RequestHeader Map headers) {
+
+ headers.forEach((key, value) -> {
+ LOG.info(String.format("Header '%s' = %s", key, value));
+ });
+
+ return new ResponseEntity(String.format("Listed %d headers", headers.size()), HttpStatus.OK);
+ }
+
+ @GetMapping("/multiValue")
+ public ResponseEntity multiValue(@RequestHeader MultiValueMap headers) {
+ headers.forEach((key, value) -> {
+ LOG.info(String.format("Header '%s' = %s", key, value.stream().collect(Collectors.joining("|"))));
+ });
+
+ return new ResponseEntity(String.format("Listed %d headers", headers.size()), HttpStatus.OK);
+ }
+
+ @GetMapping("/getBaseUrl")
+ public ResponseEntity getBaseUrl(@RequestHeader HttpHeaders headers) {
+ InetSocketAddress host = headers.getHost();
+ String url = "http://" + host.getHostName() + ":" + host.getPort();
+ return new ResponseEntity(String.format("Base URL = %s", url), HttpStatus.OK);
+ }
+
+ @GetMapping("/nonRequiredHeader")
+ public ResponseEntity evaluateNonRequiredHeader(
+ @RequestHeader(value = "optional-header", required = false) String optionalHeader) {
+
+ return new ResponseEntity(
+ String.format("Was the optional header present? %s!", (optionalHeader == null ? "No" : "Yes")),
+ HttpStatus.OK);
+ }
+
+ @GetMapping("/default")
+ public ResponseEntity evaluateDefaultHeaderValue(
+ @RequestHeader(value = "optional-header", defaultValue = "3600") int optionalHeader) {
+
+ return new ResponseEntity(String.format("Optional Header is %d", optionalHeader), HttpStatus.OK);
+ }
+}
diff --git a/spring-mvc-simple-2/src/test/java/com/baeldung/AppContextIntegrationTest.java b/spring-mvc-simple-2/src/test/java/com/baeldung/AppContextIntegrationTest.java
new file mode 100644
index 0000000000..27207688e6
--- /dev/null
+++ b/spring-mvc-simple-2/src/test/java/com/baeldung/AppContextIntegrationTest.java
@@ -0,0 +1,13 @@
+package com.baeldung;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+
+import com.baeldung.spring.Application;
+
+@SpringBootTest(classes = Application.class)
+public class AppContextIntegrationTest {
+ @Test
+ public void contextLoads() {
+ }
+}
diff --git a/spring-mvc-simple-2/src/test/java/com/baeldung/headers/controller/ReadHeaderRestControllerIntegrationTest.java b/spring-mvc-simple-2/src/test/java/com/baeldung/headers/controller/ReadHeaderRestControllerIntegrationTest.java
new file mode 100644
index 0000000000..6f94004cc7
--- /dev/null
+++ b/spring-mvc-simple-2/src/test/java/com/baeldung/headers/controller/ReadHeaderRestControllerIntegrationTest.java
@@ -0,0 +1,86 @@
+package com.baeldung.headers.controller;
+
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.setup.MockMvcBuilders;
+
+import com.baeldung.spring.headers.controller.ReadHeaderRestController;
+
+@SpringJUnitWebConfig(ReadHeaderRestControllerIntegrationTest.Config.class)
+@ExtendWith(SpringExtension.class)
+public class ReadHeaderRestControllerIntegrationTest {
+ private static final Log LOG = LogFactory.getLog(ReadHeaderRestControllerIntegrationTest.class);
+
+ @Configuration
+ static class Config {
+
+ }
+
+ private MockMvc mockMvc;
+
+ @BeforeEach
+ public void setUp() {
+ mockMvc = MockMvcBuilders.standaloneSetup(new ReadHeaderRestController())
+ .build();
+ }
+
+ @Test
+ public void whenGetRequestSentToAllHeaders_thenStatusOkAndTextReturned() throws Exception {
+ mockMvc.perform(get("/listHeaders").header("my-header", "Test"))
+ .andExpect(status().isOk())
+ .andExpect(content().string("Listed 1 headers"));
+ }
+
+ @Test
+ public void whenGetRequestSentToMultiValue_thenStatusOkAndTextReturned() throws Exception {
+ mockMvc.perform(get("/multiValue").header("my-header", "ABC", "DEF", "GHI"))
+ .andExpect(status().isOk())
+ .andExpect(content().string("Listed 1 headers"));
+ }
+
+ @Test
+ public void whenGetRequestSentToGreeting_thenStatusOKAndGreetingReturned() throws Exception {
+ mockMvc.perform(get("/greeting").header("accept-language", "de"))
+ .andExpect(status().isOk())
+ .andExpect(content().string("Hallo!"));
+ }
+
+ @Test
+ public void whenGetRequestSentToDouble_thenStatusOKAndCorrectResultReturned() throws Exception {
+ mockMvc.perform(get("/double").header("my-number", 2))
+ .andExpect(status().isOk())
+ .andExpect(content().string("2 * 2 = 4"));
+ }
+
+ @Test
+ public void whenGetRequestSentToGetBaseUrl_thenStatusOkAndHostReturned() throws Exception {
+ mockMvc.perform(get("/getBaseUrl").header("host", "localhost:8080"))
+ .andExpect(status().isOk())
+ .andExpect(content().string("Base URL = http://localhost:8080"));
+ }
+
+ @Test
+ public void whenGetRequestSentToNonRequiredHeaderWithoutHeader_thenStatusOKAndMessageReturned() throws Exception {
+ mockMvc.perform(get("/nonRequiredHeader"))
+ .andExpect(status().isOk())
+ .andExpect(content().string("Was the optional header present? No!"));
+ }
+
+ @Test
+ public void whenGetRequestSentToDefaultWithoutHeader_thenStatusOKAndMessageReturned() throws Exception {
+ mockMvc.perform(get("/default"))
+ .andExpect(status().isOk())
+ .andExpect(content().string("Optional Header is 3600"));
+ }
+}
diff --git a/spring-mvc-simple/pom.xml b/spring-mvc-simple/pom.xml
index b9ed3a3e81..cdd4a9e13a 100644
--- a/spring-mvc-simple/pom.xml
+++ b/spring-mvc-simple/pom.xml
@@ -22,7 +22,7 @@
com.sun.mail
javax.mail
- 1.6.1
+ ${javax.mail.version}
javax.servlet
@@ -182,6 +182,7 @@
5.1.0
20180130
3.0.8
+ 1.6.1
diff --git a/spring-mvc-xml/README.md b/spring-mvc-xml/README.md
index dbc6125424..216517f52d 100644
--- a/spring-mvc-xml/README.md
+++ b/spring-mvc-xml/README.md
@@ -14,3 +14,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
- [Guide to JavaServer Pages (JSP)](http://www.baeldung.com/jsp)
- [Exploring SpringMVC’s Form Tag Library](http://www.baeldung.com/spring-mvc-form-tags)
- [web.xml vs Initializer with Spring](http://www.baeldung.com/spring-xml-vs-java-config)
+- [A Java Web Application Without a web.xml](https://www.baeldung.com/java-web-app-without-web-xml)
diff --git a/spring-mvc-xml/pom.xml b/spring-mvc-xml/pom.xml
index c6a6da406c..beea8e5ee2 100644
--- a/spring-mvc-xml/pom.xml
+++ b/spring-mvc-xml/pom.xml
@@ -88,7 +88,7 @@
org.springframework.boot
spring-boot-starter-test
- 1.5.10.RELEASE
+ ${spring-boot.version}
test
@@ -118,6 +118,7 @@
5.0.2.RELEASE
+ 1.5.10.RELEASE
5.1.40
diff --git a/spring-reactor/pom.xml b/spring-reactor/pom.xml
index 051244c9db..2d69096c58 100644
--- a/spring-reactor/pom.xml
+++ b/spring-reactor/pom.xml
@@ -27,12 +27,17 @@
io.projectreactor
reactor-bus
- 2.0.8.RELEASE
+ ${reactor.version}
io.projectreactor
reactor-core
- 2.0.8.RELEASE
+ ${reactor.version}
+
+
+ 2.0.2.RELEASE
+ 2.0.8.RELEASE
+
diff --git a/spring-remoting/remoting-hessian-burlap/remoting-hessian-burlap-server/pom.xml b/spring-remoting/remoting-hessian-burlap/remoting-hessian-burlap-server/pom.xml
index 33b824442f..fa16a9a9b1 100644
--- a/spring-remoting/remoting-hessian-burlap/remoting-hessian-burlap-server/pom.xml
+++ b/spring-remoting/remoting-hessian-burlap/remoting-hessian-burlap-server/pom.xml
@@ -25,7 +25,12 @@
com.caucho
hessian
- 4.0.38
+ ${hessian.version}
+
+
+ 4.0.38
+
+
\ No newline at end of file
diff --git a/spring-rest-hal-browser/pom.xml b/spring-rest-hal-browser/pom.xml
index 413aad9e8c..cc3b1b65fe 100644
--- a/spring-rest-hal-browser/pom.xml
+++ b/spring-rest-hal-browser/pom.xml
@@ -8,6 +8,13 @@
1.0-SNAPSHOT
spring-rest-hal-browser
+
+ parent-boot-1
+ com.baeldung
+ 0.0.1-SNAPSHOT
+ ../parent-boot-1
+
+
diff --git a/spring-rest-shell/README.md b/spring-rest-shell/README.md
index 901d9a51ee..b250f06a4b 100644
--- a/spring-rest-shell/README.md
+++ b/spring-rest-shell/README.md
@@ -2,4 +2,4 @@
### Relevant Articles
-- [Spring REST Shell](http://www.baeldung.com/spring-rest-shell)
\ No newline at end of file
+- [Introduction to Spring REST Shell](http://www.baeldung.com/spring-rest-shell)
diff --git a/spring-rest/README.md b/spring-rest/README.md
index 9a2c1fd96c..6d3aac3eb8 100644
--- a/spring-rest/README.md
+++ b/spring-rest/README.md
@@ -20,5 +20,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
- [Using the Spring RestTemplate Interceptor](http://www.baeldung.com/spring-rest-template-interceptor)
- [Get and Post Lists of Objects with RestTemplate](http://www.baeldung.com/spring-rest-template-list)
- [How to Set a Header on a Response with Spring 5](http://www.baeldung.com/spring-response-header)
-- [Spring’s RequestBody and ResponseBody Annotations](https://www.baeldung.com/spring-request-response-body)
- [Uploading MultipartFile with Spring RestTemplate](http://www.baeldung.com/spring-rest-template-multipart-upload)
diff --git a/spring-security-kerberos/README.md b/spring-security-kerberos/README.md
new file mode 100644
index 0000000000..0338c2058c
--- /dev/null
+++ b/spring-security-kerberos/README.md
@@ -0,0 +1,10 @@
+## @PreFilter and @PostFilter annotations
+
+### Build the Project ###
+
+```
+mvn clean install
+```
+
+### Relevant Articles:
+- [Spring Security – Kerberos](http://www.baeldung.com/xxxxxx)
diff --git a/spring-security-kerberos/pom.xml b/spring-security-kerberos/pom.xml
new file mode 100644
index 0000000000..35c4ba4926
--- /dev/null
+++ b/spring-security-kerberos/pom.xml
@@ -0,0 +1,61 @@
+
+ 4.0.0
+ com.baeldung
+ spring-security-kerberos
+ 0.1-SNAPSHOT
+ spring-security-kerberos
+ war
+
+ parent-boot-1
+ com.baeldung
+ 0.0.1-SNAPSHOT
+ ../parent-boot-1
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ org.springframework.boot
+ spring-boot-starter-security
+
+
+
+ org.springframework.security.kerberos
+ spring-security-kerberos-core
+ 1.0.1.RELEASE
+
+
+ org.springframework.security.kerberos
+ spring-security-kerberos-web
+ 1.0.1.RELEASE
+
+
+ org.springframework.security.kerberos
+ spring-security-kerberos-client
+ 1.0.1.RELEASE
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+ org.springframework.security
+ spring-security-test
+ test
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-war-plugin
+
+
+
+
diff --git a/spring-security-kerberos/src/main/java/org/baeldung/Application.java b/spring-security-kerberos/src/main/java/org/baeldung/Application.java
new file mode 100644
index 0000000000..39c2b51356
--- /dev/null
+++ b/spring-security-kerberos/src/main/java/org/baeldung/Application.java
@@ -0,0 +1,13 @@
+package org.baeldung;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class Application {
+
+ public static void main(String[] args) {
+ SpringApplication.run(Application.class, args);
+ }
+
+}
diff --git a/spring-security-kerberos/src/main/java/org/baeldung/config/WebSecurityConfig.java b/spring-security-kerberos/src/main/java/org/baeldung/config/WebSecurityConfig.java
new file mode 100644
index 0000000000..49a1cf0a8e
--- /dev/null
+++ b/spring-security-kerberos/src/main/java/org/baeldung/config/WebSecurityConfig.java
@@ -0,0 +1,87 @@
+package org.baeldung.config;
+
+import org.baeldung.security.DummyUserDetailsService;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.io.FileSystemResource;
+import org.springframework.security.authentication.AuthenticationManager;
+import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
+import org.springframework.security.config.annotation.web.builders.HttpSecurity;
+import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
+import org.springframework.security.kerberos.authentication.KerberosAuthenticationProvider;
+import org.springframework.security.kerberos.authentication.KerberosServiceAuthenticationProvider;
+import org.springframework.security.kerberos.authentication.sun.SunJaasKerberosClient;
+import org.springframework.security.kerberos.authentication.sun.SunJaasKerberosTicketValidator;
+import org.springframework.security.kerberos.web.authentication.SpnegoAuthenticationProcessingFilter;
+import org.springframework.security.kerberos.web.authentication.SpnegoEntryPoint;
+import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
+
+@Configuration
+public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
+
+ @Override
+ protected void configure(HttpSecurity http) throws Exception {
+ http.authorizeRequests()
+ .anyRequest()
+ .authenticated()
+ .and()
+ .addFilterBefore(spnegoAuthenticationProcessingFilter(authenticationManagerBean()), BasicAuthenticationFilter.class);
+ }
+
+ @Override
+ @Bean
+ public AuthenticationManager authenticationManagerBean() throws Exception {
+ return super.authenticationManagerBean();
+ }
+
+ @Override
+ protected void configure(AuthenticationManagerBuilder auth) throws Exception {
+ auth.authenticationProvider(kerberosAuthenticationProvider())
+ .authenticationProvider(kerberosServiceAuthenticationProvider());
+ }
+
+ @Bean
+ public KerberosAuthenticationProvider kerberosAuthenticationProvider() {
+ KerberosAuthenticationProvider provider = new KerberosAuthenticationProvider();
+ SunJaasKerberosClient client = new SunJaasKerberosClient();
+ client.setDebug(true);
+ provider.setKerberosClient(client);
+ provider.setUserDetailsService(dummyUserDetailsService());
+ return provider;
+ }
+
+ @Bean
+ public SpnegoEntryPoint spnegoEntryPoint() {
+ return new SpnegoEntryPoint("/login");
+ }
+
+ @Bean
+ public SpnegoAuthenticationProcessingFilter spnegoAuthenticationProcessingFilter(AuthenticationManager authenticationManager) {
+ SpnegoAuthenticationProcessingFilter filter = new SpnegoAuthenticationProcessingFilter();
+ filter.setAuthenticationManager(authenticationManager);
+ return filter;
+ }
+
+ @Bean
+ public KerberosServiceAuthenticationProvider kerberosServiceAuthenticationProvider() {
+ KerberosServiceAuthenticationProvider provider = new KerberosServiceAuthenticationProvider();
+ provider.setTicketValidator(sunJaasKerberosTicketValidator());
+ provider.setUserDetailsService(dummyUserDetailsService());
+ return provider;
+ }
+
+ @Bean
+ public SunJaasKerberosTicketValidator sunJaasKerberosTicketValidator() {
+ SunJaasKerberosTicketValidator ticketValidator = new SunJaasKerberosTicketValidator();
+ ticketValidator.setServicePrincipal("HTTP/demo.kerberos.bealdung.com@baeldung.com");
+ ticketValidator.setKeyTabLocation(new FileSystemResource("baeldung.keytab"));
+ ticketValidator.setDebug(true);
+ return ticketValidator;
+ }
+
+ @Bean
+ public DummyUserDetailsService dummyUserDetailsService() {
+ return new DummyUserDetailsService();
+ }
+
+}
\ No newline at end of file
diff --git a/spring-security-kerberos/src/main/java/org/baeldung/security/DummyUserDetailsService.java b/spring-security-kerberos/src/main/java/org/baeldung/security/DummyUserDetailsService.java
new file mode 100644
index 0000000000..10d71fca8f
--- /dev/null
+++ b/spring-security-kerberos/src/main/java/org/baeldung/security/DummyUserDetailsService.java
@@ -0,0 +1,16 @@
+package org.baeldung.security;
+
+import org.springframework.security.core.authority.AuthorityUtils;
+import org.springframework.security.core.userdetails.User;
+import org.springframework.security.core.userdetails.UserDetails;
+import org.springframework.security.core.userdetails.UserDetailsService;
+import org.springframework.security.core.userdetails.UsernameNotFoundException;
+
+public class DummyUserDetailsService implements UserDetailsService {
+
+ @Override
+ public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
+ return new User(username, "notUsed", true, true, true, true, AuthorityUtils.createAuthorityList("ROLE_USER"));
+ }
+
+}
\ No newline at end of file
diff --git a/spring-security-mvc-jsonview/pom.xml b/spring-security-mvc-jsonview/pom.xml
index b6d3e7e399..8fa7b4ffb5 100644
--- a/spring-security-mvc-jsonview/pom.xml
+++ b/spring-security-mvc-jsonview/pom.xml
@@ -20,17 +20,17 @@
com.fasterxml.jackson.core
jackson-core
- 2.9.7
+ ${jackson.version}
com.fasterxml.jackson.core
jackson-annotations
- 2.9.7
+ ${jackson.version}
com.fasterxml.jackson.core
jackson-databind
- 2.9.7
+ ${jackson.version}
@@ -139,7 +139,7 @@
com.jayway.jsonpath
json-path
- 2.4.0
+ ${json-path.version}
test
@@ -213,6 +213,7 @@
2.6
1.6.1
+ 2.4.0
diff --git a/spring-security-mvc-ldap/README.md b/spring-security-mvc-ldap/README.md
index ac080c138d..6f03143183 100644
--- a/spring-security-mvc-ldap/README.md
+++ b/spring-security-mvc-ldap/README.md
@@ -5,7 +5,7 @@
The "Learn Spring Security" Classes: http://github.learnspringsecurity.com
### Relevant Article:
-- [Spring Security - security none, filters none, access permitAll](http://www.baeldung.com/security-none-filters-none-access-permitAll)
+- [Spring Security – security none, filters none, access permitAll](http://www.baeldung.com/security-none-filters-none-access-permitAll)
- [Intro to Spring Security LDAP](http://www.baeldung.com/spring-security-ldap)
### Notes
diff --git a/spring-security-mvc-login/README.md b/spring-security-mvc-login/README.md
index c19cbc87a5..983d949cb8 100644
--- a/spring-security-mvc-login/README.md
+++ b/spring-security-mvc-login/README.md
@@ -10,7 +10,7 @@ The "Learn Spring Security" Classes: http://github.learnspringsecurity.com
- [Spring Security Logout](http://www.baeldung.com/spring-security-logout)
- [Spring Security Expressions – hasRole Example](http://www.baeldung.com/spring-security-expressions-basic)
- [Spring HTTP/HTTPS Channel Security](http://www.baeldung.com/spring-channel-security-https)
-- [Spring Security - Customize the 403 Forbidden/Access Denied Page](http://www.baeldung.com/spring-security-custom-access-denied-page)
+- [Spring Security – Customize the 403 Forbidden/Access Denied Page](http://www.baeldung.com/spring-security-custom-access-denied-page)
- [Spring Security – Redirect to the Previous URL After Login](http://www.baeldung.com/spring-security-redirect-login)
- [Spring Security Custom AuthenticationFailureHandler](http://www.baeldung.com/spring-security-custom-authentication-failure-handler)
diff --git a/spring-security-mvc-persisted-remember-me/README.md b/spring-security-mvc-persisted-remember-me/README.md
index e505537be1..db2ae890f9 100644
--- a/spring-security-mvc-persisted-remember-me/README.md
+++ b/spring-security-mvc-persisted-remember-me/README.md
@@ -6,7 +6,7 @@
The "Learn Spring Security" Classes: http://github.learnspringsecurity.com
### Relevant Articles:
-- [Spring Security Persisted Remember Me](http://www.baeldung.com/spring-security-persistent-remember-me)
+- [Spring Security – Persistent Remember Me](http://www.baeldung.com/spring-security-persistent-remember-me)
### Build the Project
```
diff --git a/spring-security-mvc-persisted-remember-me/pom.xml b/spring-security-mvc-persisted-remember-me/pom.xml
index c65b7a30cb..d10565255d 100644
--- a/spring-security-mvc-persisted-remember-me/pom.xml
+++ b/spring-security-mvc-persisted-remember-me/pom.xml
@@ -137,7 +137,7 @@
org.springframework.boot
spring-boot-starter-test
- 1.5.10.RELEASE
+ ${spring-boot.version}
test
@@ -211,7 +211,7 @@
2.6
1.6.1
-
+ 1.5.10.RELEASE
\ No newline at end of file
diff --git a/spring-security-sso/README.md b/spring-security-sso/README.md
index 11b5f011d5..d0c1b2f7cf 100644
--- a/spring-security-sso/README.md
+++ b/spring-security-sso/README.md
@@ -1,2 +1,2 @@
### Relevant Articles:
-- [Simple Single Sign On with Spring Security OAuth2](http://www.baeldung.com/sso-spring-security-oauth2)
+- [Simple Single Sign-On with Spring Security OAuth2](http://www.baeldung.com/sso-spring-security-oauth2)
diff --git a/spring-security-sso/spring-security-sso-kerberos/src/main/java/kerberos/client/KerberosClientApp.java b/spring-security-sso/spring-security-sso-kerberos/src/main/java/kerberos/client/KerberosClientApp.java
index a353961854..9fb86e7658 100644
--- a/spring-security-sso/spring-security-sso-kerberos/src/main/java/kerberos/client/KerberosClientApp.java
+++ b/spring-security-sso/spring-security-sso-kerberos/src/main/java/kerberos/client/KerberosClientApp.java
@@ -12,6 +12,8 @@ class KerberosClientApp {
System.setProperty("java.security.krb5.conf",
Paths.get(".\\krb-test-workdir\\krb5.conf").normalize().toAbsolutePath().toString());
System.setProperty("sun.security.krb5.debug", "true");
+ // disable usage of local kerberos ticket cache
+ System.setProperty("http.use.global.creds", "false");
}
public static void main(String[] args) {
diff --git a/spring-security-sso/spring-security-sso-kerberos/src/main/java/kerberos/client/SampleService.java b/spring-security-sso/spring-security-sso-kerberos/src/main/java/kerberos/client/SampleClient.java
similarity index 87%
rename from spring-security-sso/spring-security-sso-kerberos/src/main/java/kerberos/client/SampleService.java
rename to spring-security-sso/spring-security-sso-kerberos/src/main/java/kerberos/client/SampleClient.java
index 4145cf0c1a..745193e3b0 100644
--- a/spring-security-sso/spring-security-sso-kerberos/src/main/java/kerberos/client/SampleService.java
+++ b/spring-security-sso/spring-security-sso-kerberos/src/main/java/kerberos/client/SampleClient.java
@@ -5,14 +5,14 @@ import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
@Service
-class SampleService {
+class SampleClient {
@Value("${app.access-url}")
private String endpoint;
private RestTemplate restTemplate;
- public SampleService(RestTemplate restTemplate) {
+ public SampleClient(RestTemplate restTemplate) {
this.restTemplate = restTemplate;
}
diff --git a/spring-security-sso/spring-security-sso-kerberos/src/test/java/kerberos/client/SampleServiceManualTest.java b/spring-security-sso/spring-security-sso-kerberos/src/test/java/kerberos/client/SampleClientManualTest.java
similarity index 59%
rename from spring-security-sso/spring-security-sso-kerberos/src/test/java/kerberos/client/SampleServiceManualTest.java
rename to spring-security-sso/spring-security-sso-kerberos/src/test/java/kerberos/client/SampleClientManualTest.java
index d0d9f0ae4b..fdb1b12531 100644
--- a/spring-security-sso/spring-security-sso-kerberos/src/test/java/kerberos/client/SampleServiceManualTest.java
+++ b/spring-security-sso/spring-security-sso-kerberos/src/test/java/kerberos/client/SampleClientManualTest.java
@@ -1,6 +1,5 @@
package kerberos.client;
-import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -10,7 +9,6 @@ import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import static org.junit.Assert.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
/**
@@ -23,21 +21,19 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
*/
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
-@FixMethodOrder
-public class SampleServiceManualTest {
+public class SampleClientManualTest {
@Autowired
- private SampleService sampleService;
+ private SampleClient sampleClient;
@Test
- public void a_givenKerberizedRestTemplate_whenServiceCall_thenSuccess() {
- assertNotNull(sampleService);
- assertEquals("data from kerberized server", sampleService.getData());
+ public void givenKerberizedRestTemplate_whenServiceCall_thenSuccess() {
+ assertEquals("data from kerberized server", sampleClient.getData());
}
@Test
- public void b_givenRestTemplate_whenServiceCall_thenFail() {
- sampleService.setRestTemplate(new RestTemplate());
- assertThrows(RestClientException.class, sampleService::getData);
+ public void givenRestTemplate_whenServiceCall_thenFail() {
+ sampleClient.setRestTemplate(new RestTemplate());
+ assertThrows(RestClientException.class, sampleClient::getData);
}
}
\ No newline at end of file
diff --git a/spring-security-stormpath/pom.xml b/spring-security-stormpath/pom.xml
index dd6037a22c..6db4b38d80 100644
--- a/spring-security-stormpath/pom.xml
+++ b/spring-security-stormpath/pom.xml
@@ -32,7 +32,7 @@
com.stormpath.spring
stormpath-default-spring-boot-starter
- 1.5.4
+ ${stormpath-spring.version}
@@ -60,5 +60,9 @@
+
+
+ 1.5.4
+
diff --git a/spring-session/spring-session-jdbc/pom.xml b/spring-session/spring-session-jdbc/pom.xml
index a98c4b3429..b46b549ce2 100644
--- a/spring-session/spring-session-jdbc/pom.xml
+++ b/spring-session/spring-session-jdbc/pom.xml
@@ -10,10 +10,6 @@
jar
Spring Session with JDBC tutorial
-
- 1.4.197
-
-
parent-boot-2
com.baeldung
@@ -52,5 +48,8 @@
+
+ 1.4.197
+
\ No newline at end of file
diff --git a/spring-thymeleaf/README.md b/spring-thymeleaf/README.md
index f9e7dd90a7..b6824003db 100644
--- a/spring-thymeleaf/README.md
+++ b/spring-thymeleaf/README.md
@@ -8,7 +8,7 @@
- [Thymeleaf: Custom Layout Dialect](http://www.baeldung.com/thymeleaf-spring-layouts)
- [Spring and Thymeleaf 3: Expressions](http://www.baeldung.com/spring-thymeleaf-3-expressions)
- [Spring MVC + Thymeleaf 3.0: New Features](http://www.baeldung.com/spring-thymeleaf-3)
-- [How to Work with Dates in Thymeleaef](http://www.baeldung.com/dates-in-thymeleaf)
+- [How to Work with Dates in Thymeleaf](http://www.baeldung.com/dates-in-thymeleaf)
- [How to Create an Executable JAR with Maven](http://www.baeldung.com/executable-jar-with-maven)
- [Working with Boolean in Thymeleaf](http://www.baeldung.com/thymeleaf-boolean)
- [Working with Fragments in Thymeleaf](http://www.baeldung.com/spring-thymeleaf-fragments)
diff --git a/tensorflow-java/README.md b/tensorflow-java/README.md
index aa9e9e56b9..f826375ac1 100644
--- a/tensorflow-java/README.md
+++ b/tensorflow-java/README.md
@@ -1,3 +1,3 @@
## Relevant articles:
-- [TensorFlow for Java](https://www.baeldung.com/tensorflow-java)
+- [Introduction to Tensorflow for Java](https://www.baeldung.com/tensorflow-java)
diff --git a/tensorflow-java/pom.xml b/tensorflow-java/pom.xml
index e9d92157e8..f52cd4a68f 100644
--- a/tensorflow-java/pom.xml
+++ b/tensorflow-java/pom.xml
@@ -15,12 +15,6 @@
1.0.0-SNAPSHOT
-
- 1.8
- 1.12.0
- 5.4.0
-
-
org.tensorflow
@@ -49,4 +43,10 @@
+
+
+ 1.8
+ 1.12.0
+ 5.4.0
+
\ No newline at end of file
diff --git a/testing-modules/groovy-spock/pom.xml b/testing-modules/groovy-spock/pom.xml
index d6097af208..35d8f5034f 100644
--- a/testing-modules/groovy-spock/pom.xml
+++ b/testing-modules/groovy-spock/pom.xml
@@ -48,7 +48,7 @@
- 1.3-RC1-groovy-2.4
+ 1.3-groovy-2.4
2.4.7
1.5
diff --git a/testing-modules/groovy-spock/src/test/groovy/extensions/IgnoreIfTest.groovy b/testing-modules/groovy-spock/src/test/groovy/extensions/IgnoreIfTest.groovy
index 91da2ff1ec..9010481220 100644
--- a/testing-modules/groovy-spock/src/test/groovy/extensions/IgnoreIfTest.groovy
+++ b/testing-modules/groovy-spock/src/test/groovy/extensions/IgnoreIfTest.groovy
@@ -7,6 +7,16 @@ import spock.lang.Specification
class IgnoreIfTest extends Specification {
@IgnoreIf({System.getProperty("os.name").contains("windows")})
- def "I won't run on windows"() { }
+ def "I won't run on windows"() {
+ expect:
+ true
+ }
+
+ @IgnoreIf({ os.isWindows() })
+ def "I'm using Spock helper classes to run only on windows"() {
+ expect:
+ true
+ }
+
}
diff --git a/testing-modules/groovy-spock/src/test/resources/SpockConfig.groovy b/testing-modules/groovy-spock/src/test/resources/SpockConfig.groovy
index ed94e61cbf..4b017aeefc 100644
--- a/testing-modules/groovy-spock/src/test/resources/SpockConfig.groovy
+++ b/testing-modules/groovy-spock/src/test/resources/SpockConfig.groovy
@@ -2,7 +2,10 @@ import extensions.TimeoutTest
import spock.lang.Issue
runner {
- filterStackTrace true
+
+ if (System.getenv("FILTER_STACKTRACE") == null) {
+ filterStackTrace false
+ }
report {
issueNamePrefix 'Bug '
diff --git a/testing-modules/junit-5/README.md b/testing-modules/junit-5/README.md
index d686396a1d..aafdd75e81 100644
--- a/testing-modules/junit-5/README.md
+++ b/testing-modules/junit-5/README.md
@@ -6,7 +6,7 @@
- [A Guide to JUnit 5 Extensions](http://www.baeldung.com/junit-5-extensions)
- [Inject Parameters into JUnit Jupiter Unit Tests](http://www.baeldung.com/junit-5-parameters)
- [Mockito and JUnit 5 – Using ExtendWith](http://www.baeldung.com/mockito-junit-5-extension)
-- [JUnit 5 – @RunWith](http://www.baeldung.com/junit-5-runwith)
+- [JUnit 5 @RunWith](http://www.baeldung.com/junit-5-runwith)
- [JUnit 5 @Test Annotation](http://www.baeldung.com/junit-5-test-annotation)
- [Assert an Exception is Thrown in JUnit 4 and 5](http://www.baeldung.com/junit-assert-exception)
- [@Before vs @BeforeClass vs @BeforeEach vs @BeforeAll](http://www.baeldung.com/junit-before-beforeclass-beforeeach-beforeall)
diff --git a/testing-modules/load-testing-comparison/pom.xml b/testing-modules/load-testing-comparison/pom.xml
index 63472d0467..44014e96ab 100644
--- a/testing-modules/load-testing-comparison/pom.xml
+++ b/testing-modules/load-testing-comparison/pom.xml
@@ -42,7 +42,7 @@
com.fasterxml.jackson.core
jackson-databind
- 2.9.4
+ ${jackson.version}
org.springframework.boot
@@ -68,12 +68,12 @@
com.h2database
h2
- 1.4.197
+ ${h2.version}
org.projectlombok
lombok
- 1.18.2
+ ${lombok.version}
compile
@@ -145,6 +145,7 @@
5.0
3.11
2.0.5.RELEASE
+ 1.4.197
\ No newline at end of file
diff --git a/testing-modules/parallel-tests-junit/math-test-functions/pom.xml b/testing-modules/parallel-tests-junit/math-test-functions/pom.xml
index a3569714ef..cc9f27de05 100644
--- a/testing-modules/parallel-tests-junit/math-test-functions/pom.xml
+++ b/testing-modules/parallel-tests-junit/math-test-functions/pom.xml
@@ -18,7 +18,7 @@
junit
junit
- 4.12
+ ${junit.version}
test
diff --git a/testing-modules/parallel-tests-junit/math-test-functions/src/test/java/com/baeldung/ArithmeticFunctionTest.java b/testing-modules/parallel-tests-junit/math-test-functions/src/test/java/com/baeldung/ArithmeticFunctionUnitTest.java
similarity index 93%
rename from testing-modules/parallel-tests-junit/math-test-functions/src/test/java/com/baeldung/ArithmeticFunctionTest.java
rename to testing-modules/parallel-tests-junit/math-test-functions/src/test/java/com/baeldung/ArithmeticFunctionUnitTest.java
index df0aa695fc..1f048b305f 100644
--- a/testing-modules/parallel-tests-junit/math-test-functions/src/test/java/com/baeldung/ArithmeticFunctionTest.java
+++ b/testing-modules/parallel-tests-junit/math-test-functions/src/test/java/com/baeldung/ArithmeticFunctionUnitTest.java
@@ -4,7 +4,7 @@ import static org.junit.Assert.assertEquals;
import org.junit.Test;
-public class ArithmeticFunctionTest {
+public class ArithmeticFunctionUnitTest {
@Test
public void test_addingIntegers_returnsSum() {
diff --git a/testing-modules/parallel-tests-junit/math-test-functions/src/test/java/com/baeldung/ComparisonFunctionTest.java b/testing-modules/parallel-tests-junit/math-test-functions/src/test/java/com/baeldung/ComparisonFunctionUnitTest.java
similarity index 87%
rename from testing-modules/parallel-tests-junit/math-test-functions/src/test/java/com/baeldung/ComparisonFunctionTest.java
rename to testing-modules/parallel-tests-junit/math-test-functions/src/test/java/com/baeldung/ComparisonFunctionUnitTest.java
index 4f72c87279..839b6c2cf3 100644
--- a/testing-modules/parallel-tests-junit/math-test-functions/src/test/java/com/baeldung/ComparisonFunctionTest.java
+++ b/testing-modules/parallel-tests-junit/math-test-functions/src/test/java/com/baeldung/ComparisonFunctionUnitTest.java
@@ -4,7 +4,7 @@ import static org.junit.Assert.assertEquals;
import org.junit.Test;
-public class ComparisonFunctionTest {
+public class ComparisonFunctionUnitTest {
@Test
public void test_findMax() {
diff --git a/testing-modules/parallel-tests-junit/math-test-functions/src/test/java/com/baeldung/FunctionTestSuite.java b/testing-modules/parallel-tests-junit/math-test-functions/src/test/java/com/baeldung/FunctionTestSuite.java
index 4fe551b365..d12eab5c51 100644
--- a/testing-modules/parallel-tests-junit/math-test-functions/src/test/java/com/baeldung/FunctionTestSuite.java
+++ b/testing-modules/parallel-tests-junit/math-test-functions/src/test/java/com/baeldung/FunctionTestSuite.java
@@ -5,7 +5,7 @@ import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
-@SuiteClasses({ ComparisonFunctionTest.class, ArithmeticFunctionTest.class })
+@SuiteClasses({ ComparisonFunctionUnitTest.class, ArithmeticFunctionUnitTest.class })
public class FunctionTestSuite {
}
diff --git a/testing-modules/parallel-tests-junit/pom.xml b/testing-modules/parallel-tests-junit/pom.xml
index f400a5ae07..993974046c 100644
--- a/testing-modules/parallel-tests-junit/pom.xml
+++ b/testing-modules/parallel-tests-junit/pom.xml
@@ -6,6 +6,13 @@
0.0.1-SNAPSHOT
parallel-tests-junit
pom
+
+
+ com.baeldung
+ parent-java
+ 0.0.1-SNAPSHOT
+ ../../parent-java
+
math-test-functions
diff --git a/testing-modules/parallel-tests-junit/string-test-functions/pom.xml b/testing-modules/parallel-tests-junit/string-test-functions/pom.xml
index 7fa09ff493..b0c0ed29fc 100644
--- a/testing-modules/parallel-tests-junit/string-test-functions/pom.xml
+++ b/testing-modules/parallel-tests-junit/string-test-functions/pom.xml
@@ -18,7 +18,7 @@
junit
junit
- 4.12
+ ${junit.version}
test
diff --git a/testing-modules/parallel-tests-junit/string-test-functions/src/test/java/com/baeldung/StringFunctionTest.java b/testing-modules/parallel-tests-junit/string-test-functions/src/test/java/com/baeldung/StringFunctionUnitTest.java
similarity index 88%
rename from testing-modules/parallel-tests-junit/string-test-functions/src/test/java/com/baeldung/StringFunctionTest.java
rename to testing-modules/parallel-tests-junit/string-test-functions/src/test/java/com/baeldung/StringFunctionUnitTest.java
index 7f2bc5e5e7..685a33b084 100644
--- a/testing-modules/parallel-tests-junit/string-test-functions/src/test/java/com/baeldung/StringFunctionTest.java
+++ b/testing-modules/parallel-tests-junit/string-test-functions/src/test/java/com/baeldung/StringFunctionUnitTest.java
@@ -4,7 +4,7 @@ import static org.junit.Assert.assertEquals;
import org.junit.Test;
-public class StringFunctionTest {
+public class StringFunctionUnitTest {
@Test
public void test_upperCase() {
diff --git a/testing-modules/rest-assured/README.md b/testing-modules/rest-assured/README.md
index 50f36f61eb..d44fd08335 100644
--- a/testing-modules/rest-assured/README.md
+++ b/testing-modules/rest-assured/README.md
@@ -1,2 +1,4 @@
###Relevant Articles:
- [A Guide to REST-assured](http://www.baeldung.com/rest-assured-tutorial)
+- [REST-assured Support for Spring MockMvc](https://www.baeldung.com/spring-mock-mvc-rest-assured)
+- [Getting and Verifying Response Data with REST-assured](https://www.baeldung.com/rest-assured-response)
diff --git a/testing-modules/rest-assured/pom.xml b/testing-modules/rest-assured/pom.xml
index cd342ccd11..c528a34e21 100644
--- a/testing-modules/rest-assured/pom.xml
+++ b/testing-modules/rest-assured/pom.xml
@@ -162,6 +162,11 @@
commons-collections
${commons-collections.version}
+
+
+ org.springframework.boot
+ spring-boot-starter-security
+
@@ -179,6 +184,12 @@
json-schema-validator
test
+
+ com.github.scribejava
+ scribejava-apis
+ ${scribejava.version}
+ test
+
@@ -211,6 +222,8 @@
3.0.1
3.0.1
+
+ 2.5.3
diff --git a/testing-modules/rest-assured/src/test/java/com/baeldung/restassured/authentication/BasicAuthenticationLiveTest.java b/testing-modules/rest-assured/src/test/java/com/baeldung/restassured/authentication/BasicAuthenticationLiveTest.java
new file mode 100644
index 0000000000..aff765dfa3
--- /dev/null
+++ b/testing-modules/rest-assured/src/test/java/com/baeldung/restassured/authentication/BasicAuthenticationLiveTest.java
@@ -0,0 +1,38 @@
+package com.baeldung.restassured.authentication;
+
+import static io.restassured.RestAssured.get;
+import static io.restassured.RestAssured.given;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.http.HttpStatus;
+
+/**
+ * For this Live Test we need:
+ * * a running instance of the service located in the spring-security-rest-basic-auth module.
+ * @see spring-security-rest-basic-auth module
+ *
+ */
+public class BasicAuthenticationLiveTest {
+
+ private static final String USER = "user1";
+ private static final String PASSWORD = "user1Pass";
+ private static final String SVC_URL = "http://localhost:8080/spring-security-rest-basic-auth/api/foos/1";
+
+ @Test
+ public void givenNoAuthentication_whenRequestSecuredResource_thenUnauthorizedResponse() {
+ get(SVC_URL).then()
+ .assertThat()
+ .statusCode(HttpStatus.UNAUTHORIZED.value());
+ }
+
+ @Test
+ public void givenBasicAuthentication_whenRequestSecuredResource_thenResourceRetrieved() {
+ given().auth()
+ .basic(USER, PASSWORD)
+ .when()
+ .get(SVC_URL)
+ .then()
+ .assertThat()
+ .statusCode(HttpStatus.OK.value());
+ }
+}
diff --git a/testing-modules/rest-assured/src/test/java/com/baeldung/restassured/authentication/BasicPreemtiveAuthenticationLiveTest.java b/testing-modules/rest-assured/src/test/java/com/baeldung/restassured/authentication/BasicPreemtiveAuthenticationLiveTest.java
new file mode 100644
index 0000000000..02138f22e3
--- /dev/null
+++ b/testing-modules/rest-assured/src/test/java/com/baeldung/restassured/authentication/BasicPreemtiveAuthenticationLiveTest.java
@@ -0,0 +1,56 @@
+package com.baeldung.restassured.authentication;
+
+import static io.restassured.RestAssured.get;
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.is;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.http.HttpStatus;
+
+/**
+ * For this Live Test we need:
+ * * a running instance of the service located in the spring-boot-admin/spring-boot-admin-server module.
+ * @see spring-boot-admin/spring-boot-admin-server module
+ *
+ */
+public class BasicPreemtiveAuthenticationLiveTest {
+
+ private static final String USER = "admin";
+ private static final String PASSWORD = "admin";
+ private static final String SVC_URL = "http://localhost:8080/api/applications/";
+
+ @Test
+ public void givenNoAuthentication_whenRequestSecuredResource_thenUnauthorizedResponse() {
+ get(SVC_URL).then()
+ .assertThat()
+ .statusCode(HttpStatus.OK.value())
+ .content(containsString("