From e92ecf211a0cc3f0a83cb207e7d6667efe450cd7 Mon Sep 17 00:00:00 2001 From: Usman Mohyuddin Date: Sat, 29 Aug 2020 22:31:40 +0500 Subject: [PATCH 01/54] Remove prefix from string using groovy (BAEL-4104) Remove prefix from string using groovy (BAEL-4104) --- core-groovy-strings/README.md | 8 +++ core-groovy-strings/pom.xml | 72 +++++++++++++++++++ .../removeprefix/RemovePrefixTest.groovy | 58 +++++++++++++++ 3 files changed, 138 insertions(+) create mode 100644 core-groovy-strings/README.md create mode 100644 core-groovy-strings/pom.xml create mode 100644 core-groovy-strings/src/test/groovy/com/baeldung/removeprefix/RemovePrefixTest.groovy diff --git a/core-groovy-strings/README.md b/core-groovy-strings/README.md new file mode 100644 index 0000000000..e3202e2dd0 --- /dev/null +++ b/core-groovy-strings/README.md @@ -0,0 +1,8 @@ +# Core Groovy Strings + +This module contains articles about core Groovy strings concepts + +## Relevant articles: + +- [Remove prefix in Groovy]() +- [[<-- Prev]](/core-groovy-strings) diff --git a/core-groovy-strings/pom.xml b/core-groovy-strings/pom.xml new file mode 100644 index 0000000000..059b53662c --- /dev/null +++ b/core-groovy-strings/pom.xml @@ -0,0 +1,72 @@ + + + com.baeldung + 4.0.0 + core-groovy-strings + 1.0-SNAPSHOT + core-groovy-strings + jar + + + + org.codehaus.groovy + groovy-all + ${groovy.version} + pom + + + org.junit.platform + junit-platform-runner + ${junit.platform.version} + test + + + + + src/main/groovy + src/main/java + + + org.codehaus.groovy + groovy-eclipse-compiler + ${groovy.compiler.version} + true + + + maven-compiler-plugin + ${compiler.plugin.version} + + groovy-eclipse-compiler + ${java.version} + ${java.version} + + + + org.codehaus.groovy + groovy-eclipse-compiler + ${groovy.compiler.version} + + + org.codehaus.groovy + groovy-eclipse-batch + ${groovy.version}-01 + + + + + + + + 1.0.0 + 1.1.3 + 2.5.7 + 2.20.1 + 3.8.0 + 3.3.0-01 + 1.8 + + + \ No newline at end of file diff --git a/core-groovy-strings/src/test/groovy/com/baeldung/removeprefix/RemovePrefixTest.groovy b/core-groovy-strings/src/test/groovy/com/baeldung/removeprefix/RemovePrefixTest.groovy new file mode 100644 index 0000000000..568e5fdde8 --- /dev/null +++ b/core-groovy-strings/src/test/groovy/com/baeldung/removeprefix/RemovePrefixTest.groovy @@ -0,0 +1,58 @@ +package com.baeldung.removeprefix + +import org.junit.Assert +import org.junit.Test + +class RemovePrefixTest { + + + @Test + public void givenWhenCasePrefixIsRemoved_thenReturnTrue() { + def trimPrefix = { + it.startsWith('Groovy') ? it.minus('Groovy') : it + } + + Assert.assertEquals(trimPrefix("GroovyTutorials at Baeldung"), "Tutorials at Baeldung") + } + + @Test + public void givenWhenPrefixIsRemoved_thenReturnTrue() { + + String prefix = "groovy-" + String trimPrefix = "Groovy-Tutorials at Baeldung" + def result; + if(trimPrefix.startsWithIgnoreCase(prefix)) { + result = trimPrefix.substring(prefix.length()) + } + + Assert.assertEquals("Tutorials at Baeldung", result) + } + + @Test + public void givenWhenPrefixIsRemovedUsingRegex_thenReturnTrue() { + + def regex = ~"^([Gg])roovy-" + String trimPrefix = "Groovy-Tutorials at Baeldung" + String result = trimPrefix - regex + + Assert.assertEquals("Tutorials at Baeldung", result) + } + + @Test public void givenWhenPrefixIsRemovedUsingReplaceFirst_thenReturnTrue() { + def regex = ~"^groovy" + String trimPrefix = "groovyTutorials at Baeldung's groovy page" + String result = trimPrefix.replaceFirst(regex, "") + + Assert.assertEquals("Tutorials at Baeldung's groovy page", result) + } + + @Test + public void givenWhenPrefixIsRemovedUsingReplaceAll_thenReturnTrue() { + + String trimPrefix = "groovyTutorials at Baeldung groovy" + String result = trimPrefix.replaceAll(/^groovy/, "") + + Assert.assertEquals("Tutorials at Baeldung groovy", result) + } + +} From 8415ee8096e64e7b7a57fb0fe85d17024a4d6884 Mon Sep 17 00:00:00 2001 From: Usman Mohyuddin Date: Sun, 6 Sep 2020 00:07:33 +0500 Subject: [PATCH 02/54] update the test names as whenX_thenY update the test names as whenX_thenY --- .../com/baeldung/removeprefix/RemovePrefixTest.groovy | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core-groovy-strings/src/test/groovy/com/baeldung/removeprefix/RemovePrefixTest.groovy b/core-groovy-strings/src/test/groovy/com/baeldung/removeprefix/RemovePrefixTest.groovy index 568e5fdde8..aa9e65d98d 100644 --- a/core-groovy-strings/src/test/groovy/com/baeldung/removeprefix/RemovePrefixTest.groovy +++ b/core-groovy-strings/src/test/groovy/com/baeldung/removeprefix/RemovePrefixTest.groovy @@ -7,7 +7,7 @@ class RemovePrefixTest { @Test - public void givenWhenCasePrefixIsRemoved_thenReturnTrue() { + public void whenCasePrefixIsRemoved_thenReturnTrue() { def trimPrefix = { it.startsWith('Groovy') ? it.minus('Groovy') : it } @@ -16,7 +16,7 @@ class RemovePrefixTest { } @Test - public void givenWhenPrefixIsRemoved_thenReturnTrue() { + public void whenPrefixIsRemovedWithIgnoreCase_thenReturnTrue() { String prefix = "groovy-" String trimPrefix = "Groovy-Tutorials at Baeldung" @@ -29,7 +29,7 @@ class RemovePrefixTest { } @Test - public void givenWhenPrefixIsRemovedUsingRegex_thenReturnTrue() { + public void whenPrefixIsRemovedUsingRegex_thenReturnTrue() { def regex = ~"^([Gg])roovy-" String trimPrefix = "Groovy-Tutorials at Baeldung" @@ -38,7 +38,7 @@ class RemovePrefixTest { Assert.assertEquals("Tutorials at Baeldung", result) } - @Test public void givenWhenPrefixIsRemovedUsingReplaceFirst_thenReturnTrue() { + @Test public void whenPrefixIsRemovedUsingReplaceFirst_thenReturnTrue() { def regex = ~"^groovy" String trimPrefix = "groovyTutorials at Baeldung's groovy page" String result = trimPrefix.replaceFirst(regex, "") @@ -47,7 +47,7 @@ class RemovePrefixTest { } @Test - public void givenWhenPrefixIsRemovedUsingReplaceAll_thenReturnTrue() { + public void whenPrefixIsRemovedUsingReplaceAll_thenReturnTrue() { String trimPrefix = "groovyTutorials at Baeldung groovy" String result = trimPrefix.replaceAll(/^groovy/, "") From ae5ee571b9c7528f70e47dc7d12b038376032fc2 Mon Sep 17 00:00:00 2001 From: mikr Date: Thu, 10 Sep 2020 01:08:03 +0200 Subject: [PATCH 03/54] Java-2394 Create default and integration profile for JDK-9 and above modules --- .../{AppTest.java => AppUnitTest.java} | 6 +- core-java-modules/core-java-11/pom.xml | 2 +- ...ingAPITest.java => StringAPIUnitTest.java} | 2 +- .../{PersonTest.java => PersonUnitTest.java} | 2 +- core-java-modules/core-java-9/pom.xml | 11 +++ ...esTest.java => MethodHandlesUnitTest.java} | 2 +- ...> TimestampToStringConverterUnitTest.java} | 2 +- .../consumermodule/pom.xml | 2 +- .../decoupling-pattern1/servicemodule/pom.xml | 3 +- .../providermodule/pom.xml | 2 +- .../decoupling-pattern2/servicemodule/pom.xml | 3 +- ...a => CurrentDirectoryFetcherUnitTest.java} | 2 +- .../multimodulemavenproject/daomodule/pom.xml | 4 + .../entitymodule/pom.xml | 4 + .../mainappmodule/pom.xml | 4 + .../userdaomodule/pom.xml | 4 + core-java-modules/pom.xml | 20 ---- pom.xml | 98 +++++++++++++++++++ 18 files changed, 140 insertions(+), 33 deletions(-) rename core-java-modules/core-java-10/src/test/java/com/baeldung/{AppTest.java => AppUnitTest.java} (82%) rename core-java-modules/core-java-12/src/test/java/com/baeldung/string/{StringAPITest.java => StringAPIUnitTest.java} (97%) rename core-java-modules/core-java-14/src/test/java/com/baeldung/java14/record/{PersonTest.java => PersonUnitTest.java} (99%) rename core-java-modules/core-java-9/src/test/java/com/baeldung/java9/methodhandles/{MethodHandlesTest.java => MethodHandlesUnitTest.java} (99%) rename core-java-modules/core-java-datetime-string/src/test/java/com/baeldung/timestamp/{TimestampToStringConverterTest.java => TimestampToStringConverterUnitTest.java} (92%) rename core-java-modules/core-java-os/src/test/java/com/baeldung/core/pwd/{CurrentDirectoryFetcherTest.java => CurrentDirectoryFetcherUnitTest.java} (95%) diff --git a/core-java-modules/core-java-10/src/test/java/com/baeldung/AppTest.java b/core-java-modules/core-java-10/src/test/java/com/baeldung/AppUnitTest.java similarity index 82% rename from core-java-modules/core-java-10/src/test/java/com/baeldung/AppTest.java rename to core-java-modules/core-java-10/src/test/java/com/baeldung/AppUnitTest.java index c9f61455bd..73eb8e661a 100644 --- a/core-java-modules/core-java-10/src/test/java/com/baeldung/AppTest.java +++ b/core-java-modules/core-java-10/src/test/java/com/baeldung/AppUnitTest.java @@ -7,7 +7,7 @@ import junit.framework.TestSuite; /** * Unit test for simple App. */ -public class AppTest +public class AppUnitTest extends TestCase { /** @@ -15,7 +15,7 @@ public class AppTest * * @param testName name of the test case */ - public AppTest( String testName ) + public AppUnitTest(String testName ) { super( testName ); } @@ -25,7 +25,7 @@ public class AppTest */ public static Test suite() { - return new TestSuite( AppTest.class ); + return new TestSuite( AppUnitTest.class ); } /** diff --git a/core-java-modules/core-java-11/pom.xml b/core-java-modules/core-java-11/pom.xml index bbc4219eaa..2f7f5a6bcf 100644 --- a/core-java-modules/core-java-11/pom.xml +++ b/core-java-modules/core-java-11/pom.xml @@ -107,7 +107,7 @@ benchmarks 1.22 10.0.0 - 10.0.0 + 3.2.4 diff --git a/core-java-modules/core-java-12/src/test/java/com/baeldung/string/StringAPITest.java b/core-java-modules/core-java-12/src/test/java/com/baeldung/string/StringAPIUnitTest.java similarity index 97% rename from core-java-modules/core-java-12/src/test/java/com/baeldung/string/StringAPITest.java rename to core-java-modules/core-java-12/src/test/java/com/baeldung/string/StringAPIUnitTest.java index 3d80a36bf6..e5f21bb25f 100644 --- a/core-java-modules/core-java-12/src/test/java/com/baeldung/string/StringAPITest.java +++ b/core-java-modules/core-java-12/src/test/java/com/baeldung/string/StringAPIUnitTest.java @@ -5,7 +5,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import org.junit.Test; -public class StringAPITest { +public class StringAPIUnitTest { @Test public void whenPositiveArgument_thenReturnIndentedString() { diff --git a/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/record/PersonTest.java b/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/record/PersonUnitTest.java similarity index 99% rename from core-java-modules/core-java-14/src/test/java/com/baeldung/java14/record/PersonTest.java rename to core-java-modules/core-java-14/src/test/java/com/baeldung/java14/record/PersonUnitTest.java index 9bed3dab8f..594ced56cd 100644 --- a/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/record/PersonTest.java +++ b/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/record/PersonUnitTest.java @@ -7,7 +7,7 @@ import static org.junit.Assert.assertTrue; import org.junit.Test; -public class PersonTest { +public class PersonUnitTest { @Test public void givenSameNameAndAddress_whenEquals_thenPersonsEqual() { diff --git a/core-java-modules/core-java-9/pom.xml b/core-java-modules/core-java-9/pom.xml index 0669d6f597..d7894934b1 100644 --- a/core-java-modules/core-java-9/pom.xml +++ b/core-java-modules/core-java-9/pom.xml @@ -44,6 +44,16 @@ commons-collections4 ${commons-collections4.version} + + org.apache.commons + commons-lang3 + 3.11 + + + commons-io + commons-io + 2.7 + @@ -77,6 +87,7 @@ 1.9 25.1-jre 4.1 + 3.2.2 diff --git a/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/methodhandles/MethodHandlesTest.java b/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/methodhandles/MethodHandlesUnitTest.java similarity index 99% rename from core-java-modules/core-java-9/src/test/java/com/baeldung/java9/methodhandles/MethodHandlesTest.java rename to core-java-modules/core-java-9/src/test/java/com/baeldung/java9/methodhandles/MethodHandlesUnitTest.java index 7646755358..7aa74a490f 100644 --- a/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/methodhandles/MethodHandlesTest.java +++ b/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/methodhandles/MethodHandlesUnitTest.java @@ -17,7 +17,7 @@ import org.junit.Test; /** * Test case for the {@link MethodHandles} API */ -public class MethodHandlesTest { +public class MethodHandlesUnitTest { @Test public void givenConcatMethodHandle_whenInvoked_thenCorrectlyConcatenated() throws Throwable { diff --git a/core-java-modules/core-java-datetime-string/src/test/java/com/baeldung/timestamp/TimestampToStringConverterTest.java b/core-java-modules/core-java-datetime-string/src/test/java/com/baeldung/timestamp/TimestampToStringConverterUnitTest.java similarity index 92% rename from core-java-modules/core-java-datetime-string/src/test/java/com/baeldung/timestamp/TimestampToStringConverterTest.java rename to core-java-modules/core-java-datetime-string/src/test/java/com/baeldung/timestamp/TimestampToStringConverterUnitTest.java index b25ff2edb3..b928047a9a 100644 --- a/core-java-modules/core-java-datetime-string/src/test/java/com/baeldung/timestamp/TimestampToStringConverterTest.java +++ b/core-java-modules/core-java-datetime-string/src/test/java/com/baeldung/timestamp/TimestampToStringConverterUnitTest.java @@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test; import java.sql.Timestamp; import java.time.format.DateTimeFormatter; -public class TimestampToStringConverterTest { +public class TimestampToStringConverterUnitTest { @Test public void givenDatePattern_whenFormatting_thenResultingStringIsCorrect() { diff --git a/core-java-modules/core-java-jpms/decoupling-pattern1/consumermodule/pom.xml b/core-java-modules/core-java-jpms/decoupling-pattern1/consumermodule/pom.xml index fe6689dcc3..fb6d2b1065 100644 --- a/core-java-modules/core-java-jpms/decoupling-pattern1/consumermodule/pom.xml +++ b/core-java-modules/core-java-jpms/decoupling-pattern1/consumermodule/pom.xml @@ -17,7 +17,7 @@ com.baeldung.servicemodule - servicemodule + servicemodule1 ${servicemodule.version} diff --git a/core-java-modules/core-java-jpms/decoupling-pattern1/servicemodule/pom.xml b/core-java-modules/core-java-jpms/decoupling-pattern1/servicemodule/pom.xml index c2da228ce6..4c811ea866 100644 --- a/core-java-modules/core-java-jpms/decoupling-pattern1/servicemodule/pom.xml +++ b/core-java-modules/core-java-jpms/decoupling-pattern1/servicemodule/pom.xml @@ -4,7 +4,8 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - servicemodule + com.baeldung.servicemodule + servicemodule1 jar diff --git a/core-java-modules/core-java-jpms/decoupling-pattern2/providermodule/pom.xml b/core-java-modules/core-java-jpms/decoupling-pattern2/providermodule/pom.xml index 3e8d5c0c39..1e29df7053 100644 --- a/core-java-modules/core-java-jpms/decoupling-pattern2/providermodule/pom.xml +++ b/core-java-modules/core-java-jpms/decoupling-pattern2/providermodule/pom.xml @@ -17,7 +17,7 @@ com.baeldung.servicemodule - servicemodule + servicemodule2 ${servicemodule.version} diff --git a/core-java-modules/core-java-jpms/decoupling-pattern2/servicemodule/pom.xml b/core-java-modules/core-java-jpms/decoupling-pattern2/servicemodule/pom.xml index 51d64998df..9a687c9ae7 100644 --- a/core-java-modules/core-java-jpms/decoupling-pattern2/servicemodule/pom.xml +++ b/core-java-modules/core-java-jpms/decoupling-pattern2/servicemodule/pom.xml @@ -4,7 +4,8 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - servicemodule + com.baeldung.servicemodule + servicemodule2 1.0 diff --git a/core-java-modules/core-java-os/src/test/java/com/baeldung/core/pwd/CurrentDirectoryFetcherTest.java b/core-java-modules/core-java-os/src/test/java/com/baeldung/core/pwd/CurrentDirectoryFetcherUnitTest.java similarity index 95% rename from core-java-modules/core-java-os/src/test/java/com/baeldung/core/pwd/CurrentDirectoryFetcherTest.java rename to core-java-modules/core-java-os/src/test/java/com/baeldung/core/pwd/CurrentDirectoryFetcherUnitTest.java index dbaad211d9..c92049816f 100644 --- a/core-java-modules/core-java-os/src/test/java/com/baeldung/core/pwd/CurrentDirectoryFetcherTest.java +++ b/core-java-modules/core-java-os/src/test/java/com/baeldung/core/pwd/CurrentDirectoryFetcherUnitTest.java @@ -4,7 +4,7 @@ import static org.junit.Assert.assertTrue; import org.junit.Test; -public class CurrentDirectoryFetcherTest { +public class CurrentDirectoryFetcherUnitTest { private static final String CURRENT_DIR = "core-java-os"; diff --git a/core-java-modules/multimodulemavenproject/daomodule/pom.xml b/core-java-modules/multimodulemavenproject/daomodule/pom.xml index 15f1215d89..56c2d70d24 100644 --- a/core-java-modules/multimodulemavenproject/daomodule/pom.xml +++ b/core-java-modules/multimodulemavenproject/daomodule/pom.xml @@ -20,6 +20,10 @@ org.apache.maven.plugins maven-compiler-plugin + + ${maven.compiler.source} + ${maven.compiler.target} + diff --git a/core-java-modules/multimodulemavenproject/entitymodule/pom.xml b/core-java-modules/multimodulemavenproject/entitymodule/pom.xml index 3e5a478299..00ad56b3ab 100644 --- a/core-java-modules/multimodulemavenproject/entitymodule/pom.xml +++ b/core-java-modules/multimodulemavenproject/entitymodule/pom.xml @@ -20,6 +20,10 @@ org.apache.maven.plugins maven-compiler-plugin + + ${maven.compiler.source} + ${maven.compiler.target} + diff --git a/core-java-modules/multimodulemavenproject/mainappmodule/pom.xml b/core-java-modules/multimodulemavenproject/mainappmodule/pom.xml index 196e58a419..a9fe04b108 100644 --- a/core-java-modules/multimodulemavenproject/mainappmodule/pom.xml +++ b/core-java-modules/multimodulemavenproject/mainappmodule/pom.xml @@ -38,6 +38,10 @@ org.apache.maven.plugins maven-compiler-plugin + + ${maven.compiler.source} + ${maven.compiler.target} + diff --git a/core-java-modules/multimodulemavenproject/userdaomodule/pom.xml b/core-java-modules/multimodulemavenproject/userdaomodule/pom.xml index f4a7e5c8f8..150c10b68f 100644 --- a/core-java-modules/multimodulemavenproject/userdaomodule/pom.xml +++ b/core-java-modules/multimodulemavenproject/userdaomodule/pom.xml @@ -33,6 +33,10 @@ org.apache.maven.plugins maven-compiler-plugin + + ${maven.compiler.source} + ${maven.compiler.target} + diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml index 36fca8de93..a6aecef741 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -18,20 +18,9 @@ core-java - - - - - core-java-8 core-java-8-2 - - - - - - core-java-annotations core-java-arrays-sorting @@ -51,7 +40,6 @@ core-java-collections-maps core-java-collections-maps-2 core-java-collections-maps-3 - core-java-concurrency-2 core-java-concurrency-advanced @@ -65,10 +53,7 @@ core-java-8-datetime-2 - core-java-date-operations-2 - - core-java-8-datetime core-java-exceptions @@ -85,7 +70,6 @@ core-java-jar core-java-jndi - core-java-jvm core-java-jvm-2 @@ -113,7 +97,6 @@ core-java-nio-2 core-java-optional - core-java-perf @@ -138,9 +121,6 @@ core-java-sun core-java-regex - - - pre-jpms diff --git a/pom.xml b/pom.xml index ffdfe4cffa..6d5c810784 100644 --- a/pom.xml +++ b/pom.xml @@ -1340,6 +1340,104 @@ + + default-jdk9-and-above + + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + 3 + true + + SpringContextTest + **/*UnitTest + + + **/*IntegrationTest.java + **/*IntTest.java + **/*LongRunningUnitTest.java + **/*ManualTest.java + **/JdbcTest.java + **/*LiveTest.java + + + + + + + + + core-java-modules/core-java-9 + core-java-modules/core-java-9-improvements + + + core-java-modules/core-java-9-streams + core-java-modules/core-java-10 + + + + + core-java-modules/core-java-collections-set + + + + core-java-modules/core-java-jpms + + + core-java-modules/multimodulemavenproject + + + + + + integration-jdk9-and-above + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*ManualTest.java + **/*LiveTest.java + + + **/*IntegrationTest.java + **/*IntTest.java + + + + + + + + core-java-modules/core-java-9 + core-java-modules/core-java-9-improvements + + + core-java-modules/core-java-9-streams + core-java-modules/core-java-10 + + + + + core-java-modules/core-java-collections-set + + + + core-java-modules/core-java-jpms + + + core-java-modules/multimodulemavenproject + + + From 43fb479c815a010c983560885f8b713eefd4347f Mon Sep 17 00:00:00 2001 From: Usman Mohyuddin Date: Thu, 10 Sep 2020 22:39:44 +0500 Subject: [PATCH 04/54] update the PR with removal of README file and update pom.xml files according to comments --- core-groovy-strings/README.md | 8 -- core-groovy-strings/pom.xml | 114 +++++++++++++----- .../removeprefix/RemovePrefixTest.groovy | 37 ++++-- pom.xml | 2 + 4 files changed, 108 insertions(+), 53 deletions(-) delete mode 100644 core-groovy-strings/README.md diff --git a/core-groovy-strings/README.md b/core-groovy-strings/README.md deleted file mode 100644 index e3202e2dd0..0000000000 --- a/core-groovy-strings/README.md +++ /dev/null @@ -1,8 +0,0 @@ -# Core Groovy Strings - -This module contains articles about core Groovy strings concepts - -## Relevant articles: - -- [Remove prefix in Groovy]() -- [[<-- Prev]](/core-groovy-strings) diff --git a/core-groovy-strings/pom.xml b/core-groovy-strings/pom.xml index 059b53662c..1144d748ee 100644 --- a/core-groovy-strings/pom.xml +++ b/core-groovy-strings/pom.xml @@ -3,70 +3,120 @@ xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - com.baeldung 4.0.0 core-groovy-strings 1.0-SNAPSHOT core-groovy-strings jar - + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + org.codehaus.groovy - groovy-all + groovy ${groovy.version} + + + org.codehaus.groovy + groovy-all + ${groovy-all.version} pom + + org.codehaus.groovy + groovy-dateutil + ${groovy.version} + + + org.codehaus.groovy + groovy-sql + ${groovy-sql.version} + org.junit.platform junit-platform-runner ${junit.platform.version} test + + org.hsqldb + hsqldb + ${hsqldb.version} + test + + + org.spockframework + spock-core + ${spock-core.version} + test + - src/main/groovy - src/main/java - org.codehaus.groovy - groovy-eclipse-compiler - ${groovy.compiler.version} - true + org.codehaus.gmavenplus + gmavenplus-plugin + ${gmavenplus-plugin.version} + + + + addSources + addTestSources + compile + compileTests + + + - maven-compiler-plugin - ${compiler.plugin.version} - - groovy-eclipse-compiler - ${java.version} - ${java.version} - + maven-failsafe-plugin + ${maven-failsafe-plugin.version} - org.codehaus.groovy - groovy-eclipse-compiler - ${groovy.compiler.version} - - - org.codehaus.groovy - groovy-eclipse-batch - ${groovy.version}-01 + org.junit.platform + junit-platform-surefire-provider + ${junit.platform.version} + + + junit5 + + integration-test + verify + + + + **/*Test5.java + + + + - + + + + central + https://jcenter.bintray.com + + + 1.0.0 - 1.1.3 - 2.5.7 - 2.20.1 - 3.8.0 - 3.3.0-01 - 1.8 + 2.5.6 + 2.5.6 + 2.5.6 + 2.4.0 + 1.1-groovy-2.4 + 1.6 - + \ No newline at end of file diff --git a/core-groovy-strings/src/test/groovy/com/baeldung/removeprefix/RemovePrefixTest.groovy b/core-groovy-strings/src/test/groovy/com/baeldung/removeprefix/RemovePrefixTest.groovy index aa9e65d98d..4cdcb4ddfa 100644 --- a/core-groovy-strings/src/test/groovy/com/baeldung/removeprefix/RemovePrefixTest.groovy +++ b/core-groovy-strings/src/test/groovy/com/baeldung/removeprefix/RemovePrefixTest.groovy @@ -9,23 +9,28 @@ class RemovePrefixTest { @Test public void whenCasePrefixIsRemoved_thenReturnTrue() { def trimPrefix = { - it.startsWith('Groovy') ? it.minus('Groovy') : it + it.startsWith('Groovy-') ? it.minus('Groovy-') : it } + + def actual = trimPrefix("Groovy-Tutorials at Baeldung") + def expected = "Tutorials at Baeldung" - Assert.assertEquals(trimPrefix("GroovyTutorials at Baeldung"), "Tutorials at Baeldung") + Assert.assertEquals(expected, actual) } @Test - public void whenPrefixIsRemovedWithIgnoreCase_thenReturnTrue() { + public void whenPrefixIsRemoved_thenReturnTrue() { String prefix = "groovy-" String trimPrefix = "Groovy-Tutorials at Baeldung" - def result; + def actual; if(trimPrefix.startsWithIgnoreCase(prefix)) { - result = trimPrefix.substring(prefix.length()) + actual = trimPrefix.substring(prefix.length()) } + + def expected = "Tutorials at Baeldung" - Assert.assertEquals("Tutorials at Baeldung", result) + Assert.assertEquals(expected, actual) } @Test @@ -33,26 +38,32 @@ class RemovePrefixTest { def regex = ~"^([Gg])roovy-" String trimPrefix = "Groovy-Tutorials at Baeldung" - String result = trimPrefix - regex + String actual = trimPrefix - regex + + def expected = "Tutorials at Baeldung" - Assert.assertEquals("Tutorials at Baeldung", result) + Assert.assertEquals(expected, actual) } @Test public void whenPrefixIsRemovedUsingReplaceFirst_thenReturnTrue() { def regex = ~"^groovy" String trimPrefix = "groovyTutorials at Baeldung's groovy page" - String result = trimPrefix.replaceFirst(regex, "") + String actual = trimPrefix.replaceFirst(regex, "") - Assert.assertEquals("Tutorials at Baeldung's groovy page", result) + def expected = "Tutorials at Baeldung's groovy page" + + Assert.assertEquals(expected, actual) } @Test public void whenPrefixIsRemovedUsingReplaceAll_thenReturnTrue() { String trimPrefix = "groovyTutorials at Baeldung groovy" - String result = trimPrefix.replaceAll(/^groovy/, "") + String actual = trimPrefix.replaceAll(/^groovy/, "") + + def expected = "Tutorials at Baeldung groovy" - Assert.assertEquals("Tutorials at Baeldung groovy", result) + Assert.assertEquals(expected, actual) } -} +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index ffdfe4cffa..f43318bcaa 100644 --- a/pom.xml +++ b/pom.xml @@ -383,6 +383,7 @@ core-groovy core-groovy-2 core-groovy-collections + core-groovy-strings core-java-modules core-kotlin-modules @@ -898,6 +899,7 @@ core-groovy core-groovy-2 core-groovy-collections + core-groovy-strings core-java-modules core-kotlin-modules From 751aa761594c834efae0f2074ac4fd1175706b6a Mon Sep 17 00:00:00 2001 From: Kai Yuan Date: Fri, 11 Sep 2020 01:08:12 +0200 Subject: [PATCH 05/54] [BAEL-4583] Improvement- Java Period --- .../com/baeldung/date/DateDiffUnitTest.java | 63 +++++++++++++------ 1 file changed, 43 insertions(+), 20 deletions(-) diff --git a/core-java-modules/core-java-date-operations-1/src/test/java/com/baeldung/date/DateDiffUnitTest.java b/core-java-modules/core-java-date-operations-1/src/test/java/com/baeldung/date/DateDiffUnitTest.java index 226556d4bb..9a0779ccac 100644 --- a/core-java-modules/core-java-date-operations-1/src/test/java/com/baeldung/date/DateDiffUnitTest.java +++ b/core-java-modules/core-java-date-operations-1/src/test/java/com/baeldung/date/DateDiffUnitTest.java @@ -1,6 +1,8 @@ package com.baeldung.date; -import static org.junit.Assert.assertEquals; +import org.joda.time.Days; +import org.joda.time.Minutes; +import org.junit.Test; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -16,7 +18,7 @@ import java.util.Locale; import java.util.TimeZone; import java.util.concurrent.TimeUnit; -import org.junit.Test; +import static org.junit.Assert.*; public class DateDiffUnitTest { @@ -29,18 +31,39 @@ public class DateDiffUnitTest { long diffInMillies = Math.abs(secondDate.getTime() - firstDate.getTime()); long diff = TimeUnit.DAYS.convert(diffInMillies, TimeUnit.MILLISECONDS); - assertEquals(diff, 6); + assertEquals(6, diff); } @Test - public void givenTwoDatesInJava8_whenDifferentiating_thenWeGetSix() { - LocalDate now = LocalDate.now(); - LocalDate sixDaysBehind = now.minusDays(6); + public void givenTwoDatesInJava8_whenUsingPeriodGetDays_thenWorks() { + LocalDate aDate = LocalDate.of(2020, 9, 11); + LocalDate sixDaysBehind = aDate.minusDays(6); - Period period = Period.between(now, sixDaysBehind); + Period period = Period.between(aDate, sixDaysBehind); int diff = Math.abs(period.getDays()); - assertEquals(diff, 6); + assertEquals(6, diff); + } + + @Test + public void givenTwoDatesInJava8_whenUsingPeriodGetDays_thenDoesNotWork() { + LocalDate aDate = LocalDate.of(2020, 9, 11); + LocalDate sixtyDaysBehind = aDate.minusDays(60); + Period period = Period.between(aDate, sixtyDaysBehind); + int diff = Math.abs(period.getDays()); + //not equals + assertNotEquals(60, diff); + } + + @Test + public void givenTwoDatesInJava8_whenUsingPeriod_thenWeGet0Year1Month29Days() { + LocalDate aDate = LocalDate.of(2020, 9, 11); + LocalDate sixtyDaysBehind = aDate.minusDays(60); + Period period = Period.between(aDate, sixtyDaysBehind); + int years = Math.abs(period.getYears()); + int months = Math.abs(period.getMonths()); + int days = Math.abs(period.getDays()); + assertArrayEquals(new int[] { 0, 1, 29 }, new int[] { years, months, days }); } @Test @@ -51,7 +74,7 @@ public class DateDiffUnitTest { Duration duration = Duration.between(now, sixMinutesBehind); long diff = Math.abs(duration.toMinutes()); - assertEquals(diff, 6); + assertEquals(6, diff); } @Test @@ -61,7 +84,7 @@ public class DateDiffUnitTest { long diff = ChronoUnit.SECONDS.between(now, tenSecondsLater); - assertEquals(diff, 10); + assertEquals(10, diff); } @Test @@ -69,9 +92,9 @@ public class DateDiffUnitTest { LocalDateTime ldt = LocalDateTime.now(); ZonedDateTime now = ldt.atZone(ZoneId.of("America/Montreal")); ZonedDateTime sixDaysBehind = now.withZoneSameInstant(ZoneId.of("Asia/Singapore")) - .minusDays(6); + .minusDays(6); long diff = ChronoUnit.DAYS.between(sixDaysBehind, now); - assertEquals(diff, 6); + assertEquals(6, diff); } @Test @@ -81,7 +104,7 @@ public class DateDiffUnitTest { long diff = now.until(tenSecondsLater, ChronoUnit.SECONDS); - assertEquals(diff, 10); + assertEquals(10, diff); } @Test @@ -89,10 +112,9 @@ public class DateDiffUnitTest { org.joda.time.LocalDate now = org.joda.time.LocalDate.now(); org.joda.time.LocalDate sixDaysBehind = now.minusDays(6); - org.joda.time.Period period = new org.joda.time.Period(now, sixDaysBehind); - long diff = Math.abs(period.getDays()); + long diff = Math.abs(Days.daysBetween(now, sixDaysBehind).getDays()); - assertEquals(diff, 6); + assertEquals(6, diff); } @Test @@ -100,8 +122,9 @@ public class DateDiffUnitTest { org.joda.time.LocalDateTime now = org.joda.time.LocalDateTime.now(); org.joda.time.LocalDateTime sixMinutesBehind = now.minusMinutes(6); - org.joda.time.Period period = new org.joda.time.Period(now, sixMinutesBehind); - long diff = Math.abs(period.getDays()); + long diff = Math.abs(Minutes.minutesBetween(now, sixMinutesBehind).getMinutes()); + assertEquals(6, diff); + } @Test @@ -111,6 +134,6 @@ public class DateDiffUnitTest { long diff = Math.abs(now.numDaysFrom(sixDaysBehind)); - assertEquals(diff, 6); + assertEquals(6, diff); } -} \ No newline at end of file +} From 57b66fa5788ff711f92716540f87205a1af38f80 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Sun, 13 Sep 2020 21:40:14 +0200 Subject: [PATCH 06/54] JAVA-2404: Fix Spring MVC and Security config --- .../java/com/baeldung/spring/WebConfig.java | 2 +- .../src/main/webapp/WEB-INF/web.xml | 28 +++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/spring-security-modules/spring-security-web-rest/src/main/java/com/baeldung/spring/WebConfig.java b/spring-security-modules/spring-security-web-rest/src/main/java/com/baeldung/spring/WebConfig.java index 84b211a9bd..76e9abdbdb 100644 --- a/spring-security-modules/spring-security-web-rest/src/main/java/com/baeldung/spring/WebConfig.java +++ b/spring-security-modules/spring-security-web-rest/src/main/java/com/baeldung/spring/WebConfig.java @@ -12,7 +12,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.view.InternalResourceViewResolver; @Configuration -@ComponentScan("com.baeldung.web") +@ComponentScan("com.baeldung") @EnableWebMvc @EnableAsync public class WebConfig implements WebMvcConfigurer { diff --git a/spring-security-modules/spring-security-web-rest/src/main/webapp/WEB-INF/web.xml b/spring-security-modules/spring-security-web-rest/src/main/webapp/WEB-INF/web.xml index 663c17bc56..6321277c5b 100644 --- a/spring-security-modules/spring-security-web-rest/src/main/webapp/WEB-INF/web.xml +++ b/spring-security-modules/spring-security-web-rest/src/main/webapp/WEB-INF/web.xml @@ -20,9 +20,9 @@ com.baeldung.spring - - org.springframework.web.context.ContextLoaderListener - + + + @@ -40,17 +40,17 @@ - - springSecurityFilterChain - org.springframework.web.filter.DelegatingFilterProxy - true - - - springSecurityFilterChain - /* - REQUEST - ASYNC - + + + + + + + + + + + From 0976c32038f17c07e0b2b2066c93a7017ebaf990 Mon Sep 17 00:00:00 2001 From: Reza Ebrahimpour Date: Tue, 15 Sep 2020 11:12:24 +0430 Subject: [PATCH 07/54] BAEL-4488 Create AvailableCiphers --- .../com/baeldung/cipher/AvailableCiphers.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 core-java-modules/core-java-security-2/src/main/java/com/baeldung/cipher/AvailableCiphers.java diff --git a/core-java-modules/core-java-security-2/src/main/java/com/baeldung/cipher/AvailableCiphers.java b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/cipher/AvailableCiphers.java new file mode 100644 index 0000000000..f73433ffd2 --- /dev/null +++ b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/cipher/AvailableCiphers.java @@ -0,0 +1,32 @@ +package com.baeldung.cipher; + +import java.security.Provider; +import java.security.Security; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +public class AvailableCiphers { + public static void main(String[] args) { + printAllCiphers(); + printCompatibleCiphers(); + } + + private static void printAllCiphers() { + for (Provider provider : Security.getProviders()) { + for (Provider.Service service : provider.getServices()) { + System.out.println(service.getAlgorithm()); + } + } + } + + private static void printCompatibleCiphers() { + List algorithms = Arrays.stream(Security.getProviders()) + .flatMap(provider -> provider.getServices().stream()) + .filter(service -> "Cipher".equals(service.getType())) + .map(Provider.Service::getAlgorithm) + .collect(Collectors.toList()); + + algorithms.forEach(System.out::println); + } +} From 4f148739678917085f9319c036e5f7b29ae0d2d5 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Tue, 15 Sep 2020 10:28:34 +0200 Subject: [PATCH 08/54] JAVA-2599: Update OS specific unit tests --- core-java-modules/core-java-io-3/README.md | 1 + .../emptiness/DirectoryEmptinessUnitTest.java | 5 +++-- .../TemporaryDirectoriesUnitTest.java | 15 +++++++++++---- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/core-java-modules/core-java-io-3/README.md b/core-java-modules/core-java-io-3/README.md index c4eacdf27a..06a2a5a0fc 100644 --- a/core-java-modules/core-java-io-3/README.md +++ b/core-java-modules/core-java-io-3/README.md @@ -9,4 +9,5 @@ This module contains articles about core Java input and output (IO) - [Check If a File or Directory Exists in Java](https://www.baeldung.com/java-file-directory-exists) - [Copy a Directory in Java](https://www.baeldung.com/java-copy-directory) - [Java Files Open Options](https://www.baeldung.com/java-file-options) +- [Creating Temporary Directories in Java](https://www.baeldung.com/java-temp-directories) - [[<-- Prev]](/core-java-modules/core-java-io-2) diff --git a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/emptiness/DirectoryEmptinessUnitTest.java b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/emptiness/DirectoryEmptinessUnitTest.java index a44aea1383..7f7936494f 100644 --- a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/emptiness/DirectoryEmptinessUnitTest.java +++ b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/emptiness/DirectoryEmptinessUnitTest.java @@ -4,6 +4,7 @@ import org.junit.Test; import java.io.File; import java.io.IOException; +import java.net.URISyntaxException; import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.Path; @@ -20,8 +21,8 @@ public class DirectoryEmptinessUnitTest { } @Test - public void givenPath_whenNotDirectory_thenReturnsFalse() throws IOException { - Path aFile = Paths.get(getClass().getResource("/notDir.txt").getPath()); + public void givenPath_whenNotDirectory_thenReturnsFalse() throws IOException, URISyntaxException { + Path aFile = Paths.get(getClass().getResource("/notDir.txt").toURI()); assertThat(isEmpty(aFile)).isFalse(); } diff --git a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/tempdirectory/TemporaryDirectoriesUnitTest.java b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/tempdirectory/TemporaryDirectoriesUnitTest.java index 470e06ef96..5cf7d88cd6 100644 --- a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/tempdirectory/TemporaryDirectoriesUnitTest.java +++ b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/tempdirectory/TemporaryDirectoriesUnitTest.java @@ -4,6 +4,7 @@ import org.apache.commons.io.FileUtils; import org.junit.Test; import java.io.IOException; +import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -66,10 +67,16 @@ public class TemporaryDirectoriesUnitTest { @Test public void givenTempDirWithPrefixWithFileAttrs_whenCreatePlainJava_thenAttributesAreSet() throws IOException { - final FileAttribute> attrs = PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("r--------")); + boolean isPosix = FileSystems.getDefault().supportedFileAttributeViews().contains("posix"); - final Path tmpdir = Files.createTempDirectory(Paths.get("target"), "tmpDirPrefix", attrs); - assertThat(tmpdir.toFile().getPath()).startsWith("target"); - assertThat(tmpdir.toFile().canWrite()).isFalse(); + if(!isPosix){ + System.out.println("You must be under a Posix Compliant Filesystem to run this test."); + } else { + final FileAttribute> attrs = PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("r--------")); + + final Path tmpdir = Files.createTempDirectory(Paths.get("target"), "tmpDirPrefix", attrs); + assertThat(tmpdir.toFile().getPath()).startsWith("target"); + assertThat(tmpdir.toFile().canWrite()).isFalse(); + } } } From 40ebac5142a360131df2fb1f26bee8cb0b542511 Mon Sep 17 00:00:00 2001 From: Usman Mohyuddin Date: Tue, 15 Sep 2020 15:09:35 +0500 Subject: [PATCH 09/54] Split the @Test annotation in new line --- .../groovy/com/baeldung/removeprefix/RemovePrefixTest.groovy | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core-groovy-strings/src/test/groovy/com/baeldung/removeprefix/RemovePrefixTest.groovy b/core-groovy-strings/src/test/groovy/com/baeldung/removeprefix/RemovePrefixTest.groovy index 4cdcb4ddfa..61b81fe1b2 100644 --- a/core-groovy-strings/src/test/groovy/com/baeldung/removeprefix/RemovePrefixTest.groovy +++ b/core-groovy-strings/src/test/groovy/com/baeldung/removeprefix/RemovePrefixTest.groovy @@ -45,7 +45,8 @@ class RemovePrefixTest { Assert.assertEquals(expected, actual) } - @Test public void whenPrefixIsRemovedUsingReplaceFirst_thenReturnTrue() { + @Test + public void whenPrefixIsRemovedUsingReplaceFirst_thenReturnTrue() { def regex = ~"^groovy" String trimPrefix = "groovyTutorials at Baeldung's groovy page" String actual = trimPrefix.replaceFirst(regex, "") From 4ae6ecbb39a37dde248f4d81521ba9d22dd044dc Mon Sep 17 00:00:00 2001 From: kwoyke Date: Tue, 15 Sep 2020 20:33:11 +0200 Subject: [PATCH 10/54] BAEL-4595: Upgrade to hazelcast-jet 4.2 (#10035) --- hazelcast/pom.xml | 10 +++----- .../hazelcast/cluster/NativeClient.java | 18 ++++++------- .../hazelcast/cluster/ServerNode.java | 10 ++++---- .../baeldung/hazelcast/jet/WordCounter.java | 25 ++++++++----------- .../hazelcast/jet/WordCounterUnitTest.java | 6 ++--- 5 files changed, 30 insertions(+), 39 deletions(-) diff --git a/hazelcast/pom.xml b/hazelcast/pom.xml index 287542be33..69444308a3 100644 --- a/hazelcast/pom.xml +++ b/hazelcast/pom.xml @@ -1,8 +1,8 @@ + xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 hazelcast 0.0.1-SNAPSHOT @@ -15,7 +15,6 @@ - com.hazelcast.jet hazelcast-jet @@ -34,8 +33,7 @@ - - 0.6 + 4.2 \ No newline at end of file diff --git a/hazelcast/src/main/java/com/baeldung/hazelcast/cluster/NativeClient.java b/hazelcast/src/main/java/com/baeldung/hazelcast/cluster/NativeClient.java index 697e362289..3e58897401 100644 --- a/hazelcast/src/main/java/com/baeldung/hazelcast/cluster/NativeClient.java +++ b/hazelcast/src/main/java/com/baeldung/hazelcast/cluster/NativeClient.java @@ -1,24 +1,20 @@ package com.baeldung.hazelcast.cluster; -import java.util.Map.Entry; - import com.hazelcast.client.HazelcastClient; import com.hazelcast.client.config.ClientConfig; -import com.hazelcast.config.GroupConfig; import com.hazelcast.core.HazelcastInstance; -import com.hazelcast.core.IMap; + +import java.util.Map; public class NativeClient { - public static void main(String[] args) throws InterruptedException { + public static void main(String[] args) { ClientConfig config = new ClientConfig(); - GroupConfig groupConfig = config.getGroupConfig(); - groupConfig.setName("dev"); - groupConfig.setPassword("dev-pass"); + config.setClusterName("dev"); HazelcastInstance hazelcastInstanceClient = HazelcastClient.newHazelcastClient(config); - IMap map = hazelcastInstanceClient.getMap("data"); - for (Entry entry : map.entrySet()) { - System.out.println(String.format("Key: %d, Value: %s", entry.getKey(), entry.getValue())); + Map map = hazelcastInstanceClient.getMap("data"); + for (Map.Entry entry : map.entrySet()) { + System.out.printf("Key: %d, Value: %s%n", entry.getKey(), entry.getValue()); } } } diff --git a/hazelcast/src/main/java/com/baeldung/hazelcast/cluster/ServerNode.java b/hazelcast/src/main/java/com/baeldung/hazelcast/cluster/ServerNode.java index 36028834a4..7c903e961a 100644 --- a/hazelcast/src/main/java/com/baeldung/hazelcast/cluster/ServerNode.java +++ b/hazelcast/src/main/java/com/baeldung/hazelcast/cluster/ServerNode.java @@ -1,19 +1,19 @@ package com.baeldung.hazelcast.cluster; -import java.util.Map; - import com.hazelcast.core.Hazelcast; import com.hazelcast.core.HazelcastInstance; -import com.hazelcast.core.IdGenerator; +import com.hazelcast.flakeidgen.FlakeIdGenerator; + +import java.util.Map; public class ServerNode { public static void main(String[] args) { HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(); Map map = hazelcastInstance.getMap("data"); - IdGenerator idGenerator = hazelcastInstance.getIdGenerator("newid"); + FlakeIdGenerator idGenerator = hazelcastInstance.getFlakeIdGenerator("newid"); for (int i = 0; i < 10; i++) { - map.put(idGenerator.newId(), "message" + 1); + map.put(idGenerator.newId(), "message" + i); } } } diff --git a/hazelcast/src/main/java/com/baeldung/hazelcast/jet/WordCounter.java b/hazelcast/src/main/java/com/baeldung/hazelcast/jet/WordCounter.java index 971986bcae..5d10650f89 100644 --- a/hazelcast/src/main/java/com/baeldung/hazelcast/jet/WordCounter.java +++ b/hazelcast/src/main/java/com/baeldung/hazelcast/jet/WordCounter.java @@ -1,33 +1,31 @@ package com.baeldung.hazelcast.jet; -import java.util.List; -import java.util.Map; - -import static com.hazelcast.jet.Traversers.traverseArray; -import static com.hazelcast.jet.aggregate.AggregateOperations.counting; -import static com.hazelcast.jet.function.DistributedFunctions.wholeItem; - import com.hazelcast.jet.Jet; import com.hazelcast.jet.JetInstance; import com.hazelcast.jet.pipeline.Pipeline; import com.hazelcast.jet.pipeline.Sinks; import com.hazelcast.jet.pipeline.Sources; +import java.util.List; +import java.util.Map; + +import static com.hazelcast.function.Functions.wholeItem; +import static com.hazelcast.jet.Traversers.traverseArray; +import static com.hazelcast.jet.aggregate.AggregateOperations.counting; + public class WordCounter { private static final String LIST_NAME = "textList"; - private static final String MAP_NAME = "countMap"; private Pipeline createPipeLine() { Pipeline p = Pipeline.create(); - p.drawFrom(Sources. list(LIST_NAME)) - .flatMap(word -> traverseArray(word.toLowerCase() - .split("\\W+"))) + p.readFrom(Sources.list(LIST_NAME)) + .flatMap(word -> traverseArray(word.toLowerCase().split("\\W+"))) .filter(word -> !word.isEmpty()) .groupingKey(wholeItem()) .aggregate(counting()) - .drainTo(Sinks.map(MAP_NAME)); + .writeTo(Sinks.map(MAP_NAME)); return p; } @@ -38,8 +36,7 @@ public class WordCounter { List textList = jet.getList(LIST_NAME); textList.addAll(sentences); Pipeline p = createPipeLine(); - jet.newJob(p) - .join(); + jet.newJob(p).join(); Map counts = jet.getMap(MAP_NAME); count = counts.get(word); } finally { diff --git a/hazelcast/src/test/java/com/baeldung/hazelcast/jet/WordCounterUnitTest.java b/hazelcast/src/test/java/com/baeldung/hazelcast/jet/WordCounterUnitTest.java index 95596b3860..7a60cd9a01 100644 --- a/hazelcast/src/test/java/com/baeldung/hazelcast/jet/WordCounterUnitTest.java +++ b/hazelcast/src/test/java/com/baeldung/hazelcast/jet/WordCounterUnitTest.java @@ -1,11 +1,11 @@ package com.baeldung.hazelcast.jet; -import static org.junit.Assert.assertTrue; +import org.junit.Test; import java.util.ArrayList; import java.util.List; -import org.junit.Test; +import static org.junit.Assert.assertEquals; public class WordCounterUnitTest { @@ -15,7 +15,7 @@ public class WordCounterUnitTest { sentences.add("The first second was alright, but the second second was tough."); WordCounter wordCounter = new WordCounter(); long countSecond = wordCounter.countWord(sentences, "second"); - assertTrue(countSecond == 3); + assertEquals(3, countSecond); } } From 989acd5ed7859c29eb62aabae1255918707a587b Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Wed, 16 Sep 2020 10:11:58 +0200 Subject: [PATCH 11/54] JAVA-2599: Handle Windows specific exception in the ExistenceUnitTest --- .../baeldung/existence/ExistenceUnitTest.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/existence/ExistenceUnitTest.java b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/existence/ExistenceUnitTest.java index c52e46e8c1..747ae85b65 100644 --- a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/existence/ExistenceUnitTest.java +++ b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/existence/ExistenceUnitTest.java @@ -4,10 +4,7 @@ import org.junit.Test; import java.io.File; import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.LinkOption; -import java.nio.file.Path; -import java.nio.file.Paths; +import java.nio.file.*; import java.util.concurrent.ThreadLocalRandom; import static org.junit.Assert.assertFalse; @@ -47,8 +44,18 @@ public class ExistenceUnitTest { public void givenSymbolicLink_whenTargetDoesNotExists_thenFollowOrNotBasedOnTheOptions() throws IOException { Path target = Files.createTempFile("baeldung", "target"); Path symbol = Paths.get("test-link-" + ThreadLocalRandom.current().nextInt()); + Path symbolicLink = null; + + try { + symbolicLink = Files.createSymbolicLink(symbol, target); + } catch (FileSystemException ex) { + System.out.println("Your OS security policy prevents the current user from creating symbolic links.\n" + + "Most probably you're running Windows with UAC.\n" + + "If this is the case, please see - https://docs.microsoft.com/en-us/windows/security/threat-protection/security-policy-settings/create-symbolic-links\n" + + "You must change your security settings to run this test under Windows."); + return; + } - Path symbolicLink = Files.createSymbolicLink(symbol, target); assertTrue(Files.exists(symbolicLink)); assertTrue(Files.isSymbolicLink(symbolicLink)); assertFalse(Files.isSymbolicLink(target)); From 5cc62d43a36a1b484bd99871aebd5d833ee36090 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 16 Sep 2020 22:40:09 +0800 Subject: [PATCH 12/54] Update README.md --- spring-cloud/spring-cloud-consul/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-cloud/spring-cloud-consul/README.md b/spring-cloud/spring-cloud-consul/README.md index 47dc39f0d5..e587572ffa 100644 --- a/spring-cloud/spring-cloud-consul/README.md +++ b/spring-cloud/spring-cloud-consul/README.md @@ -1,3 +1,4 @@ ### Relevant Articles: - [A Quick Guide to Spring Cloud Consul](http://www.baeldung.com/spring-cloud-consul) +- [Leadership Election With Consul](https://www.baeldung.com/consul-leadership-election) From c30abba25f0e1c335c8bfe08aa7c5f9468e0316e Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 16 Sep 2020 22:41:20 +0800 Subject: [PATCH 13/54] Update README.md --- spring-boot-modules/spring-boot-actuator/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-boot-modules/spring-boot-actuator/README.md b/spring-boot-modules/spring-boot-actuator/README.md index 6f31ee4a5e..3e8ef3411b 100644 --- a/spring-boot-modules/spring-boot-actuator/README.md +++ b/spring-boot-modules/spring-boot-actuator/README.md @@ -9,3 +9,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Liveness and Readiness Probes in Spring Boot](https://www.baeldung.com/spring-liveness-readiness-probes) - [Custom Information in Spring Boot Info Endpoint](https://www.baeldung.com/spring-boot-info-actuator-custom) +- [Health Indicators in Spring Boot](https://www.baeldung.com/spring-boot-health-indicators) From 9de2a7e7788418cc4824e6c71a69dde6747b9486 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 16 Sep 2020 22:42:16 +0800 Subject: [PATCH 14/54] Update README.md --- spring-boot-modules/spring-boot-properties-3/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot-modules/spring-boot-properties-3/README.md b/spring-boot-modules/spring-boot-properties-3/README.md index d89f825c86..df272be7f4 100644 --- a/spring-boot-modules/spring-boot-properties-3/README.md +++ b/spring-boot-modules/spring-boot-properties-3/README.md @@ -6,4 +6,4 @@ ### Relevant Articles: - [How to Define a Map in YAML for a POJO?](https://www.baeldung.com/yaml-map-pojo) - +- [Using application.yml vs application.properties in Spring Boot](https://www.baeldung.com/spring-boot-yaml-vs-properties) From 29577bd7773b9a46ed1560c2c12d8f5bf65a2095 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 16 Sep 2020 22:43:16 +0800 Subject: [PATCH 15/54] Update README.md --- core-java-modules/core-java-io-3/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-io-3/README.md b/core-java-modules/core-java-io-3/README.md index 06a2a5a0fc..4b1a14ab3e 100644 --- a/core-java-modules/core-java-io-3/README.md +++ b/core-java-modules/core-java-io-3/README.md @@ -10,4 +10,5 @@ This module contains articles about core Java input and output (IO) - [Copy a Directory in Java](https://www.baeldung.com/java-copy-directory) - [Java Files Open Options](https://www.baeldung.com/java-file-options) - [Creating Temporary Directories in Java](https://www.baeldung.com/java-temp-directories) +- [Reading a Line at a Given Line Number From a File in Java](https://www.baeldung.com/java-read-line-at-number) - [[<-- Prev]](/core-java-modules/core-java-io-2) From 9c64b62ad6227f20286f5cfe15b26db0580a70c6 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 16 Sep 2020 22:44:40 +0800 Subject: [PATCH 16/54] Update README.md --- spring-boot-modules/spring-boot-mvc-3/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-boot-modules/spring-boot-mvc-3/README.md b/spring-boot-modules/spring-boot-mvc-3/README.md index 0562224337..6627bd8eea 100644 --- a/spring-boot-modules/spring-boot-mvc-3/README.md +++ b/spring-boot-modules/spring-boot-mvc-3/README.md @@ -6,4 +6,5 @@ This module contains articles about Spring Web MVC in Spring Boot projects. - [Circular View Path Error](https://www.baeldung.com/spring-circular-view-path-error) - [Download an Image or a File with Spring MVC](https://www.baeldung.com/spring-controller-return-image-file) +- [Spring MVC Async vs Spring WebFlux](https://www.baeldung.com/spring-mvc-async-vs-webflux) - More articles: [[prev -->]](/spring-boot-modules/spring-boot-mvc-2) From ee277ad5db39c020cdc6950068280a8babb94e3e Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 16 Sep 2020 22:44:58 +0800 Subject: [PATCH 17/54] Update README.md --- spring-5-webflux/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-5-webflux/README.md b/spring-5-webflux/README.md index 55ab0b8af4..9f9a12f997 100644 --- a/spring-5-webflux/README.md +++ b/spring-5-webflux/README.md @@ -8,3 +8,4 @@ This module contains articles about Spring 5 WebFlux - [How to Return 404 with Spring WebFlux](https://www.baeldung.com/spring-webflux-404) - [Spring WebClient Requests with Parameters](https://www.baeldung.com/webflux-webclient-parameters) - [RSocket Using Spring Boot](https://www.baeldung.com/spring-boot-rsocket) +- [Spring MVC Async vs Spring WebFlux](https://www.baeldung.com/spring-mvc-async-vs-webflux) From 35fb40162c1f110d8d54c7e266e4ffb0f8beedba Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 16 Sep 2020 22:46:47 +0800 Subject: [PATCH 18/54] Update README.md --- spring-rest-http-2/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-rest-http-2/README.md b/spring-rest-http-2/README.md index 74ec59e0b5..97cdc2d068 100644 --- a/spring-rest-http-2/README.md +++ b/spring-rest-http-2/README.md @@ -7,4 +7,4 @@ The "REST With Spring 2" Classes: http://bit.ly/restwithspring ### Relevant Articles: - +- [How to Turn Off Swagger-ui in Production](https://www.baeldung.com/swagger-ui-turn-off-in-production) From 647b0e9171155402037e7d07c5b5327224d5db31 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 16 Sep 2020 22:47:55 +0800 Subject: [PATCH 19/54] Update README.md --- libraries-testing/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries-testing/README.md b/libraries-testing/README.md index 43d7673e2d..447f3f32b9 100644 --- a/libraries-testing/README.md +++ b/libraries-testing/README.md @@ -12,3 +12,4 @@ This module contains articles about test libraries. - [Introduction to Hoverfly in Java](https://www.baeldung.com/hoverfly) - [Testing with Hamcrest](https://www.baeldung.com/java-junit-hamcrest-guide) - [Introduction To DBUnit](https://www.baeldung.com/java-dbunit) +- [Introduction to ArchUnit](https://www.baeldung.com/java-archunit-intro) From c79db10648fc596c485ec4abe62d0eb887967371 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 16 Sep 2020 22:51:52 +0800 Subject: [PATCH 20/54] Update README.md --- core-java-modules/core-java-lang-math-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-lang-math-2/README.md b/core-java-modules/core-java-lang-math-2/README.md index 09039f6ed0..69ee00b5a5 100644 --- a/core-java-modules/core-java-lang-math-2/README.md +++ b/core-java-modules/core-java-lang-math-2/README.md @@ -13,4 +13,5 @@ - [Convert Latitude and Longitude to a 2D Point in Java](https://www.baeldung.com/java-convert-latitude-longitude) - [Debugging with Eclipse](https://www.baeldung.com/eclipse-debugging) - [Matrix Multiplication in Java](https://www.baeldung.com/java-matrix-multiplication) +- [Largest Power of 2 That Is Less Than the Given Number](https://www.baeldung.com/java-largest-power-of-2-less-than-number) - More articles: [[<-- Prev]](/core-java-modules/core-java-lang-math) From c221c2fa0bdd2526e64e7773c5eac637909abccc Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 16 Sep 2020 22:52:52 +0800 Subject: [PATCH 21/54] Update README.md --- core-java-modules/core-java-exceptions-3/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-exceptions-3/README.md b/core-java-modules/core-java-exceptions-3/README.md index e6c7eda881..1b2db24bdc 100644 --- a/core-java-modules/core-java-exceptions-3/README.md +++ b/core-java-modules/core-java-exceptions-3/README.md @@ -1,3 +1,4 @@ ### Relevant Articles: - [NoSuchMethodError in Java](https://www.baeldung.com/java-nosuchmethod-error) +- [IllegalArgumentException or NullPointerException for a Null Parameter?](https://www.baeldung.com/java-illegalargumentexception-or-nullpointerexception) From ede8e77f7ab04f42ee0dec9c5e6a873615141967 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 16 Sep 2020 22:53:49 +0800 Subject: [PATCH 22/54] Update README.md --- quarkus/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/quarkus/README.md b/quarkus/README.md index 3ff08c6f9e..94b71dd954 100644 --- a/quarkus/README.md +++ b/quarkus/README.md @@ -1,3 +1,4 @@ ## Relevant Articles: - [Guide to QuarkusIO](https://www.baeldung.com/quarkus-io) +- [Testing Quarkus Applications](https://www.baeldung.com/java-quarkus-testing) From a6f195dab69b21df2b5e131978811f131c178430 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 16 Sep 2020 22:55:08 +0800 Subject: [PATCH 23/54] Create README.md --- gradle-5/source-sets/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 gradle-5/source-sets/README.md diff --git a/gradle-5/source-sets/README.md b/gradle-5/source-sets/README.md new file mode 100644 index 0000000000..19fe1e1fae --- /dev/null +++ b/gradle-5/source-sets/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + +- [Gradle Source Sets](https://www.baeldung.com/gradle-source-sets) From 258f1be8ac1028d3d9c76530e3ca894ad1dcc0e8 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 16 Sep 2020 22:56:33 +0800 Subject: [PATCH 24/54] Update README.md --- core-java-modules/core-java-arrays-guides/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-arrays-guides/README.md b/core-java-modules/core-java-arrays-guides/README.md index 621443e4a9..934833b31b 100644 --- a/core-java-modules/core-java-arrays-guides/README.md +++ b/core-java-modules/core-java-arrays-guides/README.md @@ -6,3 +6,4 @@ This module contains complete guides about arrays in Java - [Arrays in Java: A Reference Guide](https://www.baeldung.com/java-arrays-guide) - [Guide to the java.util.Arrays Class](https://www.baeldung.com/java-util-arrays) - [What is \[Ljava.lang.Object;?](https://www.baeldung.com/java-tostring-array) +- [Guide to ArrayStoreException](https://www.baeldung.com/java-arraystoreexception) From 1d9cf597d8bbf31bc11f6fda449b3bc410e60414 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 16 Sep 2020 22:57:59 +0800 Subject: [PATCH 25/54] Update README.md --- testing-modules/testing-assertions/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/testing-modules/testing-assertions/README.md b/testing-modules/testing-assertions/README.md index 08e2e66062..ea238af599 100644 --- a/testing-modules/testing-assertions/README.md +++ b/testing-modules/testing-assertions/README.md @@ -1,3 +1,4 @@ ### Relevant Articles: - [Asserting Log Messages With JUnit](https://www.baeldung.com/junit-asserting-logs) +- [Assert Two Lists for Equality Ignoring Order in Java](https://www.baeldung.com/java-assert-lists-equality-ignore-order) From d04fadfb9bc2bcadaa1a96b2a932f6b5ae5cd95a Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 16 Sep 2020 22:59:27 +0800 Subject: [PATCH 26/54] Update README.md --- spring-boot-modules/spring-boot-autoconfiguration/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spring-boot-modules/spring-boot-autoconfiguration/README.md b/spring-boot-modules/spring-boot-autoconfiguration/README.md index d1b5fde7ed..881c88467b 100644 --- a/spring-boot-modules/spring-boot-autoconfiguration/README.md +++ b/spring-boot-modules/spring-boot-autoconfiguration/README.md @@ -10,4 +10,5 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Create a Custom Auto-Configuration with Spring Boot](https://www.baeldung.com/spring-boot-custom-auto-configuration) - [Guide to ApplicationContextRunner in Spring Boot](https://www.baeldung.com/spring-boot-context-runner) - [A Guide to Spring Boot Configuration Metadata](https://www.baeldung.com/spring-boot-configuration-metadata) -- [Display Auto-Configuration Report in Spring Boot](https://www.baeldung.com/spring-boot-auto-configuration-report) \ No newline at end of file +- [Display Auto-Configuration Report in Spring Boot](https://www.baeldung.com/spring-boot-auto-configuration-report) +- [The Spring @ConditionalOnProperty Annotation](https://www.baeldung.com/spring-conditionalonproperty) From f9cd2c38078c720a8229d7a9b2b22ae61b18fc33 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 16 Sep 2020 23:01:10 +0800 Subject: [PATCH 27/54] Update README.md --- testing-modules/spring-testing-2/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/testing-modules/spring-testing-2/README.md b/testing-modules/spring-testing-2/README.md index 729105e3fd..702a02ff27 100644 --- a/testing-modules/spring-testing-2/README.md +++ b/testing-modules/spring-testing-2/README.md @@ -1 +1,3 @@ ## Relevant Articles: + +- [Guide to @DynamicPropertySource in Spring](https://www.baeldung.com/spring-dynamicpropertysource) From 459dc06432a68423cb2f9685110c0864180095f0 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 16 Sep 2020 23:34:14 +0800 Subject: [PATCH 28/54] Update README.md --- spring-thymeleaf-3/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-thymeleaf-3/README.md b/spring-thymeleaf-3/README.md index 34bd1b4b35..8bb8861daf 100644 --- a/spring-thymeleaf-3/README.md +++ b/spring-thymeleaf-3/README.md @@ -8,3 +8,4 @@ This module contains articles about Spring with Thymeleaf - [Formatting Currencies in Spring Using Thymeleaf](https://www.baeldung.com/spring-thymeleaf-currencies) - [Working with Select and Option in Thymeleaf](https://www.baeldung.com/thymeleaf-select-option) - [Conditional CSS Classes in Thymeleaf](https://www.baeldung.com/spring-mvc-thymeleaf-conditional-css-classes) +- [Using Hidden Inputs with Spring and Thymeleaf](https://www.baeldung.com/spring-thymeleaf-hidden-inputs) From b7ec39842bd155d4c1f94b9111e1050b94387981 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 16 Sep 2020 23:37:50 +0800 Subject: [PATCH 29/54] Create README.md --- spring-boot-modules/spring-boot-swagger/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 spring-boot-modules/spring-boot-swagger/README.md diff --git a/spring-boot-modules/spring-boot-swagger/README.md b/spring-boot-modules/spring-boot-swagger/README.md new file mode 100644 index 0000000000..1038031210 --- /dev/null +++ b/spring-boot-modules/spring-boot-swagger/README.md @@ -0,0 +1,3 @@ +## Relevant Articles: + +- [Hiding Endpoints From Swagger Documentation in Spring Boot](https://www.baeldung.com/spring-swagger-hiding-endpoints) From 35c25daa18843cd16a81bcc9c3282408fb6db419 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 16 Sep 2020 23:39:49 +0800 Subject: [PATCH 30/54] Update README.md --- spring-boot-modules/spring-boot-keycloak/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-boot-modules/spring-boot-keycloak/README.md b/spring-boot-modules/spring-boot-keycloak/README.md index 2dfe3fc331..74fbbb6f09 100644 --- a/spring-boot-modules/spring-boot-keycloak/README.md +++ b/spring-boot-modules/spring-boot-keycloak/README.md @@ -4,3 +4,4 @@ This module contains articles about Keycloak in Spring Boot projects. ## Relevant articles: - [A Quick Guide to Using Keycloak with Spring Boot](https://www.baeldung.com/spring-boot-keycloak) +- [Custom User Attributes with Keycloak](https://www.baeldung.com/keycloak-custom-user-attributes) From 5c0391cf68d07994ed35d86441e9de893c6e7ddb Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 16 Sep 2020 23:42:36 +0800 Subject: [PATCH 31/54] Update README.md --- core-java-modules/core-java-exceptions-3/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-exceptions-3/README.md b/core-java-modules/core-java-exceptions-3/README.md index 1b2db24bdc..4e3dd22bb8 100644 --- a/core-java-modules/core-java-exceptions-3/README.md +++ b/core-java-modules/core-java-exceptions-3/README.md @@ -2,3 +2,4 @@ - [NoSuchMethodError in Java](https://www.baeldung.com/java-nosuchmethod-error) - [IllegalArgumentException or NullPointerException for a Null Parameter?](https://www.baeldung.com/java-illegalargumentexception-or-nullpointerexception) +- [IllegalMonitorStateException in Java](https://www.baeldung.com/java-illegalmonitorstateexception) From 4d84d35754ae4d9e30911fd0ceb8e06f81310863 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 16 Sep 2020 23:44:29 +0800 Subject: [PATCH 32/54] Update README.md --- spring-rest-http/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-rest-http/README.md b/spring-rest-http/README.md index bb4cfd829d..2271858f0a 100644 --- a/spring-rest-http/README.md +++ b/spring-rest-http/README.md @@ -14,3 +14,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Guide to DeferredResult in Spring](https://www.baeldung.com/spring-deferred-result) - [Using JSON Patch in Spring REST APIs](https://www.baeldung.com/spring-rest-json-patch) - [OpenAPI JSON Objects as Query Parameters](https://www.baeldung.com/openapi-json-query-parameters) +- [Dates in OpenAPI Files](https://www.baeldung.com/openapi-dates) From 1cf9a48f688f4f13f0a38b2708896a0754329c1c Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 16 Sep 2020 23:45:40 +0800 Subject: [PATCH 33/54] Update README.MD --- persistence-modules/flyway/README.MD | 1 + 1 file changed, 1 insertion(+) diff --git a/persistence-modules/flyway/README.MD b/persistence-modules/flyway/README.MD index daeb9012b5..bd5f9bbe03 100644 --- a/persistence-modules/flyway/README.MD +++ b/persistence-modules/flyway/README.MD @@ -1,3 +1,4 @@ ### Relevant Articles: - [Database Migrations with Flyway](http://www.baeldung.com/database-migrations-with-flyway) - [A Guide to Flyway Callbacks](http://www.baeldung.com/flyway-callbacks) +- [Rolling Back Migrations with Flyway](https://www.baeldung.com/flyway-roll-back) From ce9e9a605e453609a9d6db9447d7335b6d9026b1 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 16 Sep 2020 23:47:15 +0800 Subject: [PATCH 34/54] Update README.md --- libraries-security/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries-security/README.md b/libraries-security/README.md index 5ec85a15e9..1a0e16a776 100644 --- a/libraries-security/README.md +++ b/libraries-security/README.md @@ -11,3 +11,4 @@ This module contains articles about security libraries. - [Intro to Jasypt](https://www.baeldung.com/jasypt) - [Digital Signatures in Java](https://www.baeldung.com/java-digital-signature) - [How to Read PEM File to Get Public and Private Keys](https://www.baeldung.com/java-read-pem-file-keys) +- [SSH Connection With Java](https://www.baeldung.com/java-ssh-connection) From 5ae7a913cf4c9879a5ce8ba9b1f112c2f029da34 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 16 Sep 2020 23:48:50 +0800 Subject: [PATCH 35/54] Update README.md --- testing-modules/mockito-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/testing-modules/mockito-2/README.md b/testing-modules/mockito-2/README.md index 9ca5a38e2e..c7b62182b5 100644 --- a/testing-modules/mockito-2/README.md +++ b/testing-modules/mockito-2/README.md @@ -8,3 +8,4 @@ - [Introduction to Mockito’s AdditionalAnswers](https://www.baeldung.com/mockito-additionalanswers) - [Mockito – Using Spies](https://www.baeldung.com/mockito-spy) - [Using Mockito ArgumentCaptor](https://www.baeldung.com/mockito-argumentcaptor) +- [Difference Between when() and doXxx() Methods in Mockito](https://www.baeldung.com/java-mockito-when-vs-do) From fce5fac0c44524d321b4bb8d37c74fb1b32762ae Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 16 Sep 2020 23:50:34 +0800 Subject: [PATCH 36/54] Update README.md --- patterns/design-patterns-architectural/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/patterns/design-patterns-architectural/README.md b/patterns/design-patterns-architectural/README.md index fbe4221752..5b6011c159 100644 --- a/patterns/design-patterns-architectural/README.md +++ b/patterns/design-patterns-architectural/README.md @@ -1,3 +1,4 @@ ### Relevant Articles: - [Service Locator Pattern](https://www.baeldung.com/java-service-locator-pattern) - [The DAO Pattern in Java](https://www.baeldung.com/java-dao-pattern) +- [DAO vs Repository Patterns](https://www.baeldung.com/java-dao-vs-repository) From d5ada37cc7d1c04175fe4e5ce8489186ed79b2c3 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 16 Sep 2020 23:54:01 +0800 Subject: [PATCH 37/54] Update README.md --- aws-lambda/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/aws-lambda/README.md b/aws-lambda/README.md index 2fbdaace10..759c9dd506 100644 --- a/aws-lambda/README.md +++ b/aws-lambda/README.md @@ -5,3 +5,4 @@ This module contains articles about AWS Lambda ### Relevant Articles: - [Using AWS Lambda with API Gateway](https://www.baeldung.com/aws-lambda-api-gateway) - [Introduction to AWS Serverless Application Model](https://www.baeldung.com/aws-serverless) +- [How to Implement Hibernate in an AWS Lambda Function in Java](https://www.baeldung.com/java-aws-lambda-hibernate) From d30ba2c8f04284063ddec1e74b75b6c84d091d3e Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 16 Sep 2020 23:55:27 +0800 Subject: [PATCH 38/54] Create README.md --- gradle-5/cmd-line-args/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 gradle-5/cmd-line-args/README.md diff --git a/gradle-5/cmd-line-args/README.md b/gradle-5/cmd-line-args/README.md new file mode 100644 index 0000000000..de797c8588 --- /dev/null +++ b/gradle-5/cmd-line-args/README.md @@ -0,0 +1,3 @@ +## Relevant Articles: + +- [Passing Command Line Arguments in Gradle](https://www.baeldung.com/gradle-command-line-arguments) From a61f3c9b54907b8024d5f837179d951306699181 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 16 Sep 2020 23:56:46 +0800 Subject: [PATCH 39/54] Update README.md --- core-java-modules/core-java-lang-3/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-lang-3/README.md b/core-java-modules/core-java-lang-3/README.md index 0fa08ef397..121d30f20f 100644 --- a/core-java-modules/core-java-lang-3/README.md +++ b/core-java-modules/core-java-lang-3/README.md @@ -5,4 +5,5 @@ This module contains articles about core features in the Java language - [Class.isInstance vs Class.isAssignableFrom](https://www.baeldung.com/java-isinstance-isassignablefrom) - [Converting a Java String Into a Boolean](https://www.baeldung.com/java-string-to-boolean) - [When are Static Variables Initialized in Java?](https://www.baeldung.com/java-static-variables-initialization) +- [Checking if a Class Exists in Java](https://www.baeldung.com/java-check-class-exists) - [[<-- Prev]](/core-java-modules/core-java-lang-2) From 2cc967c01c535e59b42cf7f939fa2eed7bab878f Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 17 Sep 2020 00:09:56 +0800 Subject: [PATCH 40/54] Update README.md --- core-kotlin-modules/core-kotlin-collections-2/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core-kotlin-modules/core-kotlin-collections-2/README.md b/core-kotlin-modules/core-kotlin-collections-2/README.md index 2dc180b5b3..64062ee704 100644 --- a/core-kotlin-modules/core-kotlin-collections-2/README.md +++ b/core-kotlin-modules/core-kotlin-collections-2/README.md @@ -2,6 +2,6 @@ This module contains articles about core Kotlin collections. -### Relevant articles: - +## Relevant articles: +- [Aggregate Operations in Kotlin](https://www.baeldung.com/kotlin/aggregate-operations) From 8928164d224ca352b6db2a87e5bc092d9d86a62f Mon Sep 17 00:00:00 2001 From: kwoyke Date: Wed, 16 Sep 2020 20:53:28 +0200 Subject: [PATCH 41/54] BAEL-4595: Update hazelcast.xml config file (#10039) * BAEL-4595: Upgrade to hazelcast-jet 4.2 * BAEL-4595: Update hazelcast.xml config file --- hazelcast/src/main/resources/hazelcast.xml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/hazelcast/src/main/resources/hazelcast.xml b/hazelcast/src/main/resources/hazelcast.xml index f29dc532b8..889e65801b 100644 --- a/hazelcast/src/main/resources/hazelcast.xml +++ b/hazelcast/src/main/resources/hazelcast.xml @@ -1,16 +1,16 @@ - + 5701 - - - - machine1 - localhost - + + + machine1 + localhost + \ No newline at end of file From 4ce6b34c063d33a52ec7695c2d9e321403b24833 Mon Sep 17 00:00:00 2001 From: Kai Yuan Date: Fri, 11 Sep 2020 01:08:12 +0200 Subject: [PATCH 42/54] [BAEL-4583] Improvement- Java Period --- .../com/baeldung/date/DateDiffUnitTest.java | 63 +++++++++++++------ 1 file changed, 43 insertions(+), 20 deletions(-) diff --git a/core-java-modules/core-java-date-operations-1/src/test/java/com/baeldung/date/DateDiffUnitTest.java b/core-java-modules/core-java-date-operations-1/src/test/java/com/baeldung/date/DateDiffUnitTest.java index 226556d4bb..9a0779ccac 100644 --- a/core-java-modules/core-java-date-operations-1/src/test/java/com/baeldung/date/DateDiffUnitTest.java +++ b/core-java-modules/core-java-date-operations-1/src/test/java/com/baeldung/date/DateDiffUnitTest.java @@ -1,6 +1,8 @@ package com.baeldung.date; -import static org.junit.Assert.assertEquals; +import org.joda.time.Days; +import org.joda.time.Minutes; +import org.junit.Test; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -16,7 +18,7 @@ import java.util.Locale; import java.util.TimeZone; import java.util.concurrent.TimeUnit; -import org.junit.Test; +import static org.junit.Assert.*; public class DateDiffUnitTest { @@ -29,18 +31,39 @@ public class DateDiffUnitTest { long diffInMillies = Math.abs(secondDate.getTime() - firstDate.getTime()); long diff = TimeUnit.DAYS.convert(diffInMillies, TimeUnit.MILLISECONDS); - assertEquals(diff, 6); + assertEquals(6, diff); } @Test - public void givenTwoDatesInJava8_whenDifferentiating_thenWeGetSix() { - LocalDate now = LocalDate.now(); - LocalDate sixDaysBehind = now.minusDays(6); + public void givenTwoDatesInJava8_whenUsingPeriodGetDays_thenWorks() { + LocalDate aDate = LocalDate.of(2020, 9, 11); + LocalDate sixDaysBehind = aDate.minusDays(6); - Period period = Period.between(now, sixDaysBehind); + Period period = Period.between(aDate, sixDaysBehind); int diff = Math.abs(period.getDays()); - assertEquals(diff, 6); + assertEquals(6, diff); + } + + @Test + public void givenTwoDatesInJava8_whenUsingPeriodGetDays_thenDoesNotWork() { + LocalDate aDate = LocalDate.of(2020, 9, 11); + LocalDate sixtyDaysBehind = aDate.minusDays(60); + Period period = Period.between(aDate, sixtyDaysBehind); + int diff = Math.abs(period.getDays()); + //not equals + assertNotEquals(60, diff); + } + + @Test + public void givenTwoDatesInJava8_whenUsingPeriod_thenWeGet0Year1Month29Days() { + LocalDate aDate = LocalDate.of(2020, 9, 11); + LocalDate sixtyDaysBehind = aDate.minusDays(60); + Period period = Period.between(aDate, sixtyDaysBehind); + int years = Math.abs(period.getYears()); + int months = Math.abs(period.getMonths()); + int days = Math.abs(period.getDays()); + assertArrayEquals(new int[] { 0, 1, 29 }, new int[] { years, months, days }); } @Test @@ -51,7 +74,7 @@ public class DateDiffUnitTest { Duration duration = Duration.between(now, sixMinutesBehind); long diff = Math.abs(duration.toMinutes()); - assertEquals(diff, 6); + assertEquals(6, diff); } @Test @@ -61,7 +84,7 @@ public class DateDiffUnitTest { long diff = ChronoUnit.SECONDS.between(now, tenSecondsLater); - assertEquals(diff, 10); + assertEquals(10, diff); } @Test @@ -69,9 +92,9 @@ public class DateDiffUnitTest { LocalDateTime ldt = LocalDateTime.now(); ZonedDateTime now = ldt.atZone(ZoneId.of("America/Montreal")); ZonedDateTime sixDaysBehind = now.withZoneSameInstant(ZoneId.of("Asia/Singapore")) - .minusDays(6); + .minusDays(6); long diff = ChronoUnit.DAYS.between(sixDaysBehind, now); - assertEquals(diff, 6); + assertEquals(6, diff); } @Test @@ -81,7 +104,7 @@ public class DateDiffUnitTest { long diff = now.until(tenSecondsLater, ChronoUnit.SECONDS); - assertEquals(diff, 10); + assertEquals(10, diff); } @Test @@ -89,10 +112,9 @@ public class DateDiffUnitTest { org.joda.time.LocalDate now = org.joda.time.LocalDate.now(); org.joda.time.LocalDate sixDaysBehind = now.minusDays(6); - org.joda.time.Period period = new org.joda.time.Period(now, sixDaysBehind); - long diff = Math.abs(period.getDays()); + long diff = Math.abs(Days.daysBetween(now, sixDaysBehind).getDays()); - assertEquals(diff, 6); + assertEquals(6, diff); } @Test @@ -100,8 +122,9 @@ public class DateDiffUnitTest { org.joda.time.LocalDateTime now = org.joda.time.LocalDateTime.now(); org.joda.time.LocalDateTime sixMinutesBehind = now.minusMinutes(6); - org.joda.time.Period period = new org.joda.time.Period(now, sixMinutesBehind); - long diff = Math.abs(period.getDays()); + long diff = Math.abs(Minutes.minutesBetween(now, sixMinutesBehind).getMinutes()); + assertEquals(6, diff); + } @Test @@ -111,6 +134,6 @@ public class DateDiffUnitTest { long diff = Math.abs(now.numDaysFrom(sixDaysBehind)); - assertEquals(diff, 6); + assertEquals(6, diff); } -} \ No newline at end of file +} From 1509fa5ddc5b26a9148ec3a7476c2ebee2b353db Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Wed, 16 Sep 2020 22:20:32 +0200 Subject: [PATCH 43/54] JAVA-2904: Fix README.MD files extension --- core-java-modules/core-java-reflection/{README.MD => README.md} | 0 core-java-modules/pre-jpms/{README.MD => README.md} | 0 drools/{README.MD => README.md} | 0 libraries-primitive/{README.MD => README.md} | 0 persistence-modules/flyway-repair/{README.MD => README.md} | 0 persistence-modules/flyway/{README.MD => README.md} | 0 .../spring-boot-persistence/{README.MD => README.md} | 0 persistence-modules/spring-data-dynamodb/{README.MD => README.md} | 0 raml/{README.MD => README.md} | 0 spring-boot-modules/spring-boot-client/{README.MD => README.md} | 0 .../spring-boot-exceptions/{README.MD => README.md} | 0 spring-cloud-data-flow/apache-spark-job/{README.MD => README.md} | 0 spring-cloud-data-flow/batch-job/{README.MD => README.md} | 0 .../spring-cloud-data-flow-etl/{README.MD => README.md} | 0 .../{README.MD => README.md} | 0 spring-cloud/spring-cloud-functions/{README.MD => README.md} | 0 spring-cloud/spring-cloud-hystrix/{README.MD => README.md} | 0 17 files changed, 0 insertions(+), 0 deletions(-) rename core-java-modules/core-java-reflection/{README.MD => README.md} (100%) rename core-java-modules/pre-jpms/{README.MD => README.md} (100%) rename drools/{README.MD => README.md} (100%) rename libraries-primitive/{README.MD => README.md} (100%) rename persistence-modules/flyway-repair/{README.MD => README.md} (100%) rename persistence-modules/flyway/{README.MD => README.md} (100%) rename persistence-modules/spring-boot-persistence/{README.MD => README.md} (100%) rename persistence-modules/spring-data-dynamodb/{README.MD => README.md} (100%) rename raml/{README.MD => README.md} (100%) rename spring-boot-modules/spring-boot-client/{README.MD => README.md} (100%) rename spring-boot-modules/spring-boot-exceptions/{README.MD => README.md} (100%) rename spring-cloud-data-flow/apache-spark-job/{README.MD => README.md} (100%) rename spring-cloud-data-flow/batch-job/{README.MD => README.md} (100%) rename spring-cloud-data-flow/spring-cloud-data-flow-etl/{README.MD => README.md} (100%) rename spring-cloud-data-flow/spring-cloud-data-flow-stream-processing/{README.MD => README.md} (100%) rename spring-cloud/spring-cloud-functions/{README.MD => README.md} (100%) rename spring-cloud/spring-cloud-hystrix/{README.MD => README.md} (100%) diff --git a/core-java-modules/core-java-reflection/README.MD b/core-java-modules/core-java-reflection/README.md similarity index 100% rename from core-java-modules/core-java-reflection/README.MD rename to core-java-modules/core-java-reflection/README.md diff --git a/core-java-modules/pre-jpms/README.MD b/core-java-modules/pre-jpms/README.md similarity index 100% rename from core-java-modules/pre-jpms/README.MD rename to core-java-modules/pre-jpms/README.md diff --git a/drools/README.MD b/drools/README.md similarity index 100% rename from drools/README.MD rename to drools/README.md diff --git a/libraries-primitive/README.MD b/libraries-primitive/README.md similarity index 100% rename from libraries-primitive/README.MD rename to libraries-primitive/README.md diff --git a/persistence-modules/flyway-repair/README.MD b/persistence-modules/flyway-repair/README.md similarity index 100% rename from persistence-modules/flyway-repair/README.MD rename to persistence-modules/flyway-repair/README.md diff --git a/persistence-modules/flyway/README.MD b/persistence-modules/flyway/README.md similarity index 100% rename from persistence-modules/flyway/README.MD rename to persistence-modules/flyway/README.md diff --git a/persistence-modules/spring-boot-persistence/README.MD b/persistence-modules/spring-boot-persistence/README.md similarity index 100% rename from persistence-modules/spring-boot-persistence/README.MD rename to persistence-modules/spring-boot-persistence/README.md diff --git a/persistence-modules/spring-data-dynamodb/README.MD b/persistence-modules/spring-data-dynamodb/README.md similarity index 100% rename from persistence-modules/spring-data-dynamodb/README.MD rename to persistence-modules/spring-data-dynamodb/README.md diff --git a/raml/README.MD b/raml/README.md similarity index 100% rename from raml/README.MD rename to raml/README.md diff --git a/spring-boot-modules/spring-boot-client/README.MD b/spring-boot-modules/spring-boot-client/README.md similarity index 100% rename from spring-boot-modules/spring-boot-client/README.MD rename to spring-boot-modules/spring-boot-client/README.md diff --git a/spring-boot-modules/spring-boot-exceptions/README.MD b/spring-boot-modules/spring-boot-exceptions/README.md similarity index 100% rename from spring-boot-modules/spring-boot-exceptions/README.MD rename to spring-boot-modules/spring-boot-exceptions/README.md diff --git a/spring-cloud-data-flow/apache-spark-job/README.MD b/spring-cloud-data-flow/apache-spark-job/README.md similarity index 100% rename from spring-cloud-data-flow/apache-spark-job/README.MD rename to spring-cloud-data-flow/apache-spark-job/README.md diff --git a/spring-cloud-data-flow/batch-job/README.MD b/spring-cloud-data-flow/batch-job/README.md similarity index 100% rename from spring-cloud-data-flow/batch-job/README.MD rename to spring-cloud-data-flow/batch-job/README.md diff --git a/spring-cloud-data-flow/spring-cloud-data-flow-etl/README.MD b/spring-cloud-data-flow/spring-cloud-data-flow-etl/README.md similarity index 100% rename from spring-cloud-data-flow/spring-cloud-data-flow-etl/README.MD rename to spring-cloud-data-flow/spring-cloud-data-flow-etl/README.md diff --git a/spring-cloud-data-flow/spring-cloud-data-flow-stream-processing/README.MD b/spring-cloud-data-flow/spring-cloud-data-flow-stream-processing/README.md similarity index 100% rename from spring-cloud-data-flow/spring-cloud-data-flow-stream-processing/README.MD rename to spring-cloud-data-flow/spring-cloud-data-flow-stream-processing/README.md diff --git a/spring-cloud/spring-cloud-functions/README.MD b/spring-cloud/spring-cloud-functions/README.md similarity index 100% rename from spring-cloud/spring-cloud-functions/README.MD rename to spring-cloud/spring-cloud-functions/README.md diff --git a/spring-cloud/spring-cloud-hystrix/README.MD b/spring-cloud/spring-cloud-hystrix/README.md similarity index 100% rename from spring-cloud/spring-cloud-hystrix/README.MD rename to spring-cloud/spring-cloud-hystrix/README.md From 60b28c767bde255195c10c779259b1527a4c6d33 Mon Sep 17 00:00:00 2001 From: nguyennamthai Date: Thu, 17 Sep 2020 09:24:28 +0700 Subject: [PATCH 44/54] BAEL-3569: Jersey RESTful Web Services with Spring Security OAuth2 (#9949) * BAEL-3569 Jersey REST service with Spring Security OAuth * BAEL-3569 Fix indentation spaces --- spring-5-security-oauth/pom.xml | 6 +- .../baeldung/jersey/JerseyApplication.java | 13 ++++ .../com/baeldung/jersey/JerseyResource.java | 30 ++++++++ .../java/com/baeldung/jersey/RestConfig.java | 11 +++ .../com/baeldung/jersey/SecurityConfig.java | 21 ++++++ .../resources/jersey-application.properties | 3 + .../jersey/JerseyResourceUnitTest.java | 72 +++++++++++++++++++ 7 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 spring-5-security-oauth/src/main/java/com/baeldung/jersey/JerseyApplication.java create mode 100644 spring-5-security-oauth/src/main/java/com/baeldung/jersey/JerseyResource.java create mode 100644 spring-5-security-oauth/src/main/java/com/baeldung/jersey/RestConfig.java create mode 100644 spring-5-security-oauth/src/main/java/com/baeldung/jersey/SecurityConfig.java create mode 100644 spring-5-security-oauth/src/main/resources/jersey-application.properties create mode 100644 spring-5-security-oauth/src/test/java/com/baeldung/jersey/JerseyResourceUnitTest.java diff --git a/spring-5-security-oauth/pom.xml b/spring-5-security-oauth/pom.xml index 325aacea86..19aaa576c8 100644 --- a/spring-5-security-oauth/pom.xml +++ b/spring-5-security-oauth/pom.xml @@ -32,6 +32,10 @@ org.thymeleaf.extras thymeleaf-extras-springsecurity5 + + org.springframework.boot + spring-boot-starter-jersey + @@ -63,7 +67,7 @@ test - + com.baeldung.oauth2.SpringOAuthApplication diff --git a/spring-5-security-oauth/src/main/java/com/baeldung/jersey/JerseyApplication.java b/spring-5-security-oauth/src/main/java/com/baeldung/jersey/JerseyApplication.java new file mode 100644 index 0000000000..6388c10bb3 --- /dev/null +++ b/spring-5-security-oauth/src/main/java/com/baeldung/jersey/JerseyApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.jersey; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.PropertySource; + +@SpringBootApplication +@PropertySource("classpath:jersey-application.properties") +public class JerseyApplication { + public static void main(String[] args) { + SpringApplication.run(JerseyApplication.class, args); + } +} diff --git a/spring-5-security-oauth/src/main/java/com/baeldung/jersey/JerseyResource.java b/spring-5-security-oauth/src/main/java/com/baeldung/jersey/JerseyResource.java new file mode 100644 index 0000000000..8968fefbf4 --- /dev/null +++ b/spring-5-security-oauth/src/main/java/com/baeldung/jersey/JerseyResource.java @@ -0,0 +1,30 @@ +package com.baeldung.jersey; + +import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken; +import org.springframework.security.oauth2.core.OAuth2AuthenticatedPrincipal; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.SecurityContext; + +@Path("/") +public class JerseyResource { + @GET + @Path("login") + @Produces(MediaType.TEXT_HTML) + public String login() { + return "Log in with GitHub"; + } + + @GET + @Produces(MediaType.TEXT_PLAIN) + public String home(@Context SecurityContext securityContext) { + OAuth2AuthenticationToken authenticationToken = (OAuth2AuthenticationToken) securityContext.getUserPrincipal(); + OAuth2AuthenticatedPrincipal authenticatedPrincipal = authenticationToken.getPrincipal(); + String userName = authenticatedPrincipal.getAttribute("login"); + return "Hello " + userName; + } +} diff --git a/spring-5-security-oauth/src/main/java/com/baeldung/jersey/RestConfig.java b/spring-5-security-oauth/src/main/java/com/baeldung/jersey/RestConfig.java new file mode 100644 index 0000000000..306677f261 --- /dev/null +++ b/spring-5-security-oauth/src/main/java/com/baeldung/jersey/RestConfig.java @@ -0,0 +1,11 @@ +package com.baeldung.jersey; + +import org.glassfish.jersey.server.ResourceConfig; +import org.springframework.stereotype.Component; + +@Component +public class RestConfig extends ResourceConfig { + public RestConfig() { + register(JerseyResource.class); + } +} diff --git a/spring-5-security-oauth/src/main/java/com/baeldung/jersey/SecurityConfig.java b/spring-5-security-oauth/src/main/java/com/baeldung/jersey/SecurityConfig.java new file mode 100644 index 0000000000..5644856695 --- /dev/null +++ b/spring-5-security-oauth/src/main/java/com/baeldung/jersey/SecurityConfig.java @@ -0,0 +1,21 @@ +package com.baeldung.jersey; + +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; + +@Configuration +public class SecurityConfig extends WebSecurityConfigurerAdapter { + @Override + protected void configure(HttpSecurity http) throws Exception { + http + .authorizeRequests() + .antMatchers("/login") + .permitAll() + .anyRequest() + .authenticated() + .and() + .oauth2Login() + .loginPage("/login"); + } +} diff --git a/spring-5-security-oauth/src/main/resources/jersey-application.properties b/spring-5-security-oauth/src/main/resources/jersey-application.properties new file mode 100644 index 0000000000..516b24eb67 --- /dev/null +++ b/spring-5-security-oauth/src/main/resources/jersey-application.properties @@ -0,0 +1,3 @@ +server.port=8083 +spring.security.oauth2.client.registration.github.client-id= +spring.security.oauth2.client.registration.github.client-secret= \ No newline at end of file diff --git a/spring-5-security-oauth/src/test/java/com/baeldung/jersey/JerseyResourceUnitTest.java b/spring-5-security-oauth/src/test/java/com/baeldung/jersey/JerseyResourceUnitTest.java new file mode 100644 index 0000000000..e6cc3be213 --- /dev/null +++ b/spring-5-security-oauth/src/test/java/com/baeldung/jersey/JerseyResourceUnitTest.java @@ -0,0 +1,72 @@ +package com.baeldung.jersey; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import java.net.URI; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; +import static org.springframework.http.MediaType.TEXT_HTML; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = RANDOM_PORT) +@TestPropertySource(properties = "spring.security.oauth2.client.registration.github.client-id:test-id") +public class JerseyResourceUnitTest { + @Autowired + private TestRestTemplate restTemplate; + + @LocalServerPort + private int port; + + private String basePath; + + @Before + public void setup() { + basePath = "http://localhost:" + port + "/"; + } + + @Test + public void whenUserIsUnauthenticated_thenTheyAreRedirectedToLoginPage() { + ResponseEntity response = restTemplate.getForEntity(basePath, Object.class); + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.FOUND); + assertThat(response.getBody()).isNull(); + + URI redirectLocation = response.getHeaders().getLocation(); + assertThat(redirectLocation).isNotNull(); + assertThat(redirectLocation.toString()).isEqualTo(basePath + "login"); + } + + @Test + public void whenUserAttemptsToLogin_thenAuthorizationPathIsReturned() { + ResponseEntity response = restTemplate.getForEntity(basePath + "login", String.class); + assertThat(response.getHeaders().getContentType()).isEqualTo(TEXT_HTML); + assertThat(response.getBody()).isEqualTo("Log in with GitHub"); + } + + @Test + public void whenUserAccessesAuthorizationEndpoint_thenTheyAresRedirectedToProvider() { + ResponseEntity response = restTemplate.getForEntity(basePath + "oauth2/authorization/github", String.class); + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.FOUND); + assertThat(response.getBody()).isNull(); + + URI redirectLocation = response.getHeaders().getLocation(); + assertThat(redirectLocation).isNotNull(); + assertThat(redirectLocation.getHost()).isEqualTo("github.com"); + assertThat(redirectLocation.getPath()).isEqualTo("/login/oauth/authorize"); + + String redirectionQuery = redirectLocation.getQuery(); + assertThat(redirectionQuery.contains("response_type=code")); + assertThat(redirectionQuery.contains("client_id=test-id")); + assertThat(redirectionQuery.contains("scope=read:user")); + } +} From 15ba49d0f40a7d498cee38829d8b9d97cda178a2 Mon Sep 17 00:00:00 2001 From: Reza Ebrahimpour Date: Thu, 17 Sep 2020 10:25:37 +0430 Subject: [PATCH 45/54] BAEL-4488 Convert class with main to UnitTest class --- .../cipher/AvailableCiphersUnitTest.java} | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) rename core-java-modules/core-java-security-2/src/{main/java/com/baeldung/cipher/AvailableCiphers.java => test/java/com/baeldung/cipher/AvailableCiphersUnitTest.java} (57%) diff --git a/core-java-modules/core-java-security-2/src/main/java/com/baeldung/cipher/AvailableCiphers.java b/core-java-modules/core-java-security-2/src/test/java/com/baeldung/cipher/AvailableCiphersUnitTest.java similarity index 57% rename from core-java-modules/core-java-security-2/src/main/java/com/baeldung/cipher/AvailableCiphers.java rename to core-java-modules/core-java-security-2/src/test/java/com/baeldung/cipher/AvailableCiphersUnitTest.java index f73433ffd2..48aaa5fb67 100644 --- a/core-java-modules/core-java-security-2/src/main/java/com/baeldung/cipher/AvailableCiphers.java +++ b/core-java-modules/core-java-security-2/src/test/java/com/baeldung/cipher/AvailableCiphersUnitTest.java @@ -1,32 +1,35 @@ package com.baeldung.cipher; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.security.Provider; import java.security.Security; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; -public class AvailableCiphers { - public static void main(String[] args) { - printAllCiphers(); - printCompatibleCiphers(); - } +public class AvailableCiphersUnitTest { + private final Logger logger = LoggerFactory.getLogger(AvailableCiphersUnitTest.class); - private static void printAllCiphers() { + @Test + public void whenGetServices_thenGetAllCipherAlgorithms() { for (Provider provider : Security.getProviders()) { for (Provider.Service service : provider.getServices()) { - System.out.println(service.getAlgorithm()); + logger.info(service.getAlgorithm()); } } } - private static void printCompatibleCiphers() { + @Test + public void whenGetServicesWithFilter_thenGetAllCompatibleCipherAlgorithms() { List algorithms = Arrays.stream(Security.getProviders()) .flatMap(provider -> provider.getServices().stream()) .filter(service -> "Cipher".equals(service.getType())) .map(Provider.Service::getAlgorithm) .collect(Collectors.toList()); - algorithms.forEach(System.out::println); + algorithms.forEach(logger::info); } } From 0d3dafd25cce4ce11e248fff89c540685ebcf9bc Mon Sep 17 00:00:00 2001 From: Adrian Maghear Date: Thu, 17 Sep 2020 08:37:41 +0200 Subject: [PATCH 46/54] [BAEL-4471] reduce number of parallel tests --- quarkus/pom.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/quarkus/pom.xml b/quarkus/pom.xml index 67356abdef..7fdf1557fb 100644 --- a/quarkus/pom.xml +++ b/quarkus/pom.xml @@ -99,6 +99,8 @@ maven-surefire-plugin ${surefire-plugin.version} + 1 + true org.jboss.logmanager.LogManager From 6cbf1e87c5282415780c95fdb82ca4b8f48ed857 Mon Sep 17 00:00:00 2001 From: Rutuja Joshi <67615932+rutujavjoshi@users.noreply.github.com> Date: Thu, 17 Sep 2020 22:02:51 +0530 Subject: [PATCH 47/54] BAEL-4201 - Initial Commit (#9957) * BAEL-4201 - Initial commit * BAEL-4201 - Initial Commit * Update UserAccountController.java removed the additional brackets * Update UserAccountValidationTest.java Updated the tests * Bael - 4201 - recommit for github issue fix For 'This commit does not belong to any branch on this repository' - delete and recommitting controller * Bael - 4201 - recommit for github issue fix For 'This commit does not belong to any branch on this repository' - delete and recommitting test * Bael - 4201 - add for github issue fix For 'This commit does not belong to any branch on this repository' - adding controller again * Bael - 4201 - add for github issue fix For 'This commit does not belong to any branch on this repository' - adding test again * BAEL-4201: Initial Commit * Update UserAccountUnitTest.java * BAEL-4201: updated to fix the commit issue * BAEL-4201 - temporary deleting Deleting to fix branch issue * BAEL-4201 - commiting test again * BAEL-4201 Fixing build issues * BAEL-4201 Github commit issue * BAEL-4201 Github commit issue - webapp folder * BAEL-4201 - commiting test after view upload * Bael- 4201 ThymeLeaf related issues * Bael- 4201 ThymeLeaf related issues * Bael- 4201 ThymeLeaf related issues * Bael- 4201 ThymeLeaf related issues - added html * Bael- 4201 ThymeLeaf issue ; updated suffix- html * Bael - 4201 white label issue * Bael - 4201 white label issue * BAEL-4201 : moving html to templates * BAEL-4201 - moving to templates * BAEL-4201 - moving to templates * BAEL-4201 - review related updates * BAEL-4201 - review related updates * BAEL-4201 - review related updates * BAEL-4201 - review related updates * BAEL-4201 - review related updates * BAEL-4201 - review related updates * BAEL-4201 - review related updates * BAEL-4201 - added the spring-boot-starter-validation dependency --- spring-boot-modules/spring-boot-mvc-3/pom.xml | 6 +- .../springvalidation/ServletInitializer.java | 12 +++ .../SpringValidationApplication.java | 13 +++ .../controller/UserAccountController.java | 44 ++++++++++ .../springvalidation/domain/UserAccount.java | 80 +++++++++++++++++++ .../springvalidation/domain/UserAddress.java | 17 ++++ .../interfaces/AdvanceInfo.java | 6 ++ .../interfaces/BasicInfo.java | 6 ++ .../src/main/resources/application.properties | 2 + .../src/main/resources/templates/error.html | 10 +++ .../src/main/resources/templates/success.html | 10 +++ .../springvalidation/UserAccountUnitTest.java | 57 +++++++++++++ 12 files changed, 262 insertions(+), 1 deletion(-) create mode 100644 spring-boot-modules/spring-boot-mvc-3/src/main/java/com/baeldung/springvalidation/ServletInitializer.java create mode 100644 spring-boot-modules/spring-boot-mvc-3/src/main/java/com/baeldung/springvalidation/SpringValidationApplication.java create mode 100644 spring-boot-modules/spring-boot-mvc-3/src/main/java/com/baeldung/springvalidation/controller/UserAccountController.java create mode 100644 spring-boot-modules/spring-boot-mvc-3/src/main/java/com/baeldung/springvalidation/domain/UserAccount.java create mode 100644 spring-boot-modules/spring-boot-mvc-3/src/main/java/com/baeldung/springvalidation/domain/UserAddress.java create mode 100644 spring-boot-modules/spring-boot-mvc-3/src/main/java/com/baeldung/springvalidation/interfaces/AdvanceInfo.java create mode 100644 spring-boot-modules/spring-boot-mvc-3/src/main/java/com/baeldung/springvalidation/interfaces/BasicInfo.java create mode 100644 spring-boot-modules/spring-boot-mvc-3/src/main/resources/application.properties create mode 100644 spring-boot-modules/spring-boot-mvc-3/src/main/resources/templates/error.html create mode 100644 spring-boot-modules/spring-boot-mvc-3/src/main/resources/templates/success.html create mode 100644 spring-boot-modules/spring-boot-mvc-3/src/test/java/com/baeldung/springvalidation/UserAccountUnitTest.java diff --git a/spring-boot-modules/spring-boot-mvc-3/pom.xml b/spring-boot-modules/spring-boot-mvc-3/pom.xml index 31c43461d2..1290b0432f 100644 --- a/spring-boot-modules/spring-boot-mvc-3/pom.xml +++ b/spring-boot-modules/spring-boot-mvc-3/pom.xml @@ -22,6 +22,10 @@ org.springframework.boot spring-boot-starter-web + + org.springframework.boot + spring-boot-starter-validation + org.springframework.boot spring-boot-starter-thymeleaf @@ -37,4 +41,4 @@ 2.7 - \ No newline at end of file + diff --git a/spring-boot-modules/spring-boot-mvc-3/src/main/java/com/baeldung/springvalidation/ServletInitializer.java b/spring-boot-modules/spring-boot-mvc-3/src/main/java/com/baeldung/springvalidation/ServletInitializer.java new file mode 100644 index 0000000000..f365582999 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-3/src/main/java/com/baeldung/springvalidation/ServletInitializer.java @@ -0,0 +1,12 @@ +package com.baeldung.springvalidation; + +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; + +public class ServletInitializer extends SpringBootServletInitializer { + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(SpringValidationApplication.class); + } +} diff --git a/spring-boot-modules/spring-boot-mvc-3/src/main/java/com/baeldung/springvalidation/SpringValidationApplication.java b/spring-boot-modules/spring-boot-mvc-3/src/main/java/com/baeldung/springvalidation/SpringValidationApplication.java new file mode 100644 index 0000000000..ccfe990ce7 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-3/src/main/java/com/baeldung/springvalidation/SpringValidationApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.springvalidation; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SpringValidationApplication { + + public static void main(String[] args) { + SpringApplication.run(SpringValidationApplication.class, args); + } + +} diff --git a/spring-boot-modules/spring-boot-mvc-3/src/main/java/com/baeldung/springvalidation/controller/UserAccountController.java b/spring-boot-modules/spring-boot-mvc-3/src/main/java/com/baeldung/springvalidation/controller/UserAccountController.java new file mode 100644 index 0000000000..48de7b35d0 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-3/src/main/java/com/baeldung/springvalidation/controller/UserAccountController.java @@ -0,0 +1,44 @@ +package com.baeldung.springvalidation.controller; + +import javax.validation.Valid; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.ui.ModelMap; +import org.springframework.validation.BindingResult; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +import com.baeldung.springvalidation.domain.UserAccount; +import com.baeldung.springvalidation.interfaces.BasicInfo; + +@Controller +public class UserAccountController { + + @GetMapping("/getUserForm") + public String showUserForm(Model theModel) { + UserAccount theUser = new UserAccount(); + theModel.addAttribute("useraccount", theUser); + return "userHome"; + } + + @RequestMapping(value = "/saveBasicInfo", method = RequestMethod.POST) + public String saveBasicInfo(@Valid @ModelAttribute("useraccount") UserAccount useraccount, BindingResult result, ModelMap model) { + if (result.hasErrors()) { + return "error"; + } + return "success"; + } + + @RequestMapping(value = "/saveBasicInfoStep1", method = RequestMethod.POST) + public String saveBasicInfoStep1(@Validated(BasicInfo.class) @ModelAttribute("useraccount") UserAccount useraccount, BindingResult result, ModelMap model) { + if (result.hasErrors()) { + return "error"; + } + return "success"; + } + +} diff --git a/spring-boot-modules/spring-boot-mvc-3/src/main/java/com/baeldung/springvalidation/domain/UserAccount.java b/spring-boot-modules/spring-boot-mvc-3/src/main/java/com/baeldung/springvalidation/domain/UserAccount.java new file mode 100644 index 0000000000..fd5437fe5e --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-3/src/main/java/com/baeldung/springvalidation/domain/UserAccount.java @@ -0,0 +1,80 @@ +package com.baeldung.springvalidation.domain; + +import javax.validation.Valid; +import javax.validation.constraints.Min; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; + +import com.baeldung.springvalidation.interfaces.AdvanceInfo; +import com.baeldung.springvalidation.interfaces.BasicInfo; + +public class UserAccount { + + @NotNull(groups = BasicInfo.class) + @Size(min = 4, max = 15, groups = BasicInfo.class) + private String password; + + @NotBlank(groups = BasicInfo.class) + private String name; + + @Min(value = 18, message = "Age should not be less than 18", groups = AdvanceInfo.class) + private int age; + + @NotBlank(groups = AdvanceInfo.class) + private String phone; + + @Valid + @NotNull(groups = AdvanceInfo.class) + private UserAddress useraddress; + + public UserAddress getUseraddress() { + return useraddress; + } + + public void setUseraddress(UserAddress useraddress) { + this.useraddress = useraddress; + } + + public UserAccount() { + + } + + public UserAccount(String email, String password, String name, int age) { + this.password = password; + this.name = name; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + +} diff --git a/spring-boot-modules/spring-boot-mvc-3/src/main/java/com/baeldung/springvalidation/domain/UserAddress.java b/spring-boot-modules/spring-boot-mvc-3/src/main/java/com/baeldung/springvalidation/domain/UserAddress.java new file mode 100644 index 0000000000..9aa9656eed --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-3/src/main/java/com/baeldung/springvalidation/domain/UserAddress.java @@ -0,0 +1,17 @@ +package com.baeldung.springvalidation.domain; + +import javax.validation.constraints.NotBlank; +public class UserAddress { + + @NotBlank + private String countryCode; + + public String getCountryCode() { + return countryCode; + } + + public void setCountryCode(String countryCode) { + this.countryCode = countryCode; + } + +} diff --git a/spring-boot-modules/spring-boot-mvc-3/src/main/java/com/baeldung/springvalidation/interfaces/AdvanceInfo.java b/spring-boot-modules/spring-boot-mvc-3/src/main/java/com/baeldung/springvalidation/interfaces/AdvanceInfo.java new file mode 100644 index 0000000000..dd0c7c69d0 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-3/src/main/java/com/baeldung/springvalidation/interfaces/AdvanceInfo.java @@ -0,0 +1,6 @@ +package com.baeldung.springvalidation.interfaces; + +public interface AdvanceInfo { + // validation group marker interface + +} diff --git a/spring-boot-modules/spring-boot-mvc-3/src/main/java/com/baeldung/springvalidation/interfaces/BasicInfo.java b/spring-boot-modules/spring-boot-mvc-3/src/main/java/com/baeldung/springvalidation/interfaces/BasicInfo.java new file mode 100644 index 0000000000..95d2b5e6a2 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-3/src/main/java/com/baeldung/springvalidation/interfaces/BasicInfo.java @@ -0,0 +1,6 @@ +package com.baeldung.springvalidation.interfaces; + +public interface BasicInfo { + // validation group marker interface + +} diff --git a/spring-boot-modules/spring-boot-mvc-3/src/main/resources/application.properties b/spring-boot-modules/spring-boot-mvc-3/src/main/resources/application.properties new file mode 100644 index 0000000000..89390eaace --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-3/src/main/resources/application.properties @@ -0,0 +1,2 @@ +spring.mvc.view.prefix=/WEB-INF/views/ +spring.mvc.view.suffix=.html diff --git a/spring-boot-modules/spring-boot-mvc-3/src/main/resources/templates/error.html b/spring-boot-modules/spring-boot-mvc-3/src/main/resources/templates/error.html new file mode 100644 index 0000000000..341cc73603 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-3/src/main/resources/templates/error.html @@ -0,0 +1,10 @@ + + + +SpringValidation + + + +

Error!!!

+ + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-mvc-3/src/main/resources/templates/success.html b/spring-boot-modules/spring-boot-mvc-3/src/main/resources/templates/success.html new file mode 100644 index 0000000000..b422152153 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-3/src/main/resources/templates/success.html @@ -0,0 +1,10 @@ + + + +SpringValidation + + + +

SUCCESS!!!

+ + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-mvc-3/src/test/java/com/baeldung/springvalidation/UserAccountUnitTest.java b/spring-boot-modules/spring-boot-mvc-3/src/test/java/com/baeldung/springvalidation/UserAccountUnitTest.java new file mode 100644 index 0000000000..507321bf8e --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-3/src/test/java/com/baeldung/springvalidation/UserAccountUnitTest.java @@ -0,0 +1,57 @@ +package com.baeldung.springvalidation; + +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@AutoConfigureMockMvc +public class UserAccountUnitTest { + + @Autowired + private MockMvc mockMvc; + + @Test + public void givenSaveBasicInfo_whenCorrectInput_thenSuccess() throws Exception { + this.mockMvc.perform(MockMvcRequestBuilders.post("/saveBasicInfo") + .accept(MediaType.TEXT_HTML) + .param("name", "test123") + .param("password", "pass")) + .andExpect(view().name("success")) + .andExpect(status().isOk()) + .andDo(print()); + } + + @Test + public void givenSaveBasicInfoStep1_whenCorrectInput_thenSuccess() throws Exception { + this.mockMvc.perform(MockMvcRequestBuilders.post("/saveBasicInfoStep1") + .accept(MediaType.TEXT_HTML) + .param("name", "test123") + .param("password", "pass")) + .andExpect(view().name("success")) + .andExpect(status().isOk()) + .andDo(print()); + } + + @Test + public void givenSaveBasicInfoStep1_whenIncorrectInput_thenError() throws Exception { + this.mockMvc.perform(MockMvcRequestBuilders.post("/saveBasicInfoStep1") + .accept(MediaType.TEXT_HTML)) + // .param("name", "test123") + // .param("password", "pass")) + .andExpect(model().errorCount(2)) + // .andExpect(view().name("error")) + .andExpect(status().isOk()) + .andDo(print()); + } + +} From 4c39bcd6be91c5da7901d54e0cb4d5227d54da19 Mon Sep 17 00:00:00 2001 From: kwoyke Date: Thu, 17 Sep 2020 19:57:53 +0200 Subject: [PATCH 48/54] BAEL-4610: Add {noop} example security config (#10046) --- ...InMemoryNoOpAuthWebSecurityConfigurer.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 spring-5-security/src/main/java/com/baeldung/inmemory/InMemoryNoOpAuthWebSecurityConfigurer.java diff --git a/spring-5-security/src/main/java/com/baeldung/inmemory/InMemoryNoOpAuthWebSecurityConfigurer.java b/spring-5-security/src/main/java/com/baeldung/inmemory/InMemoryNoOpAuthWebSecurityConfigurer.java new file mode 100644 index 0000000000..4b6494f666 --- /dev/null +++ b/spring-5-security/src/main/java/com/baeldung/inmemory/InMemoryNoOpAuthWebSecurityConfigurer.java @@ -0,0 +1,29 @@ +package com.baeldung.inmemory; + +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; + +//@Configuration +public class InMemoryNoOpAuthWebSecurityConfigurer extends WebSecurityConfigurerAdapter { + + @Override + protected void configure(AuthenticationManagerBuilder auth) throws Exception { + auth.inMemoryAuthentication() + .withUser("spring") + .password("{noop}secret") + .roles("USER"); + } + + @Override + protected void configure(HttpSecurity http) throws Exception { + http.authorizeRequests() + .antMatchers("/private/**") + .authenticated() + .antMatchers("/public/**") + .permitAll() + .and() + .httpBasic(); + } +} From f6adcd0cb3260807a55341744fb87e547432900a Mon Sep 17 00:00:00 2001 From: Jonathan Cook Date: Thu, 17 Sep 2020 23:22:49 +0200 Subject: [PATCH 49/54] BAEL-4437 - System Rules (#10047) Co-authored-by: Jonathan Cook --- testing-modules/pom.xml | 3 +- testing-modules/testing-libraries-2/pom.xml | 43 ++++++++++++++++++ ...ClearSystemPropertiesWithRuleUnitTest.java | 19 ++++++++ .../ProvidesSystemPropertyUnitTest.java | 26 +++++++++++ ...rovidesSystemPropertyWithRuleUnitTest.java | 44 +++++++++++++++++++ .../systemrules/SystemErrPrintlnUnitTest.java | 24 ++++++++++ .../SystemErrPrintlnWithRuleUnitTest.java | 25 +++++++++++ .../systemrules/SystemExitUnitTest.java | 23 ++++++++++ .../SystemExitWithRuleUnitTest.java | 22 ++++++++++ .../systemrules/SystemInUnitTest.java | 27 ++++++++++++ .../systemrules/SystemInWithRuleUnitTest.java | 31 +++++++++++++ .../src/test/resources/test.properties | 2 + 12 files changed, 288 insertions(+), 1 deletion(-) create mode 100644 testing-modules/testing-libraries-2/pom.xml create mode 100644 testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemrules/ClearSystemPropertiesWithRuleUnitTest.java create mode 100644 testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemrules/ProvidesSystemPropertyUnitTest.java create mode 100644 testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemrules/ProvidesSystemPropertyWithRuleUnitTest.java create mode 100644 testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemrules/SystemErrPrintlnUnitTest.java create mode 100644 testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemrules/SystemErrPrintlnWithRuleUnitTest.java create mode 100644 testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemrules/SystemExitUnitTest.java create mode 100644 testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemrules/SystemExitWithRuleUnitTest.java create mode 100644 testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemrules/SystemInUnitTest.java create mode 100644 testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemrules/SystemInWithRuleUnitTest.java create mode 100644 testing-modules/testing-libraries-2/src/test/resources/test.properties diff --git a/testing-modules/pom.xml b/testing-modules/pom.xml index f1d30cd7a1..0416423239 100644 --- a/testing-modules/pom.xml +++ b/testing-modules/pom.xml @@ -41,7 +41,8 @@ junit-5-advanced xmlunit-2 junit-4 - testing-libraries + testing-libraries + testing-libraries-2 powermock diff --git a/testing-modules/testing-libraries-2/pom.xml b/testing-modules/testing-libraries-2/pom.xml new file mode 100644 index 0000000000..282583c882 --- /dev/null +++ b/testing-modules/testing-libraries-2/pom.xml @@ -0,0 +1,43 @@ + + 4.0.0 + testing-libraries-2 + testing-libraries-2 + + + com.baeldung + testing-modules + 1.0.0-SNAPSHOT + + + + + com.github.stefanbirkner + system-rules + ${system-rules.version} + test + + + com.github.stefanbirkner + system-lambda + ${system-lambda.version} + test + + + + + testing-libraries + + + src/test/resources + true + + + + + + 1.19.0 + 1.0.0 + + diff --git a/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemrules/ClearSystemPropertiesWithRuleUnitTest.java b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemrules/ClearSystemPropertiesWithRuleUnitTest.java new file mode 100644 index 0000000000..699b40bad9 --- /dev/null +++ b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemrules/ClearSystemPropertiesWithRuleUnitTest.java @@ -0,0 +1,19 @@ +package com.baeldung.systemrules; + +import static org.junit.Assert.assertNull; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.contrib.java.lang.system.ClearSystemProperties; + +public class ClearSystemPropertiesWithRuleUnitTest { + + @Rule + public final ClearSystemProperties userNameIsClearedRule = new ClearSystemProperties("user.name"); + + @Test + public void givenClearUsernameProperty_whenGetUserName_thenNull() { + assertNull(System.getProperty("user.name")); + } + +} diff --git a/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemrules/ProvidesSystemPropertyUnitTest.java b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemrules/ProvidesSystemPropertyUnitTest.java new file mode 100644 index 0000000000..361a338508 --- /dev/null +++ b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemrules/ProvidesSystemPropertyUnitTest.java @@ -0,0 +1,26 @@ +package com.baeldung.systemrules; + +import static com.github.stefanbirkner.systemlambda.SystemLambda.restoreSystemProperties; +import static org.junit.Assert.assertEquals; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +class ProvidesSystemPropertyUnitTest { + + @BeforeAll + static void setUpBeforeClass() throws Exception { + System.setProperty("log_dir", "/tmp/baeldung/logs"); + } + + @Test + void givenSetSystemProperty_whenGetLogDir_thenLogDirIsProvidedSuccessfully() throws Exception { + restoreSystemProperties(() -> { + System.setProperty("log_dir", "test/resources"); + assertEquals("log_dir should be provided", "test/resources", System.getProperty("log_dir")); + }); + + assertEquals("log_dir should be provided", "/tmp/baeldung/logs", System.getProperty("log_dir")); + } + +} diff --git a/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemrules/ProvidesSystemPropertyWithRuleUnitTest.java b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemrules/ProvidesSystemPropertyWithRuleUnitTest.java new file mode 100644 index 0000000000..3a90592a0d --- /dev/null +++ b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemrules/ProvidesSystemPropertyWithRuleUnitTest.java @@ -0,0 +1,44 @@ +package com.baeldung.systemrules; + +import static org.junit.Assert.assertEquals; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.contrib.java.lang.system.ProvideSystemProperty; + +public class ProvidesSystemPropertyWithRuleUnitTest { + + @Rule + public final ProvideSystemProperty providesSystemPropertyRule = new ProvideSystemProperty("log_dir", "test/resources").and("another_property", "another_value"); + + @Rule + public final ProvideSystemProperty providesSystemPropertyFromFileRule = ProvideSystemProperty.fromResource("/test.properties"); + + @BeforeClass + public static void setUpBeforeClass() { + setLogs(); + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + System.out.println(System.getProperty("log_dir")); + } + + @Test + public void givenProvideSystemProperty_whenGetLogDir_thenLogDirIsProvidedSuccessfully() { + assertEquals("log_dir should be provided", "test/resources", System.getProperty("log_dir")); + } + + @Test + public void givenProvideSystemPropertyFromFile_whenGetName_thenNameIsProvidedSuccessfully() { + assertEquals("name should be provided", "baeldung", System.getProperty("name")); + assertEquals("version should be provided", "1.0", System.getProperty("version")); + } + + private static void setLogs() { + System.setProperty("log_dir", "/tmp/baeldung/logs"); + } + +} diff --git a/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemrules/SystemErrPrintlnUnitTest.java b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemrules/SystemErrPrintlnUnitTest.java new file mode 100644 index 0000000000..3345ddae8a --- /dev/null +++ b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemrules/SystemErrPrintlnUnitTest.java @@ -0,0 +1,24 @@ +package com.baeldung.systemrules; + +import static com.github.stefanbirkner.systemlambda.SystemLambda.tapSystemErr; + +import org.junit.Assert; +import org.junit.jupiter.api.Test; + +class SystemErrPrintlnUnitTest { + + @Test + void givenTapSystemErr_whenInvokePrintln_thenOutputIsReturnedSuccessfully() throws Exception { + + String text = tapSystemErr(() -> { + printError("An error occurred Baeldung Readers!!"); + }); + + Assert.assertEquals("An error occurred Baeldung Readers!!", text.trim()); + } + + private void printError(String output) { + System.err.println(output); + } + +} diff --git a/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemrules/SystemErrPrintlnWithRuleUnitTest.java b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemrules/SystemErrPrintlnWithRuleUnitTest.java new file mode 100644 index 0000000000..7994f91063 --- /dev/null +++ b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemrules/SystemErrPrintlnWithRuleUnitTest.java @@ -0,0 +1,25 @@ +package com.baeldung.systemrules; + +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.contrib.java.lang.system.SystemErrRule; + +public class SystemErrPrintlnWithRuleUnitTest { + + @Rule + public final SystemErrRule systemErrRule = new SystemErrRule().enableLog(); + + @Test + public void givenSystemErrRule_whenInvokePrintln_thenLogSuccess() { + printError("An Error occurred Baeldung Readers!!"); + + Assert.assertEquals("An Error occurred Baeldung Readers!!", systemErrRule.getLog() + .trim()); + } + + private void printError(String output) { + System.err.println(output); + } + +} diff --git a/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemrules/SystemExitUnitTest.java b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemrules/SystemExitUnitTest.java new file mode 100644 index 0000000000..1e2548e714 --- /dev/null +++ b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemrules/SystemExitUnitTest.java @@ -0,0 +1,23 @@ +package com.baeldung.systemrules; + +import static org.junit.Assert.assertEquals; + +import static com.github.stefanbirkner.systemlambda.SystemLambda.catchSystemExit; + +import org.junit.jupiter.api.Test; + +class SystemExitUnitTest { + + @Test + void givenCatchSystemExit_whenAppCallsSystemExit_thenStatusIsReturnedSuccessfully() throws Exception { + int statusCode = catchSystemExit(() -> { + exit(); + }); + assertEquals("status code should be 1:", 1, statusCode); + } + + private void exit() { + System.exit(1); + } + +} diff --git a/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemrules/SystemExitWithRuleUnitTest.java b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemrules/SystemExitWithRuleUnitTest.java new file mode 100644 index 0000000000..471aab1989 --- /dev/null +++ b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemrules/SystemExitWithRuleUnitTest.java @@ -0,0 +1,22 @@ +package com.baeldung.systemrules; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.contrib.java.lang.system.ExpectedSystemExit; + +public class SystemExitWithRuleUnitTest { + + @Rule + public final ExpectedSystemExit exitRule = ExpectedSystemExit.none(); + + @Test + public void givenSystemExitRule_whenAppCallsSystemExit_thenExitRuleWorkssAsExpected() { + exitRule.expectSystemExitWithStatus(1); + exit(); + } + + private void exit() { + System.exit(1); + } + +} diff --git a/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemrules/SystemInUnitTest.java b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemrules/SystemInUnitTest.java new file mode 100644 index 0000000000..96badb59d4 --- /dev/null +++ b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemrules/SystemInUnitTest.java @@ -0,0 +1,27 @@ +package com.baeldung.systemrules; + +import static com.github.stefanbirkner.systemlambda.SystemLambda.withTextFromSystemIn; +import static org.junit.Assert.assertEquals; + +import java.util.Scanner; + +import org.junit.jupiter.api.Test; + +class SystemInUnitTest { + + @Test + void givenTwoNames_whenSystemInMock_thenNamesJoinedTogether() throws Exception { + withTextFromSystemIn("Jonathan", "Cook").execute(() -> { + assertEquals("Names should be concatenated", "Jonathan Cook", getFullname()); + }); + } + + private String getFullname() { + try (Scanner scanner = new Scanner(System.in)) { + String firstName = scanner.next(); + String surname = scanner.next(); + return String.join(" ", firstName, surname); + } + } + +} diff --git a/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemrules/SystemInWithRuleUnitTest.java b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemrules/SystemInWithRuleUnitTest.java new file mode 100644 index 0000000000..5730e2f592 --- /dev/null +++ b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemrules/SystemInWithRuleUnitTest.java @@ -0,0 +1,31 @@ +package com.baeldung.systemrules; + +import static org.junit.Assert.assertEquals; + +import java.util.Scanner; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.contrib.java.lang.system.TextFromStandardInputStream; +import static org.junit.contrib.java.lang.system.TextFromStandardInputStream.emptyStandardInputStream; + +public class SystemInWithRuleUnitTest { + + @Rule + public final TextFromStandardInputStream systemInMock = emptyStandardInputStream(); + + @Test + public void givenTwoNames_whenSystemInMock_thenNamesJoinedTogether() { + systemInMock.provideLines("Jonathan", "Cook"); + assertEquals("Names should be concatenated", "Jonathan Cook", getFullname()); + } + + private String getFullname() { + try (Scanner scanner = new Scanner(System.in)) { + String firstName = scanner.next(); + String surname = scanner.next(); + return String.join(" ", firstName, surname); + } + } + +} diff --git a/testing-modules/testing-libraries-2/src/test/resources/test.properties b/testing-modules/testing-libraries-2/src/test/resources/test.properties new file mode 100644 index 0000000000..144847cdb0 --- /dev/null +++ b/testing-modules/testing-libraries-2/src/test/resources/test.properties @@ -0,0 +1,2 @@ +name=baeldung +version=1.0 \ No newline at end of file From 7c482a8e6f53cead43e8c6addd794159d2bb9f0b Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Fri, 18 Sep 2020 22:40:10 +0200 Subject: [PATCH 50/54] JAVA-2975: Clean up the pom.xml in spring-boot-exceptions --- .../spring-boot-exceptions/pom.xml | 72 +------------------ 1 file changed, 1 insertion(+), 71 deletions(-) diff --git a/spring-boot-modules/spring-boot-exceptions/pom.xml b/spring-boot-modules/spring-boot-exceptions/pom.xml index 4b9d787b61..1bfe8e6751 100644 --- a/spring-boot-modules/spring-boot-exceptions/pom.xml +++ b/spring-boot-modules/spring-boot-exceptions/pom.xml @@ -14,15 +14,7 @@ jar spring-boot-exceptions - Demo project for working with Spring Boot exceptions - - - - org.springframework.boot - spring-boot-starter - ${spring-boot.version} - - + Demo project for working with Spring Boot exceptions spring-boot-exceptions @@ -32,68 +24,6 @@ true - - - - - org.apache.maven.plugins - maven-war-plugin - - - - org.apache.maven.plugins - maven-resources-plugin - - - @ - - false - - - - - - - autoconfiguration - - - - org.apache.maven.plugins - maven-surefire-plugin - - - integration-test - - test - - - - **/*LiveTest.java - **/*IntegrationTest.java - **/*IntTest.java - - - **/AutoconfigurationTest.java - - - - - - - json - - - - - - - - - - - com.baeldung.intro.App - 2.2.3.RELEASE - From bca4b6bca5536884a4586589daeea587b61481dd Mon Sep 17 00:00:00 2001 From: mikr Date: Sat, 19 Sep 2020 13:20:07 +0200 Subject: [PATCH 51/54] Java-82 Update pom with reference to JAVA-2824 for failing tests --- pom.xml | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/pom.xml b/pom.xml index 6d5c810784..c460c080d8 100644 --- a/pom.xml +++ b/pom.xml @@ -1374,23 +1374,23 @@ core-java-modules/core-java-9 core-java-modules/core-java-9-improvements - - + + core-java-modules/core-java-9-streams core-java-modules/core-java-10 - - - - + + + + core-java-modules/core-java-collections-set - - - + + + core-java-modules/core-java-jpms - - + + core-java-modules/multimodulemavenproject - + @@ -1419,23 +1419,23 @@ core-java-modules/core-java-9 core-java-modules/core-java-9-improvements - - + + core-java-modules/core-java-9-streams core-java-modules/core-java-10 - - - - + + + + core-java-modules/core-java-collections-set - - - + + + core-java-modules/core-java-jpms - - + + core-java-modules/multimodulemavenproject - + From 8971f2dca29f863c3929aa69bd1f8b3bff5df20e Mon Sep 17 00:00:00 2001 From: Azhwani <13301425+azhwani@users.noreply.github.com> Date: Sat, 19 Sep 2020 14:52:49 +0100 Subject: [PATCH 52/54] BAEL-4327: JSON Parameters with Spring MVC (#10036) * first commit * update commit Co-authored-by: azhwani <> --- .../jsonparams/config/JsonParamsConfig.java | 36 ++++++++++ .../jsonparams/config/JsonParamsInit.java | 29 ++++++++ .../controller/ProductController.java | 57 +++++++++++++++ .../baeldung/jsonparams/model/Product.java | 37 ++++++++++ .../propertyeditor/ProductEditor.java | 34 +++++++++ .../jsonparams/JsonParamsIntegrationTest.java | 71 +++++++++++++++++++ 6 files changed, 264 insertions(+) create mode 100644 spring-mvc-basics-4/src/main/java/com/baeldung/jsonparams/config/JsonParamsConfig.java create mode 100644 spring-mvc-basics-4/src/main/java/com/baeldung/jsonparams/config/JsonParamsInit.java create mode 100644 spring-mvc-basics-4/src/main/java/com/baeldung/jsonparams/controller/ProductController.java create mode 100644 spring-mvc-basics-4/src/main/java/com/baeldung/jsonparams/model/Product.java create mode 100644 spring-mvc-basics-4/src/main/java/com/baeldung/jsonparams/propertyeditor/ProductEditor.java create mode 100644 spring-mvc-basics-4/src/test/java/com/baeldung/jsonparams/JsonParamsIntegrationTest.java diff --git a/spring-mvc-basics-4/src/main/java/com/baeldung/jsonparams/config/JsonParamsConfig.java b/spring-mvc-basics-4/src/main/java/com/baeldung/jsonparams/config/JsonParamsConfig.java new file mode 100644 index 0000000000..f2049554ab --- /dev/null +++ b/spring-mvc-basics-4/src/main/java/com/baeldung/jsonparams/config/JsonParamsConfig.java @@ -0,0 +1,36 @@ +package com.baeldung.jsonparams.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.ViewResolver; +import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import org.springframework.web.servlet.view.InternalResourceViewResolver; + +import com.fasterxml.jackson.databind.ObjectMapper; + +@Configuration +@EnableWebMvc +@ComponentScan(basePackages = { "com.baeldung.jsonparams" }) +public class JsonParamsConfig implements WebMvcConfigurer { + @Override + public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) { + configurer.enable(); + } + + @Bean + public ViewResolver viewResolver() { + InternalResourceViewResolver bean = new InternalResourceViewResolver(); + bean.setPrefix("/WEB-INF/"); + bean.setSuffix(".jsp"); + return bean; + } + + @Bean + public ObjectMapper objectMapper() { + return new ObjectMapper(); + } + +} diff --git a/spring-mvc-basics-4/src/main/java/com/baeldung/jsonparams/config/JsonParamsInit.java b/spring-mvc-basics-4/src/main/java/com/baeldung/jsonparams/config/JsonParamsInit.java new file mode 100644 index 0000000000..6db2a92350 --- /dev/null +++ b/spring-mvc-basics-4/src/main/java/com/baeldung/jsonparams/config/JsonParamsInit.java @@ -0,0 +1,29 @@ +package com.baeldung.jsonparams.config; + +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.ServletRegistration; + +import org.springframework.web.context.ContextLoaderListener; +import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; +import org.springframework.web.servlet.DispatcherServlet; + +public class JsonParamsInit // implements WebApplicationInitializer +{ + + //uncomment to run the product controller example + //@Override + public void onStartup(ServletContext sc) throws ServletException { + AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext(); + root.register(JsonParamsConfig.class); + root.setServletContext(sc); + sc.addListener(new ContextLoaderListener(root)); + + DispatcherServlet dv = new DispatcherServlet(root); + + ServletRegistration.Dynamic appServlet = sc.addServlet("jsonparams-mvc", dv); + appServlet.setLoadOnStartup(1); + appServlet.addMapping("/"); + } + +} diff --git a/spring-mvc-basics-4/src/main/java/com/baeldung/jsonparams/controller/ProductController.java b/spring-mvc-basics-4/src/main/java/com/baeldung/jsonparams/controller/ProductController.java new file mode 100644 index 0000000000..e4e2ce085d --- /dev/null +++ b/spring-mvc-basics-4/src/main/java/com/baeldung/jsonparams/controller/ProductController.java @@ -0,0 +1,57 @@ +package com.baeldung.jsonparams.controller; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.WebDataBinder; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.InitBinder; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +import com.baeldung.jsonparams.model.Product; +import com.baeldung.jsonparams.propertyeditor.ProductEditor; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +@Controller +@RequestMapping("/products") +public class ProductController { + + private ObjectMapper objectMapper; + + @Autowired + public void setObjectMapper(ObjectMapper objectMapper) { + this.objectMapper = objectMapper; + } + + @InitBinder + public void initBinder(WebDataBinder binder) { + binder.registerCustomEditor(Product.class, new ProductEditor(objectMapper)); + } + + @PostMapping("/create") + @ResponseBody + public Product createProduct(@RequestBody Product product) { + // custom logic + return product; + } + + @GetMapping("/get") + @ResponseBody + public Product getProduct(@RequestParam String product) throws JsonMappingException, JsonProcessingException { + final Product prod = objectMapper.readValue(product, Product.class); + return prod; + } + + @GetMapping("/get2") + @ResponseBody + public Product get2Product(@RequestParam Product product) { + // custom logic + return product; + } + +} diff --git a/spring-mvc-basics-4/src/main/java/com/baeldung/jsonparams/model/Product.java b/spring-mvc-basics-4/src/main/java/com/baeldung/jsonparams/model/Product.java new file mode 100644 index 0000000000..b0baf0aa57 --- /dev/null +++ b/spring-mvc-basics-4/src/main/java/com/baeldung/jsonparams/model/Product.java @@ -0,0 +1,37 @@ +package com.baeldung.jsonparams.model; + +public class Product { + + private int id; + private String name; + private double price; + + public Product() { + + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String nom) { + this.name = nom; + } + + public double getPrice() { + return price; + } + + public void setPrice(double price) { + this.price = price; + } + +} diff --git a/spring-mvc-basics-4/src/main/java/com/baeldung/jsonparams/propertyeditor/ProductEditor.java b/spring-mvc-basics-4/src/main/java/com/baeldung/jsonparams/propertyeditor/ProductEditor.java new file mode 100644 index 0000000000..11766118cd --- /dev/null +++ b/spring-mvc-basics-4/src/main/java/com/baeldung/jsonparams/propertyeditor/ProductEditor.java @@ -0,0 +1,34 @@ +package com.baeldung.jsonparams.propertyeditor; + +import java.beans.PropertyEditorSupport; + +import org.springframework.util.StringUtils; + +import com.baeldung.jsonparams.model.Product; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class ProductEditor extends PropertyEditorSupport { + + private ObjectMapper objectMapper; + + public ProductEditor(ObjectMapper objectMapper) { + this.objectMapper = objectMapper; + } + + @Override + public void setAsText(String text) throws IllegalArgumentException { + if (StringUtils.isEmpty(text)) { + setValue(null); + } else { + Product prod = new Product(); + try { + prod = objectMapper.readValue(text, Product.class); + } catch (JsonProcessingException e) { + throw new IllegalArgumentException(e); + } + setValue(prod); + } + } + +} diff --git a/spring-mvc-basics-4/src/test/java/com/baeldung/jsonparams/JsonParamsIntegrationTest.java b/spring-mvc-basics-4/src/test/java/com/baeldung/jsonparams/JsonParamsIntegrationTest.java new file mode 100644 index 0000000000..bceadc4896 --- /dev/null +++ b/spring-mvc-basics-4/src/test/java/com/baeldung/jsonparams/JsonParamsIntegrationTest.java @@ -0,0 +1,71 @@ +package com.baeldung.jsonparams; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.AnnotationConfigWebContextLoader; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +import com.baeldung.jsonparams.config.JsonParamsConfig; + +@RunWith(SpringJUnit4ClassRunner.class) +@WebAppConfiguration +@ContextConfiguration(classes = { JsonParamsConfig.class }, loader = AnnotationConfigWebContextLoader.class) +public class JsonParamsIntegrationTest { + + private MockMvc mockMvc; + + @Autowired + private WebApplicationContext wac; + + @Before + public void setUp() { + this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac) + .build(); + } + + @Test + public void whenJsonIsPassedWithPost_thenResponseOK() throws Exception { + + this.mockMvc.perform(post("/products/create").accept(MediaType.APPLICATION_JSON) + .contentType(MediaType.APPLICATION_JSON) + .content("{\"id\": 1,\"name\": \"Asus Zenbook\",\"price\": 800}")) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.id").value("1")) + .andExpect(jsonPath("$.name").value("Asus Zenbook")); + + } + + @Test + public void whenJsonIsPassedWithGet_thenResponseOK() throws Exception { + + this.mockMvc.perform(get("/products/get").contentType(MediaType.APPLICATION_JSON) + .queryParam("product", "{\"id\": 2,\"name\": \"HP EliteBook\",\"price\": 700}")) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.id").value("2")) + .andExpect(jsonPath("$.name").value("HP EliteBook")); + + } + + @Test + public void whenJsonIsPassedWithGet2_thenResponseOK() throws Exception { + + this.mockMvc.perform(get("/products/get2").contentType(MediaType.APPLICATION_JSON) + .queryParam("product", "{\"id\": 3,\"name\": \"Dell G5 15\",\"price\": 1200}")) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.id").value("3")) + .andExpect(jsonPath("$.name").value("Dell G5 15")); + + } + +} From 1cd9875381b282aff23c40473f03754e20302d1f Mon Sep 17 00:00:00 2001 From: KevinGilmore Date: Sat, 19 Sep 2020 10:40:37 -0500 Subject: [PATCH 53/54] BAEL-3569: Update README (#10053) * BAEL-3336 BAEL-3058 add links * BAEL-3319: add link * BAEL-3284: add link * BAEL-3198: add link to article * BAEL-3479: add link to article * BAEL-3485: add article link * SCALA-38: move to new package and add link back to article * SCALA-38: add imports back into unit test * BAEL-3908: add link back to article * BAEL-2893 BAEL-3927 add link back to article * BAEL-3569: update README --- spring-5-security-oauth/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-5-security-oauth/README.md b/spring-5-security-oauth/README.md index 43cab33598..35e64da639 100644 --- a/spring-5-security-oauth/README.md +++ b/spring-5-security-oauth/README.md @@ -7,3 +7,4 @@ This module contains articles about Spring 5 OAuth Security - [Spring Security 5 – OAuth2 Login](https://www.baeldung.com/spring-security-5-oauth2-login) - [Extracting Principal and Authorities using Spring Security OAuth](https://www.baeldung.com/spring-security-oauth-principal-authorities-extractor) - [Customizing Authorization and Token Requests with Spring Security 5.1 Client](https://www.baeldung.com/spring-security-custom-oauth-requests) +- [Social Login with Spring Security in a Jersey Application](https://www.baeldung.com/spring-security-social-login-jersey) From f1348339529b20f6d61b3cc9442db89faaafcee7 Mon Sep 17 00:00:00 2001 From: Umang Budhwar Date: Sat, 19 Sep 2020 21:49:13 +0530 Subject: [PATCH 54/54] Refactored code to use generic methods and use streams. (#10052) --- .../check/staticmethods/StaticUtility.java | 19 ++++++++++++ .../staticmethods/StaticUtilityUnitTest.java | 30 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 core-java-modules/core-java-reflection-2/src/main/java/com/baeldung/reflection/check/staticmethods/StaticUtility.java create mode 100644 core-java-modules/core-java-reflection-2/src/test/java/com/baeldung/reflection/check/staticmethods/StaticUtilityUnitTest.java diff --git a/core-java-modules/core-java-reflection-2/src/main/java/com/baeldung/reflection/check/staticmethods/StaticUtility.java b/core-java-modules/core-java-reflection-2/src/main/java/com/baeldung/reflection/check/staticmethods/StaticUtility.java new file mode 100644 index 0000000000..5afb9b79c4 --- /dev/null +++ b/core-java-modules/core-java-reflection-2/src/main/java/com/baeldung/reflection/check/staticmethods/StaticUtility.java @@ -0,0 +1,19 @@ +package com.baeldung.reflection.check.staticmethods; + +import java.time.LocalDate; +import java.time.LocalTime; + +public class StaticUtility { + + public static String getAuthorName() { + return "Umang Budhwar"; + } + + public static LocalDate getLocalDate() { + return LocalDate.now(); + } + + public static LocalTime getLocalTime() { + return LocalTime.now(); + } +} diff --git a/core-java-modules/core-java-reflection-2/src/test/java/com/baeldung/reflection/check/staticmethods/StaticUtilityUnitTest.java b/core-java-modules/core-java-reflection-2/src/test/java/com/baeldung/reflection/check/staticmethods/StaticUtilityUnitTest.java new file mode 100644 index 0000000000..a4540407d5 --- /dev/null +++ b/core-java-modules/core-java-reflection-2/src/test/java/com/baeldung/reflection/check/staticmethods/StaticUtilityUnitTest.java @@ -0,0 +1,30 @@ +package com.baeldung.reflection.check.staticmethods; + +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +class StaticUtilityUnitTest { + + @Test + void whenCheckStaticMethod_ThenSuccess() throws Exception { + Method method = StaticUtility.class.getMethod("getAuthorName", null); + Assertions.assertTrue(Modifier.isStatic(method.getModifiers())); + } + + @Test + void whenCheckAllStaticMethods_thenSuccess() { + List methodList = Arrays.asList(StaticUtility.class.getMethods()) + .stream() + .filter(method -> Modifier.isStatic(method.getModifiers())) + .collect(Collectors.toList()); + Assertions.assertEquals(3, methodList.size()); + } + +}