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/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-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-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/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/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-2/src/main/kotlin/com/baeldung/inputstream/InputStreamExtension.kt b/core-kotlin-2/src/main/kotlin/com/baeldung/inputstream/InputStreamExtension.kt new file mode 100644 index 0000000000..e94a2e84ee --- /dev/null +++ b/core-kotlin-2/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-2/src/test/kotlin/com/baeldung/inputstream/InputStreamToStringTest.kt b/core-kotlin-2/src/test/kotlin/com/baeldung/inputstream/InputStreamToStringTest.kt new file mode 100644 index 0000000000..3437ddb68a --- /dev/null +++ b/core-kotlin-2/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-2/src/test/resources/inputstream2string.txt b/core-kotlin-2/src/test/resources/inputstream2string.txt new file mode 100644 index 0000000000..40ef9fc5f3 --- /dev/null +++ b/core-kotlin-2/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-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/README.md b/jackson/README.md index e9cf6f212c..eeb8f1b874 100644 --- a/jackson/README.md +++ b/jackson/README.md @@ -16,7 +16,7 @@ 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 – Decide What Fields Get Serialized/Deserialized](http://www.baeldung.com/jackson-field-serializable-deserializable-or-not) - [Jackson Annotation Examples](http://www.baeldung.com/jackson-annotations) - [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) 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/libraries-2/pom.xml b/libraries-2/pom.xml new file mode 100644 index 0000000000..a839f56b56 --- /dev/null +++ b/libraries-2/pom.xml @@ -0,0 +1,43 @@ + + + + 4.0.0 + libraries2 + libraries2 + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + + + + jboss-public-repository-group + JBoss Public Repository Group + http://repository.jboss.org/nexus/content/groups/public/ + + true + never + + + true + daily + + + + + + + org.jbpm + jbpm-test + ${jbpm.version} + + + + + 6.0.0.Final + + diff --git a/libraries-2/src/main/java/com/baeldung/jbpm/WorkflowProcessMain.java b/libraries-2/src/main/java/com/baeldung/jbpm/WorkflowProcessMain.java new file mode 100644 index 0000000000..8e54ff892e --- /dev/null +++ b/libraries-2/src/main/java/com/baeldung/jbpm/WorkflowProcessMain.java @@ -0,0 +1,19 @@ +package com.baeldung.jbpm; + +import org.kie.api.runtime.manager.Context; +import org.kie.internal.runtime.manager.context.EmptyContext; + +import com.baeldung.jbpm.engine.WorkflowEngine; +import com.baeldung.jbpm.engine.WorkflowEngineImpl; + +public class WorkflowProcessMain { + + public static void main(String[] args) { + WorkflowEngine workflowEngine = new WorkflowEngineImpl(); + String processId = "com.baeldung.bpmn.helloworld"; + String kbaseId = "kbase"; + String persistenceUnit = "org.jbpm.persistence.jpa"; + Context initialContext = EmptyContext.get(); + workflowEngine.runjBPMEngineForProcess(processId, initialContext, kbaseId, persistenceUnit); + } +} \ No newline at end of file diff --git a/libraries-2/src/main/java/com/baeldung/jbpm/engine/WorkflowEngine.java b/libraries-2/src/main/java/com/baeldung/jbpm/engine/WorkflowEngine.java new file mode 100644 index 0000000000..b47a4cc8c1 --- /dev/null +++ b/libraries-2/src/main/java/com/baeldung/jbpm/engine/WorkflowEngine.java @@ -0,0 +1,10 @@ +package com.baeldung.jbpm.engine; + +import org.kie.api.runtime.manager.Context; +import org.kie.api.runtime.process.ProcessInstance; + +public interface WorkflowEngine { + + public ProcessInstance runjBPMEngineForProcess(String processId, Context initialContext, String kbaseId, String persistenceUnit); + +} diff --git a/libraries-2/src/main/java/com/baeldung/jbpm/engine/WorkflowEngineImpl.java b/libraries-2/src/main/java/com/baeldung/jbpm/engine/WorkflowEngineImpl.java new file mode 100644 index 0000000000..7871241bef --- /dev/null +++ b/libraries-2/src/main/java/com/baeldung/jbpm/engine/WorkflowEngineImpl.java @@ -0,0 +1,66 @@ +package com.baeldung.jbpm.engine; + +import javax.persistence.EntityManagerFactory; +import javax.persistence.Persistence; + +import org.jbpm.test.JBPMHelper; +import org.kie.api.KieBase; +import org.kie.api.KieServices; +import org.kie.api.runtime.KieContainer; +import org.kie.api.runtime.KieSession; +import org.kie.api.runtime.manager.Context; +import org.kie.api.runtime.manager.RuntimeEngine; +import org.kie.api.runtime.manager.RuntimeEnvironment; +import org.kie.api.runtime.manager.RuntimeEnvironmentBuilder; +import org.kie.api.runtime.manager.RuntimeManager; +import org.kie.api.runtime.manager.RuntimeManagerFactory; +import org.kie.api.runtime.process.ProcessInstance; + +public class WorkflowEngineImpl implements WorkflowEngine { + + @Override + public ProcessInstance runjBPMEngineForProcess(String processId, Context initialContext, String kbaseId, String persistenceUnit) { + RuntimeManager manager = null; + RuntimeEngine engine = null; + ProcessInstance pInstance = null; + try { + KieBase kbase = getKieBase(kbaseId); + manager = createJBPMRuntimeManager(kbase, persistenceUnit); + engine = manager.getRuntimeEngine(initialContext); + pInstance = executeProcessInstance(processId, manager, initialContext, engine); + } catch (Exception ex) { + ex.printStackTrace(); + } finally { + if (manager != null && engine != null) + manager.disposeRuntimeEngine(engine); + System.exit(0); + } + return pInstance; + } + + private ProcessInstance executeProcessInstance(String processId, RuntimeManager manager, Context initialContext, RuntimeEngine engine) { + KieSession ksession = engine.getKieSession(); + ProcessInstance pInstance = ksession.startProcess(processId); + return pInstance; + } + + private KieBase getKieBase(String kbaseId) { + KieServices ks = KieServices.Factory.get(); + KieContainer kContainer = ks.getKieClasspathContainer(); + KieBase kbase = kContainer.getKieBase(kbaseId); + return kbase; + } + + private RuntimeManager createJBPMRuntimeManager(KieBase kbase, String persistenceUnit) { + JBPMHelper.startH2Server(); + JBPMHelper.setupDataSource(); + EntityManagerFactory emf = Persistence.createEntityManagerFactory(persistenceUnit); + RuntimeEnvironmentBuilder runtimeEnvironmentBuilder = RuntimeEnvironmentBuilder.Factory.get() + .newDefaultBuilder(); + RuntimeEnvironment runtimeEnvironment = runtimeEnvironmentBuilder.entityManagerFactory(emf) + .knowledgeBase(kbase) + .get(); + return RuntimeManagerFactory.Factory.get() + .newSingletonRuntimeManager(runtimeEnvironment); + } +} diff --git a/libraries-2/src/main/resources/META-INF/kmodule.xml b/libraries-2/src/main/resources/META-INF/kmodule.xml new file mode 100644 index 0000000000..1b9ce1ce71 --- /dev/null +++ b/libraries-2/src/main/resources/META-INF/kmodule.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/libraries-2/src/main/resources/com/baeldung/process/helloworld.bpmn b/libraries-2/src/main/resources/com/baeldung/process/helloworld.bpmn new file mode 100644 index 0000000000..30813b2057 --- /dev/null +++ b/libraries-2/src/main/resources/com/baeldung/process/helloworld.bpmn @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/libraries-2/src/test/java/com/baeldung/jbpm/WorkflowEngineIntegrationTest.java b/libraries-2/src/test/java/com/baeldung/jbpm/WorkflowEngineIntegrationTest.java new file mode 100644 index 0000000000..ded46d7639 --- /dev/null +++ b/libraries-2/src/test/java/com/baeldung/jbpm/WorkflowEngineIntegrationTest.java @@ -0,0 +1,52 @@ +package com.baeldung.jbpm; + +import org.jbpm.test.JbpmJUnitBaseTestCase; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.kie.api.runtime.KieSession; +import org.kie.api.runtime.manager.RuntimeEngine; +import org.kie.api.runtime.manager.RuntimeManager; +import org.kie.api.runtime.process.ProcessInstance; +import org.kie.internal.runtime.manager.context.ProcessInstanceIdContext; + +public class WorkflowEngineIntegrationTest extends JbpmJUnitBaseTestCase { + + private String[] triggeredNodesArray = { "Start", "HelloWorld", "End" }; + private RuntimeManager manager = null; + private RuntimeEngine runtimeEngine = null; + private KieSession ksession = null; + private ProcessInstance processInstance = null; + + @Before + public void setup() { + manager = createRuntimeManager(Strategy.SINGLETON, "manager", "com/baeldung/process/helloworld.bpmn"); + runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get()); + ksession = runtimeEngine.getKieSession(); + processInstance = ksession.startProcess("com.baeldung.bpmn.helloworld"); + } + + @After + public void cleanup() { + manager.disposeRuntimeEngine(runtimeEngine); + } + + @Test + public void givenProcessInstance_whenExecutionCompleted_thenVerifyNodesExecutionOrder() { + assertNodeTriggered(processInstance.getId(), triggeredNodesArray); + } + + @Test + public void givenProcessInstance_whenExecutionCompleted_thenVerifyKnowledgeSessionId() { + int ksessionID = ksession.getId(); + runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId())); + ksession = runtimeEngine.getKieSession(); + assertEquals(ksessionID, ksession.getId()); + } + + @Test + public void givenProcessInstance_whenExecutionCompleted_thenVerifyProcessInstanceStatus() { + assertProcessInstanceCompleted(processInstance.getId(), ksession); + assertTrue("ProcessInstance completed with status 2", processInstance.getState() == 2); + } +} 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/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/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-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/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/src/main/java/com/baeldung/domain/Employee.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entity/Employee.java similarity index 89% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/Employee.java rename to persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entity/Employee.java index f2363cf746..135439863f 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/domain/Employee.java +++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entity/Employee.java @@ -1,4 +1,4 @@ -package com.baeldung.domain; +package com.baeldung.entity; import javax.persistence.Entity; import javax.persistence.Id; 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/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/src/main/java/com/baeldung/dao/repositories/EmployeeRepository.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/repository/EmployeeRepository.java similarity index 62% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/EmployeeRepository.java rename to persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/repository/EmployeeRepository.java index 6185185791..2c4fee80e0 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/dao/repositories/EmployeeRepository.java +++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/repository/EmployeeRepository.java @@ -1,8 +1,8 @@ -package com.baeldung.dao.repositories; +package com.baeldung.repository; import org.springframework.data.jpa.repository.JpaRepository; -import com.baeldung.domain.Employee; +import com.baeldung.entity.Employee; public interface EmployeeRepository extends JpaRepository { 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-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/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/src/test/java/com/baeldung/dao/repositories/EmployeeRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/repository/EmployeeRepositoryIntegrationTest.java similarity index 94% rename from persistence-modules/spring-data-jpa/src/test/java/com/baeldung/dao/repositories/EmployeeRepositoryIntegrationTest.java rename to persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/repository/EmployeeRepositoryIntegrationTest.java index 13ceb702d2..ebeed276c9 100644 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/dao/repositories/EmployeeRepositoryIntegrationTest.java +++ b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/repository/EmployeeRepositoryIntegrationTest.java @@ -1,4 +1,4 @@ -package com.baeldung.dao.repositories; +package com.baeldung.repository; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; @@ -8,7 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.test.context.junit4.SpringRunner; -import com.baeldung.domain.Employee; +import com.baeldung.entity.Employee; @RunWith(SpringRunner.class) @DataJpaTest 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/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 a832d6156f..d6cee747ec 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 @@ -332,7 +333,7 @@ parent-spring-5 parent-java parent-kotlin - + akka-streams algorithms-genetic algorithms-miscellaneous-1 @@ -379,10 +380,13 @@ 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 @@ -440,6 +445,7 @@ jackson-2 java-collections-conversions java-collections-maps + java-collections-maps-2 @@ -448,6 +454,7 @@ java-rmi java-spi java-streams + java-streams-2 java-strings java-vavr-stream java-websocket @@ -480,6 +487,7 @@ libraries + libraries-2 libraries-data libraries-apache-commons libraries-security @@ -578,6 +586,7 @@ spring-5 spring-5-webflux + spring-5-data-reactive spring-5-mvc spring-5-reactive spring-5-reactive-client @@ -590,6 +599,7 @@ spring-akka spring-all spring-amqp + spring-amqp-simple spring-aop spring-apache-camel spring-batch @@ -613,8 +623,10 @@ 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 @@ -662,11 +674,13 @@ 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 @@ -946,9 +960,6 @@ persistence-modules/java-mongodb persistence-modules/jnosql - spring-5-data-reactive - spring-amqp-simple - vaadin @@ -982,7 +993,7 @@ parent-spring-5 parent-java parent-kotlin - + akka-streams algorithms-genetic algorithms-miscellaneous-1 @@ -1026,10 +1037,12 @@ 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 @@ -1038,6 +1051,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 @@ -1085,6 +1099,7 @@ jackson-2 java-collections-conversions java-collections-maps + java-collections-maps-2 java-ee-8-security-api java-lite @@ -1092,6 +1107,7 @@ java-rmi java-spi java-streams + java-streams-2 java-strings java-vavr-stream java-websocket @@ -1214,6 +1230,7 @@ spring-4 spring-5 + spring-5-data-reactive spring-5-mvc spring-5-reactive spring-5-reactive-client @@ -1226,6 +1243,7 @@ spring-akka spring-all spring-amqp + spring-amqp-simple spring-aop spring-apache-camel spring-batch @@ -1249,8 +1267,10 @@ 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 @@ -1296,11 +1316,13 @@ 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 @@ -1434,9 +1456,6 @@ persistence-modules/java-mongodb persistence-modules/jnosql - spring-5-data-reactive - spring-amqp-simple - vaadin 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/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-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-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 + + <Caption> + <Value></Value> + <Font> + <Alignment/> + </Font> + </Caption> + <Background xsi:type="attribute:ColorDefinition"> + <Transparency>0</Transparency> + <Red>255</Red> + <Green>255</Green> + <Blue>255</Blue> + </Background> + <Outline> + <Style>Solid</Style> + <Thickness>1</Thickness> + <Color> + <Transparency>255</Transparency> + <Red>0</Red> + <Green>0</Green> + <Blue>0</Blue> + </Color> + <Visible>false</Visible> + </Outline> + <Insets> + <Top>0.0</Top> + <Left>2.0</Left> + <Bottom>0.0</Bottom> + <Right>3.0</Right> + </Insets> + <Visible>false</Visible> + + 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 + + <Caption> + <Value>X-Axis Title</Value> + <Font> + <Size>14.0</Size> + <Bold>true</Bold> + <Alignment> + <horizontalAlignment>Center</horizontalAlignment> + <verticalAlignment>Center</verticalAlignment> + </Alignment> + </Font> + </Caption> + <Background xsi:type="attribute:ColorDefinition"> + <Transparency>0</Transparency> + <Red>255</Red> + <Green>255</Green> + <Blue>255</Blue> + </Background> + <Outline> + <Style>Solid</Style> + <Thickness>1</Thickness> + <Color> + <Transparency>255</Transparency> + <Red>0</Red> + <Green>0</Green> + <Blue>0</Blue> + </Color> + </Outline> + <Insets> + <Top>0.0</Top> + <Left>2.0</Left> + <Bottom>0.0</Bottom> + <Right>3.0</Right> + </Insets> + <Visible>false</Visible> + + Below + + Linear + + <Caption> + <Value>Y-Axis Title</Value> + <Font> + <Size>14.0</Size> + <Bold>true</Bold> + <Alignment> + <horizontalAlignment>Center</horizontalAlignment> + <verticalAlignment>Center</verticalAlignment> + </Alignment> + </Font> + </Caption> + <Background xsi:type="attribute:ColorDefinition"> + <Transparency>0</Transparency> + <Red>255</Red> + <Green>255</Green> + <Blue>255</Blue> + </Background> + <Outline> + <Style>Solid</Style> + <Thickness>1</Thickness> + <Color> + <Transparency>255</Transparency> + <Red>0</Red> + <Green>0</Green> + <Blue>0</Blue> + </Color> + </Outline> + <Insets> + <Top>0.0</Top> + <Left>2.0</Left> + <Bottom>0.0</Bottom> + <Right>3.0</Right> + </Insets> + <Visible>false</Visible> + + 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..e3e93a21db 100644 --- a/spring-boot-rest/README.md +++ b/spring-boot-rest/README.md @@ -10,4 +10,5 @@ Module for the articles that are part of the Spring REST E-book: 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) +11. [Spring Boot Consuming and Producing JSON](https://www.baeldung.com/spring-boot-json) +12. [Testing Web APIs with Postman Collections](https://www.baeldung.com/postman-testing-collections) 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/README.MD b/spring-boot/README.MD index 7d270c9c25..b8b51153a7 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) 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/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/SpringContextLiveTest.java similarity index 68% 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/SpringContextLiveTest.java index c521a0d2ef..793b4abb6c 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/SpringContextLiveTest.java @@ -1,18 +1,22 @@ 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; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; + +/** + * + * The context will load successfully with some properties provided by docker + * + */ @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = ConfigServer.class) @WebAppConfiguration -@Ignore -public class ConfigServerListIntegrationTest { +public class SpringContextLiveTest { @Test - public void contextLoads() { + public void whenSpringContextIsBootstrapped_thenNoExceptions() { } } 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-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-eureka/spring-cloud-eureka-client/src/test/java/com/baeldung/spring/cloud/eureka/client/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-client/src/test/java/com/baeldung/spring/cloud/eureka/client/SpringContextIntegrationTest.java new file mode 100644 index 0000000000..8e379fd5a0 --- /dev/null +++ b/spring-cloud/spring-cloud-eureka/spring-cloud-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-aws/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 69% rename from spring-cloud/spring-cloud-aws/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 fcba9c4132..ff742735b3 100644 --- a/spring-cloud/spring-cloud-aws/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,17 +1,16 @@ -package org.baeldung; +package com.baeldung.spring.cloud.feign.client; 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-eureka/spring-cloud-eureka-server/src/test/java/com/baeldung/spring/cloud/eureka/server/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-eureka/spring-cloud-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-eureka/spring-cloud-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-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-hystrix/rest-producer/src/test/java/com/baeldung/spring/cloud/hystrix/rest/producer/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-hystrix/rest-producer/src/test/java/com/baeldung/spring/cloud/hystrix/rest/producer/SpringContextIntegrationTest.java new file mode 100644 index 0000000000..de696dc2b1 --- /dev/null +++ b/spring-cloud/spring-cloud-hystrix/rest-producer/src/test/java/com/baeldung/spring/cloud/hystrix/rest/producer/SpringContextIntegrationTest.java @@ -0,0 +1,16 @@ +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; + +@RunWith(SpringRunner.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-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-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-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-testing/README.md b/testing-modules/rest-testing/README.md index 25e036ba5d..a07c8cb256 100644 --- a/testing-modules/rest-testing/README.md +++ b/testing-modules/rest-testing/README.md @@ -8,7 +8,7 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring ### Relevant Articles: - [Test a REST API with Java](http://www.baeldung.com/integration-testing-a-rest-api) - [Introduction to WireMock](http://www.baeldung.com/introduction-to-wiremock) -- [Using WireMock Scenarios](http://www.baeldung.com/using-wiremock-scenarios) +- [Using WireMock Scenarios](https://www.baeldung.com/wiremock-scenarios) - [REST API Testing with Cucumber](http://www.baeldung.com/cucumber-rest-api-testing) - [Testing a REST API with JBehave](http://www.baeldung.com/jbehave-rest-testing) - [REST API Testing with Karate](http://www.baeldung.com/karate-rest-api-testing) diff --git a/testing-modules/testing/README.md b/testing-modules/testing/README.md index e96b26ab41..4a7829e867 100644 --- a/testing-modules/testing/README.md +++ b/testing-modules/testing/README.md @@ -18,6 +18,6 @@ - [Custom JUnit 4 Test Runners](http://www.baeldung.com/junit-4-custom-runners) - [Guide to JSpec](http://www.baeldung.com/jspec) - [Custom Assertions with AssertJ](http://www.baeldung.com/assertj-custom-assertion) -- [Using Conditions with AssertJ](http://www.baeldung.com/assertj-conditions) -- [Guide to JavaFaker](https://www.baeldung.com/java-faker) +- [Using Conditions with AssertJ Assertions](http://www.baeldung.com/assertj-conditions) +- [A Guide to JavaFaker](https://www.baeldung.com/java-faker) - [Running JUnit Tests Programmatically, from a Java Application](https://www.baeldung.com/junit-tests-run-programmatically-from-java) diff --git a/testing-modules/testing/pom.xml b/testing-modules/testing/pom.xml index 2e783b2116..ccfa1070d1 100644 --- a/testing-modules/testing/pom.xml +++ b/testing-modules/testing/pom.xml @@ -91,7 +91,7 @@ com.github.javafaker javafaker - 0.15 + ${javafaker.version} @@ -177,6 +177,7 @@ 0.4 3.0.0 1.5 + 0.15 diff --git a/twilio/pom.xml b/twilio/pom.xml index 81fbf8ab20..266ac45c92 100644 --- a/twilio/pom.xml +++ b/twilio/pom.xml @@ -16,8 +16,12 @@ com.twilio.sdk twilio - 7.20.0 + ${twilio.version} + + 7.20.0 + +