From 96d121bcae0f7925c6077c2299473a03ae6b8514 Mon Sep 17 00:00:00 2001 From: amit2103 Date: Mon, 19 Nov 2018 00:04:52 +0530 Subject: [PATCH 01/31] [BAEL-9712] - Created spring-5-security-oauth module --- pom.xml | 4 ++ spring-5-security-oauth/README.md | 3 + spring-5-security-oauth/pom.xml | 68 +++++++++++++++++++ .../com/baeldung/oauth2/LoginController.java | 0 .../java/com/baeldung/oauth2/MvcConfig.java | 0 .../com/baeldung/oauth2/SecurityConfig.java | 4 +- .../oauth2/SpringOAuthApplication.java | 0 .../ExtractorsApplication.java | 0 .../configuration/SecurityConfig.java | 0 .../custom/BaeldungAuthoritiesExtractor.java | 0 .../custom/BaeldungPrincipalExtractor.java | 0 .../github/GithubAuthoritiesExtractor.java | 0 .../github/GithubPrincipalExtractor.java | 0 ...tion-oauth2-extractors-baeldung.properties | 0 ...cation-oauth2-extractors-github.properties | 0 .../resources/application-oauth2.properties | 0 .../src/main/resources/application.properties | 5 ++ .../src/main/resources/logback.xml | 13 ++++ .../src/main/resources/static/css/main.css | 8 +++ .../src/main/resources/templates/index.html | 11 +++ .../resources/templates/loginFailure.html | 0 .../resources/templates/loginSuccess.html | 0 .../templates/oauth2_extractors.html | 0 .../main/resources/templates/oauth_login.html | 0 .../main/resources/templates/securedPage.html | 0 .../oauth2extractors/ExtractorsUnitTest.java | 0 spring-5-security/README.md | 1 - spring-5-security/pom.xml | 15 ---- 28 files changed, 114 insertions(+), 18 deletions(-) create mode 100644 spring-5-security-oauth/README.md create mode 100644 spring-5-security-oauth/pom.xml rename {spring-5-security => spring-5-security-oauth}/src/main/java/com/baeldung/oauth2/LoginController.java (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/java/com/baeldung/oauth2/MvcConfig.java (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/java/com/baeldung/oauth2/SecurityConfig.java (95%) rename {spring-5-security => spring-5-security-oauth}/src/main/java/com/baeldung/oauth2/SpringOAuthApplication.java (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/java/com/baeldung/oauth2extractors/ExtractorsApplication.java (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/java/com/baeldung/oauth2extractors/configuration/SecurityConfig.java (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/java/com/baeldung/oauth2extractors/extractor/custom/BaeldungAuthoritiesExtractor.java (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/java/com/baeldung/oauth2extractors/extractor/custom/BaeldungPrincipalExtractor.java (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/java/com/baeldung/oauth2extractors/extractor/github/GithubAuthoritiesExtractor.java (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/java/com/baeldung/oauth2extractors/extractor/github/GithubPrincipalExtractor.java (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/resources/application-oauth2-extractors-baeldung.properties (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/resources/application-oauth2-extractors-github.properties (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/resources/application-oauth2.properties (100%) create mode 100644 spring-5-security-oauth/src/main/resources/application.properties create mode 100644 spring-5-security-oauth/src/main/resources/logback.xml create mode 100644 spring-5-security-oauth/src/main/resources/static/css/main.css create mode 100644 spring-5-security-oauth/src/main/resources/templates/index.html rename {spring-5-security => spring-5-security-oauth}/src/main/resources/templates/loginFailure.html (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/resources/templates/loginSuccess.html (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/resources/templates/oauth2_extractors.html (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/resources/templates/oauth_login.html (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/resources/templates/securedPage.html (100%) rename {spring-5-security => spring-5-security-oauth}/src/test/java/com/baeldung/oauth2extractors/ExtractorsUnitTest.java (100%) diff --git a/pom.xml b/pom.xml index 5ebf7ba4f3..0997d7ce88 100644 --- a/pom.xml +++ b/pom.xml @@ -466,6 +466,7 @@ spring-5-reactive-client spring-5-mvc spring-5-security + spring-5-security-oauth spring-5-reactive-oauth spring-activiti spring-akka @@ -768,6 +769,7 @@ spring-5-reactive-client spring-5-reactive-security spring-5-security + spring-5-security-oauth spring-activiti spring-akka spring-all @@ -994,6 +996,7 @@ spring-5-reactive-client spring-5-mvc spring-5-security + spring-5-security-oauth spring-activiti spring-akka spring-amqp @@ -1385,6 +1388,7 @@ spring-5-reactive-client spring-5-mvc spring-5-security + spring-5-security-oauth spring-activiti spring-akka spring-amqp diff --git a/spring-5-security-oauth/README.md b/spring-5-security-oauth/README.md new file mode 100644 index 0000000000..81d95c07d7 --- /dev/null +++ b/spring-5-security-oauth/README.md @@ -0,0 +1,3 @@ +## Relevant articles: + +- [Spring Security 5 -OAuth2 Login](http://www.baeldung.com/spring-security-5-oauth2-login) \ No newline at end of file diff --git a/spring-5-security-oauth/pom.xml b/spring-5-security-oauth/pom.xml new file mode 100644 index 0000000000..a741daaa18 --- /dev/null +++ b/spring-5-security-oauth/pom.xml @@ -0,0 +1,68 @@ + + 4.0.0 + com.baeldung + spring-5-security-oauth + 0.0.1-SNAPSHOT + jar + spring-5-security-oauth + spring 5 security oauth sample project + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../parent-boot-2 + + + + + + org.springframework.boot + spring-boot-starter-security + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + org.thymeleaf.extras + thymeleaf-extras-springsecurity5 + + + + + org.springframework.security.oauth.boot + spring-security-oauth2-autoconfigure + ${oauth-auto.version} + + + org.springframework.security + spring-security-oauth2-client + + + org.springframework.security + spring-security-oauth2-jose + + + + org.springframework + spring-test + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.security + spring-security-test + test + + + + diff --git a/spring-5-security/src/main/java/com/baeldung/oauth2/LoginController.java b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/LoginController.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/oauth2/LoginController.java rename to spring-5-security-oauth/src/main/java/com/baeldung/oauth2/LoginController.java diff --git a/spring-5-security/src/main/java/com/baeldung/oauth2/MvcConfig.java b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/MvcConfig.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/oauth2/MvcConfig.java rename to spring-5-security-oauth/src/main/java/com/baeldung/oauth2/MvcConfig.java diff --git a/spring-5-security/src/main/java/com/baeldung/oauth2/SecurityConfig.java b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/SecurityConfig.java similarity index 95% rename from spring-5-security/src/main/java/com/baeldung/oauth2/SecurityConfig.java rename to spring-5-security-oauth/src/main/java/com/baeldung/oauth2/SecurityConfig.java index b45f325767..e08057d92f 100644 --- a/spring-5-security/src/main/java/com/baeldung/oauth2/SecurityConfig.java +++ b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/SecurityConfig.java @@ -12,7 +12,7 @@ import org.springframework.core.env.Environment; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.config.oauth2.client.CommonOAuth2Provider; -import org.springframework.security.oauth2.client.endpoint.NimbusAuthorizationCodeTokenResponseClient; +import org.springframework.security.oauth2.client.endpoint.DefaultAuthorizationCodeTokenResponseClient; import org.springframework.security.oauth2.client.endpoint.OAuth2AccessTokenResponseClient; import org.springframework.security.oauth2.client.endpoint.OAuth2AuthorizationCodeGrantRequest; import org.springframework.security.oauth2.client.registration.ClientRegistration; @@ -54,7 +54,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { @Bean public OAuth2AccessTokenResponseClient accessTokenResponseClient() { - return new NimbusAuthorizationCodeTokenResponseClient(); + return new DefaultAuthorizationCodeTokenResponseClient(); } diff --git a/spring-5-security/src/main/java/com/baeldung/oauth2/SpringOAuthApplication.java b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/SpringOAuthApplication.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/oauth2/SpringOAuthApplication.java rename to spring-5-security-oauth/src/main/java/com/baeldung/oauth2/SpringOAuthApplication.java diff --git a/spring-5-security/src/main/java/com/baeldung/oauth2extractors/ExtractorsApplication.java b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/ExtractorsApplication.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/oauth2extractors/ExtractorsApplication.java rename to spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/ExtractorsApplication.java diff --git a/spring-5-security/src/main/java/com/baeldung/oauth2extractors/configuration/SecurityConfig.java b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/configuration/SecurityConfig.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/oauth2extractors/configuration/SecurityConfig.java rename to spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/configuration/SecurityConfig.java diff --git a/spring-5-security/src/main/java/com/baeldung/oauth2extractors/extractor/custom/BaeldungAuthoritiesExtractor.java b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/extractor/custom/BaeldungAuthoritiesExtractor.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/oauth2extractors/extractor/custom/BaeldungAuthoritiesExtractor.java rename to spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/extractor/custom/BaeldungAuthoritiesExtractor.java diff --git a/spring-5-security/src/main/java/com/baeldung/oauth2extractors/extractor/custom/BaeldungPrincipalExtractor.java b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/extractor/custom/BaeldungPrincipalExtractor.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/oauth2extractors/extractor/custom/BaeldungPrincipalExtractor.java rename to spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/extractor/custom/BaeldungPrincipalExtractor.java diff --git a/spring-5-security/src/main/java/com/baeldung/oauth2extractors/extractor/github/GithubAuthoritiesExtractor.java b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/extractor/github/GithubAuthoritiesExtractor.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/oauth2extractors/extractor/github/GithubAuthoritiesExtractor.java rename to spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/extractor/github/GithubAuthoritiesExtractor.java diff --git a/spring-5-security/src/main/java/com/baeldung/oauth2extractors/extractor/github/GithubPrincipalExtractor.java b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/extractor/github/GithubPrincipalExtractor.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/oauth2extractors/extractor/github/GithubPrincipalExtractor.java rename to spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/extractor/github/GithubPrincipalExtractor.java diff --git a/spring-5-security/src/main/resources/application-oauth2-extractors-baeldung.properties b/spring-5-security-oauth/src/main/resources/application-oauth2-extractors-baeldung.properties similarity index 100% rename from spring-5-security/src/main/resources/application-oauth2-extractors-baeldung.properties rename to spring-5-security-oauth/src/main/resources/application-oauth2-extractors-baeldung.properties diff --git a/spring-5-security/src/main/resources/application-oauth2-extractors-github.properties b/spring-5-security-oauth/src/main/resources/application-oauth2-extractors-github.properties similarity index 100% rename from spring-5-security/src/main/resources/application-oauth2-extractors-github.properties rename to spring-5-security-oauth/src/main/resources/application-oauth2-extractors-github.properties diff --git a/spring-5-security/src/main/resources/application-oauth2.properties b/spring-5-security-oauth/src/main/resources/application-oauth2.properties similarity index 100% rename from spring-5-security/src/main/resources/application-oauth2.properties rename to spring-5-security-oauth/src/main/resources/application-oauth2.properties diff --git a/spring-5-security-oauth/src/main/resources/application.properties b/spring-5-security-oauth/src/main/resources/application.properties new file mode 100644 index 0000000000..5912b0f755 --- /dev/null +++ b/spring-5-security-oauth/src/main/resources/application.properties @@ -0,0 +1,5 @@ +server.port=8081 + +logging.level.root=INFO + +logging.level.com.baeldung.dsl.ClientErrorLoggingFilter=DEBUG \ No newline at end of file diff --git a/spring-5-security-oauth/src/main/resources/logback.xml b/spring-5-security-oauth/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/spring-5-security-oauth/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-5-security-oauth/src/main/resources/static/css/main.css b/spring-5-security-oauth/src/main/resources/static/css/main.css new file mode 100644 index 0000000000..febc353af7 --- /dev/null +++ b/spring-5-security-oauth/src/main/resources/static/css/main.css @@ -0,0 +1,8 @@ +p.error { + font-weight: bold; + color: red; +} + +div.logout { + margin-right: 2em;; +} diff --git a/spring-5-security-oauth/src/main/resources/templates/index.html b/spring-5-security-oauth/src/main/resources/templates/index.html new file mode 100644 index 0000000000..4216d74037 --- /dev/null +++ b/spring-5-security-oauth/src/main/resources/templates/index.html @@ -0,0 +1,11 @@ + + + + Home + + + + Home + Welcome! + + \ No newline at end of file diff --git a/spring-5-security/src/main/resources/templates/loginFailure.html b/spring-5-security-oauth/src/main/resources/templates/loginFailure.html similarity index 100% rename from spring-5-security/src/main/resources/templates/loginFailure.html rename to spring-5-security-oauth/src/main/resources/templates/loginFailure.html diff --git a/spring-5-security/src/main/resources/templates/loginSuccess.html b/spring-5-security-oauth/src/main/resources/templates/loginSuccess.html similarity index 100% rename from spring-5-security/src/main/resources/templates/loginSuccess.html rename to spring-5-security-oauth/src/main/resources/templates/loginSuccess.html diff --git a/spring-5-security/src/main/resources/templates/oauth2_extractors.html b/spring-5-security-oauth/src/main/resources/templates/oauth2_extractors.html similarity index 100% rename from spring-5-security/src/main/resources/templates/oauth2_extractors.html rename to spring-5-security-oauth/src/main/resources/templates/oauth2_extractors.html diff --git a/spring-5-security/src/main/resources/templates/oauth_login.html b/spring-5-security-oauth/src/main/resources/templates/oauth_login.html similarity index 100% rename from spring-5-security/src/main/resources/templates/oauth_login.html rename to spring-5-security-oauth/src/main/resources/templates/oauth_login.html diff --git a/spring-5-security/src/main/resources/templates/securedPage.html b/spring-5-security-oauth/src/main/resources/templates/securedPage.html similarity index 100% rename from spring-5-security/src/main/resources/templates/securedPage.html rename to spring-5-security-oauth/src/main/resources/templates/securedPage.html diff --git a/spring-5-security/src/test/java/com/baeldung/oauth2extractors/ExtractorsUnitTest.java b/spring-5-security-oauth/src/test/java/com/baeldung/oauth2extractors/ExtractorsUnitTest.java similarity index 100% rename from spring-5-security/src/test/java/com/baeldung/oauth2extractors/ExtractorsUnitTest.java rename to spring-5-security-oauth/src/test/java/com/baeldung/oauth2extractors/ExtractorsUnitTest.java diff --git a/spring-5-security/README.md b/spring-5-security/README.md index 55fa7ab042..6e094e928f 100644 --- a/spring-5-security/README.md +++ b/spring-5-security/README.md @@ -1,6 +1,5 @@ ## Relevant articles: -- [Spring Security 5 -OAuth2 Login](http://www.baeldung.com/spring-security-5-oauth2-login) - [Extra Login Fields with Spring Security](http://www.baeldung.com/spring-security-extra-login-fields) - [A Custom Spring SecurityConfigurer](http://www.baeldung.com/spring-security-custom-configurer) - [New Password Storage In Spring Security 5](http://www.baeldung.com/spring-security-5-password-storage) diff --git a/spring-5-security/pom.xml b/spring-5-security/pom.xml index da62f39fa9..51ce822dc4 100644 --- a/spring-5-security/pom.xml +++ b/spring-5-security/pom.xml @@ -34,21 +34,6 @@ thymeleaf-extras-springsecurity5 - - - org.springframework.security.oauth.boot - spring-security-oauth2-autoconfigure - ${oauth-auto.version} - - - org.springframework.security - spring-security-oauth2-client - - - org.springframework.security - spring-security-oauth2-jose - - org.springframework spring-test From 6045b4291a618d4b00046aa9ae495f1ff325996b Mon Sep 17 00:00:00 2001 From: Jan Hauer Date: Thu, 8 Nov 2018 10:43:42 +0100 Subject: [PATCH 02/31] BAEL-2305 Adds array intersection operations --- .../array/operations/ArrayOperations.java | 14 ++++ .../operations/IntersectionUnitTest.java | 66 +++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 core-java-arrays/src/test/java/com/baeldung/array/operations/IntersectionUnitTest.java diff --git a/core-java-arrays/src/main/java/com/baeldung/array/operations/ArrayOperations.java b/core-java-arrays/src/main/java/com/baeldung/array/operations/ArrayOperations.java index 98155ed952..d8cc0afd61 100644 --- a/core-java-arrays/src/main/java/com/baeldung/array/operations/ArrayOperations.java +++ b/core-java-arrays/src/main/java/com/baeldung/array/operations/ArrayOperations.java @@ -4,11 +4,13 @@ import java.lang.reflect.Array; import java.util.Arrays; import java.util.HashSet; import java.util.LinkedHashSet; +import java.util.LinkedList; import java.util.Random; import java.util.Set; import java.util.function.Function; import java.util.function.IntPredicate; import java.util.function.Predicate; +import java.util.stream.Stream; import org.apache.commons.lang3.ArrayUtils; @@ -194,4 +196,16 @@ public class ArrayOperations { public static T getRandomFromObjectArray(T[] array) { return array[new Random().nextInt(array.length)]; } + + public static Integer[] intersectionSimple(final Integer[] a, final Integer[] b){ + return Stream.of(a).filter(Arrays.asList(b)::contains).toArray(Integer[]::new); + } + + public static Integer[] intersectionSet(final Integer[] a, final Integer[] b){ + return Stream.of(a).filter(Arrays.asList(b)::contains).distinct().toArray(Integer[]::new); + } + + public static Integer[] intersectionMultiSet(final Integer[] a, final Integer[] b){ + return Stream.of(a).filter(new LinkedList<>(Arrays.asList(b))::remove).toArray(Integer[]::new); + } } diff --git a/core-java-arrays/src/test/java/com/baeldung/array/operations/IntersectionUnitTest.java b/core-java-arrays/src/test/java/com/baeldung/array/operations/IntersectionUnitTest.java new file mode 100644 index 0000000000..3c61060ea8 --- /dev/null +++ b/core-java-arrays/src/test/java/com/baeldung/array/operations/IntersectionUnitTest.java @@ -0,0 +1,66 @@ +package com.baeldung.array.operations; + +import org.junit.jupiter.api.Test; + +import static com.baeldung.array.operations.ArrayOperations.intersectionMultiSet; +import static com.baeldung.array.operations.ArrayOperations.intersectionSet; +import static com.baeldung.array.operations.ArrayOperations.intersectionSimple; +import static org.assertj.core.api.Assertions.assertThat; + +class IntersectionUnitTest { + private static final Integer[] a = { 1, 3, 2 }; + private static final Integer[] b = { 4, 3, 2, 4, 2, 3, 4, 4, 3 }; + private static final Integer[] c = { 1, 3, 2, 3, 3, 2 }; + + @Test + void whenIntersectionSimpleIsUsed_thenCommonEntriesAreInTheResult() { + assertThat(intersectionSimple(a, b)).isEqualTo(new Integer[] { 3, 2 }); + assertThat(intersectionSimple(b, a)).isEqualTo(new Integer[] { 3, 2, 2, 3, 3 }); + } + + @Test + void whenIntersectionSimpleIsUsedWithAnArrayAndItself_thenTheResultIsTheIdentity() { + assertThat(intersectionSimple(b, b)).isEqualTo(b); + assertThat(intersectionSimple(a, a)).isEqualTo(a); + } + + @Test + void whenIntersectionSetIsUsed_thenCommonEntriesAreInTheResult() { + assertThat(intersectionSet(b, a)).isEqualTo(new Integer[] { 3, 2 }); + } + + @Test + void whenIntersectionSetIsUsed_thenTheNumberOfEntriesDoesNotChangeWithTheParameterOrder() { + assertThat(intersectionSet(a, b)).isEqualTo(new Integer[] { 3, 2 }); + assertThat(intersectionSet(b, a)).isEqualTo(new Integer[] { 3, 2 }); + } + + @Test + void whenIntersectionSetIsUsedWithAnArrayAndWithItself_andTheInputHasNoDuplicateEntries_ThenTheResultIsTheIdentity() { + assertThat(intersectionSet(a, a)).isEqualTo(a); + } + + @Test + void whenIntersectionSetIsUsedWithAnArrayAndWithItself_andTheInputHasDuplicateEntries_ThenTheResultIsNotTheIdentity() { + assertThat(intersectionSet(b, b)).isNotEqualTo(b); + } + + @Test + void whenMultiSetIsUsed_thenCommonEntriesAreInTheResult() { + assertThat(intersectionMultiSet(b, a)).isEqualTo(new Integer[] { 3, 2 }); + } + + @Test + void whenIntersectionMultiSetIsUsed_thenTheNumberOfEntriesDoesNotChangeWithTheParameterOrder() { + assertThat(intersectionMultiSet(a, b)).isEqualTo(new Integer[] { 3, 2 }); + assertThat(intersectionMultiSet(b, a)).isEqualTo(new Integer[] { 3, 2 }); + assertThat(intersectionMultiSet(b, c)).isEqualTo(new Integer[] { 3, 2, 2, 3, 3 }); + assertThat(intersectionMultiSet(c, b)).isEqualTo(new Integer[] { 3, 2, 3, 3, 2 }); + } + + @Test + void whenIntersectionMultiSetIsUsedWithAnArrayAndWithItself_ThenTheResultIsTheIdentity() { + assertThat(intersectionMultiSet(b, b)).isEqualTo(b); + assertThat(intersectionMultiSet(a, a)).isEqualTo(a); + } +} \ No newline at end of file From 2c4cefe51693fb961d15b4ea5942868909603c9a Mon Sep 17 00:00:00 2001 From: Vizsoro Date: Tue, 20 Nov 2018 19:33:54 +0100 Subject: [PATCH 03/31] Arrow in Kotlin Issue: BAEL-1495 --- kotlin-libraries/pom.xml | 7 + .../FunctionalErrorHandlingWithEither.kt | 54 +++++++ .../FunctionalErrorHandlingWithOption.kt | 46 ++++++ .../kotlin/arrow/FunctionalDataTypes.kt | 143 ++++++++++++++++++ .../FunctionalErrorHandlingWithEitherTest.kt | 68 +++++++++ .../FunctionalErrorHandlingWithOptionTest.kt | 34 +++++ 6 files changed, 352 insertions(+) create mode 100644 kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithEither.kt create mode 100644 kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithOption.kt create mode 100644 kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/arrow/FunctionalDataTypes.kt create mode 100644 kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithEitherTest.kt create mode 100644 kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithOptionTest.kt diff --git a/kotlin-libraries/pom.xml b/kotlin-libraries/pom.xml index c5b7fed951..92a643e458 100644 --- a/kotlin-libraries/pom.xml +++ b/kotlin-libraries/pom.xml @@ -87,6 +87,13 @@ h2 ${h2database.version} + + + io.arrow-kt + arrow-core + 0.7.3 + + diff --git a/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithEither.kt b/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithEither.kt new file mode 100644 index 0000000000..75dfb9a2a4 --- /dev/null +++ b/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithEither.kt @@ -0,0 +1,54 @@ +package com.baeldung.kotlin.arrow + +import arrow.core.Either +import arrow.core.filterOrElse +import kotlin.math.sqrt + +class FunctionalErrorHandlingWithEither { + + sealed class ComputeProblem { + object OddNumber : ComputeProblem() + object NotANumber : ComputeProblem() + } + + fun parseInput(s : String) : Either = Either.cond(s.toIntOrNull() != null, {-> s.toInt()}, {->ComputeProblem.NotANumber} ) + + fun isEven(x : Int) : Boolean = x % 2 == 0 + + fun biggestDivisor(x: Int) : Int = biggestDivisor(x, 2) + + fun biggestDivisor(x : Int, y : Int) : Int { + if(x == y){ + return 1; + } + if(x % y == 0){ + return x / y; + } + return biggestDivisor(x, y+1) + } + + fun isSquareNumber(x : Int) : Boolean { + val sqrt: Double = sqrt(x.toDouble()) + return sqrt % 1.0 == 0.0 + } + + fun computeWithEither(input : String) : Either { + return parseInput(input) + .filterOrElse(::isEven) {->ComputeProblem.OddNumber} + .map (::biggestDivisor) + .map (::isSquareNumber) + } + + fun computeWithEitherClient(input : String) { + val computeWithEither = computeWithEither(input) + + when(computeWithEither){ + is Either.Right -> "The greatest divisor is square number: ${computeWithEither.b}" + is Either.Left -> when(computeWithEither.a){ + is ComputeProblem.NotANumber -> "Wrong input! Not a number!" + is ComputeProblem.OddNumber -> "It is an odd number!" + } + } + } + +} \ No newline at end of file diff --git a/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithOption.kt b/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithOption.kt new file mode 100644 index 0000000000..5fddd1d88e --- /dev/null +++ b/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithOption.kt @@ -0,0 +1,46 @@ +package com.baeldung.kotlin.arrow + +import arrow.core.None +import arrow.core.Option +import arrow.core.Some +import kotlin.math.sqrt + +class FunctionalErrorHandlingWithOption { + + fun parseInput(s : String) : Option = Option.fromNullable(s.toIntOrNull()) + + fun isEven(x : Int) : Boolean = x % 2 == 0 + + fun biggestDivisor(x: Int) : Int = biggestDivisor(x, 2) + + fun biggestDivisor(x : Int, y : Int) : Int { + if(x == y){ + return 1; + } + if(x % y == 0){ + return x / y; + } + return biggestDivisor(x, y+1) + } + + fun isSquareNumber(x : Int) : Boolean { + val sqrt: Double = sqrt(x.toDouble()) + return sqrt % 1.0 == 0.0 + } + + fun computeWithOption(input : String) : Option { + return parseInput(input) + .filter(::isEven) + .map(::biggestDivisor) + .map(::isSquareNumber) + } + + fun computeWithOptionClient(input : String) : String{ + val computeOption = computeWithOption(input) + + return when(computeOption){ + is None -> "Not an even number!" + is Some -> "The greatest divisor is square number: ${computeOption.t}" + } + } +} \ No newline at end of file diff --git a/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/arrow/FunctionalDataTypes.kt b/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/arrow/FunctionalDataTypes.kt new file mode 100644 index 0000000000..692425ee07 --- /dev/null +++ b/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/arrow/FunctionalDataTypes.kt @@ -0,0 +1,143 @@ +package com.baeldung.kotlin.arrow + +import arrow.core.* +import org.junit.Assert +import org.junit.Test + +class FunctionalDataTypes { + + @Test + fun whenIdCreated_thanValueIsPresent(){ + val id = Id("foo") + val justId = Id.just("foo"); + + Assert.assertEquals("foo", id.extract()) + Assert.assertEquals(justId, id) + } + + fun length(s : String) : Int = s.length + + fun isBigEnough(i : Int) : Boolean = i > 10 + + @Test + fun whenIdCreated_thanMapIsAssociative(){ + val foo = Id("foo") + + val map1 = foo.map(::length) + .map(::isBigEnough) + val map2 = foo.map { s -> isBigEnough(length(s)) } + + Assert.assertEquals(map1, map2) + } + + fun lengthId(s : String) : Id = Id.just(length(s)) + + fun isBigEnoughId(i : Int) : Id = Id.just(isBigEnough(i)) + + @Test + fun whenIdCreated_thanFlatMapIsAssociative(){ + val bar = Id("bar") + + val flatMap = bar.flatMap(::lengthId) + .flatMap(::isBigEnoughId) + val flatMap1 = bar.flatMap { s -> lengthId(s).flatMap(::isBigEnoughId) } + + Assert.assertEquals(flatMap, flatMap1) + } + + @Test + fun whenOptionCreated_thanValueIsPresent(){ + val factory = Option.just(42) + val constructor = Option(42) + val emptyOptional = Option.empty() + val fromNullable = Option.fromNullable(null) + + Assert.assertEquals(42, factory.getOrElse { -1 }) + Assert.assertEquals(factory, constructor) + Assert.assertEquals(emptyOptional, fromNullable) + } + + @Test + fun whenOptionCreated_thanConstructorDifferFromFactory(){ + val constructor : Option = Option(null) + val fromNullable : Option = Option.fromNullable(null) + + try{ + constructor.map { s -> s!!.length } + Assert.fail() + } catch (e : KotlinNullPointerException){ + fromNullable.map { s->s!!.length } + } + Assert.assertNotEquals(constructor, fromNullable) + } + + fun wrapper(x : Integer?) : Option = if (x == null) Option.just(-1) else Option.just(x.toInt()) + + @Test + fun whenOptionFromNullableCreated_thanItBreaksLeftIdentity(){ + val optionFromNull = Option.fromNullable(null) + + Assert.assertNotEquals(optionFromNull.flatMap(::wrapper), wrapper(null)) + } + + @Test + fun whenEitherCreated_thanOneValueIsPresent(){ + val rightOnly : Either = Either.right(42) + val leftOnly : Either = Either.left("foo") + + Assert.assertTrue(rightOnly.isRight()) + Assert.assertTrue(leftOnly.isLeft()) + Assert.assertEquals(42, rightOnly.getOrElse { -1 }) + Assert.assertEquals(-1, leftOnly.getOrElse { -1 }) + + Assert.assertEquals(0, rightOnly.map { it % 2 }.getOrElse { -1 }) + Assert.assertEquals(-1, leftOnly.map { it % 2 }.getOrElse { -1 }) + Assert.assertTrue(rightOnly.flatMap { Either.Right(it % 2) }.isRight()) + Assert.assertTrue(leftOnly.flatMap { Either.Right(it % 2) }.isLeft()) + } + + @Test + fun whenEvalNowUsed_thenMapEvaluatedLazily(){ + val now = Eval.now(1) + Assert.assertEquals(1, now.value()) + + var counter : Int = 0 + val map = now.map { x -> counter++; x+1 } + Assert.assertEquals(0, counter) + + val value = map.value() + Assert.assertEquals(2, value) + Assert.assertEquals(1, counter) + } + + @Test + fun whenEvalLaterUsed_theResultIsMemoized(){ + var counter : Int = 0 + val later = Eval.later { counter++; counter } + Assert.assertEquals(0, counter) + + val firstValue = later.value() + Assert.assertEquals(1, firstValue) + Assert.assertEquals(1, counter) + + val secondValue = later.value() + Assert.assertEquals(1, secondValue) + Assert.assertEquals(1, counter) + } + + @Test + fun whenEvalAlwaysUsed_theResultIsNotMemoized(){ + var counter : Int = 0 + val later = Eval.always { counter++; counter } + Assert.assertEquals(0, counter) + + val firstValue = later.value() + Assert.assertEquals(1, firstValue) + Assert.assertEquals(1, counter) + + val secondValue = later.value() + Assert.assertEquals(2, secondValue) + Assert.assertEquals(2, counter) + } + +} \ No newline at end of file diff --git a/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithEitherTest.kt b/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithEitherTest.kt new file mode 100644 index 0000000000..47fbf825a0 --- /dev/null +++ b/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithEitherTest.kt @@ -0,0 +1,68 @@ +package com.baeldung.kotlin.arrow + +import arrow.core.Either +import com.baeldung.kotlin.arrow.FunctionalErrorHandlingWithEither.ComputeProblem.NotANumber +import com.baeldung.kotlin.arrow.FunctionalErrorHandlingWithEither.ComputeProblem.OddNumber +import org.junit.Assert +import org.junit.Test + +class FunctionalErrorHandlingWithEitherTest { + + val operator = FunctionalErrorHandlingWithEither() + + @Test + fun givenInvalidInput_whenComputeInvoked_NotANumberIsPresent(){ + val computeWithEither = operator.computeWithEither("bar") + + Assert.assertTrue(computeWithEither.isLeft()) + when(computeWithEither){ + is Either.Left -> when(computeWithEither.a){ + NotANumber -> "Ok." + else -> Assert.fail() + } + else -> Assert.fail() + } + } + + @Test + fun givenOddNumberInput_whenComputeInvoked_OddNumberIsPresent(){ + val computeWithEither = operator.computeWithEither("121") + + Assert.assertTrue(computeWithEither.isLeft()) + when(computeWithEither){ + is Either.Left -> when(computeWithEither.a){ + OddNumber -> "Ok." + else -> Assert.fail() + } + else -> Assert.fail() + } + } + + @Test + fun givenEvenNumberWithoutSquare_whenComputeInvoked_OddNumberIsPresent(){ + val computeWithEither = operator.computeWithEither("100") + + Assert.assertTrue(computeWithEither.isRight()) + when(computeWithEither){ + is Either.Right -> when(computeWithEither.b){ + false -> "Ok." + else -> Assert.fail() + } + else -> Assert.fail() + } + } + + @Test + fun givenEvenNumberWithSquare_whenComputeInvoked_OddNumberIsPresent(){ + val computeWithEither = operator.computeWithEither("98") + + Assert.assertTrue(computeWithEither.isRight()) + when(computeWithEither){ + is Either.Right -> when(computeWithEither.b){ + true -> "Ok." + else -> Assert.fail() + } + else -> Assert.fail() + } + } +} \ No newline at end of file diff --git a/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithOptionTest.kt b/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithOptionTest.kt new file mode 100644 index 0000000000..3ca4cd033f --- /dev/null +++ b/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithOptionTest.kt @@ -0,0 +1,34 @@ +package com.baeldung.kotlin.arrow + +import org.junit.Assert +import org.junit.Test + +class FunctionalErrorHandlingWithOptionTest { + + val operator = FunctionalErrorHandlingWithOption() + + @Test + fun givenInvalidInput_thenErrorMessageIsPresent(){ + val useComputeOption = operator.computeWithOptionClient("foo") + Assert.assertEquals("Not an even number!", useComputeOption) + } + + @Test + fun givenOddNumberInput_thenErrorMessageIsPresent(){ + val useComputeOption = operator.computeWithOptionClient("539") + Assert.assertEquals("Not an even number!",useComputeOption) + } + + @Test + fun givenEvenNumberInputWithNonSquareNum_thenFalseMessageIsPresent(){ + val useComputeOption = operator.computeWithOptionClient("100") + Assert.assertEquals("The greatest divisor is square number: false",useComputeOption) + } + + @Test + fun givenEvenNumberInputWithSquareNum_thenTrueMessageIsPresent(){ + val useComputeOption = operator.computeWithOptionClient("242") + Assert.assertEquals("The greatest divisor is square number: true",useComputeOption) + } + +} \ No newline at end of file From 7e9f96117e5cc9becca1660adc855e07744f3b36 Mon Sep 17 00:00:00 2001 From: KevinGilmore Date: Tue, 20 Nov 2018 21:33:41 -0600 Subject: [PATCH 04/31] BAEL-2312 update README (#5744) * BAEL-2015: add link back to article * BAEL-2166 BAEL-2302 add links back to articles * BAEL-2312: add link back to article --- core-java/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java/README.md b/core-java/README.md index 11d9fd2ee0..7617897e95 100644 --- a/core-java/README.md +++ b/core-java/README.md @@ -85,3 +85,4 @@ - [A Guide to SimpleDateFormat](https://www.baeldung.com/java-simple-date-format) - [SSL Handshake Failures](https://www.baeldung.com/java-ssl-handshake-failures) - [Implementing a Binary Tree in Java](https://www.baeldung.com/java-binary-tree) +- [Abstract Classes in Java](https://www.baeldung.com/java-abstract-class) From cf602faff9a5d2971f28c853374cb90066108831 Mon Sep 17 00:00:00 2001 From: Loredana Date: Thu, 22 Nov 2018 00:37:23 +0200 Subject: [PATCH 05/31] revert boot 2.1 upgrade --- parent-boot-2/pom.xml | 5 +++-- .../security/SpringSecurity5Application.java | 11 ++++++----- .../Spring5ReactiveServerClientIntegrationTest.java | 13 +++++++------ spring-5-security/pom.xml | 4 ++-- spring-data-rest/pom.xml | 4 ++++ spring-security-mvc-boot/pom.xml | 2 +- spring-security-sso/pom.xml | 4 +++- .../spring-security-sso-auth-server/pom.xml | 8 ++++---- .../spring-security-sso-ui-2/pom.xml | 4 ++-- spring-security-sso/spring-security-sso-ui/pom.xml | 4 ++-- spring-security-thymeleaf/pom.xml | 2 +- 11 files changed, 35 insertions(+), 26 deletions(-) diff --git a/parent-boot-2/pom.xml b/parent-boot-2/pom.xml index bb89cb2729..67837e1a4e 100644 --- a/parent-boot-2/pom.xml +++ b/parent-boot-2/pom.xml @@ -77,7 +77,8 @@ 3.1.0 1.0.11.RELEASE - 2.1.0.RELEASE - 2.1.0.RELEASE + 2.0.5.RELEASE + + diff --git a/spring-5-reactive-security/src/main/java/com/baeldung/reactive/security/SpringSecurity5Application.java b/spring-5-reactive-security/src/main/java/com/baeldung/reactive/security/SpringSecurity5Application.java index ba913bc2d7..f2963c4fa5 100644 --- a/spring-5-reactive-security/src/main/java/com/baeldung/reactive/security/SpringSecurity5Application.java +++ b/spring-5-reactive-security/src/main/java/com/baeldung/reactive/security/SpringSecurity5Application.java @@ -8,8 +8,8 @@ import org.springframework.http.server.reactive.HttpHandler; import org.springframework.http.server.reactive.ReactorHttpHandlerAdapter; import org.springframework.web.reactive.config.EnableWebFlux; import org.springframework.web.server.adapter.WebHttpHandlerBuilder; -import reactor.netty.DisposableServer; -import reactor.netty.http.server.HttpServer; +import reactor.ipc.netty.NettyContext; +import reactor.ipc.netty.http.server.HttpServer; @ComponentScan(basePackages = {"com.baeldung.reactive.security"}) @EnableWebFlux @@ -18,16 +18,17 @@ public class SpringSecurity5Application { public static void main(String[] args) { try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringSecurity5Application.class)) { - context.getBean(DisposableServer.class).onDispose().block(); + context.getBean(NettyContext.class).onClose().block(); } } @Bean - public DisposableServer nettyContext(ApplicationContext context) { + public NettyContext nettyContext(ApplicationContext context) { HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context) .build(); ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler); - return HttpServer.create().host("localhost").port(8080).handle(adapter).bind().block(); + HttpServer httpServer = HttpServer.create("localhost", 8080); + return httpServer.newHandler(adapter).block(); } } diff --git a/spring-5-reactive/src/test/java/com/baeldung/reactive/Spring5ReactiveServerClientIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/reactive/Spring5ReactiveServerClientIntegrationTest.java index 384600994e..5ebfa39358 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/reactive/Spring5ReactiveServerClientIntegrationTest.java +++ b/spring-5-reactive/src/test/java/com/baeldung/reactive/Spring5ReactiveServerClientIntegrationTest.java @@ -10,8 +10,8 @@ import org.springframework.web.reactive.function.server.RouterFunctions; import org.springframework.web.reactive.function.server.ServerResponse; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -import reactor.netty.DisposableServer; -import reactor.netty.http.server.HttpServer; +import reactor.ipc.netty.NettyContext; +import reactor.ipc.netty.http.server.HttpServer; import java.time.Duration; @@ -19,11 +19,11 @@ import static org.springframework.web.reactive.function.server.RequestPredicates import static org.springframework.web.reactive.function.server.RequestPredicates.POST; public class Spring5ReactiveServerClientIntegrationTest { - private static DisposableServer nettyServer; + private static NettyContext nettyContext; @BeforeAll public static void setUp() throws Exception { - HttpServer server = HttpServer.create().host("localhost").port(8080); + HttpServer server = HttpServer.create("localhost", 8080); RouterFunction route = RouterFunctions.route(POST("/task/process"), request -> ServerResponse.ok() .body(request.bodyToFlux(Task.class) .map(ll -> new Task("TaskName", 1)), Task.class)) @@ -31,12 +31,13 @@ public class Spring5ReactiveServerClientIntegrationTest { .body(Mono.just("server is alive"), String.class))); HttpHandler httpHandler = RouterFunctions.toHttpHandler(route); ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(httpHandler); - nettyServer = server.handle(adapter).bind().block(); + nettyContext = server.newHandler(adapter) + .block(); } @AfterAll public static void shutDown() { - nettyServer.dispose(); + nettyContext.dispose(); } // @Test diff --git a/spring-5-security/pom.xml b/spring-5-security/pom.xml index da62f39fa9..f5fb359896 100644 --- a/spring-5-security/pom.xml +++ b/spring-5-security/pom.xml @@ -31,14 +31,14 @@ org.thymeleaf.extras - thymeleaf-extras-springsecurity5 + thymeleaf-extras-springsecurity4 org.springframework.security.oauth.boot spring-security-oauth2-autoconfigure - ${oauth-auto.version} + 2.0.1.RELEASE org.springframework.security diff --git a/spring-data-rest/pom.xml b/spring-data-rest/pom.xml index a756ef0497..a6f12e1904 100644 --- a/spring-data-rest/pom.xml +++ b/spring-data-rest/pom.xml @@ -42,4 +42,8 @@ ${project.artifactId} + + 2.1.0.RELEASE + + diff --git a/spring-security-mvc-boot/pom.xml b/spring-security-mvc-boot/pom.xml index 0a40b0b324..2427d0de1a 100644 --- a/spring-security-mvc-boot/pom.xml +++ b/spring-security-mvc-boot/pom.xml @@ -36,7 +36,7 @@ org.thymeleaf.extras - thymeleaf-extras-springsecurity5 + thymeleaf-extras-springsecurity4 org.springframework.boot diff --git a/spring-security-sso/pom.xml b/spring-security-sso/pom.xml index 7761919ca7..6e61da1519 100644 --- a/spring-security-sso/pom.xml +++ b/spring-security-sso/pom.xml @@ -23,6 +23,8 @@ 3.1.0 + 2.3.3.RELEASE + 2.0.1.RELEASE - \ No newline at end of file + diff --git a/spring-security-sso/spring-security-sso-auth-server/pom.xml b/spring-security-sso/spring-security-sso-auth-server/pom.xml index c0ad6dee2e..ff76f377c6 100644 --- a/spring-security-sso/spring-security-sso-auth-server/pom.xml +++ b/spring-security-sso/spring-security-sso-auth-server/pom.xml @@ -20,10 +20,10 @@ - org.springframework.security.oauth.boot - spring-security-oauth2-autoconfigure - ${oauth-auto.version} + org.springframework.security.oauth + spring-security-oauth2 + ${oauth.version} - \ No newline at end of file + diff --git a/spring-security-sso/spring-security-sso-ui-2/pom.xml b/spring-security-sso/spring-security-sso-ui-2/pom.xml index 5881409c3a..1f9a5754ae 100644 --- a/spring-security-sso/spring-security-sso-ui-2/pom.xml +++ b/spring-security-sso/spring-security-sso-ui-2/pom.xml @@ -37,9 +37,9 @@ org.thymeleaf.extras - thymeleaf-extras-springsecurity5 + thymeleaf-extras-springsecurity4 - \ No newline at end of file + diff --git a/spring-security-sso/spring-security-sso-ui/pom.xml b/spring-security-sso/spring-security-sso-ui/pom.xml index 3e85eb4737..56131749ba 100644 --- a/spring-security-sso/spring-security-sso-ui/pom.xml +++ b/spring-security-sso/spring-security-sso-ui/pom.xml @@ -38,9 +38,9 @@ org.thymeleaf.extras - thymeleaf-extras-springsecurity5 + thymeleaf-extras-springsecurity4 - \ No newline at end of file + diff --git a/spring-security-thymeleaf/pom.xml b/spring-security-thymeleaf/pom.xml index d8b476683a..5b7715bdeb 100644 --- a/spring-security-thymeleaf/pom.xml +++ b/spring-security-thymeleaf/pom.xml @@ -43,7 +43,7 @@ org.thymeleaf.extras - thymeleaf-extras-springsecurity5 + thymeleaf-extras-springsecurity4 From 9726c99c31a163f0d34f88c409d621286e57ae64 Mon Sep 17 00:00:00 2001 From: Kuba Date: Thu, 22 Nov 2018 03:28:17 +0100 Subject: [PATCH 06/31] BAEL-2279 - Logging reactive sequence (#5667) * BAEL-2279 - Logging reactive sequence * BAEL-2279 - Logging reactive sequence * Format fix. * Add all examples. Fix formatting. * BAEL 2279 - rename file, formatting fixes, update deps. --- logging-modules/log4j/pom.xml | 10 ++++++++- .../webFluxLogging/WebFluxLoggingExample.java | 21 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 logging-modules/log4j/src/main/java/com/baeldung/webFluxLogging/WebFluxLoggingExample.java diff --git a/logging-modules/log4j/pom.xml b/logging-modules/log4j/pom.xml index 432295fc62..1b27e03445 100644 --- a/logging-modules/log4j/pom.xml +++ b/logging-modules/log4j/pom.xml @@ -1,5 +1,6 @@ - 4.0.0 com.baeldung @@ -43,6 +44,12 @@ disruptor ${disruptor.version} + + + org.springframework.boot + spring-boot-starter-webflux + ${spring-boot.version} + @@ -50,6 +57,7 @@ 2.7 2.7 3.3.6 + 2.1.0.RELEASE \ No newline at end of file diff --git a/logging-modules/log4j/src/main/java/com/baeldung/webFluxLogging/WebFluxLoggingExample.java b/logging-modules/log4j/src/main/java/com/baeldung/webFluxLogging/WebFluxLoggingExample.java new file mode 100644 index 0000000000..f429fd57f3 --- /dev/null +++ b/logging-modules/log4j/src/main/java/com/baeldung/webFluxLogging/WebFluxLoggingExample.java @@ -0,0 +1,21 @@ +package com.baeldung.webFluxLogging; + +import reactor.core.publisher.Flux; + +public class WebFluxLoggingExample { + + public static void main(String[] args) { + Flux reactiveStream = Flux.range(1, 5).log(); + + reactiveStream.subscribe(); + + reactiveStream = Flux.range(1, 5).log().take(3); + + reactiveStream.subscribe(); + + reactiveStream = Flux.range(1, 5).take(3).log(); + + reactiveStream.subscribe(); + } + +} From 31858afca7598cf4c5b8e305f7fa4cb113d340d5 Mon Sep 17 00:00:00 2001 From: charlesgonzales <39999268+charlesgonzales@users.noreply.github.com> Date: Thu, 22 Nov 2018 12:49:54 +0800 Subject: [PATCH 07/31] Bi-monthly test failure - fix (BAEL-10330) (#5736) * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.MD * Update README.md * Create README.md * Update README.md * Update README.md * Update README.md * Update README.md --- algorithms-miscellaneous-2/README.md | 1 + core-java-10/README.md | 1 + core-java-8/README.md | 1 + core-java-collections/README.md | 1 + core-java-io/README.md | 1 + core-java/README.md | 2 ++ java-dates/README.md | 1 + persistence-modules/spring-boot-persistence/README.MD | 1 + persistence-modules/spring-data-jpa/README.md | 1 + persistence-modules/spring-data-mongodb/README.md | 1 + spring-5-reactive-oauth/README.md | 3 +++ spring-all/README.md | 1 + spring-cloud/README.md | 1 + spring-rest-template/README.md | 1 + spring-rest/README.md | 1 + 15 files changed, 18 insertions(+) create mode 100644 spring-5-reactive-oauth/README.md diff --git a/algorithms-miscellaneous-2/README.md b/algorithms-miscellaneous-2/README.md index 6772a94a8d..d693a44f66 100644 --- a/algorithms-miscellaneous-2/README.md +++ b/algorithms-miscellaneous-2/README.md @@ -17,3 +17,4 @@ - [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) - [Converting Between Byte Arrays and Hexadecimal Strings in Java](https://www.baeldung.com/java-byte-arrays-hex-strings) +- [Convert Latitude and Longitude to a 2D Point in Java](https://www.baeldung.com/java-convert-latitude-longitude) diff --git a/core-java-10/README.md b/core-java-10/README.md index 84fa381a26..f0a25712a7 100644 --- a/core-java-10/README.md +++ b/core-java-10/README.md @@ -4,3 +4,4 @@ - [Java 10 LocalVariable Type-Inference](http://www.baeldung.com/java-10-local-variable-type-inference) - [Guide to Java 10](http://www.baeldung.com/java-10-overview) - [Copy a List to Another List in Java](http://www.baeldung.com/java-copy-list-to-another) +- [Deep Dive Into the New Java JIT Compiler – Graal](https://www.baeldung.com/graal-java-jit-compiler) diff --git a/core-java-8/README.md b/core-java-8/README.md index ffd629a170..6786b29120 100644 --- a/core-java-8/README.md +++ b/core-java-8/README.md @@ -33,3 +33,4 @@ - [An Overview of Regular Expressions Performance in Java](https://www.baeldung.com/java-regex-performance) - [Java Primitives versus Objects](https://www.baeldung.com/java-primitives-vs-objects) - [How to Use if/else Logic in Java 8 Streams](https://www.baeldung.com/java-8-streams-if-else-logic) +- [How to Replace Many if Statements in Java](https://www.baeldung.com/java-replace-if-statements) diff --git a/core-java-collections/README.md b/core-java-collections/README.md index 0fcf7367c7..858dbef0b3 100644 --- a/core-java-collections/README.md +++ b/core-java-collections/README.md @@ -50,3 +50,4 @@ - [Check If Two Lists are Equal in Java](http://www.baeldung.com/java-test-a-list-for-ordinality-and-equality) - [Java List Initialization in One Line](https://www.baeldung.com/java-init-list-one-line) - [ClassCastException: Arrays$ArrayList cannot be cast to ArrayList](https://www.baeldung.com/java-classcastexception-arrays-arraylist) +- [A Guide to EnumMap](https://www.baeldung.com/java-enum-map) diff --git a/core-java-io/README.md b/core-java-io/README.md index c81e466b57..3d028783ed 100644 --- a/core-java-io/README.md +++ b/core-java-io/README.md @@ -34,3 +34,4 @@ - [Read a File into an ArrayList](https://www.baeldung.com/java-file-to-arraylist) - [Guide to Java OutputStream](https://www.baeldung.com/java-outputstream) - [Reading a CSV File into an Array](https://www.baeldung.com/java-csv-file-array) +- [Guide to BufferedReader](https://www.baeldung.com/java-buffered-reader) diff --git a/core-java/README.md b/core-java/README.md index 7617897e95..e8923e9a2f 100644 --- a/core-java/README.md +++ b/core-java/README.md @@ -85,4 +85,6 @@ - [A Guide to SimpleDateFormat](https://www.baeldung.com/java-simple-date-format) - [SSL Handshake Failures](https://www.baeldung.com/java-ssl-handshake-failures) - [Implementing a Binary Tree in Java](https://www.baeldung.com/java-binary-tree) +- [Changing the Order in a Sum Operation Can Produce Different Results?](https://www.baeldung.com/java-floating-point-sum-order) +- [Java – Try with Resources](https://www.baeldung.com/java-try-with-resources) - [Abstract Classes in Java](https://www.baeldung.com/java-abstract-class) diff --git a/java-dates/README.md b/java-dates/README.md index 66046b16a6..3f6d7998b8 100644 --- a/java-dates/README.md +++ b/java-dates/README.md @@ -24,3 +24,4 @@ - [Add Hours To a Date In Java](http://www.baeldung.com/java-add-hours-date) - [Guide to DateTimeFormatter](https://www.baeldung.com/java-datetimeformatter) - [Format ZonedDateTime to String](https://www.baeldung.com/java-format-zoned-datetime-string) +- [Convert Between java.time.Instant and java.sql.Timestamp](Convert Between java.time.Instant and java.sql.Timestamp) diff --git a/persistence-modules/spring-boot-persistence/README.MD b/persistence-modules/spring-boot-persistence/README.MD index 6cf172426a..8988fb4ebd 100644 --- a/persistence-modules/spring-boot-persistence/README.MD +++ b/persistence-modules/spring-boot-persistence/README.MD @@ -4,3 +4,4 @@ - [Configuring Separate Spring DataSource for Tests](http://www.baeldung.com/spring-testing-separate-data-source) - [Quick Guide on data.sql and schema.sql Files in Spring Boot](http://www.baeldung.com/spring-boot-data-sql-and-schema-sql) - [Configuring a Tomcat Connection Pool in Spring Boot](https://www.baeldung.com/spring-boot-tomcat-connection-pool) +- [Hibernate Field Naming with Spring Boot](https://www.baeldung.com/hibernate-field-naming-spring-boot) diff --git a/persistence-modules/spring-data-jpa/README.md b/persistence-modules/spring-data-jpa/README.md index 44ce240da3..a65b744944 100644 --- a/persistence-modules/spring-data-jpa/README.md +++ b/persistence-modules/spring-data-jpa/README.md @@ -15,6 +15,7 @@ - [Query Entities by Dates and Times with Spring Data JPA](https://www.baeldung.com/spring-data-jpa-query-by-date) - [DDD Aggregates and @DomainEvents](https://www.baeldung.com/spring-data-ddd) - [Spring Data – CrudRepository save() Method](https://www.baeldung.com/spring-data-crud-repository-save) +- [Limiting Query Results with JPA and Spring Data JPA](https://www.baeldung.com/jpa-limit-query-results) ### Eclipse Config After importing the project into Eclipse, you may see the following error: diff --git a/persistence-modules/spring-data-mongodb/README.md b/persistence-modules/spring-data-mongodb/README.md index c7bc7584be..c4f21dffc0 100644 --- a/persistence-modules/spring-data-mongodb/README.md +++ b/persistence-modules/spring-data-mongodb/README.md @@ -12,3 +12,4 @@ - [Spring Data MongoDB: Projections and Aggregations](http://www.baeldung.com/spring-data-mongodb-projections-aggregations) - [Spring Data Annotations](http://www.baeldung.com/spring-data-annotations) - [Spring Data MongoDB Transactions](https://www.baeldung.com/spring-data-mongodb-transactions ) +- [ZonedDateTime with Spring Data MongoDB](https://www.baeldung.com/spring-data-mongodb-zoneddatetime) diff --git a/spring-5-reactive-oauth/README.md b/spring-5-reactive-oauth/README.md new file mode 100644 index 0000000000..0f27cf5d20 --- /dev/null +++ b/spring-5-reactive-oauth/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + +- [Spring Security OAuth Login with WebFlux](https://www.baeldung.com/spring-oauth-login-webflux) diff --git a/spring-all/README.md b/spring-all/README.md index 34e5c3435e..0d78efdcf2 100644 --- a/spring-all/README.md +++ b/spring-all/README.md @@ -33,3 +33,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Spring Cache – Creating a Custom KeyGenerator](http://www.baeldung.com/spring-cache-custom-keygenerator) - [Spring @Primary Annotation](http://www.baeldung.com/spring-primary) - [Spring Events](https://www.baeldung.com/spring-events) +- [Spring Null-Safety Annotations](https://www.baeldung.com/spring-null-safety-annotations) diff --git a/spring-cloud/README.md b/spring-cloud/README.md index 16bc2d110a..dc43bd1a66 100644 --- a/spring-cloud/README.md +++ b/spring-cloud/README.md @@ -30,3 +30,4 @@ - [Introduction to Netflix Archaius with Spring Cloud](https://www.baeldung.com/netflix-archaius-spring-cloud-integration) - [An Intro to Spring Cloud Vault](https://www.baeldung.com/spring-cloud-vault) - [Netflix Archaius with Various Database Configurations](https://www.baeldung.com/netflix-archaius-database-configurations) +- [Rate Limiting in Spring Cloud Netflix Zuul](https://www.baeldung.com/spring-cloud-zuul-rate-limit) diff --git a/spring-rest-template/README.md b/spring-rest-template/README.md index d69d5c01c7..2c31796080 100644 --- a/spring-rest-template/README.md +++ b/spring-rest-template/README.md @@ -5,3 +5,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring ### Relevant Articles: - [Uploading MultipartFile with Spring RestTemplate](http://www.baeldung.com/spring-rest-template-multipart-upload) +- [Mocking a RestTemplate in Spring](https://www.baeldung.com/spring-mock-rest-template) diff --git a/spring-rest/README.md b/spring-rest/README.md index d449a4d92a..5b8a35a4a5 100644 --- a/spring-rest/README.md +++ b/spring-rest/README.md @@ -23,3 +23,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Using the Spring RestTemplate Interceptor](http://www.baeldung.com/spring-rest-template-interceptor) - [Get and Post Lists of Objects with RestTemplate](http://www.baeldung.com/spring-rest-template-list) - [How to Set a Header on a Response with Spring 5](http://www.baeldung.com/spring-response-header) +- [Spring’s RequestBody and ResponseBody Annotations](https://www.baeldung.com/spring-request-response-body) From 4d3b4ca3f0f11cd6cfb06c57abe4f006c7db6ba4 Mon Sep 17 00:00:00 2001 From: Seun Matt Date: Thu, 22 Nov 2018 08:02:44 +0100 Subject: [PATCH 08/31] Moved example code for BAEL-2366 (#5752) * added example code for BAEL-2366 * moved example code for BAEL-2366 --- .../StringReplaceAndRemoveUnitTest.java | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 java-strings/src/test/java/com/baeldung/string/StringReplaceAndRemoveUnitTest.java diff --git a/java-strings/src/test/java/com/baeldung/string/StringReplaceAndRemoveUnitTest.java b/java-strings/src/test/java/com/baeldung/string/StringReplaceAndRemoveUnitTest.java new file mode 100644 index 0000000000..d952d2383b --- /dev/null +++ b/java-strings/src/test/java/com/baeldung/string/StringReplaceAndRemoveUnitTest.java @@ -0,0 +1,83 @@ +package com.baeldung.string; + + +import org.apache.commons.lang3.StringUtils; +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class StringReplaceAndRemoveUnitTest { + + + @Test + public void givenTestStrings_whenReplace_thenProcessedString() { + + String master = "Hello World Baeldung!"; + String target = "Baeldung"; + String replacement = "Java"; + String processed = master.replace(target, replacement); + assertTrue(processed.contains(replacement)); + assertFalse(processed.contains(target)); + + } + + @Test + public void givenTestStrings_whenReplaceAll_thenProcessedString() { + + String master2 = "Welcome to Baeldung, Hello World Baeldung"; + String regexTarget= "(Baeldung)$"; + String replacement = "Java"; + String processed2 = master2.replaceAll(regexTarget, replacement); + assertTrue(processed2.endsWith("Java")); + + } + + @Test + public void givenTestStrings_whenStringBuilderMethods_thenProcessedString() { + + String master = "Hello World Baeldung!"; + String target = "Baeldung"; + String replacement = "Java"; + + int startIndex = master.indexOf(target); + int stopIndex = startIndex + target.length(); + + StringBuilder builder = new StringBuilder(master); + + + builder.delete(startIndex, stopIndex); + assertFalse(builder.toString().contains(target)); + + + builder.replace(startIndex, stopIndex, replacement); + assertTrue(builder.toString().contains(replacement)); + + + } + + + @Test + public void givenTestStrings_whenStringUtilsMethods_thenProcessedStrings() { + + String master = "Hello World Baeldung!"; + String target = "Baeldung"; + String replacement = "Java"; + + String processed = StringUtils.replace(master, target, replacement); + assertTrue(processed.contains(replacement)); + + String master2 = "Hello World Baeldung!"; + String target2 = "baeldung"; + String processed2 = StringUtils.replaceIgnoreCase(master2, target2, replacement); + assertFalse(processed2.contains(target)); + + } + + + + + + + +} From 3928c8955934209ae00de8656c6065de1f5a565c Mon Sep 17 00:00:00 2001 From: Eugen Paraschiv Date: Thu, 22 Nov 2018 16:19:26 +0200 Subject: [PATCH 09/31] the third profile --- pom.xml | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/pom.xml b/pom.xml index 5ebf7ba4f3..2fed100fc6 100644 --- a/pom.xml +++ b/pom.xml @@ -738,6 +738,46 @@ helidon + + + + default-third + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + 3 + true + + **/*IntegrationTest.java + **/*IntTest.java + **/*LongRunningUnitTest.java + **/*ManualTest.java + **/*JdbcTest.java + **/*LiveTest.java + + + + + + + + + parent-boot-1 + parent-boot-2 + parent-spring-4 + parent-spring-5 + parent-java + parent-kotlin + + testing-modules/gatling + geotools + + From af3e0e9b063b71b6109be70b2b5c8b1a1e3db728 Mon Sep 17 00:00:00 2001 From: Eugen Paraschiv Date: Thu, 22 Nov 2018 17:38:17 +0200 Subject: [PATCH 10/31] splitting the integration-lite profile --- pom.xml | 72 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/pom.xml b/pom.xml index 2fed100fc6..d72fcc9f26 100644 --- a/pom.xml +++ b/pom.xml @@ -1238,43 +1238,8 @@ - - integration-lite-test - - - - - org.apache.maven.plugins - maven-surefire-plugin - - - **/*ManualTest.java - **/*LiveTest.java - - - **/*IntegrationTest.java - **/*IntTest.java - - - - - - - - parent-boot-1 - parent-boot-2 - parent-spring-4 - parent-spring-5 - parent-java - parent-kotlin - - spring-4 - - - - - integration-lite + integration-lite-first @@ -1302,6 +1267,7 @@ parent-spring-5 parent-java parent-kotlin + asm atomix persistence-modules/apache-cayenne @@ -1449,7 +1415,41 @@ spring-cucumber spring-ejb spring-aop + + + + + + integration-lite-second + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*ManualTest.java + **/*LiveTest.java + + + **/*IntegrationTest.java + **/*IntTest.java + + + + + + + + parent-boot-1 + parent-boot-2 + parent-spring-4 + parent-spring-5 + parent-java + parent-kotlin + persistence-modules/spring-data-dynamodb persistence-modules/spring-data-keyvalue persistence-modules/spring-data-mongodb From 608fe77823aa77578393678afed1f7709c67562a Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Thu, 22 Nov 2018 17:53:33 +0200 Subject: [PATCH 11/31] disable gib default (#5726) * disable gib default * Update .travis.yml --- .travis.yml | 2 +- pom.xml | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 683422dc97..5e86714a89 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ before_install: - echo "MAVEN_OPTS='-Xmx2048M -Xss128M -XX:+CMSClassUnloadingEnabled -XX:+UseG1GC -XX:-UseGCOverheadLimit'" > ~/.mavenrc install: skip -script: travis_wait 60 mvn -q install -Pdefault-first,default-second +script: travis_wait 60 mvn -q install -Pdefault-first,default-second -Dgib.enabled=true sudo: required diff --git a/pom.xml b/pom.xml index d72fcc9f26..00d5af8214 100644 --- a/pom.xml +++ b/pom.xml @@ -1575,7 +1575,6 @@ + false 4.12 1.3 From 076de3f006be1687b600bbb9ca86a9e1ebebdd36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Dupire?= Date: Thu, 22 Nov 2018 17:22:47 +0100 Subject: [PATCH 12/31] BAEL-2309 Retrieving a Class Name in Java (#5716) * [BAEL-2309] SomeClass and its test * [BAEL-2309] Fixing test naming * [BAEL-2309] Changed name for RetrievingClassName * [BAEL-2309] Updating package name * [BAEL-2309] Fix comment mistake * [BAEL-2309] Fixing test class name --- .../className/RetrievingClassName.java | 9 + .../RetrievingClassNameUnitTest.java | 156 ++++++++++++++++++ 2 files changed, 165 insertions(+) create mode 100644 core-java/src/main/java/com/baeldung/className/RetrievingClassName.java create mode 100644 core-java/src/test/java/com/baeldung/className/RetrievingClassNameUnitTest.java diff --git a/core-java/src/main/java/com/baeldung/className/RetrievingClassName.java b/core-java/src/main/java/com/baeldung/className/RetrievingClassName.java new file mode 100644 index 0000000000..ab6c8a51ff --- /dev/null +++ b/core-java/src/main/java/com/baeldung/className/RetrievingClassName.java @@ -0,0 +1,9 @@ +package com.baeldung.className; + +public class RetrievingClassName { + + public class InnerClass { + + } + +} diff --git a/core-java/src/test/java/com/baeldung/className/RetrievingClassNameUnitTest.java b/core-java/src/test/java/com/baeldung/className/RetrievingClassNameUnitTest.java new file mode 100644 index 0000000000..f9dbf91d2c --- /dev/null +++ b/core-java/src/test/java/com/baeldung/className/RetrievingClassNameUnitTest.java @@ -0,0 +1,156 @@ +package com.baeldung.className; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +public class RetrievingClassNameUnitTest { + + // Retrieving Simple Name + @Test + public void givenRetrievingClassName_whenGetSimpleName_thenRetrievingClassName() { + assertEquals("RetrievingClassName", RetrievingClassName.class.getSimpleName()); + } + + @Test + public void givenPrimitiveInt_whenGetSimpleName_thenInt() { + assertEquals("int", int.class.getSimpleName()); + } + + @Test + public void givenRetrievingClassNameArray_whenGetSimpleName_thenRetrievingClassNameWithBrackets() { + assertEquals("RetrievingClassName[]", RetrievingClassName[].class.getSimpleName()); + assertEquals("RetrievingClassName[][]", RetrievingClassName[][].class.getSimpleName()); + } + + @Test + public void givenAnonymousClass_whenGetSimpleName_thenEmptyString() { + assertEquals("", new RetrievingClassName() {}.getClass().getSimpleName()); + } + + // Retrieving Other Names + // - Primitive Types + @Test + public void givenPrimitiveInt_whenGetName_thenInt() { + assertEquals("int", int.class.getName()); + } + + @Test + public void givenPrimitiveInt_whenGetTypeName_thenInt() { + assertEquals("int", int.class.getTypeName()); + } + + @Test + public void givenPrimitiveInt_whenGetCanonicalName_thenInt() { + assertEquals("int", int.class.getCanonicalName()); + } + + // - Object Types + @Test + public void givenRetrievingClassName_whenGetName_thenCanonicalName() { + assertEquals("com.baeldung.className.RetrievingClassName", RetrievingClassName.class.getName()); + } + + @Test + public void givenRetrievingClassName_whenGetTypeName_thenCanonicalName() { + assertEquals("com.baeldung.className.RetrievingClassName", RetrievingClassName.class.getTypeName()); + } + + @Test + public void givenRetrievingClassName_whenGetCanonicalName_thenCanonicalName() { + assertEquals("com.baeldung.className.RetrievingClassName", RetrievingClassName.class.getCanonicalName()); + } + + // - Inner Classes + @Test + public void givenRetrievingClassNameInnerClass_whenGetName_thenCanonicalNameWithDollarSeparator() { + assertEquals("com.baeldung.className.RetrievingClassName$InnerClass", RetrievingClassName.InnerClass.class.getName()); + } + + @Test + public void givenRetrievingClassNameInnerClass_whenGetTypeName_thenCanonicalNameWithDollarSeparator() { + assertEquals("com.baeldung.className.RetrievingClassName$InnerClass", RetrievingClassName.InnerClass.class.getTypeName()); + } + + @Test + public void givenRetrievingClassNameInnerClass_whenGetCanonicalName_thenCanonicalName() { + assertEquals("com.baeldung.className.RetrievingClassName.InnerClass", RetrievingClassName.InnerClass.class.getCanonicalName()); + } + + // - Anonymous Classes + @Test + public void givenAnonymousClass_whenGetName_thenCallingClassCanonicalNameWithDollarSeparatorAndCountNumber() { + // These are the second and third appearences of an anonymous class in RetrievingClassNameUnitTest, hence $2 and $3 expectations + assertEquals("com.baeldung.className.RetrievingClassNameUnitTest$2", new RetrievingClassName() {}.getClass().getName()); + assertEquals("com.baeldung.className.RetrievingClassNameUnitTest$3", new RetrievingClassName() {}.getClass().getName()); + } + + @Test + public void givenAnonymousClass_whenGetTypeName_thenCallingClassCanonicalNameWithDollarSeparatorAndCountNumber() { + // These are the fourth and fifth appearences of an anonymous class in RetrievingClassNameUnitTest, hence $4 and $5 expectations + assertEquals("com.baeldung.className.RetrievingClassNameUnitTest$4", new RetrievingClassName() {}.getClass().getTypeName()); + assertEquals("com.baeldung.className.RetrievingClassNameUnitTest$5", new RetrievingClassName() {}.getClass().getTypeName()); + } + + @Test + public void givenAnonymousClass_whenGetCanonicalName_thenNull() { + assertNull(new RetrievingClassName() {}.getClass().getCanonicalName()); + } + + // - Arrays + @Test + public void givenPrimitiveIntArray_whenGetName_thenOpeningBracketsAndPrimitiveIntLetter() { + assertEquals("[I", int[].class.getName()); + assertEquals("[[I", int[][].class.getName()); + } + + @Test + public void givenRetrievingClassNameArray_whenGetName_thenOpeningBracketsLetterLAndRetrievingClassNameGetName() { + assertEquals("[Lcom.baeldung.className.RetrievingClassName;", RetrievingClassName[].class.getName()); + assertEquals("[[Lcom.baeldung.className.RetrievingClassName;", RetrievingClassName[][].class.getName()); + } + + @Test + public void givenRetrievingClassNameInnerClassArray_whenGetName_thenOpeningBracketsLetterLAndRetrievingClassNameInnerClassGetName() { + assertEquals("[Lcom.baeldung.className.RetrievingClassName$InnerClass;", RetrievingClassName.InnerClass[].class.getName()); + assertEquals("[[Lcom.baeldung.className.RetrievingClassName$InnerClass;", RetrievingClassName.InnerClass[][].class.getName()); + } + + @Test + public void givenPrimitiveIntArray_whenGetTypeName_thenPrimitiveIntGetTypeNameWithBrackets() { + assertEquals("int[]", int[].class.getTypeName()); + assertEquals("int[][]", int[][].class.getTypeName()); + } + + @Test + public void givenRetrievingClassNameArray_whenGetTypeName_thenRetrievingClassNameGetTypeNameWithBrackets() { + assertEquals("com.baeldung.className.RetrievingClassName[]", RetrievingClassName[].class.getTypeName()); + assertEquals("com.baeldung.className.RetrievingClassName[][]", RetrievingClassName[][].class.getTypeName()); + } + + @Test + public void givenRetrievingClassNameInnerClassArray_whenGetTypeName_thenRetrievingClassNameInnerClassGetTypeNameWithBrackets() { + assertEquals("com.baeldung.className.RetrievingClassName$InnerClass[]", RetrievingClassName.InnerClass[].class.getTypeName()); + assertEquals("com.baeldung.className.RetrievingClassName$InnerClass[][]", RetrievingClassName.InnerClass[][].class.getTypeName()); + } + + @Test + public void givenPrimitiveIntArray_whenGetCanonicalName_thenPrimitiveIntGetCanonicalNameWithBrackets() { + assertEquals("int[]", int[].class.getCanonicalName()); + assertEquals("int[][]", int[][].class.getCanonicalName()); + } + + @Test + public void givenRetrievingClassNameArray_whenGetCanonicalName_thenRetrievingClassNameGetCanonicalNameWithBrackets() { + assertEquals("com.baeldung.className.RetrievingClassName[]", RetrievingClassName[].class.getCanonicalName()); + assertEquals("com.baeldung.className.RetrievingClassName[][]", RetrievingClassName[][].class.getCanonicalName()); + } + + @Test + public void givenRetrievingClassNameInnerClassArray_whenGetCanonicalName_thenRetrievingClassNameInnerClassGetCanonicalNameWithBrackets() { + assertEquals("com.baeldung.className.RetrievingClassName.InnerClass[]", RetrievingClassName.InnerClass[].class.getCanonicalName()); + assertEquals("com.baeldung.className.RetrievingClassName.InnerClass[][]", RetrievingClassName.InnerClass[][].class.getCanonicalName()); + } + +} \ No newline at end of file From e24d89199b668199a35b445fd4fc417ac9a1dc4e Mon Sep 17 00:00:00 2001 From: Eugen Paraschiv Date: Thu, 22 Nov 2018 19:52:02 +0200 Subject: [PATCH 13/31] profile work --- pom.xml | 96 ++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 65 insertions(+), 31 deletions(-) diff --git a/pom.xml b/pom.xml index 00d5af8214..f94574a801 100644 --- a/pom.xml +++ b/pom.xml @@ -1384,37 +1384,6 @@ testing-modules/selenium-junit-testng persistence-modules/solr spark-java - spring-4 - spring-5-data-reactive - spring-5-reactive - spring-5-reactive-security - spring-5-reactive-client - spring-5-mvc - spring-5-security - spring-activiti - spring-akka - spring-amqp - spring-all - spring-amqp-simple - spring-apache-camel - spring-batch - spring-bom - spring-boot-keycloak - spring-boot-bootstrap - spring-boot-admin - spring-boot-camel - persistence-modules/spring-boot-persistence - spring-boot-security - spring-boot-mvc - spring-boot-logging-log4j2 - spring-boot-disable-console-logging - spring-cloud-data-flow - spring-cloud - spring-cloud-bus - spring-core - spring-cucumber - spring-ejb - spring-aop @@ -1450,6 +1419,38 @@ parent-java parent-kotlin + spring-4 + spring-5-data-reactive + spring-5-reactive + spring-5-reactive-security + spring-5-reactive-client + spring-5-mvc + spring-5-security + spring-activiti + spring-akka + spring-amqp + spring-all + spring-amqp-simple + spring-apache-camel + spring-batch + spring-bom + spring-boot-keycloak + spring-boot-bootstrap + spring-boot-admin + spring-boot-camel + persistence-modules/spring-boot-persistence + spring-boot-security + spring-boot-mvc + spring-boot-logging-log4j2 + spring-boot-disable-console-logging + spring-cloud-data-flow + spring-cloud + spring-cloud-bus + spring-core + spring-cucumber + spring-ejb + spring-aop + persistence-modules/spring-data-dynamodb persistence-modules/spring-data-keyvalue persistence-modules/spring-data-mongodb @@ -1531,6 +1532,39 @@ testing-modules/testing testing-modules/testng video-tutorials + + + + + + integration-lite-third + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*ManualTest.java + **/*LiveTest.java + + + **/*IntegrationTest.java + **/*IntTest.java + + + + + + + + parent-boot-1 + parent-boot-2 + parent-spring-4 + parent-spring-5 + parent-java + parent-kotlin xmlunit-2 struts-2 From 5ad9f285e14451760cb24c189276ad76cce5fcc7 Mon Sep 17 00:00:00 2001 From: Eugen Paraschiv Date: Thu, 22 Nov 2018 20:37:50 +0200 Subject: [PATCH 14/31] profile work --- pom.xml | 783 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 400 insertions(+), 383 deletions(-) diff --git a/pom.xml b/pom.xml index f94574a801..e36a972611 100644 --- a/pom.xml +++ b/pom.xml @@ -934,310 +934,6 @@ - - integration - - - - - org.apache.maven.plugins - maven-surefire-plugin - - - **/*ManualTest.java - **/*LiveTest.java - - - **/*IntegrationTest.java - **/*IntTest.java - - - - - - - - - parent-boot-1 - parent-boot-2 - parent-spring-4 - parent-spring-5 - parent-java - parent-kotlin - - - - - - - - - - testing-modules/mockito - testing-modules/mockito-2 - testing-modules/mocks - mustache - mvn-wrapper - noexception - persistence-modules/orientdb - osgi - orika - patterns - pdf - protobuffer - persistence-modules/querydsl - reactor-core - persistence-modules/redis - testing-modules/rest-assured - testing-modules/rest-testing - resteasy - rxjava - rxjava-2 - spring-swagger-codegen - testing-modules/selenium-junit-testng - persistence-modules/solr - spark-java - spring-4 - spring-5 - spring-5-data-reactive - spring-5-reactive - spring-5-reactive-security - spring-5-reactive-client - spring-5-mvc - spring-5-security - spring-activiti - spring-akka - spring-amqp - spring-all - spring-amqp-simple - spring-apache-camel - spring-batch - jmh - - - - - - spring-bom - spring-boot - spring-boot-client - spring-boot-keycloak - spring-boot-bootstrap - spring-boot-admin - spring-boot-camel - spring-boot-ops - persistence-modules/spring-boot-persistence - spring-boot-security - spring-boot-mvc - spring-boot-logging-log4j2 - spring-boot-disable-console-logging - spring-cloud-data-flow - spring-cloud - spring-cloud-bus - spring-core - spring-cucumber - spring-ejb - spring-aop - persistence-modules/spring-data-cassandra - persistence-modules/spring-data-couchbase-2 - persistence-modules/spring-data-dynamodb - persistence-modules/spring-data-elasticsearch - persistence-modules/spring-data-keyvalue - persistence-modules/spring-data-mongodb - persistence-modules/spring-data-jpa - persistence-modules/spring-data-neo4j - persistence-modules/spring-data-redis - spring-data-rest - - - - - - - persistence-modules/spring-data-solr - spring-dispatcher-servlet - spring-exceptions - spring-freemarker - persistence-modules/spring-hibernate-3 - persistence-modules/spring-hibernate4 - persistence-modules/spring-hibernate-5 - persistence-modules/spring-data-eclipselink - spring-integration - spring-jenkins-pipeline - spring-jersey - spring-jms - spring-jooq - persistence-modules/spring-jpa - spring-kafka - spring-katharsis - spring-ldap - spring-mockito - spring-mvc-forms-jsp - spring-mvc-forms-thymeleaf - spring-mvc-java - spring-mvc-velocity - spring-mvc-webflow - spring-mvc-xml - spring-mvc-kotlin - spring-protobuf - spring-quartz - spring-rest-angular - spring-rest-full - spring-rest-query-language - spring-rest - spring-resttemplate - spring-rest-simple - spring-reactive-kotlin - - - - - - - - - - - - - - - - java-websocket - persistence-modules/activejdbc - animal-sniffer-mvn-plugin - apache-avro - apache-bval - apache-shiro - apache-spark - asciidoctor - checker-plugin - - - core-java-sun - custom-pmd - dagger - data-structures - dubbo - persistence-modules/flyway - - - jni - jooby - - - - ratpack - rest-with-spark-java - spring-boot-autoconfiguration - spring-boot-custom-starter - spring-boot-jasypt - spring-data-rest-querydsl - spring-groovy - spring-mobile - spring-mustache - spring-mvc-simple - spring-mybatis - spring-rest-hal-browser - spring-rest-shell - spring-rest-template - spring-roo - spring-security-stormpath - sse-jaxrs - static-analysis - stripe - - - wicket - xstream - cas/cas-secured-app - - - - - - - - - - - - - - jenkins/hello-world - - - - spring-boot-custom-starter/greeter - persistence-modules/spring-boot-h2/spring-boot-h2-database - - - - - - - - integration-lite-first @@ -1270,7 +966,6 @@ asm atomix - persistence-modules/apache-cayenne aws aws-lambda akka-streams @@ -1290,25 +985,30 @@ autovalue axon azure + apache-velocity + apache-solrj + apache-meecrowave + antlr + bootique + cdi - java-strings - core-java-collections - java-collections-conversions - java-collections-maps core-java-io core-java-8 - java-streams core-groovy - couchbase - persistence-modules/deltaspike + dozer + disruptor + drools + deeplearning4j + ethereum + feign flips - testing-modules/groovy-spock + google-cloud gson guava @@ -1317,17 +1017,20 @@ guava-modules/guava-19 guava-modules/guava-21 guice - disruptor - spring-static-resources + hazelcast - persistence-modules/hbase - hystrix + httpclient + image-processing immutables - persistence-modules/influxdb + jackson - vavr + java-strings + + java-collections-conversions + java-collections-maps + java-streams java-lite java-numbers java-rmi @@ -1345,45 +1048,68 @@ json jsoup jta - testing-modules/junit-5 - testing-modules/junit5-migration jws + jersey + java-spi + java-ee-8-security-api + libraries-data linkrest logging-modules/log-mdc logging-modules/log4j - logging-modules/logback lombok + lucene + mapstruct - maven mesos-marathon msf4j - testing-modules/mockito - testing-modules/mockito-2 - testing-modules/mocks mustache mvn-wrapper + mybatis + metrics + maven-archetype + noexception - persistence-modules/orientdb + osgi orika + patterns pdf protobuffer - persistence-modules/querydsl - reactor-core + performance-tests + + persistence-modules/java-jdbi persistence-modules/redis - testing-modules/rest-assured - testing-modules/rest-testing + persistence-modules/orientdb + persistence-modules/querydsl + persistence-modules/apache-cayenne + persistence-modules/solr + persistence-modules/spring-data-dynamodb + persistence-modules/spring-data-keyvalue + persistence-modules/spring-data-mongodb + persistence-modules/spring-data-neo4j + persistence-modules/spring-data-solr + persistence-modules/spring-hibernate-5 + persistence-modules/spring-data-eclipselink + persistence-modules/spring-jpa + persistence-modules/spring-hibernate-3 + persistence-modules/spring-data-gemfire + persistence-modules/spring-boot-persistence + persistence-modules/liquibase + persistence-modules/java-cockroachdb + persistence-modules/deltaspike + persistence-modules/hbase + persistence-modules/influxdb + persistence-modules/spring-hibernate4 + + reactor-core resteasy rxjava rxjava-2 - spring-swagger-codegen - testing-modules/selenium-junit-testng - persistence-modules/solr - spark-java + rabbitmq @@ -1434,15 +1160,16 @@ spring-apache-camel spring-batch spring-bom + spring-boot-keycloak spring-boot-bootstrap spring-boot-admin spring-boot-camel - persistence-modules/spring-boot-persistence spring-boot-security spring-boot-mvc spring-boot-logging-log4j2 spring-boot-disable-console-logging + spring-cloud-data-flow spring-cloud spring-cloud-bus @@ -1451,27 +1178,17 @@ spring-ejb spring-aop - persistence-modules/spring-data-dynamodb - persistence-modules/spring-data-keyvalue - persistence-modules/spring-data-mongodb - persistence-modules/spring-data-neo4j - spring-data-rest - persistence-modules/spring-data-solr spring-dispatcher-servlet spring-exceptions spring-freemarker - persistence-modules/spring-hibernate-3 - persistence-modules/spring-hibernate-5 - persistence-modules/spring-data-eclipselink spring-integration spring-jenkins-pipeline spring-jersey spring-jms spring-jooq - persistence-modules/spring-jpa spring-kafka spring-katharsis spring-ldap @@ -1529,9 +1246,15 @@ spring-vault spring-jinq spring-rest-embedded-tomcat - testing-modules/testing - testing-modules/testng - video-tutorials + + spring-static-resources + spring-swagger-codegen + spring-drools + spring-boot-property-exp + spring-security-thymeleaf + spring-boot-ctx-fluent + spring-webflux-amqp + @@ -1565,48 +1288,38 @@ parent-spring-5 parent-java parent-kotlin - - xmlunit-2 + + spark-java + saas struts-2 - apache-velocity - apache-solrj - rabbitmq - - persistence-modules/spring-data-gemfire - mybatis - spring-drools - drools - persistence-modules/liquibase - spring-boot-property-exp + + testing-modules/selenium-junit-testng + testing-modules/groovy-spock + testing-modules/mockito + testing-modules/mockito-2 + testing-modules/mocks + testing-modules/rest-assured + testing-modules/rest-testing + testing-modules/junit-5 + testing-modules/junit5-migration + testing-modules/testing + testing-modules/testng testing-modules/mockserver testing-modules/test-containers + twilio + undertow + + video-tutorials vaadin vertx-and-rxjava - saas - deeplearning4j - lucene vraptor - persistence-modules/java-cockroachdb - spring-security-thymeleaf - persistence-modules/java-jdbi - jersey - java-spi - performance-tests - twilio - spring-boot-ctx-fluent - java-ee-8-security-api - spring-webflux-amqp - antlr - maven-archetype - apache-meecrowave - - persistence-modules/spring-hibernate4 - xml vertx - metrics - httpclient - + vavr + + xmlunit-2 + xml + + + + + + + + + + testing-modules/mockito + testing-modules/mockito-2 + testing-modules/mocks + mustache + mvn-wrapper + noexception + persistence-modules/orientdb + osgi + orika + patterns + pdf + protobuffer + persistence-modules/querydsl + reactor-core + persistence-modules/redis + testing-modules/rest-assured + testing-modules/rest-testing + resteasy + rxjava + rxjava-2 + spring-swagger-codegen + testing-modules/selenium-junit-testng + persistence-modules/solr + spark-java + spring-4 + spring-5 + spring-5-data-reactive + spring-5-reactive + spring-5-reactive-security + spring-5-reactive-client + spring-5-mvc + spring-5-security + spring-activiti + spring-akka + spring-amqp + spring-all + spring-amqp-simple + spring-apache-camel + spring-batch + jmh + + + + + + spring-bom + spring-boot + spring-boot-client + spring-boot-keycloak + spring-boot-bootstrap + spring-boot-admin + spring-boot-camel + spring-boot-ops + persistence-modules/spring-boot-persistence + spring-boot-security + spring-boot-mvc + spring-boot-logging-log4j2 + spring-boot-disable-console-logging + spring-cloud-data-flow + spring-cloud + spring-cloud-bus + spring-core + spring-cucumber + spring-ejb + spring-aop + persistence-modules/spring-data-cassandra + persistence-modules/spring-data-couchbase-2 + persistence-modules/spring-data-dynamodb + persistence-modules/spring-data-elasticsearch + persistence-modules/spring-data-keyvalue + persistence-modules/spring-data-mongodb + persistence-modules/spring-data-jpa + persistence-modules/spring-data-neo4j + persistence-modules/spring-data-redis + spring-data-rest + + + + + + + persistence-modules/spring-data-solr + spring-dispatcher-servlet + spring-exceptions + spring-freemarker + persistence-modules/spring-hibernate-3 + persistence-modules/spring-hibernate4 + persistence-modules/spring-hibernate-5 + persistence-modules/spring-data-eclipselink + spring-integration + spring-jenkins-pipeline + spring-jersey + spring-jms + spring-jooq + persistence-modules/spring-jpa + spring-kafka + spring-katharsis + spring-ldap + spring-mockito + spring-mvc-forms-jsp + spring-mvc-forms-thymeleaf + spring-mvc-java + spring-mvc-velocity + spring-mvc-webflow + spring-mvc-xml + spring-mvc-kotlin + spring-protobuf + spring-quartz + spring-rest-angular + spring-rest-full + spring-rest-query-language + spring-rest + spring-resttemplate + spring-rest-simple + spring-reactive-kotlin + + + + + + + + + + + + + + + + java-websocket + persistence-modules/activejdbc + animal-sniffer-mvn-plugin + apache-avro + apache-bval + apache-shiro + apache-spark + asciidoctor + checker-plugin + + + core-java-sun + custom-pmd + dagger + data-structures + dubbo + persistence-modules/flyway + + + jni + jooby + + + + ratpack + rest-with-spark-java + spring-boot-autoconfiguration + spring-boot-custom-starter + spring-boot-jasypt + spring-data-rest-querydsl + spring-groovy + spring-mobile + spring-mustache + spring-mvc-simple + spring-mybatis + spring-rest-hal-browser + spring-rest-shell + spring-rest-template + spring-roo + spring-security-stormpath + sse-jaxrs + static-analysis + stripe + + + wicket + xstream + cas/cas-secured-app + + + + + + + + + + + + + + jenkins/hello-world + + + + spring-boot-custom-starter/greeter + persistence-modules/spring-boot-h2/spring-boot-h2-database + + + + + + + + integration-heavy From bb00c371513bb44812bda03d120ee9a389a0f74d Mon Sep 17 00:00:00 2001 From: smokeyrobot Date: Thu, 22 Nov 2018 15:13:14 -0500 Subject: [PATCH 15/31] Gatling vs JMeter vs The Grinder Issue: BAEL-46 --- .../load-testing-comparison/pom.xml | 148 +++++++++ .../com/baeldung/loadtesting/Application.java | 12 + .../loadtesting/RewardsController.java | 51 +++ .../loadtesting/TransactionController.java | 26 ++ .../model/CustomerRewardsAccount.java | 22 ++ .../loadtesting/model/Transaction.java | 30 ++ .../repository/CustomerRewardsRepository.java | 11 + .../repository/TransactionRepository.java | 11 + .../scripts/Gatling/GatlingScenario.scala | 52 ++++ .../resources/scripts/JMeter/Test Plan.jmx | 293 ++++++++++++++++++ .../scripts/The Grinder/grinder.properties | 5 + .../resources/scripts/The Grinder/grinder.py | 40 +++ 12 files changed, 701 insertions(+) create mode 100644 testing-modules/load-testing-comparison/pom.xml create mode 100644 testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/Application.java create mode 100644 testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/RewardsController.java create mode 100644 testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/TransactionController.java create mode 100644 testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/model/CustomerRewardsAccount.java create mode 100644 testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/model/Transaction.java create mode 100644 testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/repository/CustomerRewardsRepository.java create mode 100644 testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/repository/TransactionRepository.java create mode 100644 testing-modules/load-testing-comparison/src/main/resources/scripts/Gatling/GatlingScenario.scala create mode 100644 testing-modules/load-testing-comparison/src/main/resources/scripts/JMeter/Test Plan.jmx create mode 100644 testing-modules/load-testing-comparison/src/main/resources/scripts/The Grinder/grinder.properties create mode 100644 testing-modules/load-testing-comparison/src/main/resources/scripts/The Grinder/grinder.py diff --git a/testing-modules/load-testing-comparison/pom.xml b/testing-modules/load-testing-comparison/pom.xml new file mode 100644 index 0000000000..869eda1bb5 --- /dev/null +++ b/testing-modules/load-testing-comparison/pom.xml @@ -0,0 +1,148 @@ + + + + parent-modules + com.baeldung + 1.0.0-SNAPSHOT + ../../pom.xml + + 4.0.0 + + load-testing-bakeoff + + + 1.8 + 1.8 + UTF-8 + 2.11.12 + 2.2.5 + 3.2.2 + 2.2.1 + 5.0 + 3.11 + 2.0.5.RELEASE + + + + + io.gatling + gatling-app + ${gatling.version} + + + io.gatling + gatling-recorder + ${gatling.version} + + + io.gatling.highcharts + gatling-charts-highcharts + ${gatling.version} + + + org.scala-lang + scala-library + ${scala.version} + + + + + + + + com.fasterxml.jackson.core + jackson-databind + 2.9.4 + + + org.springframework.boot + spring-boot-starter + ${spring.boot.version} + + + org.springframework.boot + spring-boot-starter-web + ${spring.boot.version} + + + org.springframework.boot + spring-boot-starter-data-jpa + ${spring.boot.version} + + + org.springframework.boot + spring-boot-starter-test + ${spring.boot.version} + test + + + com.h2database + h2 + 1.4.197 + + + org.projectlombok + lombok + 1.18.2 + compile + + + + + + + + + + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.0.5.RELEASE + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/Application.java b/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/Application.java new file mode 100644 index 0000000000..6647bcb640 --- /dev/null +++ b/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/Application.java @@ -0,0 +1,12 @@ +package com.baeldung.loadtesting; + +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/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/RewardsController.java b/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/RewardsController.java new file mode 100644 index 0000000000..50cc6fb7ab --- /dev/null +++ b/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/RewardsController.java @@ -0,0 +1,51 @@ +package com.baeldung.loadtesting; + +import com.baeldung.loadtesting.model.CustomerRewardsAccount; +import com.baeldung.loadtesting.model.Transaction; +import com.baeldung.loadtesting.repository.CustomerRewardsRepository; +import com.baeldung.loadtesting.repository.TransactionRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.Calendar; +import java.util.List; +import java.util.Optional; + +@RestController +public class RewardsController { + + @Autowired + private CustomerRewardsRepository customerRewardsRepository; + + @Autowired + private TransactionRepository transactionRepository; + + @PostMapping(path="/transactions/add") + public @ResponseBody Transaction saveTransactions(@RequestBody Transaction trnsctn){ + trnsctn.setTransactionDate(Calendar.getInstance().getTime()); + Transaction result = transactionRepository.save(trnsctn); + return result; + } + + @GetMapping(path="/transactions/findAll/{rewardId}") + public @ResponseBody Iterable getTransactions(@PathVariable Integer rewardId){ + return transactionRepository.findByCustomerRewardsId(rewardId); + } + + @PostMapping(path="/rewards/add") + public @ResponseBody CustomerRewardsAccount addRewardsAcount(@RequestBody CustomerRewardsAccount body) { + Optional acct = customerRewardsRepository.findByCustomerId(body.getCustomerId()); + return !acct.isPresent() ? customerRewardsRepository.save(body) : acct.get(); + } + + @GetMapping(path="/rewards/find/{customerId}") + public @ResponseBody + Optional find(@PathVariable Integer customerId) { + return customerRewardsRepository.findByCustomerId(customerId); + } + + @GetMapping(path="/rewards/all") + public @ResponseBody List findAll() { + return customerRewardsRepository.findAll(); + } +} diff --git a/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/TransactionController.java b/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/TransactionController.java new file mode 100644 index 0000000000..2ea2c06a41 --- /dev/null +++ b/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/TransactionController.java @@ -0,0 +1,26 @@ +package com.baeldung.loadtesting; + +import com.baeldung.loadtesting.model.Transaction; +import com.baeldung.loadtesting.repository.TransactionRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +@RestController +@Deprecated +public class TransactionController { + + @Autowired + private TransactionRepository transactionRepository; + + @PostMapping(path="/addTransaction") + public @ResponseBody + String saveTransactions(@RequestBody Transaction trnsctn){ + transactionRepository.save(trnsctn); + return "Saved Transaction."; + } + + @GetMapping(path="/findAll/{rewardId}") + public @ResponseBody Iterable getTransactions(@RequestParam Integer id){ + return transactionRepository.findByCustomerRewardsId(id); + } +} diff --git a/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/model/CustomerRewardsAccount.java b/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/model/CustomerRewardsAccount.java new file mode 100644 index 0000000000..2c6742fbaf --- /dev/null +++ b/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/model/CustomerRewardsAccount.java @@ -0,0 +1,22 @@ +package com.baeldung.loadtesting.model; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +import lombok.Data; + +@Entity +@Data +public class CustomerRewardsAccount { + + @Id + @GeneratedValue(strategy= GenerationType.AUTO) + private Integer id; + private Integer customerId; + + public Integer getCustomerId(){ + return this.customerId; + } +} diff --git a/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/model/Transaction.java b/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/model/Transaction.java new file mode 100644 index 0000000000..312f52f4ab --- /dev/null +++ b/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/model/Transaction.java @@ -0,0 +1,30 @@ +package com.baeldung.loadtesting.model; + +import lombok.Data; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import java.util.Date; +import java.util.Calendar; + +@Entity +@Data +public class Transaction { + + @Id + @GeneratedValue(strategy= GenerationType.AUTO) + private Integer id; + private Integer customerRewardsId; + private Integer customerId; + private Date transactionDate; + + public Transaction(){ + transactionDate = Calendar.getInstance().getTime(); + } + + public void setTransactionDate(Date transactionDate){ + this.transactionDate = transactionDate; + } +} diff --git a/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/repository/CustomerRewardsRepository.java b/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/repository/CustomerRewardsRepository.java new file mode 100644 index 0000000000..f945359eb8 --- /dev/null +++ b/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/repository/CustomerRewardsRepository.java @@ -0,0 +1,11 @@ +package com.baeldung.loadtesting.repository; + +import com.baeldung.loadtesting.model.CustomerRewardsAccount; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.Optional; + +public interface CustomerRewardsRepository extends JpaRepository { + + Optional findByCustomerId(Integer customerId); +} diff --git a/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/repository/TransactionRepository.java b/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/repository/TransactionRepository.java new file mode 100644 index 0000000000..af0b343c10 --- /dev/null +++ b/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/repository/TransactionRepository.java @@ -0,0 +1,11 @@ +package com.baeldung.loadtesting.repository; + +import com.baeldung.loadtesting.model.Transaction; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface TransactionRepository extends JpaRepository { + + List findByCustomerRewardsId(Integer rewardsId); +} diff --git a/testing-modules/load-testing-comparison/src/main/resources/scripts/Gatling/GatlingScenario.scala b/testing-modules/load-testing-comparison/src/main/resources/scripts/Gatling/GatlingScenario.scala new file mode 100644 index 0000000000..f9b3837759 --- /dev/null +++ b/testing-modules/load-testing-comparison/src/main/resources/scripts/Gatling/GatlingScenario.scala @@ -0,0 +1,52 @@ +package com.baeldung + +import scala.util._ +import io.gatling.core.Predef._ +import io.gatling.http.Predef._ +import scala.concurrent.duration._ + +class RewardsScenario extends Simulation { + + def randCustId() = Random.nextInt(99) + + val httpProtocol = http.baseUrl("http://localhost:8080") + .acceptHeader("text/html,application/json;q=0.9,*/*;q=0.8") + .doNotTrackHeader("1") + .acceptLanguageHeader("en-US,en;q=0.5") + .acceptEncodingHeader("gzip, deflate") + .userAgentHeader("Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0") + + val scn = scenario("RewardsScenario") + .repeat(10){ + exec(http("transactions_add") + .post("/transactions/add/") + .body(StringBody("""{ "customerRewardsId":null,"customerId":""""+ randCustId() + """","transactionDate":null }""")).asJson + .check(jsonPath("$.id").saveAs("txnId")) + .check(jsonPath("$.transactionDate").saveAs("txtDate")) + .check(jsonPath("$.customerId").saveAs("custId"))) + .pause(1) + + .exec(http("get_reward") + .get("/rewards/find/${custId}") + .check(jsonPath("$.id").saveAs("rwdId"))) + .pause(1) + + .doIf("${rwdId.isUndefined()}"){ + exec(http("rewards_add") + .post("/rewards/add") + .body(StringBody("""{ "customerId": "${custId}" }""")).asJson + .check(jsonPath("$.id").saveAs("rwdId"))) + } + + .exec(http("transactions_add") + .post("/transactions/add/") + .body(StringBody("""{ "customerRewardsId":"${rwdId}","customerId":"${custId}","transactionDate":"${txtDate}" }""")).asJson) + .pause(1) + + .exec(http("get_reward") + .get("/transactions/findAll/${rwdId}")) + } + setUp( + scn.inject(atOnceUsers(100)) + ).protocols(httpProtocol) +} \ No newline at end of file diff --git a/testing-modules/load-testing-comparison/src/main/resources/scripts/JMeter/Test Plan.jmx b/testing-modules/load-testing-comparison/src/main/resources/scripts/JMeter/Test Plan.jmx new file mode 100644 index 0000000000..da32a13a22 --- /dev/null +++ b/testing-modules/load-testing-comparison/src/main/resources/scripts/JMeter/Test Plan.jmx @@ -0,0 +1,293 @@ + + + + + + false + true + false + + + + + + + + continue + + false + 10 + + 100 + 0 + false + + + + + + true + 1 + + + + + + Content-Type + application/json + + + + + + true + + + + false + {"customerRewardsId":null,"customerId":${random},"transactionDate":null} + = + + + + localhost + 8080 + http + + /transactions/add + POST + true + false + true + false + + + + + + + txnId + $.id + 1 + all + foo + + + + txnDate + $.transactionDate + 1 + Never + + + + custId + $.customerId + 1 + all + bob + + + + + + + + localhost + 8080 + + + /rewards/find/${custId} + GET + true + false + true + false + + + + + + + rwdId + $.id + 1 + 0 + all + + + + + ${rwdId} == 0 + true + + + + true + + + + false + {"customerId":${custId}} + = + + + + localhost + 8080 + + + /rewards/add + POST + true + false + true + false + + + + + + + rwdId + $.id + 1 + bar + all + + + + + + true + + + + false + {"id":${txnId},"customerRewardsId":${rwdId},"customerId":${custId},"transactionDate":"${txnDate}"} + = + + + + localhost + 8080 + + + /transactions/add + POST + true + false + true + false + + + + + + + + + + localhost + 8080 + + + /transactions/findAll/${rwdId} + GET + true + false + true + false + + + + + + + + 10000 + 1 + + false + 67 + random + + + + false + + saveConfig + + + true + true + true + + true + true + true + true + false + true + true + false + false + false + true + false + false + false + true + 0 + true + true + true + true + true + true + + + + + + + false + + saveConfig + + + true + true + true + + true + true + true + true + false + true + true + false + false + false + true + false + false + false + true + 0 + true + true + true + true + true + true + + + + + + + + + diff --git a/testing-modules/load-testing-comparison/src/main/resources/scripts/The Grinder/grinder.properties b/testing-modules/load-testing-comparison/src/main/resources/scripts/The Grinder/grinder.properties new file mode 100644 index 0000000000..68adf90856 --- /dev/null +++ b/testing-modules/load-testing-comparison/src/main/resources/scripts/The Grinder/grinder.properties @@ -0,0 +1,5 @@ +grinder.script = grinder.py +grinder.threads = 100 +grinder.processes = 1 +grinder.runs = 10 +grinder.logDirectory = /logs diff --git a/testing-modules/load-testing-comparison/src/main/resources/scripts/The Grinder/grinder.py b/testing-modules/load-testing-comparison/src/main/resources/scripts/The Grinder/grinder.py new file mode 100644 index 0000000000..025f90d38b --- /dev/null +++ b/testing-modules/load-testing-comparison/src/main/resources/scripts/The Grinder/grinder.py @@ -0,0 +1,40 @@ +import java.util.Random +from net.grinder.script import Test +from net.grinder.script.Grinder import grinder +from net.grinder.plugin.http import HTTPRequest, HTTPPluginControl, HTTPUtilities +from HTTPClient import NVPair + +def parseJsonString(json, element): + for x in json.split(","): + pc = x.replace('"','').split(":") + if pc[0].replace("{","") == element: + ele = pc[1].replace("}","") + return ele + else: + return "" + +test1 = Test(1, "Request resource") +request1 = HTTPRequest() +headers = \ +( NVPair('Content-Type', 'application/json'), ) +request1.setHeaders(headers) +utilities = HTTPPluginControl.getHTTPUtilities() +test1.record(request1) +random=java.util.Random() + +class TestRunner: + def __call__(self): + customerId = str(random.nextInt()); + + result = request1.POST("http://localhost:8080/transactions/add", "{"'"customerRewardsId"'":null,"'"customerId"'":"+ customerId + ","'"transactionDate"'":null}") + txnId = parseJsonString(result.getText(), "id") + + result = request1.GET("http://localhost:8080/rewards/find/"+ customerId) + rwdId = parseJsonString(result.getText(), "id") + + if rwdId == "": + result = request1.POST("http://localhost:8080/rewards/add", "{"'"customerId"'":"+ customerId + "}") + rwdId = parseJsonString(result.getText(), "id") + + result = request1.POST("http://localhost:8080/transactions/add", "{"'"id"'":" + txnId + ","'"customerRewardsId"'":" + rwdId + ","'"customerId"'":"+ customerId + ","'"transactionDate"'":null}") + result = request1.GET("http://localhost:8080/transactions/findAll/" + rwdId) \ No newline at end of file From 668aa4a583105f6598bb861a63cd5ade1a72f854 Mon Sep 17 00:00:00 2001 From: Eugen Paraschiv Date: Thu, 22 Nov 2018 22:42:18 +0200 Subject: [PATCH 16/31] profiles work --- pom.xml | 14 +++++++++++--- spring-amqp-simple/pom.xml | 1 - 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index e36a972611..bc0c63213f 100644 --- a/pom.xml +++ b/pom.xml @@ -1089,7 +1089,6 @@ persistence-modules/solr persistence-modules/spring-data-dynamodb persistence-modules/spring-data-keyvalue - persistence-modules/spring-data-mongodb persistence-modules/spring-data-neo4j persistence-modules/spring-data-solr persistence-modules/spring-hibernate-5 @@ -1111,6 +1110,11 @@ rxjava-2 rabbitmq + + + @@ -1146,7 +1150,6 @@ parent-kotlin spring-4 - spring-5-data-reactive spring-5-reactive spring-5-reactive-security spring-5-reactive-client @@ -1156,7 +1159,6 @@ spring-akka spring-amqp spring-all - spring-amqp-simple spring-apache-camel spring-batch spring-bom @@ -1255,6 +1257,12 @@ spring-boot-ctx-fluent spring-webflux-amqp + + + diff --git a/spring-amqp-simple/pom.xml b/spring-amqp-simple/pom.xml index 3d9ea55cfa..ea9c227d8c 100644 --- a/spring-amqp-simple/pom.xml +++ b/spring-amqp-simple/pom.xml @@ -5,7 +5,6 @@ com.baeldung spring-amqp-simple 1.0.0-SNAPSHOT - Spring AMQP Simple App parent-boot-1 From 4c1f773d07d65bf3716e0d4089aebfbaf39bb04a Mon Sep 17 00:00:00 2001 From: Loredana Date: Thu, 22 Nov 2018 22:59:37 +0200 Subject: [PATCH 17/31] move constructors to java lang module --- core-java-lang/README.md | 1 + .../src/main/java/com/baeldung/constructors/BankAccount.java | 0 .../src/main/java/com/baeldung/constructors/Transaction.java | 0 .../test/java/com/baeldung/constructors/ConstructorUnitTest.java | 0 4 files changed, 1 insertion(+) rename {core-java => core-java-lang}/src/main/java/com/baeldung/constructors/BankAccount.java (100%) rename {core-java => core-java-lang}/src/main/java/com/baeldung/constructors/Transaction.java (100%) rename {core-java => core-java-lang}/src/test/java/com/baeldung/constructors/ConstructorUnitTest.java (100%) diff --git a/core-java-lang/README.md b/core-java-lang/README.md index 85312cba68..62af72818f 100644 --- a/core-java-lang/README.md +++ b/core-java-lang/README.md @@ -56,4 +56,5 @@ - [How to Separate Double into Integer and Decimal Parts](https://www.baeldung.com/java-separate-double-into-integer-decimal-parts) - [“Sneaky Throws” in Java](http://www.baeldung.com/java-sneaky-throws) - [Inheritance and Composition (Is-a vs Has-a relationship) in Java](http://www.baeldung.com/java-inheritance-composition) +- [A Guide to Constructors in Java](https://www.baeldung.com/java-constructors) diff --git a/core-java/src/main/java/com/baeldung/constructors/BankAccount.java b/core-java-lang/src/main/java/com/baeldung/constructors/BankAccount.java similarity index 100% rename from core-java/src/main/java/com/baeldung/constructors/BankAccount.java rename to core-java-lang/src/main/java/com/baeldung/constructors/BankAccount.java diff --git a/core-java/src/main/java/com/baeldung/constructors/Transaction.java b/core-java-lang/src/main/java/com/baeldung/constructors/Transaction.java similarity index 100% rename from core-java/src/main/java/com/baeldung/constructors/Transaction.java rename to core-java-lang/src/main/java/com/baeldung/constructors/Transaction.java diff --git a/core-java/src/test/java/com/baeldung/constructors/ConstructorUnitTest.java b/core-java-lang/src/test/java/com/baeldung/constructors/ConstructorUnitTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/constructors/ConstructorUnitTest.java rename to core-java-lang/src/test/java/com/baeldung/constructors/ConstructorUnitTest.java From bf184639e7f96754af246b9b78eef4a54b85b573 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Thu, 22 Nov 2018 23:36:10 +0200 Subject: [PATCH 18/31] Update README.md --- patterns/design-patterns/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/patterns/design-patterns/README.md b/patterns/design-patterns/README.md index 75f7cec73a..ae372bd460 100644 --- a/patterns/design-patterns/README.md +++ b/patterns/design-patterns/README.md @@ -12,3 +12,4 @@ - [The DAO Pattern in Java](http://www.baeldung.com/java-dao-pattern) - [Interpreter Design Pattern in Java](http://www.baeldung.com/java-interpreter-pattern) - [State Design Pattern in Java](https://www.baeldung.com/java-state-design-pattern) +- [The Decorator Pattern in Java](https://www.baeldung.com/java-decorator-pattern) From d988b1280a2c7d2d31029f3f4f1734dbd78ff511 Mon Sep 17 00:00:00 2001 From: Loredana Date: Thu, 22 Nov 2018 23:59:22 +0200 Subject: [PATCH 19/31] fix test --- .../org/baeldung/client/TestRestTemplateBasicLiveTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-resttemplate/src/test/java/org/baeldung/client/TestRestTemplateBasicLiveTest.java b/spring-resttemplate/src/test/java/org/baeldung/client/TestRestTemplateBasicLiveTest.java index 03a76aca74..e303c75a28 100644 --- a/spring-resttemplate/src/test/java/org/baeldung/client/TestRestTemplateBasicLiveTest.java +++ b/spring-resttemplate/src/test/java/org/baeldung/client/TestRestTemplateBasicLiveTest.java @@ -58,9 +58,9 @@ public class TestRestTemplateBasicLiveTest { @Test public void givenRestTemplateWrapperWithCredentials_whenSendGetForEntity_thenStatusOk() { - RestTemplateBuilder restTemplateBuilder = new RestTemplateBuilder().basicAuthentication("user", "passwd"); + RestTemplateBuilder restTemplateBuilder = new RestTemplateBuilder(); restTemplateBuilder.configure(restTemplate); - TestRestTemplate testRestTemplate = new TestRestTemplate(restTemplateBuilder); + TestRestTemplate testRestTemplate = new TestRestTemplate(restTemplateBuilder, "user", "passwd"); ResponseEntity response = testRestTemplate.getForEntity(URL_SECURED_BY_AUTHENTICATION, String.class); assertThat(response.getStatusCode(), equalTo(HttpStatus.OK)); From 58a536c3953e8a3e71dd256d11a67d8bdf49b7c9 Mon Sep 17 00:00:00 2001 From: kyleandari <44148335+kyleandari@users.noreply.github.com> Date: Fri, 23 Nov 2018 10:46:20 -0500 Subject: [PATCH 20/31] BAEL 2330 * Implementing Hexagonal Architecture in java * Removing duplicates from a string * Fix for the code review feedback - removing the hexagonal architecture code - removing the methods removeDuplicatesUsingCharArray - adding some meaningful sentences to test * Fix for the code review feedback - fix for removeDuplicatesUsingCharArray - adding unit testing - adding brackets around for loops * Fix for the code review feedback * Adding remove duplicates using java 8 distinct adding assets to the unittests to test for empty strings * Checking for empty strings in unit tests Adding an if statement to check whether an empty string is passed to removeDuplicatesUsingSorting method --- .../RemoveDuplicateFromString.java | 25 ++++++++++++------- .../RemoveDuplicateFromStringUnitTest.java | 24 ++++++++++++++++++ 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/java-strings/src/main/java/com/baeldung/stringduplicates/RemoveDuplicateFromString.java b/java-strings/src/main/java/com/baeldung/stringduplicates/RemoveDuplicateFromString.java index eeba81f334..d8fd9c4b14 100644 --- a/java-strings/src/main/java/com/baeldung/stringduplicates/RemoveDuplicateFromString.java +++ b/java-strings/src/main/java/com/baeldung/stringduplicates/RemoveDuplicateFromString.java @@ -44,16 +44,16 @@ public class RemoveDuplicateFromString { } String removeDuplicatesUsingSorting(String str) { - - char[] chars = str.toCharArray(); - - Arrays.sort(chars); - StringBuilder sb = new StringBuilder(); - sb.append(chars[0]); - for (int i = 1; i < chars.length; i++) { - if (chars[i] != chars[i - 1]) { - sb.append(chars[i]); + if(!str.isEmpty()) { + char[] chars = str.toCharArray(); + Arrays.sort(chars); + + sb.append(chars[0]); + for (int i = 1; i < chars.length; i++) { + if (chars[i] != chars[i - 1]) { + sb.append(chars[i]); + } } } @@ -90,6 +90,13 @@ public class RemoveDuplicateFromString { return sb.toString(); } + + String removeDuplicatesUsingDistinct(String str) { + StringBuilder sb = new StringBuilder(); + str.chars().distinct().forEach(c -> sb.append((char) c)); + return sb.toString(); + } + } diff --git a/java-strings/src/test/java/com/baeldung/stringduplicates/RemoveDuplicateFromStringUnitTest.java b/java-strings/src/test/java/com/baeldung/stringduplicates/RemoveDuplicateFromStringUnitTest.java index cf7819ced3..895ecc4a3b 100644 --- a/java-strings/src/test/java/com/baeldung/stringduplicates/RemoveDuplicateFromStringUnitTest.java +++ b/java-strings/src/test/java/com/baeldung/stringduplicates/RemoveDuplicateFromStringUnitTest.java @@ -8,6 +8,8 @@ public class RemoveDuplicateFromStringUnitTest { private final static String STR1 = "racecar"; private final static String STR2 = "J2ee programming"; + private final static String STR_EMPTY = ""; + private RemoveDuplicateFromString removeDuplicateFromString; @Before @@ -20,6 +22,8 @@ public class RemoveDuplicateFromStringUnitTest { public void whenUsingCharArray_DuplicatesShouldBeRemovedWithoutKeepingStringOrder() { String str1 = removeDuplicateFromString.removeDuplicatesUsingCharArray(STR1); String str2 = removeDuplicateFromString.removeDuplicatesUsingCharArray(STR2); + String strEmpty = removeDuplicateFromString.removeDuplicatesUsingCharArray(STR_EMPTY); + Assert.assertEquals("", strEmpty); Assert.assertEquals("ecar", str1); Assert.assertEquals("J2e poraming", str2); } @@ -28,6 +32,9 @@ public class RemoveDuplicateFromStringUnitTest { public void whenUsingLinkedHashSet_DuplicatesShouldBeRemovedAndItKeepStringOrder() { String str1 = removeDuplicateFromString.removeDuplicatesUsinglinkedHashSet(STR1); String str2 = removeDuplicateFromString.removeDuplicatesUsinglinkedHashSet(STR2); + + String strEmpty = removeDuplicateFromString.removeDuplicatesUsinglinkedHashSet(STR_EMPTY); + Assert.assertEquals("", strEmpty); Assert.assertEquals("race", str1); Assert.assertEquals("J2e progamin", str2); } @@ -36,6 +43,9 @@ public class RemoveDuplicateFromStringUnitTest { public void whenUsingSorting_DuplicatesShouldBeRemovedWithoutKeepingStringOrder() { String str1 = removeDuplicateFromString.removeDuplicatesUsingSorting(STR1); String str2 = removeDuplicateFromString.removeDuplicatesUsingSorting(STR2); + + String strEmpty = removeDuplicateFromString.removeDuplicatesUsingSorting(STR_EMPTY); + Assert.assertEquals("", strEmpty); Assert.assertEquals("acer", str1); Assert.assertEquals(" 2Jaegimnopr", str2); } @@ -44,6 +54,8 @@ public class RemoveDuplicateFromStringUnitTest { public void whenUsingHashSet_DuplicatesShouldBeRemovedWithoutKeepingStringOrder() { String str1 = removeDuplicateFromString.removeDuplicatesUsingHashSet(STR1); String str2 = removeDuplicateFromString.removeDuplicatesUsingHashSet(STR2); + String strEmpty = removeDuplicateFromString.removeDuplicatesUsingHashSet(STR_EMPTY); + Assert.assertEquals("", strEmpty); Assert.assertEquals("arce", str1); Assert.assertEquals(" pa2regiJmno", str2); } @@ -52,7 +64,19 @@ public class RemoveDuplicateFromStringUnitTest { public void whenUsingIndexOf_DuplicatesShouldBeRemovedWithoutKeepingStringOrder() { String str1 = removeDuplicateFromString.removeDuplicatesUsingIndexOf(STR1); String str2 = removeDuplicateFromString.removeDuplicatesUsingIndexOf(STR2); + String strEmpty = removeDuplicateFromString.removeDuplicatesUsingIndexOf(STR_EMPTY); + Assert.assertEquals("", strEmpty); Assert.assertEquals("ecar", str1); Assert.assertEquals("J2e poraming", str2); } + + @Test + public void whenUsingJava8_DuplicatesShouldBeRemovedAndItKeepStringOrder() { + String str1 = removeDuplicateFromString.removeDuplicatesUsingDistinct(STR1); + String str2 = removeDuplicateFromString.removeDuplicatesUsingDistinct(STR2); + String strEmpty = removeDuplicateFromString.removeDuplicatesUsingDistinct(STR_EMPTY); + Assert.assertEquals("", strEmpty); + Assert.assertEquals("race", str1); + Assert.assertEquals("J2e progamin", str2); + } } From cfd9a97bd48769f4bbf937e0b71be49177ad1e02 Mon Sep 17 00:00:00 2001 From: Eugen Date: Fri, 23 Nov 2018 17:57:50 +0200 Subject: [PATCH 21/31] Delete README.md --- parent-boot-1/README.md | 1 - 1 file changed, 1 deletion(-) delete mode 100644 parent-boot-1/README.md diff --git a/parent-boot-1/README.md b/parent-boot-1/README.md deleted file mode 100644 index ff12555376..0000000000 --- a/parent-boot-1/README.md +++ /dev/null @@ -1 +0,0 @@ -## Relevant articles: From 64bc8a412d2a40d82fde575c6b542c5e18106f34 Mon Sep 17 00:00:00 2001 From: eelhazati Date: Fri, 23 Nov 2018 17:00:08 +0100 Subject: [PATCH 22/31] JPA Entity Graph. --- .../com/baeldung/jpa/entitygraph/MainApp.java | 26 ++++++ .../jpa/entitygraph/model/Comment.java | 63 +++++++++++++ .../baeldung/jpa/entitygraph/model/Post.java | 86 +++++++++++++++++ .../baeldung/jpa/entitygraph/model/User.java | 48 ++++++++++ .../jpa/entitygraph/repo/PostRepository.java | 93 +++++++++++++++++++ .../main/resources/META-INF/persistence.xml | 55 +++++++---- .../java-jpa/src/main/resources/data-init.sql | 8 ++ .../entitygraph/repo/PostRepositoryTest.java | 68 ++++++++++++++ 8 files changed, 428 insertions(+), 19 deletions(-) create mode 100644 persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/entitygraph/MainApp.java create mode 100644 persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/entitygraph/model/Comment.java create mode 100644 persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/entitygraph/model/Post.java create mode 100644 persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/entitygraph/model/User.java create mode 100644 persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/entitygraph/repo/PostRepository.java create mode 100644 persistence-modules/java-jpa/src/main/resources/data-init.sql create mode 100644 persistence-modules/java-jpa/src/test/java/com/baeldung/jpa/entitygraph/repo/PostRepositoryTest.java diff --git a/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/entitygraph/MainApp.java b/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/entitygraph/MainApp.java new file mode 100644 index 0000000000..88aa4389e9 --- /dev/null +++ b/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/entitygraph/MainApp.java @@ -0,0 +1,26 @@ +package com.baeldung.jpa.entitygraph; + +import com.baeldung.jpa.entitygraph.model.Post; +import com.baeldung.jpa.entitygraph.repo.PostRepository; + +public class MainApp { + + public static void main(String... args) { + Long postId = 1L; + Post post = null; + PostRepository postRepository = new PostRepository(); + + //Using EntityManager.find(). + post = postRepository.find(postId); + post = postRepository.findWithEntityGraph(postId); + post = postRepository.findWithEntityGraph2(postId); + + //Using JPQL: Query and TypedQuery + post = postRepository.findUsingJpql(postId); + + //Using Criteria API + post = postRepository.findUsingCriteria(postId); + + postRepository.clean(); + } +} \ No newline at end of file diff --git a/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/entitygraph/model/Comment.java b/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/entitygraph/model/Comment.java new file mode 100644 index 0000000000..40ecd3262b --- /dev/null +++ b/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/entitygraph/model/Comment.java @@ -0,0 +1,63 @@ +package com.baeldung.jpa.entitygraph.model; + +import javax.persistence.*; + +@Entity +public class Comment { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String reply; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn + private Post post; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn + private User user; + //... + + public Comment() { + } + + public Comment(String reply, Post post, User user) { + this.reply = reply; + this.post = post; + this.user = user; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getReply() { + return reply; + } + + public void setReply(String reply) { + this.reply = reply; + } + + public Post getPost() { + return post; + } + + public void setPost(Post post) { + this.post = post; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } +} \ No newline at end of file diff --git a/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/entitygraph/model/Post.java b/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/entitygraph/model/Post.java new file mode 100644 index 0000000000..59f17ae0c5 --- /dev/null +++ b/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/entitygraph/model/Post.java @@ -0,0 +1,86 @@ +package com.baeldung.jpa.entitygraph.model; + +import javax.persistence.*; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +@NamedEntityGraph( + name = "post-entity-graph", + attributeNodes = { + @NamedAttributeNode("subject"), + @NamedAttributeNode("user"), + @NamedAttributeNode("comments"), + } +) +@NamedEntityGraph( + name = "post-entity-graph-with-comment-users", + attributeNodes = { + @NamedAttributeNode("subject"), + @NamedAttributeNode("user"), + @NamedAttributeNode(value = "comments", subgraph = "comments-subgraph"), + }, + subgraphs = { + @NamedSubgraph( + name = "comments-subgraph", + attributeNodes = { + @NamedAttributeNode("user") + } + ) + } +) +@Entity +public class Post { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + private String subject; + @OneToMany(mappedBy = "post") + private List comments = new ArrayList<>(); + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn + private User user; + //... + + public Post() { + } + + public Post(String subject, User user) { + this.subject = subject; + this.user = user; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getSubject() { + return subject; + } + + public void setSubject(String subject) { + this.subject = subject; + } + + public List getComments() { + return comments; + } + + public void setComments(List comments) { + this.comments = comments; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } +} diff --git a/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/entitygraph/model/User.java b/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/entitygraph/model/User.java new file mode 100644 index 0000000000..b712100d4e --- /dev/null +++ b/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/entitygraph/model/User.java @@ -0,0 +1,48 @@ +package com.baeldung.jpa.entitygraph.model; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +@Entity +public class User { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + private String name; + private String email; + + //... + + public User() { + } + + public User(String email) { + this.email = email; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } +} diff --git a/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/entitygraph/repo/PostRepository.java b/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/entitygraph/repo/PostRepository.java new file mode 100644 index 0000000000..28f1e1b93c --- /dev/null +++ b/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/entitygraph/repo/PostRepository.java @@ -0,0 +1,93 @@ +package com.baeldung.jpa.entitygraph.repo; + +import com.baeldung.jpa.entitygraph.model.Post; + +import javax.persistence.*; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import java.util.HashMap; +import java.util.Map; + +public class PostRepository { + private EntityManagerFactory emf = null; + + + public PostRepository() { + Map properties = new HashMap(); + properties.put("hibernate.show_sql", "true"); + properties.put("hibernate.format_sql", "true"); + emf = Persistence.createEntityManagerFactory("entity-graph-pu", properties); + } + + public Post find(Long id) { + EntityManager entityManager = emf.createEntityManager(); + + Post post = entityManager.find(Post.class, id); + + entityManager.close(); + return post; + } + + public Post findWithEntityGraph(Long id) { + EntityManager entityManager = emf.createEntityManager(); + + EntityGraph entityGraph = entityManager.getEntityGraph("post-entity-graph"); + Map properties = new HashMap<>(); + properties.put("javax.persistence.fetchgraph", entityGraph); + Post post = entityManager.find(Post.class, id, properties); + + entityManager.close(); + return post; + } + + public Post findWithEntityGraph2(Long id) { + EntityManager entityManager = emf.createEntityManager(); + + EntityGraph entityGraph = entityManager.createEntityGraph(Post.class); + entityGraph.addAttributeNodes("subject"); + entityGraph.addAttributeNodes("user"); + entityGraph.addSubgraph("comments") + .addAttributeNodes("user"); + + Map properties = new HashMap<>(); + properties.put("javax.persistence.fetchgraph", entityGraph); + Post post = entityManager.find(Post.class, id, properties); + + entityManager.close(); + return post; + } + + public Post findUsingJpql(Long id) { + EntityManager entityManager = emf.createEntityManager(); + + EntityGraph entityGraph = entityManager.getEntityGraph("post-entity-graph-with-comment-users"); + Post post = entityManager.createQuery("Select p from Post p where p.id=:id", Post.class) + .setParameter("id", id) + .setHint("javax.persistence.fetchgraph", entityGraph) + .getSingleResult(); + + entityManager.close(); + return post; + } + + public Post findUsingCriteria(Long id) { + EntityManager entityManager = emf.createEntityManager(); + + EntityGraph entityGraph = entityManager.getEntityGraph("post-entity-graph-with-comment-users"); + CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); + CriteriaQuery criteriaQuery = criteriaBuilder.createQuery(Post.class); + Root root = criteriaQuery.from(Post.class); + criteriaQuery.where(criteriaBuilder.equal(root.get("id"), id)); + TypedQuery typedQuery = entityManager.createQuery(criteriaQuery); + typedQuery.setHint("javax.persistence.loadgraph", entityGraph); + Post post = typedQuery.getSingleResult(); + + entityManager.close(); + return post; + } + + public void clean() { + emf.close(); + } +} diff --git a/persistence-modules/java-jpa/src/main/resources/META-INF/persistence.xml b/persistence-modules/java-jpa/src/main/resources/META-INF/persistence.xml index 3fdc8ce27c..433d456cc9 100644 --- a/persistence-modules/java-jpa/src/main/resources/META-INF/persistence.xml +++ b/persistence-modules/java-jpa/src/main/resources/META-INF/persistence.xml @@ -9,12 +9,12 @@ org.hibernate.jpa.HibernatePersistenceProvider com.baeldung.sqlresultsetmapping.ScheduledDay - + - - - + value="jdbc:h2:mem:test;INIT=RUNSCRIPT FROM 'classpath:database.sql'"/> + + + @@ -25,28 +25,45 @@ org.hibernate.jpa.HibernatePersistenceProvider com.baeldung.jpa.stringcast.Message - - - - - - + + + + + + - + org.hibernate.jpa.HibernatePersistenceProvider com.baeldung.jpa.model.Car - - - - - - + + + + + + - + + + com.baeldung.jpa.entitygraph.model.Post + com.baeldung.jpa.entitygraph.model.User + com.baeldung.jpa.entitygraph.model.Comment + true + + + + + + + + + + + \ No newline at end of file diff --git a/persistence-modules/java-jpa/src/main/resources/data-init.sql b/persistence-modules/java-jpa/src/main/resources/data-init.sql new file mode 100644 index 0000000000..86c3f2a651 --- /dev/null +++ b/persistence-modules/java-jpa/src/main/resources/data-init.sql @@ -0,0 +1,8 @@ +INSERT INTO `USER` (`ID`,`NAME`,`EMAIL`) VALUES (1,'user1','user1@test.com'); +INSERT INTO `USER` (`ID`,`NAME`,`EMAIL`) VALUES (2,'user2','user2@test.com'); +INSERT INTO `USER` (`ID`,`NAME`,`EMAIL`) VALUES (3,'user3','user3@test.com'); + +INSERT INTO `POST` (`ID`,`SUBJECT`,`USER_ID`) VALUES (1,'JPA Entity Graph In Action',1); + +INSERT INTO `COMMENT` (`ID`,`REPLY`,`POST_ID`,`USER_ID`) VALUES (1,'Nice !!',1,2); +INSERT INTO `COMMENT` (`ID`,`REPLY`,`POST_ID`,`USER_ID`) VALUES (2,'Cool !!',1,3); diff --git a/persistence-modules/java-jpa/src/test/java/com/baeldung/jpa/entitygraph/repo/PostRepositoryTest.java b/persistence-modules/java-jpa/src/test/java/com/baeldung/jpa/entitygraph/repo/PostRepositoryTest.java new file mode 100644 index 0000000000..382742f223 --- /dev/null +++ b/persistence-modules/java-jpa/src/test/java/com/baeldung/jpa/entitygraph/repo/PostRepositoryTest.java @@ -0,0 +1,68 @@ +package com.baeldung.jpa.entitygraph.repo; + +import com.baeldung.jpa.entitygraph.model.Comment; +import com.baeldung.jpa.entitygraph.model.Post; +import com.baeldung.jpa.entitygraph.model.User; +import org.hibernate.LazyInitializationException; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class PostRepositoryTest { + + private static PostRepository postRepository = null; + + @BeforeClass + public static void once() { + postRepository = new PostRepository(); + } + + @Test(expected = LazyInitializationException.class) + public void find() { + Post post = postRepository.find(1L); + assertNotNull(post.getUser()); + String email = post.getUser().getEmail(); + assertNull(email); + } + + @Test + public void findWithEntityGraph() { + Post post = postRepository.findWithEntityGraph(1L); + assertNotNull(post.getUser()); + String email = post.getUser().getEmail(); + assertNotNull(email); + } + + @Test(expected = LazyInitializationException.class) + public void findWithEntityGraph_Comment_Without_User() { + Post post = postRepository.findWithEntityGraph(1L); + assertNotNull(post.getUser()); + String email = post.getUser().getEmail(); + assertNotNull(email); + assertNotNull(post.getComments()); + assertEquals(post.getComments().size(), 2); + Comment comment = post.getComments().get(0); + assertNotNull(comment); + User user = comment.getUser(); + user.getEmail(); + } + + @Test + public void findWithEntityGraph2_Comment_With_User() { + Post post = postRepository.findWithEntityGraph2(1L); + assertNotNull(post.getComments()); + assertEquals(post.getComments().size(), 2); + Comment comment = post.getComments().get(0); + assertNotNull(comment); + User user = comment.getUser(); + assertNotNull(user); + assertEquals(user.getEmail(), "user2@test.com"); + } + + @AfterClass + public static void destroy() { + postRepository.clean(); + } +} \ No newline at end of file From 3d945c079a8b4daabc3a1cd0c15155f7aec2579f Mon Sep 17 00:00:00 2001 From: eric-martin Date: Fri, 23 Nov 2018 23:41:00 -0600 Subject: [PATCH 23/31] Added @DirtiesContext to SpringContextIntegrationTest --- .../test/java/org/baeldung/SpringContextIntegrationTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spring-jenkins-pipeline/src/test/java/org/baeldung/SpringContextIntegrationTest.java b/spring-jenkins-pipeline/src/test/java/org/baeldung/SpringContextIntegrationTest.java index 8eb1589de7..0354f7211c 100644 --- a/spring-jenkins-pipeline/src/test/java/org/baeldung/SpringContextIntegrationTest.java +++ b/spring-jenkins-pipeline/src/test/java/org/baeldung/SpringContextIntegrationTest.java @@ -3,12 +3,14 @@ package org.baeldung; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; import com.baeldung.SpringJenkinsPipelineApplication; @RunWith(SpringRunner.class) @SpringBootTest(classes = SpringJenkinsPipelineApplication.class) +@DirtiesContext public class SpringContextIntegrationTest { @Test From 6e3245a0f142d7dc2c836c1f6d67e013a27424a9 Mon Sep 17 00:00:00 2001 From: Eugen Paraschiv Date: Sat, 24 Nov 2018 12:17:39 +0200 Subject: [PATCH 24/31] profile work --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index bc0c63213f..ae5897b6f3 100644 --- a/pom.xml +++ b/pom.xml @@ -775,7 +775,7 @@ parent-kotlin testing-modules/gatling - geotools + From a6c9c5840f9942c89a7318c6ea7cced0de058345 Mon Sep 17 00:00:00 2001 From: Eugen Paraschiv Date: Sat, 24 Nov 2018 13:36:27 +0200 Subject: [PATCH 25/31] disabling unnecessary repo --- libraries/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/pom.xml b/libraries/pom.xml index 8ffd33272d..936e86873d 100644 --- a/libraries/pom.xml +++ b/libraries/pom.xml @@ -720,11 +720,11 @@ - + false From 8d393165c4ce7a372b0ff5a595d9351b8a4afa48 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sat, 24 Nov 2018 18:35:05 +0200 Subject: [PATCH 26/31] Update and rename PostRepositoryTest.java to PostRepositoryIntegrationTest.java --- ...RepositoryTest.java => PostRepositoryIntegrationTest.java} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename persistence-modules/java-jpa/src/test/java/com/baeldung/jpa/entitygraph/repo/{PostRepositoryTest.java => PostRepositoryIntegrationTest.java} (94%) diff --git a/persistence-modules/java-jpa/src/test/java/com/baeldung/jpa/entitygraph/repo/PostRepositoryTest.java b/persistence-modules/java-jpa/src/test/java/com/baeldung/jpa/entitygraph/repo/PostRepositoryIntegrationTest.java similarity index 94% rename from persistence-modules/java-jpa/src/test/java/com/baeldung/jpa/entitygraph/repo/PostRepositoryTest.java rename to persistence-modules/java-jpa/src/test/java/com/baeldung/jpa/entitygraph/repo/PostRepositoryIntegrationTest.java index 382742f223..4724bb41ad 100644 --- a/persistence-modules/java-jpa/src/test/java/com/baeldung/jpa/entitygraph/repo/PostRepositoryTest.java +++ b/persistence-modules/java-jpa/src/test/java/com/baeldung/jpa/entitygraph/repo/PostRepositoryIntegrationTest.java @@ -10,7 +10,7 @@ import org.junit.Test; import static org.junit.Assert.*; -public class PostRepositoryTest { +public class PostRepositoryIntegrationTest { private static PostRepository postRepository = null; @@ -65,4 +65,4 @@ public class PostRepositoryTest { public static void destroy() { postRepository.clean(); } -} \ No newline at end of file +} From 27ec13ea96cf876ba159babd9ec4e4a67c0877ca Mon Sep 17 00:00:00 2001 From: amit2103 Date: Sun, 25 Nov 2018 00:23:51 +0530 Subject: [PATCH 27/31] [BAEL-9712] - Modifed oauth version --- spring-5-security-oauth/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-5-security-oauth/pom.xml b/spring-5-security-oauth/pom.xml index 13359ae84a..33a0677724 100644 --- a/spring-5-security-oauth/pom.xml +++ b/spring-5-security-oauth/pom.xml @@ -66,7 +66,7 @@ - 2.0.5.RELEASE + 2.0.1.RELEASE From 4e4da4eb7739315bd797491938998723f850174e Mon Sep 17 00:00:00 2001 From: Loredana Date: Sat, 24 Nov 2018 21:50:20 +0200 Subject: [PATCH 28/31] fix start, edit readme --- spring-5-security-oauth/README.md | 3 ++- spring-5-security-oauth/pom.xml | 1 + spring-5-security/README.md | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/spring-5-security-oauth/README.md b/spring-5-security-oauth/README.md index 81d95c07d7..f13925992b 100644 --- a/spring-5-security-oauth/README.md +++ b/spring-5-security-oauth/README.md @@ -1,3 +1,4 @@ ## Relevant articles: -- [Spring Security 5 -OAuth2 Login](http://www.baeldung.com/spring-security-5-oauth2-login) \ No newline at end of file +- [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) diff --git a/spring-5-security-oauth/pom.xml b/spring-5-security-oauth/pom.xml index 33a0677724..f200052adf 100644 --- a/spring-5-security-oauth/pom.xml +++ b/spring-5-security-oauth/pom.xml @@ -67,6 +67,7 @@ 2.0.1.RELEASE + com.baeldung.oauth2.SpringOAuthApplication diff --git a/spring-5-security/README.md b/spring-5-security/README.md index 6e094e928f..37dc8b0f28 100644 --- a/spring-5-security/README.md +++ b/spring-5-security/README.md @@ -4,4 +4,4 @@ - [A Custom Spring SecurityConfigurer](http://www.baeldung.com/spring-security-custom-configurer) - [New Password Storage In Spring Security 5](http://www.baeldung.com/spring-security-5-password-storage) - [Default Password Encoder in Spring Security 5](https://www.baeldung.com/spring-security-5-default-password-encoder) -- [Extracting Principal and Authorities using Spring Security OAuth](https://www.baeldung.com/spring-security-oauth-principal-authorities-extractor) + From bff2c6f5b06ded73a09fce5ef6bc78cfc5645621 Mon Sep 17 00:00:00 2001 From: amit2103 Date: Sun, 25 Nov 2018 01:25:41 +0530 Subject: [PATCH 29/31] [BAEL-10780] - Added code for the checking string input article --- .../string/checkinputs/CheckIntegerInput.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 java-strings/src/main/java/com/baeldung/string/checkinputs/CheckIntegerInput.java diff --git a/java-strings/src/main/java/com/baeldung/string/checkinputs/CheckIntegerInput.java b/java-strings/src/main/java/com/baeldung/string/checkinputs/CheckIntegerInput.java new file mode 100644 index 0000000000..9462244bbb --- /dev/null +++ b/java-strings/src/main/java/com/baeldung/string/checkinputs/CheckIntegerInput.java @@ -0,0 +1,19 @@ +package com.baeldung.string.checkinputs; + +import java.util.Scanner; + +public class CheckIntegerInput { + + public static void main(String[] args) { + + try (Scanner scanner = new Scanner(System.in)) { + System.out.println("Enter an integer : "); + + if (scanner.hasNextInt()) { + System.out.println("You entered : " + scanner.nextInt()); + } else { + System.out.println("The input is not an integer"); + } + } + } +} \ No newline at end of file From 3c3d484eeb6a5676e3055cfa2d4b43c369b8a30b Mon Sep 17 00:00:00 2001 From: Alejandro Gervasio Date: Sat, 24 Nov 2018 18:02:25 -0300 Subject: [PATCH 30/31] BAEL-2354 - An Introduction to the Event Notification Model in CDI 2.0 (#5685) * Initial Commit * Update pom.xml * Update pom.xml * Update LowercaseTextServiceUnitTest.java * Update UppercaseTextServiceUnitTest.java * Delete TextApplication.java * Update source files * Update BootstrappingApplication.java * Add AnotherSimpleEventObserver class * Rename event classes * Update ExampleEventSource.java * Update UppercaseTextService.java * Delete TextService.java * Delete LowercaseTextService.java * Delete LowercaseTextServiceUnitTest.java * Delete UppercaseTextServiceUnitTest.java * Fixed text service unit test * Update TextService.java --- cdi/pom.xml | 25 +++++++++++-------- .../application/BootstrappingApplication.java | 15 +++++++++++ .../cdi2observers/events/ExampleEvent.java | 14 +++++++++++ .../events/ExampleEventSource.java | 14 +++++++++++ .../AnotherExampleEventObserver.java | 12 +++++++++ .../observers/ExampleEventObserver.java | 13 ++++++++++ .../cdi2observers/services/TextService.java | 8 ++++++ .../tests/TextServiceUnitTest.java | 14 +++++++++++ 8 files changed, 105 insertions(+), 10 deletions(-) create mode 100644 cdi/src/main/java/com/baeldung/cdi2observers/application/BootstrappingApplication.java create mode 100644 cdi/src/main/java/com/baeldung/cdi2observers/events/ExampleEvent.java create mode 100644 cdi/src/main/java/com/baeldung/cdi2observers/events/ExampleEventSource.java create mode 100644 cdi/src/main/java/com/baeldung/cdi2observers/observers/AnotherExampleEventObserver.java create mode 100644 cdi/src/main/java/com/baeldung/cdi2observers/observers/ExampleEventObserver.java create mode 100644 cdi/src/main/java/com/baeldung/cdi2observers/services/TextService.java create mode 100644 cdi/src/test/java/com/baeldung/test/cdi2observers/tests/TextServiceUnitTest.java diff --git a/cdi/pom.xml b/cdi/pom.xml index 2c719c1d7f..0b735e0ca5 100644 --- a/cdi/pom.xml +++ b/cdi/pom.xml @@ -5,7 +5,7 @@ com.baeldung cdi 1.0-SNAPSHOT - + com.baeldung parent-spring-4 @@ -14,6 +14,16 @@ + + javax.enterprise + cdi-api + ${cdi-api.version} + + + org.jboss.weld.se + weld-se-core + ${weld-se-core.version} + org.hamcrest hamcrest-core @@ -42,11 +52,6 @@ aspectjweaver ${aspectjweaver.version} - - org.jboss.weld.se - weld-se-core - ${weld-se-core.version} - org.springframework spring-test @@ -54,13 +59,13 @@ test - - 1.8.9 - 2.4.1.Final + 2.0.SP1 + 3.0.5.Final + 1.9.2 1.3 3.10.0 4.12 + 5.1.2.RELEASE - diff --git a/cdi/src/main/java/com/baeldung/cdi2observers/application/BootstrappingApplication.java b/cdi/src/main/java/com/baeldung/cdi2observers/application/BootstrappingApplication.java new file mode 100644 index 0000000000..4896408502 --- /dev/null +++ b/cdi/src/main/java/com/baeldung/cdi2observers/application/BootstrappingApplication.java @@ -0,0 +1,15 @@ +package com.baeldung.cdi.cdi2observers.application; + +import com.baeldung.cdi.cdi2observers.events.ExampleEvent; +import javax.enterprise.inject.se.SeContainer; +import javax.enterprise.inject.se.SeContainerInitializer; + +public class BootstrappingApplication { + + public static void main(String... args) { + SeContainerInitializer containerInitializer = SeContainerInitializer.newInstance(); + try (SeContainer container = containerInitializer.initialize()) { + container.getBeanManager().fireEvent(new ExampleEvent("Welcome to Baeldung!")); + } + } +} diff --git a/cdi/src/main/java/com/baeldung/cdi2observers/events/ExampleEvent.java b/cdi/src/main/java/com/baeldung/cdi2observers/events/ExampleEvent.java new file mode 100644 index 0000000000..a2329d2ef1 --- /dev/null +++ b/cdi/src/main/java/com/baeldung/cdi2observers/events/ExampleEvent.java @@ -0,0 +1,14 @@ +package com.baeldung.cdi.cdi2observers.events; + +public class ExampleEvent { + + private final String eventMessage; + + public ExampleEvent(String eventMessage) { + this.eventMessage = eventMessage; + } + + public String getEventMessage() { + return eventMessage; + } +} diff --git a/cdi/src/main/java/com/baeldung/cdi2observers/events/ExampleEventSource.java b/cdi/src/main/java/com/baeldung/cdi2observers/events/ExampleEventSource.java new file mode 100644 index 0000000000..f37030778a --- /dev/null +++ b/cdi/src/main/java/com/baeldung/cdi2observers/events/ExampleEventSource.java @@ -0,0 +1,14 @@ +package com.baeldung.cdi.cdi2observers.events; + +import javax.enterprise.event.Event; +import javax.inject.Inject; + +public class ExampleEventSource { + + @Inject + Event exampleEvent; + + public void fireEvent() { + exampleEvent.fireAsync(new ExampleEvent("Welcome to Baeldung!")); + } +} diff --git a/cdi/src/main/java/com/baeldung/cdi2observers/observers/AnotherExampleEventObserver.java b/cdi/src/main/java/com/baeldung/cdi2observers/observers/AnotherExampleEventObserver.java new file mode 100644 index 0000000000..34520c2b3d --- /dev/null +++ b/cdi/src/main/java/com/baeldung/cdi2observers/observers/AnotherExampleEventObserver.java @@ -0,0 +1,12 @@ +package com.baeldung.cdi.cdi2observers.observers; + +import com.baeldung.cdi.cdi2observers.events.ExampleEvent; +import javax.annotation.Priority; +import javax.enterprise.event.Observes; + +public class AnotherExampleEventObserver { + + public String onEvent(@Observes @Priority(2) ExampleEvent event) { + return event.getEventMessage(); + } +} diff --git a/cdi/src/main/java/com/baeldung/cdi2observers/observers/ExampleEventObserver.java b/cdi/src/main/java/com/baeldung/cdi2observers/observers/ExampleEventObserver.java new file mode 100644 index 0000000000..b3522b2ad0 --- /dev/null +++ b/cdi/src/main/java/com/baeldung/cdi2observers/observers/ExampleEventObserver.java @@ -0,0 +1,13 @@ +package com.baeldung.cdi.cdi2observers.observers; + +import com.baeldung.cdi.cdi2observers.events.ExampleEvent; +import com.baeldung.cdi.cdi2observers.services.TextService; +import javax.annotation.Priority; +import javax.enterprise.event.Observes; + +public class ExampleEventObserver { + + public String onEvent(@Observes @Priority(1) ExampleEvent event, TextService textService) { + return textService.parseText(event.getEventMessage()); + } +} diff --git a/cdi/src/main/java/com/baeldung/cdi2observers/services/TextService.java b/cdi/src/main/java/com/baeldung/cdi2observers/services/TextService.java new file mode 100644 index 0000000000..47788a0657 --- /dev/null +++ b/cdi/src/main/java/com/baeldung/cdi2observers/services/TextService.java @@ -0,0 +1,8 @@ +package com.baeldung.cdi.cdi2observers.services; + +public class TextService { + + public String parseText(String text) { + return text.toUpperCase(); + } +} diff --git a/cdi/src/test/java/com/baeldung/test/cdi2observers/tests/TextServiceUnitTest.java b/cdi/src/test/java/com/baeldung/test/cdi2observers/tests/TextServiceUnitTest.java new file mode 100644 index 0000000000..deecf13f9a --- /dev/null +++ b/cdi/src/test/java/com/baeldung/test/cdi2observers/tests/TextServiceUnitTest.java @@ -0,0 +1,14 @@ +package com.baeldung.cdi.cdi2observers.tests; + +import com.baeldung.cdi.cdi2observers.services.TextService; +import static org.assertj.core.api.Assertions.assertThat; +import org.junit.Test; + +public class TextServiceUnitTest { + + @Test + public void givenTextServiceInstance_whenCalledparseText_thenCorrect() { + TextService textService = new TextService(); + assertThat(textService.parseText("Baeldung")).isEqualTo("BAELDUNG"); + } +} From f784c3bb793b6de50323700e771a5e001f3e4850 Mon Sep 17 00:00:00 2001 From: Amitabh Mandal Date: Sun, 25 Nov 2018 15:31:22 +0530 Subject: [PATCH 31/31] BAEL-2168 Java EE 7 Batch Processing (#5645) * jberet batch * Batch Understanding * partition * exception * some more changes --- jee-7/pom.xml | 935 ++++++++++-------- .../ChunkExceptionSkipReadListener.java | 11 + .../batch/understanding/CustomCheckPoint.java | 12 + .../understanding/DeciderJobSequence.java | 14 + .../understanding/InjectSimpleBatchLet.java | 20 + .../batch/understanding/SimpleBatchLet.java | 13 + .../SimpleChunkItemProcessor.java | 12 + .../understanding/SimpleChunkItemReader.java | 27 + .../SimpleChunkItemReaderError.java | 31 + .../understanding/SimpleChunkWriter.java | 13 + .../exception/MyInputRecord.java | 41 + .../exception/MyItemProcessor.java | 15 + .../understanding/exception/MyItemReader.java | 42 + .../understanding/exception/MyItemWriter.java | 19 + .../exception/MyOutputRecord.java | 39 + .../exception/MyRetryProcessorListener.java | 11 + .../exception/MyRetryReadListener.java | 11 + .../exception/MyRetryWriteListener.java | 12 + .../exception/MySkipProcessorListener.java | 11 + .../exception/MySkipReadListener.java | 11 + .../exception/MySkipWriteListener.java | 13 + .../META-INF/batch-jobs/customCheckPoint.xml | 12 + .../META-INF/batch-jobs/decideJobSequence.xml | 18 + .../META-INF/batch-jobs/flowJobSequence.xml | 21 + .../batch-jobs/injectionSimpleBatchLet.xml | 13 + .../batch-jobs/partitionSimpleBatchLet.xml | 24 + .../META-INF/batch-jobs/simpleBatchLet.xml | 9 + .../META-INF/batch-jobs/simpleChunk.xml | 11 + .../META-INF/batch-jobs/simpleErrorChunk.xml | 24 + .../batch-jobs/simpleErrorSkipChunk.xml | 26 + .../META-INF/batch-jobs/simpleJobSequence.xml | 17 + .../META-INF/batch-jobs/splitJobSequence.xml | 22 + jee-7/src/main/resources/META-INF/beans.xml | 8 + .../batch/understanding/BatchTestHelper.java | 79 ++ .../CustomCheckPointUnitTest.java | 33 + .../understanding/JobSequenceUnitTest.java | 74 ++ .../understanding/SimpleBatchLetUnitTest.java | 68 ++ .../understanding/SimpleChunkUnitTest.java | 67 ++ .../SimpleErrorChunkUnitTest.java | 48 + 39 files changed, 1473 insertions(+), 414 deletions(-) create mode 100644 jee-7/src/main/java/com/baeldung/batch/understanding/ChunkExceptionSkipReadListener.java create mode 100644 jee-7/src/main/java/com/baeldung/batch/understanding/CustomCheckPoint.java create mode 100644 jee-7/src/main/java/com/baeldung/batch/understanding/DeciderJobSequence.java create mode 100644 jee-7/src/main/java/com/baeldung/batch/understanding/InjectSimpleBatchLet.java create mode 100644 jee-7/src/main/java/com/baeldung/batch/understanding/SimpleBatchLet.java create mode 100644 jee-7/src/main/java/com/baeldung/batch/understanding/SimpleChunkItemProcessor.java create mode 100644 jee-7/src/main/java/com/baeldung/batch/understanding/SimpleChunkItemReader.java create mode 100644 jee-7/src/main/java/com/baeldung/batch/understanding/SimpleChunkItemReaderError.java create mode 100644 jee-7/src/main/java/com/baeldung/batch/understanding/SimpleChunkWriter.java create mode 100644 jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyInputRecord.java create mode 100644 jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyItemProcessor.java create mode 100644 jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyItemReader.java create mode 100644 jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyItemWriter.java create mode 100644 jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyOutputRecord.java create mode 100644 jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyRetryProcessorListener.java create mode 100644 jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyRetryReadListener.java create mode 100644 jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyRetryWriteListener.java create mode 100644 jee-7/src/main/java/com/baeldung/batch/understanding/exception/MySkipProcessorListener.java create mode 100644 jee-7/src/main/java/com/baeldung/batch/understanding/exception/MySkipReadListener.java create mode 100644 jee-7/src/main/java/com/baeldung/batch/understanding/exception/MySkipWriteListener.java create mode 100644 jee-7/src/main/resources/META-INF/batch-jobs/customCheckPoint.xml create mode 100644 jee-7/src/main/resources/META-INF/batch-jobs/decideJobSequence.xml create mode 100644 jee-7/src/main/resources/META-INF/batch-jobs/flowJobSequence.xml create mode 100644 jee-7/src/main/resources/META-INF/batch-jobs/injectionSimpleBatchLet.xml create mode 100644 jee-7/src/main/resources/META-INF/batch-jobs/partitionSimpleBatchLet.xml create mode 100644 jee-7/src/main/resources/META-INF/batch-jobs/simpleBatchLet.xml create mode 100644 jee-7/src/main/resources/META-INF/batch-jobs/simpleChunk.xml create mode 100644 jee-7/src/main/resources/META-INF/batch-jobs/simpleErrorChunk.xml create mode 100644 jee-7/src/main/resources/META-INF/batch-jobs/simpleErrorSkipChunk.xml create mode 100644 jee-7/src/main/resources/META-INF/batch-jobs/simpleJobSequence.xml create mode 100644 jee-7/src/main/resources/META-INF/batch-jobs/splitJobSequence.xml create mode 100644 jee-7/src/main/resources/META-INF/beans.xml create mode 100644 jee-7/src/test/java/com/baeldung/batch/understanding/BatchTestHelper.java create mode 100644 jee-7/src/test/java/com/baeldung/batch/understanding/CustomCheckPointUnitTest.java create mode 100644 jee-7/src/test/java/com/baeldung/batch/understanding/JobSequenceUnitTest.java create mode 100644 jee-7/src/test/java/com/baeldung/batch/understanding/SimpleBatchLetUnitTest.java create mode 100644 jee-7/src/test/java/com/baeldung/batch/understanding/SimpleChunkUnitTest.java create mode 100644 jee-7/src/test/java/com/baeldung/batch/understanding/SimpleErrorChunkUnitTest.java diff --git a/jee-7/pom.xml b/jee-7/pom.xml index 4f6e6a20fb..9011648d17 100644 --- a/jee-7/pom.xml +++ b/jee-7/pom.xml @@ -1,430 +1,537 @@ - - 4.0.0 - jee-7 - 1.0-SNAPSHOT - war - JavaEE 7 Arquillian Archetype Sample + + 4.0.0 + jee-7 + 1.0-SNAPSHOT + war + JavaEE 7 Arquillian Archetype Sample - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + - - - javax - javaee-api - ${javaee_api.version} - provided - + + + javax + javaee-api + ${javaee_api.version} + provided + - - org.jboss.arquillian.junit - arquillian-junit-container - test - - - org.jboss.arquillian.graphene - graphene-webdriver - ${graphene-webdriver.version} - pom - test - - - com.jayway.awaitility - awaitility - ${awaitility.version} - test - + + org.jboss.arquillian.junit + arquillian-junit-container + test + + + org.jboss.arquillian.graphene + graphene-webdriver + ${graphene-webdriver.version} + pom + test + + + com.jayway.awaitility + awaitility + ${awaitility.version} + test + - - org.jboss.shrinkwrap.resolver - shrinkwrap-resolver-impl-maven - test - jar - + + org.jboss.shrinkwrap.resolver + shrinkwrap-resolver-impl-maven + test + jar + - - org.jboss.shrinkwrap.resolver - shrinkwrap-resolver-impl-maven-archive - test - - - org.apache.httpcomponents - httpclient - ${httpclient.version} - - - commons-io - commons-io - ${commons-io.version} - - - com.sun.faces - jsf-api - ${com.sun.faces.jsf.version} - - - com.sun.faces - jsf-impl - ${com.sun.faces.jsf.version} - - - javax.servlet - jstl - ${jstl.version} - - - javax.servlet - javax.servlet-api - ${javax.servlet-api.version} - - - javax.servlet.jsp - jsp-api - ${jsp-api.version} - provided - - - taglibs - standard - ${taglibs.standard.version} - + + org.jboss.shrinkwrap.resolver + shrinkwrap-resolver-impl-maven-archive + test + + + org.apache.httpcomponents + httpclient + ${httpclient.version} + + + commons-io + commons-io + ${commons-io.version} + + + com.sun.faces + jsf-api + ${com.sun.faces.jsf.version} + + + com.sun.faces + jsf-impl + ${com.sun.faces.jsf.version} + + + javax.servlet + jstl + ${jstl.version} + + + javax.servlet + javax.servlet-api + ${javax.servlet-api.version} + + + javax.servlet.jsp + jsp-api + ${jsp-api.version} + provided + + + taglibs + standard + ${taglibs.standard.version} + - - javax.mvc - javax.mvc-api - 20160715 - - - org.glassfish.ozark - ozark - ${ozark.version} - + + javax.mvc + javax.mvc-api + 20160715 + + + org.glassfish.ozark + ozark + ${ozark.version} + - - org.springframework.security - spring-security-web - ${org.springframework.security.version} - + + org.springframework.security + spring-security-web + ${org.springframework.security.version} + - - org.springframework.security - spring-security-config - ${org.springframework.security.version} - - - org.springframework.security - spring-security-taglibs - ${org.springframework.security.version} - - + + org.springframework.security + spring-security-config + ${org.springframework.security.version} + + + org.springframework.security + spring-security-taglibs + ${org.springframework.security.version} + + - - - - org.apache.maven.plugins - maven-war-plugin - ${maven-war-plugin.version} - - src/main/webapp - false - - - - + + org.jboss.spec.javax.batch + jboss-batch-api_1.0_spec + 1.0.0.Final + + + org.jberet + jberet-core + 1.0.2.Final + + + org.jberet + jberet-support + 1.0.2.Final + + + org.jboss.spec.javax.transaction + jboss-transaction-api_1.2_spec + 1.0.0.Final + + + org.jboss.marshalling + jboss-marshalling + 1.4.2.Final + + + org.jboss.weld + weld-core + 2.1.1.Final + + + org.jboss.weld.se + weld-se + 2.1.1.Final + + + org.jberet + jberet-se + 1.0.2.Final + + + com.h2database + h2 + 1.4.178 + + + org.glassfish.jersey.containers + jersey-container-jetty-servlet + 2.22.1 + + - - - - org.jboss.arquillian - arquillian-bom - ${arquillian_core.version} - import - pom - - - org.jboss.arquillian.extension - arquillian-drone-bom - ${arquillian-drone-bom.version} - pom - import - - - + + + + org.apache.maven.plugins + maven-war-plugin + ${maven-war-plugin.version} + + src/main/webapp + false + + + + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + + org.apache.maven.plugins + + + maven-pmd-plugin + + + [3.8,) + + + check + + + + + + + + + + + + + - - - wildfly-managed-arquillian - - true - - - standalone-full.xml - ${project.build.directory}/wildfly-${version.wildfly} - - - - io.undertow - undertow-websockets-jsr - ${undertow-websockets-jsr.version} - test - - - org.jboss.resteasy - resteasy-client - ${resteasy.version} - test - - - org.jboss.resteasy - resteasy-jaxb-provider - ${resteasy.version} - test - - - org.jboss.resteasy - resteasy-json-p-provider - ${resteasy.version} - test - - - org.wildfly - wildfly-arquillian-container-managed - ${wildfly.version} - test - - + + + + org.jboss.arquillian + arquillian-bom + ${arquillian_core.version} + import + pom + + + org.jboss.arquillian.extension + arquillian-drone-bom + ${arquillian-drone-bom.version} + pom + import + + + - - - - - maven-dependency-plugin - ${maven-dependency-plugin.version} - - ${maven.test.skip} - - - - unpack - process-test-classes - - unpack - - - - - org.wildfly - wildfly-dist - ${wildfly.version} - zip - false - ${project.build.directory} - - - - - - - - maven-surefire-plugin - ${maven-surefire-plugin.version} - - - ${project.build.directory}/wildfly-${wildfly.version} - - - - - - - - - wildfly-remote-arquillian - - - io.undertow - undertow-websockets-jsr - ${undertow-websockets-jsr.version} - test - - - org.jboss.resteasy - resteasy-client - ${resteasy.version} - test - - - org.jboss.resteasy - resteasy-jaxb-provider - ${resteasy.version} - test - - - org.jboss.resteasy - resteasy-json-p-provider - ${resteasy.version} - test - - - org.wildfly - wildfly-arquillian-container-remote - ${wildfly.version} - test - - - - - glassfish-embedded-arquillian - - - org.glassfish.main.extras - glassfish-embedded-all - ${glassfish-embedded-all.version} - test - - - org.glassfish - javax.json - ${javax.json.version} - test - - - org.glassfish.tyrus - tyrus-client - ${tyrus.version} - test - - - org.glassfish.tyrus - tyrus-container-grizzly-client - ${tyrus.version} - test - - - org.glassfish.jersey.core - jersey-client - ${jersey.version} - test - - - org.jboss.arquillian.container - arquillian-glassfish-embedded-3.1 - ${arquillian-glassfish.version} - test - - - - - glassfish-remote-arquillian - - - org.glassfish - javax.json - ${javax.json.version} - test - - - org.glassfish.tyrus - tyrus-client - ${tyrus.version} - test - - - org.glassfish.tyrus - tyrus-container-grizzly-client - ${tyrus.version} - test - - - org.glassfish.jersey.core - jersey-client - ${jersey.version} - test - - - org.glassfish.jersey.media - jersey-media-json-jackson - ${jersey.version} - test - - - org.glassfish.jersey.media - jersey-media-json-processing - ${jersey.version} - test - - - org.jboss.arquillian.container - arquillian-glassfish-remote-3.1 - ${arquillian-glassfish.version} - test - - - - - webdriver-chrome - - true - - - chrome - - - - webdriver-firefox - - firefox - - - + + + wildfly-managed-arquillian + + true + + + standalone-full.xml + ${project.build.directory}/wildfly-${version.wildfly} + + + + io.undertow + undertow-websockets-jsr + ${undertow-websockets-jsr.version} + test + + + org.jboss.resteasy + resteasy-client + ${resteasy.version} + test + + + org.jboss.resteasy + resteasy-jaxb-provider + ${resteasy.version} + test + + + org.jboss.resteasy + resteasy-json-p-provider + ${resteasy.version} + test + + + org.wildfly + wildfly-arquillian-container-managed + ${wildfly.version} + test + + + sun.jdk + jconsole + + + + - - - bintray-mvc-spec-maven - bintray - http://dl.bintray.com/mvc-spec/maven - - true - - - false - - - + + + + + maven-dependency-plugin + ${maven-dependency-plugin.version} + + ${maven.test.skip} + + + + unpack + process-test-classes + + unpack + + + + + org.wildfly + wildfly-dist + ${wildfly.version} + zip + false + ${project.build.directory} + + + sun.jdk + jconsole + + + + + + + + + + maven-surefire-plugin + ${maven-surefire-plugin.version} + + + ${project.build.directory}/wildfly-${wildfly.version} + + + + + + + + + wildfly-remote-arquillian + + + io.undertow + undertow-websockets-jsr + ${undertow-websockets-jsr.version} + test + + + org.jboss.resteasy + resteasy-client + ${resteasy.version} + test + + + org.jboss.resteasy + resteasy-jaxb-provider + ${resteasy.version} + test + + + org.jboss.resteasy + resteasy-json-p-provider + ${resteasy.version} + test + + + org.wildfly + wildfly-arquillian-container-remote + ${wildfly.version} + test + + + sun.jdk + jconsole + + + + + + + glassfish-embedded-arquillian + + + org.glassfish.main.extras + glassfish-embedded-all + ${glassfish-embedded-all.version} + test + + + org.glassfish + javax.json + ${javax.json.version} + test + + + org.glassfish.tyrus + tyrus-client + ${tyrus.version} + test + + + org.glassfish.tyrus + tyrus-container-grizzly-client + ${tyrus.version} + test + + + org.glassfish.jersey.core + jersey-client + ${jersey.version} + test + + + org.jboss.arquillian.container + arquillian-glassfish-embedded-3.1 + ${arquillian-glassfish.version} + test + + + + + glassfish-remote-arquillian + + + org.glassfish + javax.json + ${javax.json.version} + test + + + org.glassfish.tyrus + tyrus-client + ${tyrus.version} + test + + + org.glassfish.tyrus + tyrus-container-grizzly-client + ${tyrus.version} + test + + + org.glassfish.jersey.core + jersey-client + ${jersey.version} + test + + + org.glassfish.jersey.media + jersey-media-json-jackson + ${jersey.version} + test + + + org.glassfish.jersey.media + jersey-media-json-processing + ${jersey.version} + test + + + org.jboss.arquillian.container + arquillian-glassfish-remote-3.1 + ${arquillian-glassfish.version} + test + + + + + webdriver-chrome + + true + + + chrome + + + + webdriver-firefox + + firefox + + + - - 1.8 - 3.0.0 - 7.0 - 1.1.11.Final - 8.2.1.Final - 1.7.0 - 1.4.6.Final - 3.0.19.Final - 4.1.1 - 1.0.4 - 1.13 - 2.25 - 1.0.0.Final - 2.6 - 4.2.3.RELEASE - 2.21.0 - 1.1.2 - 2.4 - 2.2.14 - 4.5 - 2.0.1.Final - 3.1.0 - 2.1.0.Final - 2.8 - 1.2 - 2.2 - 20160715 - + + + bintray-mvc-spec-maven + bintray + http://dl.bintray.com/mvc-spec/maven + + true + + + false + + + - + + 1.8 + 3.0.0 + 7.0 + 1.1.11.Final + 8.2.1.Final + 1.7.0 + 1.4.6.Final + 3.0.19.Final + 4.1.1 + 1.0.4 + 1.13 + 2.25 + 1.0.0.Final + 2.6 + 4.2.3.RELEASE + 2.21.0 + 1.1.2 + 2.4 + 2.2.14 + 4.5 + 2.0.1.Final + 3.1.0 + 2.1.0.Final + 2.8 + 1.2 + 2.2 + 20160715 + + + \ No newline at end of file diff --git a/jee-7/src/main/java/com/baeldung/batch/understanding/ChunkExceptionSkipReadListener.java b/jee-7/src/main/java/com/baeldung/batch/understanding/ChunkExceptionSkipReadListener.java new file mode 100644 index 0000000000..ce47de66af --- /dev/null +++ b/jee-7/src/main/java/com/baeldung/batch/understanding/ChunkExceptionSkipReadListener.java @@ -0,0 +1,11 @@ +package com.baeldung.batch.understanding; + +import javax.batch.api.chunk.listener.SkipReadListener; +import javax.inject.Named; + +@Named +public class ChunkExceptionSkipReadListener implements SkipReadListener { + @Override + public void onSkipReadItem(Exception e) throws Exception { + } +} \ No newline at end of file diff --git a/jee-7/src/main/java/com/baeldung/batch/understanding/CustomCheckPoint.java b/jee-7/src/main/java/com/baeldung/batch/understanding/CustomCheckPoint.java new file mode 100644 index 0000000000..fe6759b365 --- /dev/null +++ b/jee-7/src/main/java/com/baeldung/batch/understanding/CustomCheckPoint.java @@ -0,0 +1,12 @@ +package com.baeldung.batch.understanding; + +import javax.batch.api.chunk.AbstractCheckpointAlgorithm; +import javax.inject.Named; + +@Named +public class CustomCheckPoint extends AbstractCheckpointAlgorithm { + @Override + public boolean isReadyToCheckpoint() throws Exception { + return SimpleChunkItemReader.COUNT % 5 == 0; + } +} diff --git a/jee-7/src/main/java/com/baeldung/batch/understanding/DeciderJobSequence.java b/jee-7/src/main/java/com/baeldung/batch/understanding/DeciderJobSequence.java new file mode 100644 index 0000000000..6cc2012f23 --- /dev/null +++ b/jee-7/src/main/java/com/baeldung/batch/understanding/DeciderJobSequence.java @@ -0,0 +1,14 @@ +package com.baeldung.batch.understanding; + +import javax.batch.api.Decider; +import javax.batch.runtime.StepExecution; +import javax.inject.Named; + +@Named +public class DeciderJobSequence implements Decider { + @Override + public String decide(StepExecution[] ses) throws Exception { + return "nothing"; + } + +} \ No newline at end of file diff --git a/jee-7/src/main/java/com/baeldung/batch/understanding/InjectSimpleBatchLet.java b/jee-7/src/main/java/com/baeldung/batch/understanding/InjectSimpleBatchLet.java new file mode 100644 index 0000000000..93eb20708d --- /dev/null +++ b/jee-7/src/main/java/com/baeldung/batch/understanding/InjectSimpleBatchLet.java @@ -0,0 +1,20 @@ +package com.baeldung.batch.understanding; + +import javax.batch.api.AbstractBatchlet; +import javax.batch.api.BatchProperty; +import javax.batch.runtime.BatchStatus; +import javax.inject.Inject; +import javax.inject.Named; + +@Named +public class InjectSimpleBatchLet extends AbstractBatchlet { + @Inject + @BatchProperty(name = "name") + private String nameString; + + @Override + public String process() throws Exception { + System.out.println("Value passed in = " + nameString); + return BatchStatus.COMPLETED.toString(); + } +} diff --git a/jee-7/src/main/java/com/baeldung/batch/understanding/SimpleBatchLet.java b/jee-7/src/main/java/com/baeldung/batch/understanding/SimpleBatchLet.java new file mode 100644 index 0000000000..6a367b064b --- /dev/null +++ b/jee-7/src/main/java/com/baeldung/batch/understanding/SimpleBatchLet.java @@ -0,0 +1,13 @@ +package com.baeldung.batch.understanding; + +import javax.batch.api.AbstractBatchlet; +import javax.batch.runtime.BatchStatus; +import javax.inject.Named; + +@Named +public class SimpleBatchLet extends AbstractBatchlet { + @Override + public String process() throws Exception { + return BatchStatus.FAILED.toString(); + } +} diff --git a/jee-7/src/main/java/com/baeldung/batch/understanding/SimpleChunkItemProcessor.java b/jee-7/src/main/java/com/baeldung/batch/understanding/SimpleChunkItemProcessor.java new file mode 100644 index 0000000000..3f8166b6d8 --- /dev/null +++ b/jee-7/src/main/java/com/baeldung/batch/understanding/SimpleChunkItemProcessor.java @@ -0,0 +1,12 @@ +package com.baeldung.batch.understanding; + +import javax.batch.api.chunk.ItemProcessor; +import javax.inject.Named; + +@Named +public class SimpleChunkItemProcessor implements ItemProcessor { + @Override + public Integer processItem(Object t) { + return ((Integer) t).intValue() % 2 == 0 ? null : ((Integer) t).intValue(); + } +} diff --git a/jee-7/src/main/java/com/baeldung/batch/understanding/SimpleChunkItemReader.java b/jee-7/src/main/java/com/baeldung/batch/understanding/SimpleChunkItemReader.java new file mode 100644 index 0000000000..10f81d95d0 --- /dev/null +++ b/jee-7/src/main/java/com/baeldung/batch/understanding/SimpleChunkItemReader.java @@ -0,0 +1,27 @@ +package com.baeldung.batch.understanding; + +import java.io.Serializable; +import java.util.StringTokenizer; +import javax.batch.api.chunk.AbstractItemReader; +import javax.inject.Named; + +@Named +public class SimpleChunkItemReader extends AbstractItemReader { + private StringTokenizer tokens; + public static int COUNT = 0; + + @Override + public Integer readItem() throws Exception { + if (tokens.hasMoreTokens()) { + COUNT++; + String tempTokenize = tokens.nextToken(); + return Integer.valueOf(tempTokenize); + } + return null; + } + + @Override + public void open(Serializable checkpoint) throws Exception { + tokens = new StringTokenizer("1,2,3,4,5,6,7,8,9,10", ","); + } +} diff --git a/jee-7/src/main/java/com/baeldung/batch/understanding/SimpleChunkItemReaderError.java b/jee-7/src/main/java/com/baeldung/batch/understanding/SimpleChunkItemReaderError.java new file mode 100644 index 0000000000..92096d0571 --- /dev/null +++ b/jee-7/src/main/java/com/baeldung/batch/understanding/SimpleChunkItemReaderError.java @@ -0,0 +1,31 @@ +package com.baeldung.batch.understanding; + +import java.io.Serializable; +import java.util.StringTokenizer; + +import javax.batch.api.chunk.AbstractItemReader; +import javax.inject.Named; + +@Named +public class SimpleChunkItemReaderError extends AbstractItemReader { + private StringTokenizer tokens; + public static int COUNT = 0; + + @Override + public Integer readItem() throws Exception { + if (tokens.hasMoreTokens()) { + COUNT++; + int token = Integer.valueOf(tokens.nextToken()); + if (token == 3) { + throw new RuntimeException("Something happened"); + } + return Integer.valueOf(token); + } + return null; + } + + @Override + public void open(Serializable checkpoint) throws Exception { + tokens = new StringTokenizer("1,2,3,4,5,6,7,8,9,10", ","); + } +} \ No newline at end of file diff --git a/jee-7/src/main/java/com/baeldung/batch/understanding/SimpleChunkWriter.java b/jee-7/src/main/java/com/baeldung/batch/understanding/SimpleChunkWriter.java new file mode 100644 index 0000000000..909596766d --- /dev/null +++ b/jee-7/src/main/java/com/baeldung/batch/understanding/SimpleChunkWriter.java @@ -0,0 +1,13 @@ +package com.baeldung.batch.understanding; + +import java.util.List; + +import javax.batch.api.chunk.AbstractItemWriter; +import javax.inject.Named; + +@Named +public class SimpleChunkWriter extends AbstractItemWriter { + @Override + public void writeItems(List items) throws Exception { + } +} diff --git a/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyInputRecord.java b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyInputRecord.java new file mode 100644 index 0000000000..e813a699c2 --- /dev/null +++ b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyInputRecord.java @@ -0,0 +1,41 @@ +package com.baeldung.batch.understanding.exception; + +import java.io.Serializable; + +public class MyInputRecord implements Serializable { + private int id; + + public MyInputRecord(int id) { + this.id = id; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + + MyInputRecord that = (MyInputRecord) o; + + return id == that.id; + } + + @Override + public int hashCode() { + return id; + } + + @Override + public String toString() { + return "MyInputRecord: " + id; + } +} diff --git a/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyItemProcessor.java b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyItemProcessor.java new file mode 100644 index 0000000000..4427a1f548 --- /dev/null +++ b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyItemProcessor.java @@ -0,0 +1,15 @@ +package com.baeldung.batch.understanding.exception; + +import javax.batch.api.chunk.ItemProcessor; +import javax.inject.Named; + +@Named +public class MyItemProcessor implements ItemProcessor { + @Override + public Object processItem(Object t) { + if (((MyInputRecord) t).getId() == 6) { + throw new NullPointerException(); + } + return new MyOutputRecord(((MyInputRecord) t).getId()); + } +} diff --git a/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyItemReader.java b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyItemReader.java new file mode 100644 index 0000000000..dd1876ab7d --- /dev/null +++ b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyItemReader.java @@ -0,0 +1,42 @@ +package com.baeldung.batch.understanding.exception; + +import javax.batch.api.chunk.AbstractItemReader; +import javax.inject.Named; +import java.io.Serializable; +import java.util.StringTokenizer; + +@Named +public class MyItemReader extends AbstractItemReader { + private StringTokenizer tokens; + private MyInputRecord lastElement; + private boolean alreadyFailed; + + @Override + public void open(Serializable checkpoint) { + tokens = new StringTokenizer("1,2,3,4,5,6,7,8,9,10", ","); + if (checkpoint != null) { + while (!Integer.valueOf(tokens.nextToken()) + .equals(((MyInputRecord) checkpoint).getId())) { + } + } + } + + @Override + public Object readItem() { + if (tokens.hasMoreTokens()) { + int token = Integer.valueOf(tokens.nextToken()); + if (token == 5 && !alreadyFailed) { + alreadyFailed = true; + throw new IllegalArgumentException("Could not read record"); + } + lastElement = new MyInputRecord(token); + return lastElement; + } + return null; + } + + @Override + public Serializable checkpointInfo() throws Exception { + return lastElement; + } +} diff --git a/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyItemWriter.java b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyItemWriter.java new file mode 100644 index 0000000000..4e80d86d44 --- /dev/null +++ b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyItemWriter.java @@ -0,0 +1,19 @@ + +package com.baeldung.batch.understanding.exception; + +import javax.batch.api.chunk.AbstractItemWriter; +import javax.inject.Named; +import java.util.List; + +@Named +public class MyItemWriter extends AbstractItemWriter { + private static int retries = 0; + + @Override + public void writeItems(List list) { + if (retries <= 3 && list.contains(new MyOutputRecord(8))) { + retries++; + throw new UnsupportedOperationException(); + } + } +} diff --git a/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyOutputRecord.java b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyOutputRecord.java new file mode 100644 index 0000000000..8f18fca7ba --- /dev/null +++ b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyOutputRecord.java @@ -0,0 +1,39 @@ +package com.baeldung.batch.understanding.exception; + +import java.io.Serializable; + +public class MyOutputRecord implements Serializable { + private int id; + + public MyOutputRecord(int id) { + this.id = id; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + MyOutputRecord that = (MyOutputRecord) o; + + return id == that.id; + } + + @Override + public int hashCode() { + return id; + } + + @Override + public String toString() { + return "MyOutputRecord: " + id; + } +} diff --git a/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyRetryProcessorListener.java b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyRetryProcessorListener.java new file mode 100644 index 0000000000..3bd35820c3 --- /dev/null +++ b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyRetryProcessorListener.java @@ -0,0 +1,11 @@ +package com.baeldung.batch.understanding.exception; + +import javax.batch.api.chunk.listener.RetryProcessListener; +import javax.inject.Named; + +@Named +public class MyRetryProcessorListener implements RetryProcessListener { + @Override + public void onRetryProcessException(Object item, Exception ex) throws Exception { + } +} diff --git a/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyRetryReadListener.java b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyRetryReadListener.java new file mode 100644 index 0000000000..5c4f56b75d --- /dev/null +++ b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyRetryReadListener.java @@ -0,0 +1,11 @@ +package com.baeldung.batch.understanding.exception; + +import javax.batch.api.chunk.listener.RetryReadListener; +import javax.inject.Named; + +@Named +public class MyRetryReadListener implements RetryReadListener { + @Override + public void onRetryReadException(Exception ex) throws Exception { + } +} diff --git a/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyRetryWriteListener.java b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyRetryWriteListener.java new file mode 100644 index 0000000000..a8683d86a9 --- /dev/null +++ b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyRetryWriteListener.java @@ -0,0 +1,12 @@ +package com.baeldung.batch.understanding.exception; + +import javax.batch.api.chunk.listener.RetryWriteListener; +import javax.inject.Named; +import java.util.List; + +@Named +public class MyRetryWriteListener implements RetryWriteListener { + @Override + public void onRetryWriteException(List items, Exception ex) throws Exception { + } +} diff --git a/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MySkipProcessorListener.java b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MySkipProcessorListener.java new file mode 100644 index 0000000000..74f7565cf7 --- /dev/null +++ b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MySkipProcessorListener.java @@ -0,0 +1,11 @@ +package com.baeldung.batch.understanding.exception; + +import javax.batch.api.chunk.listener.SkipProcessListener; +import javax.inject.Named; + +@Named +public class MySkipProcessorListener implements SkipProcessListener { + @Override + public void onSkipProcessItem(Object t, Exception e) throws Exception { + } +} diff --git a/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MySkipReadListener.java b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MySkipReadListener.java new file mode 100644 index 0000000000..aecaf93e75 --- /dev/null +++ b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MySkipReadListener.java @@ -0,0 +1,11 @@ +package com.baeldung.batch.understanding.exception; + +import javax.batch.api.chunk.listener.SkipReadListener; +import javax.inject.Named; + +@Named +public class MySkipReadListener implements SkipReadListener { + @Override + public void onSkipReadItem(Exception e) throws Exception { + } +} diff --git a/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MySkipWriteListener.java b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MySkipWriteListener.java new file mode 100644 index 0000000000..928773b61d --- /dev/null +++ b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MySkipWriteListener.java @@ -0,0 +1,13 @@ +package com.baeldung.batch.understanding.exception; + +import javax.batch.api.chunk.listener.SkipWriteListener; +import javax.inject.Named; +import java.util.List; + +@Named +public class MySkipWriteListener implements SkipWriteListener { + @Override + public void onSkipWriteItem(List list, Exception e) throws Exception { + list.remove(new MyOutputRecord(2)); + } +} diff --git a/jee-7/src/main/resources/META-INF/batch-jobs/customCheckPoint.xml b/jee-7/src/main/resources/META-INF/batch-jobs/customCheckPoint.xml new file mode 100644 index 0000000000..b0f327dd39 --- /dev/null +++ b/jee-7/src/main/resources/META-INF/batch-jobs/customCheckPoint.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/jee-7/src/main/resources/META-INF/batch-jobs/decideJobSequence.xml b/jee-7/src/main/resources/META-INF/batch-jobs/decideJobSequence.xml new file mode 100644 index 0000000000..4905586fb9 --- /dev/null +++ b/jee-7/src/main/resources/META-INF/batch-jobs/decideJobSequence.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jee-7/src/main/resources/META-INF/batch-jobs/flowJobSequence.xml b/jee-7/src/main/resources/META-INF/batch-jobs/flowJobSequence.xml new file mode 100644 index 0000000000..207a9242b1 --- /dev/null +++ b/jee-7/src/main/resources/META-INF/batch-jobs/flowJobSequence.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jee-7/src/main/resources/META-INF/batch-jobs/injectionSimpleBatchLet.xml b/jee-7/src/main/resources/META-INF/batch-jobs/injectionSimpleBatchLet.xml new file mode 100644 index 0000000000..d152f063f6 --- /dev/null +++ b/jee-7/src/main/resources/META-INF/batch-jobs/injectionSimpleBatchLet.xml @@ -0,0 +1,13 @@ + + + + + + + + + + \ No newline at end of file diff --git a/jee-7/src/main/resources/META-INF/batch-jobs/partitionSimpleBatchLet.xml b/jee-7/src/main/resources/META-INF/batch-jobs/partitionSimpleBatchLet.xml new file mode 100644 index 0000000000..76c64ee899 --- /dev/null +++ b/jee-7/src/main/resources/META-INF/batch-jobs/partitionSimpleBatchLet.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jee-7/src/main/resources/META-INF/batch-jobs/simpleBatchLet.xml b/jee-7/src/main/resources/META-INF/batch-jobs/simpleBatchLet.xml new file mode 100644 index 0000000000..9c707de8a4 --- /dev/null +++ b/jee-7/src/main/resources/META-INF/batch-jobs/simpleBatchLet.xml @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/jee-7/src/main/resources/META-INF/batch-jobs/simpleChunk.xml b/jee-7/src/main/resources/META-INF/batch-jobs/simpleChunk.xml new file mode 100644 index 0000000000..b2b15b7bd9 --- /dev/null +++ b/jee-7/src/main/resources/META-INF/batch-jobs/simpleChunk.xml @@ -0,0 +1,11 @@ + + + + + + + + + + \ No newline at end of file diff --git a/jee-7/src/main/resources/META-INF/batch-jobs/simpleErrorChunk.xml b/jee-7/src/main/resources/META-INF/batch-jobs/simpleErrorChunk.xml new file mode 100644 index 0000000000..743fcafd65 --- /dev/null +++ b/jee-7/src/main/resources/META-INF/batch-jobs/simpleErrorChunk.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jee-7/src/main/resources/META-INF/batch-jobs/simpleErrorSkipChunk.xml b/jee-7/src/main/resources/META-INF/batch-jobs/simpleErrorSkipChunk.xml new file mode 100644 index 0000000000..2fafb83cc7 --- /dev/null +++ b/jee-7/src/main/resources/META-INF/batch-jobs/simpleErrorSkipChunk.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jee-7/src/main/resources/META-INF/batch-jobs/simpleJobSequence.xml b/jee-7/src/main/resources/META-INF/batch-jobs/simpleJobSequence.xml new file mode 100644 index 0000000000..7110db7f23 --- /dev/null +++ b/jee-7/src/main/resources/META-INF/batch-jobs/simpleJobSequence.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/jee-7/src/main/resources/META-INF/batch-jobs/splitJobSequence.xml b/jee-7/src/main/resources/META-INF/batch-jobs/splitJobSequence.xml new file mode 100644 index 0000000000..0a9ea97dc7 --- /dev/null +++ b/jee-7/src/main/resources/META-INF/batch-jobs/splitJobSequence.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jee-7/src/main/resources/META-INF/beans.xml b/jee-7/src/main/resources/META-INF/beans.xml new file mode 100644 index 0000000000..ae0f4bf2ee --- /dev/null +++ b/jee-7/src/main/resources/META-INF/beans.xml @@ -0,0 +1,8 @@ + + + \ No newline at end of file diff --git a/jee-7/src/test/java/com/baeldung/batch/understanding/BatchTestHelper.java b/jee-7/src/test/java/com/baeldung/batch/understanding/BatchTestHelper.java new file mode 100644 index 0000000000..5060bd9b91 --- /dev/null +++ b/jee-7/src/test/java/com/baeldung/batch/understanding/BatchTestHelper.java @@ -0,0 +1,79 @@ +package com.baeldung.batch.understanding; + +import java.util.HashMap; +import java.util.Map; + +import javax.batch.runtime.BatchRuntime; +import javax.batch.runtime.BatchStatus; +import javax.batch.runtime.JobExecution; +import javax.batch.runtime.Metric; + +public class BatchTestHelper { + private static final int MAX_TRIES = 40; + private static final int THREAD_SLEEP = 1000; + + private BatchTestHelper() { + throw new UnsupportedOperationException(); + } + + public static JobExecution keepTestAlive(JobExecution jobExecution) throws InterruptedException { + int maxTries = 0; + while (!jobExecution.getBatchStatus() + .equals(BatchStatus.COMPLETED)) { + if (maxTries < MAX_TRIES) { + maxTries++; + Thread.sleep(THREAD_SLEEP); + jobExecution = BatchRuntime.getJobOperator() + .getJobExecution(jobExecution.getExecutionId()); + } else { + break; + } + } + Thread.sleep(THREAD_SLEEP); + return jobExecution; + } + + public static JobExecution keepTestFailed(JobExecution jobExecution) throws InterruptedException { + int maxTries = 0; + while (!jobExecution.getBatchStatus() + .equals(BatchStatus.FAILED)) { + if (maxTries < MAX_TRIES) { + maxTries++; + Thread.sleep(THREAD_SLEEP); + jobExecution = BatchRuntime.getJobOperator() + .getJobExecution(jobExecution.getExecutionId()); + } else { + break; + } + } + Thread.sleep(THREAD_SLEEP); + + return jobExecution; + } + + public static JobExecution keepTestStopped(JobExecution jobExecution) throws InterruptedException { + int maxTries = 0; + while (!jobExecution.getBatchStatus() + .equals(BatchStatus.STOPPED)) { + if (maxTries < MAX_TRIES) { + maxTries++; + Thread.sleep(THREAD_SLEEP); + jobExecution = BatchRuntime.getJobOperator() + .getJobExecution(jobExecution.getExecutionId()); + } else { + break; + } + } + Thread.sleep(THREAD_SLEEP); + return jobExecution; + } + + public static Map getMetricsMap(Metric[] metrics) { + Map metricsMap = new HashMap<>(); + for (Metric metric : metrics) { + metricsMap.put(metric.getType(), metric.getValue()); + } + return metricsMap; + } + +} diff --git a/jee-7/src/test/java/com/baeldung/batch/understanding/CustomCheckPointUnitTest.java b/jee-7/src/test/java/com/baeldung/batch/understanding/CustomCheckPointUnitTest.java new file mode 100644 index 0000000000..a9488c5c03 --- /dev/null +++ b/jee-7/src/test/java/com/baeldung/batch/understanding/CustomCheckPointUnitTest.java @@ -0,0 +1,33 @@ +package com.baeldung.batch.understanding; + +import static org.junit.jupiter.api.Assertions.*; +import java.util.Map; +import java.util.Properties; +import javax.batch.operations.JobOperator; +import javax.batch.runtime.BatchRuntime; +import javax.batch.runtime.BatchStatus; +import javax.batch.runtime.JobExecution; +import javax.batch.runtime.Metric; +import javax.batch.runtime.StepExecution; +import com.baeldung.batch.understanding.BatchTestHelper; + +import org.junit.jupiter.api.Test; + +class CustomCheckPointUnitTest { + @Test + public void givenChunk_whenCustomCheckPoint_thenCommitCount_3() throws Exception { + JobOperator jobOperator = BatchRuntime.getJobOperator(); + Long executionId = jobOperator.start("customCheckPoint", new Properties()); + JobExecution jobExecution = jobOperator.getJobExecution(executionId); + jobExecution = BatchTestHelper.keepTestAlive(jobExecution); + for (StepExecution stepExecution : jobOperator.getStepExecutions(executionId)) { + if (stepExecution.getStepName() + .equals("firstChunkStep")) { + Map metricsMap = BatchTestHelper.getMetricsMap(stepExecution.getMetrics()); + assertEquals(3L, metricsMap.get(Metric.MetricType.COMMIT_COUNT) + .longValue()); + } + } + assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED); + } +} diff --git a/jee-7/src/test/java/com/baeldung/batch/understanding/JobSequenceUnitTest.java b/jee-7/src/test/java/com/baeldung/batch/understanding/JobSequenceUnitTest.java new file mode 100644 index 0000000000..7c5e8d0b78 --- /dev/null +++ b/jee-7/src/test/java/com/baeldung/batch/understanding/JobSequenceUnitTest.java @@ -0,0 +1,74 @@ +package com.baeldung.batch.understanding; + +import static org.junit.jupiter.api.Assertions.*; + +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +import javax.batch.operations.JobOperator; +import javax.batch.runtime.BatchRuntime; +import javax.batch.runtime.BatchStatus; +import javax.batch.runtime.JobExecution; +import javax.batch.runtime.StepExecution; + +import org.junit.jupiter.api.Test; + +class JobSequenceUnitTest { + @Test + public void givenTwoSteps_thenBatch_CompleteWithSuccess() throws Exception { + JobOperator jobOperator = BatchRuntime.getJobOperator(); + Long executionId = jobOperator.start("simpleJobSequence", new Properties()); + JobExecution jobExecution = jobOperator.getJobExecution(executionId); + jobExecution = BatchTestHelper.keepTestAlive(jobExecution); + assertEquals(2 , jobOperator.getStepExecutions(executionId).size()); + assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED); + } + + @Test + public void givenFlow_thenBatch_CompleteWithSuccess() throws Exception { + JobOperator jobOperator = BatchRuntime.getJobOperator(); + Long executionId = jobOperator.start("flowJobSequence", new Properties()); + JobExecution jobExecution = jobOperator.getJobExecution(executionId); + jobExecution = BatchTestHelper.keepTestAlive(jobExecution); + assertEquals(3 , jobOperator.getStepExecutions(executionId).size()); + assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED); + } + + @Test + public void givenDecider_thenBatch_CompleteWithSuccess() throws Exception { + JobOperator jobOperator = BatchRuntime.getJobOperator(); + Long executionId = jobOperator.start("decideJobSequence", new Properties()); + JobExecution jobExecution = jobOperator.getJobExecution(executionId); + jobExecution = BatchTestHelper.keepTestAlive(jobExecution); + List stepExecutions = jobOperator.getStepExecutions(executionId); + List executedSteps = new ArrayList<>(); + for (StepExecution stepExecution : stepExecutions) { + executedSteps.add(stepExecution.getStepName()); + } + assertEquals(2, jobOperator.getStepExecutions(executionId).size()); + assertArrayEquals(new String[] { "firstBatchStepStep1", "firstBatchStepStep3" }, executedSteps.toArray()); + assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED); + } + + @Test + public void givenSplit_thenBatch_CompletesWithSuccess() throws Exception { + JobOperator jobOperator = BatchRuntime.getJobOperator(); + Long executionId = jobOperator.start("splitJobSequence", new Properties()); + JobExecution jobExecution = jobOperator.getJobExecution(executionId); + jobExecution = BatchTestHelper.keepTestAlive(jobExecution); + List stepExecutions = jobOperator.getStepExecutions(executionId); + List executedSteps = new ArrayList<>(); + for (StepExecution stepExecution : stepExecutions) { + executedSteps.add(stepExecution.getStepName()); + } + assertEquals(3, stepExecutions.size()); + assertTrue(executedSteps.contains("splitJobSequenceStep1")); + assertTrue(executedSteps.contains("splitJobSequenceStep2")); + assertTrue(executedSteps.contains("splitJobSequenceStep3")); + assertTrue(executedSteps.get(0).equals("splitJobSequenceStep1") || executedSteps.get(0).equals("splitJobSequenceStep2")); + assertTrue(executedSteps.get(1).equals("splitJobSequenceStep1") || executedSteps.get(1).equals("splitJobSequenceStep2")); + assertTrue(executedSteps.get(2).equals("splitJobSequenceStep3")); + assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED); + } +} diff --git a/jee-7/src/test/java/com/baeldung/batch/understanding/SimpleBatchLetUnitTest.java b/jee-7/src/test/java/com/baeldung/batch/understanding/SimpleBatchLetUnitTest.java new file mode 100644 index 0000000000..485c997cc6 --- /dev/null +++ b/jee-7/src/test/java/com/baeldung/batch/understanding/SimpleBatchLetUnitTest.java @@ -0,0 +1,68 @@ +package com.baeldung.batch.understanding; + +import static org.junit.jupiter.api.Assertions.*; + +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import javax.batch.operations.JobOperator; +import javax.batch.runtime.BatchRuntime; +import javax.batch.runtime.BatchStatus; +import javax.batch.runtime.JobExecution; +import javax.batch.runtime.Metric; +import javax.batch.runtime.StepExecution; + +import org.junit.jupiter.api.Test; + +class SimpleBatchLetUnitTest { + @Test + public void givenBatchLet_thenBatch_CompleteWithSuccess() throws Exception { + JobOperator jobOperator = BatchRuntime.getJobOperator(); + Long executionId = jobOperator.start("simpleBatchLet", new Properties()); + JobExecution jobExecution = jobOperator.getJobExecution(executionId); + jobExecution = BatchTestHelper.keepTestAlive(jobExecution); + assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED); + } + + @Test + public void givenBatchLetProperty_thenBatch_CompleteWithSuccess() throws Exception { + JobOperator jobOperator = BatchRuntime.getJobOperator(); + Long executionId = jobOperator.start("injectionSimpleBatchLet", new Properties()); + JobExecution jobExecution = jobOperator.getJobExecution(executionId); + jobExecution = BatchTestHelper.keepTestAlive(jobExecution); + assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED); + } + + @Test + public void givenBatchLetPartition_thenBatch_CompleteWithSuccess() throws Exception { + JobOperator jobOperator = BatchRuntime.getJobOperator(); + Long executionId = jobOperator.start("partitionSimpleBatchLet", new Properties()); + JobExecution jobExecution = jobOperator.getJobExecution(executionId); + jobExecution = BatchTestHelper.keepTestAlive(jobExecution); + assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED); + } + + @Test + public void givenBatchLetStarted_whenStopped_thenBatchStopped() throws Exception { + JobOperator jobOperator = BatchRuntime.getJobOperator(); + Long executionId = jobOperator.start("simpleBatchLet", new Properties()); + JobExecution jobExecution = jobOperator.getJobExecution(executionId); + jobOperator.stop(executionId); + jobExecution = BatchTestHelper.keepTestStopped(jobExecution); + assertEquals(jobExecution.getBatchStatus(), BatchStatus.STOPPED); + } + + @Test + public void givenBatchLetStopped_whenRestarted_thenBatchCompletesSuccess() throws Exception { + JobOperator jobOperator = BatchRuntime.getJobOperator(); + Long executionId = jobOperator.start("simpleBatchLet", new Properties()); + JobExecution jobExecution = jobOperator.getJobExecution(executionId); + jobOperator.stop(executionId); + jobExecution = BatchTestHelper.keepTestStopped(jobExecution); + assertEquals(jobExecution.getBatchStatus(), BatchStatus.STOPPED); + executionId = jobOperator.restart(jobExecution.getExecutionId(), new Properties()); + jobExecution = BatchTestHelper.keepTestAlive(jobOperator.getJobExecution(executionId)); + assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED); + } +} diff --git a/jee-7/src/test/java/com/baeldung/batch/understanding/SimpleChunkUnitTest.java b/jee-7/src/test/java/com/baeldung/batch/understanding/SimpleChunkUnitTest.java new file mode 100644 index 0000000000..57c794ba00 --- /dev/null +++ b/jee-7/src/test/java/com/baeldung/batch/understanding/SimpleChunkUnitTest.java @@ -0,0 +1,67 @@ +package com.baeldung.batch.understanding; + +import static org.junit.jupiter.api.Assertions.*; + +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import javax.batch.operations.JobOperator; +import javax.batch.runtime.BatchRuntime; +import javax.batch.runtime.BatchStatus; +import javax.batch.runtime.JobExecution; +import javax.batch.runtime.Metric; +import javax.batch.runtime.StepExecution; + +import org.junit.jupiter.api.Test; + +class SimpleChunkUnitTest { + @Test + public void givenChunk_thenBatch_CompletesWithSucess() throws Exception { + JobOperator jobOperator = BatchRuntime.getJobOperator(); + Long executionId = jobOperator.start("simpleChunk", new Properties()); + JobExecution jobExecution = jobOperator.getJobExecution(executionId); + jobExecution = BatchTestHelper.keepTestAlive(jobExecution); + List stepExecutions = jobOperator.getStepExecutions(executionId); + for (StepExecution stepExecution : stepExecutions) { + if (stepExecution.getStepName() + .equals("firstChunkStep")) { + Map metricsMap = BatchTestHelper.getMetricsMap(stepExecution.getMetrics()); + assertEquals(10L, metricsMap.get(Metric.MetricType.READ_COUNT) + .longValue()); + assertEquals(10L / 2L, metricsMap.get(Metric.MetricType.WRITE_COUNT) + .longValue()); + assertEquals(10L / 3 + (10L % 3 > 0 ? 1 : 0), metricsMap.get(Metric.MetricType.COMMIT_COUNT) + .longValue()); + } + } + assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED); + } + + @Test + public void givenChunk__thenBatch_fetchInformation() throws Exception { + JobOperator jobOperator = BatchRuntime.getJobOperator(); + Long executionId = jobOperator.start("simpleChunk", new Properties()); + JobExecution jobExecution = jobOperator.getJobExecution(executionId); + jobExecution = BatchTestHelper.keepTestAlive(jobExecution); + // job name contains simpleBatchLet which is the name of the file + assertTrue(jobOperator.getJobNames().contains("simpleChunk")); + // job parameters are empty + assertTrue(jobOperator.getParameters(executionId).isEmpty()); + // step execution information + List stepExecutions = jobOperator.getStepExecutions(executionId); + assertEquals("firstChunkStep", stepExecutions.get(0).getStepName()); + // finding out batch status + assertEquals(BatchStatus.COMPLETED, stepExecutions.get(0).getBatchStatus()); + Map metricTest = BatchTestHelper.getMetricsMap(stepExecutions.get(0).getMetrics()); + assertEquals(10L, metricTest.get(Metric.MetricType.READ_COUNT).longValue()); + assertEquals(5L, metricTest.get(Metric.MetricType.FILTER_COUNT).longValue()); + assertEquals(4L, metricTest.get(Metric.MetricType.COMMIT_COUNT).longValue()); + assertEquals(5L, metricTest.get(Metric.MetricType.WRITE_COUNT).longValue()); + assertEquals(0L, metricTest.get(Metric.MetricType.READ_SKIP_COUNT).longValue()); + assertEquals(0L, metricTest.get(Metric.MetricType.WRITE_SKIP_COUNT).longValue()); + assertEquals(0L, metricTest.get(Metric.MetricType.PROCESS_SKIP_COUNT).longValue()); + assertEquals(0L, metricTest.get(Metric.MetricType.ROLLBACK_COUNT).longValue()); + assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED); + } +} diff --git a/jee-7/src/test/java/com/baeldung/batch/understanding/SimpleErrorChunkUnitTest.java b/jee-7/src/test/java/com/baeldung/batch/understanding/SimpleErrorChunkUnitTest.java new file mode 100644 index 0000000000..0f6d068888 --- /dev/null +++ b/jee-7/src/test/java/com/baeldung/batch/understanding/SimpleErrorChunkUnitTest.java @@ -0,0 +1,48 @@ +package com.baeldung.batch.understanding; + +import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; + +import java.util.List; +import java.util.Map; +import java.util.Properties; +import javax.batch.operations.JobOperator; +import javax.batch.runtime.BatchRuntime; +import javax.batch.runtime.BatchStatus; +import javax.batch.runtime.JobExecution; +import javax.batch.runtime.Metric.MetricType; +import javax.batch.runtime.StepExecution; + +import org.junit.jupiter.api.Test; + +class SimpleErrorChunkUnitTest { + + @Test + public void givenChunkError_thenBatch_CompletesWithFailed() throws Exception { + JobOperator jobOperator = BatchRuntime.getJobOperator(); + Long executionId = jobOperator.start("simpleErrorChunk", new Properties()); + JobExecution jobExecution = jobOperator.getJobExecution(executionId); + jobExecution = BatchTestHelper.keepTestFailed(jobExecution); + System.out.println(jobExecution.getBatchStatus()); + assertEquals(jobExecution.getBatchStatus(), BatchStatus.FAILED); + } + + @Test + public void givenChunkError_thenErrorSkipped_CompletesWithSuccess() throws Exception { + JobOperator jobOperator = BatchRuntime.getJobOperator(); + Long executionId = jobOperator.start("simpleErrorSkipChunk", new Properties()); + JobExecution jobExecution = jobOperator.getJobExecution(executionId); + jobExecution = BatchTestHelper.keepTestAlive(jobExecution); + List stepExecutions = jobOperator.getStepExecutions(executionId); + for (StepExecution stepExecution : stepExecutions) { + if (stepExecution.getStepName() + .equals("errorStep")) { + Map metricsMap = BatchTestHelper.getMetricsMap(stepExecution.getMetrics()); + long skipCount = metricsMap.get(MetricType.PROCESS_SKIP_COUNT) + .longValue(); + assertTrue("Skip count=" + skipCount, skipCount == 1l || skipCount == 2l); + } + } + assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED); + } +}